| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library reflectable_test.declarations_test; | 5 library reflectable_test.declarations_test; |
| 6 | 6 |
| 7 import "package:reflectable/reflectable.dart"; | 7 import "package:reflectable/reflectable.dart"; |
| 8 import "package:unittest/unittest.dart"; | 8 import "package:unittest/unittest.dart"; |
| 9 | 9 |
| 10 class Reflector extends Reflectable { | 10 class Reflector extends Reflectable { |
| 11 // TODO(sigurdm): Include capability to reflect on constructors when | 11 // TODO(sigurdm): Include capability to reflect on constructors when |
| 12 // available. | 12 // available. |
| 13 const Reflector() : super(instanceInvokeCapability); | 13 const Reflector() : super(instanceInvokeCapability); |
| 14 } | 14 } |
| 15 | 15 |
| 16 // TODO(sigurdm): Adapt this test when we support fields. |
| 17 |
| 16 @Reflector() | 18 @Reflector() |
| 17 abstract class A { | 19 abstract class A { |
| 18 A(); | 20 A(); |
| 19 A.redirecting() : this(); | 21 A.redirecting() : this(); |
| 20 factory A.factory() { | 22 factory A.factory() { |
| 21 return new B(); | 23 return new B(); |
| 22 } | 24 } |
| 23 const factory A.redirectingFactory() = A.c; | 25 const factory A.redirectingFactory() = A.c; |
| 24 const A.c(); | 26 const A.c(); |
| 25 foo() {} | 27 foo() {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 bar() {} | 38 bar() {} |
| 37 set setter2(x) => null; | 39 set setter2(x) => null; |
| 38 @override | 40 @override |
| 39 int get getter1 => 11; | 41 int get getter1 => 11; |
| 40 @override | 42 @override |
| 41 int get getter2 => 12; | 43 int get getter2 => 12; |
| 42 } | 44 } |
| 43 | 45 |
| 44 main() { | 46 main() { |
| 45 const reflector = const Reflector(); | 47 const reflector = const Reflector(); |
| 46 test("Test declarations", () { | 48 Map<String, DeclarationMirror> declarationsA = |
| 47 // TODO(sigurdm): Adapt this test when we support constructors, fields, | 49 reflector.reflectType(A).declarations; |
| 48 // in declarations. | 50 Map<String, DeclarationMirror> declarationsB = |
| 49 Map<String, DeclarationMirror> declarationsA = | 51 reflector.reflectType(B).declarations; |
| 50 reflector.reflectType(A).declarations; | 52 |
| 51 expect(declarationsA.values | 53 test("declarations", () { |
| 52 .where((DeclarationMirror x) => x is MethodMirror) | 54 expect(declarationsA.values.map((x) => x.simpleName), new Set.from([ |
| 53 .map((x) => x.simpleName), new Set.from([ | |
| 54 "foo", | 55 "foo", |
| 55 "getter1", | 56 "getter1", |
| 56 "getter2", | 57 "getter2", |
| 57 "setter1=", | 58 "setter1=", |
| 58 "+", | 59 "+", |
| 59 "A", | 60 "A", |
| 60 "A.redirecting", | 61 "A.redirecting", |
| 61 "A.factory", | 62 "A.factory", |
| 62 "A.redirectingFactory", | 63 "A.redirectingFactory", |
| 63 "A.c" | 64 "A.c" |
| 64 ])); | 65 ])); |
| 66 |
| 67 expect(declarationsB.values.map((x) => x.simpleName), |
| 68 new Set.from(["bar", "getter1", "getter2", "setter2=", "B"])); |
| 69 }); |
| 70 |
| 71 test("MethodMirror properties", () { |
| 65 MethodMirror foo = declarationsA["foo"] as MethodMirror; | 72 MethodMirror foo = declarationsA["foo"] as MethodMirror; |
| 66 expect(foo.isRegularMethod, isTrue); | 73 expect(foo.isRegularMethod, isTrue); |
| 67 expect(foo.isStatic, isFalse); | 74 expect(foo.isStatic, isFalse); |
| 68 expect(foo.isGetter, isFalse); | 75 expect(foo.isGetter, isFalse); |
| 69 expect(foo.isSetter, isFalse); | 76 expect(foo.isSetter, isFalse); |
| 70 expect(foo.isPrivate, isFalse); | 77 expect(foo.isPrivate, isFalse); |
| 71 expect(foo.isAbstract, isFalse); | 78 expect(foo.isAbstract, isFalse); |
| 72 expect(foo.isConstructor, isFalse); | 79 expect(foo.isConstructor, isFalse); |
| 73 expect(foo.isGenerativeConstructor, isFalse); | 80 expect(foo.isGenerativeConstructor, isFalse); |
| 74 expect(foo.isFactoryConstructor, isFalse); | 81 expect(foo.isFactoryConstructor, isFalse); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 expect(constConstructorA.isFactoryConstructor, isFalse); | 152 expect(constConstructorA.isFactoryConstructor, isFalse); |
| 146 expect(constConstructorA.isConstConstructor, isTrue); | 153 expect(constConstructorA.isConstConstructor, isTrue); |
| 147 expect(constConstructorA.isRedirectingConstructor, isFalse); | 154 expect(constConstructorA.isRedirectingConstructor, isFalse); |
| 148 MethodMirror redirectingFactoryConstructorA = | 155 MethodMirror redirectingFactoryConstructorA = |
| 149 declarationsA["A.redirectingFactory"] as MethodMirror; | 156 declarationsA["A.redirectingFactory"] as MethodMirror; |
| 150 expect(redirectingFactoryConstructorA.isConstructor, isTrue); | 157 expect(redirectingFactoryConstructorA.isConstructor, isTrue); |
| 151 expect(redirectingFactoryConstructorA.isGenerativeConstructor, isFalse); | 158 expect(redirectingFactoryConstructorA.isGenerativeConstructor, isFalse); |
| 152 expect(redirectingFactoryConstructorA.isFactoryConstructor, isTrue); | 159 expect(redirectingFactoryConstructorA.isFactoryConstructor, isTrue); |
| 153 expect(redirectingFactoryConstructorA.isConstConstructor, isTrue); | 160 expect(redirectingFactoryConstructorA.isConstConstructor, isTrue); |
| 154 expect(redirectingFactoryConstructorA.isRedirectingConstructor, isTrue); | 161 expect(redirectingFactoryConstructorA.isRedirectingConstructor, isTrue); |
| 155 var declarationsB = reflector.reflectType(B).declarations; | 162 }); |
| 156 expect(declarationsB.values | 163 |
| 157 .where((DeclarationMirror x) => x is MethodMirror) | 164 test("instanceMethods", () { |
| 158 .map((x) => x.simpleName), | 165 Map<String, DeclarationMirror> instanceMembersA = |
| 159 new Set.from(["bar", "getter1", "getter2", "setter2=", "B"])); | 166 reflector.reflectType(A).instanceMembers; |
| 167 expect(instanceMembersA.values.map((x) => x.simpleName), new Set.from([ |
| 168 "toString", |
| 169 "hashCode", |
| 170 "==", |
| 171 "noSuchMethod", |
| 172 "runtimeType", |
| 173 "foo", |
| 174 "getter1", |
| 175 "setter1=", |
| 176 "+" |
| 177 ])); |
| 178 Map<String, DeclarationMirror> instanceMembersB = |
| 179 reflector.reflectType(B).instanceMembers; |
| 180 expect(instanceMembersB.values.map((x) => x.simpleName), new Set.from([ |
| 181 "toString", |
| 182 "hashCode", |
| 183 "==", |
| 184 "noSuchMethod", |
| 185 "runtimeType", |
| 186 "foo", |
| 187 "bar", |
| 188 "getter1", |
| 189 "getter2", |
| 190 "setter1=", |
| 191 "setter2=", |
| 192 "+" |
| 193 ])); |
| 160 }); | 194 }); |
| 161 } | 195 } |
| OLD | NEW |