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.mixin_test; | |
6 | |
7 @MirrorsUsed(targets: 'test.mixin_test, test.model, Object', override: '*') | |
ahe
2013/08/09 12:17:49
I have discovered this test doesn't work without a
| |
8 import 'dart:mirrors'; | |
9 | |
10 import 'package:expect/expect.dart'; | |
11 | |
12 import 'model.dart'; | |
13 import 'stringify.dart'; | |
14 | |
15 class Mixin { | |
16 int i; | |
17 m() {} | |
18 } | |
19 | |
20 class Mixin2 { | |
21 int i2; | |
22 m2() {} | |
23 } | |
24 | |
25 typedef MixinApplication = C with Mixin; | |
26 typedef MixinApplicationA = C with Mixin, Mixin2; | |
27 | |
28 typedef UnusedMixinApplication = C with Mixin; | |
29 | |
30 class Subclass extends C with Mixin { | |
31 f() {} | |
32 } | |
33 | |
34 class Subclass2 extends MixinApplication { | |
35 g() {} | |
36 } | |
37 | |
38 class SubclassA extends C with Mixin, Mixin2 { | |
39 fa() {} | |
40 } | |
41 | |
42 class Subclass2A extends MixinApplicationA { | |
43 ga() {} | |
44 } | |
45 | |
46 checkClass(Type type, List<String> expectedSuperclasses) { | |
47 int i = 0; | |
48 for (var cls = reflectClass(type); cls != null; cls = cls.superclass) { | |
49 expect(expectedSuperclasses[i++], cls); | |
50 } | |
51 Expect.equals(i, expectedSuperclasses.length, '$type'); | |
52 } | |
53 | |
54 expectSame(ClassMirror a, ClassMirror b) { | |
55 Expect.equals(a, b); | |
56 expect(stringify(a), b); | |
57 expect(stringify(b), a); | |
58 } | |
59 | |
60 testMixin() { | |
61 checkClass(Mixin, [ | |
62 'Class(s(Mixin) in s(test.mixin_test), top-level)', | |
63 'Class(s(Object) in s(dart.core), top-level)', | |
64 ]); | |
65 expect( | |
66 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' | |
ahe
2013/08/09 12:17:49
This is wrong, members should not include construc
| |
67 ' i: Variable(s(i) in s(Mixin)),' | |
68 ' m: Method(s(m) in s(Mixin))}', | |
69 reflectClass(Mixin).members); | |
70 } | |
71 | |
72 testMixin2() { | |
73 checkClass(Mixin2, [ | |
74 'Class(s(Mixin2) in s(test.mixin_test), top-level)', | |
75 'Class(s(Object) in s(dart.core), top-level)', | |
76 ]); | |
77 expect( | |
78 '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),' | |
79 ' i2: Variable(s(i2) in s(Mixin2)),' | |
80 ' m2: Method(s(m2) in s(Mixin2))}', | |
81 reflectClass(Mixin2).members); | |
82 } | |
83 | |
84 testMixinApplication() { | |
85 checkClass(MixinApplication, [ | |
86 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', | |
87 'Class(s(C) in s(test.model), top-level)', | |
88 'Class(s(B) in s(test.model), top-level)', | |
89 'Class(s(A) in s(test.model), top-level)', | |
90 'Class(s(Object) in s(dart.core), top-level)', | |
91 ]); | |
92 | |
93 expect( | |
94 '{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),' | |
95 ' constructor),' | |
96 ' i: Variable(s(i) in s(MixinApplication)),' | |
97 ' m: Method(s(m) in s(MixinApplication))}', | |
98 reflectClass(MixinApplication).members); | |
99 | |
100 expectSame(reflectClass(C), reflectClass(MixinApplication).superclass); | |
101 } | |
102 | |
103 testMixinApplicationA() { | |
104 checkClass(MixinApplicationA, [ | |
105 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', | |
106 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', | |
107 'Class(s(C) in s(test.model), top-level)', | |
108 'Class(s(B) in s(test.model), top-level)', | |
109 'Class(s(A) in s(test.model), top-level)', | |
110 'Class(s(Object) in s(dart.core), top-level)', | |
111 ]); | |
112 | |
113 expect( | |
114 '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),' | |
115 ' constructor),' | |
116 ' i2: Variable(s(i2) in s(MixinApplicationA)),' | |
117 ' m2: Method(s(m2) in s(MixinApplicationA))}', | |
118 reflectClass(MixinApplicationA).members); | |
119 | |
120 expect( | |
121 // TODO(ahe): The owner should probably be the mixin application. | |
ahe
2013/08/09 12:17:49
Actually, the mixin is the owner of members, but n
| |
122 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' | |
123 ' i: Variable(s(i) in s(Mixin)),' | |
124 ' m: Method(s(m) in s(Mixin))}', | |
125 reflectClass(MixinApplicationA).superclass.members); | |
126 | |
127 expectSame( | |
128 reflectClass(C), | |
129 reflectClass(MixinApplicationA).superclass.superclass); | |
130 } | |
131 | |
132 testUnusedMixinApplication() { | |
133 checkClass(UnusedMixinApplication, [ | |
134 'Class(s(UnusedMixinApplication) in s(test.mixin_test), top-level)', | |
135 'Class(s(C) in s(test.model), top-level)', | |
136 'Class(s(B) in s(test.model), top-level)', | |
137 'Class(s(A) in s(test.model), top-level)', | |
138 'Class(s(Object) in s(dart.core), top-level)', | |
139 ]); | |
140 | |
141 expect( | |
142 '{UnusedMixinApplication: Method(s(UnusedMixinApplication)' | |
143 ' in s(UnusedMixinApplication), constructor),' | |
144 ' i: Variable(s(i) in s(UnusedMixinApplication)),' | |
145 ' m: Method(s(m) in s(UnusedMixinApplication))}', | |
146 reflectClass(UnusedMixinApplication).members); | |
147 | |
148 expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass); | |
149 } | |
150 | |
151 testSubclass() { | |
152 checkClass(Subclass, [ | |
153 'Class(s(Subclass) in s(test.mixin_test), top-level)', | |
154 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', | |
155 'Class(s(C) in s(test.model), top-level)', | |
156 'Class(s(B) in s(test.model), top-level)', | |
157 'Class(s(A) in s(test.model), top-level)', | |
158 'Class(s(Object) in s(dart.core), top-level)', | |
159 ]); | |
160 | |
161 expect( | |
162 '{Subclass: Method(s(Subclass) in s(Subclass), constructor),' | |
163 ' f: Method(s(f) in s(Subclass))}', | |
164 reflectClass(Subclass).members); | |
165 | |
166 expect( | |
167 // TODO(ahe): The owner should probably be the mixin application. | |
168 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' | |
169 ' i: Variable(s(i) in s(Mixin)),' | |
170 ' m: Method(s(m) in s(Mixin))}', | |
171 reflectClass(Subclass).superclass.members); | |
172 | |
173 expectSame( | |
174 reflectClass(C), | |
175 reflectClass(Subclass).superclass.superclass); | |
176 } | |
177 | |
178 testSubclass2() { | |
179 checkClass(Subclass2, [ | |
180 'Class(s(Subclass2) in s(test.mixin_test), top-level)', | |
181 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', | |
182 'Class(s(C) in s(test.model), top-level)', | |
183 'Class(s(B) in s(test.model), top-level)', | |
184 'Class(s(A) in s(test.model), top-level)', | |
185 'Class(s(Object) in s(dart.core), top-level)', | |
186 ]); | |
187 | |
188 expect( | |
189 '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor),' | |
190 ' g: Method(s(g) in s(Subclass2))}', | |
191 reflectClass(Subclass2).members); | |
192 | |
193 expectSame( | |
194 reflectClass(MixinApplication), | |
195 reflectClass(Subclass2).superclass); | |
196 } | |
197 | |
198 testSubclassA() { | |
199 checkClass(SubclassA, [ | |
200 'Class(s(SubclassA) in s(test.mixin_test), top-level)', | |
201 'Class(s(test.mixin_test.Mixin2(test.mixin_test.Mixin(test.model.C))),' | |
202 ' top-level)', | |
203 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', | |
204 'Class(s(C) in s(test.model), top-level)', | |
205 'Class(s(B) in s(test.model), top-level)', | |
206 'Class(s(A) in s(test.model), top-level)', | |
207 'Class(s(Object) in s(dart.core), top-level)', | |
208 ]); | |
209 | |
210 expect( | |
211 '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor),' | |
212 ' fa: Method(s(fa) in s(SubclassA))}', | |
213 reflectClass(SubclassA).members); | |
214 | |
215 expect( | |
216 // TODO(ahe): The owner should probably be the mixin application. | |
217 '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),' | |
218 ' i2: Variable(s(i2) in s(Mixin2)),' | |
219 ' m2: Method(s(m2) in s(Mixin2))}', | |
220 reflectClass(SubclassA).superclass.members); | |
221 | |
222 expect( | |
223 // TODO(ahe): The owner should probably be the mixin application. | |
224 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' | |
225 ' i: Variable(s(i) in s(Mixin)),' | |
226 ' m: Method(s(m) in s(Mixin))}', | |
227 reflectClass(SubclassA).superclass.superclass.members); | |
228 | |
229 expectSame( | |
230 reflectClass(C), | |
231 reflectClass(SubclassA).superclass.superclass.superclass); | |
232 } | |
233 | |
234 testSubclass2A() { | |
235 checkClass(Subclass2A, [ | |
236 'Class(s(Subclass2A) in s(test.mixin_test), top-level)', | |
237 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', | |
238 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', | |
239 'Class(s(C) in s(test.model), top-level)', | |
240 'Class(s(B) in s(test.model), top-level)', | |
241 'Class(s(A) in s(test.model), top-level)', | |
242 'Class(s(Object) in s(dart.core), top-level)', | |
243 ]); | |
244 | |
245 expect( | |
246 '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor),' | |
247 ' ga: Method(s(ga) in s(Subclass2A))}', | |
248 reflectClass(Subclass2A).members); | |
249 | |
250 expectSame(reflectClass(MixinApplicationA), | |
251 reflectClass(Subclass2A).superclass); | |
252 } | |
253 | |
254 main() { | |
255 testMixin(); | |
256 testMixin2(); | |
257 testMixinApplication(); | |
258 testMixinApplicationA(); | |
259 testUnusedMixinApplication(); | |
260 testSubclass(); | |
261 testSubclass2(); | |
262 testSubclassA(); | |
263 testSubclass2A(); | |
264 } | |
OLD | NEW |