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

Side by Side Diff: test/declaration_test.dart

Issue 1832993003: Fix all strong mode errors and warnings. (Closed) Base URL: https://github.com/dart-lang/csslib.git@master
Patch Set: Move type. Created 4 years, 8 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 | « test/compiler_test.dart ('k') | test/error_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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library declaration_test; 5 library declaration_test;
6 6
7 import 'package:csslib/src/messages.dart';
8 import 'package:csslib/visitor.dart';
7 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
8 10
9 import 'testing.dart'; 11 import 'testing.dart';
10 12
11 void testSimpleTerms() { 13 void testSimpleTerms() {
12 var errors = []; 14 var errors = <Message>[];
13 final String input = r''' 15 final String input = r'''
14 @ import url("test.css"); 16 @ import url("test.css");
15 .foo { 17 .foo {
16 background-color: #191919; 18 background-color: #191919;
17 width: 10PX; 19 width: 10PX;
18 height: 22mM !important; 20 height: 22mM !important;
19 border-width: 20cm; 21 border-width: 20cm;
20 margin-width: 33%; 22 margin-width: 33%;
21 border-height: 30EM; 23 border-height: 30EM;
22 width: .6in; 24 width: .6in;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 expect(stylesheet != null, true); 59 expect(stylesheet != null, true);
58 expect(errors.isEmpty, true, reason: errors.toString()); 60 expect(errors.isEmpty, true, reason: errors.toString());
59 expect(prettyPrint(stylesheet), generated2); 61 expect(prettyPrint(stylesheet), generated2);
60 } 62 }
61 63
62 /** 64 /**
63 * Declarations with comments, references with single-quotes, double-quotes, 65 * Declarations with comments, references with single-quotes, double-quotes,
64 * no quotes. Hex values with # and letters, and functions (rgba, url, etc.) 66 * no quotes. Hex values with # and letters, and functions (rgba, url, etc.)
65 */ 67 */
66 void testDeclarations() { 68 void testDeclarations() {
67 var errors = []; 69 var errors = <Message>[];
68 final String input = r''' 70 final String input = r'''
69 .more { 71 .more {
70 color: white; 72 color: white;
71 color: black; 73 color: black;
72 color: cyan; 74 color: cyan;
73 color: red; 75 color: red;
74 color: #aabbcc; /* test -- 3 */ 76 color: #aabbcc; /* test -- 3 */
75 color: blue; 77 color: blue;
76 background-image: url(http://test.jpeg); 78 background-image: url(http://test.jpeg);
77 background-image: url("http://double_quote.html"); 79 background-image: url("http://double_quote.html");
(...skipping 17 matching lines...) Expand all
95 }'''; 97 }''';
96 98
97 var stylesheet = parseCss(input, errors: errors); 99 var stylesheet = parseCss(input, errors: errors);
98 100
99 expect(stylesheet != null, true); 101 expect(stylesheet != null, true);
100 expect(errors.isEmpty, true, reason: errors.toString()); 102 expect(errors.isEmpty, true, reason: errors.toString());
101 expect(prettyPrint(stylesheet), generated); 103 expect(prettyPrint(stylesheet), generated);
102 } 104 }
103 105
104 void testIdentifiers() { 106 void testIdentifiers() {
105 var errors = []; 107 var errors = <Message>[];
106 final String input = r''' 108 final String input = r'''
107 #da { 109 #da {
108 height: 100px; 110 height: 100px;
109 } 111 }
110 #foo { 112 #foo {
111 width: 10px; 113 width: 10px;
112 color: #ff00cc; 114 color: #ff00cc;
113 } 115 }
114 '''; 116 ''';
115 final String generated = r''' 117 final String generated = r'''
116 #da { 118 #da {
117 height: 100px; 119 height: 100px;
118 } 120 }
119 #foo { 121 #foo {
120 width: 10px; 122 width: 10px;
121 color: #f0c; 123 color: #f0c;
122 }'''; 124 }''';
123 125
124 var stylesheet = parseCss(input, errors: errors); 126 var stylesheet = parseCss(input, errors: errors);
125 127
126 expect(errors.isEmpty, true, reason: errors.toString()); 128 expect(errors.isEmpty, true, reason: errors.toString());
127 expect(stylesheet != null, true); 129 expect(stylesheet != null, true);
128 expect(prettyPrint(stylesheet), generated); 130 expect(prettyPrint(stylesheet), generated);
129 } 131 }
130 132
131 void testComposites() { 133 void testComposites() {
132 var errors = []; 134 var errors = <Message>[];
133 final String input = r''' 135 final String input = r'''
134 .xyzzy { 136 .xyzzy {
135 border: 10px 80px 90px 100px; 137 border: 10px 80px 90px 100px;
136 width: 99%; 138 width: 99%;
137 } 139 }
138 @-webkit-keyframes pulsate { 140 @-webkit-keyframes pulsate {
139 0% { 141 0% {
140 -webkit-transform: translate3d(0, 0, 0) scale(1.0); 142 -webkit-transform: translate3d(0, 0, 0) scale(1.0);
141 } 143 }
142 }'''; 144 }''';
143 final String generated = r''' 145 final String generated = r'''
144 .xyzzy { 146 .xyzzy {
145 border: 10px 80px 90px 100px; 147 border: 10px 80px 90px 100px;
146 width: 99%; 148 width: 99%;
147 } 149 }
148 @-webkit-keyframes pulsate { 150 @-webkit-keyframes pulsate {
149 0% { 151 0% {
150 -webkit-transform: translate3d(0, 0, 0) scale(1.0); 152 -webkit-transform: translate3d(0, 0, 0) scale(1.0);
151 } 153 }
152 }'''; 154 }''';
153 155
154 var stylesheet = parseCss(input, errors: errors); 156 var stylesheet = parseCss(input, errors: errors);
155 expect(stylesheet != null, true); 157 expect(stylesheet != null, true);
156 expect(errors.isEmpty, true, reason: errors.toString()); 158 expect(errors.isEmpty, true, reason: errors.toString());
157 expect(prettyPrint(stylesheet), generated); 159 expect(prettyPrint(stylesheet), generated);
158 } 160 }
159 161
160 void testUnits() { 162 void testUnits() {
161 var errors = []; 163 var errors = <Message>[];
162 final String input = r''' 164 final String input = r'''
163 #id-1 { 165 #id-1 {
164 transition: color 0.4s; 166 transition: color 0.4s;
165 animation-duration: 500ms; 167 animation-duration: 500ms;
166 top: 1em; 168 top: 1em;
167 left: 200ex; 169 left: 200ex;
168 right: 300px; 170 right: 300px;
169 bottom: 400cm; 171 bottom: 400cm;
170 border-width: 2.5mm; 172 border-width: 2.5mm;
171 margin-top: .5in; 173 margin-top: .5in;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 }'''; 237 }''';
236 238
237 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions); 239 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions);
238 240
239 expect(stylesheet != null, true); 241 expect(stylesheet != null, true);
240 expect(errors.isEmpty, true, reason: errors.toString()); 242 expect(errors.isEmpty, true, reason: errors.toString());
241 expect(prettyPrint(stylesheet), generated); 243 expect(prettyPrint(stylesheet), generated);
242 } 244 }
243 245
244 void testUnicode() { 246 void testUnicode() {
245 var errors = []; 247 var errors = <Message>[];
246 final String input = r''' 248 final String input = r'''
247 .toggle:after { 249 .toggle:after {
248 content: '✔'; 250 content: '✔';
249 line-height: 43px; 251 line-height: 43px;
250 font-size: 20px; 252 font-size: 20px;
251 color: #d9d9d9; 253 color: #d9d9d9;
252 text-shadow: 0 -1px 0 #bfbfbf; 254 text-shadow: 0 -1px 0 #bfbfbf;
253 } 255 }
254 '''; 256 ''';
255 257
256 final String generated = r''' 258 final String generated = r'''
257 .toggle:after { 259 .toggle:after {
258 content: '✔'; 260 content: '✔';
259 line-height: 43px; 261 line-height: 43px;
260 font-size: 20px; 262 font-size: 20px;
261 color: #d9d9d9; 263 color: #d9d9d9;
262 text-shadow: 0 -1px 0 #bfbfbf; 264 text-shadow: 0 -1px 0 #bfbfbf;
263 }'''; 265 }''';
264 266
265 var stylesheet = parseCss(input, errors: errors); 267 var stylesheet = parseCss(input, errors: errors);
266 268
267 expect(stylesheet != null, true); 269 expect(stylesheet != null, true);
268 expect(errors.isEmpty, true, reason: errors.toString()); 270 expect(errors.isEmpty, true, reason: errors.toString());
269 expect(prettyPrint(stylesheet), generated); 271 expect(prettyPrint(stylesheet), generated);
270 } 272 }
271 273
272 void testNewerCss() { 274 void testNewerCss() {
273 var errors = []; 275 var errors = <Message>[];
274 final String input = r''' 276 final String input = r'''
275 @media screen,print { 277 @media screen,print {
276 .foobar_screen { 278 .foobar_screen {
277 width: 10px; 279 width: 10px;
278 } 280 }
279 } 281 }
280 @page { 282 @page {
281 height: 22px; 283 height: 22px;
282 size: 3in 3in; 284 size: 3in 3in;
283 } 285 }
(...skipping 26 matching lines...) Expand all
310 @charset "ASCII";'''; 312 @charset "ASCII";''';
311 313
312 var stylesheet = parseCss(input, errors: errors); 314 var stylesheet = parseCss(input, errors: errors);
313 315
314 expect(stylesheet != null, true); 316 expect(stylesheet != null, true);
315 expect(errors.isEmpty, true, reason: errors.toString()); 317 expect(errors.isEmpty, true, reason: errors.toString());
316 expect(prettyPrint(stylesheet), generated); 318 expect(prettyPrint(stylesheet), generated);
317 } 319 }
318 320
319 void testMediaQueries() { 321 void testMediaQueries() {
320 var errors = []; 322 var errors = <Message>[];
321 String input = ''' 323 String input = '''
322 @media screen and (-webkit-min-device-pixel-ratio:0) { 324 @media screen and (-webkit-min-device-pixel-ratio:0) {
323 .todo-item .toggle { 325 .todo-item .toggle {
324 background: none; 326 background: none;
325 } 327 }
326 #todo-item .toggle { 328 #todo-item .toggle {
327 height: 40px; 329 height: 40px;
328 } 330 }
329 }'''; 331 }''';
330 String generated = ''' 332 String generated = '''
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 '@import "test.css" ONLY screen, NOT print (min-device-width:4000px);'; 430 '@import "test.css" ONLY screen, NOT print (min-device-width:4000px);';
429 431
430 stylesheet = parseCss(input, errors: errors..clear(), opts: simpleOptions); 432 stylesheet = parseCss(input, errors: errors..clear(), opts: simpleOptions);
431 433
432 expect(stylesheet != null, true); 434 expect(stylesheet != null, true);
433 expect(errors.isEmpty, true, reason: errors.toString()); 435 expect(errors.isEmpty, true, reason: errors.toString());
434 expect(prettyPrint(stylesheet), generated); 436 expect(prettyPrint(stylesheet), generated);
435 } 437 }
436 438
437 void testFontFace() { 439 void testFontFace() {
438 var errors = []; 440 var errors = <Message>[];
439 441
440 final String input = ''' 442 final String input = '''
441 @font-face { 443 @font-face {
442 font-family: BBCBengali; 444 font-family: BBCBengali;
443 src: url(fonts/BBCBengali.ttf) format("opentype"); 445 src: url(fonts/BBCBengali.ttf) format("opentype");
444 unicode-range: U+0A-FF, U+980-9FF, U+????, U+3???; 446 unicode-range: U+0A-FF, U+980-9FF, U+????, U+3???;
445 }'''; 447 }''';
446 final String generated = '''@font-face { 448 final String generated = '''@font-face {
447 font-family: BBCBengali; 449 font-family: BBCBengali;
448 src: url("fonts/BBCBengali.ttf") format("opentype"); 450 src: url("fonts/BBCBengali.ttf") format("opentype");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF; 522 unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
521 }'''; 523 }''';
522 stylesheet = parseCss(input4, errors: errors..clear(), opts: simpleOptions); 524 stylesheet = parseCss(input4, errors: errors..clear(), opts: simpleOptions);
523 525
524 expect(stylesheet != null, true); 526 expect(stylesheet != null, true);
525 expect(errors.isEmpty, true, reason: errors.toString()); 527 expect(errors.isEmpty, true, reason: errors.toString());
526 expect(prettyPrint(stylesheet), generated4); 528 expect(prettyPrint(stylesheet), generated4);
527 } 529 }
528 530
529 void testCssFile() { 531 void testCssFile() {
530 var errors = []; 532 var errors = <Message>[];
531 final String input = r''' 533 final String input = r'''
532 @import 'simple.css' 534 @import 'simple.css'
533 @import "test.css" print 535 @import "test.css" print
534 @import url(test.css) screen, print 536 @import url(test.css) screen, print
535 @import url(http://google.com/maps/maps.css); 537 @import url(http://google.com/maps/maps.css);
536 538
537 div[href^='test'] { 539 div[href^='test'] {
538 height: 10px; 540 height: 10px;
539 } 541 }
540 542
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 ' background: url("http://www.foo.com/bar.png");\n' 586 ' background: url("http://www.foo.com/bar.png");\n'
585 '}'; 587 '}';
586 var stylesheet = parseCss(input, errors: errors); 588 var stylesheet = parseCss(input, errors: errors);
587 589
588 expect(stylesheet != null, true); 590 expect(stylesheet != null, true);
589 expect(errors.isEmpty, true, reason: errors.toString()); 591 expect(errors.isEmpty, true, reason: errors.toString());
590 expect(prettyPrint(stylesheet), generated); 592 expect(prettyPrint(stylesheet), generated);
591 } 593 }
592 594
593 void testCompactEmitter() { 595 void testCompactEmitter() {
594 var errors = []; 596 var errors = <Message>[];
595 597
596 // Check !import compactly emitted. 598 // Check !import compactly emitted.
597 final String input = r''' 599 final String input = r'''
598 div { 600 div {
599 color: green !important; 601 color: green !important;
600 } 602 }
601 '''; 603 ''';
602 final String generated = "div { color: green!important; }"; 604 final String generated = "div { color: green!important; }";
603 605
604 var stylesheet = parseCss(input, errors: errors); 606 var stylesheet = parseCss(input, errors: errors);
605 607
606 expect(stylesheet != null, true); 608 expect(stylesheet != null, true);
607 expect(errors.isEmpty, true, reason: errors.toString()); 609 expect(errors.isEmpty, true, reason: errors.toString());
608 expect(compactOuptut(stylesheet), generated); 610 expect(compactOuptut(stylesheet), generated);
609 611
610 // Check namespace directive compactly emitted. 612 // Check namespace directive compactly emitted.
611 final String input2 = "@namespace a url(http://www.example.org/a);"; 613 final String input2 = "@namespace a url(http://www.example.org/a);";
612 final String generated2 = "@namespace a url(http://www.example.org/a);"; 614 final String generated2 = "@namespace a url(http://www.example.org/a);";
613 615
614 var stylesheet2 = parseCss(input2, errors: errors..clear()); 616 var stylesheet2 = parseCss(input2, errors: errors..clear());
615 617
616 expect(stylesheet2 != null, true); 618 expect(stylesheet2 != null, true);
617 expect(errors.isEmpty, true, reason: errors.toString()); 619 expect(errors.isEmpty, true, reason: errors.toString());
618 expect(compactOuptut(stylesheet2), generated2); 620 expect(compactOuptut(stylesheet2), generated2);
619 } 621 }
620 622
621 void testNotSelectors() { 623 void testNotSelectors() {
622 var errors = []; 624 var errors = <Message>[];
623 625
624 final String input = r''' 626 final String input = r'''
625 .details:not(.open-details) x-element, 627 .details:not(.open-details) x-element,
626 .details:not(.open-details) .summary { 628 .details:not(.open-details) .summary {
627 overflow: hidden; 629 overflow: hidden;
628 } 630 }
629 631
630 .details:not(.open-details) x-icon { 632 .details:not(.open-details) x-icon {
631 margin-left: 99px; 633 margin-left: 99px;
632 } 634 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 }'''; 704 }''';
703 705
704 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions); 706 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions);
705 707
706 expect(stylesheet != null, true); 708 expect(stylesheet != null, true);
707 expect(errors.isEmpty, true, reason: errors.toString()); 709 expect(errors.isEmpty, true, reason: errors.toString());
708 expect(prettyPrint(stylesheet), generated); 710 expect(prettyPrint(stylesheet), generated);
709 } 711 }
710 712
711 void testIE() { 713 void testIE() {
712 var errors = []; 714 var errors = <Message>[];
713 final String input = ".test {\n" 715 final String input = ".test {\n"
714 " filter: progid:DXImageTransform.Microsoft.gradient" 716 " filter: progid:DXImageTransform.Microsoft.gradient"
715 "(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');\n" 717 "(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');\n"
716 "}"; 718 "}";
717 final String generated = ".test {\n" 719 final String generated = ".test {\n"
718 " filter: progid:DXImageTransform.Microsoft.gradient" 720 " filter: progid:DXImageTransform.Microsoft.gradient"
719 "(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');\n" 721 "(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');\n"
720 "}"; 722 "}";
721 723
722 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions); 724 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 * Test IE specific declaration syntax: 780 * Test IE specific declaration syntax:
779 * IE6 property name prefixed with _ (normal CSS property name can start 781 * IE6 property name prefixed with _ (normal CSS property name can start
780 * with an underscore). 782 * with an underscore).
781 * 783 *
782 * IE7 or below property add asterisk before the CSS property. 784 * IE7 or below property add asterisk before the CSS property.
783 * 785 *
784 * IE8 or below add \9 at end of declaration expression e.g., 786 * IE8 or below add \9 at end of declaration expression e.g.,
785 * background: red\9; 787 * background: red\9;
786 */ 788 */
787 void testIEDeclaration() { 789 void testIEDeclaration() {
788 var errors = []; 790 var errors = <Message>[];
789 791
790 final input = ''' 792 final input = '''
791 .testIE-6 { 793 .testIE-6 {
792 _zoom : 5; 794 _zoom : 5;
793 } 795 }
794 .clearfix { 796 .clearfix {
795 *zoom: 1; 797 *zoom: 1;
796 } 798 }
797 audio, video { 799 audio, video {
798 display: inline-block; 800 display: inline-block;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 946 }
945 }'''; 947 }''';
946 948
947 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions); 949 var stylesheet = parseCss(input, errors: errors, opts: simpleOptions);
948 expect(stylesheet != null, true); 950 expect(stylesheet != null, true);
949 expect(errors.isEmpty, true, reason: errors.toString()); 951 expect(errors.isEmpty, true, reason: errors.toString());
950 expect(prettyPrint(stylesheet), generated); 952 expect(prettyPrint(stylesheet), generated);
951 } 953 }
952 954
953 void testHangs() { 955 void testHangs() {
954 var errors = []; 956 var errors = <Message>[];
955 957
956 // Bad hexvalue had caused a hang in processTerm. 958 // Bad hexvalue had caused a hang in processTerm.
957 final input = r'''#a { color: #ebebeburl(0/IE8+9+); }'''; 959 final input = r'''#a { color: #ebebeburl(0/IE8+9+); }''';
958 var stylesheet = parseCss(input, errors: errors, opts: options); 960 var stylesheet = parseCss(input, errors: errors, opts: options);
959 961
960 expect(stylesheet != null, true); 962 expect(stylesheet != null, true);
961 expect(errors.length, 3, reason: errors.toString()); 963 expect(errors.length, 3, reason: errors.toString());
962 964
963 var errorMessage = errors[0]; 965 var errorMessage = errors[0];
964 expect(errorMessage.message, contains('Bad hex number')); 966 expect(errorMessage.message, contains('Bad hex number'));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 expect(errorMessage.message, contains('unexpected end of file')); 1003 expect(errorMessage.message, contains('unexpected end of file'));
1002 expect(errorMessage.span, isNotNull); 1004 expect(errorMessage.span, isNotNull);
1003 expect(errorMessage.span.start.line, 7); 1005 expect(errorMessage.span.start.line, 7);
1004 expect(errorMessage.span.start.column, 0); 1006 expect(errorMessage.span.start.column, 0);
1005 expect(errorMessage.span.text.trim(), ''); 1007 expect(errorMessage.span.text.trim(), '');
1006 } 1008 }
1007 1009
1008 void testExpressionSpans() { 1010 void testExpressionSpans() {
1009 final input = r'''.foo { width: 50px; }'''; 1011 final input = r'''.foo { width: 50px; }''';
1010 var stylesheet = parseCss(input); 1012 var stylesheet = parseCss(input);
1011 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1013 var decl = (stylesheet.topLevels.single as RuleSet)
1014 .declarationGroup
1015 .declarations
1016 .single;
1012 // This passes 1017 // This passes
1013 expect(decl.span.text, 'width: 50px'); 1018 expect(decl.span.text, 'width: 50px');
1014 // This currently fails 1019 // This currently fails
1015 expect(decl.expression.span.text, '50px'); 1020 expect((decl as Declaration).expression.span.text, '50px');
1016 } 1021 }
1017 1022
1018 void simpleCalc() { 1023 void simpleCalc() {
1019 final input = r'''.foo { height: calc(100% - 55px); }'''; 1024 final input = r'''.foo { height: calc(100% - 55px); }''';
1020 var stylesheet = parseCss(input); 1025 var stylesheet = parseCss(input);
1021 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1026 var decl = (stylesheet.topLevels.single as RuleSet)
1027 .declarationGroup
1028 .declarations
1029 .single;
1022 expect(decl.span.text, 'height: calc(100% - 55px)'); 1030 expect(decl.span.text, 'height: calc(100% - 55px)');
1023 } 1031 }
1024 1032
1025 void complexCalc() { 1033 void complexCalc() {
1026 final input = r'''.foo { left: calc((100%/3 - 2) * 1em - 2 * 1px); }'''; 1034 final input = r'''.foo { left: calc((100%/3 - 2) * 1em - 2 * 1px); }''';
1027 var stylesheet = parseCss(input); 1035 var stylesheet = parseCss(input);
1028 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1036 var decl = (stylesheet.topLevels.single as RuleSet)
1037 .declarationGroup
1038 .declarations
1039 .single;
1029 expect(decl.span.text, 'left: calc((100%/3 - 2) * 1em - 2 * 1px)'); 1040 expect(decl.span.text, 'left: calc((100%/3 - 2) * 1em - 2 * 1px)');
1030 } 1041 }
1031 1042
1032 void twoCalcs() { 1043 void twoCalcs() {
1033 final input = r'''.foo { margin: calc(1rem - 2px) calc(1rem - 1px); }'''; 1044 final input = r'''.foo { margin: calc(1rem - 2px) calc(1rem - 1px); }''';
1034 var stylesheet = parseCss(input); 1045 var stylesheet = parseCss(input);
1035 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1046 var decl = (stylesheet.topLevels.single as RuleSet)
1047 .declarationGroup
1048 .declarations
1049 .single;
1036 expect(decl.span.text, 'margin: calc(1rem - 2px) calc(1rem - 1px)'); 1050 expect(decl.span.text, 'margin: calc(1rem - 2px) calc(1rem - 1px)');
1037 } 1051 }
1038 1052
1039 void selectorWithCalcs() { 1053 void selectorWithCalcs() {
1040 var errors = []; 1054 var errors = <Message>[];
1041 final String input = r''' 1055 final String input = r'''
1042 .foo { 1056 .foo {
1043 width: calc(1em + 5 * 2em); 1057 width: calc(1em + 5 * 2em);
1044 height: calc(1px + 2%) !important; 1058 height: calc(1px + 2%) !important;
1045 border: 5px calc(1pt + 2cm) 6px calc(1em + 1in + 2px) red; 1059 border: 5px calc(1pt + 2cm) 6px calc(1em + 1in + 2px) red;
1046 border: calc(5px + 1em) 0px 1px calc(10 + 20 + 1px); 1060 border: calc(5px + 1em) 0px 1px calc(10 + 20 + 1px);
1047 margin: 25px calc(50px + (100% / (3 - 1em) - 20%)) calc(10px + 10 * 20) calc(1 00% - 10px); 1061 margin: 25px calc(50px + (100% / (3 - 1em) - 20%)) calc(10px + 10 * 20) calc(1 00% - 10px);
1048 }'''; 1062 }''';
1049 final String generated = r''' 1063 final String generated = r'''
1050 .foo { 1064 .foo {
(...skipping 21 matching lines...) Expand all
1072 test('Media Queries', testMediaQueries); 1086 test('Media Queries', testMediaQueries);
1073 test('Font-Face', testFontFace); 1087 test('Font-Face', testFontFace);
1074 test('CSS file', testCssFile); 1088 test('CSS file', testCssFile);
1075 test('Compact Emitter', testCompactEmitter); 1089 test('Compact Emitter', testCompactEmitter);
1076 test('Selector Negation', testNotSelectors); 1090 test('Selector Negation', testNotSelectors);
1077 test('IE stuff', testIE); 1091 test('IE stuff', testIE);
1078 test('IE declaration syntax', testIEDeclaration); 1092 test('IE declaration syntax', testIEDeclaration);
1079 test('Hanging bugs', testHangs); 1093 test('Hanging bugs', testHangs);
1080 test('Expression spans', testExpressionSpans, 1094 test('Expression spans', testExpressionSpans,
1081 skip: 'expression spans are broken' 1095 skip: 'expression spans are broken'
1082 ' (https://github.com/dart-lang/csslib/issues/15)'); 1096 ' (https://github.com/dart-lang/csslib/issues/15)');
1083 group('calc function', () { 1097 group('calc function', () {
1084 test('simple calc', simpleCalc); 1098 test('simple calc', simpleCalc);
1085 test('single complex', complexCalc); 1099 test('single complex', complexCalc);
1086 test('two calc terms for same declaration', twoCalcs); 1100 test('two calc terms for same declaration', twoCalcs);
1087 test('selector with many calc declarations', selectorWithCalcs); 1101 test('selector with many calc declarations', selectorWithCalcs);
1088 }); 1102 });
1089 } 1103 }
1090
OLDNEW
« no previous file with comments | « test/compiler_test.dart ('k') | test/error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698