aliddle-sass 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +11 -0
- data/CONTRIBUTING +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/Rakefile +347 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/sass +9 -0
- data/bin/sass-convert +8 -0
- data/bin/scss +9 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass.rb +95 -0
- data/lib/sass/cache_stores.rb +15 -0
- data/lib/sass/cache_stores/base.rb +88 -0
- data/lib/sass/cache_stores/chain.rb +33 -0
- data/lib/sass/cache_stores/filesystem.rb +60 -0
- data/lib/sass/cache_stores/memory.rb +47 -0
- data/lib/sass/cache_stores/null.rb +25 -0
- data/lib/sass/callbacks.rb +66 -0
- data/lib/sass/css.rb +409 -0
- data/lib/sass/engine.rb +928 -0
- data/lib/sass/environment.rb +101 -0
- data/lib/sass/error.rb +201 -0
- data/lib/sass/exec.rb +707 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/importers/base.rb +139 -0
- data/lib/sass/importers/filesystem.rb +190 -0
- data/lib/sass/logger.rb +15 -0
- data/lib/sass/logger/base.rb +32 -0
- data/lib/sass/logger/log_level.rb +49 -0
- data/lib/sass/media.rb +213 -0
- data/lib/sass/plugin.rb +132 -0
- data/lib/sass/plugin/compiler.rb +406 -0
- data/lib/sass/plugin/configuration.rb +123 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +60 -0
- data/lib/sass/plugin/rails.rb +47 -0
- data/lib/sass/plugin/staleness_checker.rb +183 -0
- data/lib/sass/railtie.rb +9 -0
- data/lib/sass/repl.rb +57 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script.rb +39 -0
- data/lib/sass/script/arg_list.rb +52 -0
- data/lib/sass/script/bool.rb +18 -0
- data/lib/sass/script/color.rb +606 -0
- data/lib/sass/script/css_lexer.rb +29 -0
- data/lib/sass/script/css_parser.rb +31 -0
- data/lib/sass/script/funcall.rb +237 -0
- data/lib/sass/script/functions.rb +1543 -0
- data/lib/sass/script/interpolation.rb +79 -0
- data/lib/sass/script/lexer.rb +348 -0
- data/lib/sass/script/list.rb +85 -0
- data/lib/sass/script/literal.rb +221 -0
- data/lib/sass/script/node.rb +99 -0
- data/lib/sass/script/null.rb +37 -0
- data/lib/sass/script/number.rb +453 -0
- data/lib/sass/script/operation.rb +110 -0
- data/lib/sass/script/parser.rb +495 -0
- data/lib/sass/script/string.rb +51 -0
- data/lib/sass/script/string_interpolation.rb +103 -0
- data/lib/sass/script/unary_operation.rb +69 -0
- data/lib/sass/script/variable.rb +58 -0
- data/lib/sass/scss.rb +16 -0
- data/lib/sass/scss/css_parser.rb +36 -0
- data/lib/sass/scss/parser.rb +1179 -0
- data/lib/sass/scss/rx.rb +133 -0
- data/lib/sass/scss/script_lexer.rb +15 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/scss/static_parser.rb +54 -0
- data/lib/sass/selector.rb +452 -0
- data/lib/sass/selector/abstract_sequence.rb +94 -0
- data/lib/sass/selector/comma_sequence.rb +92 -0
- data/lib/sass/selector/sequence.rb +507 -0
- data/lib/sass/selector/simple.rb +119 -0
- data/lib/sass/selector/simple_sequence.rb +212 -0
- data/lib/sass/shared.rb +76 -0
- data/lib/sass/supports.rb +229 -0
- data/lib/sass/tree/charset_node.rb +22 -0
- data/lib/sass/tree/comment_node.rb +82 -0
- data/lib/sass/tree/content_node.rb +9 -0
- data/lib/sass/tree/css_import_node.rb +60 -0
- data/lib/sass/tree/debug_node.rb +18 -0
- data/lib/sass/tree/directive_node.rb +42 -0
- data/lib/sass/tree/each_node.rb +24 -0
- data/lib/sass/tree/extend_node.rb +36 -0
- data/lib/sass/tree/for_node.rb +36 -0
- data/lib/sass/tree/function_node.rb +34 -0
- data/lib/sass/tree/if_node.rb +52 -0
- data/lib/sass/tree/import_node.rb +75 -0
- data/lib/sass/tree/media_node.rb +58 -0
- data/lib/sass/tree/mixin_def_node.rb +38 -0
- data/lib/sass/tree/mixin_node.rb +39 -0
- data/lib/sass/tree/node.rb +196 -0
- data/lib/sass/tree/prop_node.rb +152 -0
- data/lib/sass/tree/return_node.rb +18 -0
- data/lib/sass/tree/root_node.rb +28 -0
- data/lib/sass/tree/rule_node.rb +132 -0
- data/lib/sass/tree/supports_node.rb +51 -0
- data/lib/sass/tree/trace_node.rb +32 -0
- data/lib/sass/tree/variable_node.rb +30 -0
- data/lib/sass/tree/visitors/base.rb +75 -0
- data/lib/sass/tree/visitors/check_nesting.rb +147 -0
- data/lib/sass/tree/visitors/convert.rb +316 -0
- data/lib/sass/tree/visitors/cssize.rb +229 -0
- data/lib/sass/tree/visitors/deep_copy.rb +102 -0
- data/lib/sass/tree/visitors/extend.rb +68 -0
- data/lib/sass/tree/visitors/perform.rb +446 -0
- data/lib/sass/tree/visitors/set_options.rb +125 -0
- data/lib/sass/tree/visitors/to_css.rb +230 -0
- data/lib/sass/tree/warn_node.rb +18 -0
- data/lib/sass/tree/while_node.rb +18 -0
- data/lib/sass/util.rb +906 -0
- data/lib/sass/util/multibyte_string_scanner.rb +155 -0
- data/lib/sass/util/subset_map.rb +109 -0
- data/lib/sass/util/test.rb +10 -0
- data/lib/sass/version.rb +126 -0
- data/rails/init.rb +1 -0
- data/test/Gemfile +3 -0
- data/test/Gemfile.lock +10 -0
- data/test/sass/cache_test.rb +89 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/conversion_test.rb +1760 -0
- data/test/sass/css2sass_test.rb +439 -0
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/engine_test.rb +3243 -0
- data/test/sass/exec_test.rb +86 -0
- data/test/sass/extend_test.rb +1461 -0
- data/test/sass/fixtures/test_staleness_check_across_importers.css +1 -0
- data/test/sass/fixtures/test_staleness_check_across_importers.scss +1 -0
- data/test/sass/functions_test.rb +1139 -0
- data/test/sass/importer_test.rb +192 -0
- data/test/sass/logger_test.rb +58 -0
- data/test/sass/mock_importer.rb +49 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +550 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/cached_import_option.css +3 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +86 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/filename_fn.css +3 -0
- data/test/sass/results/if.css +3 -0
- data/test/sass/results/import.css +31 -0
- data/test/sass/results/import_charset.css +5 -0
- data/test/sass/results/import_charset_1_8.css +5 -0
- data/test/sass/results/import_charset_ibm866.css +5 -0
- data/test/sass/results/import_content.css +1 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/scss_import.css +31 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +299 -0
- data/test/sass/script_test.rb +591 -0
- data/test/sass/scss/css_test.rb +1093 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +2043 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/templates/_cached_import_option_partial.scss +1 -0
- data/test/sass/templates/_double_import_loop2.sass +1 -0
- data/test/sass/templates/_filename_fn_import.scss +11 -0
- data/test/sass/templates/_imported_charset_ibm866.sass +4 -0
- data/test/sass/templates/_imported_charset_utf8.sass +4 -0
- data/test/sass/templates/_imported_content.sass +3 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/_same_name_different_partiality.scss +1 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/bork5.sass +3 -0
- data/test/sass/templates/cached_import_option.scss +3 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +305 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/double_import_loop1.sass +1 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/filename_fn.scss +18 -0
- data/test/sass/templates/if.sass +11 -0
- data/test/sass/templates/import.sass +12 -0
- data/test/sass/templates/import_charset.sass +9 -0
- data/test/sass/templates/import_charset_1_8.sass +6 -0
- data/test/sass/templates/import_charset_ibm866.sass +11 -0
- data/test/sass/templates/import_content.sass +4 -0
- data/test/sass/templates/importee.less +2 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_import.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/same_name_different_ext.sass +2 -0
- data/test/sass/templates/same_name_different_ext.scss +1 -0
- data/test/sass/templates/same_name_different_partiality.scss +1 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/scss_import.scss +11 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/single_import_loop.sass +1 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/sass/templates/warn.sass +3 -0
- data/test/sass/templates/warn_imported.sass +4 -0
- data/test/sass/test_helper.rb +8 -0
- data/test/sass/util/multibyte_string_scanner_test.rb +147 -0
- data/test/sass/util/subset_map_test.rb +91 -0
- data/test/sass/util_test.rb +313 -0
- data/test/test_helper.rb +80 -0
- metadata +348 -0
@@ -0,0 +1,1093 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
|
+
require 'sass/scss/css_parser'
|
5
|
+
|
6
|
+
# These tests just test the parsing of CSS
|
7
|
+
# (both standard and any hacks we intend to support).
|
8
|
+
# Tests of SCSS-specific behavior go in scss_test.rb.
|
9
|
+
class ScssCssTest < Test::Unit::TestCase
|
10
|
+
include ScssTestHelper
|
11
|
+
|
12
|
+
def test_basic_scss
|
13
|
+
assert_parses <<SCSS
|
14
|
+
selector {
|
15
|
+
property: value;
|
16
|
+
property2: value; }
|
17
|
+
SCSS
|
18
|
+
|
19
|
+
assert_equal <<CSS, render('sel{p:v}')
|
20
|
+
sel {
|
21
|
+
p: v; }
|
22
|
+
CSS
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_empty_rule
|
26
|
+
assert_equal "", render("#foo .bar {}")
|
27
|
+
assert_equal "", render(<<SCSS)
|
28
|
+
#foo .bar {
|
29
|
+
}
|
30
|
+
SCSS
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cdo_and_cdc_ignored_at_toplevel
|
34
|
+
assert_equal <<CSS, render(<<SCSS)
|
35
|
+
foo {
|
36
|
+
bar: baz; }
|
37
|
+
|
38
|
+
bar {
|
39
|
+
bar: baz; }
|
40
|
+
|
41
|
+
baz {
|
42
|
+
bar: baz; }
|
43
|
+
CSS
|
44
|
+
foo {bar: baz}
|
45
|
+
<!--
|
46
|
+
bar {bar: baz}
|
47
|
+
-->
|
48
|
+
baz {bar: baz}
|
49
|
+
SCSS
|
50
|
+
end
|
51
|
+
|
52
|
+
if Sass::Util.ruby1_8?
|
53
|
+
def test_unicode
|
54
|
+
assert_parses <<SCSS
|
55
|
+
@charset "UTF-8";
|
56
|
+
foo {
|
57
|
+
bar: föö bâr; }
|
58
|
+
SCSS
|
59
|
+
assert_parses <<SCSS
|
60
|
+
foo {
|
61
|
+
bar: föö bâr; }
|
62
|
+
SCSS
|
63
|
+
end
|
64
|
+
else
|
65
|
+
def test_unicode
|
66
|
+
assert_parses <<SCSS
|
67
|
+
@charset "UTF-8";
|
68
|
+
foo {
|
69
|
+
bar: föö bâr; }
|
70
|
+
SCSS
|
71
|
+
assert_equal <<CSS, render(<<SCSS)
|
72
|
+
@charset "UTF-8";
|
73
|
+
foo {
|
74
|
+
bar: föö bâr; }
|
75
|
+
CSS
|
76
|
+
foo {
|
77
|
+
bar: föö bâr; }
|
78
|
+
SCSS
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_invisible_comments
|
83
|
+
assert_equal <<CSS, render(<<SCSS)
|
84
|
+
foo {
|
85
|
+
a: d; }
|
86
|
+
CSS
|
87
|
+
foo {a: /* b; c: */ d}
|
88
|
+
SCSS
|
89
|
+
assert_equal <<CSS, render(<<SCSS)
|
90
|
+
foo {
|
91
|
+
a: d; }
|
92
|
+
CSS
|
93
|
+
foo {a /*: b; c */: d}
|
94
|
+
SCSS
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_crazy_comments
|
98
|
+
# http://www.w3.org/Style/CSS/Test/CSS2.1/current/xhtml1/t040109-c17-comments-00-b.xht
|
99
|
+
assert_equal <<CSS, render(<<SCSS)
|
100
|
+
/* This is a CSS comment. */
|
101
|
+
.one {
|
102
|
+
color: green; }
|
103
|
+
|
104
|
+
/* Another comment */
|
105
|
+
/* The following should not be used:
|
106
|
+
.two {color: red;} */
|
107
|
+
.three {
|
108
|
+
color: green;
|
109
|
+
/* color: red; */ }
|
110
|
+
|
111
|
+
/**
|
112
|
+
.four {color: red;} */
|
113
|
+
.five {
|
114
|
+
color: green; }
|
115
|
+
|
116
|
+
/**/
|
117
|
+
.six {
|
118
|
+
color: green; }
|
119
|
+
|
120
|
+
/*********/
|
121
|
+
.seven {
|
122
|
+
color: green; }
|
123
|
+
|
124
|
+
/* a comment **/
|
125
|
+
.eight {
|
126
|
+
color: green; }
|
127
|
+
CSS
|
128
|
+
/* This is a CSS comment. */
|
129
|
+
.one {color: green;} /* Another comment */
|
130
|
+
/* The following should not be used:
|
131
|
+
.two {color: red;} */
|
132
|
+
.three {color: green; /* color: red; */}
|
133
|
+
/**
|
134
|
+
.four {color: red;} */
|
135
|
+
.five {color: green;}
|
136
|
+
/**/
|
137
|
+
.six {color: green;}
|
138
|
+
/*********/
|
139
|
+
.seven {color: green;}
|
140
|
+
/* a comment **/
|
141
|
+
.eight {color: green;}
|
142
|
+
SCSS
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_rule_comments
|
146
|
+
assert_parses <<SCSS
|
147
|
+
/* Foo */
|
148
|
+
.foo {
|
149
|
+
a: b; }
|
150
|
+
SCSS
|
151
|
+
assert_equal <<CSS, render(<<SCSS)
|
152
|
+
/* Foo
|
153
|
+
* Bar */
|
154
|
+
.foo {
|
155
|
+
a: b; }
|
156
|
+
CSS
|
157
|
+
/* Foo
|
158
|
+
* Bar */.foo {
|
159
|
+
a: b; }
|
160
|
+
SCSS
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_property_comments
|
164
|
+
assert_parses <<SCSS
|
165
|
+
.foo {
|
166
|
+
/* Foo */
|
167
|
+
a: b; }
|
168
|
+
SCSS
|
169
|
+
assert_equal <<CSS, render(<<SCSS)
|
170
|
+
.foo {
|
171
|
+
/* Foo
|
172
|
+
* Bar */
|
173
|
+
a: b; }
|
174
|
+
CSS
|
175
|
+
.foo {
|
176
|
+
/* Foo
|
177
|
+
* Bar */a: b; }
|
178
|
+
SCSS
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_selector_comments
|
182
|
+
assert_equal <<CSS, render(<<SCSS)
|
183
|
+
.foo #bar:baz(bip) {
|
184
|
+
a: b; }
|
185
|
+
CSS
|
186
|
+
.foo /* .a #foo */ #bar:baz(/* bang )*/ bip) {
|
187
|
+
a: b; }
|
188
|
+
SCSS
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_lonely_comments
|
192
|
+
assert_parses <<SCSS
|
193
|
+
/* Foo
|
194
|
+
* Bar */
|
195
|
+
SCSS
|
196
|
+
assert_parses <<SCSS
|
197
|
+
.foo {
|
198
|
+
/* Foo
|
199
|
+
* Bar */ }
|
200
|
+
SCSS
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_multiple_comments
|
204
|
+
assert_parses <<SCSS
|
205
|
+
/* Foo
|
206
|
+
* Bar */
|
207
|
+
/* Baz
|
208
|
+
* Bang */
|
209
|
+
SCSS
|
210
|
+
assert_parses <<SCSS
|
211
|
+
.foo {
|
212
|
+
/* Foo
|
213
|
+
* Bar */
|
214
|
+
/* Baz
|
215
|
+
* Bang */ }
|
216
|
+
SCSS
|
217
|
+
assert_equal <<CSS, render(<<SCSS)
|
218
|
+
.foo {
|
219
|
+
/* Foo Bar */
|
220
|
+
/* Baz Bang */ }
|
221
|
+
CSS
|
222
|
+
.foo {
|
223
|
+
/* Foo Bar *//* Baz Bang */ }
|
224
|
+
SCSS
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_bizarrely_formatted_comments
|
228
|
+
assert_parses <<SCSS
|
229
|
+
.foo {
|
230
|
+
/* Foo
|
231
|
+
Bar
|
232
|
+
Baz */
|
233
|
+
a: b; }
|
234
|
+
SCSS
|
235
|
+
assert_parses <<SCSS
|
236
|
+
.foo {
|
237
|
+
/* Foo
|
238
|
+
Bar
|
239
|
+
Baz */
|
240
|
+
a: b; }
|
241
|
+
SCSS
|
242
|
+
assert_equal <<CSS, render(<<SCSS)
|
243
|
+
.foo {
|
244
|
+
/* Foo
|
245
|
+
Bar */
|
246
|
+
a: b; }
|
247
|
+
CSS
|
248
|
+
.foo {/* Foo
|
249
|
+
Bar */
|
250
|
+
a: b; }
|
251
|
+
SCSS
|
252
|
+
assert_equal <<CSS, render(<<SCSS)
|
253
|
+
.foo {
|
254
|
+
/* Foo
|
255
|
+
Bar
|
256
|
+
Baz */
|
257
|
+
a: b; }
|
258
|
+
CSS
|
259
|
+
.foo {/* Foo
|
260
|
+
Bar
|
261
|
+
Baz */
|
262
|
+
a: b; }
|
263
|
+
SCSS
|
264
|
+
end
|
265
|
+
|
266
|
+
## Declarations
|
267
|
+
|
268
|
+
def test_vendor_properties
|
269
|
+
assert_parses <<SCSS
|
270
|
+
foo {
|
271
|
+
-moz-foo-bar: blat;
|
272
|
+
-o-flat-blang: wibble; }
|
273
|
+
SCSS
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_empty_declarations
|
277
|
+
assert_equal <<CSS, render(<<SCSS)
|
278
|
+
foo {
|
279
|
+
bar: baz; }
|
280
|
+
CSS
|
281
|
+
foo {;;;;
|
282
|
+
bar: baz;;;;
|
283
|
+
;;}
|
284
|
+
SCSS
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_basic_property_types
|
288
|
+
assert_parses <<SCSS
|
289
|
+
foo {
|
290
|
+
a: 2;
|
291
|
+
b: 2.3em;
|
292
|
+
c: 50%;
|
293
|
+
d: "fraz bran";
|
294
|
+
e: flanny-blanny-blan;
|
295
|
+
f: url(http://sass-lang.com);
|
296
|
+
g: U+ffa?;
|
297
|
+
h: #aabbcc; }
|
298
|
+
SCSS
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_functions
|
302
|
+
assert_parses <<SCSS
|
303
|
+
foo {
|
304
|
+
a: foo-bar(12);
|
305
|
+
b: -foo-bar-baz(13, 14 15); }
|
306
|
+
SCSS
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_unary_minus
|
310
|
+
assert_parses <<SCSS
|
311
|
+
foo {
|
312
|
+
a: -2;
|
313
|
+
b: -2.3em;
|
314
|
+
c: -50%;
|
315
|
+
d: -foo(bar baz); }
|
316
|
+
SCSS
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_operators
|
320
|
+
assert_parses <<SCSS
|
321
|
+
foo {
|
322
|
+
a: foo bar baz;
|
323
|
+
b: foo, #aabbcc, -12;
|
324
|
+
c: 1px/2px/-3px;
|
325
|
+
d: foo bar, baz/bang; }
|
326
|
+
SCSS
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_important
|
330
|
+
assert_parses <<SCSS
|
331
|
+
foo {
|
332
|
+
a: foo !important;
|
333
|
+
b: foo bar !important;
|
334
|
+
b: foo, bar !important; }
|
335
|
+
SCSS
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_initial_hyphen
|
339
|
+
assert_parses <<SCSS
|
340
|
+
foo {
|
341
|
+
a: -moz-bar-baz;
|
342
|
+
b: foo -o-bar-baz; }
|
343
|
+
SCSS
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_ms_long_filter_syntax
|
347
|
+
assert_equal <<CSS, render(<<SCSS)
|
348
|
+
foo {
|
349
|
+
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000);
|
350
|
+
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000); }
|
351
|
+
CSS
|
352
|
+
foo {
|
353
|
+
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000);
|
354
|
+
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#c0ff3300, endColorstr=#ff000000); }
|
355
|
+
SCSS
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_ms_short_filter_syntax
|
359
|
+
assert_parses <<SCSS
|
360
|
+
foo {
|
361
|
+
filter: alpha(opacity=20);
|
362
|
+
filter: alpha(opacity=20, enabled=true);
|
363
|
+
filter: blaznicate(foo=bar, baz=bang bip, bart=#fa4600); }
|
364
|
+
SCSS
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_declaration_hacks
|
368
|
+
assert_parses <<SCSS
|
369
|
+
foo {
|
370
|
+
_name: val;
|
371
|
+
*name: val;
|
372
|
+
:name: val;
|
373
|
+
.name: val;
|
374
|
+
#name: val;
|
375
|
+
name/**/: val;
|
376
|
+
name/*\\**/: val;
|
377
|
+
name: val; }
|
378
|
+
SCSS
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_trailing_hash_hack
|
382
|
+
assert_parses <<SCSS
|
383
|
+
foo {
|
384
|
+
foo: bar;
|
385
|
+
#baz: bang;
|
386
|
+
#bip: bop; }
|
387
|
+
SCSS
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_zero_arg_functions
|
391
|
+
assert_parses <<SCSS
|
392
|
+
foo {
|
393
|
+
a: foo();
|
394
|
+
b: bar baz-bang() bip; }
|
395
|
+
SCSS
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_expression_function
|
399
|
+
assert_parses <<SCSS
|
400
|
+
foo {
|
401
|
+
a: 12px expression(1 + (3 / Foo.bar("baz" + "bang") + function() {return 12;}) % 12); }
|
402
|
+
SCSS
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_calc_function
|
406
|
+
assert_parses <<SCSS
|
407
|
+
foo {
|
408
|
+
a: 12px calc(100%/3 - 2*1em - 2*1px);
|
409
|
+
b: 12px -moz-calc(100%/3 - 2*1em - 2*1px);
|
410
|
+
b: 12px -webkit-calc(100%/3 - 2*1em - 2*1px);
|
411
|
+
b: 12px -foobar-calc(100%/3 - 2*1em - 2*1px); }
|
412
|
+
SCSS
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_element_function
|
416
|
+
assert_parses <<SCSS
|
417
|
+
foo {
|
418
|
+
a: -moz-element(#foo);
|
419
|
+
b: -webkit-element(#foo);
|
420
|
+
b: -foobar-element(#foo); }
|
421
|
+
SCSS
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_unary_ops
|
425
|
+
assert_equal <<CSS, render(<<SCSS)
|
426
|
+
foo {
|
427
|
+
a: -0.5em;
|
428
|
+
b: +0.5em;
|
429
|
+
c: -foo(12px);
|
430
|
+
d: +foo(12px); }
|
431
|
+
CSS
|
432
|
+
foo {
|
433
|
+
a: -0.5em;
|
434
|
+
b: +0.5em;
|
435
|
+
c: -foo(12px);
|
436
|
+
d: +foo(12px); }
|
437
|
+
SCSS
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_css_string_escapes
|
441
|
+
assert_parses <<SCSS
|
442
|
+
foo {
|
443
|
+
a: "\\foo bar";
|
444
|
+
b: "foo\\ bar";
|
445
|
+
c: "\\2022 \\0020";
|
446
|
+
d: "foo\\\\bar";
|
447
|
+
e: "foo\\"'bar"; }
|
448
|
+
SCSS
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_css_ident_escapes
|
452
|
+
assert_parses <<SCSS
|
453
|
+
foo {
|
454
|
+
a: \\foo bar;
|
455
|
+
b: foo\\ bar;
|
456
|
+
c: \\2022 \\0020;
|
457
|
+
d: foo\\\\bar;
|
458
|
+
e: foo\\"\\'bar; }
|
459
|
+
SCSS
|
460
|
+
end
|
461
|
+
|
462
|
+
## Directives
|
463
|
+
|
464
|
+
def test_namespace_directive
|
465
|
+
assert_parses '@namespace "http://www.w3.org/Profiles/xhtml1-strict";'
|
466
|
+
assert_parses '@namespace url(http://www.w3.org/Profiles/xhtml1-strict);'
|
467
|
+
assert_parses '@namespace html url("http://www.w3.org/Profiles/xhtml1-strict");'
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_media_directive
|
471
|
+
assert_parses <<SCSS
|
472
|
+
@media all {
|
473
|
+
rule1 {
|
474
|
+
prop: val; }
|
475
|
+
|
476
|
+
rule2 {
|
477
|
+
prop: val; } }
|
478
|
+
SCSS
|
479
|
+
assert_parses <<SCSS
|
480
|
+
@media screen, print {
|
481
|
+
rule1 {
|
482
|
+
prop: val; }
|
483
|
+
|
484
|
+
rule2 {
|
485
|
+
prop: val; } }
|
486
|
+
SCSS
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_media_directive_with_keywords
|
490
|
+
assert_parses <<SCSS
|
491
|
+
@media screen and (-webkit-min-device-pixel-ratio: 0) {
|
492
|
+
a: b; }
|
493
|
+
SCSS
|
494
|
+
assert_parses <<SCSS
|
495
|
+
@media only screen, print and (foo: 0px) and (bar: flam(12px solid)) {
|
496
|
+
a: b; }
|
497
|
+
SCSS
|
498
|
+
end
|
499
|
+
|
500
|
+
def test_import_directive
|
501
|
+
assert_parses '@import "foo.css";'
|
502
|
+
assert_parses "@import 'foo.css';"
|
503
|
+
assert_parses '@import url("foo.css");'
|
504
|
+
assert_parses "@import url('foo.css');"
|
505
|
+
assert_parses '@import url(foo.css);'
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_import_directive_with_media
|
509
|
+
assert_parses '@import "foo.css" screen;'
|
510
|
+
assert_parses '@import "foo.css" screen, print;'
|
511
|
+
assert_parses '@import "foo.css" screen, print and (foo: 0);'
|
512
|
+
assert_parses '@import "foo.css" screen, only print, screen and (foo: 0);'
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_page_directive
|
516
|
+
assert_parses <<SCSS
|
517
|
+
@page {
|
518
|
+
prop1: val;
|
519
|
+
prop2: val; }
|
520
|
+
SCSS
|
521
|
+
assert_parses <<SCSS
|
522
|
+
@page flap {
|
523
|
+
prop1: val;
|
524
|
+
prop2: val; }
|
525
|
+
SCSS
|
526
|
+
assert_parses <<SCSS
|
527
|
+
@page :first {
|
528
|
+
prop1: val;
|
529
|
+
prop2: val; }
|
530
|
+
SCSS
|
531
|
+
assert_parses <<SCSS
|
532
|
+
@page flap:first {
|
533
|
+
prop1: val;
|
534
|
+
prop2: val; }
|
535
|
+
SCSS
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_blockless_directive_without_semicolon
|
539
|
+
assert_equal "@foo \"bar\";\n", render('@foo "bar"')
|
540
|
+
end
|
541
|
+
|
542
|
+
def test_directive_with_lots_of_whitespace
|
543
|
+
assert_equal "@foo \"bar\";\n", render('@foo "bar" ;')
|
544
|
+
end
|
545
|
+
|
546
|
+
def test_empty_blockless_directive
|
547
|
+
assert_parses "@foo;"
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_multiple_blockless_directives
|
551
|
+
assert_parses <<SCSS
|
552
|
+
@foo bar;
|
553
|
+
@bar baz;
|
554
|
+
SCSS
|
555
|
+
end
|
556
|
+
|
557
|
+
def test_empty_block_directive
|
558
|
+
assert_parses "@foo {}"
|
559
|
+
assert_equal "@foo {}\n", render(<<SCSS)
|
560
|
+
@foo {
|
561
|
+
}
|
562
|
+
SCSS
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_multiple_block_directives
|
566
|
+
assert_parses <<SCSS
|
567
|
+
@foo bar {
|
568
|
+
a: b; }
|
569
|
+
|
570
|
+
@bar baz {
|
571
|
+
c: d; }
|
572
|
+
SCSS
|
573
|
+
end
|
574
|
+
|
575
|
+
def test_block_directive_with_rule_and_property
|
576
|
+
assert_parses <<SCSS
|
577
|
+
@foo {
|
578
|
+
rule {
|
579
|
+
a: b; }
|
580
|
+
|
581
|
+
a: b; }
|
582
|
+
SCSS
|
583
|
+
end
|
584
|
+
|
585
|
+
def test_block_directive_with_semicolon
|
586
|
+
assert_equal <<CSS, render(<<SCSS)
|
587
|
+
@foo {
|
588
|
+
a: b; }
|
589
|
+
|
590
|
+
@bar {
|
591
|
+
a: b; }
|
592
|
+
CSS
|
593
|
+
@foo {a:b};
|
594
|
+
@bar {a:b};
|
595
|
+
SCSS
|
596
|
+
end
|
597
|
+
|
598
|
+
def test_moz_document_directive
|
599
|
+
assert_equal <<CSS, render(<<SCSS)
|
600
|
+
@-moz-document url(http://www.w3.org/),
|
601
|
+
url-prefix(http://www.w3.org/Style/),
|
602
|
+
domain(mozilla.org),
|
603
|
+
regexp("^https:.*") {
|
604
|
+
.foo {
|
605
|
+
a: b; } }
|
606
|
+
CSS
|
607
|
+
@-moz-document url(http://www.w3.org/),
|
608
|
+
url-prefix(http://www.w3.org/Style/),
|
609
|
+
domain(mozilla.org),
|
610
|
+
regexp("^https:.*") {
|
611
|
+
.foo {a: b}
|
612
|
+
}
|
613
|
+
SCSS
|
614
|
+
end
|
615
|
+
|
616
|
+
def test_supports
|
617
|
+
assert_equal <<CSS, render(<<SCSS)
|
618
|
+
@supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
|
619
|
+
.foo {
|
620
|
+
a: b; } }
|
621
|
+
@supports (a: b) {
|
622
|
+
.foo {
|
623
|
+
a: b; } }
|
624
|
+
CSS
|
625
|
+
@supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
|
626
|
+
.foo {
|
627
|
+
a: b;
|
628
|
+
}
|
629
|
+
}
|
630
|
+
|
631
|
+
@supports (a: b) {
|
632
|
+
.foo {
|
633
|
+
a: b;
|
634
|
+
}
|
635
|
+
}
|
636
|
+
SCSS
|
637
|
+
|
638
|
+
assert_equal <<CSS, render(<<SCSS)
|
639
|
+
@-prefix-supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
|
640
|
+
.foo {
|
641
|
+
a: b; } }
|
642
|
+
CSS
|
643
|
+
@-prefix-supports (a: b) and (c: d) or (not (d: e)) and ((not (f: g)) or (not ((h: i) and (j: k)))) {
|
644
|
+
.foo {
|
645
|
+
a: b;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
SCSS
|
649
|
+
end
|
650
|
+
|
651
|
+
## Selectors
|
652
|
+
|
653
|
+
# Taken from http://dev.w3.org/csswg/selectors4/#overview
|
654
|
+
def test_summarized_selectors
|
655
|
+
assert_selector_parses('*')
|
656
|
+
assert_selector_parses('E')
|
657
|
+
assert_selector_parses('E:not(s)')
|
658
|
+
assert_selector_parses('E:not(s1, s2)')
|
659
|
+
assert_selector_parses('E:matches(s1, s2)')
|
660
|
+
assert_selector_parses('E.warning')
|
661
|
+
assert_selector_parses('E#myid')
|
662
|
+
assert_selector_parses('E[foo]')
|
663
|
+
assert_selector_parses('E[foo="bar"]')
|
664
|
+
assert_selector_parses('E[foo="bar" i]')
|
665
|
+
assert_selector_parses('E[foo~="bar"]')
|
666
|
+
assert_selector_parses('E[foo^="bar"]')
|
667
|
+
assert_selector_parses('E[foo$="bar"]')
|
668
|
+
assert_selector_parses('E[foo*="bar"]')
|
669
|
+
assert_selector_parses('E[foo|="en"]')
|
670
|
+
assert_selector_parses('E:dir(ltr)')
|
671
|
+
assert_selector_parses('E:lang(fr)')
|
672
|
+
assert_selector_parses('E:lang(zh, *-hant)')
|
673
|
+
assert_selector_parses('E:any-link')
|
674
|
+
assert_selector_parses('E:link')
|
675
|
+
assert_selector_parses('E:visited')
|
676
|
+
assert_selector_parses('E:local-link')
|
677
|
+
assert_selector_parses('E:local-link(0)')
|
678
|
+
assert_selector_parses('E:target')
|
679
|
+
assert_selector_parses('E:scope')
|
680
|
+
assert_selector_parses('E:current')
|
681
|
+
assert_selector_parses('E:current(s)')
|
682
|
+
assert_selector_parses('E:past')
|
683
|
+
assert_selector_parses('E:future')
|
684
|
+
assert_selector_parses('E:active')
|
685
|
+
assert_selector_parses('E:hover')
|
686
|
+
assert_selector_parses('E:focus')
|
687
|
+
assert_selector_parses('E:enabled')
|
688
|
+
assert_selector_parses('E:disabled')
|
689
|
+
assert_selector_parses('E:checked')
|
690
|
+
assert_selector_parses('E:indeterminate')
|
691
|
+
assert_selector_parses('E:default')
|
692
|
+
assert_selector_parses('E:in-range')
|
693
|
+
assert_selector_parses('E:out-of-range')
|
694
|
+
assert_selector_parses('E:required')
|
695
|
+
assert_selector_parses('E:optional')
|
696
|
+
assert_selector_parses('E:read-only')
|
697
|
+
assert_selector_parses('E:read-write')
|
698
|
+
assert_selector_parses('E:root')
|
699
|
+
assert_selector_parses('E:empty')
|
700
|
+
assert_selector_parses('E:first-child')
|
701
|
+
assert_selector_parses('E:nth-child(n)')
|
702
|
+
assert_selector_parses('E:last-child')
|
703
|
+
assert_selector_parses('E:nth-last-child(n)')
|
704
|
+
assert_selector_parses('E:only-child')
|
705
|
+
assert_selector_parses('E:first-of-type')
|
706
|
+
assert_selector_parses('E:nth-of-type(n)')
|
707
|
+
assert_selector_parses('E:last-of-type')
|
708
|
+
assert_selector_parses('E:nth-last-of-type(n)')
|
709
|
+
assert_selector_parses('E:only-of-type')
|
710
|
+
assert_selector_parses('E:nth-match(n of selector)')
|
711
|
+
assert_selector_parses('E:nth-last-match(n of selector)')
|
712
|
+
assert_selector_parses('E:column(selector)')
|
713
|
+
assert_selector_parses('E:nth-column(n)')
|
714
|
+
assert_selector_parses('E:nth-last-column(n)')
|
715
|
+
assert_selector_parses('E F')
|
716
|
+
assert_selector_parses('E > F')
|
717
|
+
assert_selector_parses('E + F')
|
718
|
+
assert_selector_parses('E ~ F')
|
719
|
+
assert_selector_parses('E /foo/ F')
|
720
|
+
assert_selector_parses('E! > F')
|
721
|
+
|
722
|
+
assert_selector_parses('E /ns|foo/ F')
|
723
|
+
assert_selector_parses('E /*|foo/ F')
|
724
|
+
end
|
725
|
+
|
726
|
+
# Taken from http://dev.w3.org/csswg/selectors4/#overview, but without element
|
727
|
+
# names.
|
728
|
+
def test_more_summarized_selectors
|
729
|
+
assert_selector_parses(':not(s)')
|
730
|
+
assert_selector_parses(':not(s1, s2)')
|
731
|
+
assert_selector_parses(':matches(s1, s2)')
|
732
|
+
assert_selector_parses('.warning')
|
733
|
+
assert_selector_parses('#myid')
|
734
|
+
assert_selector_parses('[foo]')
|
735
|
+
assert_selector_parses('[foo="bar"]')
|
736
|
+
assert_selector_parses('[foo="bar" i]')
|
737
|
+
assert_selector_parses('[foo~="bar"]')
|
738
|
+
assert_selector_parses('[foo^="bar"]')
|
739
|
+
assert_selector_parses('[foo$="bar"]')
|
740
|
+
assert_selector_parses('[foo*="bar"]')
|
741
|
+
assert_selector_parses('[foo|="en"]')
|
742
|
+
assert_selector_parses(':dir(ltr)')
|
743
|
+
assert_selector_parses(':lang(fr)')
|
744
|
+
assert_selector_parses(':lang(zh, *-hant)')
|
745
|
+
assert_selector_parses(':any-link')
|
746
|
+
assert_selector_parses(':link')
|
747
|
+
assert_selector_parses(':visited')
|
748
|
+
assert_selector_parses(':local-link')
|
749
|
+
assert_selector_parses(':local-link(0)')
|
750
|
+
assert_selector_parses(':target')
|
751
|
+
assert_selector_parses(':scope')
|
752
|
+
assert_selector_parses(':current')
|
753
|
+
assert_selector_parses(':current(s)')
|
754
|
+
assert_selector_parses(':past')
|
755
|
+
assert_selector_parses(':future')
|
756
|
+
assert_selector_parses(':active')
|
757
|
+
assert_selector_parses(':hover')
|
758
|
+
assert_selector_parses(':focus')
|
759
|
+
assert_selector_parses(':enabled')
|
760
|
+
assert_selector_parses(':disabled')
|
761
|
+
assert_selector_parses(':checked')
|
762
|
+
assert_selector_parses(':indeterminate')
|
763
|
+
assert_selector_parses(':default')
|
764
|
+
assert_selector_parses(':in-range')
|
765
|
+
assert_selector_parses(':out-of-range')
|
766
|
+
assert_selector_parses(':required')
|
767
|
+
assert_selector_parses(':optional')
|
768
|
+
assert_selector_parses(':read-only')
|
769
|
+
assert_selector_parses(':read-write')
|
770
|
+
assert_selector_parses(':root')
|
771
|
+
assert_selector_parses(':empty')
|
772
|
+
assert_selector_parses(':first-child')
|
773
|
+
assert_selector_parses(':nth-child(n)')
|
774
|
+
assert_selector_parses(':last-child')
|
775
|
+
assert_selector_parses(':nth-last-child(n)')
|
776
|
+
assert_selector_parses(':only-child')
|
777
|
+
assert_selector_parses(':first-of-type')
|
778
|
+
assert_selector_parses(':nth-of-type(n)')
|
779
|
+
assert_selector_parses(':last-of-type')
|
780
|
+
assert_selector_parses(':nth-last-of-type(n)')
|
781
|
+
assert_selector_parses(':only-of-type')
|
782
|
+
assert_selector_parses(':nth-match(n of selector)')
|
783
|
+
assert_selector_parses(':nth-last-match(n of selector)')
|
784
|
+
assert_selector_parses(':column(selector)')
|
785
|
+
assert_selector_parses(':nth-column(n)')
|
786
|
+
assert_selector_parses(':nth-last-column(n)')
|
787
|
+
end
|
788
|
+
|
789
|
+
def test_attribute_selectors_with_identifiers
|
790
|
+
assert_selector_parses('[foo~=bar]')
|
791
|
+
assert_selector_parses('[foo^=bar]')
|
792
|
+
assert_selector_parses('[foo$=bar]')
|
793
|
+
assert_selector_parses('[foo*=bar]')
|
794
|
+
assert_selector_parses('[foo|=en]')
|
795
|
+
end
|
796
|
+
|
797
|
+
def test_nth_selectors
|
798
|
+
assert_selector_parses(':nth-child(-n)')
|
799
|
+
assert_selector_parses(':nth-child(+n)')
|
800
|
+
|
801
|
+
assert_selector_parses(':nth-child(even)')
|
802
|
+
assert_selector_parses(':nth-child(odd)')
|
803
|
+
|
804
|
+
assert_selector_parses(':nth-child(50)')
|
805
|
+
assert_selector_parses(':nth-child(-50)')
|
806
|
+
assert_selector_parses(':nth-child(+50)')
|
807
|
+
|
808
|
+
assert_selector_parses(':nth-child(2n+3)')
|
809
|
+
assert_selector_parses(':nth-child(2n-3)')
|
810
|
+
assert_selector_parses(':nth-child(+2n-3)')
|
811
|
+
assert_selector_parses(':nth-child(-2n+3)')
|
812
|
+
assert_selector_parses(':nth-child(-2n+ 3)')
|
813
|
+
|
814
|
+
assert_equal(<<CSS, render(<<SCSS))
|
815
|
+
:nth-child(2n + 3) {
|
816
|
+
a: b; }
|
817
|
+
CSS
|
818
|
+
:nth-child( 2n + 3 ) {
|
819
|
+
a: b; }
|
820
|
+
SCSS
|
821
|
+
end
|
822
|
+
|
823
|
+
def test_selectors_containing_selectors
|
824
|
+
assert_selector_can_contain_selectors(':not(<sel>)')
|
825
|
+
assert_selector_can_contain_selectors(':current(<sel>)')
|
826
|
+
assert_selector_can_contain_selectors(':nth-match(n of <sel>)')
|
827
|
+
assert_selector_can_contain_selectors(':nth-last-match(n of <sel>)')
|
828
|
+
assert_selector_can_contain_selectors(':column(<sel>)')
|
829
|
+
assert_selector_can_contain_selectors(':-moz-any(<sel>)')
|
830
|
+
end
|
831
|
+
|
832
|
+
def assert_selector_can_contain_selectors(sel)
|
833
|
+
try = lambda {|subsel| assert_selector_parses(sel.gsub('<sel>', subsel))}
|
834
|
+
|
835
|
+
try['foo|bar']
|
836
|
+
try['*|bar']
|
837
|
+
|
838
|
+
try['foo|*']
|
839
|
+
try['*|*']
|
840
|
+
|
841
|
+
try['#blah']
|
842
|
+
try['.blah']
|
843
|
+
|
844
|
+
try['[foo]']
|
845
|
+
try['[foo^="bar"]']
|
846
|
+
try['[baz|foo~="bar"]']
|
847
|
+
|
848
|
+
try[':hover']
|
849
|
+
try[':nth-child(2n + 3)']
|
850
|
+
|
851
|
+
try['h1, h2, h3']
|
852
|
+
try['#foo, bar, [baz]']
|
853
|
+
|
854
|
+
# Not technically allowed for most selectors, but what the heck
|
855
|
+
try[':not(#foo)']
|
856
|
+
try['a#foo.bar']
|
857
|
+
try['#foo .bar > baz']
|
858
|
+
end
|
859
|
+
|
860
|
+
def test_namespaced_selectors
|
861
|
+
assert_selector_parses('foo|E')
|
862
|
+
assert_selector_parses('*|E')
|
863
|
+
assert_selector_parses('foo|*')
|
864
|
+
assert_selector_parses('*|*')
|
865
|
+
end
|
866
|
+
|
867
|
+
def test_namespaced_attribute_selectors
|
868
|
+
assert_selector_parses('[foo|bar=baz]')
|
869
|
+
assert_selector_parses('[*|bar=baz]')
|
870
|
+
assert_selector_parses('[foo|bar|=baz]')
|
871
|
+
end
|
872
|
+
|
873
|
+
def test_comma_selectors
|
874
|
+
assert_selector_parses('E, F')
|
875
|
+
assert_selector_parses('E F, G H')
|
876
|
+
assert_selector_parses('E > F, G > H')
|
877
|
+
end
|
878
|
+
|
879
|
+
def test_selectors_with_newlines
|
880
|
+
assert_selector_parses("E,\nF")
|
881
|
+
assert_selector_parses("E\nF")
|
882
|
+
assert_selector_parses("E, F\nG, H")
|
883
|
+
end
|
884
|
+
|
885
|
+
def test_expression_fallback_selectors
|
886
|
+
assert_selector_parses('0%')
|
887
|
+
assert_selector_parses('60%')
|
888
|
+
assert_selector_parses('100%')
|
889
|
+
assert_selector_parses('12px')
|
890
|
+
assert_selector_parses('"foo"')
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_functional_pseudo_selectors
|
894
|
+
assert_selector_parses(':foo("bar")')
|
895
|
+
assert_selector_parses(':foo(bar)')
|
896
|
+
assert_selector_parses(':foo(12px)')
|
897
|
+
assert_selector_parses(':foo(+)')
|
898
|
+
assert_selector_parses(':foo(-)')
|
899
|
+
assert_selector_parses(':foo(+"bar")')
|
900
|
+
assert_selector_parses(':foo(-++--baz-"bar"12px)')
|
901
|
+
end
|
902
|
+
|
903
|
+
def test_selector_hacks
|
904
|
+
assert_selector_parses('> E')
|
905
|
+
assert_selector_parses('+ E')
|
906
|
+
assert_selector_parses('~ E')
|
907
|
+
assert_selector_parses('> > E')
|
908
|
+
assert_equal <<CSS, render(<<SCSS)
|
909
|
+
> > E {
|
910
|
+
a: b; }
|
911
|
+
CSS
|
912
|
+
>> E {
|
913
|
+
a: b; }
|
914
|
+
SCSS
|
915
|
+
|
916
|
+
assert_selector_parses('E*')
|
917
|
+
assert_selector_parses('E*.foo')
|
918
|
+
assert_selector_parses('E*:hover')
|
919
|
+
end
|
920
|
+
|
921
|
+
def test_spaceless_combo_selectors
|
922
|
+
assert_equal "E > F {\n a: b; }\n", render("E>F { a: b;} ")
|
923
|
+
assert_equal "E ~ F {\n a: b; }\n", render("E~F { a: b;} ")
|
924
|
+
assert_equal "E + F {\n a: b; }\n", render("E+F { a: b;} ")
|
925
|
+
end
|
926
|
+
|
927
|
+
## Errors
|
928
|
+
|
929
|
+
def test_invalid_directives
|
930
|
+
assert_not_parses("identifier", '@<err> import "foo";')
|
931
|
+
assert_not_parses("identifier", '@<err>12 "foo";')
|
932
|
+
end
|
933
|
+
|
934
|
+
def test_invalid_classes
|
935
|
+
assert_not_parses("class name", 'p.<err> foo {a: b}')
|
936
|
+
assert_not_parses("class name", 'p.<err>1foo {a: b}')
|
937
|
+
end
|
938
|
+
|
939
|
+
def test_invalid_ids
|
940
|
+
assert_not_parses("id name", 'p#<err> foo {a: b}')
|
941
|
+
end
|
942
|
+
|
943
|
+
def test_no_properties_at_toplevel
|
944
|
+
assert_not_parses('pseudoclass or pseudoelement', 'a:<err> b;')
|
945
|
+
end
|
946
|
+
|
947
|
+
def test_no_scss_directives
|
948
|
+
assert_parses('@import "foo.sass";')
|
949
|
+
assert_parses <<SCSS
|
950
|
+
@mixin foo {
|
951
|
+
a: b; }
|
952
|
+
SCSS
|
953
|
+
end
|
954
|
+
|
955
|
+
def test_no_variables
|
956
|
+
assert_not_parses("selector or at-rule", "<err>$var = 12;")
|
957
|
+
assert_not_parses('"}"', "foo { <err>!var = 12; }")
|
958
|
+
end
|
959
|
+
|
960
|
+
def test_no_parent_selectors
|
961
|
+
assert_not_parses('"{"', "foo <err>&.bar {a: b}")
|
962
|
+
end
|
963
|
+
|
964
|
+
def test_no_selector_interpolation
|
965
|
+
assert_not_parses('"{"', 'foo <err>#{"bar"}.baz {a: b}')
|
966
|
+
end
|
967
|
+
|
968
|
+
def test_no_prop_name_interpolation
|
969
|
+
assert_not_parses('":"', 'foo {a<err>#{"bar"}baz: b}')
|
970
|
+
end
|
971
|
+
|
972
|
+
def test_no_prop_val_interpolation
|
973
|
+
assert_not_parses('"}"', 'foo {a: b <err>#{"bar"} c}')
|
974
|
+
end
|
975
|
+
|
976
|
+
def test_no_string_interpolation
|
977
|
+
assert_parses <<SCSS
|
978
|
+
foo {
|
979
|
+
a: "bang \#{1 + " bar "} bip"; }
|
980
|
+
SCSS
|
981
|
+
end
|
982
|
+
|
983
|
+
def test_no_sass_script_values
|
984
|
+
assert_not_parses('"}"', 'foo {a: b <err>* c}')
|
985
|
+
end
|
986
|
+
|
987
|
+
def test_no_nested_rules
|
988
|
+
assert_not_parses('":"', 'foo {bar <err>{a: b}}')
|
989
|
+
assert_not_parses('"}"', 'foo {<err>[bar=baz] {a: b}}')
|
990
|
+
end
|
991
|
+
|
992
|
+
def test_no_nested_properties
|
993
|
+
assert_not_parses('expression (e.g. 1px, bold)', 'foo {bar: <err>{a: b}}')
|
994
|
+
assert_not_parses('expression (e.g. 1px, bold)', 'foo {bar: bang <err>{a: b}}')
|
995
|
+
end
|
996
|
+
|
997
|
+
def test_no_nested_directives
|
998
|
+
assert_not_parses('"}"', 'foo {<err>@bar {a: b}}')
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def test_error_with_windows_newlines
|
1002
|
+
render <<SCSS
|
1003
|
+
foo {bar}\r
|
1004
|
+
baz {a: b}
|
1005
|
+
SCSS
|
1006
|
+
assert(false, "Expected syntax error")
|
1007
|
+
rescue Sass::SyntaxError => e
|
1008
|
+
assert_equal 'Invalid CSS after "foo {bar": expected ":", was "}"', e.message
|
1009
|
+
assert_equal 1, e.sass_line
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
## Regressions
|
1013
|
+
|
1014
|
+
def test_double_space_string
|
1015
|
+
assert_equal(<<CSS, render(<<SCSS))
|
1016
|
+
.a {
|
1017
|
+
content: " a"; }
|
1018
|
+
CSS
|
1019
|
+
.a {
|
1020
|
+
content: " a";
|
1021
|
+
}
|
1022
|
+
SCSS
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
def test_very_long_number_with_important_doesnt_take_forever
|
1026
|
+
assert_equal(<<CSS, render(<<SCSS))
|
1027
|
+
.foo {
|
1028
|
+
width: 97.916666666666666666666666666667% !important; }
|
1029
|
+
CSS
|
1030
|
+
.foo {
|
1031
|
+
width: 97.916666666666666666666666666667% !important;
|
1032
|
+
}
|
1033
|
+
SCSS
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
def test_selector_without_closing_bracket
|
1037
|
+
assert_not_parses('"]"', "foo[bar <err>{a: b}")
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
def test_closing_line_comment_end_with_compact_output
|
1041
|
+
assert_equal(<<CSS, render(<<SCSS, :style => :compact))
|
1042
|
+
/* foo */
|
1043
|
+
bar { baz: bang; }
|
1044
|
+
CSS
|
1045
|
+
/*
|
1046
|
+
* foo
|
1047
|
+
*/
|
1048
|
+
bar {baz: bang}
|
1049
|
+
SCSS
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
def test_single_line_comment_within_multiline_comment
|
1053
|
+
assert_equal(<<CSS, render(<<SCSS))
|
1054
|
+
body {
|
1055
|
+
/*
|
1056
|
+
//comment here
|
1057
|
+
*/ }
|
1058
|
+
CSS
|
1059
|
+
body {
|
1060
|
+
/*
|
1061
|
+
//comment here
|
1062
|
+
*/
|
1063
|
+
}
|
1064
|
+
SCSS
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def test_malformed_media
|
1068
|
+
render <<SCSS
|
1069
|
+
@media {
|
1070
|
+
margin: 0;
|
1071
|
+
}
|
1072
|
+
SCSS
|
1073
|
+
assert(false, "Expected syntax error")
|
1074
|
+
rescue Sass::SyntaxError => e
|
1075
|
+
assert_equal 'Invalid CSS after "@media ": expected media query (e.g. print, screen, print and screen), was "{"', e.message
|
1076
|
+
assert_equal 1, e.sass_line
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
private
|
1080
|
+
|
1081
|
+
def assert_selector_parses(selector)
|
1082
|
+
assert_parses <<SCSS
|
1083
|
+
#{selector} {
|
1084
|
+
a: b; }
|
1085
|
+
SCSS
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
def render(scss, options = {})
|
1089
|
+
tree = Sass::SCSS::CssParser.new(scss, options[:filename]).parse
|
1090
|
+
tree.options = Sass::Engine::DEFAULT_OPTIONS.merge(options)
|
1091
|
+
tree.render
|
1092
|
+
end
|
1093
|
+
end
|