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 var_test; | 5 library var_test; |
6 | 6 |
7 import 'dart:utf'; | 7 import 'dart:utf'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'package:csslib/parser.dart'; | 9 import 'package:csslib/parser.dart'; |
10 import 'package:csslib/visitor.dart'; | 10 import 'package:csslib/visitor.dart'; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 body { | 201 body { |
202 background: var(a) var(image) no-repeat right top; | 202 background: var(a) var(image) no-repeat right top; |
203 } | 203 } |
204 | 204 |
205 div { | 205 div { |
206 background: var(color-background) url('img_tree.png') no-repeat right top; | 206 background: var(color-background) url('img_tree.png') no-repeat right top; |
207 } | 207 } |
208 | 208 |
209 .test-2 { | 209 .test-2 { |
210 background: var(color-background) var(image-2, url('img_1.png')) | 210 background: var(color-background) var(image-2, url('img_1.png')) |
211 no-repeat right top; | 211 no-repeat right top; |
212 } | 212 } |
213 | 213 |
214 .test-3 { | 214 .test-3 { |
215 background: var(color-background) var(image-2) no-repeat right top; | 215 background: var(color-background) var(image-2) no-repeat right top; |
216 } | 216 } |
217 | 217 |
218 .test-4 { | 218 .test-4 { |
219 background: #ffff00 var(image) no-repeat right top; | 219 background: #ffff00 var(image) no-repeat right top; |
220 } | 220 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 .test-2 { | 316 .test-2 { |
317 color: var(one); | 317 color: var(one); |
318 }'''; | 318 }'''; |
319 | 319 |
320 var stylesheet = compileCss(input, errors: errors, | 320 var stylesheet = compileCss(input, errors: errors, |
321 opts: ['--no-colors', '--warnings_as_errors', 'memory']); | 321 opts: ['--no-colors', '--warnings_as_errors', 'memory']); |
322 | 322 |
323 expect(stylesheet != null, true); | 323 expect(stylesheet != null, true); |
324 expect(errors.length, 8, reason: errors.toString()); | 324 expect(errors.length, 8, reason: errors.toString()); |
325 expect(errors[0].toString(), | 325 int testBitMap = 0; |
| 326 var errorStrings = [ |
326 'error :14:3: var cycle detected var-six\n' | 327 'error :14:3: var cycle detected var-six\n' |
327 ' var-six: var(four);\n' | 328 ' var-six: var(four);\n' |
328 ' ^^^^^^^^^^^^^^^^^^'); | 329 ' ^^^^^^^^^^^^^^^^^^', |
329 expect(errors[1].toString(), | |
330 'error :18:3: var cycle detected var-def-3\n' | 330 'error :18:3: var cycle detected var-def-3\n' |
331 ' var-def-3: var(def-2);\n' | 331 ' var-def-3: var(def-2);\n' |
332 ' ^^^^^^^^^^^^^^^^^^^^^'); | 332 ' ^^^^^^^^^^^^^^^^^^^^^', |
333 expect(errors[2].toString(), | |
334 'error :10:3: var cycle detected var-two\n' | 333 'error :10:3: var cycle detected var-two\n' |
335 ' var-two: var(one);\n' | 334 ' var-two: var(one);\n' |
336 ' ^^^^^^^^^^^^^^^^^'); | 335 ' ^^^^^^^^^^^^^^^^^', |
337 expect(errors[3].toString(), | |
338 'error :17:3: var cycle detected var-def-2\n' | 336 'error :17:3: var cycle detected var-def-2\n' |
339 ' var-def-2: var(def-3);\n' | 337 ' var-def-2: var(def-3);\n' |
340 ' ^^^^^^^^^^^^^^^^^^^^^'); | 338 ' ^^^^^^^^^^^^^^^^^^^^^', |
341 expect(errors[4].toString(), | |
342 'error :16:3: var cycle detected var-def-1\n' | 339 'error :16:3: var cycle detected var-def-1\n' |
343 ' var-def-1: var(def-2);\n' | 340 ' var-def-1: var(def-2);\n' |
344 ' ^^^^^^^^^^^^^^^^^^^^^'); | 341 ' ^^^^^^^^^^^^^^^^^^^^^', |
345 expect(errors[5].toString(), | |
346 'error :13:3: var cycle detected var-five\n' | 342 'error :13:3: var cycle detected var-five\n' |
347 ' var-five: var(six);\n' | 343 ' var-five: var(six);\n' |
348 ' ^^^^^^^^^^^^^^^^^^'); | 344 ' ^^^^^^^^^^^^^^^^^^', |
349 expect(errors[6].toString(), | |
350 'error :9:3: var cycle detected var-one\n' | 345 'error :9:3: var cycle detected var-one\n' |
351 ' var-one: var(two);\n' | 346 ' var-one: var(two);\n' |
352 ' ^^^^^^^^^^^^^^^^^'); | 347 ' ^^^^^^^^^^^^^^^^^', |
353 expect(errors[7].toString(), | |
354 'error :12:3: var cycle detected var-four\n' | 348 'error :12:3: var cycle detected var-four\n' |
355 ' var-four: var(five);\n' | 349 ' var-four: var(five);\n' |
356 ' ^^^^^^^^^^^^^^^^^^^'); | 350 ' ^^^^^^^^^^^^^^^^^^^' |
| 351 ]; |
| 352 outer: for (var error in errors) { |
| 353 var errorString = error.toString(); |
| 354 for (int i = 0; i < 8; i++) { |
| 355 if (errorString == errorStrings[i]) { |
| 356 testBitMap |= 1 << i; |
| 357 continue outer; |
| 358 } |
| 359 } |
| 360 fail("Unexpected error string: $errorString"); |
| 361 } |
| 362 expect(testBitMap, equals((1 << 8) - 1)); |
357 expect(prettyPrint(stylesheet), generated); | 363 expect(prettyPrint(stylesheet), generated); |
358 } | 364 } |
359 | 365 |
360 parserVar() { | 366 parserVar() { |
361 final errors = []; | 367 final errors = []; |
362 final input = ''':root { | 368 final input = ''':root { |
363 var-color-background: red; | 369 var-color-background: red; |
364 var-color-foreground: blue; | 370 var-color-foreground: blue; |
365 | 371 |
366 var-a: var(b); | 372 var-a: var(b); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 | 626 |
621 main() { | 627 main() { |
622 test('Simple var', simpleVar); | 628 test('Simple var', simpleVar); |
623 test('Expressions var', expressionsVar); | 629 test('Expressions var', expressionsVar); |
624 test('Default value in var()', defaultVar); | 630 test('Default value in var()', defaultVar); |
625 test('CSS Parser only var', parserVar); | 631 test('CSS Parser only var', parserVar); |
626 test('Var syntax', testVar); | 632 test('Var syntax', testVar); |
627 test('Cycles var', cyclesVar); | 633 test('Cycles var', cyclesVar); |
628 test('Less syntax', testLess); | 634 test('Less syntax', testLess); |
629 } | 635 } |
OLD | NEW |