| OLD | NEW |
| 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) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 Expect.isNotNull(types, "No types map returned"); | 59 Expect.isNotNull(types, "No types map returned"); |
| 60 Expect.isFalse(types.isEmpty(), "Empty types map returned"); | 60 Expect.isFalse(types.isEmpty(), "Empty types map returned"); |
| 61 | 61 |
| 62 testFoo(mirrors, helperLibrary, types); | 62 testFoo(mirrors, helperLibrary, types); |
| 63 testBar(mirrors, helperLibrary, types); | 63 testBar(mirrors, helperLibrary, types); |
| 64 testBaz(mirrors, helperLibrary, types); | 64 testBaz(mirrors, helperLibrary, types); |
| 65 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func]. | 65 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func]. |
| 66 // TODO(johnniwinther): Add tests of type argument substitution, which | 66 // TODO(johnniwinther): Add tests of type argument substitution, which |
| 67 // is not currently implemented in dart2js. | 67 // is not currently implemented in dart2js. |
| 68 // TODO(johnniwinther): Add tests of Location and Source. | 68 // TODO(johnniwinther): Add tests of Location and Source. |
| 69 testPrivate(mirrors, helperLibrary, types); |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Testing class Foo: | 72 // Testing class Foo: |
| 72 // | 73 // |
| 73 // class Foo { | 74 // class Foo { |
| 74 // | 75 // |
| 75 // } | 76 // } |
| 76 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, | 77 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, |
| 77 Map<Object,TypeMirror> types) { | 78 Map<String,TypeMirror> types) { |
| 78 var fooClass = types["Foo"]; | 79 var fooClass = types["Foo"]; |
| 79 Expect.isNotNull(fooClass, "Type 'Foo' not found"); | 80 Expect.isNotNull(fooClass, "Type 'Foo' not found"); |
| 80 Expect.isTrue(fooClass is InterfaceMirror, | 81 Expect.isTrue(fooClass is InterfaceMirror, |
| 81 "Unexpected mirror type returned"); | 82 "Unexpected mirror type returned"); |
| 82 Expect.stringEquals("Foo", fooClass.simpleName, | 83 Expect.stringEquals("Foo", fooClass.simpleName, |
| 83 "Unexpected type simple name"); | 84 "Unexpected type simple name"); |
| 84 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName, | 85 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName, |
| 85 "Unexpected type qualified name"); | 86 "Unexpected type qualified name"); |
| 86 | 87 |
| 87 Expect.equals(helperLibrary, fooClass.library, | 88 Expect.equals(helperLibrary, fooClass.library, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 Expect.isTrue(fooClassConstructors.isEmpty(), | 141 Expect.isTrue(fooClassConstructors.isEmpty(), |
| 141 "Constructors map is unempty"); | 142 "Constructors map is unempty"); |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Testing interface Bar: | 145 // Testing interface Bar: |
| 145 // | 146 // |
| 146 // interface Bar<E> { | 147 // interface Bar<E> { |
| 147 // | 148 // |
| 148 // } | 149 // } |
| 149 void testBar(MirrorSystem system, LibraryMirror helperLibrary, | 150 void testBar(MirrorSystem system, LibraryMirror helperLibrary, |
| 150 Map<Object,TypeMirror> types) { | 151 Map<String,TypeMirror> types) { |
| 151 var barInterface = types["Bar"]; | 152 var barInterface = types["Bar"]; |
| 152 Expect.isNotNull(barInterface, "Type 'Bar' not found"); | 153 Expect.isNotNull(barInterface, "Type 'Bar' not found"); |
| 153 Expect.isTrue(barInterface is InterfaceMirror, | 154 Expect.isTrue(barInterface is InterfaceMirror, |
| 154 "Unexpected mirror type returned"); | 155 "Unexpected mirror type returned"); |
| 155 Expect.stringEquals("Bar", barInterface.simpleName, | 156 Expect.stringEquals("Bar", barInterface.simpleName, |
| 156 "Unexpected type simple name"); | 157 "Unexpected type simple name"); |
| 157 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName, | 158 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName, |
| 158 "Unexpected type qualified name"); | 159 "Unexpected type qualified name"); |
| 159 | 160 |
| 160 Expect.equals(helperLibrary, barInterface.library, | 161 Expect.equals(helperLibrary, barInterface.library, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // factory Baz.factory() => new Baz<E,F>(); | 231 // factory Baz.factory() => new Baz<E,F>(); |
| 231 // | 232 // |
| 232 // static method1(e) {} | 233 // static method1(e) {} |
| 233 // void method2(E e, [F f = null]) {} | 234 // void method2(E e, [F f = null]) {} |
| 234 // 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; |
| 235 // | 236 // |
| 236 // bool operator==(Object other) => false; | 237 // bool operator==(Object other) => false; |
| 237 // int operator -() => 0; | 238 // int operator -() => 0; |
| 238 // } | 239 // } |
| 239 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, | 240 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, |
| 240 Map<Object,TypeMirror> types) { | 241 Map<String,TypeMirror> types) { |
| 241 var bazClass = types["Baz"]; | 242 var bazClass = types["Baz"]; |
| 242 Expect.isNotNull(bazClass, "Type 'Baz' not found"); | 243 Expect.isNotNull(bazClass, "Type 'Baz' not found"); |
| 243 Expect.isTrue(bazClass is InterfaceMirror, | 244 Expect.isTrue(bazClass is InterfaceMirror, |
| 244 "Unexpected mirror type returned"); | 245 "Unexpected mirror type returned"); |
| 245 Expect.stringEquals("Baz", bazClass.simpleName, | 246 Expect.stringEquals("Baz", bazClass.simpleName, |
| 246 "Unexpected type simple name"); | 247 "Unexpected type simple name"); |
| 247 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName, | 248 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName, |
| 248 "Unexpected type qualified name"); | 249 "Unexpected type qualified name"); |
| 249 | 250 |
| 250 Expect.equals(helperLibrary, bazClass.library, | 251 Expect.equals(helperLibrary, bazClass.library, |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 Expect.isTrue(bazClassFactoryConstructor.isFactory); | 679 Expect.isTrue(bazClassFactoryConstructor.isFactory); |
| 679 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.simpleName); | 680 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.simpleName); |
| 680 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.displayName); | 681 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.displayName); |
| 681 Expect.stringEquals('mirrors_helper.Baz.Baz.factory', | 682 Expect.stringEquals('mirrors_helper.Baz.Baz.factory', |
| 682 bazClassFactoryConstructor.qualifiedName); | 683 bazClassFactoryConstructor.qualifiedName); |
| 683 Expect.stringEquals('factory', bazClassFactoryConstructor.constructorName); | 684 Expect.stringEquals('factory', bazClassFactoryConstructor.constructorName); |
| 684 | 685 |
| 685 // TODO(johnniwinther): Add more tests of constructors. | 686 // TODO(johnniwinther): Add more tests of constructors. |
| 686 // TODO(johnniwinther): Add a test for unnamed factory methods. | 687 // TODO(johnniwinther): Add a test for unnamed factory methods. |
| 687 } | 688 } |
| 689 |
| 690 // class _PrivateClass { |
| 691 // var _privateField; |
| 692 // get _privateGetter => _privateField; |
| 693 // void set _privateSetter(value) => _privateField = value; |
| 694 // void _privateMethod() {} |
| 695 // _PrivateClass._privateConstructor(); |
| 696 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); |
| 697 // } |
| 698 void testPrivate(MirrorSystem system, LibraryMirror helperLibrary, |
| 699 Map<String,TypeMirror> types) { |
| 700 var privateClass = types['_PrivateClass']; |
| 701 Expect.isNotNull(privateClass); |
| 702 Expect.isTrue(privateClass is InterfaceMirror); |
| 703 Expect.isTrue(privateClass.isClass); |
| 704 Expect.isTrue(privateClass.isPrivate); |
| 705 |
| 706 var privateField = privateClass.declaredMembers['_privateField']; |
| 707 Expect.isNotNull(privateField); |
| 708 Expect.isTrue(privateField is FieldMirror); |
| 709 Expect.isTrue(privateField.isPrivate); |
| 710 |
| 711 var privateGetter = privateClass.declaredMembers['_privateGetter']; |
| 712 Expect.isNotNull(privateGetter); |
| 713 Expect.isTrue(privateGetter is MethodMirror); |
| 714 Expect.isTrue(privateGetter.isGetter); |
| 715 Expect.isTrue(privateGetter.isPrivate); |
| 716 |
| 717 var privateSetter = privateClass.declaredMembers['_privateSetter=']; |
| 718 Expect.isNotNull(privateSetter); |
| 719 Expect.isTrue(privateSetter is MethodMirror); |
| 720 Expect.isTrue(privateSetter.isSetter); |
| 721 Expect.isTrue(privateSetter.isPrivate); |
| 722 |
| 723 var privateMethod = privateClass.declaredMembers['_privateMethod']; |
| 724 Expect.isNotNull(privateMethod); |
| 725 Expect.isTrue(privateMethod is MethodMirror); |
| 726 Expect.isTrue(privateMethod.isPrivate); |
| 727 |
| 728 var privateConstructor = |
| 729 privateClass.declaredMembers['_PrivateClass._privateConstructor']; |
| 730 Expect.isNotNull(privateConstructor); |
| 731 Expect.isTrue(privateConstructor is MethodMirror); |
| 732 Expect.isTrue(privateConstructor.isConstructor); |
| 733 Expect.isTrue(privateConstructor.isPrivate); |
| 734 |
| 735 var privateFactoryConstructor = |
| 736 privateClass.declaredMembers['_PrivateClass._privateFactoryConstructor']; |
| 737 Expect.isNotNull(privateFactoryConstructor); |
| 738 Expect.isTrue(privateFactoryConstructor is MethodMirror); |
| 739 Expect.isTrue(privateFactoryConstructor.isFactory); |
| 740 Expect.isTrue(privateFactoryConstructor.isPrivate); |
| 741 } |
| OLD | NEW |