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

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

Issue 304603003: Make source map location information more readable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/csslib/pubspec.yaml ('k') | pkg/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
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:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 import 'testing.dart'; 8 import 'testing.dart';
9 import 'package:csslib/src/messages.dart'; 9 import 'package:csslib/src/messages.dart';
10 10
11 /** 11 /**
12 * Test for unsupported font-weights values of bolder, lighter and inherit. 12 * Test for unsupported font-weights values of bolder, lighter and inherit.
13 */ 13 */
14 void testUnsupportedFontWeights() { 14 void testUnsupportedFontWeights() {
15 var errors = []; 15 var errors = [];
16 16
17 // TODO(terry): Need to support bolder. 17 // TODO(terry): Need to support bolder.
18 // font-weight value bolder. 18 // font-weight value bolder.
19 var input = ".foobar { font-weight: bolder; }"; 19 var input = ".foobar { font-weight: bolder; }";
20 var stylesheet = parseCss(input, errors: errors); 20 var stylesheet = parseCss(input, errors: errors);
21 21
22 expect(errors.isEmpty, false); 22 expect(errors.isEmpty, false);
23 expect(errors[0].toString(), r''' 23 expect(errors[0].toString(), r'''
24 error :1:24: Unknown property value bolder 24 error on line 1, column 24: Unknown property value bolder
25 .foobar { font-weight: bolder; } 25 .foobar { font-weight: bolder; }
26 ^^^^^^'''); 26 ^^^^^^''');
27 expect(stylesheet != null, true); 27 expect(stylesheet != null, true);
28 28
29 expect(prettyPrint(stylesheet), r''' 29 expect(prettyPrint(stylesheet), r'''
30 .foobar { 30 .foobar {
31 font-weight: bolder; 31 font-weight: bolder;
32 }'''); 32 }''');
33 33
34 // TODO(terry): Need to support lighter. 34 // TODO(terry): Need to support lighter.
35 // font-weight value lighter. 35 // font-weight value lighter.
36 input = ".foobar { font-weight: lighter; }"; 36 input = ".foobar { font-weight: lighter; }";
37 stylesheet = parseCss(input, errors: errors..clear()); 37 stylesheet = parseCss(input, errors: errors..clear());
38 38
39 expect(errors.isEmpty, false); 39 expect(errors.isEmpty, false);
40 expect(errors[0].toString(), r''' 40 expect(errors[0].toString(), r'''
41 error :1:24: Unknown property value lighter 41 error on line 1, column 24: Unknown property value lighter
42 .foobar { font-weight: lighter; } 42 .foobar { font-weight: lighter; }
43 ^^^^^^^'''); 43 ^^^^^^^''');
44 expect(stylesheet != null, true); 44 expect(stylesheet != null, true);
45 expect(prettyPrint(stylesheet), r''' 45 expect(prettyPrint(stylesheet), r'''
46 .foobar { 46 .foobar {
47 font-weight: lighter; 47 font-weight: lighter;
48 }'''); 48 }''');
49 49
50 // TODO(terry): Need to support inherit. 50 // TODO(terry): Need to support inherit.
51 // font-weight value inherit. 51 // font-weight value inherit.
52 input = ".foobar { font-weight: inherit; }"; 52 input = ".foobar { font-weight: inherit; }";
53 stylesheet = parseCss(input, errors: errors..clear()); 53 stylesheet = parseCss(input, errors: errors..clear());
54 54
55 expect(errors.isEmpty, false); 55 expect(errors.isEmpty, false);
56 expect(errors[0].toString(), r''' 56 expect(errors[0].toString(), r'''
57 error :1:24: Unknown property value inherit 57 error on line 1, column 24: Unknown property value inherit
58 .foobar { font-weight: inherit; } 58 .foobar { font-weight: inherit; }
59 ^^^^^^^'''); 59 ^^^^^^^''');
60 expect(stylesheet != null, true); 60 expect(stylesheet != null, true);
61 expect(prettyPrint(stylesheet), r''' 61 expect(prettyPrint(stylesheet), r'''
62 .foobar { 62 .foobar {
63 font-weight: inherit; 63 font-weight: inherit;
64 }'''); 64 }''');
65 } 65 }
66 66
67 /** 67 /**
68 * Test for unsupported line-height values of units other than px, pt and 68 * Test for unsupported line-height values of units other than px, pt and
69 * inherit. 69 * inherit.
70 */ 70 */
71 void testUnsupportedLineHeights() { 71 void testUnsupportedLineHeights() {
72 var errors = []; 72 var errors = [];
73 73
74 // line-height value in percentge unit. 74 // line-height value in percentge unit.
75 var input = ".foobar { line-height: 120%; }"; 75 var input = ".foobar { line-height: 120%; }";
76 var stylesheet = parseCss(input, errors: errors); 76 var stylesheet = parseCss(input, errors: errors);
77 77
78 expect(errors.isEmpty, false); 78 expect(errors.isEmpty, false);
79 expect(errors[0].toString(), r''' 79 expect(errors[0].toString(), r'''
80 error :1:24: Unexpected value for line-height 80 error on line 1, column 24: Unexpected value for line-height
81 .foobar { line-height: 120%; } 81 .foobar { line-height: 120%; }
82 ^^^'''); 82 ^^^''');
83 expect(stylesheet != null, true); 83 expect(stylesheet != null, true);
84 expect(prettyPrint(stylesheet), r''' 84 expect(prettyPrint(stylesheet), r'''
85 .foobar { 85 .foobar {
86 line-height: 120%; 86 line-height: 120%;
87 }'''); 87 }''');
88 88
89 // TODO(terry): Need to support all units. 89 // TODO(terry): Need to support all units.
90 // line-height value in cm unit. 90 // line-height value in cm unit.
91 input = ".foobar { line-height: 20cm; }"; 91 input = ".foobar { line-height: 20cm; }";
92 stylesheet = parseCss(input, errors: errors..clear()); 92 stylesheet = parseCss(input, errors: errors..clear());
93 93
94 expect(errors.isEmpty, false); 94 expect(errors.isEmpty, false);
95 expect(errors[0].toString(), r''' 95 expect(errors[0].toString(), r'''
96 error :1:24: Unexpected unit for line-height 96 error on line 1, column 24: Unexpected unit for line-height
97 .foobar { line-height: 20cm; } 97 .foobar { line-height: 20cm; }
98 ^^'''); 98 ^^''');
99 expect(stylesheet != null, true); 99 expect(stylesheet != null, true);
100 expect(prettyPrint(stylesheet), r''' 100 expect(prettyPrint(stylesheet), r'''
101 .foobar { 101 .foobar {
102 line-height: 20cm; 102 line-height: 20cm;
103 }'''); 103 }''');
104 104
105 // TODO(terry): Need to support inherit. 105 // TODO(terry): Need to support inherit.
106 // line-height value inherit. 106 // line-height value inherit.
107 input = ".foobar { line-height: inherit; }"; 107 input = ".foobar { line-height: inherit; }";
108 stylesheet = parseCss(input, errors: errors..clear()); 108 stylesheet = parseCss(input, errors: errors..clear());
109 109
110 expect(errors.isEmpty, false); 110 expect(errors.isEmpty, false);
111 expect(errors[0].toString(), r''' 111 expect(errors[0].toString(), r'''
112 error :1:24: Unknown property value inherit 112 error on line 1, column 24: Unknown property value inherit
113 .foobar { line-height: inherit; } 113 .foobar { line-height: inherit; }
114 ^^^^^^^'''); 114 ^^^^^^^''');
115 expect(stylesheet != null, true); 115 expect(stylesheet != null, true);
116 expect(prettyPrint(stylesheet), r''' 116 expect(prettyPrint(stylesheet), r'''
117 .foobar { 117 .foobar {
118 line-height: inherit; 118 line-height: inherit;
119 }'''); 119 }''');
120 } 120 }
121 121
122 /** Test for bad selectors. */ 122 /** Test for bad selectors. */
123 void testBadSelectors() { 123 void testBadSelectors() {
124 var errors = []; 124 var errors = [];
125 125
126 // Invalid id selector. 126 // Invalid id selector.
127 var input = "# foo { color: #ff00ff; }"; 127 var input = "# foo { color: #ff00ff; }";
128 var stylesheet = parseCss(input, errors: errors); 128 var stylesheet = parseCss(input, errors: errors);
129 129
130 expect(errors.isEmpty, false); 130 expect(errors.isEmpty, false);
131 expect(errors[0].toString(), r''' 131 expect(errors[0].toString(), r'''
132 error :1:1: Not a valid ID selector expected #id 132 error on line 1, column 1: Not a valid ID selector expected #id
133 # foo { color: #ff00ff; } 133 # foo { color: #ff00ff; }
134 ^'''); 134 ^''');
135 expect(stylesheet != null, true); 135 expect(stylesheet != null, true);
136 expect(prettyPrint(stylesheet), r''' 136 expect(prettyPrint(stylesheet), r'''
137 # foo { 137 # foo {
138 color: #f0f; 138 color: #f0f;
139 }'''); 139 }''');
140 140
141 // Invalid class selector. 141 // Invalid class selector.
142 input = ". foo { color: #ff00ff; }"; 142 input = ". foo { color: #ff00ff; }";
143 stylesheet = parseCss(input, errors: errors..clear()); 143 stylesheet = parseCss(input, errors: errors..clear());
144 144
145 expect(errors.isEmpty, false); 145 expect(errors.isEmpty, false);
146 expect(errors[0].toString(), r''' 146 expect(errors[0].toString(), r'''
147 error :1:1: Not a valid class selector expected .className 147 error on line 1, column 1: Not a valid class selector expected .className
148 . foo { color: #ff00ff; } 148 . foo { color: #ff00ff; }
149 ^'''); 149 ^''');
150 expect(stylesheet != null, true); 150 expect(stylesheet != null, true);
151 expect(prettyPrint(stylesheet), r''' 151 expect(prettyPrint(stylesheet), r'''
152 . foo { 152 . foo {
153 color: #f0f; 153 color: #f0f;
154 }'''); 154 }''');
155 } 155 }
156 156
157 /** Test for bad hex values. */ 157 /** Test for bad hex values. */
158 void testBadHexValues() { 158 void testBadHexValues() {
159 var errors = []; 159 var errors = [];
160 160
161 // Invalid hex value. 161 // Invalid hex value.
162 var input = ".foobar { color: #AH787; }"; 162 var input = ".foobar { color: #AH787; }";
163 var stylesheet = parseCss(input, errors: errors); 163 var stylesheet = parseCss(input, errors: errors);
164 164
165 expect(errors.isEmpty, false); 165 expect(errors.isEmpty, false);
166 expect(errors[0].toString(), r''' 166 expect(errors[0].toString(), r'''
167 error :1:18: Bad hex number 167 error on line 1, column 18: Bad hex number
168 .foobar { color: #AH787; } 168 .foobar { color: #AH787; }
169 ^^^^^^'''); 169 ^^^^^^''');
170 expect(stylesheet != null, true); 170 expect(stylesheet != null, true);
171 expect(prettyPrint(stylesheet), r''' 171 expect(prettyPrint(stylesheet), r'''
172 .foobar { 172 .foobar {
173 color: #AH787; 173 color: #AH787;
174 }'''); 174 }''');
175 175
176 // Bad color constant. 176 // Bad color constant.
177 input = ".foobar { color: redder; }"; 177 input = ".foobar { color: redder; }";
178 stylesheet = parseCss(input, errors: errors..clear()); 178 stylesheet = parseCss(input, errors: errors..clear());
179 179
180 expect(errors.isEmpty, false); 180 expect(errors.isEmpty, false);
181 expect(errors[0].toString(), r''' 181 expect(errors[0].toString(), r'''
182 error :1:18: Unknown property value redder 182 error on line 1, column 18: Unknown property value redder
183 .foobar { color: redder; } 183 .foobar { color: redder; }
184 ^^^^^^'''); 184 ^^^^^^''');
185 185
186 expect(stylesheet != null, true); 186 expect(stylesheet != null, true);
187 expect(prettyPrint(stylesheet), r''' 187 expect(prettyPrint(stylesheet), r'''
188 .foobar { 188 .foobar {
189 color: redder; 189 color: redder;
190 }'''); 190 }''');
191 191
192 // Bad hex color #<space>ffffff. 192 // Bad hex color #<space>ffffff.
193 input = ".foobar { color: # ffffff; }"; 193 input = ".foobar { color: # ffffff; }";
194 stylesheet = parseCss(input, errors: errors..clear()); 194 stylesheet = parseCss(input, errors: errors..clear());
195 195
196 expect(errors.isEmpty, false); 196 expect(errors.isEmpty, false);
197 expect(errors[0].toString(), r''' 197 expect(errors[0].toString(), r'''
198 error :1:18: Expected hex number 198 error on line 1, column 18: Expected hex number
199 .foobar { color: # ffffff; } 199 .foobar { color: # ffffff; }
200 ^'''); 200 ^''');
201 201
202 expect(stylesheet != null, true); 202 expect(stylesheet != null, true);
203 expect(prettyPrint(stylesheet), r''' 203 expect(prettyPrint(stylesheet), r'''
204 .foobar { 204 .foobar {
205 color: # ffffff; 205 color: # ffffff;
206 }'''); 206 }''');
207 207
208 // Bad hex color #<space>123fff. 208 // Bad hex color #<space>123fff.
209 input = ".foobar { color: # 123fff; }"; 209 input = ".foobar { color: # 123fff; }";
210 stylesheet = parseCss(input, errors: errors..clear()); 210 stylesheet = parseCss(input, errors: errors..clear());
211 211
212 expect(errors.isEmpty, false); 212 expect(errors.isEmpty, false);
213 expect(errors[0].toString(), r''' 213 expect(errors[0].toString(), r'''
214 error :1:18: Expected hex number 214 error on line 1, column 18: Expected hex number
215 .foobar { color: # 123fff; } 215 .foobar { color: # 123fff; }
216 ^'''); 216 ^''');
217 217
218 expect(stylesheet != null, true); 218 expect(stylesheet != null, true);
219 219
220 // Formating is off with an extra space. However, the entire value is bad 220 // Formating is off with an extra space. However, the entire value is bad
221 // and isn't processed anyway. 221 // and isn't processed anyway.
222 expect(prettyPrint(stylesheet), r''' 222 expect(prettyPrint(stylesheet), r'''
223 .foobar { 223 .foobar {
224 color: # 123 fff; 224 color: # 123 fff;
225 }'''); 225 }''');
226 226
227 } 227 }
228 228
229 void testBadUnicode() { 229 void testBadUnicode() {
230 var errors = []; 230 var errors = [];
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 var stylesheet = parseCss(input, errors: errors); 237 var stylesheet = 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(),
241 'error :3:20: unicode first range can not be greater than last\n' 241 'error on line 3, column 20: unicode first range can not be greater than '
242 'last\n'
242 ' unicode-range: U+400-200;\n' 243 ' unicode-range: U+400-200;\n'
243 ' ^^^^^^^'); 244 ' ^^^^^^^');
244 245
245 final String input2 = ''' 246 final String input2 = '''
246 @font-face { 247 @font-face {
247 src: url(fonts/BBCBengali.ttf) format("opentype"); 248 src: url(fonts/BBCBengali.ttf) format("opentype");
248 unicode-range: U+12FFFF; 249 unicode-range: U+12FFFF;
249 }'''; 250 }''';
250 251
251 stylesheet = parseCss(input2, errors: errors..clear()); 252 stylesheet = parseCss(input2, errors: errors..clear());
252 253
253 expect(errors.isEmpty, false); 254 expect(errors.isEmpty, false);
254 expect(errors[0].toString(), 255 expect(errors[0].toString(),
255 'error :3:20: unicode range must be less than 10FFFF\n' 256 'error on line 3, column 20: unicode range must be less than 10FFFF\n'
256 ' unicode-range: U+12FFFF;\n' 257 ' unicode-range: U+12FFFF;\n'
257 ' ^^^^^^'); 258 ' ^^^^^^');
258 } 259 }
259 260
260 void testBadNesting() { 261 void testBadNesting() {
261 var errors = []; 262 var errors = [];
262 263
263 // Test for bad declaration in a nested rule. 264 // Test for bad declaration in a nested rule.
264 final String input = ''' 265 final String input = '''
265 div { 266 div {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 345 }
345 346
346 main() { 347 main() {
347 test('font-weight value errors', testUnsupportedFontWeights); 348 test('font-weight value errors', testUnsupportedFontWeights);
348 test('line-height value errors', testUnsupportedLineHeights); 349 test('line-height value errors', testUnsupportedLineHeights);
349 test('bad selectors', testBadSelectors); 350 test('bad selectors', testBadSelectors);
350 test('bad Hex values', testBadHexValues); 351 test('bad Hex values', testBadHexValues);
351 test('bad unicode ranges', testBadUnicode); 352 test('bad unicode ranges', testBadUnicode);
352 test('nested rules', testBadNesting); 353 test('nested rules', testBadNesting);
353 } 354 }
OLDNEW
« no previous file with comments | « pkg/csslib/pubspec.yaml ('k') | pkg/csslib/test/selector_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698