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

Unified Diff: test_reflectable/test/declarations_test.dart

Issue 1181993003: Add support for getters, setters and constructors in declarations of classMirrors. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: test_reflectable/test/declarations_test.dart
diff --git a/test_reflectable/test/declarations_test.dart b/test_reflectable/test/declarations_test.dart
index 3962dd00e632f3a1a9813f22339cd468592f9655..287aa2d1e380910d3c405976b07d5b06c2fb1a04 100644
--- a/test_reflectable/test/declarations_test.dart
+++ b/test_reflectable/test/declarations_test.dart
@@ -8,29 +8,138 @@ import "package:reflectable/reflectable.dart";
import "package:unittest/unittest.dart";
class Reflector extends Reflectable {
+ // TODO(sigurdm): Include capability to reflect on constructors when
+ // available.
const Reflector() : super(invokeMembersCapability);
}
@Reflector()
-class A {
+abstract class A {
+ A();
+ A.redirecting() : this();
+ factory A.factory() {
+ return new B();
+ }
+ const factory A.redirectingFactory() = A.c;
+ const A.c();
foo() {}
+ int get getter1 => 10;
+ int get getter2;
+ set setter1(x) => null;
+ operator +(Object other) {
+ return this;
+ }
}
@Reflector()
class B extends A {
bar() {}
+ set setter2(x) => null;
+ @override
+ int get getter1 => 11;
+ @override
+ int get getter2 => 12;
}
main() {
const reflector = const Reflector();
test("Test declarations", () {
// TODO(sigurdm): Adapt this test when we support constructors, fields,
- // getters and setters in declarations.
- expect(reflector.reflectType(A).declarations.values
- .where((DeclarationMirror x) => x is MethodMirror && x.isRegularMethod)
- .map((x) => x.simpleName), ["foo"]);
- expect(reflector.reflectType(B).declarations.values
- .where((DeclarationMirror x) => x is MethodMirror && x.isRegularMethod)
- .map((x) => x.simpleName), ["bar"]);
+ // in declarations.
+ Map<String, DeclarationMirror> declarationsA =
+ reflector.reflectType(A).declarations;
+ expect(declarationsA.values
+ .where((DeclarationMirror x) => x is MethodMirror)
+ .map((x) => x.simpleName), new Set.from([
+ "foo",
+ "getter1",
+ "setter1=",
+ "+",
+ "A",
+ "A.redirecting",
+ "A.factory",
+ "A.redirectingFactory",
+ "A.c"
+ ]));
+ MethodMirror foo = declarationsA["foo"] as MethodMirror;
+ expect(foo.isRegularMethod, isTrue);
+ expect(foo.isStatic, isFalse);
+ expect(foo.isGetter, isFalse);
+ expect(foo.isSetter, isFalse);
+ expect(foo.isPrivate, isFalse);
+ expect(foo.isAbstract, isFalse);
+ expect(foo.isConstructor, isFalse);
+ expect(foo.isGenerativeConstructor, isFalse);
+ expect(foo.isFactoryConstructor, isFalse);
+ expect(foo.isConstConstructor, isFalse);
+ expect(foo.isRedirectingConstructor, isFalse);
+ expect(foo.isOperator, isFalse);
+ expect(foo.isSynthetic, isFalse);
+ expect(foo.isTopLevel, isFalse);
+ MethodMirror setter1 = declarationsA["setter1="] as MethodMirror;
+ expect(setter1.isRegularMethod, isFalse);
+ expect(setter1.isStatic, isFalse);
+ expect(setter1.isGetter, isFalse);
+ expect(setter1.isSetter, isTrue);
+ expect(setter1.isPrivate, isFalse);
+ expect(setter1.isAbstract, isFalse);
+ expect(setter1.isOperator, isFalse);
+ expect(setter1.isSynthetic, isFalse);
+ MethodMirror operatorPlus = declarationsA["+"] as MethodMirror;
+ expect(operatorPlus.isRegularMethod, isTrue);
+ expect(operatorPlus.isStatic, isFalse);
+ expect(operatorPlus.isGetter, isFalse);
+ expect(operatorPlus.isSetter, isFalse);
+ expect(operatorPlus.isPrivate, isFalse);
+ expect(operatorPlus.isAbstract, isFalse);
+ expect(operatorPlus.isConstructor, isFalse);
+ expect(operatorPlus.isOperator, isTrue);
+ MethodMirror constructorA = declarationsA["A"] as MethodMirror;
+ expect(constructorA.isRegularMethod, isFalse);
+ expect(constructorA.isStatic, isFalse);
+ expect(constructorA.isGetter, isFalse);
+ expect(constructorA.isSetter, isFalse);
+ expect(constructorA.isPrivate, isFalse);
+ expect(constructorA.isAbstract, isFalse);
+ expect(constructorA.isConstructor, isTrue);
+ expect(constructorA.isGenerativeConstructor, isTrue);
+ expect(constructorA.isFactoryConstructor, isFalse);
+ expect(constructorA.isConstConstructor, isFalse);
+ expect(constructorA.isRedirectingConstructor, isFalse);
+ expect(constructorA.isOperator, isFalse);
+ expect(constructorA.isSynthetic, isFalse);
+ expect(constructorA.isTopLevel, isFalse);
+ MethodMirror redirectingConstructorA =
+ declarationsA["A.redirecting"] as MethodMirror;
+ expect(redirectingConstructorA.isConstructor, isTrue);
+ expect(redirectingConstructorA.isGenerativeConstructor, isTrue);
+ expect(redirectingConstructorA.isFactoryConstructor, isFalse);
+ expect(redirectingConstructorA.isConstConstructor, isFalse);
+ expect(redirectingConstructorA.isRedirectingConstructor, isTrue);
+ MethodMirror factoryConstructorA =
+ declarationsA["A.factory"] as MethodMirror;
+ expect(factoryConstructorA.isConstructor, isTrue);
+ expect(factoryConstructorA.isGenerativeConstructor, isFalse);
+ expect(factoryConstructorA.isFactoryConstructor, isTrue);
+ expect(factoryConstructorA.isConstConstructor, isFalse);
+ expect(factoryConstructorA.isRedirectingConstructor, isFalse);
+ MethodMirror constConstructorA = declarationsA["A.c"] as MethodMirror;
+ expect(constConstructorA.isConstructor, isTrue);
+ expect(constConstructorA.isGenerativeConstructor, isTrue);
+ expect(constConstructorA.isFactoryConstructor, isFalse);
+ expect(constConstructorA.isConstConstructor, isTrue);
+ expect(constConstructorA.isRedirectingConstructor, isFalse);
+ MethodMirror redirectingFactoryConstructorA =
+ declarationsA["A.redirectingFactory"] as MethodMirror;
+ expect(redirectingFactoryConstructorA.isConstructor, isTrue);
+ expect(redirectingFactoryConstructorA.isGenerativeConstructor, isFalse);
+ expect(redirectingFactoryConstructorA.isFactoryConstructor, isTrue);
+ expect(redirectingFactoryConstructorA.isConstConstructor, isTrue);
+ expect(redirectingFactoryConstructorA.isRedirectingConstructor, isTrue);
+ var declarationsB = reflector.reflectType(B).declarations;
+ expect(declarationsB.values
+ .where((DeclarationMirror x) => x is MethodMirror)
+ .map((x) => x.simpleName),
+ new Set.from(["bar", "getter1", "getter2", "setter2=", "B"]));
});
}
« reflectable/lib/src/transformer_implementation.dart ('K') | « test_reflectable/.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698