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 test; | 5 library 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 typedef int _F(int); | 10 typedef int _F(int); |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Test private symbols are distinct across libraries, and the same within a | 22 // Test private symbols are distinct across libraries, and the same within a |
23 // library when created multiple ways. Test the string can be properly | 23 // library when created multiple ways. Test the string can be properly |
24 // extracted. | 24 // extracted. |
25 LibraryMirror libcore = currentMirrorSystem().findLibrary(#dart.core); | 25 LibraryMirror libcore = currentMirrorSystem().findLibrary(#dart.core); |
26 LibraryMirror libmath = currentMirrorSystem().findLibrary(#dart.math); | 26 LibraryMirror libmath = currentMirrorSystem().findLibrary(#dart.math); |
27 LibraryMirror libtest = currentMirrorSystem().findLibrary(#test); | 27 LibraryMirror libtest = currentMirrorSystem().findLibrary(#test); |
28 | 28 |
29 Symbol corefoo = MirrorSystem.getSymbol('foo', libcore); | 29 Symbol corefoo = MirrorSystem.getSymbol('foo', libcore); |
30 Symbol mathfoo = MirrorSystem.getSymbol('foo', libmath); | 30 Symbol mathfoo = MirrorSystem.getSymbol('foo', libmath); |
31 Symbol testfoo = MirrorSystem.getSymbol('foo', libtest); | 31 Symbol testfoo = MirrorSystem.getSymbol('foo', libtest); |
| 32 Symbol nullfoo1 = MirrorSystem.getSymbol('foo'); |
| 33 Symbol nullfoo2 = MirrorSystem.getSymbol('foo', null); |
32 | 34 |
33 Expect.equals(corefoo, mathfoo); | 35 Expect.equals(corefoo, mathfoo); |
34 Expect.equals(mathfoo, testfoo); | 36 Expect.equals(mathfoo, testfoo); |
35 Expect.equals(testfoo, corefoo); | 37 Expect.equals(testfoo, corefoo); |
| 38 Expect.equals(nullfoo1, corefoo); |
| 39 Expect.equals(nullfoo2, corefoo); |
36 | 40 |
37 Expect.equals('foo', MirrorSystem.getName(corefoo)); | 41 Expect.equals('foo', MirrorSystem.getName(corefoo)); |
38 Expect.equals('foo', MirrorSystem.getName(mathfoo)); | 42 Expect.equals('foo', MirrorSystem.getName(mathfoo)); |
39 Expect.equals('foo', MirrorSystem.getName(testfoo)); | 43 Expect.equals('foo', MirrorSystem.getName(testfoo)); |
40 Expect.equals('foo', MirrorSystem.getName(#foo)); | 44 Expect.equals('foo', MirrorSystem.getName(#foo)); |
| 45 Expect.equals('foo', MirrorSystem.getName(nullfoo1)); |
| 46 Expect.equals('foo', MirrorSystem.getName(nullfoo2)); |
41 | 47 |
42 Symbol core_foo = MirrorSystem.getSymbol('_foo', libcore); | 48 Symbol core_foo = MirrorSystem.getSymbol('_foo', libcore); |
43 Symbol math_foo = MirrorSystem.getSymbol('_foo', libmath); | 49 Symbol math_foo = MirrorSystem.getSymbol('_foo', libmath); |
44 Symbol test_foo = MirrorSystem.getSymbol('_foo', libtest); | 50 Symbol test_foo = MirrorSystem.getSymbol('_foo', libtest); |
45 | 51 |
46 Expect.equals('_foo', MirrorSystem.getName(core_foo)); | 52 Expect.equals('_foo', MirrorSystem.getName(core_foo)); |
47 Expect.equals('_foo', MirrorSystem.getName(math_foo)); | 53 Expect.equals('_foo', MirrorSystem.getName(math_foo)); |
48 Expect.equals('_foo', MirrorSystem.getName(test_foo)); | 54 Expect.equals('_foo', MirrorSystem.getName(test_foo)); |
49 Expect.equals('_foo', MirrorSystem.getName(#_foo)); | 55 Expect.equals('_foo', MirrorSystem.getName(#_foo)); |
50 | 56 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 Expect.throws(() => MirrorSystem.getSymbol('_private'), | 124 Expect.throws(() => MirrorSystem.getSymbol('_private'), |
119 (e) => e is ArgumentError); | 125 (e) => e is ArgumentError); |
120 | 126 |
121 var notALibraryMirror = 7; | 127 var notALibraryMirror = 7; |
122 Expect.throws(() => MirrorSystem.getSymbol('_private', notALibraryMirror), | 128 Expect.throws(() => MirrorSystem.getSymbol('_private', notALibraryMirror), |
123 (e) => e is ArgumentError || e is TypeError); | 129 (e) => e is ArgumentError || e is TypeError); |
124 | 130 |
125 Expect.throws(() => MirrorSystem.getSymbol('public', notALibraryMirror), | 131 Expect.throws(() => MirrorSystem.getSymbol('public', notALibraryMirror), |
126 (e) => e is ArgumentError || e is TypeError); | 132 (e) => e is ArgumentError || e is TypeError); |
127 } | 133 } |
OLD | NEW |