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

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

Powered by Google App Engine
This is Rietveld 408576698