csspool 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +4 -0
- data/Manifest.txt +32 -0
- data/README.txt +71 -0
- data/Rakefile +56 -0
- data/lib/css/sac/attribute_condition.rb +78 -0
- data/lib/css/sac/condition.rb +21 -0
- data/lib/css/sac/document_handler.rb +67 -0
- data/lib/css/sac/error_handler.rb +14 -0
- data/lib/css/sac/generated_property_parser.rb +9214 -0
- data/lib/css/sac/lexeme.rb +29 -0
- data/lib/css/sac/lexical_unit.rb +111 -0
- data/lib/css/sac/parse_exception.rb +6 -0
- data/lib/css/sac/parser.rb +98 -0
- data/lib/css/sac/property_parser.rb +47 -0
- data/lib/css/sac/selectors.rb +87 -0
- data/lib/css/sac/token.rb +27 -0
- data/lib/css/sac/tokenizer.rb +186 -0
- data/lib/css/sac.rb +13 -0
- data/lib/parser.y +287 -0
- data/lib/property_parser.y +2346 -0
- data/lib/property_parser.y.erb +1321 -0
- data/test/helper.rb +7 -0
- data/test/test_all.rb +4 -0
- data/test/test_lexeme.rb +39 -0
- data/test/test_lexical_unit.rb +96 -0
- data/test/test_parse_error.rb +199 -0
- data/test/test_parser.rb +183 -0
- data/test/test_property_parser.rb +593 -0
- data/test/test_selector_as_string.rb +83 -0
- data/test/test_selector_parser.rb +170 -0
- data/test/test_token.rb +24 -0
- data/test/test_tokenizer.rb +117 -0
- metadata +88 -0
@@ -0,0 +1,593 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class PropertyParserTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tokenizer = CSS::SAC::Tokenizer.new()
|
6
|
+
@property_parser = CSS::SAC::PropertyParser.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_error
|
10
|
+
tokens = @tokenizer.tokenize("h1 { azimuth: blahblah; }").find_all { |x|
|
11
|
+
![:LBRACE, :S].include?(x.name) &&
|
12
|
+
!['h1', '}', ':', ';'].include?(x.value)
|
13
|
+
}
|
14
|
+
assert_nil(@property_parser.parse_tokens(tokens))
|
15
|
+
end
|
16
|
+
|
17
|
+
@@valid_value_tests = {
|
18
|
+
:azimuth => {
|
19
|
+
:values => [ '10deg', 'left-side', 'far-left', 'left', 'center-left',
|
20
|
+
'right', 'far-right', 'right-side', 'behind', 'left behind',
|
21
|
+
'leftwards', 'rightwards', 'inherit'
|
22
|
+
],
|
23
|
+
:unit_types => [ :SAC_DEGREE, nil, nil, nil, nil, nil, nil, nil, nil,
|
24
|
+
[:SAC_IDENT, :SAC_IDENT], nil, nil, nil ],
|
25
|
+
},
|
26
|
+
|
27
|
+
'background-attachment' => {
|
28
|
+
:values => [ 'scroll', 'fixed', 'inherit' ],
|
29
|
+
:unit_types => [nil, nil, nil],
|
30
|
+
},
|
31
|
+
|
32
|
+
'background-color' => {
|
33
|
+
:values => ['red', '#FFFFFF', 'transparent', 'inherit'],
|
34
|
+
:unit_types => [nil, :SAC_RGBCOLOR, nil, nil ],
|
35
|
+
},
|
36
|
+
|
37
|
+
'background-image' => {
|
38
|
+
:values => [ 'url("http://example.com/test.png")', 'none', 'inherit'],
|
39
|
+
:unit_types => [ :SAC_URI, nil, nil ],
|
40
|
+
},
|
41
|
+
|
42
|
+
'background-position' => {
|
43
|
+
:values => [ '10%', '10px', 'left', 'center', 'right',
|
44
|
+
'10% 10%', '10% top', 'left center',
|
45
|
+
'center left', 'inherit'],
|
46
|
+
:unit_types => [ :SAC_PERCENTAGE, :SAC_PIXEL, nil, nil, nil,
|
47
|
+
[:SAC_PERCENTAGE, :SAC_PERCENTAGE], [:SAC_PERCENTAGE, nil], [nil,nil],
|
48
|
+
[nil, nil], nil ],
|
49
|
+
},
|
50
|
+
|
51
|
+
'background-repeat' => {
|
52
|
+
:values => ['repeat', 'repeat-x', 'repeat-y', 'no-repeat',
|
53
|
+
'inherit'],
|
54
|
+
:unit_types => [nil, nil, nil, nil, nil],
|
55
|
+
},
|
56
|
+
|
57
|
+
'background' => {
|
58
|
+
:values => ['red', 'url("http://example.com/test.png")', 'repeat',
|
59
|
+
'scroll', 'left', 'red repeat', 'repeat red'],
|
60
|
+
:unit_types => [nil, :SAC_URI, nil,
|
61
|
+
nil, nil, [nil, nil], [nil, nil]],
|
62
|
+
},
|
63
|
+
|
64
|
+
'border-collapse' => {
|
65
|
+
:values => ['collapse', 'separate', 'inherit'],
|
66
|
+
:unit_types => [nil, nil, nil],
|
67
|
+
},
|
68
|
+
|
69
|
+
'border-color' => {
|
70
|
+
:values => ['black', '#aaa', 'black red blue green', 'black red',
|
71
|
+
'black red #aaa', 'inherit'],
|
72
|
+
:unit_types => [nil, :SAC_RGBCOLOR, [nil, nil, nil, nil], [nil, nil],
|
73
|
+
[nil, nil, :SAC_RGBCOLOR], nil],
|
74
|
+
},
|
75
|
+
|
76
|
+
'border-spacing' => {
|
77
|
+
:values => ['0.5em', '10px 0.5em', 'inherit'],
|
78
|
+
:unit_types => [:SAC_EM, [:SAC_PIXEL, :SAC_EM], nil],
|
79
|
+
},
|
80
|
+
|
81
|
+
'border-style' => {
|
82
|
+
:values => ['none', 'hidden dotted', 'dashed solid groove',
|
83
|
+
'outset inset ridge double'],
|
84
|
+
:unit_types => [nil, [nil, nil], [nil, nil, nil], [nil,nil,nil,nil]],
|
85
|
+
},
|
86
|
+
|
87
|
+
[ 'border-top',
|
88
|
+
'border-right',
|
89
|
+
'border-bottom',
|
90
|
+
'border-left' ] => {
|
91
|
+
:values => ['thin', 'red', 'hidden', '10px dashed',
|
92
|
+
'medium red dashed', 'inherit'],
|
93
|
+
:unit_types => [nil, nil, nil, [:SAC_PIXEL, nil], [nil, nil, nil], nil],
|
94
|
+
},
|
95
|
+
|
96
|
+
[ 'border-top-color',
|
97
|
+
'border-right-color',
|
98
|
+
'border-bottom-color',
|
99
|
+
'border-left-color' ] => {
|
100
|
+
:values => ['#fff', 'green', 'transparent', 'inherit'],
|
101
|
+
:unit_types => [:SAC_RGBCOLOR, nil, nil, nil],
|
102
|
+
},
|
103
|
+
|
104
|
+
[ 'border-top-style',
|
105
|
+
'border-right-style',
|
106
|
+
'border-bottom-style',
|
107
|
+
'border-left-style' ] => {
|
108
|
+
:values => ['none', 'dotted', 'dashed', 'inherit'],
|
109
|
+
:unit_types => [nil, nil, nil, nil],
|
110
|
+
},
|
111
|
+
|
112
|
+
[ 'border-top-width',
|
113
|
+
'border-right-width',
|
114
|
+
'border-bottom-width',
|
115
|
+
'border-left-width' ] => {
|
116
|
+
:values => ['thin', 'medium', 'thick', '10px', 'inherit'],
|
117
|
+
:unit_types => [nil, nil, nil, :SAC_PIXEL, nil],
|
118
|
+
},
|
119
|
+
|
120
|
+
'border-width' => {
|
121
|
+
:values => ['thin', 'medium thin', 'thin medium 10px',
|
122
|
+
'thin thick 10px medium', 'inherit' ],
|
123
|
+
:unit_types => [nil, [nil, nil], [nil, nil, :SAC_PIXEL],
|
124
|
+
[nil, nil, :SAC_PIXEL, nil], nil],
|
125
|
+
},
|
126
|
+
|
127
|
+
'border' => {
|
128
|
+
:values => [ 'thin', 'thin dotted', 'thin red dotted', 'inherit'],
|
129
|
+
:unit_types => [nil, [nil, nil], [nil, nil, nil], nil]
|
130
|
+
},
|
131
|
+
|
132
|
+
'bottom' => {
|
133
|
+
:values => ['10em', '100%', 'auto', 'inherit'],
|
134
|
+
:unit_types => [:SAC_EM, :SAC_PERCENTAGE, nil, nil],
|
135
|
+
},
|
136
|
+
|
137
|
+
'caption-side' => {
|
138
|
+
:values => ['top', 'bottom', 'inherit'],
|
139
|
+
:unit_types => [nil, nil, nil],
|
140
|
+
},
|
141
|
+
|
142
|
+
'clear' => {
|
143
|
+
:values => ['none', 'left', 'right', 'both', 'inherit'],
|
144
|
+
:unit_types => [nil, nil, nil, nil, nil],
|
145
|
+
},
|
146
|
+
|
147
|
+
'clip' => {
|
148
|
+
:values => ['auto', 'rect(5px, 40px, 45px, 5px)', 'inherit'],
|
149
|
+
:unit_types => [nil, :SAC_RECT_FUNCTION, nil],
|
150
|
+
},
|
151
|
+
|
152
|
+
'color' => {
|
153
|
+
:values => ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime',
|
154
|
+
'maroon', 'navy', 'olive', 'orange', 'purple', 'red', 'silver',
|
155
|
+
'teal', 'white', 'yellow', '#f00', '#aabbcc'],
|
156
|
+
:unit_types => [nil, nil, nil, nil, nil, nil, nil,
|
157
|
+
nil, nil, nil, nil, nil, nil, nil,
|
158
|
+
nil, nil, nil, :SAC_RGBCOLOR, :SAC_RGBCOLOR],
|
159
|
+
},
|
160
|
+
|
161
|
+
'content' => {
|
162
|
+
:values => ['normal', 'none', '"test"', 'open-quote "foo"',
|
163
|
+
'url("http://example.com/test.png")', 'inherit', 'attr(foo)'],
|
164
|
+
:unit_types => [nil, nil, :SAC_STRING_VALUE, [nil, :SAC_STRING_VALUE],
|
165
|
+
:SAC_URI, nil, :SAC_FUNCTION],
|
166
|
+
},
|
167
|
+
|
168
|
+
[ 'counter-increment',
|
169
|
+
'counter-reset' ] => {
|
170
|
+
:values => ['foo 10', 'foo', 'none', 'foo 10 bar 20','inherit'],
|
171
|
+
:unit_types => [[nil, :SAC_INTEGER], nil, nil,
|
172
|
+
[nil, :SAC_INTEGER, nil, :SAC_INTEGER], nil],
|
173
|
+
},
|
174
|
+
|
175
|
+
[ 'cue-after',
|
176
|
+
'cue-before' ] => {
|
177
|
+
:values => ['none', 'url("http://tenderlovemaking.com")',
|
178
|
+
'inherit'],
|
179
|
+
:unit_types => [nil, :SAC_URI, nil],
|
180
|
+
},
|
181
|
+
|
182
|
+
'cue' => {
|
183
|
+
:values => ['none url("http://tenderlovemaking.com")', 'none', 'inherit'],
|
184
|
+
:unit_types => [[nil, :SAC_URI], nil, nil],
|
185
|
+
},
|
186
|
+
|
187
|
+
'cursor' => {
|
188
|
+
:values => [ 'url("http://tenderlovemaking.com"), url("http://tenderlovemaking.com") auto', 'inherit' ] +
|
189
|
+
[
|
190
|
+
'auto', 'crosshair', 'default', 'pointer', 'move',
|
191
|
+
'e-resize', 'ne-resize', 'nw-resize', 'n-resize',
|
192
|
+
'se-resize', 'sw-resize', 's-resize', 'w-resize', 'text',
|
193
|
+
'wait', 'help', 'progress' ].map { |x|
|
194
|
+
"url(\"http://tenderlovemaking.com/\") #{x}"
|
195
|
+
},
|
196
|
+
:unit_types => [[:SAC_URI, :SAC_URI, nil], nil] + [[:SAC_URI, nil]] * 17,
|
197
|
+
},
|
198
|
+
|
199
|
+
'direction' => {
|
200
|
+
:values => [ 'ltr', 'rtl', 'inherit' ],
|
201
|
+
:unit_types => [nil, nil, nil],
|
202
|
+
},
|
203
|
+
|
204
|
+
'display' => {
|
205
|
+
:values => [ 'inline', 'block', 'list-item', 'run-in', 'inline-block',
|
206
|
+
'table', 'inline-table', 'table-row-group',
|
207
|
+
'table-header-group', 'table-footer-group', 'table-row',
|
208
|
+
'table-column-group', 'table-column', 'table-cell',
|
209
|
+
'table-caption', 'none', 'inherit' ],
|
210
|
+
:unit_types => [nil] * 17,
|
211
|
+
},
|
212
|
+
|
213
|
+
'elevation' => {
|
214
|
+
:values => ['98deg', 'below', 'level', 'above', 'higher', 'lower',
|
215
|
+
'inherit'],
|
216
|
+
:unit_types => [:SAC_DEGREE] + [nil] * 6,
|
217
|
+
},
|
218
|
+
|
219
|
+
'empty-cells' => {
|
220
|
+
:values => ['show', 'hide', 'inherit'],
|
221
|
+
:unit_types => [nil, nil, nil],
|
222
|
+
},
|
223
|
+
|
224
|
+
'float' => {
|
225
|
+
:values => ['left', 'right', 'none', 'inherit'],
|
226
|
+
:unit_types => [nil, nil, nil, nil],
|
227
|
+
},
|
228
|
+
|
229
|
+
'font-family' => {
|
230
|
+
:values => ['Gill', 'Gill, serif', '"Aaron P", sans-serif',
|
231
|
+
'serif, sans-serif', 'serif', 'sans-serif', 'cursive',
|
232
|
+
'fantasy', 'monospace', 'inherit' ],
|
233
|
+
:unit_types => [nil, [nil, nil], [:SAC_STRING_VALUE, nil], [nil, nil],
|
234
|
+
nil, nil],
|
235
|
+
},
|
236
|
+
|
237
|
+
'font-size' => {
|
238
|
+
:values => ['xx-small', 'x-small', 'small', 'medium', 'large',
|
239
|
+
'x-large', 'xx-large', 'larger', 'smaller', '10in',
|
240
|
+
'50%', 'inherit'],
|
241
|
+
:unit_types => [nil] * 9 + [:SAC_INCH, :SAC_PERCENTAGE, nil]
|
242
|
+
},
|
243
|
+
|
244
|
+
'font-style' => {
|
245
|
+
:values => ['normal', 'italic', 'oblique', 'inherit'],
|
246
|
+
:unit_types => [nil] * 4,
|
247
|
+
},
|
248
|
+
|
249
|
+
'font-variant'=> {
|
250
|
+
:values => ['normal', 'small-caps', 'inherit'],
|
251
|
+
:unit_types => [nil] * 3,
|
252
|
+
},
|
253
|
+
|
254
|
+
'font-weight' => {
|
255
|
+
:values => ['normal', 'bold', 'bolder', 'lighter', '100', '200',
|
256
|
+
'300', '400', '500', '600', '700', '800', '900',
|
257
|
+
'inherit'],
|
258
|
+
:unit_types => ([nil] * 4) + ([:SAC_INTEGER] * 9) + [nil],
|
259
|
+
},
|
260
|
+
|
261
|
+
'font' => {
|
262
|
+
:values => ['x-large/110% "New Century Schoolbook", serif',
|
263
|
+
'12px/14px sans-serif', 'message-box', 'small-caption',
|
264
|
+
'80% sans-serif', 'caption', 'icon', 'menu',
|
265
|
+
'bold italic large Palatino, serif', 'status-bar',
|
266
|
+
'normal small-caps 120%/120% fantasy',
|
267
|
+
],
|
268
|
+
:unit_types => [[nil, :SAC_PERCENTAGE, :SAC_STRING_VALUE, nil],
|
269
|
+
[:SAC_PIXEL, :SAC_PIXEL, nil], nil, nil,
|
270
|
+
[:SAC_PERCENTAGE, nil], nil, nil, nil,
|
271
|
+
[nil] * 5, nil, [nil, nil, :SAC_PERCENTAGE, :SAC_PERCENTAGE, nil]],
|
272
|
+
},
|
273
|
+
|
274
|
+
['height','left','right','top'] => {
|
275
|
+
:values => ['100px', '100%', 'auto', 'inherit'],
|
276
|
+
:unit_types => [:SAC_PIXEL, :SAC_PERCENTAGE, nil, nil ],
|
277
|
+
},
|
278
|
+
|
279
|
+
'letter-spacing' => {
|
280
|
+
:values => ['normal', '100em', 'inherit'],
|
281
|
+
:unit_types => [nil, :SAC_EM, nil ],
|
282
|
+
},
|
283
|
+
|
284
|
+
'line-height' => {
|
285
|
+
:values => ['normal', '55', '100px', '49%', 'inherit'],
|
286
|
+
:unit_types => [nil, :SAC_INTEGER, :SAC_PIXEL, :SAC_PERCENTAGE, nil],
|
287
|
+
},
|
288
|
+
|
289
|
+
'list-style-image' => {
|
290
|
+
:values => ['url("http://tenderlovemaking.com")', 'none',
|
291
|
+
'inherit'],
|
292
|
+
:unit_types => [ :SAC_URI, nil, nil ]
|
293
|
+
},
|
294
|
+
|
295
|
+
'list-style-position' => {
|
296
|
+
:values => ['inside', 'outside', 'inherit'],
|
297
|
+
:unit_types => [nil, nil, nil],
|
298
|
+
},
|
299
|
+
|
300
|
+
'list-style-type' => {
|
301
|
+
:values => ['disc', 'circle', 'square', 'decimal',
|
302
|
+
'decimal-leading-zero', 'lower-roman', 'upper-roman',
|
303
|
+
'lower-greek', 'lower-latin', 'upper-latin',
|
304
|
+
'armenian', 'georgian', 'lower-alpha', 'upper-alpha',
|
305
|
+
'none', 'inherit'],
|
306
|
+
:unit_types => [nil] * 16,
|
307
|
+
},
|
308
|
+
|
309
|
+
'list-style' => {
|
310
|
+
:values => ['disc', 'inside', 'url("http://tenderlovemaking.com")',
|
311
|
+
'disc url("http://tenderlovemaking.com") inside',
|
312
|
+
'inherit'],
|
313
|
+
:unit_types => [nil, nil, :SAC_URI, [nil, :SAC_URI, nil], nil],
|
314
|
+
},
|
315
|
+
|
316
|
+
[ 'margin-right',
|
317
|
+
'margin-left',
|
318
|
+
'margin-top',
|
319
|
+
'margin-bottom' ] => {
|
320
|
+
:values => ['100px', '50%', 'auto' ],
|
321
|
+
:unit_types => [:SAC_PIXEL, :SAC_PERCENTAGE, nil],
|
322
|
+
},
|
323
|
+
|
324
|
+
'margin' => {
|
325
|
+
:values => ['auto', '100px', '50%', 'auto 100px', '100px 54% auto',
|
326
|
+
'auto 100px 90px 85px'],
|
327
|
+
:unit_types => [nil, :SAC_PIXEL, :SAC_PERCENTAGE, [nil, :SAC_PIXEL],
|
328
|
+
[:SAC_PIXEL, :SAC_PERCENTAGE, nil],
|
329
|
+
[nil, :SAC_PIXEL, :SAC_PIXEL, :SAC_PIXEL]],
|
330
|
+
},
|
331
|
+
|
332
|
+
[ 'max-height',
|
333
|
+
'max-width' ] => {
|
334
|
+
:values => ['10px', '60%', 'none', 'inherit'],
|
335
|
+
:unit_types => [:SAC_PIXEL, :SAC_PERCENTAGE, nil, nil],
|
336
|
+
},
|
337
|
+
|
338
|
+
[ 'min-height',
|
339
|
+
'min-width' ] => {
|
340
|
+
:values => ['10px', '60%', 'inherit'],
|
341
|
+
:unit_types => [:SAC_PIXEL, :SAC_PERCENTAGE, nil],
|
342
|
+
},
|
343
|
+
|
344
|
+
'orphans' => {
|
345
|
+
:values => ['1000', 'inherit'],
|
346
|
+
:unit_types => [:SAC_INTEGER, nil],
|
347
|
+
},
|
348
|
+
|
349
|
+
'outline-color' => {
|
350
|
+
:values => ['red', '#ddd', '#ab12ff', 'invert', 'inherit'],
|
351
|
+
:unit_types => [nil, :SAC_RGBCOLOR, :SAC_RGBCOLOR, nil, nil]
|
352
|
+
},
|
353
|
+
|
354
|
+
'outline-style' => {
|
355
|
+
:values => ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
|
356
|
+
'groove', 'ridge', 'inset', 'outset', 'inherit'],
|
357
|
+
:unit_types => [nil] * 11,
|
358
|
+
},
|
359
|
+
|
360
|
+
'outline-width' => {
|
361
|
+
:values => ['thin', 'thick', 'medium', '100in'],
|
362
|
+
:unit_types => [nil, nil, nil, :SAC_INCH],
|
363
|
+
},
|
364
|
+
|
365
|
+
'outline' => {
|
366
|
+
:values => ['red', 'hidden', '100in', 'hidden 100in red', 'hidden red',
|
367
|
+
'100in red', 'inherit'],
|
368
|
+
:unit_types => [nil, nil, :SAC_INCH, [nil, :SAC_INCH, nil], [nil, nil],
|
369
|
+
[:SAC_INCH, nil], nil],
|
370
|
+
},
|
371
|
+
|
372
|
+
'overflow' => {
|
373
|
+
:values => ['visible', 'hidden', 'scroll', 'auto', 'inherit'],
|
374
|
+
:unit_types => [nil] * 5,
|
375
|
+
},
|
376
|
+
|
377
|
+
[ 'padding-top',
|
378
|
+
'padding-right',
|
379
|
+
'padding-bottom',
|
380
|
+
'padding-left' ] => {
|
381
|
+
:values => [ '100in', '100%', 'inherit' ],
|
382
|
+
:unit_types => [ :SAC_INCH, :SAC_PERCENTAGE, nil],
|
383
|
+
},
|
384
|
+
|
385
|
+
'padding' => {
|
386
|
+
:values => ['100in', '100in 100%', '2em 4in 5ex', '1ex 100% 5% 2%',
|
387
|
+
'inherit' ],
|
388
|
+
:unit_types => [:SAC_INCH, [:SAC_INCH, :SAC_PERCENTAGE],
|
389
|
+
[:SAC_EM, :SAC_INCH, :SAC_EX],
|
390
|
+
[:SAC_EX, :SAC_PERCENTAGE, :SAC_PERCENTAGE, :SAC_PERCENTAGE], nil ],
|
391
|
+
},
|
392
|
+
|
393
|
+
[ 'page-break-after',
|
394
|
+
'page-break-before' ] => {
|
395
|
+
:values => ['auto', 'always', 'avoid', 'left', 'right',
|
396
|
+
'inherit'],
|
397
|
+
:unit_types => [nil] * 6,
|
398
|
+
},
|
399
|
+
|
400
|
+
'page-break-inside' => {
|
401
|
+
:values => ['avoid', 'auto', 'inherit'],
|
402
|
+
:unit_types => [nil] * 3,
|
403
|
+
},
|
404
|
+
|
405
|
+
[ 'pause-after',
|
406
|
+
'pause-before' ] => {
|
407
|
+
:values => ['123ms', '321s', '10%', 'inherit'],
|
408
|
+
:unit_types => [:SAC_MILLISECOND, :SAC_SECOND, :SAC_PERCENTAGE, nil],
|
409
|
+
},
|
410
|
+
|
411
|
+
'pause' => {
|
412
|
+
:values => ['10ms 19%', '10s 10ms', '10ms', 'inherit' ],
|
413
|
+
:unit_types => [[:SAC_MILLISECOND, :SAC_PERCENTAGE],
|
414
|
+
[:SAC_SECOND, :SAC_MILLISECOND], :SAC_MILLISECOND, nil],
|
415
|
+
},
|
416
|
+
|
417
|
+
'pitch-range' => {
|
418
|
+
:values => ['1000', 'inherit'],
|
419
|
+
:unit_types => [:SAC_INTEGER, nil],
|
420
|
+
},
|
421
|
+
|
422
|
+
'pitch' => {
|
423
|
+
:values => ['10Hz', '100kHz', 'x-low', 'low', 'medium', 'high', 'x-high',
|
424
|
+
'inherit'],
|
425
|
+
:unit_types => [:SAC_HERTZ, :SAC_KILOHERTZ] + [nil] * 6,
|
426
|
+
},
|
427
|
+
|
428
|
+
'play-during' => {
|
429
|
+
:values => ['url("http://tenderlovemaking.com/")',
|
430
|
+
'url("http://tenderlovemaking.com/") mix',
|
431
|
+
'url("http://tenderlovemaking.com/") repeat mix',
|
432
|
+
'auto', 'none', 'inherit'],
|
433
|
+
:unit_types => [:SAC_URI, [:SAC_URI, nil], [:SAC_URI, nil, nil],
|
434
|
+
nil, nil, nil],
|
435
|
+
},
|
436
|
+
|
437
|
+
'position' => {
|
438
|
+
:values => ['static', 'relative', 'absolute', 'fixed', 'inherit'],
|
439
|
+
:unit_types => [nil] * 5,
|
440
|
+
},
|
441
|
+
|
442
|
+
'quotes' => {
|
443
|
+
:values => ['"one" "two"', 'none', 'inherit'],
|
444
|
+
:unit_types => [[:SAC_STRING_VALUE, :SAC_STRING_VALUE], nil, nil],
|
445
|
+
},
|
446
|
+
|
447
|
+
'richness' => {
|
448
|
+
:values => ['1000', 'inherit'],
|
449
|
+
:unit_types => [:SAC_INTEGER, nil],
|
450
|
+
},
|
451
|
+
|
452
|
+
'speak-header' => {
|
453
|
+
:values => ['once', 'always', 'inherit'],
|
454
|
+
:unit_types => [nil] * 3,
|
455
|
+
},
|
456
|
+
|
457
|
+
'speak-numeral' => {
|
458
|
+
:values => ['digits', 'continuous', 'inherit'],
|
459
|
+
:unit_types => [nil] * 3,
|
460
|
+
},
|
461
|
+
|
462
|
+
'speak-punctuation' => {
|
463
|
+
:values => ['code', 'none', 'inherit'],
|
464
|
+
:unit_types => [nil] * 3,
|
465
|
+
},
|
466
|
+
|
467
|
+
'speak' => {
|
468
|
+
:values => ['normal', 'none', 'spell-out', 'inherit'],
|
469
|
+
:unit_types => [nil] * 4,
|
470
|
+
},
|
471
|
+
|
472
|
+
'speech-rate' => {
|
473
|
+
:values => ['1000', 'x-slow', 'slow', 'medium', 'fast', 'x-fast',
|
474
|
+
'faster', 'slower', 'inherit'],
|
475
|
+
:unit_types => [:SAC_INTEGER] + [nil] * 8,
|
476
|
+
},
|
477
|
+
|
478
|
+
'stress' => {
|
479
|
+
:values => ['69', 'inherit'],
|
480
|
+
:unit_types => [:SAC_INTEGER, nil],
|
481
|
+
},
|
482
|
+
|
483
|
+
'table-layout' => {
|
484
|
+
:values => ['auto', 'fixed', 'inherit'],
|
485
|
+
:unit_types => [nil] * 3,
|
486
|
+
},
|
487
|
+
|
488
|
+
'text-align' => {
|
489
|
+
:values => ['left', 'right', 'center', 'justify', 'inherit'],
|
490
|
+
:unit_types => [nil] * 5,
|
491
|
+
},
|
492
|
+
|
493
|
+
'text-decoration' => {
|
494
|
+
:values => ['none', 'underline', 'overline underline',
|
495
|
+
'blink line-through underline',
|
496
|
+
'underline blink overline line-through', 'inherit'],
|
497
|
+
:unit_types => [nil, nil, [nil, nil], [nil, nil, nil],
|
498
|
+
[nil, nil, nil, nil], nil],
|
499
|
+
},
|
500
|
+
|
501
|
+
'text-indent' => {
|
502
|
+
:values => ['69in', '69%', 'inherit'],
|
503
|
+
:unit_types => [:SAC_INCH, :SAC_PERCENTAGE, nil],
|
504
|
+
},
|
505
|
+
|
506
|
+
'text-transform' => {
|
507
|
+
:values => ['capitalize', 'uppercase', 'lowercase', 'none', 'inherit'],
|
508
|
+
:unit_types => [nil] * 5,
|
509
|
+
},
|
510
|
+
|
511
|
+
'unicode-bidi' => {
|
512
|
+
:values => ['normal', 'embed', 'bidi-override', 'inherit'],
|
513
|
+
:unit_types => [nil] * 4,
|
514
|
+
},
|
515
|
+
|
516
|
+
'vertical-align' => {
|
517
|
+
:values => ['baseline', 'sub', 'super', 'top', 'text-top',
|
518
|
+
'middle', 'bottom', 'text-bottom', '70%', '100in',
|
519
|
+
'inherit'],
|
520
|
+
:unit_types => ([nil] * 8) + [:SAC_PERCENTAGE, :SAC_INCH, nil],
|
521
|
+
},
|
522
|
+
|
523
|
+
'visibility' => {
|
524
|
+
:values => ['visible', 'hidden', 'collapse', 'inherit'],
|
525
|
+
:unit_types => [nil] * 4,
|
526
|
+
},
|
527
|
+
|
528
|
+
'voice-family' => {
|
529
|
+
:values => ['romeo, male', 'juliet, female', 'male', 'male, female',
|
530
|
+
'inherit'],
|
531
|
+
:unit_types => [[nil, nil], [nil, nil], nil, [nil, nil], nil],
|
532
|
+
},
|
533
|
+
|
534
|
+
'volume' => {
|
535
|
+
:values => ['10', '10%', 'silent', 'x-soft', 'soft', 'medium', 'loud',
|
536
|
+
'x-loud', 'inherit'],
|
537
|
+
:unit_types => [:SAC_INTEGER, :SAC_PERCENTAGE] + ([nil] * 7),
|
538
|
+
},
|
539
|
+
|
540
|
+
'white-space' => {
|
541
|
+
:values => ['normal', 'pre', 'nowrap', 'pre-wrap', 'pre-line', 'inherit'],
|
542
|
+
:unit_types => [nil] * 6,
|
543
|
+
},
|
544
|
+
|
545
|
+
'windows' => {
|
546
|
+
:values => ['169', 'inherit'],
|
547
|
+
:unit_types => [:SAC_INTEGER, nil],
|
548
|
+
},
|
549
|
+
|
550
|
+
'width' => {
|
551
|
+
:values => ['100em', '50%', 'auto', 'inherit'],
|
552
|
+
:unit_types => [:SAC_EM, :SAC_PERCENTAGE, nil, nil],
|
553
|
+
},
|
554
|
+
|
555
|
+
'word-spacing' => {
|
556
|
+
:values => ['normal', '10in', 'inherit'],
|
557
|
+
:unit_types => [nil, :SAC_INCH, nil],
|
558
|
+
},
|
559
|
+
|
560
|
+
'z-index' => {
|
561
|
+
:values => ['auto', '10', 'inherit'],
|
562
|
+
:unit_types => [nil, :SAC_INTEGER, nil],
|
563
|
+
},
|
564
|
+
}
|
565
|
+
|
566
|
+
@@valid_value_tests.each do |k,v|
|
567
|
+
[k].flatten.each do |key|
|
568
|
+
define_method :"test_valid_#{key.to_s.gsub(/-/, '_')}" do
|
569
|
+
v[:values].each_with_index do |value, i|
|
570
|
+
tok = @tokenizer.tokenize("#{key}: #{value}")
|
571
|
+
result = @property_parser.parse_tokens(tok)
|
572
|
+
if result.nil?
|
573
|
+
p tok
|
574
|
+
end
|
575
|
+
assert_not_nil(result)
|
576
|
+
|
577
|
+
unit_types = [v[:unit_types][i] || :SAC_IDENT].flatten.map { |x|
|
578
|
+
x || :SAC_IDENT
|
579
|
+
}
|
580
|
+
result_types = [result].flatten.map { |x| x.lexical_unit_type }
|
581
|
+
result_strings = [result].flatten.map { |x| x.to_s }
|
582
|
+
|
583
|
+
assert_equal(unit_types, result_types, tok.inspect)
|
584
|
+
assert(result_strings.length > 0)
|
585
|
+
result_strings.each do |rs|
|
586
|
+
assert(rs)
|
587
|
+
assert_match(rs, value)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class SelectorAsStringTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@sac = CSS::SAC::Parser.new()
|
6
|
+
class << @sac.document_handler
|
7
|
+
attr_accessor :selectors
|
8
|
+
def start_selector(selectors)
|
9
|
+
@selectors = selectors
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_any_node_selector
|
15
|
+
@sac.parse('* { }')
|
16
|
+
selectors = @sac.document_handler.selectors
|
17
|
+
assert_equal(1, selectors.length)
|
18
|
+
assert_equal('*', selectors.first.to_css)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_element_node_selector
|
22
|
+
@sac.parse('h1 { }')
|
23
|
+
selectors = @sac.document_handler.selectors
|
24
|
+
assert_equal(1, selectors.length)
|
25
|
+
assert_equal('h1', selectors.first.to_css)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_element_node_conditional_selector
|
29
|
+
@sac.parse('h1.awesome { }')
|
30
|
+
selectors = @sac.document_handler.selectors
|
31
|
+
assert_equal(1, selectors.length)
|
32
|
+
assert_equal('h1.awesome', selectors.first.to_css)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_element_node_conditional
|
36
|
+
@sac.parse('.awesome { }')
|
37
|
+
selectors = @sac.document_handler.selectors
|
38
|
+
assert_equal(1, selectors.length)
|
39
|
+
assert_equal('.awesome', selectors.first.to_css)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_element_node_conditional_selector_id
|
43
|
+
@sac.parse('h1#awesome { }')
|
44
|
+
selectors = @sac.document_handler.selectors
|
45
|
+
assert_equal(1, selectors.length)
|
46
|
+
assert_equal('h1#awesome', selectors.first.to_css)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_selector_attribute
|
50
|
+
@sac.parse('h1[class=foo] { }')
|
51
|
+
selectors = @sac.document_handler.selectors
|
52
|
+
assert_equal(1, selectors.length)
|
53
|
+
assert_equal('h1[class=foo]', selectors.first.to_css)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_combinator_selector
|
57
|
+
@sac.parse('h1[class=foo].aaron { }')
|
58
|
+
selectors = @sac.document_handler.selectors
|
59
|
+
assert_equal(1, selectors.length)
|
60
|
+
assert_equal('h1[class=foo].aaron', selectors.first.to_css)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_descendant_selectors
|
64
|
+
@sac.parse('div h1 { }')
|
65
|
+
selectors = @sac.document_handler.selectors
|
66
|
+
assert_equal(1, selectors.length)
|
67
|
+
assert_equal('div h1', selectors.first.to_css)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_direct_descendant_selectors
|
71
|
+
@sac.parse('div > h1 { }')
|
72
|
+
selectors = @sac.document_handler.selectors
|
73
|
+
assert_equal(1, selectors.length)
|
74
|
+
assert_equal('div > h1', selectors.first.to_css)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_direct_sibling_selectors
|
78
|
+
@sac.parse('div + h1 { }')
|
79
|
+
selectors = @sac.document_handler.selectors
|
80
|
+
assert_equal(1, selectors.length)
|
81
|
+
assert_equal('div + h1', selectors.first.to_css)
|
82
|
+
end
|
83
|
+
end
|