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