OLD | NEW |
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(errors[0].toString(), r''' |
25 error on line 1, column 24: Unknown property value bolder | 25 error on line 1, column 24: Unknown property value bolder |
26 .foobar { font-weight: bolder; } | 26 .foobar { font-weight: bolder; } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 .foobar { | 63 .foobar { |
64 font-weight: inherit; | 64 font-weight: inherit; |
65 }'''); | 65 }'''); |
66 } | 66 } |
67 | 67 |
68 /** | 68 /** |
69 * Test for unsupported line-height values of units other than px, pt and | 69 * Test for unsupported line-height values of units other than px, pt and |
70 * inherit. | 70 * inherit. |
71 */ | 71 */ |
72 void testUnsupportedLineHeights() { | 72 void testUnsupportedLineHeights() { |
73 var errors = []; | 73 var errors = <Message>[]; |
74 | 74 |
75 // line-height value in percentge unit. | 75 // line-height value in percentge unit. |
76 var input = ".foobar { line-height: 120%; }"; | 76 var input = ".foobar { line-height: 120%; }"; |
77 var stylesheet = parseCss(input, errors: errors); | 77 var stylesheet = parseCss(input, errors: errors); |
78 | 78 |
79 expect(errors.isEmpty, false); | 79 expect(errors.isEmpty, false); |
80 expect(errors[0].toString(), r''' | 80 expect(errors[0].toString(), r''' |
81 error on line 1, column 24: Unexpected value for line-height | 81 error on line 1, column 24: Unexpected value for line-height |
82 .foobar { line-height: 120%; } | 82 .foobar { line-height: 120%; } |
83 ^^^'''); | 83 ^^^'''); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 ^^^^^^^'''); | 115 ^^^^^^^'''); |
116 expect(stylesheet != null, true); | 116 expect(stylesheet != null, true); |
117 expect(prettyPrint(stylesheet), r''' | 117 expect(prettyPrint(stylesheet), r''' |
118 .foobar { | 118 .foobar { |
119 line-height: inherit; | 119 line-height: inherit; |
120 }'''); | 120 }'''); |
121 } | 121 } |
122 | 122 |
123 /** Test for bad selectors. */ | 123 /** Test for bad selectors. */ |
124 void testBadSelectors() { | 124 void testBadSelectors() { |
125 var errors = []; | 125 var errors = <Message>[]; |
126 | 126 |
127 // Invalid id selector. | 127 // Invalid id selector. |
128 var input = "# foo { color: #ff00ff; }"; | 128 var input = "# foo { color: #ff00ff; }"; |
129 var stylesheet = parseCss(input, errors: errors); | 129 var stylesheet = parseCss(input, errors: errors); |
130 | 130 |
131 expect(errors.isEmpty, false); | 131 expect(errors.isEmpty, false); |
132 expect(errors[0].toString(), r''' | 132 expect(errors[0].toString(), r''' |
133 error on line 1, column 1: Not a valid ID selector expected #id | 133 error on line 1, column 1: Not a valid ID selector expected #id |
134 # foo { color: #ff00ff; } | 134 # foo { color: #ff00ff; } |
135 ^'''); | 135 ^'''); |
(...skipping 14 matching lines...) Expand all Loading... |
150 ^'''); | 150 ^'''); |
151 expect(stylesheet != null, true); | 151 expect(stylesheet != null, true); |
152 expect(prettyPrint(stylesheet), r''' | 152 expect(prettyPrint(stylesheet), r''' |
153 . foo { | 153 . foo { |
154 color: #f0f; | 154 color: #f0f; |
155 }'''); | 155 }'''); |
156 } | 156 } |
157 | 157 |
158 /** Test for bad hex values. */ | 158 /** Test for bad hex values. */ |
159 void testBadHexValues() { | 159 void testBadHexValues() { |
160 var errors = []; | 160 var errors = <Message>[]; |
161 | 161 |
162 // Invalid hex value. | 162 // Invalid hex value. |
163 var input = ".foobar { color: #AH787; }"; | 163 var input = ".foobar { color: #AH787; }"; |
164 var stylesheet = parseCss(input, errors: errors); | 164 var stylesheet = parseCss(input, errors: errors); |
165 | 165 |
166 expect(errors.isEmpty, false); | 166 expect(errors.isEmpty, false); |
167 expect(errors[0].toString(), r''' | 167 expect(errors[0].toString(), r''' |
168 error on line 1, column 18: Bad hex number | 168 error on line 1, column 18: Bad hex number |
169 .foobar { color: #AH787; } | 169 .foobar { color: #AH787; } |
170 ^^^^^^'''); | 170 ^^^^^^'''); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 // Formating is off with an extra space. However, the entire value is bad | 221 // Formating is off with an extra space. However, the entire value is bad |
222 // and isn't processed anyway. | 222 // and isn't processed anyway. |
223 expect(prettyPrint(stylesheet), r''' | 223 expect(prettyPrint(stylesheet), r''' |
224 .foobar { | 224 .foobar { |
225 color: # 123 fff; | 225 color: # 123 fff; |
226 }'''); | 226 }'''); |
227 } | 227 } |
228 | 228 |
229 void testBadUnicode() { | 229 void testBadUnicode() { |
230 var errors = []; | 230 var errors = <Message>[]; |
231 final String input = ''' | 231 final String input = ''' |
232 @font-face { | 232 @font-face { |
233 src: url(fonts/BBCBengali.ttf) format("opentype"); | 233 src: url(fonts/BBCBengali.ttf) format("opentype"); |
234 unicode-range: U+400-200; | 234 unicode-range: U+400-200; |
235 }'''; | 235 }'''; |
236 | 236 |
237 parseCss(input, errors: errors); | 237 parseCss(input, errors: errors); |
238 | 238 |
239 expect(errors.isEmpty, false); | 239 expect(errors.isEmpty, false); |
240 expect(errors[0].toString(), | 240 expect(errors[0].toString(), |
(...skipping 11 matching lines...) Expand all Loading... |
252 parseCss(input2, errors: errors..clear()); | 252 parseCss(input2, errors: errors..clear()); |
253 | 253 |
254 expect(errors.isEmpty, false); | 254 expect(errors.isEmpty, false); |
255 expect(errors[0].toString(), | 255 expect(errors[0].toString(), |
256 'error on line 3, column 20: unicode range must be less than 10FFFF\n' | 256 'error on line 3, column 20: unicode range must be less than 10FFFF\n' |
257 ' unicode-range: U+12FFFF;\n' | 257 ' unicode-range: U+12FFFF;\n' |
258 ' ^^^^^^'); | 258 ' ^^^^^^'); |
259 } | 259 } |
260 | 260 |
261 void testBadNesting() { | 261 void testBadNesting() { |
262 var errors = []; | 262 var errors = <Message>[]; |
263 | 263 |
264 // Test for bad declaration in a nested rule. | 264 // Test for bad declaration in a nested rule. |
265 final String input = ''' | 265 final String input = ''' |
266 div { | 266 div { |
267 width: 20px; | 267 width: 20px; |
268 span + ul { color: blue; } | 268 span + ul { color: blue; } |
269 span + ul > #aaaa { | 269 span + ul > #aaaa { |
270 color: #ffghghgh; | 270 color: #ffghghgh; |
271 } | 271 } |
272 background-color: red; | 272 background-color: red; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 345 } |
346 | 346 |
347 main() { | 347 main() { |
348 test('font-weight value errors', testUnsupportedFontWeights); | 348 test('font-weight value errors', testUnsupportedFontWeights); |
349 test('line-height value errors', testUnsupportedLineHeights); | 349 test('line-height value errors', testUnsupportedLineHeights); |
350 test('bad selectors', testBadSelectors); | 350 test('bad selectors', testBadSelectors); |
351 test('bad Hex values', testBadHexValues); | 351 test('bad Hex values', testBadHexValues); |
352 test('bad unicode ranges', testBadUnicode); | 352 test('bad unicode ranges', testBadUnicode); |
353 test('nested rules', testBadNesting); | 353 test('nested rules', testBadNesting); |
354 } | 354 } |
OLD | NEW |