test/sass/engine_test.rb in sass-3.4.25 vs test/sass/engine_test.rb in sass-3.5.0.pre.rc.1
- old
+ new
@@ -286,14 +286,14 @@
end
def test_exception_line
to_render = <<SASS
rule
- prop: val
+ :prop val
// comment!
- broken:
+ :broken
SASS
begin
Sass::Engine.new(to_render).render
rescue Sass::SyntaxError => err
assert_equal(5, err.sass_line)
@@ -303,14 +303,14 @@
end
def test_exception_location
to_render = <<SASS
rule
- prop: val
+ :prop val
// comment!
- broken:
+ :broken
SASS
begin
Sass::Engine.new(to_render, :filename => FAKE_FILE_NAME, :line => (__LINE__-7)).render
rescue Sass::SyntaxError => err
assert_equal(FAKE_FILE_NAME, err.sass_filename)
@@ -747,26 +747,26 @@
assert_equal("foo {\n bar: /baz/boom; }\n", render(%Q{foo\n bar: /baz/boom}))
end
def test_basic_multiline_selector
assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
- render("#foo #bar,\n#baz #boom\n foo: bar"))
+ render("#foo #bar,\n#baz #boom\n :foo bar"))
assert_equal("#foo #bar,\n#foo #baz {\n foo: bar; }\n",
- render("#foo\n #bar,\n #baz\n foo: bar"))
+ render("#foo\n #bar,\n #baz\n :foo bar"))
assert_equal("#foo,\n#bar {\n foo: bar; }\n #foo #baz,\n #bar #baz {\n foo: bar; }\n",
- render("#foo,\n#bar\n foo: bar\n #baz\n foo: bar"))
+ render("#foo,\n#bar\n :foo bar\n #baz\n :foo bar"))
assert_equal("#foo #bar, #baz #boom { foo: bar; }\n",
- render("#foo #bar,\n#baz #boom\n foo: bar", :style => :compact))
+ render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compact))
assert_equal("#foo #bar,#baz #boom{foo:bar}\n",
- render("#foo #bar,\n#baz #boom\n foo: bar", :style => :compressed))
+ render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compressed))
assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
- render("#foo #bar,,\n,#baz #boom,\n foo: bar"))
+ render("#foo #bar,,\n,#baz #boom,\n :foo bar"))
assert_equal("#bip #bop {\n foo: bar; }\n",
- render("#bip #bop,, ,\n foo: bar"))
+ render("#bip #bop,, ,\n :foo bar"))
end
def test_complex_multiline_selector
renders_correctly "multiline"
end
@@ -781,11 +781,11 @@
else
assert(false, "SyntaxError not raised for :property_syntax => :old")
end
begin
- silence_warnings {render("a\n :b c", :property_syntax => :new)}
+ render("a\n :b c", :property_syntax => :new)
assert_equal(2, e.sass_line)
rescue Sass::SyntaxError => e
assert_equal("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.",
e.message)
else
@@ -804,57 +804,57 @@
end
def test_directive
assert_equal("@a b;\n", render("@a b"))
- assert_equal("@a {\n b: c; }\n", render("@a\n b: c"))
- assert_equal("@a { b: c; }\n", render("@a\n b: c", :style => :compact))
- assert_equal("@a {\n b: c;\n}\n", render("@a\n b: c", :style => :expanded))
- assert_equal("@a{b:c}\n", render("@a\n b: c", :style => :compressed))
+ assert_equal("@a {\n b: c; }\n", render("@a\n :b c"))
+ assert_equal("@a { b: c; }\n", render("@a\n :b c", :style => :compact))
+ assert_equal("@a {\n b: c;\n}\n", render("@a\n :b c", :style => :expanded))
+ assert_equal("@a{b:c}\n", render("@a\n :b c", :style => :compressed))
assert_equal("@a {\n b: c;\n d: e; }\n",
- render("@a\n b: c\n d: e"))
+ render("@a\n :b c\n :d e"))
assert_equal("@a { b: c; d: e; }\n",
- render("@a\n b: c\n d: e", :style => :compact))
+ render("@a\n :b c\n :d e", :style => :compact))
assert_equal("@a {\n b: c;\n d: e;\n}\n",
- render("@a\n b: c\n d: e", :style => :expanded))
+ render("@a\n :b c\n :d e", :style => :expanded))
assert_equal("@a{b:c;d:e}\n",
- render("@a\n b: c\n d: e", :style => :compressed))
+ render("@a\n :b c\n :d e", :style => :compressed))
assert_equal("@a {\n #b {\n c: d; } }\n",
- render("@a\n #b\n c: d"))
+ render("@a\n #b\n :c d"))
assert_equal("@a { #b { c: d; } }\n",
- render("@a\n #b\n c: d", :style => :compact))
+ render("@a\n #b\n :c d", :style => :compact))
assert_equal("@a {\n #b {\n c: d;\n }\n}\n",
- render("@a\n #b\n c: d", :style => :expanded))
+ render("@a\n #b\n :c d", :style => :expanded))
assert_equal("@a{#b{c:d}}\n",
- render("@a\n #b\n c: d", :style => :compressed))
+ render("@a\n #b\n :c d", :style => :compressed))
assert_equal("@a {\n #b {\n a: b; }\n #b #c {\n d: e; } }\n",
- render("@a\n #b\n a: b\n #c\n d: e"))
+ render("@a\n #b\n :a b\n #c\n :d e"))
assert_equal("@a { #b { a: b; }\n #b #c { d: e; } }\n",
- render("@a\n #b\n a: b\n #c\n d: e", :style => :compact))
+ render("@a\n #b\n :a b\n #c\n :d e", :style => :compact))
assert_equal("@a {\n #b {\n a: b;\n }\n #b #c {\n d: e;\n }\n}\n",
- render("@a\n #b\n a: b\n #c\n d: e", :style => :expanded))
+ render("@a\n #b\n :a b\n #c\n :d e", :style => :expanded))
assert_equal("@a{#b{a:b}#b #c{d:e}}\n",
- render("@a\n #b\n a: b\n #c\n d: e", :style => :compressed))
+ render("@a\n #b\n :a b\n #c\n :d e", :style => :compressed))
assert_equal("@a {\n #foo,\n #bar {\n b: c; } }\n",
- render("@a\n #foo, \n #bar\n b: c"))
+ render("@a\n #foo, \n #bar\n :b c"))
assert_equal("@a { #foo, #bar { b: c; } }\n",
- render("@a\n #foo, \n #bar\n b: c", :style => :compact))
+ render("@a\n #foo, \n #bar\n :b c", :style => :compact))
assert_equal("@a {\n #foo,\n #bar {\n b: c;\n }\n}\n",
- render("@a\n #foo, \n #bar\n b: c", :style => :expanded))
+ render("@a\n #foo, \n #bar\n :b c", :style => :expanded))
assert_equal("@a{#foo,#bar{b:c}}\n",
- render("@a\n #foo, \n #bar\n b: c", :style => :compressed))
+ render("@a\n #foo, \n #bar\n :b c", :style => :compressed))
to_render = <<END
@a
- b: c
+ :b c
#d
- e: f
- g: h
+ :e f
+ :g h
END
rendered = <<END
@a { b: c;
#d { e: f; }
g: h; }
@@ -1139,11 +1139,11 @@
black {
color: #000; }
CSS
=foo($a: #FFF)
- color: $a
+ :color $a
white
+foo
black
+foo(#000)
SASS
@@ -1163,13 +1163,13 @@
padding: 2px;
margin: 3px; }
CSS
$a: 5px
=foo($a, $b: 1px, $c: 3px + $b)
- color: $a
- padding: $b
- margin: $c
+ :color $a
+ :padding $b
+ :margin $c
one
+foo(#fff)
two
+foo(#fff, 2px)
three
@@ -2596,33 +2596,33 @@
assert_equal(<<RESULT, render(<<SOURCE))
.box {
border-style: solid; }
RESULT
.box
- border:
- //color: black
- style: solid
+ :border
+ //:color black
+ :style solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE))
.box {
- /* color: black */
+ /* :color black */
border-style: solid; }
RESULT
.box
- border:
- /* color: black
- style: solid
+ :border
+ /* :color black
+ :style solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
.box{border-style:solid}
RESULT
.box
- border:
- /*color: black
- style: solid
+ :border
+ /*:color black
+ :style solid
SOURCE
end
def test_compressed_comment_beneath_directive
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
@@ -2698,19 +2698,10 @@
a
b: option("style")
SASS
end
- def test_mixin_no_arg_error
- assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "($bar,": expected variable (e.g. $foo), was ")"') do
- render(<<SASS)
-=foo($bar,)
- bip: bap
-SASS
- end
- end
-
def test_import_with_commas_in_url
assert_equal <<CSS, render(<<SASS)
@import url(foo.css?bar,baz);
CSS
@import url(foo.css?bar,baz)
@@ -3389,19 +3380,77 @@
.classname[a="1, 2, 3"], .another[b="4, 5, 6"]
color: red
SASS
end
+ def test_trailing_commas_in_arglists
+ assert_equal(<<CSS, render(<<SASS, :style => :nested))
+.includes {
+ one-positional-arg: positional 1 a;
+ two-positional-args: positional 2 a b;
+ one-keyword-arg: keyword 1 z;
+ two-keyword-args: keyword 2 y z;
+ mixed-args: mixed 2 y z; }
+
+.calls {
+ one-positional-arg: positional 1 a;
+ two-positional-args: positional 2 a b;
+ one-keyword-arg: keyword 1 z;
+ two-keyword-args: keyword 2 y z;
+ mixed-args: mixed 2 y z; }
+CSS
+=one-positional-arg($a,)
+ one-positional-arg: positional 1 $a
+
+=two-positional-args($a, $b,)
+ two-positional-args: positional 2 $a $b
+
+=one-keyword-arg($a: a,)
+ one-keyword-arg: keyword 1 $a
+
+=two-keyword-args($a: a, $b: b,)
+ two-keyword-args: keyword 2 $a $b
+
+=mixed-args($a, $b: b,)
+ mixed-args: mixed 2 $a $b
+
+@function one-positional-arg($a)
+ @return positional 1 $a
+
+@function two-positional-args($a, $b)
+ @return positional 2 $a $b
+
+@function one-keyword-arg($a: a)
+ @return keyword 1 $a
+
+@function two-keyword-args($a: a, $b: b)
+ @return keyword 2 $a $b
+
+@function mixed-args($a, $b: b)
+ @return mixed 2 $a $b
+
+
+.includes
+ +one-positional-arg(a,)
+ +two-positional-args(a, b,)
+ +one-keyword-arg($a: z,)
+ +two-keyword-args($a: y, $b: z,)
+ +mixed-args(y, $b: z,)
+
+
+.calls
+ one-positional-arg: one-positional-arg(a)
+ two-positional-args: two-positional-args(a, b)
+ one-keyword-arg: one-keyword-arg($a: z)
+ two-keyword-args: two-keyword-args($a: y, $b: z)
+ mixed-args: mixed-args(y, $b: z)
+SASS
+ end
+
private
def assert_hash_has(hash, expected)
- expected.each do |k, v|
- if v.nil?
- assert_nil(hash[k])
- else
- assert_equal(v, hash[k])
- end
- end
+ expected.each {|k, v| assert_equal(v, hash[k])}
end
def assert_renders_encoded(css, sass)
result = render(sass)
assert_equal css.encoding, result.encoding