OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 import 'package:expect/expect.dart'; |
| 9 |
| 10 typedef int _F(int); |
| 11 |
| 12 class _C<_T> { |
| 13 get g {} |
| 14 set s(x) {} |
| 15 m(_p) {} |
| 16 get _g {} |
| 17 set _s(x) {} |
| 18 _m() {} |
| 19 } |
| 20 |
| 21 main() { |
| 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 |
| 24 // extracted. |
| 25 LibraryMirror libcore = currentMirrorSystem().findLibrary(#dart.core).single; |
| 26 LibraryMirror libmath = currentMirrorSystem().findLibrary(#dart.math).single; |
| 27 LibraryMirror libtest = currentMirrorSystem().findLibrary(#test).single; |
| 28 |
| 29 Symbol corefoo = MirrorSystem.getSymbol('foo', libcore); |
| 30 Symbol mathfoo = MirrorSystem.getSymbol('foo', libmath); |
| 31 Symbol testfoo = MirrorSystem.getSymbol('foo', libtest); |
| 32 |
| 33 Expect.equals(corefoo, mathfoo); |
| 34 Expect.equals(mathfoo, testfoo); |
| 35 Expect.equals(testfoo, corefoo); |
| 36 |
| 37 Expect.equals('foo', MirrorSystem.getName(corefoo)); |
| 38 Expect.equals('foo', MirrorSystem.getName(mathfoo)); |
| 39 Expect.equals('foo', MirrorSystem.getName(testfoo)); |
| 40 Expect.equals('foo', MirrorSystem.getName(#foo)); |
| 41 |
| 42 Symbol core_foo = MirrorSystem.getSymbol('_foo', libcore); |
| 43 Symbol math_foo = MirrorSystem.getSymbol('_foo', libmath); |
| 44 Symbol test_foo = MirrorSystem.getSymbol('_foo', libtest); |
| 45 |
| 46 Expect.equals('_foo', MirrorSystem.getName(core_foo)); |
| 47 Expect.equals('_foo', MirrorSystem.getName(math_foo)); |
| 48 Expect.equals('_foo', MirrorSystem.getName(test_foo)); |
| 49 Expect.equals('_foo', MirrorSystem.getName(#_foo)); |
| 50 |
| 51 Expect.notEquals(core_foo, math_foo); |
| 52 Expect.notEquals(math_foo, test_foo); |
| 53 Expect.notEquals(test_foo, core_foo); |
| 54 |
| 55 Expect.notEquals(corefoo, core_foo); |
| 56 Expect.notEquals(mathfoo, math_foo); |
| 57 Expect.notEquals(testfoo, test_foo); |
| 58 |
| 59 Expect.equals(test_foo, #_foo); |
| 60 |
| 61 |
| 62 // Test interactions with the manglings for getters and setters, etc. |
| 63 ClassMirror cm = reflectClass(_C); |
| 64 Expect.equals(#_C, cm.simpleName); |
| 65 Expect.equals('_C', MirrorSystem.getName(cm.simpleName)); |
| 66 |
| 67 MethodMirror mm = cm.members[#g]; |
| 68 Expect.isNotNull(mm); |
| 69 Expect.isTrue(mm.isGetter); |
| 70 Expect.equals(#g, mm.simpleName); |
| 71 Expect.equals('g', MirrorSystem.getName(mm.simpleName)); |
| 72 |
| 73 mm = cm.members[const Symbol('s=')]; |
| 74 Expect.isNotNull(mm); |
| 75 Expect.isTrue(mm.isSetter); |
| 76 Expect.equals(const Symbol('s='), mm.simpleName); |
| 77 Expect.equals('s=', MirrorSystem.getName(mm.simpleName)); |
| 78 |
| 79 mm = cm.members[#m]; |
| 80 Expect.isNotNull(mm); |
| 81 Expect.isTrue(mm.isRegularMethod); |
| 82 Expect.equals(#m, mm.simpleName); |
| 83 Expect.equals('m', MirrorSystem.getName(mm.simpleName)); |
| 84 |
| 85 mm = cm.members[#_g]; |
| 86 Expect.isNotNull(mm); |
| 87 Expect.isTrue(mm.isGetter); |
| 88 Expect.equals(#_g, mm.simpleName); |
| 89 Expect.equals('_g', MirrorSystem.getName(mm.simpleName)); |
| 90 |
| 91 mm = cm.members[MirrorSystem.getSymbol('_s=', libtest)]; |
| 92 Expect.isNotNull(mm); |
| 93 Expect.isTrue(mm.isSetter); |
| 94 Expect.equals(MirrorSystem.getSymbol('_s=', libtest), mm.simpleName); |
| 95 Expect.equals('_s=', MirrorSystem.getName(mm.simpleName)); |
| 96 |
| 97 mm = cm.members[#_m]; |
| 98 Expect.isNotNull(mm); |
| 99 Expect.isTrue(mm.isRegularMethod); |
| 100 Expect.equals(#_m, mm.simpleName); |
| 101 Expect.equals('_m', MirrorSystem.getName(mm.simpleName)); |
| 102 |
| 103 TypeVariableMirror tvm = cm.typeVariables[0]; |
| 104 Expect.isNotNull(tvm); |
| 105 Expect.equals(#_T, tvm.simpleName); |
| 106 Expect.equals('_T', MirrorSystem.getName(tvm.simpleName)); |
| 107 |
| 108 TypedefMirror tdm = reflectClass(_F); |
| 109 Expect.equals(#_F, tdm.simpleName); |
| 110 Expect.equals('_F', MirrorSystem.getName(tdm.simpleName)); |
| 111 |
| 112 ParameterMirror pm = cm.members[#m].parameters[0]; |
| 113 Expect.equals(#_p, pm.simpleName); |
| 114 Expect.equals('_p', MirrorSystem.getName(pm.simpleName)); |
| 115 } |
OLD | NEW |