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

Side by Side Diff: tests/compiler/dart2js/mirrors_test.dart

Issue 10692040: Mirrors prototype added to dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: dart2js_mirror.dart included in the cl Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 #import("../../../lib/dartdoc/mirrors/mirrors.dart");
6
7 #import('dart:io');
8
9 find(Map<Object,Mirror> map, String name, [String constructorName, String operat orName]) {
Lasse Reichstein Nielsen 2012/07/02 11:48:53 Line too long. Do give it a return type, since it
Johnni Winther 2012/07/03 07:38:50 Done.
10 var mirror = null;
11 map.forEach((_,m) {
12 bool found = false;
13 if (m.simpleName() == name) {
14 found = true;
15 if (constructorName !== null && m is MethodMirror) {
16 if (constructorName != m.constructorName) {
17 found = false;
18 }
19 }
20 if (operatorName !== null && m is MethodMirror) {
21 if (operatorName != m.operatorName) {
22 found = false;
23 }
24 }
25 }
26 if (found) {
27 mirror = m;
28 }
29 });
30 return mirror;
31 }
32
33 int count(Iterable iterable) {
34 var count = 0;
35 for (var element in iterable) {
36 count++;
37 }
38 return count;
39 }
40
41 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) {
42 for (var element in iterable) {
43 if (element.declaration == expected.declaration) {
44 return true;
45 }
46 }
47 return false;
48 }
49
50 main() {
51 var scriptPath = new Path.fromNative(new Options().script);
52 var dirPath = scriptPath.directoryPath;
53 var libPath = dirPath.join(new Path.fromNative('../../../'));
54 var inputPath = dirPath.join(new Path.fromNative('mirrors_helper.dart'));
55 var compilation = new Compilation(inputPath.toNativePath(),
56 libPath.toNativePath());
57 Expect.isNotNull(compilation, "No compilation created");
58
59 var mirrors = compilation.mirrors();
60 Expect.isNotNull(mirrors, "No mirror system returned from compilation");
61
62 var libraries = mirrors.libraries();
63 Expect.isNotNull(libraries, "No libraries map returned");
64 Expect.isFalse(libraries.isEmpty(), "Empty libraries map returned");
65
66 var helperLibrary = find(libraries, "mirrors_helper");
67 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found");
68 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName(),
69 "Unexpected library simple name");
70 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName(),
71 "Unexpected library qualified name");
72
73 var types = helperLibrary.types();
74 Expect.isNotNull(types, "No types map returned");
75 Expect.isFalse(types.isEmpty(), "Empty types map returned");
76
77 testFoo(helperLibrary, types);
78 testBar(helperLibrary, types);
79 testBaz(helperLibrary, types);
80 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func].
81 // TODO(johnniwinther): Add tests of type argument substitution, which
82 // is not currently implemented in dart2js.
83 // TODO(johnniwinther): Add tests of Location and Source.
84 }
85
86 // Testing class Foo:
87 //
88 // class Foo {
89 //
90 // }
91 void testFoo(LibraryMirror helperLibrary, Map<Object,TypeMirror> types) {
92 var fooClass = find(types, "Foo");
93 Expect.isNotNull(fooClass, "Type 'Foo' not found");
94 Expect.isTrue(fooClass is InterfaceMirror,
95 "Unexpected mirror type returned");
96 Expect.stringEquals("Foo", fooClass.simpleName(),
97 "Unexpected type simple name");
98 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName(),
99 "Unexpected type qualified name");
100
101 Expect.equals(helperLibrary, fooClass.library(),
102 "Unexpected library returned from type");
103
104 Expect.isFalse(fooClass.isObject, "Class is Object");
105 Expect.isFalse(fooClass.isDynamic, "Class is Dynamic");
106 Expect.isFalse(fooClass.isVoid, "Class is void");
107 Expect.isFalse(fooClass.isTypeVariable, "Class is a type variable");
108 Expect.isFalse(fooClass.isTypedef, "Class is a typedef");
109 Expect.isFalse(fooClass.isFunction, "Class is a function");
110
111 Expect.isTrue(fooClass.isDeclaration, "Class is not declaration");
112 Expect.equals(fooClass, fooClass.declaration,
113 "Class is not its declaration");
114
115 Expect.isTrue(fooClass.isClass, "Class is not class");
116 Expect.isFalse(fooClass.isInterface, "Class is interface");
117 Expect.isFalse(fooClass.isPrivate, "Class is private");
118
119 var objectType = fooClass.superclass();
120 Expect.isNotNull(objectType, "Superclass is null");
121 Expect.isTrue(objectType.isObject, "Object is not Object");
122 Expect.isFalse(objectType.isDeclaration, "Object type is declaration");
123 Expect.isTrue(containsType(fooClass, objectType.computeSubdeclarations()),
124 "Class is not subclass of superclass");
125
126 var fooInterfaces = fooClass.interfaces();
127 Expect.isNotNull(fooInterfaces, "Interfaces map is null");
128 Expect.isTrue(fooInterfaces.isEmpty(), "Interfaces map is not empty");
129
130 var fooSubdeclarations = fooClass.computeSubdeclarations();
131 Expect.equals(1, count(fooSubdeclarations), "Unexpected subtype count");
132 for (var fooSubdeclaration in fooSubdeclarations) {
133 Expect.equals(fooClass, fooSubdeclaration.superclass().declaration,
134 "Class is not superclass of subclass");
135 }
136
137 Expect.throws(() => fooClass.typeArguments(),
138 (exception) => true,
139 "Class has type arguments");
140 var fooClassTypeVariables = fooClass.typeVariables();
141 Expect.isNotNull(fooClassTypeVariables, "Type variable list is null");
142 Expect.isTrue(fooClassTypeVariables.isEmpty(),
143 "Type variable list is not empty");
144
145 Expect.isNull(fooClass.defaultType(), "Class has default type");
146
147 var fooClassMembers = fooClass.declaredMembers();
148 Expect.isNotNull(fooClassMembers, "Declared members map is null");
149 Expect.isTrue(fooClassMembers.isEmpty(), "Declared members map is unempty");
150
151 var fooClassConstructors = fooClass.constructors();
152 Expect.isNotNull(fooClassConstructors, "Constructors map is null");
153 Expect.isTrue(fooClassConstructors.isEmpty(),
154 "Constructors map is unempty");
155 }
156
157 // Testing interface Bar:
158 //
159 // interface Bar<E> {
160 //
161 // }
162 void testBar(LibraryMirror helperLibrary, Map<Object,TypeMirror> types) {
163 var barInterface = find(types, "Bar");
164 Expect.isNotNull(barInterface, "Type 'Bar' not found");
165 Expect.isTrue(barInterface is InterfaceMirror,
166 "Unexpected mirror type returned");
167 Expect.stringEquals("Bar", barInterface.simpleName(),
168 "Unexpected type simple name");
169 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName(),
170 "Unexpected type qualified name");
171
172 Expect.equals(helperLibrary, barInterface.library(),
173 "Unexpected library returned from type");
174
175 Expect.isFalse(barInterface.isObject, "Interface is Object");
176 Expect.isFalse(barInterface.isDynamic, "Interface is Dynamic");
177 Expect.isFalse(barInterface.isVoid, "Interface is void");
178 Expect.isFalse(barInterface.isTypeVariable, "Interface is a type variable");
179 Expect.isFalse(barInterface.isTypedef, "Interface is a typedef");
180 Expect.isFalse(barInterface.isFunction, "Interface is a function");
181
182 Expect.isTrue(barInterface.isDeclaration, "Interface is not declaration");
183 Expect.equals(barInterface, barInterface.declaration,
184 "Interface is not its declaration");
185
186 Expect.isFalse(barInterface.isClass, "Interface is class");
187 Expect.isTrue(barInterface.isInterface, "Interface is not interface");
188 Expect.isFalse(barInterface.isPrivate, "Interface is private");
189
190 var objectType = barInterface.superclass();
191 Expect.isNotNull(objectType, "Superclass is null");
192 Expect.isTrue(objectType.isObject, "Object is not Object");
193 Expect.isFalse(objectType.isDeclaration, "Object type is declaration");
194 Expect.isTrue(containsType(barInterface,
195 objectType.computeSubdeclarations()),
196 "Class is not subclass of superclass");
197
198 var barInterfaces = barInterface.interfaces();
199 Expect.isNotNull(barInterfaces, "Interfaces map is null");
200 Expect.isTrue(barInterfaces.isEmpty(), "Interfaces map is not empty");
201
202 var barSubdeclarations = barInterface.computeSubdeclarations();
203 Expect.equals(1, count(barSubdeclarations), "Unexpected subtype count");
204 for (var barSubdeclaration in barSubdeclarations) {
205 Expect.isTrue(containsType(barInterface,
206 barSubdeclaration.interfaces().getValues()),
207 "Interface is not superinterface of subclass");
208 }
209
210 Expect.throws(() => barInterface.typeArguments(),
211 (exception) => true,
212 "Interface has type arguments");
213 var barInterfaceTypeVariables = barInterface.typeVariables();
214 Expect.isNotNull(barInterfaceTypeVariables, "Type variable list is null");
215 Expect.isFalse(barInterfaceTypeVariables.isEmpty(),
216 "Type variable list is empty");
217 Expect.equals(barInterfaceTypeVariables.length, 1,
218 "Unexpected number of type variables");
219
220 var barE = barInterfaceTypeVariables[0];
221 Expect.isNotNull(barE, "Type variable is null");
222 Expect.isTrue(barE.isTypeVariable, "Type variable is not type variable");
223
224 Expect.isNull(barInterface.defaultType(), "Interface has default type");
225
226 var barInterfaceMembers = barInterface.declaredMembers();
227 Expect.isNotNull(barInterfaceMembers, "Declared members map is null");
228 Expect.isTrue(barInterfaceMembers.isEmpty(),
229 "Declared members map is unempty");
230
231 var barInterfaceConstructors = barInterface.constructors();
232 Expect.isNotNull(barInterfaceConstructors, "Constructors map is null");
233 Expect.isTrue(barInterfaceConstructors.isEmpty(),
234 "Constructors map is unempty");
235 }
236
237 // Testing class Baz:
238 //
239 // class Baz<E,F extends Foo> implements Bar<E> {
240 // Baz();
241 // const Baz.named();
242 // factory Baz.factory();
243 //
244 // method1(e) {}
245 // static void method2(E e, [F f = null]) {}
246 // void method3(E func1(F f), Func<E,F> func2) {}
247 //
248 // bool operator==(Object other) => return false;
249 // Baz<E,F> operator negate() => this;
250 // }
251 void testBaz(LibraryMirror helperLibrary, Map<Object,TypeMirror> types) {
252 var bazClass = find(types, "Baz");
253 Expect.isNotNull(bazClass, "Type 'Baz' not found");
254 Expect.isTrue(bazClass is InterfaceMirror,
255 "Unexpected mirror type returned");
256 Expect.stringEquals("Baz", bazClass.simpleName(),
257 "Unexpected type simple name");
258 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName(),
259 "Unexpected type qualified name");
260
261 Expect.equals(helperLibrary, bazClass.library(),
262 "Unexpected library returned from type");
263
264 Expect.isFalse(bazClass.isObject, "Class is Object");
265 Expect.isFalse(bazClass.isDynamic, "Class is Dynamic");
266 Expect.isFalse(bazClass.isVoid, "Class is void");
267 Expect.isFalse(bazClass.isTypeVariable, "Class is a type variable");
268 Expect.isFalse(bazClass.isTypedef, "Class is a typedef");
269 Expect.isFalse(bazClass.isFunction, "Class is a function");
270
271 Expect.isTrue(bazClass.isDeclaration, "Class is not declaration");
272 Expect.equals(bazClass, bazClass.declaration,
273 "Class is not its declaration");
274
275 Expect.isTrue(bazClass.isClass, "Class is not class");
276 Expect.isFalse(bazClass.isInterface, "Class is interface");
277 Expect.isFalse(bazClass.isPrivate, "Class is private");
278
279 var objectType = bazClass.superclass();
280 Expect.isNotNull(objectType, "Superclass is null");
281 Expect.isTrue(objectType.isObject, "Object is not Object");
282 Expect.isFalse(objectType.isDeclaration, "Object type is declaration");
283 Expect.isTrue(containsType(bazClass, objectType.computeSubdeclarations()),
284 "Class is not subclass of superclass");
285
286 var bazInterfaces = bazClass.interfaces();
287 Expect.isNotNull(bazInterfaces, "Interfaces map is null");
288 Expect.isTrue(!bazInterfaces.isEmpty(), "Interfaces map is empty");
289 for (var bazInterface in bazInterfaces.getValues()) {
290 Expect.isTrue(containsType(bazClass,
291 objectType.computeSubdeclarations()),
292 "Class is not subclass of superinterface");
293 }
294
295 var bazSubdeclarations = bazClass.computeSubdeclarations();
296 Expect.equals(0, count(bazSubdeclarations), "Unexpected subtype count");
297
298 var barInterface = find(bazInterfaces, "Bar");
299 Expect.isNotNull(barInterface, "Interface bar is missing");
300 Expect.isFalse(barInterface.isDeclaration, "Interface type is declaration");
301 var barInterfaceTypeArguments = barInterface.typeArguments();
302 Expect.isNotNull(barInterfaceTypeArguments, "Type arguments are missing");
303 // TODO(johnniwinther): Ensure type arguments on supertypes. Expected result
304 // should have been 1:
305 Expect.equals(0, barInterfaceTypeArguments.length,
306 "Type arguments is empty");
307
308 Expect.throws(() => bazClass.typeArguments(),
309 (exception) => true,
310 "Class has type arguments");
311 var bazClassTypeVariables = bazClass.typeVariables();
312 Expect.isNotNull(bazClassTypeVariables, "Type variable list is null");
313 Expect.equals(2, bazClassTypeVariables.length,
314 "Type variable list is not empty");
315
316 var bazE = bazClassTypeVariables[0];
317 Expect.isNotNull(bazE, "Type variable is null");
318 Expect.stringEquals('E', bazE.simpleName(), "Unexpected simpleName");
319 Expect.stringEquals('mirrors_helper.Baz.E', bazE.qualifiedName(),
320 "Unexpected qualifiedName");
321 Expect.equals(bazClass, bazE.declarer(),
322 "Unexpected type variable declarer");
323 var bazEbound = bazE.bound();
324 Expect.isNotNull(bazEbound, "Missing type variable bound");
325 Expect.isFalse(bazEbound.isDeclaration, "Bound is declaration");
326 Expect.isTrue(bazEbound.isObject, "Bound is not object");
327
328 var bazF = bazClassTypeVariables[1];
329 Expect.isNotNull(bazF, "Type variable is null");
330 Expect.stringEquals('F', bazF.simpleName(), "Unexpected simpleName");
331 Expect.stringEquals('mirrors_helper.Baz.F', bazF.qualifiedName(),
332 "Unexpected qualifiedName");
333 Expect.equals(bazClass, bazF.declarer());
334 var bazFbound = bazF.bound();
335 Expect.isNotNull(bazFbound, "Missing type variable bound");
336 Expect.isFalse(bazFbound.isDeclaration, "Bound is declaration");
337 Expect.stringEquals("mirrors_helper.Foo", bazFbound.qualifiedName(),
338 "Bound is not Foo");
339
340 Expect.isNull(bazClass.defaultType(), "Class has default type");
341
342 var bazClassMembers = bazClass.declaredMembers();
343 Expect.isNotNull(bazClassMembers, "Declared members map is null");
344 Expect.equals(8, bazClassMembers.length,
345 "Unexpected number of declared members");
346
347 ////////////////////////////////////////////////////////////////////////////
348 // method1(e) {}
349 ////////////////////////////////////////////////////////////////////////////
350 var method1 = find(bazClassMembers, "method1");
351 Expect.isNotNull(method1, "method1 not found");
352 Expect.stringEquals('method1', method1.simpleName(),
353 "Unexpected method simpleName");
354 Expect.stringEquals('mirrors_helper.Baz.method1', method1.qualifiedName(),
355 "Unexpected method qualifiedName");
356 Expect.equals(method1.surroundingDeclaration(), bazClass,
357 "Unexpected surrounding declaration");
358 Expect.isFalse(method1.isTopLevel, "Method is top level");
359 Expect.isFalse(method1.isConstructor, "Method is constructor");
360 Expect.isFalse(method1.isField, "Method is field");
361 Expect.isTrue(method1.isMethod, "Method is not method");
362 Expect.isFalse(method1.isPrivate, "Method is private");
363 Expect.isFalse(method1.isStatic, "Method is static");
364 Expect.isTrue(method1 is MethodMirror, "Method is not MethodMirror");
365 Expect.isFalse(method1.isConst, "Method is const");
366 Expect.isFalse(method1.isFactory, "Method is factory");
367 Expect.isNull(method1.constructorName,
368 "Method constructorName is non-null");
369 Expect.isFalse(method1.isGetter, "Method is getter");
370 Expect.isFalse(method1.isSetter, "Method is setter");
371 Expect.isFalse(method1.isOperator, "Method is operator");
372 Expect.isNull(method1.operatorName,
373 "Method operatorName is non-null");
374
375 var dynamicType = method1.returnType();
376 Expect.isNotNull(dynamicType, "Return type was null");
377 Expect.isFalse(dynamicType.isObject, "Dynamic is Object");
378 Expect.isTrue(dynamicType.isDynamic, "Dynamic is not Dynamic");
379 Expect.isFalse(dynamicType.isVoid, "Dynamic is void");
380 Expect.isFalse(dynamicType.isTypeVariable, "Dynamic is a type variable");
381 Expect.isFalse(dynamicType.isTypedef, "Dynamic is a typedef");
382 Expect.isFalse(dynamicType.isFunction, "Dynamic is a function");
383
384 var method1Parameters = method1.parameters();
385 Expect.isNotNull(method1Parameters, "Method parameters is null");
386 Expect.equals(1, method1Parameters.length, "Unexpected parameter count");
387 var method1Parameter1 = method1Parameters[0];
388 Expect.isNotNull(method1Parameter1, "Parameter is null");
389 Expect.equals(dynamicType, method1Parameter1.type());
390 Expect.stringEquals("e", method1Parameter1.simpleName(),
391 "Unexpected parameter simpleName");
392 Expect.stringEquals("mirrors_helper.Baz.method1#e",
393 method1Parameter1.qualifiedName(),
394 "Unexpected parameter qualifiedName");
395 Expect.isFalse(method1Parameter1.hasDefaultValue(),
396 "Parameter has default value");
397 Expect.isNull(method1Parameter1.defaultValue(),
398 "Parameter default value is non-null");
399 Expect.isFalse(method1Parameter1.isOptional(), "Parameter is optional");
400
401 ////////////////////////////////////////////////////////////////////////////
402 // static void method2(E e, [F f = null]) {}
403 ////////////////////////////////////////////////////////////////////////////
404 var method2 = find(bazClassMembers, "method2");
405 Expect.isNotNull(method2, "method2 not found");
406 Expect.stringEquals('method2', method2.simpleName(),
407 "Unexpected method simpleName");
408 Expect.stringEquals('mirrors_helper.Baz.method2', method2.qualifiedName(),
409 "Unexpected method qualifiedName");
410 Expect.equals(method2.surroundingDeclaration(), bazClass,
411 "Unexpected surrounding declaration");
412 Expect.isFalse(method2.isTopLevel, "Method is top level");
413 Expect.isFalse(method2.isConstructor, "Method is constructor");
414 Expect.isFalse(method2.isField, "Method is field");
415 Expect.isTrue(method2.isMethod, "Method is not method");
416 Expect.isFalse(method2.isPrivate, "Method is private");
417 Expect.isTrue(method2.isStatic, "Method is not static");
418 Expect.isTrue(method2 is MethodMirror, "Method is not MethodMirror");
419 Expect.isFalse(method2.isConst, "Method is const");
420 Expect.isFalse(method2.isFactory, "Method is factory");
421 Expect.isNull(method2.constructorName,
422 "Method constructorName is non-null");
423 Expect.isFalse(method2.isGetter, "Method is getter");
424 Expect.isFalse(method2.isSetter, "Method is setter");
425 Expect.isFalse(method2.isOperator, "Method is operator");
426 Expect.isNull(method2.operatorName,
427 "Method operatorName is non-null");
428
429 var voidType = method2.returnType();
430 Expect.isNotNull(voidType, "Return type was null");
431 Expect.isFalse(voidType.isObject, "void is Object");
432 Expect.isFalse(voidType.isDynamic, "void is Dynamic");
433 Expect.isTrue(voidType.isVoid, "void is not void");
434 Expect.isFalse(voidType.isTypeVariable, "void is a type variable");
435 Expect.isFalse(voidType.isTypedef, "void is a typedef");
436 Expect.isFalse(voidType.isFunction, "void is a function");
437
438 var method2Parameters = method2.parameters();
439 Expect.isNotNull(method2Parameters, "Method parameters is null");
440 Expect.equals(2, method2Parameters.length, "Unexpected parameter count");
441 var method2Parameter1 = method2Parameters[0];
442 Expect.isNotNull(method2Parameter1, "Parameter is null");
443 Expect.equals(bazE, method2Parameter1.type());
444 Expect.stringEquals("e", method2Parameter1.simpleName(),
445 "Unexpected parameter simpleName");
446 Expect.stringEquals("mirrors_helper.Baz.method2#e",
447 method2Parameter1.qualifiedName(),
448 "Unexpected parameter qualifiedName");
449 Expect.isFalse(method2Parameter1.hasDefaultValue(),
450 "Parameter has default value");
451 Expect.isNull(method2Parameter1.defaultValue(),
452 "Parameter default value is non-null");
453 Expect.isFalse(method2Parameter1.isOptional(), "Parameter is optional");
454 var method2Parameter2 = method2Parameters[1];
455 Expect.isNotNull(method2Parameter2, "Parameter is null");
456 Expect.equals(bazF, method2Parameter2.type());
457 Expect.stringEquals("f", method2Parameter2.simpleName(),
458 "Unexpected parameter simpleName");
459 Expect.stringEquals("mirrors_helper.Baz.method2#f",
460 method2Parameter2.qualifiedName(),
461 "Unexpected parameter qualifiedName");
462 // TODO(johnniwinther): Should return true:
463 Expect.isFalse(method2Parameter2.hasDefaultValue(),
464 "Parameter has default value");
465 // TODO(johnniwinther): Should return a non-null value:
466 Expect.isNull(method2Parameter2.defaultValue(),
467 "Parameter default value is non-null");
468 Expect.isTrue(method2Parameter2.isOptional(), "Parameter is not optional");
469
470 ////////////////////////////////////////////////////////////////////////////
471 // void method3(E func1(F f), Func<E,F> func2) {}
472 ////////////////////////////////////////////////////////////////////////////
473 var method3 = find(bazClassMembers, "method3");
474 Expect.isNotNull(method3, "method3 not found");
475 Expect.stringEquals('method3', method3.simpleName(),
476 "Unexpected method simpleName");
477 Expect.stringEquals('mirrors_helper.Baz.method3', method3.qualifiedName(),
478 "Unexpected method qualifiedName");
479 Expect.equals(method3.surroundingDeclaration(), bazClass,
480 "Unexpected surrounding declaration");
481 Expect.isFalse(method3.isTopLevel, "Method is top level");
482 Expect.isFalse(method3.isConstructor, "Method is constructor");
483 Expect.isFalse(method3.isField, "Method is field");
484 Expect.isTrue(method3.isMethod, "Method is not method");
485 Expect.isFalse(method3.isPrivate, "Method is private");
486 Expect.isFalse(method3.isStatic, "Method is static");
487 Expect.isTrue(method3 is MethodMirror, "Method is not MethodMirror");
488 Expect.isFalse(method3.isConst, "Method is const");
489 Expect.isFalse(method3.isFactory, "Method is factory");
490 Expect.isNull(method3.constructorName,
491 "Method constructorName is non-null");
492 Expect.isFalse(method3.isGetter, "Method is getter");
493 Expect.isFalse(method3.isSetter, "Method is setter");
494 Expect.isFalse(method3.isOperator, "Method is operator");
495 Expect.isNull(method3.operatorName,
496 "Method operatorName is non-null");
497
498 Expect.equals(voidType, method3.returnType(), "Return type is not void");
499
500 var method3Parameters = method3.parameters();
501 Expect.isNotNull(method3Parameters, "Method parameters is null");
502 Expect.equals(2, method3Parameters.length, "Unexpected parameter count");
503 var method3Parameter1 = method3Parameters[0];
504 Expect.isNotNull(method3Parameter1, "Parameter is null");
505 // TODO(johnniwinther): Should return the function type E func(F f):
506 Expect.equals(dynamicType, method3Parameter1.type());
507 Expect.stringEquals("func1", method3Parameter1.simpleName(),
508 "Unexpected parameter simpleName");
509 Expect.stringEquals("mirrors_helper.Baz.method3#func1",
510 method3Parameter1.qualifiedName(),
511 "Unexpected parameter qualifiedName");
512 Expect.isFalse(method3Parameter1.hasDefaultValue(),
513 "Parameter has default value");
514 Expect.isNull(method3Parameter1.defaultValue(),
515 "Parameter default value is non-null");
516 Expect.isFalse(method3Parameter1.isOptional(), "Parameter is optional");
517
518 var method3Parameter2 = method3Parameters[1];
519 Expect.isNotNull(method3Parameter2, "Parameter is null");
520 var funcTypedef = method3Parameter2.type();
521 Expect.isNotNull(funcTypedef, "Parameter type is null");
522 Expect.stringEquals("Func", funcTypedef.simpleName(),
523 "Unexpected simpleName");
524 Expect.stringEquals("mirrors_helper.Func", funcTypedef.qualifiedName(),
525 "Unexpected simpleName");
526 Expect.isFalse(funcTypedef.isObject, "Typedef is Object");
527 Expect.isFalse(funcTypedef.isDynamic, "Typedef is Dynamic");
528 Expect.isFalse(funcTypedef.isVoid, "Typedef is void");
529 Expect.isFalse(funcTypedef.isTypeVariable, "Typedef is a type variable");
530 Expect.isTrue(funcTypedef.isTypedef, "Typedef is not a typedef");
531 Expect.isFalse(funcTypedef.isFunction, "Typedef is a function");
532
533 Expect.equals(helperLibrary, funcTypedef.library(),
534 "Unexpected typedef library");
535 Expect.isNull(funcTypedef.superclass(), "Non-null superclass on typedef");
536 Expect.isNotNull(funcTypedef.interfaces(),
537 "Null interfaces map on typedef");
538 Expect.isTrue(funcTypedef.interfaces().isEmpty(),
539 "Non-empty interfaces map on typedef");
540 Expect.isNotNull(funcTypedef.declaredMembers(),
541 "Declared members map is null on type def");
542 Expect.isTrue(funcTypedef.declaredMembers().isEmpty(),
543 "Non-empty declared members map on typedef");
544
545 // TODO(johnniwinther): Returned typedef should not be the declaration:
546 Expect.isTrue(funcTypedef.isDeclaration, "Typedef is not declaration");
547 Expect.isFalse(funcTypedef.isClass, "Typedef is class");
548 Expect.isFalse(funcTypedef.isInterface, "Typedef is interface");
549 Expect.isFalse(funcTypedef.isPrivate, "Typedef is private");
550 Expect.isNull(funcTypedef.defaultType(),
551 "Typedef default type is non-null");
552 // TODO(johnniwinther): Should not throw an exception since the type should
553 // not be the declaration.
554 Expect.throws(() => funcTypedef.typeArguments(),
555 (exception) => true,
556 "Typedef has type arguments");
557 Expect.isNotNull(funcTypedef.typeVariables(), "Type variables is null");
558 // TODO(johnniwinther): Should return a non-empty map.
559 Expect.isTrue(funcTypedef.typeVariables().isEmpty(),
560 "Type variables is non-empty");
561 // TODO(johnniwinther): Provide access to the definition type.
562 Expect.isNull(funcTypedef.definition(), "Typedef definition is not null");
563
564 Expect.stringEquals("func2", method3Parameter2.simpleName(),
565 "Unexpected parameter simpleName");
566 Expect.stringEquals("mirrors_helper.Baz.method3#func2",
567 method3Parameter2.qualifiedName(),
568 "Unexpected parameter qualifiedName");
569 Expect.isFalse(method3Parameter2.hasDefaultValue(),
570 "Parameter has default value");
571 Expect.isNull(method3Parameter2.defaultValue(),
572 "Parameter default value is non-null");
573 Expect.isFalse(method3Parameter2.isOptional(), "Parameter is optional");
574
575 ////////////////////////////////////////////////////////////////////////////
576 // bool operator==(Object other) => return false;
577 ////////////////////////////////////////////////////////////////////////////
578 var operator_eq = find(bazClassMembers, "operator", operatorName: '==');
579 Expect.isNotNull(operator_eq, "operator == not found");
580 Expect.stringEquals('operator', operator_eq.simpleName(),
581 "Unexpected method simpleName");
582 Expect.stringEquals('mirrors_helper.Baz.operator ==',
583 operator_eq.qualifiedName(),
584 "Unexpected method qualifiedName");
585 Expect.equals(operator_eq.surroundingDeclaration(), bazClass,
586 "Unexpected surrounding declaration");
587 Expect.isFalse(operator_eq.isTopLevel, "Method is top level");
588 Expect.isFalse(operator_eq.isConstructor, "Method is constructor");
589 Expect.isFalse(operator_eq.isField, "Method is field");
590 Expect.isTrue(operator_eq.isMethod, "Method is not method");
591 Expect.isFalse(operator_eq.isPrivate, "Method is private");
592 Expect.isFalse(operator_eq.isStatic, "Method is static");
593 Expect.isTrue(operator_eq is MethodMirror, "Method is not MethodMirror");
594 Expect.isFalse(operator_eq.isConst, "Method is const");
595 Expect.isFalse(operator_eq.isFactory, "Method is factory");
596 Expect.isNull(operator_eq.constructorName,
597 "Method constructorName is non-null");
598 Expect.isFalse(operator_eq.isGetter, "Method is getter");
599 Expect.isFalse(operator_eq.isSetter, "Method is setter");
600 Expect.isTrue(operator_eq.isOperator, "Method is not operator");
601 Expect.stringEquals('==', operator_eq.operatorName,
602 "Unexpected operatorName");
603
604 ////////////////////////////////////////////////////////////////////////////
605 // Baz<E,F> operator negate() => this;
606 ////////////////////////////////////////////////////////////////////////////
607 var operator_negate = find(bazClassMembers, "operator",
608 operatorName: 'negate');
609 Expect.isNotNull(operator_negate, "operator < not found");
610 Expect.stringEquals('operator', operator_negate.simpleName(),
611 "Unexpected method simpleName");
612 Expect.stringEquals('mirrors_helper.Baz.operator negate',
613 operator_negate.qualifiedName(),
614 "Unexpected method qualifiedName");
615 Expect.equals(operator_negate.surroundingDeclaration(), bazClass,
616 "Unexpected surrounding declaration");
617 Expect.isFalse(operator_negate.isTopLevel, "Method is top level");
618 Expect.isFalse(operator_negate.isConstructor, "Method is constructor");
619 Expect.isFalse(operator_negate.isField, "Method is field");
620 Expect.isTrue(operator_negate.isMethod, "Method is not method");
621 Expect.isFalse(operator_negate.isPrivate, "Method is private");
622 Expect.isFalse(operator_negate.isStatic, "Method is static");
623 Expect.isTrue(operator_negate is MethodMirror,
624 "Method is not MethodMirror");
625 Expect.isFalse(operator_negate.isConst, "Method is const");
626 Expect.isFalse(operator_negate.isFactory, "Method is factory");
627 Expect.isNull(operator_negate.constructorName,
628 "Method constructorName is non-null");
629 Expect.isFalse(operator_negate.isGetter, "Method is getter");
630 Expect.isFalse(operator_negate.isSetter, "Method is setter");
631 Expect.isTrue(operator_negate.isOperator, "Method is not operator");
632 Expect.stringEquals('negate', operator_negate.operatorName,
633 "Unexpected operatorName");
634
635
636 var bazClassConstructors = bazClass.constructors();
637 Expect.isNotNull(bazClassConstructors, "Constructors map is null");
638 Expect.equals(3, bazClassConstructors.length,
639 "Unexpected number of constructors");
640 // TODO(johnniwinther): Add tests of constructors.
641 }
OLDNEW
« tests/compiler/dart2js/mirrors_helper.dart ('K') | « tests/compiler/dart2js/mirrors_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698