Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: utils/tests/css/expression_tests.dart

Issue 10154010: test rename overhaul: step 3 _tests.dart => _test.dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library("expression_tests");
6 #import("../../css/css.dart");
7
8 main() {
9 initCssWorld();
10
11 testClass();
12 testId();
13 testElement();
14 testNamespace();
15 testSelectorGroups();
16 testCombinator();
17 testWildcard();
18 testPseudo();
19 testAttribute();
20 testNegation();
21 }
22
23 void testClass() {
24 Parser parser = new Parser(new SourceFile(
25 SourceFile.IN_MEMORY_FILE, ".foobar {}"));
26
27 Stylesheet stylesheet = parser.parse();
28 Expect.isNotNull(stylesheet);
29 Expect.equals(stylesheet.topLevels.length, 1);
30
31 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
32 RuleSet ruleset = stylesheet.topLevels[0];
33 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
34 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
35
36 List<SimpleSelectorSequence> simpleSeqs =
37 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
38 Expect.equals(simpleSeqs.length, 1);
39 for (final selector in simpleSeqs) {
40 final simpSelector = selector.simpleSelector;
41 Expect.isTrue(simpSelector is ClassSelector);
42 Expect.isTrue(selector.isCombinatorNone());
43 Expect.equals(simpSelector.name, "foobar");
44 }
45
46 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
47 ".foobar .bar .no-story {}"));
48
49 stylesheet = parser.parse();
50 Expect.isNotNull(stylesheet);
51 Expect.equals(stylesheet.topLevels.length, 1);
52
53 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
54 ruleset = stylesheet.topLevels[0];
55 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
56 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
57
58 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
59
60 var idx = 0;
61 for (final selector in simpleSeqs) {
62 final simpSelector = selector.simpleSelector;
63 if (idx == 0) {
64 Expect.isTrue(simpSelector is ClassSelector);
65 Expect.isTrue(selector.isCombinatorNone());
66 Expect.equals(simpSelector.name, "foobar");
67 } else if (idx == 1) {
68 Expect.isTrue(simpSelector is ClassSelector);
69 Expect.isTrue(selector.isCombinatorDescendant());
70 Expect.equals(simpSelector.name, "bar");
71 } else if (idx == 2) {
72 Expect.isTrue(simpSelector is ClassSelector);
73 Expect.isTrue(selector.isCombinatorDescendant());
74 Expect.equals(simpSelector.name, "no-story");
75 } else {
76 Expect.fail("unexpected expression");
77 }
78
79 idx++;
80 }
81
82 Expect.equals(simpleSeqs.length, idx);
83 }
84
85 void testId() {
86 Parser parser = new Parser(new SourceFile(
87 SourceFile.IN_MEMORY_FILE, "#elemId {}"));
88
89 Stylesheet stylesheet = parser.parse();
90 Expect.isNotNull(stylesheet);
91 Expect.equals(stylesheet.topLevels.length, 1);
92
93 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
94 RuleSet ruleset = stylesheet.topLevels[0];
95 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
96 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
97
98 List<SimpleSelectorSequence> simpleSeqs =
99 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
100
101 for (final selector in simpleSeqs) {
102 final simpSelector = selector.simpleSelector;
103 Expect.isTrue(simpSelector is IdSelector);
104 Expect.isTrue(selector.isCombinatorNone());
105 Expect.equals(simpSelector.name, "elemId");
106 }
107 }
108
109 void testElement() {
110 Parser parser = new Parser(new SourceFile(
111 SourceFile.IN_MEMORY_FILE, "div {}"));
112 Stylesheet stylesheet = parser.parse();
113 Expect.isNotNull(stylesheet);
114 Expect.equals(stylesheet.topLevels.length, 1);
115
116 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
117 RuleSet ruleset = stylesheet.topLevels[0];
118 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
119 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
120
121 List<SimpleSelectorSequence> simpleSeqs =
122 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
123
124 for (final selector in simpleSeqs) {
125 final simpSelector = selector.simpleSelector;
126 Expect.isTrue(simpSelector is ElementSelector);
127 Expect.isTrue(selector.isCombinatorNone());
128 Expect.equals(simpSelector.name, "div");
129 }
130
131 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
132 "div div span {}"));
133 stylesheet = parser.parse();
134 Expect.isNotNull(stylesheet);
135 Expect.equals(stylesheet.topLevels.length, 1);
136
137 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
138 ruleset = stylesheet.topLevels[0];
139 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
140 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
141
142 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
143
144 var idx = 0;
145 for (final selector in simpleSeqs) {
146 final simpSelector = selector.simpleSelector;
147 if (idx == 0) {
148 Expect.isTrue(simpSelector is ElementSelector);
149 Expect.isTrue(selector.isCombinatorNone());
150 Expect.equals(simpSelector.name, "div");
151 } else if (idx == 1) {
152 Expect.isTrue(simpSelector is ElementSelector);
153 Expect.isTrue(selector.isCombinatorDescendant());
154 Expect.equals(simpSelector.name, "div");
155 } else if (idx == 2) {
156 Expect.isTrue(simpSelector is ElementSelector);
157 Expect.isTrue(selector.isCombinatorDescendant());
158 Expect.equals(simpSelector.name, "span");
159 } else {
160 Expect.fail("unexpected expression");
161 }
162
163 idx++;
164 }
165 Expect.equals(simpleSeqs.length, idx);
166 }
167
168 void testNamespace() {
169 Parser parser = new Parser(new SourceFile(
170 SourceFile.IN_MEMORY_FILE, "ns1|div {}"));
171 Stylesheet stylesheet = parser.parse();
172 Expect.isNotNull(stylesheet);
173 Expect.equals(stylesheet.topLevels.length, 1);
174
175 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
176 RuleSet ruleset = stylesheet.topLevels[0];
177 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
178 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
179
180 List<SimpleSelectorSequence> simpleSeqs =
181 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
182
183 for (final selector in simpleSeqs) {
184 final simpSelector = selector.simpleSelector;
185 Expect.isTrue(simpSelector is NamespaceSelector);
186 Expect.isTrue(selector.isCombinatorNone());
187 Expect.isFalse(simpSelector.isNamespaceWildcard());
188 Expect.equals(simpSelector.namespace, "ns1");
189 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
190 Expect.isTrue(elementSelector is ElementSelector);
191 Expect.isFalse(elementSelector.isWildcard());
192 Expect.equals(elementSelector.name, "div");
193 }
194
195 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
196 "ns1|div div ns2|span .foobar {}"));
197 stylesheet = parser.parse();
198 Expect.isNotNull(stylesheet);
199
200 Expect.equals(stylesheet.topLevels.length, 1);
201
202 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
203 ruleset = stylesheet.topLevels[0];
204 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
205 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
206
207 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
208
209 var idx = 0;
210 for (final selector in simpleSeqs) {
211 final simpSelector = selector.simpleSelector;
212 if (idx == 0) {
213 Expect.isTrue(simpSelector is NamespaceSelector);
214 Expect.isTrue(selector.isCombinatorNone());
215 Expect.equals(simpSelector.namespace, "ns1");
216 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
217 Expect.isTrue(elementSelector is ElementSelector);
218 Expect.isFalse(elementSelector.isWildcard());
219 Expect.equals(elementSelector.name, "div");
220 } else if (idx == 1) {
221 Expect.isTrue(simpSelector is ElementSelector);
222 Expect.isTrue(selector.isCombinatorDescendant());
223 Expect.equals(simpSelector.name, "div");
224 } else if (idx == 2) {
225 Expect.isTrue(simpSelector is NamespaceSelector);
226 Expect.isTrue(selector.isCombinatorDescendant());
227 Expect.equals(simpSelector.namespace, "ns2");
228 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
229 Expect.isTrue(elementSelector is ElementSelector);
230 Expect.isFalse(elementSelector.isWildcard());
231 Expect.equals(elementSelector.name, "span");
232 } else if (idx == 3) {
233 Expect.isTrue(simpSelector is ClassSelector);
234 Expect.isTrue(selector.isCombinatorDescendant());
235 Expect.equals(simpSelector.name, "foobar");
236 } else {
237 Expect.fail("unexpected expression");
238 }
239
240 idx++;
241 }
242
243 Expect.equals(simpleSeqs.length, idx);
244 }
245
246 void testSelectorGroups() {
247 Parser parser = new Parser(new SourceFile(
248 SourceFile.IN_MEMORY_FILE,
249 "div, .foobar ,#elemId, .xyzzy .test, ns1|div div #elemId .foobar {}"));
250 Stylesheet stylesheet = parser.parse();
251 Expect.isNotNull(stylesheet);
252
253 Expect.equals(stylesheet.topLevels.length, 1);
254
255 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
256 RuleSet ruleset = stylesheet.topLevels[0];
257 Expect.equals(ruleset.selectorGroup.selectors.length, 5);
258 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
259
260 var groupIdx = 0;
261 for (final selectorGroup in ruleset.selectorGroup.selectors) {
262 var idx = 0;
263 for (final selector in selectorGroup.simpleSelectorSequences) {
264 final simpSelector = selector.simpleSelector;
265 switch (groupIdx) {
266 case 0: // First selector group.
267 Expect.isTrue(simpSelector is ElementSelector);
268 Expect.isTrue(selector.isCombinatorNone());
269 Expect.equals(simpSelector.name, "div");
270 break;
271 case 1: // Second selector group.
272 Expect.isTrue(simpSelector is ClassSelector);
273 Expect.isTrue(selector.isCombinatorNone());
274 Expect.equals(simpSelector.name, "foobar");
275 break;
276 case 2: // Third selector group.
277 Expect.isTrue(simpSelector is IdSelector);
278 Expect.isTrue(selector.isCombinatorNone());
279 Expect.equals(simpSelector.name, "elemId");
280 break;
281 case 3: // Fourth selector group.
282 Expect.equals(selectorGroup.simpleSelectorSequences.length, 2);
283 if (idx == 0) {
284 Expect.isTrue(simpSelector is ClassSelector);
285 Expect.isTrue(selector.isCombinatorNone());
286 Expect.equals(simpSelector.name, "xyzzy");
287 } else if (idx == 1) {
288 Expect.isTrue(simpSelector is ClassSelector);
289 Expect.isTrue(selector.isCombinatorDescendant());
290 Expect.equals(simpSelector.name, "test");
291 } else {
292 Expect.fail("unexpected expression");
293 }
294 break;
295 case 4: // Fifth selector group.
296 Expect.equals(selectorGroup.simpleSelectorSequences.length, 4);
297 if (idx == 0) {
298 Expect.isTrue(simpSelector is NamespaceSelector);
299 Expect.isTrue(selector.isCombinatorNone());
300 Expect.equals(simpSelector.namespace, "ns1");
301 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
302 Expect.isTrue(elementSelector is ElementSelector);
303 Expect.isFalse(elementSelector.isWildcard());
304 Expect.equals(elementSelector.name, "div");
305 } else if (idx == 1) {
306 Expect.isTrue(simpSelector is ElementSelector);
307 Expect.isTrue(selector.isCombinatorDescendant());
308 Expect.equals(simpSelector.name, "div");
309 } else if (idx == 2) {
310 Expect.isTrue(simpSelector is IdSelector);
311 Expect.isTrue(selector.isCombinatorDescendant());
312 Expect.equals(simpSelector.name, "elemId");
313 } else if (idx == 3) {
314 Expect.isTrue(simpSelector is ClassSelector);
315 Expect.isTrue(selector.isCombinatorDescendant());
316 Expect.equals(simpSelector.name, "foobar");
317 } else {
318 Expect.fail("unexpected expression");
319 }
320 break;
321 }
322 idx++;
323 }
324 groupIdx++;
325 }
326 }
327
328 void testCombinator() {
329 Parser parser = new Parser(new SourceFile(
330 SourceFile.IN_MEMORY_FILE,
331 ".foobar > .bar + .no-story ~ myNs|div #elemId {}"));
332
333 Stylesheet stylesheet = parser.parse();
334 Expect.isNotNull(stylesheet);
335 Expect.equals(stylesheet.topLevels.length, 1);
336
337 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
338 RuleSet ruleset = stylesheet.topLevels[0];
339 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
340 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
341
342 List<SimpleSelectorSequence> simpleSeqs =
343 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
344
345 Expect.equals(simpleSeqs.length, 5);
346 var idx = 0;
347 for (final selector in simpleSeqs) {
348 final simpSelector = selector.simpleSelector;
349 if (idx == 0) {
350 Expect.isTrue(simpSelector is ClassSelector);
351 Expect.isTrue(selector.isCombinatorNone());
352 Expect.equals(simpSelector.name, "foobar");
353 } else if (idx == 1) {
354 Expect.isTrue(simpSelector is ClassSelector);
355 Expect.isTrue(selector.isCombinatorGreater());
356 Expect.equals(simpSelector.name, "bar");
357 } else if (idx == 2) {
358 Expect.isTrue(simpSelector is ClassSelector);
359 Expect.isTrue(selector.isCombinatorPlus());
360 Expect.equals(simpSelector.name, "no-story");
361 } else if (idx == 3) {
362 Expect.isTrue(simpSelector is NamespaceSelector);
363 Expect.isTrue(selector.isCombinatorTilde());
364 Expect.equals(simpSelector.namespace, "myNs");
365 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
366 Expect.isTrue(elementSelector is ElementSelector);
367 Expect.isFalse(elementSelector.isWildcard());
368 Expect.equals(elementSelector.name, "div");
369 } else if (idx == 4) {
370 Expect.isTrue(simpSelector is IdSelector);
371 Expect.isTrue(selector.isCombinatorDescendant());
372 Expect.equals(simpSelector.name, "elemId");
373 } else {
374 Expect.fail("unexpected expression");
375 }
376
377 idx++;
378 }
379 }
380
381 void testWildcard() {
382 Parser parser = new Parser(new SourceFile(
383 SourceFile.IN_MEMORY_FILE, "* {}"));
384
385 Stylesheet stylesheet = parser.parse();
386 Expect.isNotNull(stylesheet);
387 Expect.equals(stylesheet.topLevels.length, 1);
388
389 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
390 RuleSet ruleset = stylesheet.topLevels[0];
391 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
392 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
393
394 List<SimpleSelectorSequence> simpleSeqs =
395 ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
396
397 for (final selector in simpleSeqs) {
398 final simpSelector = selector.simpleSelector;
399 Expect.isTrue(simpSelector is ElementSelector);
400 Expect.isTrue(selector.isCombinatorNone());
401 Expect.isTrue(simpSelector.isWildcard());
402 Expect.equals(simpSelector.name, "*");
403 }
404
405 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
406 "*.foobar {}"));
407
408 stylesheet = parser.parse();
409 Expect.isNotNull(stylesheet);
410 Expect.equals(stylesheet.topLevels.length, 1);
411
412 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
413 ruleset = stylesheet.topLevels[0];
414 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
415 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
416
417 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
418
419 Expect.equals(simpleSeqs.length, 2);
420 var idx = 0;
421 for (final selector in simpleSeqs) {
422 final simpSelector = selector.simpleSelector;
423 if (idx == 0) {
424 Expect.isTrue(simpSelector is ElementSelector);
425 Expect.isTrue(selector.isCombinatorNone());
426 Expect.isTrue(simpSelector.isWildcard());
427 Expect.equals(simpSelector.name, "*");
428 } else if (idx == 1) {
429 Expect.isTrue(simpSelector is ClassSelector);
430 Expect.isTrue(selector.isCombinatorNone());
431 Expect.equals(simpSelector.name, "foobar");
432 } else {
433 Expect.fail("unexpected expression");
434 }
435
436 idx++;
437 }
438
439 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
440 "myNs|*.foobar {}"));
441
442 stylesheet = parser.parse();
443 Expect.isNotNull(stylesheet);
444 Expect.equals(stylesheet.topLevels.length, 1);
445
446 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
447 ruleset = stylesheet.topLevels[0];
448 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
449 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
450
451 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
452
453 Expect.equals(simpleSeqs.length, 2);
454 idx = 0;
455 for (final selector in simpleSeqs) {
456 final simpSelector = selector.simpleSelector;
457 if (idx == 0) {
458 Expect.isTrue(simpSelector is NamespaceSelector);
459 Expect.isTrue(selector.isCombinatorNone());
460 Expect.isFalse(simpSelector.isNamespaceWildcard());
461 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
462 Expect.equals("myNs", simpSelector.namespace);
463 Expect.isTrue(elementSelector.isWildcard());
464 Expect.equals("*", elementSelector.name);
465 } else if (idx == 1) {
466 Expect.isTrue(simpSelector is ClassSelector);
467 Expect.isTrue(selector.isCombinatorNone());
468 Expect.equals("foobar", simpSelector.name);
469 } else {
470 Expect.fail("unexpected expression");
471 }
472
473 idx++;
474 }
475
476 parser = new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE,
477 "*|*.foobar {}"));
478
479 stylesheet = parser.parse();
480 Expect.isNotNull(stylesheet);
481
482 Expect.isTrue(stylesheet.topLevels[0] is RuleSet);
483 ruleset = stylesheet.topLevels[0];
484 Expect.equals(ruleset.selectorGroup.selectors.length, 1);
485 Expect.equals(ruleset.declarationGroup.declarations.length, 0);
486
487 simpleSeqs = ruleset.selectorGroup.selectors[0].simpleSelectorSequences;
488
489 Expect.equals(simpleSeqs.length, 2);
490 idx = 0;
491 for (final selector in simpleSeqs) {
492 final simpSelector = selector.simpleSelector;
493 if (idx == 0) {
494 Expect.isTrue(simpSelector is NamespaceSelector);
495 Expect.isTrue(selector.isCombinatorNone());
496 Expect.isTrue(simpSelector.isNamespaceWildcard());
497 Expect.equals("*", simpSelector.namespace);
498 ElementSelector elementSelector = simpSelector.nameAsSimpleSelector;
499 Expect.isTrue(elementSelector.isWildcard());
500 Expect.equals("*", elementSelector.name);
501 } else if (idx == 1) {
502 Expect.isTrue(simpSelector is ClassSelector);
503 Expect.isTrue(selector.isCombinatorNone());
504 Expect.equals("foobar", simpSelector.name);
505 } else {
506 Expect.fail("unexpected expression");
507 }
508
509 idx++;
510 }
511
512 }
513
514 void testPseudo() {
515 // TODO(terry): Implement
516 }
517
518 void testAttribute() {
519 // TODO(terry): Implement
520 }
521
522 void testNegation() {
523 // TODO(terry): Implement
524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698