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

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

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 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
« no previous file with comments | « packages/csslib/test/declaration_test.dart ('k') | packages/csslib/test/extend_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) 2013, the Dart project authors. Please see the AUTHORS file 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 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 error_test; 5 library error_test;
6 6
7 import 'package:csslib/src/messages.dart'; 7 import 'package:csslib/src/messages.dart';
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 import 'testing.dart'; 10 import 'testing.dart';
11 11
12 /** 12 /**
13 * Test for unsupported font-weights values of bolder, lighter and inherit. 13 * Test for unsupported font-weights values of bolder, lighter and inherit.
14 */ 14 */
15 void testUnsupportedFontWeights() { 15 void testUnsupportedFontWeights() {
16 var errors = []; 16 var errors = <Message>[];
17 17
18 // TODO(terry): Need to support bolder. 18 // TODO(terry): Need to support bolder.
19 // font-weight value bolder. 19 // font-weight value bolder.
20 var input = ".foobar { font-weight: bolder; }"; 20 var input = ".foobar { font-weight: bolder; }";
21 var stylesheet = parseCss(input, errors: errors); 21 var stylesheet = parseCss(input, errors: errors);
22 22
23 expect(errors.isEmpty, false); 23 expect(errors.isEmpty, false);
24 expect(errors[0].toString(), r''' 24 expect(
25 errors[0].toString(),
26 r'''
25 error on line 1, column 24: Unknown property value bolder 27 error on line 1, column 24: Unknown property value bolder
26 .foobar { font-weight: bolder; } 28 .foobar { font-weight: bolder; }
27 ^^^^^^'''); 29 ^^^^^^''');
28 expect(stylesheet != null, true); 30 expect(stylesheet != null, true);
29 31
30 expect(prettyPrint(stylesheet), r''' 32 expect(
33 prettyPrint(stylesheet),
34 r'''
31 .foobar { 35 .foobar {
32 font-weight: bolder; 36 font-weight: bolder;
33 }'''); 37 }''');
34 38
35 // TODO(terry): Need to support lighter. 39 // TODO(terry): Need to support lighter.
36 // font-weight value lighter. 40 // font-weight value lighter.
37 input = ".foobar { font-weight: lighter; }"; 41 input = ".foobar { font-weight: lighter; }";
38 stylesheet = parseCss(input, errors: errors..clear()); 42 stylesheet = parseCss(input, errors: errors..clear());
39 43
40 expect(errors.isEmpty, false); 44 expect(errors.isEmpty, false);
41 expect(errors[0].toString(), r''' 45 expect(
46 errors[0].toString(),
47 r'''
42 error on line 1, column 24: Unknown property value lighter 48 error on line 1, column 24: Unknown property value lighter
43 .foobar { font-weight: lighter; } 49 .foobar { font-weight: lighter; }
44 ^^^^^^^'''); 50 ^^^^^^^''');
45 expect(stylesheet != null, true); 51 expect(stylesheet != null, true);
46 expect(prettyPrint(stylesheet), r''' 52 expect(
53 prettyPrint(stylesheet),
54 r'''
47 .foobar { 55 .foobar {
48 font-weight: lighter; 56 font-weight: lighter;
49 }'''); 57 }''');
50 58
51 // TODO(terry): Need to support inherit. 59 // TODO(terry): Need to support inherit.
52 // font-weight value inherit. 60 // font-weight value inherit.
53 input = ".foobar { font-weight: inherit; }"; 61 input = ".foobar { font-weight: inherit; }";
54 stylesheet = parseCss(input, errors: errors..clear()); 62 stylesheet = parseCss(input, errors: errors..clear());
55 63
56 expect(errors.isEmpty, false); 64 expect(errors.isEmpty, false);
57 expect(errors[0].toString(), r''' 65 expect(
66 errors[0].toString(),
67 r'''
58 error on line 1, column 24: Unknown property value inherit 68 error on line 1, column 24: Unknown property value inherit
59 .foobar { font-weight: inherit; } 69 .foobar { font-weight: inherit; }
60 ^^^^^^^'''); 70 ^^^^^^^''');
61 expect(stylesheet != null, true); 71 expect(stylesheet != null, true);
62 expect(prettyPrint(stylesheet), r''' 72 expect(
73 prettyPrint(stylesheet),
74 r'''
63 .foobar { 75 .foobar {
64 font-weight: inherit; 76 font-weight: inherit;
65 }'''); 77 }''');
66 } 78 }
67 79
68 /** 80 /**
69 * Test for unsupported line-height values of units other than px, pt and 81 * Test for unsupported line-height values of units other than px, pt and
70 * inherit. 82 * inherit.
71 */ 83 */
72 void testUnsupportedLineHeights() { 84 void testUnsupportedLineHeights() {
73 var errors = []; 85 var errors = <Message>[];
74 86
75 // line-height value in percentge unit. 87 // line-height value in percentge unit.
76 var input = ".foobar { line-height: 120%; }"; 88 var input = ".foobar { line-height: 120%; }";
77 var stylesheet = parseCss(input, errors: errors); 89 var stylesheet = parseCss(input, errors: errors);
78 90
79 expect(errors.isEmpty, false); 91 expect(errors.isEmpty, false);
80 expect(errors[0].toString(), r''' 92 expect(
93 errors[0].toString(),
94 r'''
81 error on line 1, column 24: Unexpected value for line-height 95 error on line 1, column 24: Unexpected value for line-height
82 .foobar { line-height: 120%; } 96 .foobar { line-height: 120%; }
83 ^^^'''); 97 ^^^''');
84 expect(stylesheet != null, true); 98 expect(stylesheet != null, true);
85 expect(prettyPrint(stylesheet), r''' 99 expect(
100 prettyPrint(stylesheet),
101 r'''
86 .foobar { 102 .foobar {
87 line-height: 120%; 103 line-height: 120%;
88 }'''); 104 }''');
89 105
90 // TODO(terry): Need to support all units. 106 // TODO(terry): Need to support all units.
91 // line-height value in cm unit. 107 // line-height value in cm unit.
92 input = ".foobar { line-height: 20cm; }"; 108 input = ".foobar { line-height: 20cm; }";
93 stylesheet = parseCss(input, errors: errors..clear()); 109 stylesheet = parseCss(input, errors: errors..clear());
94 110
95 expect(errors.isEmpty, false); 111 expect(errors.isEmpty, false);
96 expect(errors[0].toString(), r''' 112 expect(
113 errors[0].toString(),
114 r'''
97 error on line 1, column 24: Unexpected unit for line-height 115 error on line 1, column 24: Unexpected unit for line-height
98 .foobar { line-height: 20cm; } 116 .foobar { line-height: 20cm; }
99 ^^'''); 117 ^^''');
100 expect(stylesheet != null, true); 118 expect(stylesheet != null, true);
101 expect(prettyPrint(stylesheet), r''' 119 expect(
120 prettyPrint(stylesheet),
121 r'''
102 .foobar { 122 .foobar {
103 line-height: 20cm; 123 line-height: 20cm;
104 }'''); 124 }''');
105 125
106 // TODO(terry): Need to support inherit. 126 // TODO(terry): Need to support inherit.
107 // line-height value inherit. 127 // line-height value inherit.
108 input = ".foobar { line-height: inherit; }"; 128 input = ".foobar { line-height: inherit; }";
109 stylesheet = parseCss(input, errors: errors..clear()); 129 stylesheet = parseCss(input, errors: errors..clear());
110 130
111 expect(errors.isEmpty, false); 131 expect(errors.isEmpty, false);
112 expect(errors[0].toString(), r''' 132 expect(
133 errors[0].toString(),
134 r'''
113 error on line 1, column 24: Unknown property value inherit 135 error on line 1, column 24: Unknown property value inherit
114 .foobar { line-height: inherit; } 136 .foobar { line-height: inherit; }
115 ^^^^^^^'''); 137 ^^^^^^^''');
116 expect(stylesheet != null, true); 138 expect(stylesheet != null, true);
117 expect(prettyPrint(stylesheet), r''' 139 expect(
140 prettyPrint(stylesheet),
141 r'''
118 .foobar { 142 .foobar {
119 line-height: inherit; 143 line-height: inherit;
120 }'''); 144 }''');
121 } 145 }
122 146
123 /** Test for bad selectors. */ 147 /** Test for bad selectors. */
124 void testBadSelectors() { 148 void testBadSelectors() {
125 var errors = []; 149 var errors = <Message>[];
126 150
127 // Invalid id selector. 151 // Invalid id selector.
128 var input = "# foo { color: #ff00ff; }"; 152 var input = "# foo { color: #ff00ff; }";
129 var stylesheet = parseCss(input, errors: errors); 153 var stylesheet = parseCss(input, errors: errors);
130 154
131 expect(errors.isEmpty, false); 155 expect(errors.isEmpty, false);
132 expect(errors[0].toString(), r''' 156 expect(
157 errors[0].toString(),
158 r'''
133 error on line 1, column 1: Not a valid ID selector expected #id 159 error on line 1, column 1: Not a valid ID selector expected #id
134 # foo { color: #ff00ff; } 160 # foo { color: #ff00ff; }
135 ^'''); 161 ^''');
136 expect(stylesheet != null, true); 162 expect(stylesheet != null, true);
137 expect(prettyPrint(stylesheet), r''' 163 expect(
164 prettyPrint(stylesheet),
165 r'''
138 # foo { 166 # foo {
139 color: #f0f; 167 color: #f0f;
140 }'''); 168 }''');
141 169
142 // Invalid class selector. 170 // Invalid class selector.
143 input = ". foo { color: #ff00ff; }"; 171 input = ". foo { color: #ff00ff; }";
144 stylesheet = parseCss(input, errors: errors..clear()); 172 stylesheet = parseCss(input, errors: errors..clear());
145 173
146 expect(errors.isEmpty, false); 174 expect(errors.isEmpty, false);
147 expect(errors[0].toString(), r''' 175 expect(
176 errors[0].toString(),
177 r'''
148 error on line 1, column 1: Not a valid class selector expected .className 178 error on line 1, column 1: Not a valid class selector expected .className
149 . foo { color: #ff00ff; } 179 . foo { color: #ff00ff; }
150 ^'''); 180 ^''');
151 expect(stylesheet != null, true); 181 expect(stylesheet != null, true);
152 expect(prettyPrint(stylesheet), r''' 182 expect(
183 prettyPrint(stylesheet),
184 r'''
153 . foo { 185 . foo {
154 color: #f0f; 186 color: #f0f;
155 }'''); 187 }''');
156 } 188 }
157 189
158 /** Test for bad hex values. */ 190 /** Test for bad hex values. */
159 void testBadHexValues() { 191 void testBadHexValues() {
160 var errors = []; 192 var errors = <Message>[];
161 193
162 // Invalid hex value. 194 // Invalid hex value.
163 var input = ".foobar { color: #AH787; }"; 195 var input = ".foobar { color: #AH787; }";
164 var stylesheet = parseCss(input, errors: errors); 196 var stylesheet = parseCss(input, errors: errors);
165 197
166 expect(errors.isEmpty, false); 198 expect(errors.isEmpty, false);
167 expect(errors[0].toString(), r''' 199 expect(
200 errors[0].toString(),
201 r'''
168 error on line 1, column 18: Bad hex number 202 error on line 1, column 18: Bad hex number
169 .foobar { color: #AH787; } 203 .foobar { color: #AH787; }
170 ^^^^^^'''); 204 ^^^^^^''');
171 expect(stylesheet != null, true); 205 expect(stylesheet != null, true);
172 expect(prettyPrint(stylesheet), r''' 206 expect(
207 prettyPrint(stylesheet),
208 r'''
173 .foobar { 209 .foobar {
174 color: #AH787; 210 color: #AH787;
175 }'''); 211 }''');
176 212
177 // Bad color constant. 213 // Bad color constant.
178 input = ".foobar { color: redder; }"; 214 input = ".foobar { color: redder; }";
179 stylesheet = parseCss(input, errors: errors..clear()); 215 stylesheet = parseCss(input, errors: errors..clear());
180 216
181 expect(errors.isEmpty, false); 217 expect(errors.isEmpty, false);
182 expect(errors[0].toString(), r''' 218 expect(
219 errors[0].toString(),
220 r'''
183 error on line 1, column 18: Unknown property value redder 221 error on line 1, column 18: Unknown property value redder
184 .foobar { color: redder; } 222 .foobar { color: redder; }
185 ^^^^^^'''); 223 ^^^^^^''');
186 224
187 expect(stylesheet != null, true); 225 expect(stylesheet != null, true);
188 expect(prettyPrint(stylesheet), r''' 226 expect(
227 prettyPrint(stylesheet),
228 r'''
189 .foobar { 229 .foobar {
190 color: redder; 230 color: redder;
191 }'''); 231 }''');
192 232
193 // Bad hex color #<space>ffffff. 233 // Bad hex color #<space>ffffff.
194 input = ".foobar { color: # ffffff; }"; 234 input = ".foobar { color: # ffffff; }";
195 stylesheet = parseCss(input, errors: errors..clear()); 235 stylesheet = parseCss(input, errors: errors..clear());
196 236
197 expect(errors.isEmpty, false); 237 expect(errors.isEmpty, false);
198 expect(errors[0].toString(), r''' 238 expect(
239 errors[0].toString(),
240 r'''
199 error on line 1, column 18: Expected hex number 241 error on line 1, column 18: Expected hex number
200 .foobar { color: # ffffff; } 242 .foobar { color: # ffffff; }
201 ^'''); 243 ^''');
202 244
203 expect(stylesheet != null, true); 245 expect(stylesheet != null, true);
204 expect(prettyPrint(stylesheet), r''' 246 expect(
247 prettyPrint(stylesheet),
248 r'''
205 .foobar { 249 .foobar {
206 color: # ffffff; 250 color: # ffffff;
207 }'''); 251 }''');
208 252
209 // Bad hex color #<space>123fff. 253 // Bad hex color #<space>123fff.
210 input = ".foobar { color: # 123fff; }"; 254 input = ".foobar { color: # 123fff; }";
211 stylesheet = parseCss(input, errors: errors..clear()); 255 stylesheet = parseCss(input, errors: errors..clear());
212 256
213 expect(errors.isEmpty, false); 257 expect(errors.isEmpty, false);
214 expect(errors[0].toString(), r''' 258 expect(
259 errors[0].toString(),
260 r'''
215 error on line 1, column 18: Expected hex number 261 error on line 1, column 18: Expected hex number
216 .foobar { color: # 123fff; } 262 .foobar { color: # 123fff; }
217 ^'''); 263 ^''');
218 264
219 expect(stylesheet != null, true); 265 expect(stylesheet != null, true);
220 266
221 // Formating is off with an extra space. However, the entire value is bad 267 // Formating is off with an extra space. However, the entire value is bad
222 // and isn't processed anyway. 268 // and isn't processed anyway.
223 expect(prettyPrint(stylesheet), r''' 269 expect(
270 prettyPrint(stylesheet),
271 r'''
224 .foobar { 272 .foobar {
225 color: # 123 fff; 273 color: # 123 fff;
226 }'''); 274 }''');
227 } 275 }
228 276
229 void testBadUnicode() { 277 void testBadUnicode() {
230 var errors = []; 278 var errors = <Message>[];
231 final String input = ''' 279 final String input = '''
232 @font-face { 280 @font-face {
233 src: url(fonts/BBCBengali.ttf) format("opentype"); 281 src: url(fonts/BBCBengali.ttf) format("opentype");
234 unicode-range: U+400-200; 282 unicode-range: U+400-200;
235 }'''; 283 }''';
236 284
237 parseCss(input, errors: errors); 285 parseCss(input, errors: errors);
238 286
239 expect(errors.isEmpty, false); 287 expect(errors.isEmpty, false);
240 expect(errors[0].toString(), 288 expect(
289 errors[0].toString(),
241 'error on line 3, column 20: unicode first range can not be greater than ' 290 'error on line 3, column 20: unicode first range can not be greater than '
242 'last\n' 291 'last\n'
243 ' unicode-range: U+400-200;\n' 292 ' unicode-range: U+400-200;\n'
244 ' ^^^^^^^'); 293 ' ^^^^^^^');
245 294
246 final String input2 = ''' 295 final String input2 = '''
247 @font-face { 296 @font-face {
248 src: url(fonts/BBCBengali.ttf) format("opentype"); 297 src: url(fonts/BBCBengali.ttf) format("opentype");
249 unicode-range: U+12FFFF; 298 unicode-range: U+12FFFF;
250 }'''; 299 }''';
251 300
252 parseCss(input2, errors: errors..clear()); 301 parseCss(input2, errors: errors..clear());
253 302
254 expect(errors.isEmpty, false); 303 expect(errors.isEmpty, false);
255 expect(errors[0].toString(), 304 expect(
305 errors[0].toString(),
256 'error on line 3, column 20: unicode range must be less than 10FFFF\n' 306 'error on line 3, column 20: unicode range must be less than 10FFFF\n'
257 ' unicode-range: U+12FFFF;\n' 307 ' unicode-range: U+12FFFF;\n'
258 ' ^^^^^^'); 308 ' ^^^^^^');
259 } 309 }
260 310
261 void testBadNesting() { 311 void testBadNesting() {
262 var errors = []; 312 var errors = <Message>[];
263 313
264 // Test for bad declaration in a nested rule. 314 // Test for bad declaration in a nested rule.
265 final String input = ''' 315 final String input = '''
266 div { 316 div {
267 width: 20px; 317 width: 20px;
268 span + ul { color: blue; } 318 span + ul { color: blue; }
269 span + ul > #aaaa { 319 span + ul > #aaaa {
270 color: #ffghghgh; 320 color: #ffghghgh;
271 } 321 }
272 background-color: red; 322 background-color: red;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 395 }
346 396
347 main() { 397 main() {
348 test('font-weight value errors', testUnsupportedFontWeights); 398 test('font-weight value errors', testUnsupportedFontWeights);
349 test('line-height value errors', testUnsupportedLineHeights); 399 test('line-height value errors', testUnsupportedLineHeights);
350 test('bad selectors', testBadSelectors); 400 test('bad selectors', testBadSelectors);
351 test('bad Hex values', testBadHexValues); 401 test('bad Hex values', testBadHexValues);
352 test('bad unicode ranges', testBadUnicode); 402 test('bad unicode ranges', testBadUnicode);
353 test('nested rules', testBadNesting); 403 test('nested rules', testBadNesting);
354 } 404 }
OLDNEW
« no previous file with comments | « packages/csslib/test/declaration_test.dart ('k') | packages/csslib/test/extend_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698