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 mixin_members_test; | 5 library mixin_members_test; |
6 | 6 |
7 import "dart:mirrors"; | 7 import "dart:mirrors"; |
8 | 8 |
9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 bar2() {} | 24 bar2() {} |
25 } | 25 } |
26 | 26 |
27 class M2 { | 27 class M2 { |
28 baz1() {} | 28 baz1() {} |
29 baz2() {} | 29 baz2() {} |
30 } | 30 } |
31 | 31 |
32 class C extends S with M1, M2 {} | 32 class C extends S with M1, M2 {} |
33 | 33 |
34 membersOf(ClassMirror cm) { | |
35 var result = new Map(); | |
36 cm.declarations.forEach((k,v) { | |
37 if(v is MethodMirror && !v.isConstructor) result[k] = v; | |
38 if(v is VariableMirror) result[k] = v; | |
39 }); | |
40 return result; | |
41 } | |
42 | |
43 main() { | 34 main() { |
44 ClassMirror cm = reflectClass(C); | 35 ClassMirror cm = reflectClass(C); |
45 ClassMirror sM1M2 = cm.superclass; | 36 ClassMirror sM1M2 = cm.superclass; |
46 ClassMirror sM1 = sM1M2.superclass; | 37 ClassMirror sM1 = sM1M2.superclass; |
47 ClassMirror s = sM1.superclass; | 38 ClassMirror s = sM1.superclass; |
48 expect('{}', membersOf(cm)); | 39 expect('{}', cm.members); |
49 expect('[s(baz1), s(baz2)]', | 40 expect('[s(baz1), s(baz2)]', |
50 // TODO(ahe): Shouldn't have to sort. | 41 // TODO(ahe): Shouldn't have to sort. |
51 sort(membersOf(sM1M2).keys), | 42 sort(sM1M2.members.keys), |
52 '(S with M1, M2).members'); | 43 '(S with M1, M2).members'); |
53 expect('[s(M2)]', simpleNames(sM1M2.superinterfaces), | 44 expect('[s(M2)]', simpleNames(sM1M2.superinterfaces), |
54 '(S with M1, M2).superinterfaces'); | 45 '(S with M1, M2).superinterfaces'); |
55 expect('[s(bar1), s(bar2)]', | 46 expect('[s(bar1), s(bar2)]', |
56 // TODO(ahe): Shouldn't have to sort. | 47 // TODO(ahe): Shouldn't have to sort. |
57 sort(membersOf(sM1).keys), '(S with M1).members'); | 48 sort(sM1.members.keys), '(S with M1).members'); |
58 expect('[s(M1)]', simpleNames(sM1.superinterfaces), | 49 expect('[s(M1)]', simpleNames(sM1.superinterfaces), |
59 '(S with M1).superinterfaces'); | 50 '(S with M1).superinterfaces'); |
60 expect('[s(foo1), s(foo2)]', | 51 expect('[s(foo1), s(foo2)]', |
61 // TODO(ahe): Shouldn't have to sort. | 52 // TODO(ahe): Shouldn't have to sort. |
62 sort(membersOf(s).keys), 's.members'); | 53 sort(s.members.keys), 's.members'); |
63 expect('[s(Fooer)]', simpleNames(s.superinterfaces), 's.superinterfaces'); | 54 expect('[s(Fooer)]', simpleNames(s.superinterfaces), 's.superinterfaces'); |
64 Expect.equals(s, reflectClass(S)); | 55 Expect.equals(s, reflectClass(S)); |
65 } | 56 } |
OLD | NEW |