sass 3.1.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.yardopts +11 -0
  2. data/CONTRIBUTING +3 -0
  3. data/EDGE_GEM_VERSION +1 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +201 -0
  6. data/REVISION +1 -0
  7. data/Rakefile +353 -0
  8. data/VERSION +1 -0
  9. data/VERSION_NAME +1 -0
  10. data/bin/css2sass +13 -0
  11. data/bin/sass +8 -0
  12. data/bin/sass-convert +7 -0
  13. data/extra/update_watch.rb +13 -0
  14. data/init.rb +18 -0
  15. data/lib/sass.rb +71 -0
  16. data/lib/sass/cache_store.rb +208 -0
  17. data/lib/sass/callbacks.rb +66 -0
  18. data/lib/sass/css.rb +294 -0
  19. data/lib/sass/engine.rb +792 -0
  20. data/lib/sass/environment.rb +143 -0
  21. data/lib/sass/error.rb +201 -0
  22. data/lib/sass/exec.rb +619 -0
  23. data/lib/sass/importers.rb +22 -0
  24. data/lib/sass/importers/base.rb +138 -0
  25. data/lib/sass/importers/filesystem.rb +121 -0
  26. data/lib/sass/less.rb +363 -0
  27. data/lib/sass/plugin.rb +126 -0
  28. data/lib/sass/plugin/compiler.rb +346 -0
  29. data/lib/sass/plugin/configuration.rb +123 -0
  30. data/lib/sass/plugin/generic.rb +15 -0
  31. data/lib/sass/plugin/merb.rb +48 -0
  32. data/lib/sass/plugin/rack.rb +47 -0
  33. data/lib/sass/plugin/rails.rb +41 -0
  34. data/lib/sass/plugin/staleness_checker.rb +145 -0
  35. data/lib/sass/railtie.rb +8 -0
  36. data/lib/sass/repl.rb +58 -0
  37. data/lib/sass/root.rb +7 -0
  38. data/lib/sass/script.rb +63 -0
  39. data/lib/sass/script/bool.rb +18 -0
  40. data/lib/sass/script/color.rb +490 -0
  41. data/lib/sass/script/css_lexer.rb +29 -0
  42. data/lib/sass/script/css_parser.rb +31 -0
  43. data/lib/sass/script/funcall.rb +78 -0
  44. data/lib/sass/script/functions.rb +852 -0
  45. data/lib/sass/script/interpolation.rb +70 -0
  46. data/lib/sass/script/lexer.rb +337 -0
  47. data/lib/sass/script/literal.rb +236 -0
  48. data/lib/sass/script/node.rb +101 -0
  49. data/lib/sass/script/number.rb +420 -0
  50. data/lib/sass/script/operation.rb +92 -0
  51. data/lib/sass/script/parser.rb +392 -0
  52. data/lib/sass/script/string.rb +67 -0
  53. data/lib/sass/script/string_interpolation.rb +93 -0
  54. data/lib/sass/script/unary_operation.rb +57 -0
  55. data/lib/sass/script/variable.rb +48 -0
  56. data/lib/sass/scss.rb +17 -0
  57. data/lib/sass/scss/css_parser.rb +51 -0
  58. data/lib/sass/scss/parser.rb +838 -0
  59. data/lib/sass/scss/rx.rb +126 -0
  60. data/lib/sass/scss/sass_parser.rb +11 -0
  61. data/lib/sass/scss/script_lexer.rb +15 -0
  62. data/lib/sass/scss/script_parser.rb +25 -0
  63. data/lib/sass/scss/static_parser.rb +40 -0
  64. data/lib/sass/selector.rb +361 -0
  65. data/lib/sass/selector/abstract_sequence.rb +62 -0
  66. data/lib/sass/selector/comma_sequence.rb +82 -0
  67. data/lib/sass/selector/sequence.rb +236 -0
  68. data/lib/sass/selector/simple.rb +113 -0
  69. data/lib/sass/selector/simple_sequence.rb +135 -0
  70. data/lib/sass/shared.rb +78 -0
  71. data/lib/sass/tree/comment_node.rb +128 -0
  72. data/lib/sass/tree/debug_node.rb +36 -0
  73. data/lib/sass/tree/directive_node.rb +75 -0
  74. data/lib/sass/tree/extend_node.rb +65 -0
  75. data/lib/sass/tree/for_node.rb +67 -0
  76. data/lib/sass/tree/if_node.rb +81 -0
  77. data/lib/sass/tree/import_node.rb +124 -0
  78. data/lib/sass/tree/mixin_def_node.rb +60 -0
  79. data/lib/sass/tree/mixin_node.rb +123 -0
  80. data/lib/sass/tree/node.rb +490 -0
  81. data/lib/sass/tree/prop_node.rb +220 -0
  82. data/lib/sass/tree/root_node.rb +125 -0
  83. data/lib/sass/tree/rule_node.rb +273 -0
  84. data/lib/sass/tree/variable_node.rb +39 -0
  85. data/lib/sass/tree/warn_node.rb +42 -0
  86. data/lib/sass/tree/while_node.rb +48 -0
  87. data/lib/sass/util.rb +687 -0
  88. data/lib/sass/util/subset_map.rb +101 -0
  89. data/lib/sass/version.rb +109 -0
  90. data/rails/init.rb +1 -0
  91. data/test/sass/cache_test.rb +74 -0
  92. data/test/sass/callbacks_test.rb +61 -0
  93. data/test/sass/conversion_test.rb +1210 -0
  94. data/test/sass/css2sass_test.rb +364 -0
  95. data/test/sass/data/hsl-rgb.txt +319 -0
  96. data/test/sass/engine_test.rb +2273 -0
  97. data/test/sass/extend_test.rb +1348 -0
  98. data/test/sass/functions_test.rb +565 -0
  99. data/test/sass/importer_test.rb +104 -0
  100. data/test/sass/less_conversion_test.rb +632 -0
  101. data/test/sass/mock_importer.rb +49 -0
  102. data/test/sass/more_results/more1.css +9 -0
  103. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  104. data/test/sass/more_results/more_import.css +29 -0
  105. data/test/sass/more_templates/_more_partial.sass +2 -0
  106. data/test/sass/more_templates/more1.sass +23 -0
  107. data/test/sass/more_templates/more_import.sass +11 -0
  108. data/test/sass/plugin_test.rb +430 -0
  109. data/test/sass/results/alt.css +4 -0
  110. data/test/sass/results/basic.css +9 -0
  111. data/test/sass/results/compact.css +5 -0
  112. data/test/sass/results/complex.css +86 -0
  113. data/test/sass/results/compressed.css +1 -0
  114. data/test/sass/results/expanded.css +19 -0
  115. data/test/sass/results/import.css +31 -0
  116. data/test/sass/results/line_numbers.css +49 -0
  117. data/test/sass/results/mixins.css +95 -0
  118. data/test/sass/results/multiline.css +24 -0
  119. data/test/sass/results/nested.css +22 -0
  120. data/test/sass/results/options.css +1 -0
  121. data/test/sass/results/parent_ref.css +13 -0
  122. data/test/sass/results/script.css +16 -0
  123. data/test/sass/results/scss_import.css +31 -0
  124. data/test/sass/results/scss_importee.css +2 -0
  125. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  126. data/test/sass/results/subdir/subdir.css +3 -0
  127. data/test/sass/results/units.css +11 -0
  128. data/test/sass/results/warn.css +0 -0
  129. data/test/sass/results/warn_imported.css +0 -0
  130. data/test/sass/script_conversion_test.rb +254 -0
  131. data/test/sass/script_test.rb +459 -0
  132. data/test/sass/scss/css_test.rb +897 -0
  133. data/test/sass/scss/rx_test.rb +156 -0
  134. data/test/sass/scss/scss_test.rb +1088 -0
  135. data/test/sass/scss/test_helper.rb +37 -0
  136. data/test/sass/templates/_partial.sass +2 -0
  137. data/test/sass/templates/alt.sass +16 -0
  138. data/test/sass/templates/basic.sass +23 -0
  139. data/test/sass/templates/bork1.sass +2 -0
  140. data/test/sass/templates/bork2.sass +2 -0
  141. data/test/sass/templates/bork3.sass +2 -0
  142. data/test/sass/templates/bork4.sass +2 -0
  143. data/test/sass/templates/compact.sass +17 -0
  144. data/test/sass/templates/complex.sass +305 -0
  145. data/test/sass/templates/compressed.sass +15 -0
  146. data/test/sass/templates/expanded.sass +17 -0
  147. data/test/sass/templates/import.sass +12 -0
  148. data/test/sass/templates/importee.less +2 -0
  149. data/test/sass/templates/importee.sass +19 -0
  150. data/test/sass/templates/line_numbers.sass +13 -0
  151. data/test/sass/templates/mixin_bork.sass +5 -0
  152. data/test/sass/templates/mixins.sass +76 -0
  153. data/test/sass/templates/multiline.sass +20 -0
  154. data/test/sass/templates/nested.sass +25 -0
  155. data/test/sass/templates/nested_bork1.sass +2 -0
  156. data/test/sass/templates/nested_bork2.sass +2 -0
  157. data/test/sass/templates/nested_bork3.sass +2 -0
  158. data/test/sass/templates/nested_bork4.sass +2 -0
  159. data/test/sass/templates/nested_mixin_bork.sass +6 -0
  160. data/test/sass/templates/options.sass +2 -0
  161. data/test/sass/templates/parent_ref.sass +25 -0
  162. data/test/sass/templates/script.sass +101 -0
  163. data/test/sass/templates/scss_import.scss +11 -0
  164. data/test/sass/templates/scss_importee.scss +1 -0
  165. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  166. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  167. data/test/sass/templates/subdir/subdir.sass +6 -0
  168. data/test/sass/templates/units.sass +11 -0
  169. data/test/sass/templates/warn.sass +3 -0
  170. data/test/sass/templates/warn_imported.sass +4 -0
  171. data/test/sass/test_helper.rb +8 -0
  172. data/test/sass/util/subset_map_test.rb +91 -0
  173. data/test/sass/util_test.rb +275 -0
  174. data/test/test_helper.rb +64 -0
  175. data/vendor/fssm/LICENSE +20 -0
  176. data/vendor/fssm/README.markdown +55 -0
  177. data/vendor/fssm/Rakefile +59 -0
  178. data/vendor/fssm/VERSION.yml +5 -0
  179. data/vendor/fssm/example.rb +9 -0
  180. data/vendor/fssm/fssm.gemspec +77 -0
  181. data/vendor/fssm/lib/fssm.rb +33 -0
  182. data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
  183. data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
  184. data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
  185. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
  186. data/vendor/fssm/lib/fssm/monitor.rb +26 -0
  187. data/vendor/fssm/lib/fssm/path.rb +91 -0
  188. data/vendor/fssm/lib/fssm/pathname.rb +502 -0
  189. data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
  190. data/vendor/fssm/lib/fssm/state/file.rb +24 -0
  191. data/vendor/fssm/lib/fssm/support.rb +63 -0
  192. data/vendor/fssm/lib/fssm/tree.rb +176 -0
  193. data/vendor/fssm/profile/prof-cache.rb +40 -0
  194. data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
  195. data/vendor/fssm/profile/prof-pathname.rb +68 -0
  196. data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
  197. data/vendor/fssm/profile/prof.html +2379 -0
  198. data/vendor/fssm/spec/path_spec.rb +75 -0
  199. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  200. data/vendor/fssm/spec/root/file.css +0 -0
  201. data/vendor/fssm/spec/root/file.rb +0 -0
  202. data/vendor/fssm/spec/root/file.yml +0 -0
  203. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  204. data/vendor/fssm/spec/spec_helper.rb +14 -0
  205. metadata +297 -0
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require File.dirname(__FILE__) + '/../../test_helper'
4
+ require 'sass/engine'
5
+
6
+ class ScssRxTest < Test::Unit::TestCase
7
+ include Sass::SCSS::RX
8
+
9
+ def test_identifiers
10
+ assert_match IDENT, "foo"
11
+ assert_match IDENT, "\xC3\xBFoo" # Initial char can be nonascii
12
+ assert_match IDENT, "\\123abcoo" # Initial char can be unicode escape
13
+ assert_match IDENT, "\\f oo" # Unicode escapes can be followed by whitespace
14
+ assert_match IDENT, "\\fa\too"
15
+ assert_match IDENT, "\\ff2\roo"
16
+ assert_match IDENT, "\\f13a\foo"
17
+ assert_match IDENT, "\\f13abcoo"
18
+ assert_match IDENT, "\\ oo" # Initial char can be a plain escape as well
19
+ assert_match IDENT, "\\~oo"
20
+ assert_match IDENT, "\\\\oo"
21
+ assert_match IDENT, "\\{oo"
22
+ assert_match IDENT, "\\\xC3\xBFoo"
23
+ assert_match IDENT, "-foo" # Can put a - before anything
24
+ assert_match IDENT, "-\xC3\xBFoo"
25
+ assert_match IDENT, "-\\f oo"
26
+ assert_match IDENT, "_foo" # Can put a _ before anything
27
+ assert_match IDENT, "_\xC3\xBFoo"
28
+ assert_match IDENT, "_\\f oo"
29
+
30
+ assert_match IDENT, "foo-bar"
31
+ assert_match IDENT, "f012-23"
32
+ assert_match IDENT, "foo_-_bar"
33
+ assert_match IDENT, "f012_23"
34
+
35
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/escapes-003.xht
36
+ assert_match IDENT, "c\\lass"
37
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/escapes-004.xht
38
+ assert_match IDENT, "c\\00006Cas\\000073"
39
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/ident-001.xht
40
+ assert_match IDENT, "IdE6n-3t0_6"
41
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/ident-006.xht
42
+ assert_match IDENT, "\\6000ident"
43
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/ident-007.xht
44
+ assert_match IDENT, "iden\\6000t\\6000"
45
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/ident-013.xht
46
+ assert_match IDENT, "\\-ident"
47
+ end
48
+
49
+ def test_underscores_in_identifiers
50
+ assert_match IDENT, "foo_bar"
51
+ assert_match IDENT, "_\xC3\xBFfoo"
52
+ assert_match IDENT, "__foo"
53
+ assert_match IDENT, "_1foo"
54
+ assert_match IDENT, "-_foo"
55
+ assert_match IDENT, "_-foo"
56
+ end
57
+
58
+ def test_invalid_identifiers
59
+ assert_no_match IDENT, ""
60
+ assert_no_match IDENT, "1foo"
61
+ assert_no_match IDENT, "-1foo"
62
+ assert_no_match IDENT, "--foo"
63
+ assert_no_match IDENT, "foo bar"
64
+ assert_no_match IDENT, "foo~bar"
65
+
66
+ # http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/escapes-008.xht
67
+ assert_no_match IDENT, "c\\06C ass"
68
+ assert_no_match IDENT, "back\\67\n round"
69
+ end
70
+
71
+ def test_double_quote_strings
72
+ assert_match STRING, '"foo bar"'
73
+ assert_match STRING, '"foo\\\nbar"'
74
+ assert_match STRING, "\"\\\"\""
75
+ assert_match STRING, '"\t !#$%&(-~()*+,-./0123456789~"'
76
+ end
77
+
78
+ def test_single_quote_strings
79
+ assert_match STRING, "'foo bar'"
80
+ assert_match STRING, "'foo\\\nbar'"
81
+ assert_match STRING, "'\\''"
82
+ assert_match STRING, "'\t !#\$%&(-~()*+,-./0123456789~'"
83
+ end
84
+
85
+ def test_invalid_strings
86
+ assert_no_match STRING, "\"foo\nbar\""
87
+ assert_no_match STRING, "\"foo\"bar\""
88
+ assert_no_match STRING, "'foo\nbar'"
89
+ assert_no_match STRING, "'foo'bar'"
90
+ end
91
+
92
+ def test_uri
93
+ assert_match URI, 'url("foo bar)")'
94
+ assert_match URI, "url('foo bar)')"
95
+ assert_match URI, 'url( "foo bar)" )'
96
+ assert_match URI, "url(#\\%&**+,-./0123456789~)"
97
+ end
98
+
99
+ def test_invalid_uri
100
+ assert_no_match URI, 'url(foo)bar)'
101
+ end
102
+
103
+ def test_unicode_range
104
+ assert_match UNICODERANGE, 'U+00-Ff'
105
+ assert_match UNICODERANGE, 'u+980-9FF'
106
+ assert_match UNICODERANGE, 'U+9aF??'
107
+ assert_match UNICODERANGE, 'U+??'
108
+ end
109
+
110
+ def test_escape_empty_ident
111
+ assert_equal "", Sass::SCSS::RX.escape_ident("")
112
+ end
113
+
114
+ def test_escape_just_prefix_ident
115
+ assert_equal "\\-", Sass::SCSS::RX.escape_ident("-")
116
+ assert_equal "\\_", Sass::SCSS::RX.escape_ident("_")
117
+ end
118
+
119
+ def test_escape_plain_ident
120
+ assert_equal "foo", Sass::SCSS::RX.escape_ident("foo")
121
+ assert_equal "foo-1bar", Sass::SCSS::RX.escape_ident("foo-1bar")
122
+ assert_equal "-foo-bar", Sass::SCSS::RX.escape_ident("-foo-bar")
123
+ assert_equal "f2oo_bar", Sass::SCSS::RX.escape_ident("f2oo_bar")
124
+ assert_equal "_foo_bar", Sass::SCSS::RX.escape_ident("_foo_bar")
125
+ end
126
+
127
+ def test_escape_initial_funky_ident
128
+ assert_equal "\\000035foo", Sass::SCSS::RX.escape_ident("5foo")
129
+ assert_equal "-\\000035foo", Sass::SCSS::RX.escape_ident("-5foo")
130
+ assert_equal "_\\000035foo", Sass::SCSS::RX.escape_ident("_5foo")
131
+
132
+ assert_equal "\\&foo", Sass::SCSS::RX.escape_ident("&foo")
133
+ assert_equal "-\\&foo", Sass::SCSS::RX.escape_ident("-&foo")
134
+
135
+ assert_equal "-\\ foo", Sass::SCSS::RX.escape_ident("- foo")
136
+ end
137
+
138
+ def test_escape_mid_funky_ident
139
+ assert_equal "foo\\&bar", Sass::SCSS::RX.escape_ident("foo&bar")
140
+ assert_equal "foo\\ \\ bar", Sass::SCSS::RX.escape_ident("foo bar")
141
+ assert_equal "foo\\00007fbar", Sass::SCSS::RX.escape_ident("foo\177bar")
142
+ end
143
+
144
+ private
145
+
146
+ def assert_match(rx, str)
147
+ assert_not_nil(match = rx.match(str))
148
+ assert_equal str.size, match[0].size
149
+ end
150
+
151
+ def assert_no_match(rx, str)
152
+ match = rx.match(str)
153
+ assert_not_equal str.size, match && match[0].size
154
+ end
155
+
156
+ end
@@ -0,0 +1,1088 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require File.dirname(__FILE__) + '/test_helper'
4
+
5
+ class ScssTest < Test::Unit::TestCase
6
+ include ScssTestHelper
7
+
8
+ ## One-Line Comments
9
+
10
+ def test_one_line_comments
11
+ assert_equal <<CSS, render(<<SCSS)
12
+ .foo {
13
+ baz: bang; }
14
+ CSS
15
+ .foo {// bar: baz;}
16
+ baz: bang; //}
17
+ }
18
+ SCSS
19
+ assert_equal <<CSS, render(<<SCSS)
20
+ .foo bar[val="//"] {
21
+ baz: bang; }
22
+ CSS
23
+ .foo bar[val="//"] {
24
+ baz: bang; //}
25
+ }
26
+ SCSS
27
+ end
28
+
29
+ ## Script
30
+
31
+ def test_variables
32
+ assert_equal <<CSS, render(<<SCSS)
33
+ blat {
34
+ a: foo; }
35
+ CSS
36
+ $var: foo;
37
+
38
+ blat {a: $var}
39
+ SCSS
40
+
41
+ assert_equal <<CSS, render(<<SCSS)
42
+ foo {
43
+ a: 2;
44
+ b: 6; }
45
+ CSS
46
+ foo {
47
+ $var: 2;
48
+ $another-var: 4;
49
+ a: $var;
50
+ b: $var + $another-var;}
51
+ SCSS
52
+ end
53
+
54
+ def test_unicode_variables
55
+ assert_equal <<CSS, render(<<SCSS)
56
+ blat {
57
+ a: foo; }
58
+ CSS
59
+ $vär: foo;
60
+
61
+ blat {a: $vär}
62
+ SCSS
63
+ end
64
+
65
+ def test_guard_assign
66
+ assert_equal <<CSS, render(<<SCSS)
67
+ foo {
68
+ a: 1; }
69
+ CSS
70
+ $var: 1;
71
+ $var: 2 !default;
72
+
73
+ foo {a: $var}
74
+ SCSS
75
+
76
+ assert_equal <<CSS, render(<<SCSS)
77
+ foo {
78
+ a: 2; }
79
+ CSS
80
+ $var: 2 !default;
81
+
82
+ foo {a: $var}
83
+ SCSS
84
+ end
85
+
86
+ def test_sass_script
87
+ assert_equal <<CSS, render(<<SCSS)
88
+ foo {
89
+ a: 3;
90
+ b: -1;
91
+ c: foobar;
92
+ d: 12px; }
93
+ CSS
94
+ foo {
95
+ a: 1 + 2;
96
+ b: 1 - 2;
97
+ c: foo + bar;
98
+ d: floor(12.3px); }
99
+ SCSS
100
+ end
101
+
102
+ def test_debug_directive
103
+ assert_warning "test_debug_directive_inline.scss:2 DEBUG: hello world!" do
104
+ assert_equal <<CSS, render(<<SCSS)
105
+ foo {
106
+ a: b; }
107
+
108
+ bar {
109
+ c: d; }
110
+ CSS
111
+ foo {a: b}
112
+ @debug "hello world!";
113
+ bar {c: d}
114
+ SCSS
115
+ end
116
+ end
117
+
118
+ def test_warn_directive
119
+ expected_warning = <<EXPECTATION
120
+ WARNING: this is a warning
121
+ on line 2 of test_warn_directive_inline.scss
122
+
123
+ WARNING: this is a mixin
124
+ on line 1 of test_warn_directive_inline.scss, in `foo'
125
+ from line 3 of test_warn_directive_inline.scss
126
+ EXPECTATION
127
+ assert_warning expected_warning do
128
+ assert_equal <<CSS, render(<<SCSS)
129
+ bar {
130
+ c: d; }
131
+ CSS
132
+ @mixin foo { @warn "this is a mixin";}
133
+ @warn "this is a warning";
134
+ bar {c: d; @include foo;}
135
+ SCSS
136
+ end
137
+ end
138
+
139
+ def test_for_directive
140
+ assert_equal <<CSS, render(<<SCSS)
141
+ .foo {
142
+ a: 1;
143
+ a: 2;
144
+ a: 3;
145
+ a: 4; }
146
+ CSS
147
+ .foo {
148
+ @for $var from 1 to 5 {a: $var;}
149
+ }
150
+ SCSS
151
+
152
+ assert_equal <<CSS, render(<<SCSS)
153
+ .foo {
154
+ a: 1;
155
+ a: 2;
156
+ a: 3;
157
+ a: 4;
158
+ a: 5; }
159
+ CSS
160
+ .foo {
161
+ @for $var from 1 through 5 {a: $var;}
162
+ }
163
+ SCSS
164
+ end
165
+
166
+ def test_if_directive
167
+ assert_equal <<CSS, render(<<SCSS)
168
+ foo {
169
+ a: b; }
170
+ CSS
171
+ @if "foo" == "foo" {foo {a: b}}
172
+ @if "foo" != "foo" {bar {a: b}}
173
+ SCSS
174
+
175
+ assert_equal <<CSS, render(<<SCSS)
176
+ bar {
177
+ a: b; }
178
+ CSS
179
+ @if "foo" != "foo" {foo {a: b}}
180
+ @else if "foo" == "foo" {bar {a: b}}
181
+ @else if true {baz {a: b}}
182
+ SCSS
183
+
184
+ assert_equal <<CSS, render(<<SCSS)
185
+ bar {
186
+ a: b; }
187
+ CSS
188
+ @if "foo" != "foo" {foo {a: b}}
189
+ @else {bar {a: b}}
190
+ SCSS
191
+ end
192
+
193
+ def test_comment_after_if_directive
194
+ assert_equal <<CSS, render(<<SCSS)
195
+ foo {
196
+ a: b;
197
+ /* This is a comment */
198
+ c: d; }
199
+ CSS
200
+ foo {
201
+ @if true {a: b}
202
+ /* This is a comment */
203
+ c: d }
204
+ SCSS
205
+ assert_equal <<CSS, render(<<SCSS)
206
+ foo {
207
+ a: b;
208
+ /* This is a comment */
209
+ c: d; }
210
+ CSS
211
+ foo {
212
+ @if true {a: b}
213
+ @else {x: y}
214
+ /* This is a comment */
215
+ c: d }
216
+ SCSS
217
+ end
218
+
219
+ def test_while_directive
220
+ assert_equal <<CSS, render(<<SCSS)
221
+ .foo {
222
+ a: 1;
223
+ a: 2;
224
+ a: 3;
225
+ a: 4; }
226
+ CSS
227
+ $i: 1;
228
+
229
+ .foo {
230
+ @while $i != 5 {
231
+ a: $i;
232
+ $i: $i + 1;
233
+ }
234
+ }
235
+ SCSS
236
+ end
237
+
238
+ def test_css_import_directive
239
+ assert_equal "@import url(foo.css);\n", render('@import "foo.css";')
240
+ assert_equal "@import url(foo.css);\n", render("@import 'foo.css';")
241
+ assert_equal "@import url(\"foo.css\");\n", render('@import url("foo.css");')
242
+ assert_equal "@import url('foo.css');\n", render("@import url('foo.css');")
243
+ assert_equal "@import url(foo.css);\n", render('@import url(foo.css);')
244
+ end
245
+
246
+ def test_media_import
247
+ assert_equal("@import \"./fonts.sass\" all;\n", render("@import \"./fonts.sass\" all;"))
248
+ end
249
+
250
+ def test_http_import
251
+ assert_equal("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\";\n",
252
+ render("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\";"))
253
+ end
254
+
255
+ def test_url_import
256
+ assert_equal("@import url(fonts.sass);\n", render("@import url(fonts.sass);"))
257
+ end
258
+
259
+ def test_block_comment_in_script
260
+ assert_equal <<CSS, render(<<SCSS)
261
+ foo {
262
+ a: 1bar; }
263
+ CSS
264
+ foo {a: 1 + /* flang */ bar}
265
+ SCSS
266
+ end
267
+
268
+ def test_line_comment_in_script
269
+ assert_equal <<CSS, render(<<SCSS)
270
+ foo {
271
+ a: 1blang; }
272
+ CSS
273
+ foo {a: 1 + // flang }
274
+ blang }
275
+ SCSS
276
+ end
277
+
278
+ ## Nested Rules
279
+
280
+ def test_nested_rules
281
+ assert_equal <<CSS, render(<<SCSS)
282
+ foo bar {
283
+ a: b; }
284
+ CSS
285
+ foo {bar {a: b}}
286
+ SCSS
287
+ assert_equal <<CSS, render(<<SCSS)
288
+ foo bar {
289
+ a: b; }
290
+ foo baz {
291
+ b: c; }
292
+ CSS
293
+ foo {
294
+ bar {a: b}
295
+ baz {b: c}}
296
+ SCSS
297
+ assert_equal <<CSS, render(<<SCSS)
298
+ foo bar baz {
299
+ a: b; }
300
+ foo bang bip {
301
+ a: b; }
302
+ CSS
303
+ foo {
304
+ bar {baz {a: b}}
305
+ bang {bip {a: b}}}
306
+ SCSS
307
+ end
308
+
309
+ def test_nested_rules_with_declarations
310
+ assert_equal <<CSS, render(<<SCSS)
311
+ foo {
312
+ a: b; }
313
+ foo bar {
314
+ c: d; }
315
+ CSS
316
+ foo {
317
+ a: b;
318
+ bar {c: d}}
319
+ SCSS
320
+ assert_equal <<CSS, render(<<SCSS)
321
+ foo {
322
+ a: b; }
323
+ foo bar {
324
+ c: d; }
325
+ CSS
326
+ foo {
327
+ bar {c: d}
328
+ a: b}
329
+ SCSS
330
+ assert_equal <<CSS, render(<<SCSS)
331
+ foo {
332
+ ump: nump;
333
+ grump: clump; }
334
+ foo bar {
335
+ blat: bang;
336
+ habit: rabbit; }
337
+ foo bar baz {
338
+ a: b; }
339
+ foo bar bip {
340
+ c: d; }
341
+ foo bibble bap {
342
+ e: f; }
343
+ CSS
344
+ foo {
345
+ ump: nump;
346
+ grump: clump;
347
+ bar {
348
+ blat: bang;
349
+ habit: rabbit;
350
+ baz {a: b}
351
+ bip {c: d}}
352
+ bibble {
353
+ bap {e: f}}}
354
+ SCSS
355
+ end
356
+
357
+ def test_nested_rules_with_fancy_selectors
358
+ assert_equal <<CSS, render(<<SCSS)
359
+ foo .bar {
360
+ a: b; }
361
+ foo :baz {
362
+ c: d; }
363
+ foo bang:bop {
364
+ e: f; }
365
+ CSS
366
+ foo {
367
+ .bar {a: b}
368
+ :baz {c: d}
369
+ bang:bop {e: f}}
370
+ SCSS
371
+ end
372
+
373
+ def test_almost_ambiguous_nested_rules_and_declarations
374
+ assert_equal <<CSS, render(<<SCSS)
375
+ foo {
376
+ bar: baz bang bop biddle woo look at all these elems; }
377
+ foo bar:baz:bang:bop:biddle:woo:look:at:all:these:pseudoclasses {
378
+ a: b; }
379
+ foo bar:baz bang bop biddle woo look at all these elems {
380
+ a: b; }
381
+ CSS
382
+ foo {
383
+ bar:baz:bang:bop:biddle:woo:look:at:all:these:pseudoclasses {a: b};
384
+ bar:baz bang bop biddle woo look at all these elems {a: b};
385
+ bar:baz bang bop biddle woo look at all these elems; }
386
+ SCSS
387
+ end
388
+
389
+ def test_newlines_in_selectors
390
+ assert_equal <<CSS, render(<<SCSS)
391
+ foo
392
+ bar {
393
+ a: b; }
394
+ CSS
395
+ foo
396
+ bar {a: b}
397
+ SCSS
398
+
399
+ assert_equal <<CSS, render(<<SCSS)
400
+ foo baz,
401
+ foo bang,
402
+ bar baz,
403
+ bar bang {
404
+ a: b; }
405
+ CSS
406
+ foo,
407
+ bar {
408
+ baz,
409
+ bang {a: b}}
410
+ SCSS
411
+
412
+ assert_equal <<CSS, render(<<SCSS)
413
+ foo
414
+ bar baz
415
+ bang {
416
+ a: b; }
417
+ foo
418
+ bar bip bop {
419
+ c: d; }
420
+ CSS
421
+ foo
422
+ bar {
423
+ baz
424
+ bang {a: b}
425
+
426
+ bip bop {c: d}}
427
+ SCSS
428
+
429
+ assert_equal <<CSS, render(<<SCSS)
430
+ foo bang, foo bip
431
+ bop, bar
432
+ baz bang, bar
433
+ baz bip
434
+ bop {
435
+ a: b; }
436
+ CSS
437
+ foo, bar
438
+ baz {
439
+ bang, bip
440
+ bop {a: b}}
441
+ SCSS
442
+ end
443
+
444
+ def test_parent_selectors
445
+ assert_equal <<CSS, render(<<SCSS)
446
+ foo:hover {
447
+ a: b; }
448
+ bar foo.baz {
449
+ c: d; }
450
+ CSS
451
+ foo {
452
+ &:hover {a: b}
453
+ bar &.baz {c: d}}
454
+ SCSS
455
+ end
456
+
457
+ ## Namespace Properties
458
+
459
+ def test_namespace_properties
460
+ assert_equal <<CSS, render(<<SCSS)
461
+ foo {
462
+ bar: baz;
463
+ bang-bip: 1px;
464
+ bang-bop: bar; }
465
+ CSS
466
+ foo {
467
+ bar: baz;
468
+ bang: {
469
+ bip: 1px;
470
+ bop: bar;}}
471
+ SCSS
472
+ end
473
+
474
+ def test_several_namespace_properties
475
+ assert_equal <<CSS, render(<<SCSS)
476
+ foo {
477
+ bar: baz;
478
+ bang-bip: 1px;
479
+ bang-bop: bar;
480
+ buzz-fram: "foo";
481
+ buzz-frum: moo; }
482
+ CSS
483
+ foo {
484
+ bar: baz;
485
+ bang: {
486
+ bip: 1px;
487
+ bop: bar;}
488
+ buzz: {
489
+ fram: "foo";
490
+ frum: moo;
491
+ }
492
+ }
493
+ SCSS
494
+ end
495
+
496
+ def test_nested_namespace_properties
497
+ assert_equal <<CSS, render(<<SCSS)
498
+ foo {
499
+ bar: baz;
500
+ bang-bip: 1px;
501
+ bang-bop: bar;
502
+ bang-blat-baf: bort; }
503
+ CSS
504
+ foo {
505
+ bar: baz;
506
+ bang: {
507
+ bip: 1px;
508
+ bop: bar;
509
+ blat:{baf:bort}}}
510
+ SCSS
511
+ end
512
+
513
+ def test_namespace_properties_with_value
514
+ assert_equal <<CSS, render(<<SCSS)
515
+ foo {
516
+ bar: baz;
517
+ bar-bip: bop;
518
+ bar-bing: bop; }
519
+ CSS
520
+ foo {
521
+ bar: baz {
522
+ bip: bop;
523
+ bing: bop; }}
524
+ SCSS
525
+ end
526
+
527
+ def test_namespace_properties_with_script_value
528
+ assert_equal <<CSS, render(<<SCSS)
529
+ foo {
530
+ bar: bazbang;
531
+ bar-bip: bop;
532
+ bar-bing: bop; }
533
+ CSS
534
+ foo {
535
+ bar: baz + bang {
536
+ bip: bop;
537
+ bing: bop; }}
538
+ SCSS
539
+ end
540
+
541
+ def test_no_namespace_properties_without_space
542
+ assert_equal <<CSS, render(<<SCSS)
543
+ foo bar:baz {
544
+ bip: bop; }
545
+ CSS
546
+ foo {
547
+ bar:baz {
548
+ bip: bop }}
549
+ SCSS
550
+ end
551
+
552
+ def test_no_namespace_properties_without_space_even_when_its_unambiguous
553
+ render(<<SCSS)
554
+ foo {
555
+ bar:1px {
556
+ bip: bop }}
557
+ SCSS
558
+ assert(false, "Expected syntax error")
559
+ rescue Sass::SyntaxError => e
560
+ assert_equal <<MESSAGE, e.message
561
+ Invalid CSS: a space is required between a property and its definition
562
+ when it has other properties nested beneath it.
563
+ MESSAGE
564
+ assert_equal 2, e.sass_line
565
+ end
566
+
567
+ ## Mixins
568
+
569
+ def test_basic_mixins
570
+ assert_equal <<CSS, render(<<SCSS)
571
+ .foo {
572
+ a: b; }
573
+ CSS
574
+ @mixin foo {
575
+ .foo {a: b}}
576
+
577
+ @include foo;
578
+ SCSS
579
+
580
+ assert_equal <<CSS, render(<<SCSS)
581
+ bar {
582
+ c: d; }
583
+ bar .foo {
584
+ a: b; }
585
+ CSS
586
+ @mixin foo {
587
+ .foo {a: b}}
588
+
589
+ bar {
590
+ @include foo;
591
+ c: d; }
592
+ SCSS
593
+
594
+ assert_equal <<CSS, render(<<SCSS)
595
+ bar {
596
+ a: b;
597
+ c: d; }
598
+ CSS
599
+ @mixin foo {a: b}
600
+
601
+ bar {
602
+ @include foo;
603
+ c: d; }
604
+ SCSS
605
+ end
606
+
607
+ def test_mixins_with_empty_args
608
+ assert_equal <<CSS, render(<<SCSS)
609
+ .foo {
610
+ a: b; }
611
+ CSS
612
+ @mixin foo() {a: b}
613
+
614
+ .foo {@include foo();}
615
+ SCSS
616
+
617
+ assert_equal <<CSS, render(<<SCSS)
618
+ .foo {
619
+ a: b; }
620
+ CSS
621
+ @mixin foo() {a: b}
622
+
623
+ .foo {@include foo;}
624
+ SCSS
625
+
626
+ assert_equal <<CSS, render(<<SCSS)
627
+ .foo {
628
+ a: b; }
629
+ CSS
630
+ @mixin foo {a: b}
631
+
632
+ .foo {@include foo();}
633
+ SCSS
634
+ end
635
+
636
+ def test_mixins_with_args
637
+ assert_equal <<CSS, render(<<SCSS)
638
+ .foo {
639
+ a: bar; }
640
+ CSS
641
+ @mixin foo($a) {a: $a}
642
+
643
+ .foo {@include foo(bar)}
644
+ SCSS
645
+
646
+ assert_equal <<CSS, render(<<SCSS)
647
+ .foo {
648
+ a: bar;
649
+ b: 12px; }
650
+ CSS
651
+ @mixin foo($a, $b) {
652
+ a: $a;
653
+ b: $b; }
654
+
655
+ .foo {@include foo(bar, 12px)}
656
+ SCSS
657
+ end
658
+
659
+ ## Interpolation
660
+
661
+ def test_basic_selector_interpolation
662
+ assert_equal <<CSS, render(<<SCSS)
663
+ foo 3 baz {
664
+ a: b; }
665
+ CSS
666
+ foo \#{1 + 2} baz {a: b}
667
+ SCSS
668
+ assert_equal <<CSS, render(<<SCSS)
669
+ foo.bar baz {
670
+ a: b; }
671
+ CSS
672
+ foo\#{".bar"} baz {a: b}
673
+ SCSS
674
+ assert_equal <<CSS, render(<<SCSS)
675
+ foo.bar baz {
676
+ a: b; }
677
+ CSS
678
+ \#{"foo"}.bar baz {a: b}
679
+ SCSS
680
+ end
681
+
682
+ def test_selector_only_interpolation
683
+ assert_equal <<CSS, render(<<SCSS)
684
+ foo bar {
685
+ a: b; }
686
+ CSS
687
+ \#{"foo" + " bar"} {a: b}
688
+ SCSS
689
+ end
690
+
691
+ def test_selector_interpolation_before_element_name
692
+ assert_equal <<CSS, render(<<SCSS)
693
+ foo barbaz {
694
+ a: b; }
695
+ CSS
696
+ \#{"foo" + " bar"}baz {a: b}
697
+ SCSS
698
+ end
699
+
700
+ def test_selector_interpolation_in_string
701
+ assert_equal <<CSS, render(<<SCSS)
702
+ foo[val="bar foo bar baz"] {
703
+ a: b; }
704
+ CSS
705
+ foo[val="bar \#{"foo" + " bar"} baz"] {a: b}
706
+ SCSS
707
+ end
708
+
709
+ def test_selector_interpolation_in_pseudoclass
710
+ assert_equal <<CSS, render(<<SCSS)
711
+ foo:nth-child(5n) {
712
+ a: b; }
713
+ CSS
714
+ foo:nth-child(\#{5 + "n"}) {a: b}
715
+ SCSS
716
+ end
717
+
718
+ def test_selector_interpolation_at_class_begininng
719
+ assert_equal <<CSS, render(<<SCSS)
720
+ .zzz {
721
+ a: b; }
722
+ CSS
723
+ $zzz: zzz;
724
+ .\#{$zzz} { a: b; }
725
+ SCSS
726
+ end
727
+
728
+ def test_selector_interpolation_at_id_begininng
729
+ assert_equal <<CSS, render(<<SCSS)
730
+ #zzz {
731
+ a: b; }
732
+ CSS
733
+ $zzz: zzz;
734
+ #\#{$zzz} { a: b; }
735
+ SCSS
736
+ end
737
+
738
+ def test_selector_interpolation_at_pseudo_begininng
739
+ assert_equal <<CSS, render(<<SCSS)
740
+ :zzz::zzz {
741
+ a: b; }
742
+ CSS
743
+ $zzz: zzz;
744
+ :\#{$zzz}::\#{$zzz} { a: b; }
745
+ SCSS
746
+ end
747
+
748
+ def test_selector_interpolation_at_attr_beginning
749
+ assert_equal <<CSS, render(<<SCSS)
750
+ [zzz=foo] {
751
+ a: b; }
752
+ CSS
753
+ $zzz: zzz;
754
+ [\#{$zzz}=foo] { a: b; }
755
+ SCSS
756
+ end
757
+
758
+ def test_selector_interpolation_at_dashes
759
+ assert_equal <<CSS, render(<<SCSS)
760
+ div {
761
+ -foo-a-b-foo: foo; }
762
+ CSS
763
+ $a : a;
764
+ $b : b;
765
+ div { -foo-\#{$a}-\#{$b}-foo: foo }
766
+ SCSS
767
+ end
768
+
769
+ def test_basic_prop_name_interpolation
770
+ assert_equal <<CSS, render(<<SCSS)
771
+ foo {
772
+ barbazbang: blip; }
773
+ CSS
774
+ foo {bar\#{"baz" + "bang"}: blip}
775
+ SCSS
776
+ assert_equal <<CSS, render(<<SCSS)
777
+ foo {
778
+ bar3: blip; }
779
+ CSS
780
+ foo {bar\#{1 + 2}: blip}
781
+ SCSS
782
+ end
783
+
784
+ def test_prop_name_only_interpolation
785
+ assert_equal <<CSS, render(<<SCSS)
786
+ foo {
787
+ bazbang: blip; }
788
+ CSS
789
+ foo {\#{"baz" + "bang"}: blip}
790
+ SCSS
791
+ end
792
+
793
+ ## Errors
794
+
795
+ def test_mixin_defs_only_at_toplevel
796
+ render <<SCSS
797
+ foo {
798
+ @mixin bar {a: b}}
799
+ SCSS
800
+ assert(false, "Expected syntax error")
801
+ rescue Sass::SyntaxError => e
802
+ assert_equal "Mixins may only be defined at the root of a document.", e.message
803
+ assert_equal 2, e.sass_line
804
+ end
805
+
806
+ def test_imports_only_at_toplevel
807
+ render <<SCSS
808
+ foo {
809
+ @import "foo.scss";}
810
+ SCSS
811
+ assert(false, "Expected syntax error")
812
+ rescue Sass::SyntaxError => e
813
+ assert_equal "Import directives may only be used at the root of a document.", e.message
814
+ assert_equal 2, e.sass_line
815
+ end
816
+
817
+ def test_rules_beneath_properties
818
+ render <<SCSS
819
+ foo {
820
+ bar: {
821
+ baz {
822
+ bang: bop }}}
823
+ SCSS
824
+ assert(false, "Expected syntax error")
825
+ rescue Sass::SyntaxError => e
826
+ assert_equal 'Illegal nesting: Only properties may be nested beneath properties.', e.message
827
+ assert_equal 3, e.sass_line
828
+ end
829
+
830
+ def test_uses_property_exception_with_star_hack
831
+ render <<SCSS
832
+ foo {
833
+ *bar:baz [fail]; }
834
+ SCSS
835
+ assert(false, "Expected syntax error")
836
+ rescue Sass::SyntaxError => e
837
+ assert_equal 'Invalid CSS after " *bar:baz ": expected ";", was "[fail]; }"', e.message
838
+ assert_equal 2, e.sass_line
839
+ end
840
+
841
+ def test_uses_property_exception_with_colon_hack
842
+ render <<SCSS
843
+ foo {
844
+ :bar:baz [fail]; }
845
+ SCSS
846
+ assert(false, "Expected syntax error")
847
+ rescue Sass::SyntaxError => e
848
+ assert_equal 'Invalid CSS after " :bar:baz ": expected ";", was "[fail]; }"', e.message
849
+ assert_equal 2, e.sass_line
850
+ end
851
+
852
+ def test_uses_rule_exception_with_dot_hack
853
+ render <<SCSS
854
+ foo {
855
+ .bar:baz <fail>; }
856
+ SCSS
857
+ assert(false, "Expected syntax error")
858
+ rescue Sass::SyntaxError => e
859
+ assert_equal 'Invalid CSS after " .bar:baz ": expected "{", was "<fail>; }"', e.message
860
+ assert_equal 2, e.sass_line
861
+ end
862
+
863
+ def test_uses_property_exception_with_space_after_name
864
+ render <<SCSS
865
+ foo {
866
+ bar: baz [fail]; }
867
+ SCSS
868
+ assert(false, "Expected syntax error")
869
+ rescue Sass::SyntaxError => e
870
+ assert_equal 'Invalid CSS after " bar: baz ": expected ";", was "[fail]; }"', e.message
871
+ assert_equal 2, e.sass_line
872
+ end
873
+
874
+ def test_uses_property_exception_with_non_identifier_after_name
875
+ render <<SCSS
876
+ foo {
877
+ bar:1px [fail]; }
878
+ SCSS
879
+ assert(false, "Expected syntax error")
880
+ rescue Sass::SyntaxError => e
881
+ assert_equal 'Invalid CSS after " bar:1px ": expected ";", was "[fail]; }"', e.message
882
+ assert_equal 2, e.sass_line
883
+ end
884
+
885
+ def test_uses_property_exception_when_followed_by_open_bracket
886
+ render <<SCSS
887
+ foo {
888
+ bar:{baz: .fail} }
889
+ SCSS
890
+ assert(false, "Expected syntax error")
891
+ rescue Sass::SyntaxError => e
892
+ assert_equal 'Invalid CSS after " bar:{baz: ": expected expression (e.g. 1px, bold), was ".fail} }"', e.message
893
+ assert_equal 2, e.sass_line
894
+ end
895
+
896
+ def test_script_error
897
+ render <<SCSS
898
+ foo {
899
+ bar: "baz" * * }
900
+ SCSS
901
+ assert(false, "Expected syntax error")
902
+ rescue Sass::SyntaxError => e
903
+ assert_equal 'Invalid CSS after " bar: "baz" * ": expected expression (e.g. 1px, bold), was "* }"', e.message
904
+ assert_equal 2, e.sass_line
905
+ end
906
+
907
+ def test_multiline_script_syntax_error
908
+ render <<SCSS
909
+ foo {
910
+ bar:
911
+ "baz" * * }
912
+ SCSS
913
+ assert(false, "Expected syntax error")
914
+ rescue Sass::SyntaxError => e
915
+ assert_equal 'Invalid CSS after " "baz" * ": expected expression (e.g. 1px, bold), was "* }"', e.message
916
+ assert_equal 3, e.sass_line
917
+ end
918
+
919
+ def test_multiline_script_runtime_error
920
+ render <<SCSS
921
+ foo {
922
+ bar: "baz" +
923
+ "bar" +
924
+ $bang }
925
+ SCSS
926
+ assert(false, "Expected syntax error")
927
+ rescue Sass::SyntaxError => e
928
+ assert_equal "Undefined variable: \"$bang\".", e.message
929
+ assert_equal 4, e.sass_line
930
+ end
931
+
932
+ def test_post_multiline_script_runtime_error
933
+ render <<SCSS
934
+ foo {
935
+ bar: "baz" +
936
+ "bar" +
937
+ "baz";
938
+ bip: $bop; }
939
+ SCSS
940
+ assert(false, "Expected syntax error")
941
+ rescue Sass::SyntaxError => e
942
+ assert_equal "Undefined variable: \"$bop\".", e.message
943
+ assert_equal 5, e.sass_line
944
+ end
945
+
946
+ def test_multiline_property_runtime_error
947
+ render <<SCSS
948
+ foo {
949
+ bar: baz
950
+ bar
951
+ \#{$bang} }
952
+ SCSS
953
+ assert(false, "Expected syntax error")
954
+ rescue Sass::SyntaxError => e
955
+ assert_equal "Undefined variable: \"$bang\".", e.message
956
+ assert_equal 4, e.sass_line
957
+ end
958
+
959
+ def test_post_resolution_selector_error
960
+ render "\n\nfoo \#{\") bar\"} {a: b}"
961
+ assert(false, "Expected syntax error")
962
+ rescue Sass::SyntaxError => e
963
+ assert_equal 'Invalid CSS after "foo ": expected selector, was ") bar"', e.message
964
+ assert_equal 3, e.sass_line
965
+ end
966
+
967
+ def test_parent_in_mid_selector_error
968
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
969
+ Invalid CSS after ".foo": expected "{", was "&.bar"
970
+
971
+ In Sass 3, the parent selector & can only be used where element names are valid,
972
+ since it could potentially be replaced by an element name.
973
+ MESSAGE
974
+ flim {
975
+ .foo&.bar {a: b}
976
+ }
977
+ SCSS
978
+ end
979
+
980
+ def test_parent_in_mid_selector_error
981
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
982
+ Invalid CSS after " .foo.bar": expected "{", was "& {a: b}"
983
+
984
+ In Sass 3, the parent selector & can only be used where element names are valid,
985
+ since it could potentially be replaced by an element name.
986
+ MESSAGE
987
+ flim {
988
+ .foo.bar& {a: b}
989
+ }
990
+ SCSS
991
+ end
992
+
993
+ def test_double_parent_selector_error
994
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
995
+ Invalid CSS after " &": expected "{", was "& {a: b}"
996
+
997
+ In Sass 3, the parent selector & can only be used where element names are valid,
998
+ since it could potentially be replaced by an element name.
999
+ MESSAGE
1000
+ flim {
1001
+ && {a: b}
1002
+ }
1003
+ SCSS
1004
+ end
1005
+
1006
+ def test_no_interpolation_in_media_queries
1007
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
1008
+ Invalid CSS after "...nd (min-width: ": expected expression (e.g. 1px, bold), was "\#{100}px) {"
1009
+ MESSAGE
1010
+ @media screen and (min-width: \#{100}px) {
1011
+ foo {bar: baz}
1012
+ }
1013
+ SCSS
1014
+ end
1015
+
1016
+ def test_no_interpolation_in_unrecognized_directives
1017
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
1018
+ Invalid CSS after "@foo ": expected selector or at-rule, was "\#{100} {"
1019
+ MESSAGE
1020
+ @foo \#{100} {
1021
+ foo {bar: baz}
1022
+ }
1023
+ SCSS
1024
+ end
1025
+
1026
+ # Regression
1027
+
1028
+ def test_weird_added_space
1029
+ assert_equal <<CSS, render(<<SCSS)
1030
+ foo {
1031
+ bar: -moz-bip; }
1032
+ CSS
1033
+ $value : bip;
1034
+
1035
+ foo {
1036
+ bar: -moz-\#{$value};
1037
+ }
1038
+ SCSS
1039
+ end
1040
+
1041
+ def test_interpolation_with_bracket_on_next_line
1042
+ assert_equal <<CSS, render(<<SCSS)
1043
+ a.foo b {
1044
+ color: red; }
1045
+ CSS
1046
+ a.\#{"foo"} b
1047
+ {color: red}
1048
+ SCSS
1049
+ end
1050
+
1051
+ def test_extra_comma_in_mixin_arglist_error
1052
+ assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
1053
+ Invalid CSS after "...clude foo(bar, ": expected mixin argument, was ");"
1054
+ MESSAGE
1055
+ @mixin foo($a1, $a2) {
1056
+ baz: $a1 $a2;
1057
+ }
1058
+
1059
+ .bar {
1060
+ @include foo(bar, );
1061
+ }
1062
+ SCSS
1063
+ end
1064
+
1065
+ def test_interpolation
1066
+ assert_equal <<CSS, render(<<SCSS)
1067
+ ul li#foo a span.label {
1068
+ foo: bar; }
1069
+ CSS
1070
+ $bar : "#foo";
1071
+ ul li\#{$bar} a span.label { foo: bar; }
1072
+ SCSS
1073
+ end
1074
+
1075
+ def test_newlines_removed_from_selectors_when_compressed
1076
+ assert_equal <<CSS, render(<<SCSS, :style=>:compressed)
1077
+ z a,z b{display:block}
1078
+ CSS
1079
+ a,
1080
+ b {
1081
+ z & {
1082
+ display: block;
1083
+ }
1084
+ }
1085
+ SCSS
1086
+
1087
+ end
1088
+ end