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 = <Message>[]; | 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( | 24 expect(errors[0].toString(), r''' |
25 errors[0].toString(), | |
26 r''' | |
27 error on line 1, column 24: Unknown property value bolder | 25 error on line 1, column 24: Unknown property value bolder |
28 .foobar { font-weight: bolder; } | 26 .foobar { font-weight: bolder; } |
29 ^^^^^^'''); | 27 ^^^^^^'''); |
30 expect(stylesheet != null, true); | 28 expect(stylesheet != null, true); |
31 | 29 |
32 expect( | 30 expect(prettyPrint(stylesheet), r''' |
33 prettyPrint(stylesheet), | |
34 r''' | |
35 .foobar { | 31 .foobar { |
36 font-weight: bolder; | 32 font-weight: bolder; |
37 }'''); | 33 }'''); |
38 | 34 |
39 // TODO(terry): Need to support lighter. | 35 // TODO(terry): Need to support lighter. |
40 // font-weight value lighter. | 36 // font-weight value lighter. |
41 input = ".foobar { font-weight: lighter; }"; | 37 input = ".foobar { font-weight: lighter; }"; |
42 stylesheet = parseCss(input, errors: errors..clear()); | 38 stylesheet = parseCss(input, errors: errors..clear()); |
43 | 39 |
44 expect(errors.isEmpty, false); | 40 expect(errors.isEmpty, false); |
45 expect( | 41 expect(errors[0].toString(), r''' |
46 errors[0].toString(), | |
47 r''' | |
48 error on line 1, column 24: Unknown property value lighter | 42 error on line 1, column 24: Unknown property value lighter |
49 .foobar { font-weight: lighter; } | 43 .foobar { font-weight: lighter; } |
50 ^^^^^^^'''); | 44 ^^^^^^^'''); |
51 expect(stylesheet != null, true); | 45 expect(stylesheet != null, true); |
52 expect( | 46 expect(prettyPrint(stylesheet), r''' |
53 prettyPrint(stylesheet), | |
54 r''' | |
55 .foobar { | 47 .foobar { |
56 font-weight: lighter; | 48 font-weight: lighter; |
57 }'''); | 49 }'''); |
58 | 50 |
59 // TODO(terry): Need to support inherit. | 51 // TODO(terry): Need to support inherit. |
60 // font-weight value inherit. | 52 // font-weight value inherit. |
61 input = ".foobar { font-weight: inherit; }"; | 53 input = ".foobar { font-weight: inherit; }"; |
62 stylesheet = parseCss(input, errors: errors..clear()); | 54 stylesheet = parseCss(input, errors: errors..clear()); |
63 | 55 |
64 expect(errors.isEmpty, false); | 56 expect(errors.isEmpty, false); |
65 expect( | 57 expect(errors[0].toString(), r''' |
66 errors[0].toString(), | |
67 r''' | |
68 error on line 1, column 24: Unknown property value inherit | 58 error on line 1, column 24: Unknown property value inherit |
69 .foobar { font-weight: inherit; } | 59 .foobar { font-weight: inherit; } |
70 ^^^^^^^'''); | 60 ^^^^^^^'''); |
71 expect(stylesheet != null, true); | 61 expect(stylesheet != null, true); |
72 expect( | 62 expect(prettyPrint(stylesheet), r''' |
73 prettyPrint(stylesheet), | |
74 r''' | |
75 .foobar { | 63 .foobar { |
76 font-weight: inherit; | 64 font-weight: inherit; |
77 }'''); | 65 }'''); |
78 } | 66 } |
79 | 67 |
80 /** | 68 /** |
81 * 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 |
82 * inherit. | 70 * inherit. |
83 */ | 71 */ |
84 void testUnsupportedLineHeights() { | 72 void testUnsupportedLineHeights() { |
85 var errors = <Message>[]; | 73 var errors = <Message>[]; |
86 | 74 |
87 // line-height value in percentge unit. | 75 // line-height value in percentge unit. |
88 var input = ".foobar { line-height: 120%; }"; | 76 var input = ".foobar { line-height: 120%; }"; |
89 var stylesheet = parseCss(input, errors: errors); | 77 var stylesheet = parseCss(input, errors: errors); |
90 | 78 |
91 expect(errors.isEmpty, false); | 79 expect(errors.isEmpty, false); |
92 expect( | 80 expect(errors[0].toString(), r''' |
93 errors[0].toString(), | |
94 r''' | |
95 error on line 1, column 24: Unexpected value for line-height | 81 error on line 1, column 24: Unexpected value for line-height |
96 .foobar { line-height: 120%; } | 82 .foobar { line-height: 120%; } |
97 ^^^'''); | 83 ^^^'''); |
98 expect(stylesheet != null, true); | 84 expect(stylesheet != null, true); |
99 expect( | 85 expect(prettyPrint(stylesheet), r''' |
100 prettyPrint(stylesheet), | |
101 r''' | |
102 .foobar { | 86 .foobar { |
103 line-height: 120%; | 87 line-height: 120%; |
104 }'''); | 88 }'''); |
105 | 89 |
106 // TODO(terry): Need to support all units. | 90 // TODO(terry): Need to support all units. |
107 // line-height value in cm unit. | 91 // line-height value in cm unit. |
108 input = ".foobar { line-height: 20cm; }"; | 92 input = ".foobar { line-height: 20cm; }"; |
109 stylesheet = parseCss(input, errors: errors..clear()); | 93 stylesheet = parseCss(input, errors: errors..clear()); |
110 | 94 |
111 expect(errors.isEmpty, false); | 95 expect(errors.isEmpty, false); |
112 expect( | 96 expect(errors[0].toString(), r''' |
113 errors[0].toString(), | |
114 r''' | |
115 error on line 1, column 24: Unexpected unit for line-height | 97 error on line 1, column 24: Unexpected unit for line-height |
116 .foobar { line-height: 20cm; } | 98 .foobar { line-height: 20cm; } |
117 ^^'''); | 99 ^^'''); |
118 expect(stylesheet != null, true); | 100 expect(stylesheet != null, true); |
119 expect( | 101 expect(prettyPrint(stylesheet), r''' |
120 prettyPrint(stylesheet), | |
121 r''' | |
122 .foobar { | 102 .foobar { |
123 line-height: 20cm; | 103 line-height: 20cm; |
124 }'''); | 104 }'''); |
125 | 105 |
126 // TODO(terry): Need to support inherit. | 106 // TODO(terry): Need to support inherit. |
127 // line-height value inherit. | 107 // line-height value inherit. |
128 input = ".foobar { line-height: inherit; }"; | 108 input = ".foobar { line-height: inherit; }"; |
129 stylesheet = parseCss(input, errors: errors..clear()); | 109 stylesheet = parseCss(input, errors: errors..clear()); |
130 | 110 |
131 expect(errors.isEmpty, false); | 111 expect(errors.isEmpty, false); |
132 expect( | 112 expect(errors[0].toString(), r''' |
133 errors[0].toString(), | |
134 r''' | |
135 error on line 1, column 24: Unknown property value inherit | 113 error on line 1, column 24: Unknown property value inherit |
136 .foobar { line-height: inherit; } | 114 .foobar { line-height: inherit; } |
137 ^^^^^^^'''); | 115 ^^^^^^^'''); |
138 expect(stylesheet != null, true); | 116 expect(stylesheet != null, true); |
139 expect( | 117 expect(prettyPrint(stylesheet), r''' |
140 prettyPrint(stylesheet), | |
141 r''' | |
142 .foobar { | 118 .foobar { |
143 line-height: inherit; | 119 line-height: inherit; |
144 }'''); | 120 }'''); |
145 } | 121 } |
146 | 122 |
147 /** Test for bad selectors. */ | 123 /** Test for bad selectors. */ |
148 void testBadSelectors() { | 124 void testBadSelectors() { |
149 var errors = <Message>[]; | 125 var errors = <Message>[]; |
150 | 126 |
151 // Invalid id selector. | 127 // Invalid id selector. |
152 var input = "# foo { color: #ff00ff; }"; | 128 var input = "# foo { color: #ff00ff; }"; |
153 var stylesheet = parseCss(input, errors: errors); | 129 var stylesheet = parseCss(input, errors: errors); |
154 | 130 |
155 expect(errors.isEmpty, false); | 131 expect(errors.isEmpty, false); |
156 expect( | 132 expect(errors[0].toString(), r''' |
157 errors[0].toString(), | |
158 r''' | |
159 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 |
160 # foo { color: #ff00ff; } | 134 # foo { color: #ff00ff; } |
161 ^'''); | 135 ^'''); |
162 expect(stylesheet != null, true); | 136 expect(stylesheet != null, true); |
163 expect( | 137 expect(prettyPrint(stylesheet), r''' |
164 prettyPrint(stylesheet), | |
165 r''' | |
166 # foo { | 138 # foo { |
167 color: #f0f; | 139 color: #f0f; |
168 }'''); | 140 }'''); |
169 | 141 |
170 // Invalid class selector. | 142 // Invalid class selector. |
171 input = ". foo { color: #ff00ff; }"; | 143 input = ". foo { color: #ff00ff; }"; |
172 stylesheet = parseCss(input, errors: errors..clear()); | 144 stylesheet = parseCss(input, errors: errors..clear()); |
173 | 145 |
174 expect(errors.isEmpty, false); | 146 expect(errors.isEmpty, false); |
175 expect( | 147 expect(errors[0].toString(), r''' |
176 errors[0].toString(), | |
177 r''' | |
178 error on line 1, column 1: Not a valid class selector expected .className | 148 error on line 1, column 1: Not a valid class selector expected .className |
179 . foo { color: #ff00ff; } | 149 . foo { color: #ff00ff; } |
180 ^'''); | 150 ^'''); |
181 expect(stylesheet != null, true); | 151 expect(stylesheet != null, true); |
182 expect( | 152 expect(prettyPrint(stylesheet), r''' |
183 prettyPrint(stylesheet), | |
184 r''' | |
185 . foo { | 153 . foo { |
186 color: #f0f; | 154 color: #f0f; |
187 }'''); | 155 }'''); |
188 } | 156 } |
189 | 157 |
190 /** Test for bad hex values. */ | 158 /** Test for bad hex values. */ |
191 void testBadHexValues() { | 159 void testBadHexValues() { |
192 var errors = <Message>[]; | 160 var errors = <Message>[]; |
193 | 161 |
194 // Invalid hex value. | 162 // Invalid hex value. |
195 var input = ".foobar { color: #AH787; }"; | 163 var input = ".foobar { color: #AH787; }"; |
196 var stylesheet = parseCss(input, errors: errors); | 164 var stylesheet = parseCss(input, errors: errors); |
197 | 165 |
198 expect(errors.isEmpty, false); | 166 expect(errors.isEmpty, false); |
199 expect( | 167 expect(errors[0].toString(), r''' |
200 errors[0].toString(), | |
201 r''' | |
202 error on line 1, column 18: Bad hex number | 168 error on line 1, column 18: Bad hex number |
203 .foobar { color: #AH787; } | 169 .foobar { color: #AH787; } |
204 ^^^^^^'''); | 170 ^^^^^^'''); |
205 expect(stylesheet != null, true); | 171 expect(stylesheet != null, true); |
206 expect( | 172 expect(prettyPrint(stylesheet), r''' |
207 prettyPrint(stylesheet), | |
208 r''' | |
209 .foobar { | 173 .foobar { |
210 color: #AH787; | 174 color: #AH787; |
211 }'''); | 175 }'''); |
212 | 176 |
213 // Bad color constant. | 177 // Bad color constant. |
214 input = ".foobar { color: redder; }"; | 178 input = ".foobar { color: redder; }"; |
215 stylesheet = parseCss(input, errors: errors..clear()); | 179 stylesheet = parseCss(input, errors: errors..clear()); |
216 | 180 |
217 expect(errors.isEmpty, false); | 181 expect(errors.isEmpty, false); |
218 expect( | 182 expect(errors[0].toString(), r''' |
219 errors[0].toString(), | |
220 r''' | |
221 error on line 1, column 18: Unknown property value redder | 183 error on line 1, column 18: Unknown property value redder |
222 .foobar { color: redder; } | 184 .foobar { color: redder; } |
223 ^^^^^^'''); | 185 ^^^^^^'''); |
224 | 186 |
225 expect(stylesheet != null, true); | 187 expect(stylesheet != null, true); |
226 expect( | 188 expect(prettyPrint(stylesheet), r''' |
227 prettyPrint(stylesheet), | |
228 r''' | |
229 .foobar { | 189 .foobar { |
230 color: redder; | 190 color: redder; |
231 }'''); | 191 }'''); |
232 | 192 |
233 // Bad hex color #<space>ffffff. | 193 // Bad hex color #<space>ffffff. |
234 input = ".foobar { color: # ffffff; }"; | 194 input = ".foobar { color: # ffffff; }"; |
235 stylesheet = parseCss(input, errors: errors..clear()); | 195 stylesheet = parseCss(input, errors: errors..clear()); |
236 | 196 |
237 expect(errors.isEmpty, false); | 197 expect(errors.isEmpty, false); |
238 expect( | 198 expect(errors[0].toString(), r''' |
239 errors[0].toString(), | |
240 r''' | |
241 error on line 1, column 18: Expected hex number | 199 error on line 1, column 18: Expected hex number |
242 .foobar { color: # ffffff; } | 200 .foobar { color: # ffffff; } |
243 ^'''); | 201 ^'''); |
244 | 202 |
245 expect(stylesheet != null, true); | 203 expect(stylesheet != null, true); |
246 expect( | 204 expect(prettyPrint(stylesheet), r''' |
247 prettyPrint(stylesheet), | |
248 r''' | |
249 .foobar { | 205 .foobar { |
250 color: # ffffff; | 206 color: # ffffff; |
251 }'''); | 207 }'''); |
252 | 208 |
253 // Bad hex color #<space>123fff. | 209 // Bad hex color #<space>123fff. |
254 input = ".foobar { color: # 123fff; }"; | 210 input = ".foobar { color: # 123fff; }"; |
255 stylesheet = parseCss(input, errors: errors..clear()); | 211 stylesheet = parseCss(input, errors: errors..clear()); |
256 | 212 |
257 expect(errors.isEmpty, false); | 213 expect(errors.isEmpty, false); |
258 expect( | 214 expect(errors[0].toString(), r''' |
259 errors[0].toString(), | |
260 r''' | |
261 error on line 1, column 18: Expected hex number | 215 error on line 1, column 18: Expected hex number |
262 .foobar { color: # 123fff; } | 216 .foobar { color: # 123fff; } |
263 ^'''); | 217 ^'''); |
264 | 218 |
265 expect(stylesheet != null, true); | 219 expect(stylesheet != null, true); |
266 | 220 |
267 // 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 |
268 // and isn't processed anyway. | 222 // and isn't processed anyway. |
269 expect( | 223 expect(prettyPrint(stylesheet), r''' |
270 prettyPrint(stylesheet), | |
271 r''' | |
272 .foobar { | 224 .foobar { |
273 color: # 123 fff; | 225 color: # 123 fff; |
274 }'''); | 226 }'''); |
275 } | 227 } |
276 | 228 |
277 void testBadUnicode() { | 229 void testBadUnicode() { |
278 var errors = <Message>[]; | 230 var errors = <Message>[]; |
279 final String input = ''' | 231 final String input = ''' |
280 @font-face { | 232 @font-face { |
281 src: url(fonts/BBCBengali.ttf) format("opentype"); | 233 src: url(fonts/BBCBengali.ttf) format("opentype"); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 347 } |
396 | 348 |
397 main() { | 349 main() { |
398 test('font-weight value errors', testUnsupportedFontWeights); | 350 test('font-weight value errors', testUnsupportedFontWeights); |
399 test('line-height value errors', testUnsupportedLineHeights); | 351 test('line-height value errors', testUnsupportedLineHeights); |
400 test('bad selectors', testBadSelectors); | 352 test('bad selectors', testBadSelectors); |
401 test('bad Hex values', testBadHexValues); | 353 test('bad Hex values', testBadHexValues); |
402 test('bad unicode ranges', testBadUnicode); | 354 test('bad unicode ranges', testBadUnicode); |
403 test('nested rules', testBadNesting); | 355 test('nested rules', testBadNesting); |
404 } | 356 } |
OLD | NEW |