Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: test/codegen/lib/mirrors/mixin_application_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // This test uses the multi-test "ok" feature to create two positive tests from
6 // one file. One of these tests fail on dart2js, but pass on the VM, or vice
7 // versa.
8 // TODO(ahe): When both implementations agree, remove the multi-test parts.
9
10 library test.mixin_application_test;
11
12 import 'dart:mirrors';
13
14 import 'package:expect/expect.dart';
15
16 import 'model.dart';
17 import 'stringify.dart';
18
19 class Mixin {
20 int i;
21 m() {}
22 }
23
24 class Mixin2 {
25 int i2;
26 m2() {}
27 }
28
29 class MixinApplication = C with Mixin;
30 class MixinApplicationA = C with Mixin, Mixin2;
31
32 class UnusedMixinApplication = C with Mixin;
33
34 class Subclass extends C with Mixin {
35 f() {}
36 }
37
38 class Subclass2 extends MixinApplication {
39 g() {}
40 }
41
42 class SubclassA extends C with Mixin, Mixin2 {
43 fa() {}
44 }
45
46 class Subclass2A extends MixinApplicationA {
47 ga() {}
48 }
49
50 membersOf(ClassMirror cm) {
51 var result = new Map();
52 cm.declarations.forEach((k,v) {
53 if(v is MethodMirror && !v.isConstructor) result[k] = v;
54 if(v is VariableMirror) result[k] = v;
55 });
56 return result;
57 }
58
59 constructorsOf(ClassMirror cm) {
60 var result = new Map();
61 cm.declarations.forEach((k,v) {
62 if(v is MethodMirror && v.isConstructor) result[k] = v;
63 });
64 return result;
65 }
66
67 checkClass(Type type, List<String> expectedSuperclasses) {
68 int i = 0;
69 for (var cls = reflectClass(type); cls != null; cls = cls.superclass) {
70 expect(expectedSuperclasses[i++], cls);
71 }
72 Expect.equals(i, expectedSuperclasses.length, '$type');
73 }
74
75 expectSame(ClassMirror a, ClassMirror b) {
76 Expect.equals(a, b);
77 expect(stringify(a), b);
78 expect(stringify(b), a);
79 }
80
81 testMixin() {
82 checkClass(Mixin, [
83 'Class(s(Mixin) in s(test.mixin_application_test), top-level)',
84 'Class(s(Object) in s(dart.core), top-level)',
85 ]);
86
87 expect(
88 '{i: Variable(s(i) in s(Mixin)),'
89 ' m: Method(s(m) in s(Mixin))}',
90 membersOf(reflectClass(Mixin)));
91
92 expect('{Mixin: Method(s(Mixin) in s(Mixin), constructor)}',
93 constructorsOf(reflectClass(Mixin)));
94 }
95
96 testMixin2() {
97 checkClass(Mixin2, [
98 'Class(s(Mixin2) in s(test.mixin_application_test), top-level)',
99 'Class(s(Object) in s(dart.core), top-level)',
100 ]);
101
102 expect(
103 '{i2: Variable(s(i2) in s(Mixin2)),'
104 ' m2: Method(s(m2) in s(Mixin2))}',
105 membersOf(reflectClass(Mixin2)));
106
107 expect('{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor)}',
108 constructorsOf(reflectClass(Mixin2)));
109 }
110
111 testMixinApplication() {
112 checkClass(MixinApplication, [
113 'Class(s(MixinApplication) in s(test.mixin_application_test), top-level)',
114 'Class(s(C) in s(test.model), top-level)',
115 'Class(s(B) in s(test.model), top-level)',
116 'Class(s(A) in s(test.model), top-level)',
117 'Class(s(Object) in s(dart.core), top-level)',
118 ]);
119
120 String owner = 'Mixin';
121 expect(
122 '{i: Variable(s(i) in s($owner)),'
123 ' m: Method(s(m) in s($owner))}',
124 membersOf(reflectClass(MixinApplication)));
125
126 expect('{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),'
127 ' constructor)}',
128 constructorsOf(reflectClass(MixinApplication)));
129
130 expectSame(reflectClass(C), reflectClass(MixinApplication).superclass);
131 }
132
133 testMixinApplicationA() {
134 String owner = ' in s(test.mixin_application_test)';
135 checkClass(MixinApplicationA, [
136 'Class(s(MixinApplicationA)'
137 ' in s(test.mixin_application_test), top-level)',
138 'Class(s(test.model.C with test.mixin_application_test.Mixin)'
139 '$owner, top-level)',
140 'Class(s(C) in s(test.model), top-level)',
141 'Class(s(B) in s(test.model), top-level)',
142 'Class(s(A) in s(test.model), top-level)',
143 'Class(s(Object) in s(dart.core), top-level)',
144 ]);
145
146 owner = 'Mixin2';
147 expect(
148 '{i2: Variable(s(i2) in s($owner)),'
149 ' m2: Method(s(m2) in s($owner))}',
150 membersOf(reflectClass(MixinApplicationA)));
151
152 expect(
153 '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),'
154 ' constructor)}',
155 constructorsOf(reflectClass(MixinApplicationA)));
156
157 expect(
158 '{i: Variable(s(i) in s(Mixin)),'
159 ' m: Method(s(m) in s(Mixin))}',
160 membersOf(reflectClass(MixinApplicationA).superclass));
161
162 String name = 'test.model.C with test.mixin_application_test.Mixin';
163 expect(
164 '{$name:'
165 ' Method(s($name)'
166 ' in s($name), constructor)}',
167 constructorsOf(reflectClass(MixinApplicationA).superclass));
168
169 expectSame(
170 reflectClass(C),
171 reflectClass(MixinApplicationA).superclass.superclass);
172 }
173
174 testUnusedMixinApplication() {
175 checkClass(UnusedMixinApplication, [
176 'Class(s(UnusedMixinApplication) in s(test.mixin_application_test),'
177 ' top-level)',
178 'Class(s(C) in s(test.model), top-level)',
179 'Class(s(B) in s(test.model), top-level)',
180 'Class(s(A) in s(test.model), top-level)',
181 'Class(s(Object) in s(dart.core), top-level)',
182 ]);
183
184 String owner = 'Mixin';
185 expect(
186 '{i: Variable(s(i) in s($owner)),'
187 ' m: Method(s(m) in s($owner))}',
188 membersOf(reflectClass(UnusedMixinApplication)));
189
190 expect(
191 '{UnusedMixinApplication: Method(s(UnusedMixinApplication)'
192 ' in s(UnusedMixinApplication), constructor)}',
193 constructorsOf(reflectClass(UnusedMixinApplication)));
194
195 expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass);
196 }
197
198 testSubclass() {
199 String owner = ' in s(test.mixin_application_test)';
200 checkClass(Subclass, [
201 'Class(s(Subclass) in s(test.mixin_application_test), top-level)',
202 'Class(s(test.model.C with test.mixin_application_test.Mixin)'
203 '$owner, 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 '{f: Method(s(f) in s(Subclass))}',
212 membersOf(reflectClass(Subclass)));
213
214 expect(
215 '{Subclass: Method(s(Subclass) in s(Subclass), constructor)}',
216 constructorsOf(reflectClass(Subclass)));
217
218 expect(
219 '{i: Variable(s(i) in s(Mixin)),'
220 ' m: Method(s(m) in s(Mixin))}',
221 membersOf(reflectClass(Subclass).superclass));
222
223 String name = 'test.model.C with test.mixin_application_test.Mixin';
224 expect(
225 '{$name:'
226 ' Method(s($name)'
227 ' in s($name), constructor)}',
228 constructorsOf(reflectClass(Subclass).superclass));
229
230 expectSame(
231 reflectClass(C),
232 reflectClass(Subclass).superclass.superclass);
233 }
234
235 testSubclass2() {
236 checkClass(Subclass2, [
237 'Class(s(Subclass2) in s(test.mixin_application_test), top-level)',
238 'Class(s(MixinApplication) in s(test.mixin_application_test), 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 '{g: Method(s(g) in s(Subclass2))}',
247 membersOf(reflectClass(Subclass2)));
248
249 expect(
250 '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor)}',
251 constructorsOf(reflectClass(Subclass2)));
252
253 expectSame(
254 reflectClass(MixinApplication),
255 reflectClass(Subclass2).superclass);
256 }
257
258 testSubclassA() {
259 String owner = ' in s(test.mixin_application_test)';
260 checkClass(SubclassA, [
261 'Class(s(SubclassA) in s(test.mixin_application_test), top-level)',
262 'Class(s(test.model.C with test.mixin_application_test.Mixin,'
263 ' test.mixin_application_test.Mixin2)$owner, top-level)',
264 'Class(s(test.model.C with test.mixin_application_test.Mixin)$owner,'
265 ' top-level)',
266 'Class(s(C) in s(test.model), top-level)',
267 'Class(s(B) in s(test.model), top-level)',
268 'Class(s(A) in s(test.model), top-level)',
269 'Class(s(Object) in s(dart.core), top-level)',
270 ]);
271
272 expect(
273 '{fa: Method(s(fa) in s(SubclassA))}',
274 membersOf(reflectClass(SubclassA)));
275
276 expect(
277 '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor)}',
278 constructorsOf(reflectClass(SubclassA)));
279
280 expect(
281 '{i2: Variable(s(i2) in s(Mixin2)),'
282 ' m2: Method(s(m2) in s(Mixin2))}',
283 membersOf(reflectClass(SubclassA).superclass));
284
285 String name =
286 'test.model.C with test.mixin_application_test.Mixin,'
287 ' test.mixin_application_test.Mixin2';
288 expect(
289 '{$name: Method(s($name) in s($name), constructor)}',
290 constructorsOf(reflectClass(SubclassA).superclass));
291
292 expect(
293 '{i: Variable(s(i) in s(Mixin)),'
294 ' m: Method(s(m) in s(Mixin))}',
295 membersOf(reflectClass(SubclassA).superclass.superclass));
296
297 name = 'test.model.C with test.mixin_application_test.Mixin';
298 expect(
299 '{$name:'
300 ' Method(s($name)'
301 ' in s($name), constructor)}',
302 constructorsOf(reflectClass(SubclassA).superclass.superclass));
303
304 expectSame(
305 reflectClass(C),
306 reflectClass(SubclassA).superclass.superclass.superclass);
307 }
308
309 testSubclass2A() {
310 String owner = ' in s(test.mixin_application_test)';
311 checkClass(Subclass2A, [
312 'Class(s(Subclass2A) in s(test.mixin_application_test), top-level)',
313 'Class(s(MixinApplicationA) in s(test.mixin_application_test),'
314 ' top-level)',
315 'Class(s(test.model.C with test.mixin_application_test.Mixin)$owner,'
316 ' top-level)',
317 'Class(s(C) in s(test.model), top-level)',
318 'Class(s(B) in s(test.model), top-level)',
319 'Class(s(A) in s(test.model), top-level)',
320 'Class(s(Object) in s(dart.core), top-level)',
321 ]);
322
323 expect(
324 '{ga: Method(s(ga) in s(Subclass2A))}',
325 membersOf(reflectClass(Subclass2A)));
326
327 expect(
328 '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor)}',
329 constructorsOf(reflectClass(Subclass2A)));
330
331 expectSame(reflectClass(MixinApplicationA),
332 reflectClass(Subclass2A).superclass);
333 }
334
335 main() {
336 testMixin();
337 testMixin2();
338 testMixinApplication();
339 testMixinApplicationA();
340 testUnusedMixinApplication();
341 testSubclass();
342 testSubclass2();
343 testSubclassA();
344 testSubclass2A();
345 }
OLDNEW
« no previous file with comments | « test/codegen/lib/mirrors/mirrors_visitor.dart ('k') | test/codegen/lib/mirrors/mixin_members_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698