OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 selector_test; | 5 library selector_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/parser.dart'; | 9 import 'package:csslib/parser.dart'; |
10 | 10 |
11 void testSelectorSuccesses() { | 11 void testSelectorSuccesses() { |
12 var errors = []; | 12 var errors = []; |
13 var selectorAst = selector('#div .foo', errors: errors); | 13 var selectorAst = selector('#div .foo', errors: errors); |
14 expect(errors.isEmpty, true, reason: errors.toString()); | 14 expect(errors.isEmpty, true, reason: errors.toString()); |
15 expect('#div .foo', compactOuptut(selectorAst)); | 15 expect('#div .foo', compactOuptut(selectorAst)); |
16 | 16 |
17 // Valid selectors for class names. | 17 // Valid selectors for class names. |
18 selectorAst = selector('.foo', errors: errors..clear()); | 18 selectorAst = selector('.foo', errors: errors..clear()); |
19 expect(errors.isEmpty, true, reason: errors.toString()); | 19 expect(errors.isEmpty, true, reason: errors.toString()); |
20 expect('.foo', compactOuptut(selectorAst)); | 20 expect('.foo', compactOuptut(selectorAst)); |
21 | 21 |
22 selectorAst = selector('.foobar .xyzzy', errors: errors..clear()); | 22 selectorAst = selector('.foobar .xyzzy', errors: errors..clear()); |
23 expect(errors.isEmpty, true, reason: errors.toString()); | 23 expect(errors.isEmpty, true, reason: errors.toString()); |
24 expect('.foobar .xyzzy', compactOuptut(selectorAst)); | 24 expect('.foobar .xyzzy', compactOuptut(selectorAst)); |
25 | 25 |
26 selectorAst = selector('.foobar .a-story .xyzzy', errors: errors..clear()); | 26 selectorAst = selector('.foobar .a-story .xyzzy', errors: errors..clear()); |
27 expect(errors.isEmpty, true, reason: errors.toString()); | 27 expect(errors.isEmpty, true, reason: errors.toString()); |
28 expect('.foobar .a-story .xyzzy', compactOuptut(selectorAst)); | 28 expect('.foobar .a-story .xyzzy', compactOuptut(selectorAst)); |
29 | 29 |
30 selectorAst = selector('.foobar .xyzzy .a-story .b-story', | 30 selectorAst = |
31 errors: errors..clear()); | 31 selector('.foobar .xyzzy .a-story .b-story', errors: errors..clear()); |
32 expect(errors.isEmpty, true, reason: errors.toString()); | 32 expect(errors.isEmpty, true, reason: errors.toString()); |
33 expect('.foobar .xyzzy .a-story .b-story', compactOuptut(selectorAst)); | 33 expect('.foobar .xyzzy .a-story .b-story', compactOuptut(selectorAst)); |
34 | 34 |
35 // Valid selectors for element IDs. | 35 // Valid selectors for element IDs. |
36 selectorAst = selector('#id1', errors: errors..clear()); | 36 selectorAst = selector('#id1', errors: errors..clear()); |
37 expect(errors.isEmpty, true, reason: errors.toString()); | 37 expect(errors.isEmpty, true, reason: errors.toString()); |
38 expect('#id1', compactOuptut(selectorAst)); | 38 expect('#id1', compactOuptut(selectorAst)); |
39 | 39 |
40 selectorAst = selector('#id-number-3', errors: errors..clear()); | 40 selectorAst = selector('#id-number-3', errors: errors..clear()); |
41 expect(errors.isEmpty, true, reason: errors.toString()); | 41 expect(errors.isEmpty, true, reason: errors.toString()); |
42 expect('#id-number-3', compactOuptut(selectorAst)); | 42 expect('#id-number-3', compactOuptut(selectorAst)); |
43 | 43 |
44 selectorAst = selector('#_privateId', errors: errors..clear()); | 44 selectorAst = selector('#_privateId', errors: errors..clear()); |
45 expect(errors.isEmpty, true, reason: errors.toString()); | 45 expect(errors.isEmpty, true, reason: errors.toString()); |
46 expect('#_privateId', compactOuptut(selectorAst)); | 46 expect('#_privateId', compactOuptut(selectorAst)); |
47 } | 47 } |
48 | 48 |
49 // TODO(terry): Move this failure case to a failure_test.dart when the analyzer | 49 // TODO(terry): Move this failure case to a failure_test.dart when the analyzer |
50 // and validator exit then they'll be a bunch more checks. | 50 // and validator exit then they'll be a bunch more checks. |
51 void testSelectorFailures() { | 51 void testSelectorFailures() { |
52 var errors = []; | 52 var errors = []; |
53 | 53 |
54 // Test for invalid class name (can't start with number). | 54 // Test for invalid class name (can't start with number). |
55 var selectorAst = selector('.foobar .1a-story .xyzzy', errors: errors); | 55 var selectorAst = selector('.foobar .1a-story .xyzzy', errors: errors); |
56 expect(errors.isEmpty, false); | 56 expect(errors.isEmpty, false); |
57 expect(errors[0].toString(), | 57 expect(errors[0].toString(), |
58 'error on line 1, column 9: name must start with a alpha character, but ' | 58 'error on line 1, column 9: name must start with a alpha character, but ' |
59 'found a number\n' | 59 'found a number\n' |
60 '.foobar .1a-story .xyzzy\n' | 60 '.foobar .1a-story .xyzzy\n' |
61 ' ^^'); | 61 ' ^^'); |
62 } | 62 } |
63 | 63 |
64 main() { | 64 main() { |
65 test('Valid Selectors', testSelectorSuccesses); | 65 test('Valid Selectors', testSelectorSuccesses); |
66 test('Invalid Selectors', testSelectorFailures); | 66 test('Invalid Selectors', testSelectorFailures); |
67 } | 67 } |
OLD | NEW |