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

Side by Side Diff: tests/lib/mirrors/symbol_validation_test.dart

Issue 177483002: Add validation of private symbols to the dart2js mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
11 Expect.equals(string, 11 Expect.equals(string,
12 MirrorSystem.getName(new Symbol(string)), 12 MirrorSystem.getName(new Symbol(string)),
13 'Valid symbol "$string" should be invertable'); 13 'Valid symbol "$string" should be invertable');
14 return; /// 01: ok
15 Expect.equals(string, 14 Expect.equals(string,
16 MirrorSystem.getName(MirrorSystem.getSymbol(string)), 15 MirrorSystem.getName(MirrorSystem.getSymbol(string)),
17 'Valid symbol "$string" should be invertable'); 16 'Valid symbol "$string" should be invertable');
18 } 17 }
19 18
20 invalidSymbol(String string) { 19 invalidSymbol(String string) {
21 Expect.throws(() => new Symbol(string), 20 Expect.throws(() => new Symbol(string),
22 (e) => e is ArgumentError, 21 (e) => e is ArgumentError,
23 'Invalid symbol "$string" should be rejected'); 22 'Invalid symbol "$string" should be rejected');
24 return; /// 01: continued
25 Expect.throws(() => MirrorSystem.getSymbol(string), 23 Expect.throws(() => MirrorSystem.getSymbol(string),
26 (e) => e is ArgumentError, 24 (e) => e is ArgumentError,
27 'Invalid symbol "$string" should be rejected'); 25 'Invalid symbol "$string" should be rejected');
28 } 26 }
29 27
28 validPrivateSymbol(String string) {
29 ClosureMirror closure = reflect(main);
30 LibraryMirror library = closure.function.owner;
31 Expect.equals(string,
32 MirrorSystem.getName(MirrorSystem.getSymbol(string, library)),
33 'Valid private symbol "$string" should be invertable');
34 }
35
30 main() { 36 main() {
31 // Operators that can be declared as class member operators. 37 // Operators that can be declared as class member operators.
32 // These are all valid as symbols. 38 // These are all valid as symbols.
33 var operators = [ 39 var operators = [
34 '%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>', 40 '%', '&', '*', '+', '-', '/', '<', '<<', '<=', '==', '>',
35 '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/' 41 '>=', '>>', '[]', '[]=', '^', 'unary-', '|', '~', '~/'
36 ]; 42 ];
37 operators.expand((op) => [op, "x.$op"]).forEach(validSymbol); 43 operators.expand((op) => [op, "x.$op"]).forEach(validSymbol);
38 operators.expand((op) => [".$op", "$op.x", "x$op", "_x.$op"]) 44 operators.expand((op) => [".$op", "$op.x", "x$op", "_x.$op"])
39 .forEach(invalidSymbol); 45 .forEach(invalidSymbol);
40 operators.expand((op) => operators.contains("$op=") ? [] : ["x.$op=", "$op="]) 46 operators.expand((op) => operators.contains("$op=") ? [] : ["x.$op=", "$op="])
41 .forEach(invalidSymbol); 47 .forEach(invalidSymbol);
42 48
43 var simpleSymbols = [ 49 var simpleSymbols = [
44 'foo', 'bar_', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e', 50 'foo', 'bar_', 'baz.quz', 'fisk1', 'hest2fisk', 'a.b.c.d.e',
45 r'$', r'foo$', r'bar$bar', r'$.$', r'x6$_', r'$6_', r'x.$$6_', 51 r'$', r'foo$', r'bar$bar', r'$.$', r'x6$_', r'$6_', r'x.$$6_',
46 'x_', 'x_.x_', 52 'x_', 'x_.x_', 'unary', 'x.unary'
47 ]; 53 ];
48 simpleSymbols.expand((s) => [s, "s="]).forEach(validSymbol); 54 simpleSymbols.expand((s) => [s, "s="]).forEach(validSymbol);
49 55
50 var nonSymbols = [ 56 var nonSymbols = [
51 // Non-identifiers. 57 // Non-identifiers.
52 '6', '0foo', ',', 'S with M', '_invalid&private', "#foo", " foo", "foo ", 58 '6', '0foo', ',', 'S with M', '_invalid&private', "#foo", " foo", "foo ",
53 // Operator variants. 59 // Operator variants.
54 '+=', '()', 'operator+', 'unary+', '>>>', "&&", "||", "!", "@", "#", "[", 60 '+=', '()', 'operator+', 'unary+', '>>>', "&&", "||", "!", "@", "#", "[",
55 // Private symbols. 61 // Private symbols.
56 '_', '_x', 'x._y', 'x._', 62 '_', '_x', 'x._y', 'x._',
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 "library", 121 "library",
116 "operator", 122 "operator",
117 "part", 123 "part",
118 "set", 124 "set",
119 "static", 125 "static",
120 "typedef" 126 "typedef"
121 ]; 127 ];
122 builtInIdentifiers.expand((w) => [w, "$w=", "x.$w" , "$w.x", "x.$w.x", 128 builtInIdentifiers.expand((w) => [w, "$w=", "x.$w" , "$w.x", "x.$w.x",
123 "$w=", "x.$w="]) 129 "$w=", "x.$w="])
124 .forEach(validSymbol); 130 .forEach(validSymbol);
131
132 var privateSymbols = [
133 '_', '_x', 'x._y', 'x._', 'x.y._', 'x._.y', '_true'
134 ];
135 privateSymbols.forEach(invalidSymbol);
136 privateSymbols.forEach(validPrivateSymbol); /// 01: ok
125 } 137 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698