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

Side by Side Diff: packages/csslib/test/nested_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/csslib/test/mixin_test.dart ('k') | packages/csslib/test/selector_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 nested_test;
6
7 import 'package:test/test.dart';
8
9 import 'testing.dart';
10
11 compileAndValidate(String input, String generated) {
12 var errors = [];
13 var stylesheet = compileCss(input, errors: errors, opts: simpleOptions);
14 expect(stylesheet != null, true);
15 expect(errors.isEmpty, true, reason: errors.toString());
16 expect(prettyPrint(stylesheet), generated);
17 }
18
19 selectorVariations() {
20 final input1 = r'''html { color: red; }''';
21 final generated1 = r'''html {
22 color: #f00;
23 }''';
24 compileAndValidate(input1, generated1);
25
26 final input2 = r'''button { span { height: 200 } }''';
27 final generated2 = r'''button {
28 }
29 button span {
30 height: 200;
31 }''';
32 compileAndValidate(input2, generated2);
33
34 final input3 = r'''div { color: red; } button { span { height: 200 } }''';
35 final generated3 = r'''div {
36 color: #f00;
37 }
38 button {
39 }
40 button span {
41 height: 200;
42 }''';
43 compileAndValidate(input3, generated3);
44
45 final input4 = r'''#header { color: red; h1 { font-size: 26px; } }''';
46 final generated4 = r'''#header {
47 color: #f00;
48 }
49 #header h1 {
50 font-size: 26px;
51 }''';
52 compileAndValidate(input4, generated4);
53
54 final input5 = r'''
55 #header {
56 color: red;
57 h1 { font-size: 26px; }
58 background-color: blue;
59 }''';
60 final generated5 = r'''#header {
61 color: #f00;
62 background-color: #00f;
63 }
64 #header h1 {
65 font-size: 26px;
66 }''';
67 compileAndValidate(input5, generated5);
68
69 final input6 = r'''html { body {color: red; }}''';
70 final generated6 = r'''html {
71 }
72 html body {
73 color: #f00;
74 }''';
75 compileAndValidate(input6, generated6);
76
77 final input7 = r'''html body {color: red; }''';
78 final generated7 = r'''html body {
79 color: #f00;
80 }''';
81 compileAndValidate(input7, generated7);
82
83 final input8 = r'''
84 html, body { color: red; }
85 button { height: 200 }
86 body { width: 300px; }''';
87 final generated8 = r'''html, body {
88 color: #f00;
89 }
90 button {
91 height: 200;
92 }
93 body {
94 width: 300px;
95 }''';
96 compileAndValidate(input8, generated8);
97
98 final input9 = '''
99 html, body {
100 color: red;
101 button { height: 200 }
102 div { width: 300px; }
103 }''';
104 final generated9 = r'''html, body {
105 color: #f00;
106 }
107 html button, body button {
108 height: 200;
109 }
110 html div, body div {
111 width: 300px;
112 }''';
113 compileAndValidate(input9, generated9);
114
115 final input10 = '''
116 html {
117 color: red;
118 button, div { height: 200 }
119 body { width: 300px; }
120 }''';
121 final generated10 = r'''html {
122 color: #f00;
123 }
124 html button, html div {
125 height: 200;
126 }
127 html body {
128 width: 300px;
129 }''';
130 compileAndValidate(input10, generated10);
131
132 final input11 = '''
133 html, body {
134 color: red;
135 button, div { height: 200 }
136 table { width: 300px; }
137 }''';
138 final generated11 = r'''html, body {
139 color: #f00;
140 }
141 html button, body button, html div, body div {
142 height: 200;
143 }
144 html table, body table {
145 width: 300px;
146 }''';
147 compileAndValidate(input11, generated11);
148
149 final input12 = '''
150 html, body {
151 color: red;
152 button, div {
153 span, a, ul { height: 200 }
154 }
155 table { width: 300px; }
156 }''';
157 final generated12 = r'''html, body {
158 color: #f00;
159 }
160 '''
161 'html button span, body button span, html div span, body div span, '
162 'html button a, body button a, html div a, body div a, html button ul, '
163 r'''body button ul, html div ul, body div ul {
164 height: 200;
165 }
166 html table, body table {
167 width: 300px;
168 }''';
169 compileAndValidate(input12, generated12);
170
171 final input13 = r'''
172 #header {
173 div {
174 width: 100px;
175 a { height: 200px; }
176 }
177 color: blue;
178 }
179 span { color: #1f1f1f; }
180 ''';
181 final generated13 = r'''#header {
182 color: #00f;
183 }
184 #header div {
185 width: 100px;
186 }
187 #header div a {
188 height: 200px;
189 }
190 span {
191 color: #1f1f1f;
192 }''';
193 compileAndValidate(input13, generated13);
194 }
195
196 void simpleNest() {
197 final input = '''
198 div span { color: green; }
199 #header {
200 color: red;
201 h1 {
202 font-size: 26px;
203 font-weight: bold;
204 }
205 p {
206 font-size: 12px;
207 a {
208 text-decoration: none;
209 }
210 }
211 background-color: blue;
212 }
213 div > span[attr="foo"] { color: yellow; }
214 ''';
215
216 final generated = r'''div span {
217 color: #008000;
218 }
219 #header {
220 color: #f00;
221 background-color: #00f;
222 }
223 #header h1 {
224 font-size: 26px;
225 font-weight: bold;
226 }
227 #header p {
228 font-size: 12px;
229 }
230 #header p a {
231 text-decoration: none;
232 }
233 div > span[attr="foo"] {
234 color: #ff0;
235 }''';
236 compileAndValidate(input, generated);
237 }
238
239 void complexNest() {
240 final input = '''
241 @font-face { font-family: arial; }
242 div { color: #f0f0f0; }
243 #header + div {
244 color: url(abc.png);
245 *[attr="bar"] {
246 font-size: 26px;
247 font-weight: bold;
248 }
249 p~ul {
250 font-size: 12px;
251 :not(p) {
252 text-decoration: none;
253 div > span[attr="foo"] { color: yellow; }
254 }
255 }
256 background-color: blue;
257 span {
258 color: red;
259 .one { color: blue; }
260 .two { color: green; }
261 .three { color: yellow; }
262 .four {
263 .four-1 { background-color: #00000f; }
264 .four-2 { background-color: #0000ff; }
265 .four-3 { background-color: #000fff; }
266 .four-4 {
267 height: 44px;
268 .four-4-1 { height: 10px; }
269 .four-4-2 { height: 20px; }
270 .four-4-3 { height: 30px; }
271 width: 44px;
272 }
273 }
274 }
275 }
276 span { color: #1f1f2f; }
277 ''';
278
279 final generated = r'''@font-face {
280 font-family: arial;
281 }
282 div {
283 color: #f0f0f0;
284 }
285 #header + div {
286 color: url("abc.png");
287 background-color: #00f;
288 }
289 #header + div *[attr="bar"] {
290 font-size: 26px;
291 font-weight: bold;
292 }
293 #header + div p ~ ul {
294 font-size: 12px;
295 }
296 #header + div p ~ ul :not(p) {
297 text-decoration: none;
298 }
299 #header + div p ~ ul :not(p) div > span[attr="foo"] {
300 color: #ff0;
301 }
302 #header + div span {
303 color: #f00;
304 }
305 #header + div span .one {
306 color: #00f;
307 }
308 #header + div span .two {
309 color: #008000;
310 }
311 #header + div span .three {
312 color: #ff0;
313 }
314 #header + div span .four .four-1 {
315 background-color: #00000f;
316 }
317 #header + div span .four .four-2 {
318 background-color: #00f;
319 }
320 #header + div span .four .four-3 {
321 background-color: #000fff;
322 }
323 #header + div span .four .four-4 {
324 height: 44px;
325 width: 44px;
326 }
327 #header + div span .four .four-4 .four-4-1 {
328 height: 10px;
329 }
330 #header + div span .four .four-4 .four-4-2 {
331 height: 20px;
332 }
333 #header + div span .four .four-4 .four-4-3 {
334 height: 30px;
335 }
336 span {
337 color: #1f1f2f;
338 }''';
339
340 compileAndValidate(input, generated);
341 }
342
343 void mediaNesting() {
344 final input = r'''
345 @media screen and (-webkit-min-device-pixel-ratio:0) {
346 #toggle-all {
347 image: url(test.jpb);
348 div, table {
349 background: none;
350 a { width: 100px; }
351 }
352 color: red;
353 }
354 }
355 ''';
356 final generated = r'''@media screen AND (-webkit-min-device-pixel-ratio:0) {
357 #toggle-all {
358 image: url("test.jpb");
359 color: #f00;
360 }
361 #toggle-all div, #toggle-all table {
362 background: none;
363 }
364 #toggle-all div a, #toggle-all table a {
365 width: 100px;
366 }
367 }''';
368
369 compileAndValidate(input, generated);
370 }
371
372 void simpleThis() {
373 final input = '''#header {
374 h1 {
375 font-size: 26px;
376 font-weight: bold;
377 }
378 p { font-size: 12px;
379 a { text-decoration: none;
380 &:hover { border-width: 1px }
381 }
382 }
383 }
384 ''';
385
386 final generated = r'''#header {
387 }
388 #header h1 {
389 font-size: 26px;
390 font-weight: bold;
391 }
392 #header p {
393 font-size: 12px;
394 }
395 #header p a {
396 text-decoration: none;
397 }
398 #header p a:hover {
399 border-width: 1px;
400 }''';
401
402 compileAndValidate(input, generated);
403 }
404
405 void complexThis() {
406 final input1 = r'''
407 .light {
408 .leftCol {
409 .textLink {
410 color: fooL1;
411 &:hover { color: barL1;}
412 }
413 .picLink {
414 background-image: url(/fooL1.jpg);
415 &:hover { background-image: url(/barL1.jpg);}
416 }
417 .textWithIconLink {
418 color: fooL2;
419 background-image: url(/fooL2.jpg);
420 &:hover { color: barL2; background-image: url(/barL2.jpg);}
421 }
422 }
423 }''';
424
425 final generated1 = r'''.light {
426 }
427 .light .leftCol .textLink {
428 color: fooL1;
429 }
430 .light .leftCol .textLink:hover {
431 color: barL1;
432 }
433 .light .leftCol .picLink {
434 background-image: url("/fooL1.jpg");
435 }
436 .light .leftCol .picLink:hover {
437 background-image: url("/barL1.jpg");
438 }
439 .light .leftCol .textWithIconLink {
440 color: fooL2;
441 background-image: url("/fooL2.jpg");
442 }
443 .light .leftCol .textWithIconLink:hover {
444 color: barL2;
445 background-image: url("/barL2.jpg");
446 }''';
447
448 compileAndValidate(input1, generated1);
449
450 final input2 = r'''
451 .textLink {
452 .light .leftCol & {
453 color: fooL1;
454 &:hover { color: barL1; }
455 }
456 .light .rightCol & {
457 color: fooL3;
458 &:hover { color: barL3; }
459 }
460 }''';
461
462 final generated2 = r'''
463 .textLink {
464 }
465 .light .leftCol .textLink {
466 color: fooL1;
467 }
468 .light .leftCol .textLink:hover {
469 color: barL1;
470 }
471 .light .rightCol .textLink {
472 color: fooL3;
473 }
474 .light .rightCol .textLink:hover {
475 color: barL3;
476 }''';
477
478 compileAndValidate(input2, generated2);
479 }
480
481 variationsThis() {
482 final input1 = r'''
483 .textLink {
484 a {
485 light .leftCol & {
486 color: red;
487 }
488 }
489 }''';
490 final generated1 = r'''.textLink {
491 }
492 light .leftCol .textLink a {
493 color: #f00;
494 }''';
495
496 compileAndValidate(input1, generated1);
497
498 final input2 = r'''.textLink {
499 a {
500 & light .leftCol & {
501 color: red;
502 }
503 }
504 }''';
505 final generated2 = r'''.textLink {
506 }
507 .textLink a light .leftCol .textLink a {
508 color: #f00;
509 }''';
510 compileAndValidate(input2, generated2);
511
512 final input3 = r'''
513 .textLink {
514 a {
515 & light .leftCol { color: red; }
516 }
517 }''';
518 final generated3 = r'''.textLink {
519 }
520 .textLink a light .leftCol {
521 color: #f00;
522 }''';
523 compileAndValidate(input3, generated3);
524
525 final input4 = r'''
526 .textLink {
527 a {
528 & light .leftCol { color: red; }
529 &:hover { width: 100px; }
530 }
531 }''';
532 final generated4 = r'''.textLink {
533 }
534 .textLink a light .leftCol {
535 color: #f00;
536 }
537 .textLink a:hover {
538 width: 100px;
539 }''';
540 compileAndValidate(input4, generated4);
541
542 final input5 = r'''.textLink { a { &:hover { color: red; } } }''';
543 final generated5 = r'''.textLink {
544 }
545 .textLink a:hover {
546 color: #f00;
547 }''';
548
549 compileAndValidate(input5, generated5);
550
551 final input6 = r'''.textLink { &:hover { color: red; } }''';
552 final generated6 = r'''.textLink {
553 }
554 .textLink:hover {
555 color: #f00;
556 }''';
557 compileAndValidate(input6, generated6);
558
559 final input7 = r'''.textLink { a { & + & { color: red; } } }''';
560 final generated7 = r'''.textLink {
561 }
562 .textLink a + .textLink a {
563 color: #f00;
564 }''';
565 compileAndValidate(input7, generated7);
566
567 final input8 = r'''.textLink { a { & { color: red; } } }''';
568 final generated8 = r'''.textLink {
569 }
570 .textLink a {
571 color: #f00;
572 }''';
573 compileAndValidate(input8, generated8);
574
575 final input9 = r'''.textLink { a { & ~ & { color: red; } } }''';
576 final generated9 = r'''.textLink {
577 }
578 .textLink a ~ .textLink a {
579 color: #f00;
580 }''';
581 compileAndValidate(input9, generated9);
582
583 final input10 = r'''.textLink { a { & & { color: red; } } }''';
584 final generated10 = r'''.textLink {
585 }
586 .textLink a .textLink a {
587 color: #f00;
588 }''';
589 compileAndValidate(input10, generated10);
590 }
591
592 thisCombinator() {
593 var input = r'''
594 .btn {
595 color: red;
596 }
597 .btn + .btn {
598 margin-left: 5px;
599 }
600 input.second {
601 & + label {
602 color: blue;
603 }
604 }
605 ''';
606
607 var generated = r'''.btn {
608 color: #f00;
609 }
610 .btn + .btn {
611 margin-left: 5px;
612 }
613 input.second {
614 }
615 input.second + label {
616 color: #00f;
617 }''';
618
619 compileAndValidate(input, generated);
620 }
621
622 main() {
623 test('Selector and Nested Variations', selectorVariations);
624 test('Simple nesting', simpleNest);
625 test('Complex nesting', complexNest);
626 test('@media nesting', mediaNesting);
627 test('Simple &', simpleThis);
628 test("Variations &", variationsThis);
629 test('Complex &', complexThis);
630 test('& with + selector', thisCombinator);
631 }
OLDNEW
« no previous file with comments | « packages/csslib/test/mixin_test.dart ('k') | packages/csslib/test/selector_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698