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 symbol_validation_test; | 5 library symbol_validation_test; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 validSymbol(String string) { | 10 validSymbol(String string) { |
(...skipping 18 matching lines...) Expand all Loading... |
29 ['%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>', | 29 ['%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>', |
30 '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/'] | 30 '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/'] |
31 .forEach(validSymbol); | 31 .forEach(validSymbol); |
32 | 32 |
33 ['foo', '_bar', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e', | 33 ['foo', '_bar', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e', |
34 '\$', 'foo\$', 'bar\$bar'] | 34 '\$', 'foo\$', 'bar\$bar'] |
35 .forEach(validSymbol); | 35 .forEach(validSymbol); |
36 | 36 |
37 ['6', '0foo', ',', 'S with M', '_invalid&private'] | 37 ['6', '0foo', ',', 'S with M', '_invalid&private'] |
38 .forEach(invalidSymbol); | 38 .forEach(invalidSymbol); |
| 39 |
| 40 // Reserved words are not valid identifiers and therefore not valid symbols. |
| 41 var reservedWords = [ |
| 42 "assert", |
| 43 "break", |
| 44 "case", |
| 45 "catch", |
| 46 "class", |
| 47 "const", |
| 48 "continue", |
| 49 "default", |
| 50 "do", |
| 51 "else", |
| 52 "enum", |
| 53 "extends", |
| 54 "false", |
| 55 "final", |
| 56 "finally", |
| 57 "for", |
| 58 "if", |
| 59 "in", |
| 60 "is", |
| 61 "new", |
| 62 "null", |
| 63 "rethrow", |
| 64 "return", |
| 65 "super", |
| 66 "switch", |
| 67 "this", |
| 68 "throw", |
| 69 "true", |
| 70 "try", |
| 71 "var", |
| 72 "void", |
| 73 "while", |
| 74 "with" |
| 75 ]; |
| 76 reservedWords.expand((w) => [w, "$w=", "x.$w" , "$w.x", "x.$w.x"]) |
| 77 .forEach(invalidSymbol); |
39 } | 78 } |
| 79 |
| 80 |
OLD | NEW |