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

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

Issue 11014022: Make Mirror.simpleName unique. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 #import("../../../pkg/dartdoc/lib/mirrors.dart"); 5 #import("../../../pkg/dartdoc/lib/mirrors.dart");
6 #import("../../../pkg/dartdoc/lib/mirrors_util.dart"); 6 #import("../../../pkg/dartdoc/lib/mirrors_util.dart");
7 7
8 #import('dart:io'); 8 #import('dart:io');
9 9
10 int count(Iterable iterable) { 10 int count(Iterable iterable) {
11 var count = 0; 11 var count = 0;
12 for (var element in iterable) { 12 for (var element in iterable) {
13 count++; 13 count++;
14 } 14 }
15 return count; 15 return count;
16 } 16 }
17 17
18 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) { 18 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) {
19 for (var element in iterable) { 19 for (var element in iterable) {
20 if (element.declaration == expected.declaration) { 20 if (element.declaration == expected.declaration) {
21 return true; 21 return true;
22 } 22 }
23 } 23 }
24 return false; 24 return false;
25 } 25 }
26 26
27 Mirror findMirror(List<Mirror> list, String name) {
28 var foundMirror = null;
29 list.forEach((Mirror mirror) {
30 if (mirror.simpleName == name) {
31 foundMirror = mirror;
ngeoffray 2012/10/02 20:19:43 Can it have duplicates and then you take the last
Johnni Winther 2012/10/03 09:36:24 Done.
32 }
33 });
34 return foundMirror;
35 }
36
27 main() { 37 main() {
28 var scriptPath = new Path.fromNative(new Options().script); 38 var scriptPath = new Path.fromNative(new Options().script);
29 var dirPath = scriptPath.directoryPath; 39 var dirPath = scriptPath.directoryPath;
30 var libPath = dirPath.join(new Path.fromNative('../../../')); 40 var libPath = dirPath.join(new Path.fromNative('../../../'));
31 var inputPath = dirPath.join(new Path.fromNative('mirrors_helper.dart')); 41 var inputPath = dirPath.join(new Path.fromNative('mirrors_helper.dart'));
32 var compilation = new Compilation.library([inputPath], libPath); 42 var compilation = new Compilation.library([inputPath], libPath);
33 Expect.isNotNull(compilation, "No compilation created"); 43 Expect.isNotNull(compilation, "No compilation created");
34 44
35 var mirrors = compilation.mirrors; 45 var mirrors = compilation.mirrors;
36 Expect.isNotNull(mirrors, "No mirror system returned from compilation"); 46 Expect.isNotNull(mirrors, "No mirror system returned from compilation");
37 47
38 var libraries = mirrors.libraries; 48 var libraries = mirrors.libraries;
39 Expect.isNotNull(libraries, "No libraries map returned"); 49 Expect.isNotNull(libraries, "No libraries map returned");
40 Expect.isFalse(libraries.isEmpty(), "Empty libraries map returned"); 50 Expect.isFalse(libraries.isEmpty(), "Empty libraries map returned");
41 51
42 var helperLibrary = findMirror(libraries, "mirrors_helper"); 52 var helperLibrary = libraries["mirrors_helper"];
43 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); 53 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found");
44 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName, 54 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName,
45 "Unexpected library simple name"); 55 "Unexpected library simple name");
46 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName, 56 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName,
47 "Unexpected library qualified name"); 57 "Unexpected library qualified name");
48 58
49 var types = helperLibrary.types; 59 var types = helperLibrary.types;
50 Expect.isNotNull(types, "No types map returned"); 60 Expect.isNotNull(types, "No types map returned");
51 Expect.isFalse(types.isEmpty(), "Empty types map returned"); 61 Expect.isFalse(types.isEmpty(), "Empty types map returned");
52 62
53 testFoo(mirrors, helperLibrary, types); 63 testFoo(mirrors, helperLibrary, types);
54 testBar(mirrors, helperLibrary, types); 64 testBar(mirrors, helperLibrary, types);
55 testBaz(mirrors, helperLibrary, types); 65 testBaz(mirrors, helperLibrary, types);
56 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func]. 66 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func].
57 // TODO(johnniwinther): Add tests of type argument substitution, which 67 // TODO(johnniwinther): Add tests of type argument substitution, which
58 // is not currently implemented in dart2js. 68 // is not currently implemented in dart2js.
59 // TODO(johnniwinther): Add tests of Location and Source. 69 // TODO(johnniwinther): Add tests of Location and Source.
60 } 70 }
61 71
62 // Testing class Foo: 72 // Testing class Foo:
63 // 73 //
64 // class Foo { 74 // class Foo {
65 // 75 //
66 // } 76 // }
67 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, 77 void testFoo(MirrorSystem system, LibraryMirror helperLibrary,
68 Map<Object,TypeMirror> types) { 78 Map<Object,TypeMirror> types) {
69 var fooClass = findMirror(types, "Foo"); 79 var fooClass = types["Foo"];
70 Expect.isNotNull(fooClass, "Type 'Foo' not found"); 80 Expect.isNotNull(fooClass, "Type 'Foo' not found");
71 Expect.isTrue(fooClass is InterfaceMirror, 81 Expect.isTrue(fooClass is InterfaceMirror,
72 "Unexpected mirror type returned"); 82 "Unexpected mirror type returned");
73 Expect.stringEquals("Foo", fooClass.simpleName, 83 Expect.stringEquals("Foo", fooClass.simpleName,
74 "Unexpected type simple name"); 84 "Unexpected type simple name");
75 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName, 85 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName,
76 "Unexpected type qualified name"); 86 "Unexpected type qualified name");
77 87
78 Expect.equals(helperLibrary, fooClass.library, 88 Expect.equals(helperLibrary, fooClass.library,
79 "Unexpected library returned from type"); 89 "Unexpected library returned from type");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 "Constructors map is unempty"); 142 "Constructors map is unempty");
133 } 143 }
134 144
135 // Testing interface Bar: 145 // Testing interface Bar:
136 // 146 //
137 // interface Bar<E> { 147 // interface Bar<E> {
138 // 148 //
139 // } 149 // }
140 void testBar(MirrorSystem system, LibraryMirror helperLibrary, 150 void testBar(MirrorSystem system, LibraryMirror helperLibrary,
141 Map<Object,TypeMirror> types) { 151 Map<Object,TypeMirror> types) {
142 var barInterface = findMirror(types, "Bar"); 152 var barInterface = types["Bar"];
143 Expect.isNotNull(barInterface, "Type 'Bar' not found"); 153 Expect.isNotNull(barInterface, "Type 'Bar' not found");
144 Expect.isTrue(barInterface is InterfaceMirror, 154 Expect.isTrue(barInterface is InterfaceMirror,
145 "Unexpected mirror type returned"); 155 "Unexpected mirror type returned");
146 Expect.stringEquals("Bar", barInterface.simpleName, 156 Expect.stringEquals("Bar", barInterface.simpleName,
147 "Unexpected type simple name"); 157 "Unexpected type simple name");
148 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName, 158 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName,
149 "Unexpected type qualified name"); 159 "Unexpected type qualified name");
150 160
151 Expect.equals(helperLibrary, barInterface.library, 161 Expect.equals(helperLibrary, barInterface.library,
152 "Unexpected library returned from type"); 162 "Unexpected library returned from type");
(...skipping 22 matching lines...) Expand all
175 "Class is not subclass of superclass"); 185 "Class is not subclass of superclass");
176 186
177 var barInterfaces = barInterface.interfaces; 187 var barInterfaces = barInterface.interfaces;
178 Expect.isNotNull(barInterfaces, "Interfaces map is null"); 188 Expect.isNotNull(barInterfaces, "Interfaces map is null");
179 Expect.isTrue(barInterfaces.isEmpty(), "Interfaces map is not empty"); 189 Expect.isTrue(barInterfaces.isEmpty(), "Interfaces map is not empty");
180 190
181 var barSubdeclarations = computeSubdeclarations(barInterface); 191 var barSubdeclarations = computeSubdeclarations(barInterface);
182 Expect.equals(1, count(barSubdeclarations), "Unexpected subtype count"); 192 Expect.equals(1, count(barSubdeclarations), "Unexpected subtype count");
183 for (var barSubdeclaration in barSubdeclarations) { 193 for (var barSubdeclaration in barSubdeclarations) {
184 Expect.isTrue(containsType(barInterface, 194 Expect.isTrue(containsType(barInterface,
185 barSubdeclaration.interfaces.getValues()), 195 barSubdeclaration.interfaces),
186 "Interface is not superinterface of subclass"); 196 "Interface is not superinterface of subclass");
187 } 197 }
188 198
189 Expect.throws(() => barInterface.typeArguments, 199 Expect.throws(() => barInterface.typeArguments,
190 (exception) => true, 200 (exception) => true,
191 "Interface has type arguments"); 201 "Interface has type arguments");
192 var barInterfaceTypeVariables = barInterface.typeVariables; 202 var barInterfaceTypeVariables = barInterface.typeVariables;
193 Expect.isNotNull(barInterfaceTypeVariables, "Type variable list is null"); 203 Expect.isNotNull(barInterfaceTypeVariables, "Type variable list is null");
194 Expect.isFalse(barInterfaceTypeVariables.isEmpty(), 204 Expect.isFalse(barInterfaceTypeVariables.isEmpty(),
195 "Type variable list is empty"); 205 "Type variable list is empty");
(...skipping 26 matching lines...) Expand all
222 // 232 //
223 // static method1(e) {} 233 // static method1(e) {}
224 // void method2(E e, [F f = null]) {} 234 // void method2(E e, [F f = null]) {}
225 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; 235 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null;
226 // 236 //
227 // bool operator==(Object other) => false; 237 // bool operator==(Object other) => false;
228 // int operator -() => 0; 238 // int operator -() => 0;
229 // } 239 // }
230 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, 240 void testBaz(MirrorSystem system, LibraryMirror helperLibrary,
231 Map<Object,TypeMirror> types) { 241 Map<Object,TypeMirror> types) {
232 var bazClass = findMirror(types, "Baz"); 242 var bazClass = types["Baz"];
233 Expect.isNotNull(bazClass, "Type 'Baz' not found"); 243 Expect.isNotNull(bazClass, "Type 'Baz' not found");
234 Expect.isTrue(bazClass is InterfaceMirror, 244 Expect.isTrue(bazClass is InterfaceMirror,
235 "Unexpected mirror type returned"); 245 "Unexpected mirror type returned");
236 Expect.stringEquals("Baz", bazClass.simpleName, 246 Expect.stringEquals("Baz", bazClass.simpleName,
237 "Unexpected type simple name"); 247 "Unexpected type simple name");
238 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName, 248 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName,
239 "Unexpected type qualified name"); 249 "Unexpected type qualified name");
240 250
241 Expect.equals(helperLibrary, bazClass.library, 251 Expect.equals(helperLibrary, bazClass.library,
242 "Unexpected library returned from type"); 252 "Unexpected library returned from type");
(...skipping 17 matching lines...) Expand all
260 Expect.isNotNull(objectType, "Superclass is null"); 270 Expect.isNotNull(objectType, "Superclass is null");
261 Expect.isTrue(objectType.isObject, "Object is not Object"); 271 Expect.isTrue(objectType.isObject, "Object is not Object");
262 Expect.isFalse(objectType.isDeclaration, "Object type is declaration"); 272 Expect.isFalse(objectType.isDeclaration, "Object type is declaration");
263 Expect.isTrue(containsType(bazClass, 273 Expect.isTrue(containsType(bazClass,
264 computeSubdeclarations(objectType)), 274 computeSubdeclarations(objectType)),
265 "Class is not subclass of superclass"); 275 "Class is not subclass of superclass");
266 276
267 var bazInterfaces = bazClass.interfaces; 277 var bazInterfaces = bazClass.interfaces;
268 Expect.isNotNull(bazInterfaces, "Interfaces map is null"); 278 Expect.isNotNull(bazInterfaces, "Interfaces map is null");
269 Expect.isTrue(!bazInterfaces.isEmpty(), "Interfaces map is empty"); 279 Expect.isTrue(!bazInterfaces.isEmpty(), "Interfaces map is empty");
270 for (var bazInterface in bazInterfaces.getValues()) { 280 for (var bazInterface in bazInterfaces) {
271 Expect.isTrue(containsType(bazClass, 281 Expect.isTrue(containsType(bazClass,
272 computeSubdeclarations(objectType)), 282 computeSubdeclarations(objectType)),
273 "Class is not subclass of superinterface"); 283 "Class is not subclass of superinterface");
274 } 284 }
275 285
276 var bazSubdeclarations = computeSubdeclarations(bazClass); 286 var bazSubdeclarations = computeSubdeclarations(bazClass);
277 Expect.equals(0, count(bazSubdeclarations), "Unexpected subtype count"); 287 Expect.equals(0, count(bazSubdeclarations), "Unexpected subtype count");
278 288
279 var barInterface = findMirror(bazInterfaces, "Bar"); 289 var barInterface = findMirror(bazInterfaces, "Bar");
280 Expect.isNotNull(barInterface, "Interface bar is missing"); 290 Expect.isNotNull(barInterface, "Interface bar is missing");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 Expect.isNull(bazClass.defaultType, "Class has default type"); 329 Expect.isNull(bazClass.defaultType, "Class has default type");
320 330
321 var bazClassMembers = bazClass.declaredMembers; 331 var bazClassMembers = bazClass.declaredMembers;
322 Expect.isNotNull(bazClassMembers, "Declared members map is null"); 332 Expect.isNotNull(bazClassMembers, "Declared members map is null");
323 Expect.equals(8, bazClassMembers.length, 333 Expect.equals(8, bazClassMembers.length,
324 "Unexpected number of declared members"); 334 "Unexpected number of declared members");
325 335
326 //////////////////////////////////////////////////////////////////////////// 336 ////////////////////////////////////////////////////////////////////////////
327 // static method1(e) {} 337 // static method1(e) {}
328 //////////////////////////////////////////////////////////////////////////// 338 ////////////////////////////////////////////////////////////////////////////
329 var method1 = findMirror(bazClassMembers, "method1"); 339 var method1 = bazClassMembers["method1"];
330 Expect.isNotNull(method1, "method1 not found"); 340 Expect.isNotNull(method1, "method1 not found");
331 Expect.stringEquals('method1', method1.simpleName, 341 Expect.stringEquals('method1', method1.simpleName,
332 "Unexpected method simpleName"); 342 "Unexpected method simpleName");
333 Expect.stringEquals('mirrors_helper.Baz.method1', method1.qualifiedName, 343 Expect.stringEquals('mirrors_helper.Baz.method1', method1.qualifiedName,
334 "Unexpected method qualifiedName"); 344 "Unexpected method qualifiedName");
335 Expect.equals(method1.surroundingDeclaration, bazClass, 345 Expect.equals(method1.surroundingDeclaration, bazClass,
336 "Unexpected surrounding declaration"); 346 "Unexpected surrounding declaration");
337 Expect.isFalse(method1.isTopLevel, "Method is top level"); 347 Expect.isFalse(method1.isTopLevel, "Method is top level");
338 Expect.isFalse(method1.isConstructor, "Method is constructor"); 348 Expect.isFalse(method1.isConstructor, "Method is constructor");
339 Expect.isFalse(method1.isField, "Method is field"); 349 Expect.isFalse(method1.isField, "Method is field");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 "Unexpected parameter qualifiedName"); 383 "Unexpected parameter qualifiedName");
374 Expect.isFalse(method1Parameter1.hasDefaultValue, 384 Expect.isFalse(method1Parameter1.hasDefaultValue,
375 "Parameter has default value"); 385 "Parameter has default value");
376 Expect.isNull(method1Parameter1.defaultValue, 386 Expect.isNull(method1Parameter1.defaultValue,
377 "Parameter default value is non-null"); 387 "Parameter default value is non-null");
378 Expect.isFalse(method1Parameter1.isOptional, "Parameter is optional"); 388 Expect.isFalse(method1Parameter1.isOptional, "Parameter is optional");
379 389
380 //////////////////////////////////////////////////////////////////////////// 390 ////////////////////////////////////////////////////////////////////////////
381 // static void method2(E e, [F f = null]) {} 391 // static void method2(E e, [F f = null]) {}
382 //////////////////////////////////////////////////////////////////////////// 392 ////////////////////////////////////////////////////////////////////////////
383 var method2 = findMirror(bazClassMembers, "method2"); 393 var method2 = bazClassMembers["method2"];
384 Expect.isNotNull(method2, "method2 not found"); 394 Expect.isNotNull(method2, "method2 not found");
385 Expect.stringEquals('method2', method2.simpleName, 395 Expect.stringEquals('method2', method2.simpleName,
386 "Unexpected method simpleName"); 396 "Unexpected method simpleName");
387 Expect.stringEquals('mirrors_helper.Baz.method2', method2.qualifiedName, 397 Expect.stringEquals('mirrors_helper.Baz.method2', method2.qualifiedName,
388 "Unexpected method qualifiedName"); 398 "Unexpected method qualifiedName");
389 Expect.equals(method2.surroundingDeclaration, bazClass, 399 Expect.equals(method2.surroundingDeclaration, bazClass,
390 "Unexpected surrounding declaration"); 400 "Unexpected surrounding declaration");
391 Expect.isFalse(method2.isTopLevel, "Method is top level"); 401 Expect.isFalse(method2.isTopLevel, "Method is top level");
392 Expect.isFalse(method2.isConstructor, "Method is constructor"); 402 Expect.isFalse(method2.isConstructor, "Method is constructor");
393 Expect.isFalse(method2.isField, "Method is field"); 403 Expect.isFalse(method2.isField, "Method is field");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 "Unexpected parameter qualifiedName"); 450 "Unexpected parameter qualifiedName");
441 Expect.isTrue(method2Parameter2.hasDefaultValue, 451 Expect.isTrue(method2Parameter2.hasDefaultValue,
442 "Parameter has default value"); 452 "Parameter has default value");
443 Expect.stringEquals("null", method2Parameter2.defaultValue, 453 Expect.stringEquals("null", method2Parameter2.defaultValue,
444 "Parameter default value is non-null"); 454 "Parameter default value is non-null");
445 Expect.isTrue(method2Parameter2.isOptional, "Parameter is not optional"); 455 Expect.isTrue(method2Parameter2.isOptional, "Parameter is not optional");
446 456
447 //////////////////////////////////////////////////////////////////////////// 457 ////////////////////////////////////////////////////////////////////////////
448 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; 458 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null;
449 //////////////////////////////////////////////////////////////////////////// 459 ////////////////////////////////////////////////////////////////////////////
450 var method3 = findMirror(bazClassMembers, "method3"); 460 var method3 = bazClassMembers["method3"];
451 Expect.isNotNull(method3, "method3 not found"); 461 Expect.isNotNull(method3, "method3 not found");
452 Expect.stringEquals('method3', method3.simpleName, 462 Expect.stringEquals('method3', method3.simpleName,
453 "Unexpected method simpleName"); 463 "Unexpected method simpleName");
454 Expect.stringEquals('mirrors_helper.Baz.method3', method3.qualifiedName, 464 Expect.stringEquals('mirrors_helper.Baz.method3', method3.qualifiedName,
455 "Unexpected method qualifiedName"); 465 "Unexpected method qualifiedName");
456 Expect.equals(method3.surroundingDeclaration, bazClass, 466 Expect.equals(method3.surroundingDeclaration, bazClass,
457 "Unexpected surrounding declaration"); 467 "Unexpected surrounding declaration");
458 Expect.isFalse(method3.isTopLevel, "Method is top level"); 468 Expect.isFalse(method3.isTopLevel, "Method is top level");
459 Expect.isFalse(method3.isConstructor, "Method is constructor"); 469 Expect.isFalse(method3.isConstructor, "Method is constructor");
460 Expect.isFalse(method3.isField, "Method is field"); 470 Expect.isFalse(method3.isField, "Method is field");
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 Expect.isFalse(method3Parameter2.hasDefaultValue, 579 Expect.isFalse(method3Parameter2.hasDefaultValue,
570 "Parameter 'func2' has default value: " 580 "Parameter 'func2' has default value: "
571 "${method3Parameter2.defaultValue}"); 581 "${method3Parameter2.defaultValue}");
572 Expect.isNull(method3Parameter2.defaultValue, 582 Expect.isNull(method3Parameter2.defaultValue,
573 "Parameter default value is non-null"); 583 "Parameter default value is non-null");
574 Expect.isFalse(method3Parameter2.isOptional, "Parameter is optional"); 584 Expect.isFalse(method3Parameter2.isOptional, "Parameter is optional");
575 585
576 //////////////////////////////////////////////////////////////////////////// 586 ////////////////////////////////////////////////////////////////////////////
577 // bool operator==(Object other) => false; 587 // bool operator==(Object other) => false;
578 //////////////////////////////////////////////////////////////////////////// 588 ////////////////////////////////////////////////////////////////////////////
579 var operator_eq = findMirror(bazClassMembers, "operator", operatorName: '=='); 589 var operator_eq = bazClassMembers['=='];
580 Expect.isNotNull(operator_eq, "operator == not found"); 590 Expect.isNotNull(operator_eq, "operator == not found");
581 Expect.stringEquals('operator', operator_eq.simpleName, 591 Expect.stringEquals('==', operator_eq.simpleName,
582 "Unexpected method simpleName"); 592 "Unexpected method simpleName");
583 Expect.stringEquals('mirrors_helper.Baz.operator ==', 593 Expect.stringEquals('operator ==', operator_eq.displayName);
594 Expect.stringEquals('mirrors_helper.Baz.==',
584 operator_eq.qualifiedName, 595 operator_eq.qualifiedName,
585 "Unexpected method qualifiedName"); 596 "Unexpected method qualifiedName");
586 Expect.equals(operator_eq.surroundingDeclaration, bazClass, 597 Expect.equals(operator_eq.surroundingDeclaration, bazClass,
587 "Unexpected surrounding declaration"); 598 "Unexpected surrounding declaration");
588 Expect.isFalse(operator_eq.isTopLevel, "Method is top level"); 599 Expect.isFalse(operator_eq.isTopLevel, "Method is top level");
589 Expect.isFalse(operator_eq.isConstructor, "Method is constructor"); 600 Expect.isFalse(operator_eq.isConstructor, "Method is constructor");
590 Expect.isFalse(operator_eq.isField, "Method is field"); 601 Expect.isFalse(operator_eq.isField, "Method is field");
591 Expect.isTrue(operator_eq.isMethod, "Method is not method"); 602 Expect.isTrue(operator_eq.isMethod, "Method is not method");
592 Expect.isFalse(operator_eq.isPrivate, "Method is private"); 603 Expect.isFalse(operator_eq.isPrivate, "Method is private");
593 Expect.isFalse(operator_eq.isStatic, "Method is static"); 604 Expect.isFalse(operator_eq.isStatic, "Method is static");
594 Expect.isTrue(operator_eq is MethodMirror, "Method is not MethodMirror"); 605 Expect.isTrue(operator_eq is MethodMirror, "Method is not MethodMirror");
595 Expect.isFalse(operator_eq.isConst, "Method is const"); 606 Expect.isFalse(operator_eq.isConst, "Method is const");
596 Expect.isFalse(operator_eq.isFactory, "Method is factory"); 607 Expect.isFalse(operator_eq.isFactory, "Method is factory");
597 Expect.isNull(operator_eq.constructorName, 608 Expect.isNull(operator_eq.constructorName,
598 "Method constructorName is non-null"); 609 "Method constructorName is non-null");
599 Expect.isFalse(operator_eq.isGetter, "Method is getter"); 610 Expect.isFalse(operator_eq.isGetter, "Method is getter");
600 Expect.isFalse(operator_eq.isSetter, "Method is setter"); 611 Expect.isFalse(operator_eq.isSetter, "Method is setter");
601 Expect.isTrue(operator_eq.isOperator, "Method is not operator"); 612 Expect.isTrue(operator_eq.isOperator, "Method is not operator");
602 Expect.stringEquals('==', operator_eq.operatorName, 613 Expect.stringEquals('==', operator_eq.operatorName,
603 "Unexpected operatorName"); 614 "Unexpected operatorName");
604 615
605 //////////////////////////////////////////////////////////////////////////// 616 ////////////////////////////////////////////////////////////////////////////
606 // int operator -() => 0; 617 // int operator -() => 0;
607 //////////////////////////////////////////////////////////////////////////// 618 ////////////////////////////////////////////////////////////////////////////
608 var operator_negate = findMirror(bazClassMembers, "operator", 619 var operator_negate = bazClassMembers[Mirror.UNARY_MINUS];
609 operatorName: 'negate');
610 Expect.isNotNull(operator_negate, "operator < not found"); 620 Expect.isNotNull(operator_negate, "operator < not found");
611 Expect.stringEquals('operator', operator_negate.simpleName, 621 Expect.stringEquals(Mirror.UNARY_MINUS, operator_negate.simpleName,
612 "Unexpected method simpleName"); 622 "Unexpected method simpleName");
613 Expect.stringEquals('mirrors_helper.Baz.operator negate', 623 Expect.stringEquals('operator -', operator_negate.displayName);
624 Expect.stringEquals('mirrors_helper.Baz.${Mirror.UNARY_MINUS}',
614 operator_negate.qualifiedName, 625 operator_negate.qualifiedName,
615 "Unexpected method qualifiedName"); 626 "Unexpected method qualifiedName");
616 Expect.equals(operator_negate.surroundingDeclaration, bazClass, 627 Expect.equals(operator_negate.surroundingDeclaration, bazClass,
617 "Unexpected surrounding declaration"); 628 "Unexpected surrounding declaration");
618 Expect.isFalse(operator_negate.isTopLevel, "Method is top level"); 629 Expect.isFalse(operator_negate.isTopLevel, "Method is top level");
619 Expect.isFalse(operator_negate.isConstructor, "Method is constructor"); 630 Expect.isFalse(operator_negate.isConstructor, "Method is constructor");
620 Expect.isFalse(operator_negate.isField, "Method is field"); 631 Expect.isFalse(operator_negate.isField, "Method is field");
621 Expect.isTrue(operator_negate.isMethod, "Method is not method"); 632 Expect.isTrue(operator_negate.isMethod, "Method is not method");
622 Expect.isFalse(operator_negate.isPrivate, "Method is private"); 633 Expect.isFalse(operator_negate.isPrivate, "Method is private");
623 Expect.isFalse(operator_negate.isStatic, "Method is static"); 634 Expect.isFalse(operator_negate.isStatic, "Method is static");
624 Expect.isTrue(operator_negate is MethodMirror, 635 Expect.isTrue(operator_negate is MethodMirror,
625 "Method is not MethodMirror"); 636 "Method is not MethodMirror");
626 Expect.isFalse(operator_negate.isConst, "Method is const"); 637 Expect.isFalse(operator_negate.isConst, "Method is const");
627 Expect.isFalse(operator_negate.isFactory, "Method is factory"); 638 Expect.isFalse(operator_negate.isFactory, "Method is factory");
628 Expect.isNull(operator_negate.constructorName, 639 Expect.isNull(operator_negate.constructorName,
629 "Method constructorName is non-null"); 640 "Method constructorName is non-null");
630 Expect.isFalse(operator_negate.isGetter, "Method is getter"); 641 Expect.isFalse(operator_negate.isGetter, "Method is getter");
631 Expect.isFalse(operator_negate.isSetter, "Method is setter"); 642 Expect.isFalse(operator_negate.isSetter, "Method is setter");
632 Expect.isTrue(operator_negate.isOperator, "Method is not operator"); 643 Expect.isTrue(operator_negate.isOperator, "Method is not operator");
633 Expect.stringEquals('negate', operator_negate.operatorName, 644 Expect.stringEquals('-', operator_negate.operatorName,
634 "Unexpected operatorName"); 645 "Unexpected operatorName");
635 646
636 647
637 var bazClassConstructors = bazClass.constructors; 648 var bazClassConstructors = bazClass.constructors;
638 Expect.isNotNull(bazClassConstructors, "Constructors map is null"); 649 Expect.isNotNull(bazClassConstructors, "Constructors map is null");
639 Expect.equals(3, bazClassConstructors.length, 650 Expect.equals(3, bazClassConstructors.length,
640 "Unexpected number of constructors"); 651 "Unexpected number of constructors");
641 // TODO(johnniwinther): Add tests of constructors. 652
653 var bazClassNonameConstructor = bazClassConstructors['Baz'];
654 Expect.isNotNull(bazClassNonameConstructor);
655 Expect.isTrue(bazClassNonameConstructor is MethodMirror);
656 Expect.isTrue(bazClassNonameConstructor.isConstructor);
657 Expect.isFalse(bazClassNonameConstructor.isFactory);
658 Expect.stringEquals('Baz', bazClassNonameConstructor.simpleName);
659 Expect.stringEquals('Baz', bazClassNonameConstructor.displayName);
660 Expect.stringEquals('mirrors_helper.Baz.Baz',
661 bazClassNonameConstructor.qualifiedName);
662 Expect.stringEquals('', bazClassNonameConstructor.constructorName);
663
664 var bazClassNamedConstructor = bazClassConstructors['Baz.named'];
665 Expect.isNotNull(bazClassNamedConstructor);
666 Expect.isTrue(bazClassNamedConstructor is MethodMirror);
667 Expect.isTrue(bazClassNamedConstructor.isConstructor);
668 Expect.isFalse(bazClassNamedConstructor.isFactory);
669 Expect.stringEquals('Baz.named', bazClassNamedConstructor.simpleName);
670 Expect.stringEquals('Baz.named', bazClassNamedConstructor.displayName);
671 Expect.stringEquals('mirrors_helper.Baz.Baz.named',
672 bazClassNamedConstructor.qualifiedName);
673 Expect.stringEquals('named', bazClassNamedConstructor.constructorName);
674
675 var bazClassFactoryConstructor = bazClassConstructors['Baz.factory'];
676 Expect.isNotNull(bazClassFactoryConstructor);
677 Expect.isTrue(bazClassFactoryConstructor is MethodMirror);
678 Expect.isTrue(bazClassFactoryConstructor.isConstructor);
679 Expect.isTrue(bazClassFactoryConstructor.isFactory);
680 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.simpleName);
681 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.displayName);
682 Expect.stringEquals('mirrors_helper.Baz.Baz.factory',
683 bazClassFactoryConstructor.qualifiedName);
684 Expect.stringEquals('factory', bazClassFactoryConstructor.constructorName);
685
686 // TODO(johnniwinther): Add more tests of constructors.
687 // TODO(johnniwinther): Add a test for unnamed factory methods.
642 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698