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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 Expect.isNotNull(libraries, "No libraries map returned"); | 48 Expect.isNotNull(libraries, "No libraries map returned"); |
49 Expect.isFalse(libraries.isEmpty, "Empty libraries map returned"); | 49 Expect.isFalse(libraries.isEmpty, "Empty libraries map returned"); |
50 | 50 |
51 var helperLibrary = libraries["mirrors_helper"]; | 51 var helperLibrary = libraries["mirrors_helper"]; |
52 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); | 52 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); |
53 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName, | 53 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName, |
54 "Unexpected library simple name"); | 54 "Unexpected library simple name"); |
55 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName, | 55 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName, |
56 "Unexpected library qualified name"); | 56 "Unexpected library qualified name"); |
57 | 57 |
58 var types = helperLibrary.types; | 58 var classes = helperLibrary.classes; |
59 Expect.isNotNull(types, "No types map returned"); | 59 Expect.isNotNull(classes, "No classes map returned"); |
60 Expect.isFalse(types.isEmpty, "Empty types map returned"); | 60 Expect.isFalse(classes.isEmpty, "Empty classes map returned"); |
61 | 61 |
62 testFoo(mirrors, helperLibrary, types); | 62 testFoo(mirrors, helperLibrary, classes); |
63 testBar(mirrors, helperLibrary, types); | 63 testBar(mirrors, helperLibrary, classes); |
64 testBaz(mirrors, helperLibrary, types); | 64 testBaz(mirrors, helperLibrary, classes); |
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 testPrivate(mirrors, helperLibrary, classes); |
| 70 // TODO(johnniwinther): Add tests of [LibraryMirror.functions], |
| 71 // [LibraryMirror.getters], [LibraryMirror.setters] and |
| 72 // [LibraryMirror.members]. |
70 } | 73 } |
71 | 74 |
72 // Testing class Foo: | 75 // Testing class Foo: |
73 // | 76 // |
74 // class Foo { | 77 // class Foo { |
75 // | 78 // |
76 // } | 79 // } |
77 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, | 80 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, |
78 Map<String,TypeMirror> types) { | 81 Map<String,TypeMirror> classes) { |
79 var fooClass = types["Foo"]; | 82 var fooClass = classes["Foo"]; |
80 Expect.isNotNull(fooClass, "Type 'Foo' not found"); | 83 Expect.isNotNull(fooClass, "Type 'Foo' not found"); |
81 Expect.isTrue(fooClass is ClassMirror, | 84 Expect.isTrue(fooClass is ClassMirror, |
82 "Unexpected mirror type returned"); | 85 "Unexpected mirror type returned"); |
83 Expect.stringEquals("Foo", fooClass.simpleName, | 86 Expect.stringEquals("Foo", fooClass.simpleName, |
84 "Unexpected type simple name"); | 87 "Unexpected type simple name"); |
85 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName, | 88 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName, |
86 "Unexpected type qualified name"); | 89 "Unexpected type qualified name"); |
87 | 90 |
88 Expect.equals(helperLibrary, fooClass.library, | 91 Expect.equals(helperLibrary, fooClass.library, |
89 "Unexpected library returned from type"); | 92 "Unexpected library returned from type"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Expect.isTrue(fooClassConstructors.isEmpty, | 144 Expect.isTrue(fooClassConstructors.isEmpty, |
142 "Constructors map is unempty"); | 145 "Constructors map is unempty"); |
143 } | 146 } |
144 | 147 |
145 // Testing interface Bar: | 148 // Testing interface Bar: |
146 // | 149 // |
147 // interface Bar<E> { | 150 // interface Bar<E> { |
148 // | 151 // |
149 // } | 152 // } |
150 void testBar(MirrorSystem system, LibraryMirror helperLibrary, | 153 void testBar(MirrorSystem system, LibraryMirror helperLibrary, |
151 Map<String,TypeMirror> types) { | 154 Map<String,TypeMirror> classes) { |
152 var barInterface = types["Bar"]; | 155 var barInterface = classes["Bar"]; |
153 Expect.isNotNull(barInterface, "Type 'Bar' not found"); | 156 Expect.isNotNull(barInterface, "Type 'Bar' not found"); |
154 Expect.isTrue(barInterface is ClassMirror, | 157 Expect.isTrue(barInterface is ClassMirror, |
155 "Unexpected mirror type returned"); | 158 "Unexpected mirror type returned"); |
156 Expect.stringEquals("Bar", barInterface.simpleName, | 159 Expect.stringEquals("Bar", barInterface.simpleName, |
157 "Unexpected type simple name"); | 160 "Unexpected type simple name"); |
158 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName, | 161 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName, |
159 "Unexpected type qualified name"); | 162 "Unexpected type qualified name"); |
160 | 163 |
161 Expect.equals(helperLibrary, barInterface.library, | 164 Expect.equals(helperLibrary, barInterface.library, |
162 "Unexpected library returned from type"); | 165 "Unexpected library returned from type"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // factory Baz.factory() => new Baz<E,F>(); | 234 // factory Baz.factory() => new Baz<E,F>(); |
232 // | 235 // |
233 // static method1(e) {} | 236 // static method1(e) {} |
234 // void method2(E e, [F f = null]) {} | 237 // void method2(E e, [F f = null]) {} |
235 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; | 238 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; |
236 // | 239 // |
237 // bool operator==(Object other) => false; | 240 // bool operator==(Object other) => false; |
238 // int operator -() => 0; | 241 // int operator -() => 0; |
239 // } | 242 // } |
240 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, | 243 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, |
241 Map<String,TypeMirror> types) { | 244 Map<String,TypeMirror> classes) { |
242 var bazClass = types["Baz"]; | 245 var bazClass = classes["Baz"]; |
243 Expect.isNotNull(bazClass, "Type 'Baz' not found"); | 246 Expect.isNotNull(bazClass, "Type 'Baz' not found"); |
244 Expect.isTrue(bazClass is ClassMirror, | 247 Expect.isTrue(bazClass is ClassMirror, |
245 "Unexpected mirror type returned"); | 248 "Unexpected mirror type returned"); |
246 Expect.stringEquals("Baz", bazClass.simpleName, | 249 Expect.stringEquals("Baz", bazClass.simpleName, |
247 "Unexpected type simple name"); | 250 "Unexpected type simple name"); |
248 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName, | 251 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName, |
249 "Unexpected type qualified name"); | 252 "Unexpected type qualified name"); |
250 | 253 |
251 Expect.equals(helperLibrary, bazClass.library, | 254 Expect.equals(helperLibrary, bazClass.library, |
252 "Unexpected library returned from type"); | 255 "Unexpected library returned from type"); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 692 |
690 // class _PrivateClass { | 693 // class _PrivateClass { |
691 // var _privateField; | 694 // var _privateField; |
692 // get _privateGetter => _privateField; | 695 // get _privateGetter => _privateField; |
693 // void set _privateSetter(value) => _privateField = value; | 696 // void set _privateSetter(value) => _privateField = value; |
694 // void _privateMethod() {} | 697 // void _privateMethod() {} |
695 // _PrivateClass._privateConstructor(); | 698 // _PrivateClass._privateConstructor(); |
696 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); | 699 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); |
697 // } | 700 // } |
698 void testPrivate(MirrorSystem system, LibraryMirror helperLibrary, | 701 void testPrivate(MirrorSystem system, LibraryMirror helperLibrary, |
699 Map<String,TypeMirror> types) { | 702 Map<String,TypeMirror> classes) { |
700 var privateClass = types['_PrivateClass']; | 703 var privateClass = classes['_PrivateClass']; |
701 Expect.isNotNull(privateClass); | 704 Expect.isNotNull(privateClass); |
702 Expect.isTrue(privateClass is ClassMirror); | 705 Expect.isTrue(privateClass is ClassMirror); |
703 Expect.isTrue(privateClass.isClass); | 706 Expect.isTrue(privateClass.isClass); |
704 Expect.isTrue(privateClass.isPrivate); | 707 Expect.isTrue(privateClass.isPrivate); |
705 | 708 |
706 var privateField = privateClass.declaredMembers['_privateField']; | 709 var privateField = privateClass.declaredMembers['_privateField']; |
707 Expect.isNotNull(privateField); | 710 Expect.isNotNull(privateField); |
708 Expect.isTrue(privateField is FieldMirror); | 711 Expect.isTrue(privateField is FieldMirror); |
709 Expect.isTrue(privateField.isPrivate); | 712 Expect.isTrue(privateField.isPrivate); |
710 | 713 |
(...skipping 21 matching lines...) Expand all Loading... |
732 Expect.isTrue(privateConstructor.isConstructor); | 735 Expect.isTrue(privateConstructor.isConstructor); |
733 Expect.isTrue(privateConstructor.isPrivate); | 736 Expect.isTrue(privateConstructor.isPrivate); |
734 | 737 |
735 var privateFactoryConstructor = | 738 var privateFactoryConstructor = |
736 privateClass.declaredMembers['_PrivateClass._privateFactoryConstructor']; | 739 privateClass.declaredMembers['_PrivateClass._privateFactoryConstructor']; |
737 Expect.isNotNull(privateFactoryConstructor); | 740 Expect.isNotNull(privateFactoryConstructor); |
738 Expect.isTrue(privateFactoryConstructor is MethodMirror); | 741 Expect.isTrue(privateFactoryConstructor is MethodMirror); |
739 Expect.isTrue(privateFactoryConstructor.isFactory); | 742 Expect.isTrue(privateFactoryConstructor.isFactory); |
740 Expect.isTrue(privateFactoryConstructor.isPrivate); | 743 Expect.isTrue(privateFactoryConstructor.isPrivate); |
741 } | 744 } |
OLD | NEW |