test/sass/engine_test.rb in sass-3.2.19 vs test/sass/engine_test.rb in sass-3.3.0.alpha.1

- old
+ new

@@ -132,23 +132,23 @@ %Q{@warn "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath warn directives.", "/* foo\n bar\n baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.", '+foo(1 + 1: 2)' => 'Invalid CSS after "(1 + 1": expected comma, was ": 2)"', '+foo($var: )' => 'Invalid CSS after "($var: ": expected mixin argument, was ")"', '+foo($var: a, $var: b)' => 'Keyword argument "$var" passed more than once', - '+foo($var-var: a, $var_var: b)' => 'Keyword argument "$var_var" passed more than once', - '+foo($var_var: a, $var-var: b)' => 'Keyword argument "$var-var" passed more than once', + '+foo($var-var: a, $var_var: b)' => 'Keyword argument "$var-var" passed more than once', + '+foo($var_var: a, $var-var: b)' => 'Keyword argument "$var_var" passed more than once', "a\n b: foo(1 + 1: 2)" => 'Invalid CSS after "foo(1 + 1": expected comma, was ": 2)"', "a\n b: foo($var: )" => 'Invalid CSS after "foo($var: ": expected function argument, was ")"', "a\n b: foo($var: a, $var: b)" => 'Keyword argument "$var" passed more than once', - "a\n b: foo($var-var: a, $var_var: b)" => 'Keyword argument "$var_var" passed more than once', - "a\n b: foo($var_var: a, $var-var: b)" => 'Keyword argument "$var-var" passed more than once', + "a\n b: foo($var-var: a, $var_var: b)" => 'Keyword argument "$var-var" passed more than once', + "a\n b: foo($var_var: a, $var-var: b)" => 'Keyword argument "$var_var" passed more than once', "@if foo\n @extend .bar" => ["Extend directives may only be used within rules.", 2], "$var: true\n@while $var\n @extend .bar\n $var: false" => ["Extend directives may only be used within rules.", 3], "@for $i from 0 to 1\n @extend .bar" => ["Extend directives may only be used within rules.", 2], "@mixin foo\n @extend .bar\n@include foo" => ["Extend directives may only be used within rules.", 2], - "foo\n &a\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"a\"\n\n\"a\" may only be used at the beginning of a compound selector.", 2], - "foo\n &1\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"1\"\n\n\"1\" may only be used at the beginning of a compound selector.", 2], + "foo\n &a\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"a\"\n\n\"a\" may only be used at the beginning of a selector.", 2], + "foo\n &1\n b: c" => ["Invalid CSS after \"&\": expected \"{\", was \"1\"\n\n\"1\" may only be used at the beginning of a selector.", 2], "foo %\n a: b" => ['Invalid CSS after "foo %": expected placeholder name, was ""', 1], "=foo\n @content error" => "Invalid content directive. Trailing characters found: \"error\".", "=foo\n @content\n b: c" => "Illegal nesting: Nothing may be nested beneath @content directives.", "@content" => '@content may only be used within a mixin.', "=simple\n .simple\n color: red\n+simple\n color: blue" => ['Mixin "simple" does not accept a content block.', 4], @@ -156,11 +156,10 @@ # Regression tests "a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3], "& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1], "a\n b: c\n& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 3], - "@" => "Invalid directive: '@'.", } def teardown clean_up_sassc end @@ -216,51 +215,11 @@ assert_equal("p {\n a: b; }\n p q {\n c: d; }\n", render("p\n a: b\n q\n c: d\n")) assert_equal("p {\n a: b; }\n p q {\n c: d; }\n", render("p\n\ta: b\n\tq\n\t\tc: d\n")) end - - def test_import_same_name_different_ext - assert_warning <<WARNING do -WARNING: On line 1 of test_import_same_name_different_ext_inline.sass: - It's not clear which file to import for '@import "same_name_different_ext"'. - Candidates: - same_name_different_ext.sass - same_name_different_ext.scss - For now I'll choose same_name_different_ext.sass. - This will be an error in future versions of Sass. -WARNING - options = {:load_paths => [File.dirname(__FILE__) + '/templates/']} - munge_filename options - result = Sass::Engine.new("@import 'same_name_different_ext'", options).render - assert_equal(<<CSS, result) -.foo { - ext: sass; } -CSS - end - end - - def test_import_same_name_different_partiality - assert_warning <<WARNING do -WARNING: On line 1 of test_import_same_name_different_partiality_inline.sass: - It's not clear which file to import for '@import "same_name_different_partiality"'. - Candidates: - _same_name_different_partiality.scss - same_name_different_partiality.scss - For now I'll choose _same_name_different_partiality.scss. - This will be an error in future versions of Sass. -WARNING - options = {:load_paths => [File.dirname(__FILE__) + '/templates/']} - munge_filename options - result = Sass::Engine.new("@import 'same_name_different_partiality'", options).render - assert_equal(<<CSS, result) -.foo { - partial: yes; } -CSS - end - end - + EXCEPTION_MAP.each do |key, value| define_method("test_exception (#{key.inspect})") do line = 10 begin silence_warnings {Sass::Engine.new(key, :filename => FAKE_FILE_NAME, :line => line).render} @@ -522,25 +481,10 @@ assert_hash_has(err.sass_backtrace[0], :mixin => "baz", :line => 8) assert_hash_has(err.sass_backtrace[1], :mixin => "bar", :line => 5) assert_hash_has(err.sass_backtrace[2], :mixin => "foo", :line => 2) end - def test_mixin_loop_with_content - render <<SASS -=foo - @content -=bar - +foo - +bar -+bar -SASS - assert(false, "Exception not raised") - rescue Sass::SyntaxError => err - assert_equal("An @include loop has been found: bar includes itself", err.message) - assert_hash_has(err.sass_backtrace[0], :mixin => "@content", :line => 5) - end - def test_basic_import_loop_exception import = filename_for_test importer = MockImporter.new importer.add_import(import, "@import '#{import}'") @@ -556,11 +500,11 @@ importer = MockImporter.new importer.add_import("foo", "@import 'bar'") importer.add_import("bar", "@import 'foo'") engine = Sass::Engine.new('@import "foo"', :filename => filename_for_test, - :load_paths => [importer], :importer => importer) + :load_paths => [importer]) assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) {engine.render} An @import loop has been found: #{filename_for_test} imports foo foo imports bar @@ -573,11 +517,11 @@ importer.add_import("foo", "@import 'bar'") importer.add_import("bar", "@import 'baz'") importer.add_import("baz", "@import 'foo'") engine = Sass::Engine.new('@import "foo"', :filename => filename_for_test, - :load_paths => [importer], :importer => importer) + :load_paths => [importer]) assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) {engine.render} An @import loop has been found: #{filename_for_test} imports foo foo imports bar @@ -679,15 +623,10 @@ def test_http_import assert_equal("@import url(http://fonts.googleapis.com/css?family=Droid+Sans);\n", render("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\"")) end - def test_protocol_relative_import - assert_equal("@import url(//fonts.googleapis.com/css?family=Droid+Sans);\n", - render("@import \"//fonts.googleapis.com/css?family=Droid+Sans\"")) - end - def test_import_with_interpolation assert_equal(<<CSS, render(<<SASS)) @import url("http://fonts.googleapis.com/css?family=Droid+Sans"); CSS $family: unquote("Droid+Sans") @@ -729,11 +668,11 @@ def test_import_from_global_load_paths importer = MockImporter.new importer.add_import("imported", "div{color:red}") Sass.load_paths << importer - assert_equal "div {\n color: red; }\n", Sass::Engine.new('@import "imported"', :importer => importer).render + assert_equal "div {\n color: red; }\n", Sass::Engine.new('@import "imported"').render ensure Sass.load_paths.clear end def test_nonexistent_import @@ -1803,11 +1742,11 @@ SASS end def test_loud_comment_in_compressed_mode assert_equal <<CSS, render(<<SASS, :style => :compressed) -foo{color:blue;/*! foo +foo{color:blue;/* foo * bar */} CSS foo color: blue @@ -1817,12 +1756,11 @@ SASS end def test_loud_comment_is_evaluated assert_equal <<CSS, render(<<SASS) -/*! - * Hue: 327.21649deg */ +/* Hue: 327.21649deg */ CSS /*! Hue: \#{hue(#f836a0)} SASS end @@ -2396,59 +2334,10 @@ SASS end # Regression tests - def test_parent_mixin_in_content_nested - assert_equal(<<CSS, render(<<SASS)) -a { - b: c; } -CSS -=foo - @content - -=bar - +foo - +foo - a - b: c - -+bar -SASS - end - - def test_supports_bubbles - assert_equal <<CSS, render(<<SASS) -parent { - background: orange; } - @supports (perspective: 10px) or (-moz-perspective: 10px) { - parent child { - background: blue; } } -CSS -parent - background: orange - @supports (perspective: 10px) or (-moz-perspective: 10px) - child - background: blue -SASS - end - - def test_line_numbers_with_dos_line_endings - assert_equal <<CSS, render(<<SASS, :line_comments => true) -/* line 5, test_line_numbers_with_dos_line_endings_inline.sass */ -.foo { - a: b; } -CSS -\r -\r -\r -\r -.foo - a: b -SASS - end - def test_variable_in_media_in_mixin assert_equal <<CSS, render(<<SASS) @media screen and (min-width: 10px) { body { background: red; } } @@ -2486,19 +2375,19 @@ assert_hash_has(err.sass_backtrace[0], :mixin => "foo", :line => 3) end def test_interpolated_comment_in_mixin assert_equal <<CSS, render(<<SASS) -/*! color: red */ +/* color: red */ .foo { color: red; } -/*! color: blue */ +/* color: blue */ .foo { color: blue; } -/*! color: green */ +/* color: green */ .foo { color: green; } CSS =foo($var) /*! color: \#{$var} @@ -2789,11 +2678,11 @@ /* \#{foo} */ CSS /* \\\#{foo} SASS assert_equal <<CSS, render(<<SASS) -/*! \#{foo} */ +/* \#{foo} */ CSS /*! \\\#{foo} SASS end @@ -2972,11 +2861,11 @@ importer = MockImporter.new importer.add_import("imported", "div{color:red}") original_filename = filename_for_test engine = Sass::Engine.new('@import "imported"; div{color:blue}', - :filename => original_filename, :load_paths => [importer], :syntax => :scss, :importer => importer) + :filename => original_filename, :load_paths => [importer], :syntax => :scss) engine.render assert_equal original_filename, engine.options[:original_filename] assert_equal original_filename, importer.engine("imported").options[:original_filename] end @@ -3207,10 +3096,9 @@ assert_equal css, result end def render(sass, options = {}) munge_filename options - options[:importer] ||= MockImporter.new Sass::Engine.new(sass, options).render end def renders_correctly(name, options={}) sass_file = load_file(name, "sass")