From 9d64bf737c3002a35e5f12f188aa524cc5816218 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 16 Oct 2019 14:20:39 -0700 Subject: [PATCH] Update specs to keep trailing comments on the previous line See sass/dart-sass#417 --- lib/sass_spec/test.rb | 24 ++++++++++-- spec/basic/06_nesting_and_comments.hrx | 47 +++++++++++++++++++++++ spec/css/keyframes.hrx | 4 ++ spec/directives/use/css/order.hrx | 17 ++++++++ spec/libsass-closed-issues/issue_1007.hrx | 9 +++++ spec/libsass-closed-issues/issue_1294.hrx | 8 ++++ spec/libsass-closed-issues/issue_1567.hrx | 8 ++++ spec/libsass-closed-issues/issue_894.hrx | 9 ++--- spec/libsass-closed-issues/issue_941.hrx | 6 +++ 9 files changed, 124 insertions(+), 8 deletions(-) diff --git a/lib/sass_spec/test.rb b/lib/sass_spec/test.rb index 31411637e5..535a702f4e 100644 --- a/lib/sass_spec/test.rb +++ b/lib/sass_spec/test.rb @@ -499,22 +499,40 @@ def delete_test! def migrate_impl! if @status == 0 if @test_case.expected != @normalized_output || @test_case.should_fail? - @test_case.write("output.css", @output, impl: true) + _write_for_impl("output.css", @output) end if extract_error_message(@test_case.expected_warning) != extract_error_message(@error) - @test_case.write("warning", @error, impl: true) + _write_for_impl("warning", @error) end else actual_error = @test_case.expected_error && extract_error_message(@test_case.expected_error) if actual_error != extract_error_message(@error) - @test_case.write("error", @error, impl: true) + _write_for_impl("error", @error) end end change_options(remove_warning_todo: [@test_case.impl], remove_todo: [@test_case.impl]) end + # Writes `contents` to the implementation-specific version of `file`. + # + # If the current implementation is Dart Sass, this instead migrates the + # existing file to a LibSass-specific file and overwrites the default file + # with the Dart Sass expectation. + def _write_for_impl(file, contents) + if @test_case.impl != "dart-sass" + @test_case.write(file, contents, impl: true) + return + end + + libsass_test_case = SassSpec::TestCase.new(@test_case.dir, "libsass") + libsass_test_case.write(file, libsass_test_case.read(file, impl: :auto), impl: true) + + @test_case.delete(file, if_exists: true, impl: true) + @test_case.write(file, contents, impl: false) + end + ## Other utilities # Returns whether the current test case is marked as TODO, but is still being diff --git a/spec/basic/06_nesting_and_comments.hrx b/spec/basic/06_nesting_and_comments.hrx index 43ff0fd61a..4080061a19 100644 --- a/spec/basic/06_nesting_and_comments.hrx +++ b/spec/basic/06_nesting_and_comments.hrx @@ -65,6 +65,53 @@ div span { /* yet another comment that should be preserved */ display: inline-block; } +div span a { + text-decoration: none; /* where will this comment go? */ + color: green; + /* what about this comment? */ + border: 1px bloo blee red; +} +div empty not_empty { + blah: blah; + bloo: bloo; +} +div p { + padding: 10px 8%; + -webkit-box-sizing: hux; +} +div h1 { + color: "a 'red' and \"blue\" value"; +} + +/* last comment, top level again -- + compare the indentation! */ +div { + f: g; +} +div empty span { + a: b; +} +div empty_with_comment { + /* hey now */ +} +div empty_with_comment span { + c: d; +} + +<===> output-libsass.css +/* top level comment -- should be preserved */ +div { + /* another comment that should be preserved */ + color: red; + background: blue; + /* the next selector should be indented two spaces */ + margin: 10px 5px; +} +div span { + font-weight: bold; + /* yet another comment that should be preserved */ + display: inline-block; +} div span a { text-decoration: none; /* where will this comment go? */ diff --git a/spec/css/keyframes.hrx b/spec/css/keyframes.hrx index 6d4d6228dd..91c674af4a 100644 --- a/spec/css/keyframes.hrx +++ b/spec/css/keyframes.hrx @@ -5,6 +5,10 @@ a { } <===> bubble/empty/output.css +@keyframes { /**/ +} + +<===> bubble/empty/output-libsass.css @keyframes { /**/ } diff --git a/spec/directives/use/css/order.hrx b/spec/directives/use/css/order.hrx index 5050569238..0a0f7b9e8f 100644 --- a/spec/directives/use/css/order.hrx +++ b/spec/directives/use/css/order.hrx @@ -451,6 +451,23 @@ a {file: midstream} <===> import_order/comments_and_imports/output.css /* upstream comment before import */ +@import "upstream.css"; /* midstream comment before use */ +/* midstream comment before first import */ +@import "midstream1.css"; +/* midstream comment before second import */ +@import "midstream2.css"; /* input comment before use */ +/* input comment before import */ +@import "input.css"; +/* upstream comment after import */ +/* midstream comment after imports */ +a { + file: midstream; +} + +/* input comment after import */ + +<===> import_order/comments_and_imports/output-libsass.css +/* upstream comment before import */ @import "upstream.css"; diff --git a/spec/libsass-closed-issues/issue_1007.hrx b/spec/libsass-closed-issues/issue_1007.hrx index 626f26132a..6d84d519e2 100644 --- a/spec/libsass-closed-issues/issue_1007.hrx +++ b/spec/libsass-closed-issues/issue_1007.hrx @@ -4,6 +4,15 @@ } /* end */ <===> output.css /* start */ +foo baz { + /* before */ + margin: 0; /* after */ +} + +/* end */ + +<===> output-libsass.css +/* start */ foo baz { /* before */ margin: 0; diff --git a/spec/libsass-closed-issues/issue_1294.hrx b/spec/libsass-closed-issues/issue_1294.hrx index f476603f9a..a4b1af59cd 100644 --- a/spec/libsass-closed-issues/issue_1294.hrx +++ b/spec/libsass-closed-issues/issue_1294.hrx @@ -11,6 +11,14 @@ foo { /*------------------------------------*\ #BUTTONS \*------------------------------------*/ +foo { + display: inline-block; /* [1] */ +} + +<===> output-libsass.css +/*------------------------------------*\ + #BUTTONS +\*------------------------------------*/ foo { display: inline-block; /* [1] */ diff --git a/spec/libsass-closed-issues/issue_1567.hrx b/spec/libsass-closed-issues/issue_1567.hrx index 102c18e422..7a3558b321 100644 --- a/spec/libsass-closed-issues/issue_1567.hrx +++ b/spec/libsass-closed-issues/issue_1567.hrx @@ -7,6 +7,14 @@ <===> output.css /* any */ +@media screen, not print { /* whatever */ + body { + line-height: 1.2; + } +} + +<===> output-libsass.css +/* any */ @media screen, not print { /* whatever */ body { diff --git a/spec/libsass-closed-issues/issue_894.hrx b/spec/libsass-closed-issues/issue_894.hrx index 90189bd76a..c3b6101834 100644 --- a/spec/libsass-closed-issues/issue_894.hrx +++ b/spec/libsass-closed-issues/issue_894.hrx @@ -2,19 +2,18 @@ a {/**/} b {content: 'something so I have a non-empty expected output'} <===> output.css -a { - /**/ +a { /**/ } b { - content: 'something so I have a non-empty expected output'; + content: "something so I have a non-empty expected output"; } -<===> output-dart-sass.css +<===> output-libsass.css a { /**/ } b { - content: "something so I have a non-empty expected output"; + content: 'something so I have a non-empty expected output'; } diff --git a/spec/libsass-closed-issues/issue_941.hrx b/spec/libsass-closed-issues/issue_941.hrx index fdcd88e11c..72e49460c7 100644 --- a/spec/libsass-closed-issues/issue_941.hrx +++ b/spec/libsass-closed-issues/issue_941.hrx @@ -6,6 +6,12 @@ <===> output.css .one, +.two { /* 3 */ + color: #F00; /* 4 */ +} + +<===> output-libsass.css +.one, .two { /* 3 */ color: #F00;