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

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