test/sass/engine_test.rb in sass-3.2.0.alpha.11 vs test/sass/engine_test.rb in sass-3.2.0.alpha.21

- old
+ new

@@ -37,12 +37,12 @@ "a\n :b:c d" => 'Invalid property: ":b:c d".', "a\n :b c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"', "a\n b: c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"', ".foo ^bar\n a: b" => ['Invalid CSS after ".foo ": expected selector, was "^bar"', 1], "a\n @extend .foo ^bar" => 'Invalid CSS after ".foo ": expected selector, was "^bar"', - "a: b" => 'Properties are only allowed within rules, directives, or other properties.', - ":a b" => 'Properties are only allowed within rules, directives, or other properties.', + "a: b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.', + ":a b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.', "$" => 'Invalid variable: "$".', "$a" => 'Invalid variable: "$a".', "$ a" => 'Invalid variable: "$ a".', "$a b" => 'Invalid variable: "$a b".', "$a: 1b + 2c" => "Incompatible units: 'c' and 'b'.", @@ -60,17 +60,17 @@ "$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.", "@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.", "foo\n @import foo.css" => "CSS import directives may only be used at the root of a document.", "@if true\n @import foo" => "Import directives may not be used within control directives or mixins.", "@mixin foo\n @import foo" => "Import directives may not be used within control directives or mixins.", + "@import foo;" => "Invalid @import: expected end of line, was \";\".", '$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"}, '$foo: "bar" "baz" $' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "$"}, "=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.", "=foo\n :color red\n.bar\n +bang_bop" => "Undefined mixin 'bang_bop'.", "=foo\n :color red\n.bar\n +bang-bop" => "Undefined mixin 'bang-bop'.", ".bar\n =foo\n :color red\n" => ["Mixins may only be defined at the root of a document.", 2], - "=foo\n :color red\n.bar\n +foo\n :color red" => "Illegal nesting: Nothing may be nested beneath mixin directives.", " a\n b: c" => ["Indenting at the beginning of the document is illegal.", 1], " \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4], "a\n b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3], "a\n b: c\na\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 4], "a\n\t\tb: c\n\tb: c" => ["Inconsistent indentation: 1 tab was used for indentation, but the rest of the document was indented using 2 tabs.", 3], @@ -82,11 +82,11 @@ "=a(" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ""', "=a(b)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "b)"', "=a(,)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ",)"', "=a($)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "$)"', "=a($foo bar)" => 'Invalid CSS after "($foo ": expected ")", was "bar)"', - "=foo\n bar: baz\n+foo" => ["Properties are only allowed within rules, directives, or other properties.", 2], + "=foo\n bar: baz\n+foo" => ["Properties are only allowed within rules, directives, mixin includes, or other properties.", 2], "a-\#{$b\n c: d" => ['Invalid CSS after "a-#{$b": expected "}", was ""', 1], "=a($b: 1, $c)" => "Required argument $c must come before any optional arguments.", "=a($b: 1)\n a: $b\ndiv\n +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.", "=a($b: 1)\n a: $b\ndiv\n +a(1,$c: 3)" => "Mixin a doesn't have an argument named $c", "=a($b)\n a: $b\ndiv\n +a" => "Mixin a is missing parameter $b.", @@ -137,10 +137,17 @@ "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 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 @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], + "=foo\n @content\n+foo" => ["No @content passed.", 2], # 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], @@ -303,10 +310,27 @@ assert(false, "Exception not raised for imported template: bork#{i}") end end end + def test_selector_tracing + actual_css = render(<<-SCSS, :syntax => :scss, :trace_selectors => true) + @mixin mixed { + .mixed { color: red; } + } + .context { + @include mixed; + } + SCSS + assert_equal(<<CSS,actual_css) +/* on line 2 of test_selector_tracing_inline.scss, in `mixed' + from line 5 of test_selector_tracing_inline.scss */ +.context .mixed { + color: red; } +CSS + end + def test_mixin_exception render(<<SASS) =error-mixin($a) color: $a * 1em * 1px @@ -521,11 +545,11 @@ a: b SASS rescue Sass::SyntaxError => e assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..11].join("\n")) /* -Syntax error: Properties are only allowed within rules, directives, or other properties. +Syntax error: Properties are only allowed within rules, directives, mixin includes, or other properties. on line 4 of test_cssize_exception_css_inline.sass 1: .filler 2: stuff: "stuff!" 3: @@ -1774,26 +1798,26 @@ SASS end def test_interpolation_doesnt_deep_unquote_strings assert_equal(<<CSS, render(<<SASS)) -.foo- "bar" "baz" { - a: b; } +.foo { + a: "bar" "baz"; } CSS -.foo-\#{"bar" "baz"} - a: b +.foo + a: \#{"bar" "baz"} SASS end def test_warn_directive expected_warning = <<EXPECTATION WARNING: this is a warning - on line 4 of test_warn_directive_inline.sass + on line 4 of test_warn_directive_inline.sass WARNING: this is a mixin warning - on line 2 of test_warn_directive_inline.sass, in `foo' - from line 7 of test_warn_directive_inline.sass + on line 2 of test_warn_directive_inline.sass, in `foo' + from line 7 of test_warn_directive_inline.sass EXPECTATION assert_warning expected_warning do assert_equal <<CSS, render(<<SASS) bar { c: d; } @@ -1819,19 +1843,19 @@ end def test_warn_with_imports expected_warning = <<WARN WARNING: In the main file - on line 1 of #{File.dirname(__FILE__)}/templates/warn.sass + on line 1 of #{File.dirname(__FILE__)}/templates/warn.sass WARNING: Imported - on line 1 of #{File.dirname(__FILE__)}/templates/warn_imported.sass - from line 2 of #{File.dirname(__FILE__)}/templates/warn.sass + on line 1 of #{File.dirname(__FILE__)}/templates/warn_imported.sass + from line 2 of #{File.dirname(__FILE__)}/templates/warn.sass WARNING: In an imported mixin - on line 4 of #{File.dirname(__FILE__)}/templates/warn_imported.sass, in `emits-a-warning' - from line 3 of #{File.dirname(__FILE__)}/templates/warn.sass + on line 4 of #{File.dirname(__FILE__)}/templates/warn_imported.sass, in `emits-a-warning' + from line 3 of #{File.dirname(__FILE__)}/templates/warn.sass WARN assert_warning expected_warning do renders_correctly "warn", :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"] end end @@ -2432,9 +2456,216 @@ assert_equal original_filename, engine.options[:original_filename] assert_equal original_filename, importer.engine("imported").options[:original_filename] end + def test_deprecated_PRECISION + assert_warning(<<END) {assert_equal 1000.0, Sass::Script::Number::PRECISION} +Sass::Script::Number::PRECISION is deprecated and will be removed in a future release. Use Sass::Script::Number.precision_factor instead. +END + end + def test_changing_precision + begin + Sass::Script::Number.precision = 8 + assert_equal <<CSS, render(<<SASS) +div { + maximum: 1.00000001; + too-much: 1.0; } +CSS +div + maximum : 1.00000001 + too-much: 1.000000001 +SASS + ensure + Sass::Script::Number.precision = 3 + end + end + + def test_content + assert_equal <<CSS, render(<<SASS) +.children { + background-color: red; + color: blue; + border-color: red; } +CSS +$color: blue +=context($class, $color: red) + .\#{$class} + background-color: $color + @content + border-color: $color ++context(children) + color: $color +SASS + end + + def test_selector_in_content + assert_equal <<CSS, render(<<SASS) +.parent { + background-color: red; + border-color: red; } + .parent .children { + color: blue; } +CSS +$color: blue +=context($class, $color: red) + .\#{$class} + background-color: $color + @content + border-color: $color ++context(parent) + .children + color: $color +SASS + end + + def test_using_parent_mixin_in_content + assert_equal <<CSS, render(<<SASS) +.parent { + before-color: red; + after-color: red; } + .parent .sibling { + before-color: yellow; + after-color: yellow; } + .parent .sibling .child { + before-color: green; + color: blue; + after-color: green; } +CSS +$color: blue +=context($class, $color: red) + .\#{$class} + before-color: $color + @content + after-color: $color ++context(parent) + +context(sibling, $color: yellow) + +context(child, $color: green) + color: $color +SASS + end + + def test_content_more_than_once + assert_equal <<CSS, render(<<SASS) +.once { + color: blue; } + +.twice { + color: blue; } +CSS +$color: blue +=context($class, $color: red) + .once + @content + .twice + @content ++context(parent) + color: $color +SASS + end + + def test_content_with_variable + assert_equal <<CSS, render(<<SASS) +.foo { + a: 1px; } +CSS +=foo + .foo + @content ++foo + $a: 1px + a: $a +SASS + end + + def test_nested_content_blocks + assert_equal <<CSS, render(<<SASS) +.foo { + a: foo; } + .foo .bar { + a: bar; } + .foo .bar .baz { + a: baz; } + .foo .bar .baz .outside { + a: outside; + color: red; } +CSS +$a: outside +=baz($a: baz) + .baz + a: $a + @content +=bar($a: bar) + .bar + a: $a + +baz + @content +=foo($a: foo) + .foo + a: $a + +bar + @content ++foo + .outside + a: $a + color: red +SASS + end + + def test_content_not_seen_through_mixin + render(<<SASS) +=foo + foo + @content + +bar +=bar + bar + @content +a + +foo + a: b +SASS + assert(false, "Expected exception") + rescue Sass::SyntaxError => e + assert_equal("No @content passed.", e.message) + assert_equal(7, e.sass_line) + end + + def test_content_backtrace_for_perform + render(<<SASS) +=foo + @content + +a + +foo + b: 1em + 2px +SASS + assert(false, "Expected exception") + rescue Sass::SyntaxError => e + assert_equal([ + {:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_perform_inline.sass'}, + {:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_perform_inline.sass'}, + {:line => 5, :filename => 'test_content_backtrace_for_perform_inline.sass'}, + ], e.sass_backtrace) + end + + def test_content_backtrace_for_cssize + render(<<SASS) +=foo + @content + +a + +foo + @extend foo bar baz +SASS + assert(false, "Expected exception") + rescue Sass::SyntaxError => e + assert_equal([ + {:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_cssize_inline.sass'}, + {:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_cssize_inline.sass'}, + {:line => 5, :filename => 'test_content_backtrace_for_cssize_inline.sass'}, + ], e.sass_backtrace) + end private def assert_hash_has(hash, expected) expected.each {|k, v| assert_equal(v, hash[k])}