OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 library reserved_names_test; | 6 library reserved_names_test; |
7 | 7 |
8 import 'dart:mirrors' as mirrors; | 8 import 'dart:mirrors' as mirrors; |
9 | 9 |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
12 import '../lib/protoc.dart' show MessageGenerator; | 12 import '../lib/protoc.dart' show MessageGenerator; |
13 | 13 |
14 import 'test_util.dart'; | 14 import 'test_util.dart'; |
15 | 15 |
16 void main() { | 16 void main() { |
17 test('testReservedNamesList', () { | 17 test('testReservedNamesList', () { |
18 Set<String> names = new Set<String>(); | 18 Set<String> names = new Set<String>(); |
19 fillConflictingNames(ClassMirror cls) { | 19 fillConflictingNames(mirrors.ClassMirror cls) { |
20 String className = mirrors.MirrorSystem.getName(cls.simpleName); | 20 String className = mirrors.MirrorSystem.getName(cls.simpleName); |
21 names.addAll( | 21 names.addAll( |
22 cls | 22 cls |
23 .constructors | 23 .constructors |
24 .values | 24 .values |
25 .where((ctor) => !ctor.isPrivate) | 25 .where((ctor) => !ctor.isPrivate) |
26 .map((m) => mirrors.MirrorSystem.getName(m.simpleName)) | 26 .map((m) => mirrors.MirrorSystem.getName(m.simpleName)) |
27 .map((n) => n.startsWith(className + '.') | 27 .map((n) => n.startsWith(className + '.') |
28 ? n.substring(className.length + 1) : n) | 28 ? n.substring(className.length + 1) : n) |
29 .toList()); | 29 .toList()); |
(...skipping 10 matching lines...) Expand all Loading... |
40 .classes[#GeneratedMessage]; | 40 .classes[#GeneratedMessage]; |
41 do { | 41 do { |
42 fillConflictingNames(cls); | 42 fillConflictingNames(cls); |
43 cls = cls.superclass; | 43 cls = cls.superclass; |
44 } while (cls != null); | 44 } while (cls != null); |
45 | 45 |
46 var x = new Set<String>()..addAll(MessageGenerator.reservedNames); | 46 var x = new Set<String>()..addAll(MessageGenerator.reservedNames); |
47 expect(names.toList()..sort(), equals(x.toList()..sort())); | 47 expect(names.toList()..sort(), equals(x.toList()..sort())); |
48 }); | 48 }); |
49 } | 49 } |
OLD | NEW |