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

Side by Side Diff: pkg/csslib/test/var_test.dart

Issue 23168002: move csslib into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « pkg/csslib/test/testing.dart ('k') | pkg/csslib/test/visitor_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 var_test;
6
7 import 'dart:utf';
8 import 'package:unittest/unittest.dart';
9 import 'package:csslib/parser.dart';
10 import 'package:csslib/visitor.dart';
11 import 'testing.dart';
12
13 void simpleVar() {
14 final errors = [];
15 final input = ''':root {
16 var-color-background: red;
17 var-color-foreground: blue;
18
19 var-a: var(b);
20 var-b: var(c);
21 var-c: #00ff00;
22 }
23 .testIt {
24 color: var(color-foreground);
25 background: var(color-background);
26 }
27 ''';
28
29 final generated = ''':root {
30 var-color-background: #f00;
31 var-color-foreground: #00f;
32 var-a: var(b);
33 var-b: var(c);
34 var-c: #0f0;
35 }
36 .testIt {
37 color: var(color-foreground);
38 background: var(color-background);
39 }''';
40
41 var stylesheet = compileCss(input, errors: errors,
42 opts: ['--no-colors', 'memory']);
43
44 expect(stylesheet != null, true);
45 expect(errors.isEmpty, true, reason: errors.toString());
46 expect(prettyPrint(stylesheet), generated);
47 }
48
49 void expressionsVar() {
50 final errors = [];
51 final input = ''':root {
52 var-color-background: red;
53 var-color-foreground: blue;
54
55 var-a: var(b);
56 var-b: var(c);
57 var-c: #00ff00;
58
59 var-image: url(test.png);
60
61 var-b-width: 20cm;
62 var-m-width: 33%;
63 var-b-height: 30EM;
64 var-width: .6in;
65 var-length: 1.2in;
66 var-web-stuff: -10Px;
67 var-rgba: rgba(10,20,255);
68 var-transition: color 0.4s;
69 var-transform: rotate(20deg);
70 var-content: "✔";
71 var-text-shadow: 0 -1px 0 #bfbfbf;
72 var-font-family: Gentium;
73 var-src: url("http://example.com/fonts/Gentium.ttf");
74 var-src-1: local(Gentium Bold), local(Gentium-Bold), url("GentiumBold.ttf");
75 var-unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
76 var-unicode-range-1: U+0A-FF, U+980-9FF, U+????, U+3???;
77 var-grid-columns: 10px ("content" 1fr 10px) [4];
78 }
79
80 .testIt {
81 color: var(color-foreground);
82 background: var(c);
83 background-image: var(image);
84
85 border-width: var(b-width);
86 margin-width: var(m-width);
87 border-height: var(b-height);
88 width: var(width);
89 length: var(length);
90 -web-stuff: var(web-stuff);
91 background-color: var(rgba);
92
93 transition: var(transition);
94 transform: var(transform);
95 content: var(content);
96 text-shadow: var(text-shadow);
97 }
98
99 @font-face {
100 font-family: var(font-family);
101 src: var(src);
102 unicode-range: var(unicode-range);
103 }
104
105 @font-face {
106 font-family: var(font-family);
107 src: var(src-1);
108 unicode-range: var(unicode-range-1);
109 }
110
111 .foobar {
112 grid-columns: var(grid-columns);
113 }
114 ''';
115
116 final generated = ''':root {
117 var-color-background: #f00;
118 var-color-foreground: #00f;
119 var-a: var(b);
120 var-b: var(c);
121 var-c: #0f0;
122 var-image: url("test.png");
123 var-b-width: 20cm;
124 var-m-width: 33%;
125 var-b-height: 30em;
126 var-width: .6in;
127 var-length: 1.2in;
128 var-web-stuff: -10px;
129 var-rgba: rgba(10, 20, 255);
130 var-transition: color 0.4s;
131 var-transform: rotate(20deg);
132 var-content: "✔";
133 var-text-shadow: 0 -1px 0 #bfbfbf;
134 var-font-family: Gentium;
135 var-src: url("http://example.com/fonts/Gentium.ttf");
136 var-src-1: local(Gentium Bold), local(Gentium-Bold), url("GentiumBold.ttf");
137 var-unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
138 var-unicode-range-1: U+0A-FF, U+980-9FF, U+????, U+3???;
139 var-grid-columns: 10px ("content" 1fr 10px) [4];
140 }
141 .testIt {
142 color: var(color-foreground);
143 background: var(c);
144 background-image: var(image);
145 border-width: var(b-width);
146 margin-width: var(m-width);
147 border-height: var(b-height);
148 width: var(width);
149 length: var(length);
150 -web-stuff: var(web-stuff);
151 background-color: var(rgba);
152 transition: var(transition);
153 transform: var(transform);
154 content: var(content);
155 text-shadow: var(text-shadow);
156 }
157 @font-face {
158 font-family: var(font-family);
159 src: var(src);
160 unicode-range: var(unicode-range);
161 }
162 @font-face {
163 font-family: var(font-family);
164 src: var(src-1);
165 unicode-range: var(unicode-range-1);
166 }
167 .foobar {
168 grid-columns: var(grid-columns);
169 }''';
170
171 var stylesheet = compileCss(input, errors: errors,
172 opts: ['--no-colors', 'memory']);
173
174 expect(stylesheet != null, true);
175 expect(errors.isEmpty, true, reason: errors.toString());
176 expect(prettyPrint(stylesheet), generated);
177 }
178
179 void defaultVar() {
180 final errors = [];
181 final input = '''
182 :root {
183 var-color-background: red;
184 var-color-foreground: blue;
185
186 var-a: var(b);
187 var-b: var(c);
188 var-c: #00ff00;
189
190 var-image: url(test.png);
191
192 var-b-width: 20cm;
193 var-m-width: 33%;
194 var-b-height: 30EM;
195 }
196
197 .test {
198 background-color: var(test, orange);
199 }
200
201 body {
202 background: var(a) var(image) no-repeat right top;
203 }
204
205 div {
206 background: var(color-background) url('img_tree.png') no-repeat right top;
207 }
208
209 .test-2 {
210 background: var(color-background) var(image-2, url('img_1.png'))
211 no-repeat right top;
212 }
213
214 .test-3 {
215 background: var(color-background) var(image-2) no-repeat right top;
216 }
217
218 .test-4 {
219 background: #ffff00 var(image) no-repeat right top;
220 }
221
222 .test-5 {
223 background: var(test-color, var(a)) var(image) no-repeat right top;
224 }
225
226 .test-6 {
227 border: red var(a-1, solid 20px);
228 }
229 ''';
230
231 final generated = ''':root {
232 var-color-background: #f00;
233 var-color-foreground: #00f;
234 var-a: var(b);
235 var-b: var(c);
236 var-c: #0f0;
237 var-image: url("test.png");
238 var-b-width: 20cm;
239 var-m-width: 33%;
240 var-b-height: 30em;
241 }
242 .test {
243 background-color: var(test, #ffa500);
244 }
245 body {
246 background: var(a) var(image) no-repeat right top;
247 }
248 div {
249 background: var(color-background) url("img_tree.png") no-repeat right top;
250 }
251 .test-2 {
252 background: var(color-background) var(image-2, url("img_1.png")) no-repeat rig ht top;
253 }
254 .test-3 {
255 background: var(color-background) var(image-2) no-repeat right top;
256 }
257 .test-4 {
258 background: #ff0 var(image) no-repeat right top;
259 }
260 .test-5 {
261 background: var(test-color, var(a)) var(image) no-repeat right top;
262 }
263 .test-6 {
264 border: #f00 var(a-1, solid 20px);
265 }''';
266
267 var stylesheet = compileCss(input, errors: errors,
268 opts: ['--no-colors', 'memory']);
269
270 expect(stylesheet != null, true);
271 expect(errors.isEmpty, true, reason: errors.toString());
272 expect(prettyPrint(stylesheet), generated);
273 }
274
275 void cyclesVar() {
276 final errors = [];
277 final input = ''':root {
278 var-color-background: red;
279 var-color-foreground: blue;
280
281 var-a: var(b);
282 var-b: var(c);
283 var-c: #00ff00;
284
285 var-one: var(two);
286 var-two: var(one);
287
288 var-four: var(five);
289 var-five: var(six);
290 var-six: var(four);
291
292 var-def-1: var(def-2);
293 var-def-2: var(def-3);
294 var-def-3: var(def-2);
295 }
296 .testIt {
297 color: var(color-foreground);
298 background: var(color-background);
299 }
300 .test-2 {
301 color: var(one);
302 }
303 ''';
304
305 final generated = ''':root {
306 var-color-background: #f00;
307 var-color-foreground: #00f;
308 var-a: var(b);
309 var-b: var(c);
310 var-c: #0f0;
311 }
312 .testIt {
313 color: var(color-foreground);
314 background: var(color-background);
315 }
316 .test-2 {
317 color: var(one);
318 }''';
319
320 var stylesheet = compileCss(input, errors: errors,
321 opts: ['--no-colors', '--warnings_as_errors', 'memory']);
322
323 expect(stylesheet != null, true);
324 expect(errors.length, 8, reason: errors.toString());
325 expect(errors[0].toString(),
326 'error :14:3: var cycle detected var-six\n'
327 ' var-six: var(four);\n'
328 ' ^^^^^^^^^^^^^^^^^^');
329 expect(errors[1].toString(),
330 'error :18:3: var cycle detected var-def-3\n'
331 ' var-def-3: var(def-2);\n'
332 ' ^^^^^^^^^^^^^^^^^^^^^');
333 expect(errors[2].toString(),
334 'error :10:3: var cycle detected var-two\n'
335 ' var-two: var(one);\n'
336 ' ^^^^^^^^^^^^^^^^^');
337 expect(errors[3].toString(),
338 'error :17:3: var cycle detected var-def-2\n'
339 ' var-def-2: var(def-3);\n'
340 ' ^^^^^^^^^^^^^^^^^^^^^');
341 expect(errors[4].toString(),
342 'error :16:3: var cycle detected var-def-1\n'
343 ' var-def-1: var(def-2);\n'
344 ' ^^^^^^^^^^^^^^^^^^^^^');
345 expect(errors[5].toString(),
346 'error :13:3: var cycle detected var-five\n'
347 ' var-five: var(six);\n'
348 ' ^^^^^^^^^^^^^^^^^^');
349 expect(errors[6].toString(),
350 'error :9:3: var cycle detected var-one\n'
351 ' var-one: var(two);\n'
352 ' ^^^^^^^^^^^^^^^^^');
353 expect(errors[7].toString(),
354 'error :12:3: var cycle detected var-four\n'
355 ' var-four: var(five);\n'
356 ' ^^^^^^^^^^^^^^^^^^^');
357 expect(prettyPrint(stylesheet), generated);
358 }
359
360 parserVar() {
361 final errors = [];
362 final input = ''':root {
363 var-color-background: red;
364 var-color-foreground: blue;
365
366 var-a: var(b);
367 var-b: var(c);
368 var-c: #00ff00;
369
370 var-image: url(test.png);
371
372 var-b-width: 20cm;
373 var-m-width: 33%;
374 var-b-height: 30EM;
375 var-width: .6in;
376 var-length: 1.2in;
377 var-web-stuff: -10Px;
378 var-rgba: rgba(10,20,255);
379 var-transition: color 0.4s;
380 var-transform: rotate(20deg);
381 var-content: "✔";
382 var-text-shadow: 0 -1px 0 #bfbfbf;
383 var-font-family: Gentium;
384 var-src: url("http://example.com/fonts/Gentium.ttf");
385 var-src-1: local(Gentium Bold), local(Gentium-Bold), url("GentiumBold.ttf");
386 var-unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
387 var-unicode-range-1: U+0A-FF, U+980-9FF, U+????, U+3???;
388 var-grid-columns: 10px ("content" 1fr 10px) [4];
389 }
390
391 .testIt {
392 color: var(color-foreground);
393 background: var(c);
394 background-image: var(image);
395
396 border-width: var(b-width);
397 margin-width: var(m-width);
398 border-height: var(b-height);
399 width: var(width);
400 length: var(length);
401 -web-stuff: var(web-stuff);
402 background-color: var(rgba);
403
404 transition: var(transition);
405 transform: var(transform);
406 content: var(content);
407 text-shadow: var(text-shadow);
408 }
409
410 @font-face {
411 font-family: var(font-family);
412 src: var(src);
413 unicode-range: var(unicode-range);
414 }
415
416 @font-face {
417 font-family: var(font-family);
418 src: var(src-1);
419 unicode-range: var(unicode-range-1);
420 }
421
422 .foobar {
423 grid-columns: var(grid-columns);
424 }
425 ''';
426
427 final generated = ''':root {
428 var-color-background: #f00;
429 var-color-foreground: #00f;
430 var-a: var(b);
431 var-b: var(c);
432 var-c: #0f0;
433 var-image: url("test.png");
434 var-b-width: 20cm;
435 var-m-width: 33%;
436 var-b-height: 30em;
437 var-width: .6in;
438 var-length: 1.2in;
439 var-web-stuff: -10px;
440 var-rgba: rgba(10, 20, 255);
441 var-transition: color 0.4s;
442 var-transform: rotate(20deg);
443 var-content: "✔";
444 var-text-shadow: 0 -1px 0 #bfbfbf;
445 var-font-family: Gentium;
446 var-src: url("http://example.com/fonts/Gentium.ttf");
447 var-src-1: local(Gentium Bold), local(Gentium-Bold), url("GentiumBold.ttf");
448 var-unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
449 var-unicode-range-1: U+0A-FF, U+980-9FF, U+????, U+3???;
450 var-grid-columns: 10px ("content" 1fr 10px) [4];
451 }
452 .testIt {
453 color: var(color-foreground);
454 background: var(c);
455 background-image: var(image);
456 border-width: var(b-width);
457 margin-width: var(m-width);
458 border-height: var(b-height);
459 width: var(width);
460 length: var(length);
461 -web-stuff: var(web-stuff);
462 background-color: var(rgba);
463 transition: var(transition);
464 transform: var(transform);
465 content: var(content);
466 text-shadow: var(text-shadow);
467 }
468 @font-face {
469 font-family: var(font-family);
470 src: var(src);
471 unicode-range: var(unicode-range);
472 }
473 @font-face {
474 font-family: var(font-family);
475 src: var(src-1);
476 unicode-range: var(unicode-range-1);
477 }
478 .foobar {
479 grid-columns: var(grid-columns);
480 }''';
481
482 var stylesheet = parseCss(input, errors: errors,
483 opts: ['--no-colors', 'memory']);
484
485 expect(stylesheet != null, true);
486 expect(errors.isEmpty, true, reason: errors.toString());
487 expect(prettyPrint(stylesheet), generated);
488 }
489
490 testVar() {
491 final errors = [];
492 final input = '''
493 @color-background: red;
494 @color-foreground: blue;
495
496 .test {
497 background-color: var(color-background);
498 color: var(color-foreground);
499 }
500 ''';
501 final generated = '''
502 var-color-background: #f00;
503 var-color-foreground: #00f;
504
505 .test {
506 background-color: var(color-background);
507 color: var(color-foreground);
508 }''';
509
510 var stylesheet = parseCss(input, errors: errors,
511 opts: ['--no-colors', 'memory']);
512
513 expect(stylesheet != null, true);
514 expect(errors.isEmpty, true, reason: errors.toString());
515 expect(prettyPrint(stylesheet), generated);
516
517 stylesheet = compileCss(input, errors: errors..clear(),
518 opts: ['--no-colors', 'memory']);
519
520 expect(stylesheet != null, true);
521 expect(errors.isEmpty, true, reason: errors.toString());
522 expect(prettyPrint(stylesheet), generated);
523
524 final input2 = '''
525 @color-background: red;
526 @color-foreground: blue;
527
528 .test {
529 background-color: @color-background;
530 color: @color-foreground;
531 }
532 ''';
533 final generated2 = '''var-color-background: #f00;
534 var-color-foreground: #00f;
535
536 .test {
537 background-color: var(color-background);
538 color: var(color-foreground);
539 }''';
540
541 stylesheet = parseCss(input, errors: errors..clear(),
542 opts: ['--no-colors', 'memory']);
543
544 expect(stylesheet != null, true);
545 expect(errors.isEmpty, true, reason: errors.toString());
546 expect(prettyPrint(stylesheet), generated2);
547
548 stylesheet = compileCss(input2, errors: errors..clear(),
549 opts: ['--no-colors', 'memory', '--no-less']);
550
551 expect(stylesheet != null, true);
552 expect(errors.isEmpty, true, reason: errors.toString());
553 expect(prettyPrint(stylesheet), generated2);
554 }
555
556 testLess() {
557 final errors = [];
558 final input = '''
559 @color-background: red;
560 @color-foreground: blue;
561
562 .test {
563 background-color: var(color-background);
564 color: var(color-foreground);
565 }
566 ''';
567 final generated = '''var-color-background: #f00;
568 var-color-foreground: #00f;
569
570 .test {
571 background-color: var(color-background);
572 color: var(color-foreground);
573 }''';
574
575 var stylesheet = parseCss(input, errors: errors,
576 opts: ['--no-colors', 'memory']);
577
578 expect(stylesheet != null, true);
579 expect(errors.isEmpty, true, reason: errors.toString());
580 expect(prettyPrint(stylesheet), generated);
581
582 stylesheet = compileCss(input, errors: errors..clear(),
583 opts: ['--no-colors', 'memory']);
584
585 expect(stylesheet != null, true);
586 expect(errors.isEmpty, true, reason: errors.toString());
587 expect(prettyPrint(stylesheet), generated);
588
589 final input2 = '''
590 @color-background: red;
591 @color-foreground: blue;
592
593 .test {
594 background-color: @color-background;
595 color: @color-foreground;
596 }
597 ''';
598 final generated2 = '''var-color-background: #f00;
599 var-color-foreground: #00f;
600
601 .test {
602 background-color: var(color-background);
603 color: var(color-foreground);
604 }''';
605
606 stylesheet = parseCss(input, errors: errors..clear(),
607 opts: ['--no-colors', 'memory']);
608
609 expect(stylesheet != null, true);
610 expect(errors.isEmpty, true, reason: errors.toString());
611 expect(prettyPrint(stylesheet), generated2);
612
613 stylesheet = compileCss(input2, errors: errors..clear(),
614 opts: ['--no-colors', 'memory', '--no-less']);
615
616 expect(stylesheet != null, true);
617 expect(errors.isEmpty, true, reason: errors.toString());
618 expect(prettyPrint(stylesheet), generated2);
619 }
620
621 main() {
622 test('Simple var', simpleVar);
623 test('Expressions var', expressionsVar);
624 test('Default value in var()', defaultVar);
625 test('CSS Parser only var', parserVar);
626 test('Var syntax', testVar);
627 test('Cycles var', cyclesVar);
628 test('Less syntax', testLess);
629 }
OLDNEW
« no previous file with comments | « pkg/csslib/test/testing.dart ('k') | pkg/csslib/test/visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698