crass 1.0.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +8 -4
- data/HISTORY.md +21 -0
- data/LICENSE +1 -1
- data/README.md +0 -22
- data/Rakefile +5 -4
- data/crass.gemspec +8 -2
- data/lib/crass/parser.rb +15 -15
- data/lib/crass/tokenizer.rb +57 -38
- data/lib/crass/version.rb +1 -1
- metadata +9 -67
- data/test/css-parsing-tests/An+B.json +0 -156
- data/test/css-parsing-tests/LICENSE +0 -8
- data/test/css-parsing-tests/README.rst +0 -301
- data/test/css-parsing-tests/color3.json +0 -142
- data/test/css-parsing-tests/color3_hsl.json +0 -3890
- data/test/css-parsing-tests/color3_keywords.json +0 -803
- data/test/css-parsing-tests/component_value_list.json +0 -432
- data/test/css-parsing-tests/declaration_list.json +0 -44
- data/test/css-parsing-tests/make_color3_hsl.py +0 -17
- data/test/css-parsing-tests/make_color3_keywords.py +0 -191
- data/test/css-parsing-tests/one_component_value.json +0 -27
- data/test/css-parsing-tests/one_declaration.json +0 -46
- data/test/css-parsing-tests/one_rule.json +0 -36
- data/test/css-parsing-tests/rule_list.json +0 -48
- data/test/css-parsing-tests/stylesheet.json +0 -44
- data/test/css-parsing-tests/stylesheet_bytes.json +0 -146
- data/test/shared/parse_rules.rb +0 -463
- data/test/support/common.rb +0 -170
- data/test/support/serialization/animate.css +0 -3158
- data/test/support/serialization/bootstrap-theme.css +0 -384
- data/test/support/serialization/bootstrap.css +0 -6805
- data/test/support/serialization/html5-boilerplate.css +0 -268
- data/test/support/serialization/misc.css +0 -9
- data/test/support/serialization/pure.css +0 -1662
- data/test/test_crass.rb +0 -31
- data/test/test_css_parsing_tests.rb +0 -150
- data/test/test_parse_properties.rb +0 -310
- data/test/test_parse_rules.rb +0 -17
- data/test/test_parse_stylesheet.rb +0 -17
- data/test/test_serialization.rb +0 -71
data/test/shared/parse_rules.rb
DELETED
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
# Includes tests based on Simon Sapin's CSS parsing tests:
|
|
4
|
-
# https://github.com/SimonSapin/css-parsing-tests/
|
|
5
|
-
|
|
6
|
-
shared_tests_for 'parsing a list of rules' do
|
|
7
|
-
it 'should parse an empty stylesheet' do
|
|
8
|
-
assert_equal([], parse(''))
|
|
9
|
-
assert_equal([{:node=>:error, :value=>"invalid"}], parse('foo'))
|
|
10
|
-
assert_equal([{:node=>:error, :value=>"invalid"}], parse('foo 4'))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe 'should parse an at-rule' do
|
|
14
|
-
describe 'without a block' do
|
|
15
|
-
it 'without a prelude' do
|
|
16
|
-
tree = parse('@foo')
|
|
17
|
-
|
|
18
|
-
assert_equal([
|
|
19
|
-
{:node=>:at_rule,
|
|
20
|
-
:name=>"foo",
|
|
21
|
-
:prelude=>[],
|
|
22
|
-
:tokens=>[{:node=>:at_keyword, :pos=>0, :raw=>"@foo", :value=>"foo"}]}
|
|
23
|
-
], tree)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'with a prelude followed by a comment' do
|
|
27
|
-
tree = parse("@foo bar; \t/* comment */")
|
|
28
|
-
|
|
29
|
-
assert_equal([
|
|
30
|
-
{:node=>:at_rule,
|
|
31
|
-
:name=>"foo",
|
|
32
|
-
:prelude=>
|
|
33
|
-
[{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
34
|
-
{:node=>:ident, :pos=>5, :raw=>"bar", :value=>"bar"}],
|
|
35
|
-
:tokens=>
|
|
36
|
-
[{:node=>:at_keyword, :pos=>0, :raw=>"@foo", :value=>"foo"},
|
|
37
|
-
{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
38
|
-
{:node=>:ident, :pos=>5, :raw=>"bar", :value=>"bar"},
|
|
39
|
-
{:node=>:semicolon, :pos=>8, :raw=>";"}]},
|
|
40
|
-
{:node=>:whitespace, :pos=>9, :raw=>" \t"}
|
|
41
|
-
], tree)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'with a prelude followed by a comment, when :preserve_comments == true' do
|
|
45
|
-
options = {:preserve_comments => true}
|
|
46
|
-
tree = parse("@foo bar; \t/* comment */", options)
|
|
47
|
-
|
|
48
|
-
assert_equal([
|
|
49
|
-
{:node=>:at_rule,
|
|
50
|
-
:name=>"foo",
|
|
51
|
-
:prelude=>
|
|
52
|
-
[{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
53
|
-
{:node=>:ident, :pos=>5, :raw=>"bar", :value=>"bar"}],
|
|
54
|
-
:tokens=>
|
|
55
|
-
[{:node=>:at_keyword, :pos=>0, :raw=>"@foo", :value=>"foo"},
|
|
56
|
-
{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
57
|
-
{:node=>:ident, :pos=>5, :raw=>"bar", :value=>"bar"},
|
|
58
|
-
{:node=>:semicolon, :pos=>8, :raw=>";"}]},
|
|
59
|
-
{:node=>:whitespace, :pos=>9, :raw=>" \t"},
|
|
60
|
-
{:node=>:comment, :pos=>11, :raw=>"/* comment */", :value=>" comment "}
|
|
61
|
-
], tree)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'with a prelude containing a simple block' do
|
|
65
|
-
tree = parse("@foo [ bar")
|
|
66
|
-
|
|
67
|
-
assert_equal([
|
|
68
|
-
{:node=>:at_rule,
|
|
69
|
-
:name=>"foo",
|
|
70
|
-
:prelude=>
|
|
71
|
-
[{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
72
|
-
{:node=>:simple_block,
|
|
73
|
-
:start=>"[",
|
|
74
|
-
:end=>"]",
|
|
75
|
-
:value=>
|
|
76
|
-
[{:node=>:whitespace, :pos=>6, :raw=>" "},
|
|
77
|
-
{:node=>:ident, :pos=>7, :raw=>"bar", :value=>"bar"}],
|
|
78
|
-
:tokens=>
|
|
79
|
-
[{:node=>:"[", :pos=>5, :raw=>"["},
|
|
80
|
-
{:node=>:whitespace, :pos=>6, :raw=>" "},
|
|
81
|
-
{:node=>:ident, :pos=>7, :raw=>"bar", :value=>"bar"}]}],
|
|
82
|
-
:tokens=>
|
|
83
|
-
[{:node=>:at_keyword, :pos=>0, :raw=>"@foo", :value=>"foo"},
|
|
84
|
-
{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
85
|
-
{:node=>:"[", :pos=>5, :raw=>"["},
|
|
86
|
-
{:node=>:whitespace, :pos=>6, :raw=>" "},
|
|
87
|
-
{:node=>:ident, :pos=>7, :raw=>"bar", :value=>"bar"}]}
|
|
88
|
-
], tree)
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe 'with a block' do
|
|
93
|
-
it 'unclosed' do
|
|
94
|
-
tree = parse("@foo { bar")
|
|
95
|
-
|
|
96
|
-
assert_equal([
|
|
97
|
-
{:node=>:at_rule,
|
|
98
|
-
:name=>"foo",
|
|
99
|
-
:prelude=>[{:node=>:whitespace, :pos=>4, :raw=>" "}],
|
|
100
|
-
:block=>
|
|
101
|
-
[{:node=>:whitespace, :pos=>6, :raw=>" "},
|
|
102
|
-
{:node=>:ident, :pos=>7, :raw=>"bar", :value=>"bar"}],
|
|
103
|
-
:tokens=>
|
|
104
|
-
[{:node=>:at_keyword, :pos=>0, :raw=>"@foo", :value=>"foo"},
|
|
105
|
-
{:node=>:whitespace, :pos=>4, :raw=>" "},
|
|
106
|
-
{:node=>:"{", :pos=>5, :raw=>"{"},
|
|
107
|
-
{:node=>:whitespace, :pos=>6, :raw=>" "},
|
|
108
|
-
{:node=>:ident, :pos=>7, :raw=>"bar", :value=>"bar"}]}
|
|
109
|
-
], tree)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it 'unclosed, preceded by a comment' do
|
|
113
|
-
tree = parse(" /**/ @foo bar{[(4")
|
|
114
|
-
|
|
115
|
-
assert_equal([
|
|
116
|
-
{:node=>:whitespace, :pos=>0, :raw=>" "},
|
|
117
|
-
{:node=>:whitespace, :pos=>5, :raw=>" "},
|
|
118
|
-
{:node=>:at_rule,
|
|
119
|
-
:name=>"foo",
|
|
120
|
-
:prelude=>
|
|
121
|
-
[{:node=>:whitespace, :pos=>10, :raw=>" "},
|
|
122
|
-
{:node=>:ident, :pos=>11, :raw=>"bar", :value=>"bar"}],
|
|
123
|
-
:block=>
|
|
124
|
-
[{:node=>:simple_block,
|
|
125
|
-
:start=>"[",
|
|
126
|
-
:end=>"]",
|
|
127
|
-
:value=>
|
|
128
|
-
[{:node=>:simple_block,
|
|
129
|
-
:start=>"(",
|
|
130
|
-
:end=>")",
|
|
131
|
-
:value=>
|
|
132
|
-
[{:node=>:number,
|
|
133
|
-
:pos=>17,
|
|
134
|
-
:raw=>"4",
|
|
135
|
-
:repr=>"4",
|
|
136
|
-
:type=>:integer,
|
|
137
|
-
:value=>4}],
|
|
138
|
-
:tokens=>
|
|
139
|
-
[{:node=>:"(", :pos=>16, :raw=>"("},
|
|
140
|
-
{:node=>:number,
|
|
141
|
-
:pos=>17,
|
|
142
|
-
:raw=>"4",
|
|
143
|
-
:repr=>"4",
|
|
144
|
-
:type=>:integer,
|
|
145
|
-
:value=>4}]}],
|
|
146
|
-
:tokens=>
|
|
147
|
-
[{:node=>:"[", :pos=>15, :raw=>"["},
|
|
148
|
-
{:node=>:"(", :pos=>16, :raw=>"("},
|
|
149
|
-
{:node=>:number,
|
|
150
|
-
:pos=>17,
|
|
151
|
-
:raw=>"4",
|
|
152
|
-
:repr=>"4",
|
|
153
|
-
:type=>:integer,
|
|
154
|
-
:value=>4}]}],
|
|
155
|
-
:tokens=>
|
|
156
|
-
[{:node=>:at_keyword, :pos=>6, :raw=>"@foo", :value=>"foo"},
|
|
157
|
-
{:node=>:whitespace, :pos=>10, :raw=>" "},
|
|
158
|
-
{:node=>:ident, :pos=>11, :raw=>"bar", :value=>"bar"},
|
|
159
|
-
{:node=>:"{", :pos=>14, :raw=>"{"},
|
|
160
|
-
{:node=>:"[", :pos=>15, :raw=>"["},
|
|
161
|
-
{:node=>:"(", :pos=>16, :raw=>"("},
|
|
162
|
-
{:node=>:number,
|
|
163
|
-
:pos=>17,
|
|
164
|
-
:raw=>"4",
|
|
165
|
-
:repr=>"4",
|
|
166
|
-
:type=>:integer,
|
|
167
|
-
:value=>4}]}
|
|
168
|
-
], tree)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it 'unclosed, preceded by a comment, when :preserve_comments == true' do
|
|
172
|
-
options = {:preserve_comments => true}
|
|
173
|
-
tree = parse(" /**/ @foo bar{[(4", options)
|
|
174
|
-
|
|
175
|
-
assert_equal([
|
|
176
|
-
{:node=>:whitespace, :pos=>0, :raw=>" "},
|
|
177
|
-
{:node=>:comment, :pos=>1, :raw=>"/**/", :value=>""},
|
|
178
|
-
{:node=>:whitespace, :pos=>5, :raw=>" "},
|
|
179
|
-
{:node=>:at_rule,
|
|
180
|
-
:name=>"foo",
|
|
181
|
-
:prelude=>
|
|
182
|
-
[{:node=>:whitespace, :pos=>10, :raw=>" "},
|
|
183
|
-
{:node=>:ident, :pos=>11, :raw=>"bar", :value=>"bar"}],
|
|
184
|
-
:block=>
|
|
185
|
-
[{:node=>:simple_block,
|
|
186
|
-
:start=>"[",
|
|
187
|
-
:end=>"]",
|
|
188
|
-
:value=>
|
|
189
|
-
[{:node=>:simple_block,
|
|
190
|
-
:start=>"(",
|
|
191
|
-
:end=>")",
|
|
192
|
-
:value=>
|
|
193
|
-
[{:node=>:number,
|
|
194
|
-
:pos=>17,
|
|
195
|
-
:raw=>"4",
|
|
196
|
-
:repr=>"4",
|
|
197
|
-
:type=>:integer,
|
|
198
|
-
:value=>4}],
|
|
199
|
-
:tokens=>
|
|
200
|
-
[{:node=>:"(", :pos=>16, :raw=>"("},
|
|
201
|
-
{:node=>:number,
|
|
202
|
-
:pos=>17,
|
|
203
|
-
:raw=>"4",
|
|
204
|
-
:repr=>"4",
|
|
205
|
-
:type=>:integer,
|
|
206
|
-
:value=>4}]}],
|
|
207
|
-
:tokens=>
|
|
208
|
-
[{:node=>:"[", :pos=>15, :raw=>"["},
|
|
209
|
-
{:node=>:"(", :pos=>16, :raw=>"("},
|
|
210
|
-
{:node=>:number,
|
|
211
|
-
:pos=>17,
|
|
212
|
-
:raw=>"4",
|
|
213
|
-
:repr=>"4",
|
|
214
|
-
:type=>:integer,
|
|
215
|
-
:value=>4}]}],
|
|
216
|
-
:tokens=>
|
|
217
|
-
[{:node=>:at_keyword, :pos=>6, :raw=>"@foo", :value=>"foo"},
|
|
218
|
-
{:node=>:whitespace, :pos=>10, :raw=>" "},
|
|
219
|
-
{:node=>:ident, :pos=>11, :raw=>"bar", :value=>"bar"},
|
|
220
|
-
{:node=>:"{", :pos=>14, :raw=>"{"},
|
|
221
|
-
{:node=>:"[", :pos=>15, :raw=>"["},
|
|
222
|
-
{:node=>:"(", :pos=>16, :raw=>"("},
|
|
223
|
-
{:node=>:number,
|
|
224
|
-
:pos=>17,
|
|
225
|
-
:raw=>"4",
|
|
226
|
-
:repr=>"4",
|
|
227
|
-
:type=>:integer,
|
|
228
|
-
:value=>4}]}
|
|
229
|
-
], tree)
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
describe 'should parse a style rule' do
|
|
236
|
-
it 'with preceding comment, selector, block, comment' do
|
|
237
|
-
tree = parse(" /**/ div > p { color: #aaa; } /**/ ")
|
|
238
|
-
|
|
239
|
-
assert_equal([
|
|
240
|
-
{:node=>:whitespace, :pos=>0, :raw=>" "},
|
|
241
|
-
{:node=>:whitespace, :pos=>5, :raw=>" "},
|
|
242
|
-
{:node=>:style_rule,
|
|
243
|
-
:selector=>
|
|
244
|
-
{:node=>:selector,
|
|
245
|
-
:value=>"div > p",
|
|
246
|
-
:tokens=>
|
|
247
|
-
[{:node=>:ident, :pos=>6, :raw=>"div", :value=>"div"},
|
|
248
|
-
{:node=>:whitespace, :pos=>9, :raw=>" "},
|
|
249
|
-
{:node=>:delim, :pos=>10, :raw=>">", :value=>">"},
|
|
250
|
-
{:node=>:whitespace, :pos=>11, :raw=>" "},
|
|
251
|
-
{:node=>:ident, :pos=>12, :raw=>"p", :value=>"p"},
|
|
252
|
-
{:node=>:whitespace, :pos=>13, :raw=>" "}]},
|
|
253
|
-
:children=>
|
|
254
|
-
[{:node=>:whitespace, :pos=>15, :raw=>" "},
|
|
255
|
-
{:node=>:property,
|
|
256
|
-
:name=>"color",
|
|
257
|
-
:value=>"#aaa",
|
|
258
|
-
:children=>
|
|
259
|
-
[{:node=>:whitespace, :pos=>22, :raw=>" "},
|
|
260
|
-
{:node=>:hash, :pos=>23, :raw=>"#aaa", :type=>:id, :value=>"aaa"}],
|
|
261
|
-
:important=>false,
|
|
262
|
-
:tokens=>
|
|
263
|
-
[{:node=>:ident, :pos=>16, :raw=>"color", :value=>"color"},
|
|
264
|
-
{:node=>:colon, :pos=>21, :raw=>":"},
|
|
265
|
-
{:node=>:whitespace, :pos=>22, :raw=>" "},
|
|
266
|
-
{:node=>:hash, :pos=>23, :raw=>"#aaa", :type=>:id, :value=>"aaa"}]},
|
|
267
|
-
{:node=>:semicolon, :pos=>27, :raw=>";"},
|
|
268
|
-
{:node=>:whitespace, :pos=>28, :raw=>" "}]},
|
|
269
|
-
{:node=>:whitespace, :pos=>31, :raw=>" "},
|
|
270
|
-
{:node=>:whitespace, :pos=>36, :raw=>" "}
|
|
271
|
-
], tree)
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it 'with preceding comment, selector, block, comment, when :preserve_comments == true' do
|
|
275
|
-
options = {:preserve_comments => true}
|
|
276
|
-
tree = parse(" /**/ div > p { color: #aaa; } /**/ ", options)
|
|
277
|
-
|
|
278
|
-
assert_equal([
|
|
279
|
-
{:node=>:whitespace, :pos=>0, :raw=>" "},
|
|
280
|
-
{:node=>:comment, :pos=>1, :raw=>"/**/", :value=>""},
|
|
281
|
-
{:node=>:whitespace, :pos=>5, :raw=>" "},
|
|
282
|
-
{:node=>:style_rule,
|
|
283
|
-
:selector=>
|
|
284
|
-
{:node=>:selector,
|
|
285
|
-
:value=>"div > p",
|
|
286
|
-
:tokens=>
|
|
287
|
-
[{:node=>:ident, :pos=>6, :raw=>"div", :value=>"div"},
|
|
288
|
-
{:node=>:whitespace, :pos=>9, :raw=>" "},
|
|
289
|
-
{:node=>:delim, :pos=>10, :raw=>">", :value=>">"},
|
|
290
|
-
{:node=>:whitespace, :pos=>11, :raw=>" "},
|
|
291
|
-
{:node=>:ident, :pos=>12, :raw=>"p", :value=>"p"},
|
|
292
|
-
{:node=>:whitespace, :pos=>13, :raw=>" "}]},
|
|
293
|
-
:children=>
|
|
294
|
-
[{:node=>:whitespace, :pos=>15, :raw=>" "},
|
|
295
|
-
{:node=>:property,
|
|
296
|
-
:name=>"color",
|
|
297
|
-
:value=>"#aaa",
|
|
298
|
-
:children=>
|
|
299
|
-
[{:node=>:whitespace, :pos=>22, :raw=>" "},
|
|
300
|
-
{:node=>:hash, :pos=>23, :raw=>"#aaa", :type=>:id, :value=>"aaa"}],
|
|
301
|
-
:important=>false,
|
|
302
|
-
:tokens=>
|
|
303
|
-
[{:node=>:ident, :pos=>16, :raw=>"color", :value=>"color"},
|
|
304
|
-
{:node=>:colon, :pos=>21, :raw=>":"},
|
|
305
|
-
{:node=>:whitespace, :pos=>22, :raw=>" "},
|
|
306
|
-
{:node=>:hash, :pos=>23, :raw=>"#aaa", :type=>:id, :value=>"aaa"}]},
|
|
307
|
-
{:node=>:semicolon, :pos=>27, :raw=>";"},
|
|
308
|
-
{:node=>:whitespace, :pos=>28, :raw=>" "}]},
|
|
309
|
-
{:node=>:whitespace, :pos=>31, :raw=>" "},
|
|
310
|
-
{:node=>:comment, :pos=>32, :raw=>"/**/", :value=>""},
|
|
311
|
-
{:node=>:whitespace, :pos=>36, :raw=>" "}
|
|
312
|
-
], tree)
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
it 'should parse property values containing functions' do
|
|
317
|
-
tree = parse("p:before { content: a\\ttr(data-foo) \" \"; }")
|
|
318
|
-
|
|
319
|
-
assert_equal([
|
|
320
|
-
{:node=>:style_rule,
|
|
321
|
-
:selector=>
|
|
322
|
-
{:node=>:selector,
|
|
323
|
-
:value=>"p:before",
|
|
324
|
-
:tokens=>
|
|
325
|
-
[{:node=>:ident, :pos=>0, :raw=>"p", :value=>"p"},
|
|
326
|
-
{:node=>:colon, :pos=>1, :raw=>":"},
|
|
327
|
-
{:node=>:ident, :pos=>2, :raw=>"before", :value=>"before"},
|
|
328
|
-
{:node=>:whitespace, :pos=>8, :raw=>" "}]},
|
|
329
|
-
:children=>
|
|
330
|
-
[{:node=>:whitespace, :pos=>10, :raw=>" "},
|
|
331
|
-
{:node=>:property,
|
|
332
|
-
:name=>"content",
|
|
333
|
-
:value=>"attr(data-foo) \" \"",
|
|
334
|
-
:children=>
|
|
335
|
-
[{:node=>:whitespace, :pos=>19, :raw=>" "},
|
|
336
|
-
{:node=>:function,
|
|
337
|
-
:name=>"attr",
|
|
338
|
-
:value=>
|
|
339
|
-
[{:node=>:ident, :pos=>26, :raw=>"data-foo", :value=>"data-foo"}],
|
|
340
|
-
:tokens=>
|
|
341
|
-
[{:node=>:function, :pos=>20, :raw=>"a\\ttr(", :value=>"attr"},
|
|
342
|
-
{:node=>:ident, :pos=>26, :raw=>"data-foo", :value=>"data-foo"},
|
|
343
|
-
{:node=>:")", :pos=>34, :raw=>")"}]},
|
|
344
|
-
{:node=>:whitespace, :pos=>35, :raw=>" "},
|
|
345
|
-
{:node=>:string, :pos=>36, :raw=>"\" \"", :value=>" "}],
|
|
346
|
-
:important=>false,
|
|
347
|
-
:tokens=>
|
|
348
|
-
[{:node=>:ident, :pos=>11, :raw=>"content", :value=>"content"},
|
|
349
|
-
{:node=>:colon, :pos=>18, :raw=>":"},
|
|
350
|
-
{:node=>:whitespace, :pos=>19, :raw=>" "},
|
|
351
|
-
{:node=>:function,
|
|
352
|
-
:name=>"attr",
|
|
353
|
-
:value=>
|
|
354
|
-
[{:node=>:ident, :pos=>26, :raw=>"data-foo", :value=>"data-foo"}],
|
|
355
|
-
:tokens=>
|
|
356
|
-
[{:node=>:function, :pos=>20, :raw=>"a\\ttr(", :value=>"attr"},
|
|
357
|
-
{:node=>:ident, :pos=>26, :raw=>"data-foo", :value=>"data-foo"},
|
|
358
|
-
{:node=>:")", :pos=>34, :raw=>")"}]},
|
|
359
|
-
{:node=>:whitespace, :pos=>35, :raw=>" "},
|
|
360
|
-
{:node=>:string, :pos=>36, :raw=>"\" \"", :value=>" "}]},
|
|
361
|
-
{:node=>:semicolon, :pos=>39, :raw=>";"},
|
|
362
|
-
{:node=>:whitespace, :pos=>40, :raw=>" "}]}
|
|
363
|
-
], tree)
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it 'should parse property values containing nested functions' do
|
|
367
|
-
tree = parse("div { width: e\\78 pression(alert(1)); }")
|
|
368
|
-
|
|
369
|
-
assert_equal([
|
|
370
|
-
{:node=>:style_rule,
|
|
371
|
-
:selector=>
|
|
372
|
-
{:node=>:selector,
|
|
373
|
-
:value=>"div",
|
|
374
|
-
:tokens=>
|
|
375
|
-
[{:node=>:ident, :pos=>0, :raw=>"div", :value=>"div"},
|
|
376
|
-
{:node=>:whitespace, :pos=>3, :raw=>" "}]},
|
|
377
|
-
:children=>
|
|
378
|
-
[{:node=>:whitespace, :pos=>5, :raw=>" "},
|
|
379
|
-
{:node=>:property,
|
|
380
|
-
:name=>"width",
|
|
381
|
-
:value=>"expression(alert(1))",
|
|
382
|
-
:children=>
|
|
383
|
-
[{:node=>:whitespace, :pos=>12, :raw=>" "},
|
|
384
|
-
{:node=>:function,
|
|
385
|
-
:name=>"expression",
|
|
386
|
-
:value=>
|
|
387
|
-
[{:node=>:function,
|
|
388
|
-
:name=>"alert",
|
|
389
|
-
:value=>
|
|
390
|
-
[{:node=>:number,
|
|
391
|
-
:pos=>33,
|
|
392
|
-
:raw=>"1",
|
|
393
|
-
:repr=>"1",
|
|
394
|
-
:type=>:integer,
|
|
395
|
-
:value=>1}],
|
|
396
|
-
:tokens=>
|
|
397
|
-
[{:node=>:function, :pos=>27, :raw=>"alert(", :value=>"alert"},
|
|
398
|
-
{:node=>:number,
|
|
399
|
-
:pos=>33,
|
|
400
|
-
:raw=>"1",
|
|
401
|
-
:repr=>"1",
|
|
402
|
-
:type=>:integer,
|
|
403
|
-
:value=>1},
|
|
404
|
-
{:node=>:")", :pos=>34, :raw=>")"}]}],
|
|
405
|
-
:tokens=>
|
|
406
|
-
[{:node=>:function,
|
|
407
|
-
:pos=>13,
|
|
408
|
-
:raw=>"e\\78 pression(",
|
|
409
|
-
:value=>"expression"},
|
|
410
|
-
{:node=>:function, :pos=>27, :raw=>"alert(", :value=>"alert"},
|
|
411
|
-
{:node=>:number,
|
|
412
|
-
:pos=>33,
|
|
413
|
-
:raw=>"1",
|
|
414
|
-
:repr=>"1",
|
|
415
|
-
:type=>:integer,
|
|
416
|
-
:value=>1},
|
|
417
|
-
{:node=>:")", :pos=>34, :raw=>")"},
|
|
418
|
-
{:node=>:")", :pos=>35, :raw=>")"}]}],
|
|
419
|
-
:important=>false,
|
|
420
|
-
:tokens=>
|
|
421
|
-
[{:node=>:ident, :pos=>6, :raw=>"width", :value=>"width"},
|
|
422
|
-
{:node=>:colon, :pos=>11, :raw=>":"},
|
|
423
|
-
{:node=>:whitespace, :pos=>12, :raw=>" "},
|
|
424
|
-
{:node=>:function,
|
|
425
|
-
:name=>"expression",
|
|
426
|
-
:value=>
|
|
427
|
-
[{:node=>:function,
|
|
428
|
-
:name=>"alert",
|
|
429
|
-
:value=>
|
|
430
|
-
[{:node=>:number,
|
|
431
|
-
:pos=>33,
|
|
432
|
-
:raw=>"1",
|
|
433
|
-
:repr=>"1",
|
|
434
|
-
:type=>:integer,
|
|
435
|
-
:value=>1}],
|
|
436
|
-
:tokens=>
|
|
437
|
-
[{:node=>:function, :pos=>27, :raw=>"alert(", :value=>"alert"},
|
|
438
|
-
{:node=>:number,
|
|
439
|
-
:pos=>33,
|
|
440
|
-
:raw=>"1",
|
|
441
|
-
:repr=>"1",
|
|
442
|
-
:type=>:integer,
|
|
443
|
-
:value=>1},
|
|
444
|
-
{:node=>:")", :pos=>34, :raw=>")"}]}],
|
|
445
|
-
:tokens=>
|
|
446
|
-
[{:node=>:function,
|
|
447
|
-
:pos=>13,
|
|
448
|
-
:raw=>"e\\78 pression(",
|
|
449
|
-
:value=>"expression"},
|
|
450
|
-
{:node=>:function, :pos=>27, :raw=>"alert(", :value=>"alert"},
|
|
451
|
-
{:node=>:number,
|
|
452
|
-
:pos=>33,
|
|
453
|
-
:raw=>"1",
|
|
454
|
-
:repr=>"1",
|
|
455
|
-
:type=>:integer,
|
|
456
|
-
:value=>1},
|
|
457
|
-
{:node=>:")", :pos=>34, :raw=>")"},
|
|
458
|
-
{:node=>:")", :pos=>35, :raw=>")"}]}]},
|
|
459
|
-
{:node=>:semicolon, :pos=>36, :raw=>";"},
|
|
460
|
-
{:node=>:whitespace, :pos=>37, :raw=>" "}]}
|
|
461
|
-
], tree)
|
|
462
|
-
end
|
|
463
|
-
end
|
data/test/support/common.rb
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
gem 'minitest'
|
|
3
|
-
require 'minitest/autorun'
|
|
4
|
-
|
|
5
|
-
require_relative '../../lib/crass'
|
|
6
|
-
|
|
7
|
-
CP = Crass::Parser
|
|
8
|
-
CT = Crass::Tokenizer
|
|
9
|
-
|
|
10
|
-
# Hack shared test support into MiniTest.
|
|
11
|
-
MiniTest::Spec.class_eval do
|
|
12
|
-
def self.shared_tests
|
|
13
|
-
@shared_tests ||= {}
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
module MiniTest::Spec::SharedTests
|
|
18
|
-
def behaves_like(desc)
|
|
19
|
-
self.instance_eval(&MiniTest::Spec.shared_tests[desc])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def shared_tests_for(desc, &block)
|
|
23
|
-
MiniTest::Spec.shared_tests[desc] = block
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
Object.class_eval { include MiniTest::Spec::SharedTests }
|
|
28
|
-
|
|
29
|
-
# Custom assertions and helpers.
|
|
30
|
-
def assert_tokens(input, actual, offset = 0, options = {})
|
|
31
|
-
actual = [actual] unless actual.is_a?(Array)
|
|
32
|
-
tokens = tokenize(input, offset, options)
|
|
33
|
-
|
|
34
|
-
assert_equal tokens, actual
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def reposition_tokens(tokens, offset)
|
|
38
|
-
tokens.each {|token| token[:pos] += offset }
|
|
39
|
-
tokens
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def tokenize(input, offset = 0, options = {})
|
|
43
|
-
tokens = CT.tokenize(input, options)
|
|
44
|
-
reposition_tokens(tokens, offset) unless offset == 0
|
|
45
|
-
tokens
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Translates Crass tokens into a form that can be compared to the expected
|
|
49
|
-
# values of Simon Sapin's CSS parsing tests.
|
|
50
|
-
#
|
|
51
|
-
# https://github.com/SimonSapin/css-parsing-tests/#result-representation
|
|
52
|
-
def translate_tokens(tokens)
|
|
53
|
-
return [] if tokens.nil?
|
|
54
|
-
|
|
55
|
-
translated = []
|
|
56
|
-
tokens = [tokens] unless tokens.is_a?(Array)
|
|
57
|
-
|
|
58
|
-
tokens.each do |token|
|
|
59
|
-
value = token[:value]
|
|
60
|
-
|
|
61
|
-
result = case token[:node]
|
|
62
|
-
|
|
63
|
-
# Rules and declarations.
|
|
64
|
-
when :at_rule
|
|
65
|
-
['at-rule', token[:name], translate_tokens(token[:prelude]), token[:block] ? translate_tokens(token[:block]) : nil]
|
|
66
|
-
|
|
67
|
-
when :qualified_rule
|
|
68
|
-
['qualified rule', translate_tokens(token[:prelude]), token[:block] ? translate_tokens(token[:block]) : nil]
|
|
69
|
-
|
|
70
|
-
when :declaration
|
|
71
|
-
['declaration', token[:name], translate_tokens(value), token[:important]]
|
|
72
|
-
|
|
73
|
-
# Component values.
|
|
74
|
-
when :at_keyword
|
|
75
|
-
['at-keyword', value]
|
|
76
|
-
|
|
77
|
-
when :bad_string
|
|
78
|
-
['error', 'bad-string']
|
|
79
|
-
|
|
80
|
-
when :bad_url
|
|
81
|
-
['error', 'bad-url']
|
|
82
|
-
|
|
83
|
-
when :cdc
|
|
84
|
-
'-->'
|
|
85
|
-
|
|
86
|
-
when :cdo
|
|
87
|
-
'<!--'
|
|
88
|
-
|
|
89
|
-
when :colon
|
|
90
|
-
':'
|
|
91
|
-
|
|
92
|
-
when :column
|
|
93
|
-
'||'
|
|
94
|
-
|
|
95
|
-
when :comma
|
|
96
|
-
','
|
|
97
|
-
|
|
98
|
-
when :dash_match
|
|
99
|
-
'|='
|
|
100
|
-
|
|
101
|
-
when :delim
|
|
102
|
-
value
|
|
103
|
-
|
|
104
|
-
when :dimension
|
|
105
|
-
['dimension', token[:repr], value, token[:type].to_s, token[:unit]]
|
|
106
|
-
|
|
107
|
-
when :error
|
|
108
|
-
['error', value]
|
|
109
|
-
|
|
110
|
-
when :function
|
|
111
|
-
if token[:name]
|
|
112
|
-
['function', token[:name]].concat(translate_tokens(value))
|
|
113
|
-
else
|
|
114
|
-
['function', value]
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
when :hash
|
|
118
|
-
['hash', value, token[:type].to_s]
|
|
119
|
-
|
|
120
|
-
when :ident
|
|
121
|
-
['ident', value]
|
|
122
|
-
|
|
123
|
-
when :include_match
|
|
124
|
-
'~='
|
|
125
|
-
|
|
126
|
-
when :number
|
|
127
|
-
['number', token[:repr], value, token[:type].to_s]
|
|
128
|
-
|
|
129
|
-
when :percentage
|
|
130
|
-
['percentage', token[:repr], value, token[:type].to_s]
|
|
131
|
-
|
|
132
|
-
when :prefix_match
|
|
133
|
-
'^='
|
|
134
|
-
|
|
135
|
-
when :semicolon
|
|
136
|
-
';'
|
|
137
|
-
|
|
138
|
-
when :simple_block
|
|
139
|
-
[token[:start] + token[:end]].concat(translate_tokens(value))
|
|
140
|
-
|
|
141
|
-
when :string
|
|
142
|
-
['string', value]
|
|
143
|
-
|
|
144
|
-
when :substring_match
|
|
145
|
-
'*='
|
|
146
|
-
|
|
147
|
-
when :suffix_match
|
|
148
|
-
'$='
|
|
149
|
-
|
|
150
|
-
when :unicode_range
|
|
151
|
-
['unicode-range', token[:start], token[:end]]
|
|
152
|
-
|
|
153
|
-
when :url
|
|
154
|
-
['url', value]
|
|
155
|
-
|
|
156
|
-
when :whitespace
|
|
157
|
-
' '
|
|
158
|
-
|
|
159
|
-
when :'}', :']', :')'
|
|
160
|
-
['error', token[:node].to_s]
|
|
161
|
-
|
|
162
|
-
else
|
|
163
|
-
nil
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
translated << result unless result.nil?
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
translated
|
|
170
|
-
end
|