test/sass/engine_test.rb in sass-3.3.14 vs test/sass/engine_test.rb in sass-3.4.0.rc.1
- old
+ new
@@ -15,20 +15,25 @@
def set_a_variable(name, value)
environment.set_var(name.value, value)
return Sass::Script::Value::Null.new
end
+ def set_a_global_variable(name, value)
+ environment.set_global_var(name.value, value)
+ return Sass::Script::Value::Null.new
+ end
+
def get_a_variable(name)
environment.var(name.value) || Sass::Script::Value::String.new("undefined")
end
end
module Sass::Script::Functions
include Sass::Script::Functions::UserFunctions
end
-class SassEngineTest < Test::Unit::TestCase
+class SassEngineTest < MiniTest::Test
FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass")
# A map of erroneous Sass documents to the error messages they should produce.
# The error messages may be arrays;
# if so, the second element should be the line number that should be reported for the error.
# If this isn't provided, the tests will assume the line number should be the last line of the document.
@@ -66,12 +71,12 @@
"$a: 1b > 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b <= 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b >= 2c" => "Incompatible units: 'c' and 'b'.",
"a\n b: 1b * 2c" => "2b*c isn't a valid CSS value.",
"a\n b: 1b % 2c" => "Incompatible units: 'c' and 'b'.",
- "$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#cccccc).",
- "$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#cccccc).",
+ "$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#ccc).",
+ "$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#ccc).",
"& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
"a\n :b\n c" => "Illegal nesting: Only properties may be nested beneath properties.",
"$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
"$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.",
@@ -139,10 +144,12 @@
'@for $a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
'@if' => "Invalid if directive '@if': expected expression.",
'@while' => "Invalid while directive '@while': expected expression.",
'@debug' => "Invalid debug directive '@debug': expected expression.",
%Q{@debug "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath debug directives.",
+ '@error' => "Invalid error directive '@error': expected expression.",
+ %Q{@error "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath error directives.",
'@warn' => "Invalid warn directive '@warn': expected expression.",
%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 ")"',
@@ -524,13 +531,13 @@
def test_exception_css_with_offset
opts = {:full_exception => true, :line => 362}
render(("a\n b: c\n" * 10) + "d\n e:\n" + ("f\n g: h\n" * 10), opts)
rescue Sass::SyntaxError => e
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..15].join("\n"))
+ assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts[:line]).split("\n")[0..15].join("\n"))
/*
-Syntax error: Invalid property: "e:" (no value).
+Error: Invalid property: "e:" (no value).
on line 383 of test_exception_css_with_offset_inline.sass
378: a
379: b: c
380: a
@@ -546,25 +553,24 @@
else
assert(false, "Exception not raised for test_exception_css_with_offset")
end
def test_exception_css_with_mixins
- opts = {:full_exception => true}
- render(<<SASS, opts)
+ render(<<SASS, :full_exception => true)
=error-mixin($a)
color: $a * 1em * 1px
=outer-mixin($a)
+error-mixin($a)
.error
+outer-mixin(12)
SASS
rescue Sass::SyntaxError => e
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..13].join("\n"))
+ assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e).split("\n")[0..13].join("\n"))
/*
-Syntax error: 12em*px isn't a valid CSS value.
+Error: 12em*px isn't a valid CSS value.
on line 2 of test_exception_css_with_mixins_inline.sass, in `error-mixin'
from line 5 of test_exception_css_with_mixins_inline.sass, in `outer-mixin'
from line 8 of test_exception_css_with_mixins_inline.sass
1: =error-mixin($a)
@@ -578,24 +584,23 @@
else
assert(false, "Exception not raised")
end
def test_cssize_exception_css
- opts = {:full_exception => true}
- render(<<SASS, opts)
+ render(<<SASS, :full_exception => true)
.filler
stuff: "stuff!"
a: b
.more.filler
a: b
SASS
rescue Sass::SyntaxError => e
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..11].join("\n"))
+ assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e).split("\n")[0..11].join("\n"))
/*
-Syntax error: Properties are only allowed within rules, directives, mixin includes, or other properties.
+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:
@@ -611,16 +616,16 @@
def test_css_import
assert_equal("@import url(./fonts.css);\n", render("@import \"./fonts.css\""))
end
def test_http_import
- assert_equal("@import url(http://fonts.googleapis.com/css?family=Droid+Sans);\n",
+ assert_equal("@import \"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",
+ assert_equal("@import \"//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))
@@ -700,16 +705,16 @@
end
def test_import_in_rule
assert_equal(<<CSS, render(<<SASS, :load_paths => [File.dirname(__FILE__) + '/templates/']))
.foo #foo {
- background-color: #bbaaff; }
+ background-color: #baf; }
.bar {
a: b; }
.bar #foo {
- background-color: #bbaaff; }
+ background-color: #baf; }
CSS
.foo
@import partial
.bar
@@ -1024,11 +1029,10 @@
def test_debug_info_in_keyframes
assert_equal(<<CSS, render(<<SASS, :debug_info => true))
@-webkit-keyframes warm {
from {
color: black; }
-
to {
color: red; } }
CSS
@-webkit-keyframes warm
from
@@ -1128,31 +1132,37 @@
bang: $c
SASS
end
def test_default_values_for_mixin_arguments
- assert_equal("white {\n color: white; }\n\nblack {\n color: black; }\n", render(<<SASS))
+ assert_equal(<<CSS, render(<<SASS))
+white {
+ color: #FFF; }
+
+black {
+ color: #000; }
+CSS
=foo($a: #FFF)
:color $a
white
+foo
black
+foo(#000)
SASS
assert_equal(<<CSS, render(<<SASS))
one {
- color: white;
+ color: #fff;
padding: 1px;
margin: 4px; }
two {
- color: white;
+ color: #fff;
padding: 2px;
margin: 5px; }
three {
- color: white;
+ color: #fff;
padding: 2px;
margin: 3px; }
CSS
$a: 5px
=foo($a, $b: 1px, $c: 3px + $b)
@@ -1166,21 +1176,21 @@
three
+foo(#fff, 2px, 3px)
SASS
assert_equal(<<CSS, render(<<SASS))
one {
- color: white;
+ color: #fff;
padding: 1px;
margin: 4px; }
two {
- color: white;
+ color: #fff;
padding: 2px;
margin: 5px; }
three {
- color: white;
+ color: #fff;
padding: 2px;
margin: 3px; }
CSS
$a: 5px
=foo($a, $b: 1px, $c: null)
@@ -1381,11 +1391,11 @@
a: 5; }
CSS
$variable: 0
bar
$local: 10
- -no-op: set-a-variable(variable, 5)
+ -no-op: set-a-global-variable(variable, 5)
a: $variable
SASS
end
def test_user_defined_function_cannot_read_local_variable
@@ -1615,35 +1625,10 @@
$a: 2
c: $a
SASS
end
- def test_variable_scope
- silence_warnings {assert_equal(<<CSS, render(<<SASS))}
-a {
- b-1: c;
- b-2: c;
- d: 12; }
-
-b {
- d: 17; }
-CSS
-$i: 12
-a
- @for $i from 1 through 2
- b-\#{$i}: c
- d: $i
-
-=foo
- $i: 17
-
-b
- +foo
- d: $i
-SASS
- end
-
def test_hyphen_underscore_insensitive_variables
assert_equal(<<CSS, render(<<SASS))
d {
e: 13;
f: foobar; }
@@ -1682,11 +1667,11 @@
b: $foo !important
SASS
end
def test_argument_error
- assert_raise(Sass::SyntaxError) { render("a\n b: hsl(1)") }
+ assert_raises(Sass::SyntaxError) { render("a\n b: hsl(1)") }
end
def test_comments_at_the_top_of_a_document
render(<<SASS)
//
@@ -2896,149 +2881,10 @@
@unknown-directive
SASS
end
- # Encodings
-
- unless Sass::Util.ruby1_8?
- def test_encoding_error
- render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
- assert(false, "Expected exception")
- rescue Sass::SyntaxError => e
- assert_equal(3, e.sass_line)
- assert_equal('Invalid UTF-8 character "\xFE"', e.message)
- end
-
- def test_ascii_incompatible_encoding_error
- template = "foo\nbar\nb_z".encode("utf-16le")
- template[9] = "\xFE".force_encoding("utf-16le")
- render(template)
- assert(false, "Expected exception")
- rescue Sass::SyntaxError => e
- assert_equal(3, e.sass_line)
- assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
- end
-
- def test_same_charset_as_encoding
- assert_renders_encoded(<<CSS, <<SASS)
-@charset "UTF-8";
-fóó {
- a: b; }
-CSS
-@charset "utf-8"
-fóó
- a: b
-SASS
- end
-
- def test_different_charset_than_encoding
- assert_renders_encoded(<<CSS.force_encoding("IBM866"), <<SASS)
-@charset "IBM866";
-fóó {
- a: b; }
-CSS
-@charset "ibm866"
-fóó
- a: b
-SASS
- end
-
- def test_different_encoding_than_system
- assert_renders_encoded(<<CSS.encode("IBM866"), <<SASS.encode("IBM866"))
-@charset "IBM866";
-тАЬ {
- a: b; }
-CSS
-тАЬ
- a: b
-SASS
- end
-
- def test_multibyte_charset
- assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("UTF-8"))
-@charset "UTF-16LE";
-fóó {
- a: b; }
-CSS
-@charset "utf-16le"
-fóó
- a: b
-SASS
- end
-
- def test_multibyte_charset_without_endian_specifier
- assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("UTF-8"))
-@charset "UTF-32BE";
-fóó {
- a: b; }
-CSS
-@charset "utf-32"
-fóó
- a: b
-SASS
- end
-
- def test_utf8_bom
- assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
-@charset "UTF-8";
-fóó {
- a: b; }
-CSS
-\uFEFFfóó
- a: b
-SASS
- end
-
- def test_utf16le_bom
- assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("BINARY"))
-@charset "UTF-16LE";
-fóó {
- a: b; }
-CSS
-\uFEFFfóó
- a: b
-SASS
- end
-
- def test_utf32be_bom
- assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("BINARY"))
-@charset "UTF-32BE";
-fóó {
- a: b; }
-CSS
-\uFEFFfóó
- a: b
-SASS
- end
-
- # Encoding Regression Test
-
- def test_multibyte_prop_name
- assert_equal(<<CSS, render(<<SASS))
-@charset "UTF-8";
-#bar {
- cölor: blue; }
-CSS
-#bar
- cölor: blue
-SASS
- end
-
- def test_multibyte_and_interpolation
- assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))
-#bar {
- background: a 0%; }
-CSS
-#bar {
- //
- background: \#{a} 0%;
-}
-SCSS
- end
- end
-
def test_original_filename_set
importer = MockImporter.new
importer.add_import("imported", "div{color:red}")
original_filename = filename_for_test
@@ -3285,10 +3131,17 @@
assert_warning(<<END) {render("$map: (a: 1, b: 2); @debug $map", :syntax => :scss)}
test_debug_inspects_sass_objects_inline.scss:1 DEBUG: (a: 1, b: 2)
END
end
+ def test_error_throws_sass_objects
+ assert_raise_message(Sass::SyntaxError, "(a: 1, b: 2)") {render("@error (a: 1, b: 2)")}
+ assert_raise_message(Sass::SyntaxError, "(a: 1, b: 2)") do
+ render("$map: (a: 1, b: 2); @error $map", :syntax => :scss)
+ end
+ end
+
def test_default_arg_before_splat
assert_equal <<CSS, render(<<SASS, :syntax => :scss)
.foo-positional {
a: 1;
b: 2;
@@ -3310,9 +3163,93 @@
@include foo(1, 2, 3, 4);
}
.foo-keywords {
@include foo($c: c, $d: d);
}
+SASS
+ end
+
+ def test_keyframes
+ assert_equal <<CSS, render(<<SASS)
+@keyframes identifier {
+ 0% {
+ top: 0;
+ left: 0; }
+ 30% {
+ top: 50px; }
+ 68%, 72% {
+ left: 50px; }
+ 100% {
+ top: 100px;
+ left: 100%; } }
+CSS
+@keyframes identifier
+ 0%
+ top: 0
+ left: 0
+ \#{"30%"}
+ top: 50px
+ 68%, 72%
+ left: 50px
+ 100%
+ top: 100px
+ left: 100%
+SASS
+ end
+
+ def test_prefixed_keyframes
+ assert_equal <<CSS, render(<<SASS)
+@-moz-keyframes identifier {
+ 0% {
+ top: 0;
+ left: 0; }
+ 30% {
+ top: 50px; }
+ 68%, 72% {
+ left: 50px; }
+ 100% {
+ top: 100px;
+ left: 100%; } }
+CSS
+@-moz-keyframes identifier
+ 0%
+ top: 0
+ left: 0
+ \#{"30%"}
+ top: 50px
+ 68%, 72%
+ left: 50px
+ 100%
+ top: 100px
+ left: 100%
+SASS
+ end
+
+ def test_uppercase_keyframes
+ assert_equal <<CSS, render(<<SASS)
+@KEYFRAMES identifier {
+ 0% {
+ top: 0;
+ left: 0; }
+ 30% {
+ top: 50px; }
+ 68%, 72% {
+ left: 50px; }
+ 100% {
+ top: 100px;
+ left: 100%; } }
+CSS
+@KEYFRAMES identifier
+ 0%
+ top: 0
+ left: 0
+ \#{"30%"}
+ top: 50px
+ 68%, 72%
+ left: 50px
+ 100%
+ top: 100px
+ left: 100%
SASS
end
private