Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: tests/lib/mirrors/symbol_validation_test.dart

Issue 140643006: Update documentation on Symbol. Make validation match. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allow qualified names Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/internal/symbol.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/symbol_validation_test.dart
diff --git a/tests/lib/mirrors/symbol_validation_test.dart b/tests/lib/mirrors/symbol_validation_test.dart
index 0fe3c45c3d412b142226754f67f66ee0473c4d18..11261abe1332f224ce858dd197ff4259d9e7ec84 100644
--- a/tests/lib/mirrors/symbol_validation_test.dart
+++ b/tests/lib/mirrors/symbol_validation_test.dart
@@ -26,14 +26,96 @@ invalidSymbol(String string) {
}
main() {
- ['%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>',
- '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/']
- .forEach(validSymbol);
+ // Operators that can be declared as class member operators.
+ // These are all valid as symbols.
+ var operators = [
+ '%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>',
+ '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/'
+ ];
+ operator.expand((op) => [op, "x.op"]).forEach(validSymbol);
ahe 2014/02/21 12:09:28 x.$op
+ operator.expand((op) => [".$op", "$op.x", "x$op", "_x.$op"])
+ .forEach(invalidSymbol);
+ operator.expand((op) => operators.contains("$op=") ? [] : ["x.$op=", "$op="])
+ .forEach(invalidSymbol);
- ['foo', '_bar', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e',
- '\$', 'foo\$', 'bar\$bar']
- .forEach(validSymbol);
+ var simpleSymbols = [
+ 'foo', '_bar', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e',
+ r'$', r'foo$', r'bar$bar', r'$.$', r'x6$_', r'$6_', r'x.$$6_',
+ 'x_', 'x_.x_',
+ ];
+ simpleSymbols.expand((s) => [s, "s="]).forEach(validSymbol);
- ['6', '0foo', ',', 'S with M', '_invalid&private']
- .forEach(invalidSymbol);
+ var nonSymbols = [
+ // Non-identifiers.
+ '6', '0foo', ',', 'S with M', '_invalid&private', "#foo", " foo", "foo ",
+ // Operator variants.
+ '+=', '()', 'operator+', 'unary+', '>>>', "&&", "||", "!", "@", "#", "[",
+ // Privat symbols.
+ '_', '_x', 'x._y', 'x._',
+ // Empty parts of "qualified" symbols.
+ '.', 'x.', '.x', 'x..y'
+ ];
+ nonSymbols.forEach(invalidSymbol);
+
+ // Reserved words are not valid identifiers and therefore not valid symbols.
+ var reservedWords = [
+ "assert",
+ "break",
+ "case",
+ "catch",
+ "class",
+ "const",
+ "continue",
+ "default",
+ "do",
+ "else",
+ "enum",
+ "extends",
+ "false",
+ "final",
+ "finally",
+ "for",
+ "if",
+ "in",
+ "is",
+ "new",
+ "null",
+ "rethrow",
+ "return",
+ "super",
+ "switch",
+ "this",
+ "throw",
+ "true",
+ "try",
+ "var",
+ "void",
+ "while",
+ "with"
+ ];
+ reservedWords.expand((w) => [w, "$w=", "x.$w" , "$w.x", "x.$w.x"])
+ .forEach(invalidSymbol);
+
+ // Built-in identifiers are valid identifiers that are restricted from being
+ // used in some cases, but they are all valid symbols.
+ var builtInIdentifiers = [
+ "abstract",
+ "as",
+ "dynamic",
+ "export",
+ "external",
+ "factory",
+ "get",
+ "implements",
+ "import",
+ "library",
+ "operator",
+ "part",
+ "set",
+ "static",
+ "typedef"
+ ];
+ builtInIdentifiers.expand((w) => [w, "$w=", "x.$w" , "$w.x", "x.$w.x",
+ "$w=", "x.$w="])
+ .forEach(validSymbol);
}
« no previous file with comments | « sdk/lib/internal/symbol.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698