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.type_arguments_test; | 5 library test.type_arguments_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 import 'generics_helper.dart'; |
10 | 11 |
11 class A<T> {} | 12 class A<T> {} |
12 class Z<T> {} | 13 class Z<T> {} |
13 class B extends A {} // Same as class B extends A<dynamic>. | 14 class B extends A {} |
14 class C extends A | 15 class C |
15 <num, int> // TODO(zarah): Should be "01: static warning". | 16 extends A<num, int> /// 01: static type warning |
16 {} // Same as class C extends A<dynamic>. | 17 {} |
17 class D extends A<int> {} | 18 class D extends A<int> {} |
18 class E<S> extends A<S> {} | 19 class E<S> extends A<S> {} |
19 class F<R> extends A<int> {} | 20 class F<R> extends A<int> {} |
20 class G {} | 21 class G {} |
21 class H<A,B,C> {} | 22 class H<A,B,C> {} |
22 class I extends G {} | 23 class I extends G {} |
23 | 24 |
24 typeParameters(mirror, parameterNames) { | |
25 Expect.listEquals(parameterNames, | |
26 mirror.typeVariables.map((v) => v.simpleName).toList()); | |
27 } | |
28 | |
29 typeArguments(mirror, argumentMirrors) { | |
30 Expect.listEquals(argumentMirrors, mirror.typeArguments); | |
31 } | |
32 | |
33 main() { | 25 main() { |
34 // Declarations. | 26 // Declarations. |
35 typeParameters(reflectClass(A), [#T]); | 27 typeParameters(reflectClass(A), [#T]); |
36 typeParameters(reflectClass(G), []); | 28 typeParameters(reflectClass(G), []); |
37 typeParameters(reflectClass(B), []); | 29 typeParameters(reflectClass(B), []); |
38 typeParameters(reflectClass(C), []); | 30 typeParameters(reflectClass(C), []); |
39 typeParameters(reflectClass(D), []); | 31 typeParameters(reflectClass(D), []); |
40 typeParameters(reflectClass(E), [#S]); | 32 typeParameters(reflectClass(E), [#S]); |
41 typeParameters(reflectClass(F), [#R]); | 33 typeParameters(reflectClass(F), [#R]); |
42 typeParameters(reflectClass(G), []); | 34 typeParameters(reflectClass(G), []); |
(...skipping 25 matching lines...) Expand all Loading... |
68 Expect.equals(reflectClass(C), reflectClass(C).originalDeclaration); | 60 Expect.equals(reflectClass(C), reflectClass(C).originalDeclaration); |
69 Expect.equals(reflectClass(D), reflectClass(D).originalDeclaration); | 61 Expect.equals(reflectClass(D), reflectClass(D).originalDeclaration); |
70 Expect.equals(reflectClass(E), reflectClass(E).originalDeclaration); | 62 Expect.equals(reflectClass(E), reflectClass(E).originalDeclaration); |
71 Expect.equals(reflectClass(F), reflectClass(F).originalDeclaration); | 63 Expect.equals(reflectClass(F), reflectClass(F).originalDeclaration); |
72 Expect.equals(reflectClass(G), reflectClass(G).originalDeclaration); | 64 Expect.equals(reflectClass(G), reflectClass(G).originalDeclaration); |
73 Expect.equals(reflectClass(H), reflectClass(H).originalDeclaration); | 65 Expect.equals(reflectClass(H), reflectClass(H).originalDeclaration); |
74 Expect.equals(reflectClass(I), reflectClass(I).originalDeclaration); | 66 Expect.equals(reflectClass(I), reflectClass(I).originalDeclaration); |
75 | 67 |
76 // Instantiations. | 68 // Instantiations. |
77 typeParameters(reflect(new A<num>()).type, [#T]); | 69 typeParameters(reflect(new A<num>()).type, [#T]); |
78 typeParameters(reflect(new B<num>()).type, []); | 70 typeParameters(reflect(new B()).type, []); |
79 typeParameters(reflect(new C()).type, []); | 71 typeParameters(reflect(new C()).type, []); |
80 typeParameters(reflect(new D()).type, []); | 72 typeParameters(reflect(new D()).type, []); |
81 typeParameters(reflect(new E()).type, [#S]); | 73 typeParameters(reflect(new E()).type, [#S]); |
82 typeParameters(reflect(new F<num>()).type, [#R]); | 74 typeParameters(reflect(new F<num>()).type, [#R]); |
83 typeParameters(reflect(new G()).type, []); | 75 typeParameters(reflect(new G()).type, []); |
84 typeParameters(reflect(new H()).type, [#A, #B, #C]); | 76 typeParameters(reflect(new H()).type, [#A, #B, #C]); |
85 typeParameters(reflect(new I()).type, []); | 77 typeParameters(reflect(new I()).type, []); |
86 | 78 |
87 var numMirror = reflectClass(num); | 79 var numMirror = reflectClass(num); |
88 var dynamicMirror = currentMirrorSystem().dynamicType; | 80 var dynamicMirror = currentMirrorSystem().dynamicType; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 }); | 154 }); |
163 }); | 155 }); |
164 | 156 |
165 Expect.equals(reflectClass(A).typeVariables[0].owner, reflectClass(A)); | 157 Expect.equals(reflectClass(A).typeVariables[0].owner, reflectClass(A)); |
166 Expect.equals(reflectClass(Z).typeVariables[0].owner, reflectClass(Z)); | 158 Expect.equals(reflectClass(Z).typeVariables[0].owner, reflectClass(Z)); |
167 Expect.notEquals(reflectClass(A).typeVariables[0], | 159 Expect.notEquals(reflectClass(A).typeVariables[0], |
168 reflectClass(Z).typeVariables[0]); | 160 reflectClass(Z).typeVariables[0]); |
169 Expect.equals(reflectClass(A).typeVariables[0], | 161 Expect.equals(reflectClass(A).typeVariables[0], |
170 reflectClass(A).typeVariables[0]); | 162 reflectClass(A).typeVariables[0]); |
171 } | 163 } |
OLD | NEW |