OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library symbol_validation_test; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 import 'package:expect/expect.dart'; |
| 9 |
| 10 validSymbol(String string) { |
| 11 Expect.equals(string, |
| 12 MirrorSystem.getName(new Symbol(string)), |
| 13 'Valid symbol "$string" should be invertable'); |
| 14 Expect.equals(string, |
| 15 MirrorSystem.getName(MirrorSystem.getSymbol(string)), |
| 16 'Valid symbol "$string" should be invertable'); |
| 17 } |
| 18 |
| 19 invalidSymbol(String string) { |
| 20 Expect.throws(() => new Symbol(string), |
| 21 (e) => e is ArgumentError, |
| 22 'Invalid symbol "$string" should be rejected'); |
| 23 Expect.throws(() => MirrorSystem.getSymbol(string), |
| 24 (e) => e is ArgumentError, |
| 25 'Invalid symbol "$string" should be rejected'); |
| 26 } |
| 27 |
| 28 main() { |
| 29 ['%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>', |
| 30 '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/'] |
| 31 .forEach(validSymbol); |
| 32 |
| 33 ['foo', '_bar', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e', |
| 34 '\$', 'foo\$', 'bar\$bar'] |
| 35 .forEach(validSymbol); |
| 36 |
| 37 ['6', '0foo', ',', 'S with M', '_invalid&private'] |
| 38 .forEach(invalidSymbol); |
| 39 } |
OLD | NEW |