Chromium Code Reviews

Unified Diff: test/codegen/lib/mirrors/generic_type_mirror_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: test/codegen/lib/mirrors/generic_type_mirror_test.dart
diff --git a/test/codegen/lib/mirrors/generic_type_mirror_test.dart b/test/codegen/lib/mirrors/generic_type_mirror_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e48892f6b8bde2f3b58c95adf8b0bd941b407125
--- /dev/null
+++ b/test/codegen/lib/mirrors/generic_type_mirror_test.dart
@@ -0,0 +1,90 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:mirrors";
+import "package:expect/expect.dart";
+
+class Foo<W, V> {
+ V field;
+ V get bar => field;
+ set bar(V v) {}
+ W m() {}
+ V n() {}
+ H<V> p() {}
+ o(W w) {}
+}
+class H<T> {}
+class Bar {}
+class Baz {}
+
+void testInstance() {
+ ClassMirror foo = reflect((new Foo<Bar, Baz>())).type;
+ ClassMirror bar = reflect(new Bar()).type;
+ ClassMirror baz = reflect(new Baz()).type;
+ ClassMirror hOfBaz = reflect(new H<Baz>()).type;
+ VariableMirror field = foo.declarations[#field];
+ MethodMirror getter = foo.declarations[#bar];
+ MethodMirror setter = foo.declarations[const Symbol('bar=')];
+ MethodMirror m = foo.declarations[#m];
+ MethodMirror n = foo.declarations[#n];
+ MethodMirror o = foo.declarations[#o];
+ MethodMirror p = foo.declarations[#p];
+
+ Expect.equals(foo, field.owner);
+ Expect.equals(foo, getter.owner);
+ Expect.equals(foo, setter.owner);
+ Expect.equals(foo, m.owner);
+ Expect.equals(foo, n.owner);
+ Expect.equals(foo, o.owner);
+ Expect.equals(foo, p.owner);
+
+ Expect.equals(baz, field.type);
+ Expect.equals(baz, getter.returnType);
+ Expect.equals(bar, m.returnType);
+ Expect.equals(baz, n.returnType);
+ Expect.equals(bar, o.parameters.single.type);
+ Expect.equals(hOfBaz, p.returnType);
+ Expect.equals(1, p.returnType.typeArguments.length);
+ Expect.equals(baz, p.returnType.typeArguments[0]);
+
+ Expect.equals(baz, setter.parameters.single.type);
+
+}
+
+void testOriginalDeclaration() {
+ ClassMirror foo = reflectClass(Foo);
+
+ VariableMirror field = foo.declarations[#field];
+ MethodMirror getter = foo.declarations[#bar];
+ MethodMirror setter = foo.declarations[const Symbol('bar=')];
+ MethodMirror m = foo.declarations[#m];
+ MethodMirror n = foo.declarations[#n];
+ MethodMirror o = foo.declarations[#o];
+ MethodMirror p = foo.declarations[#p];
+ TypeVariableMirror w = foo.typeVariables[0];
+ TypeVariableMirror v = foo.typeVariables[1];
+
+ Expect.equals(foo, field.owner);
+ Expect.equals(foo, getter.owner);
+ Expect.equals(foo, setter.owner);
+ Expect.equals(foo, m.owner);
+ Expect.equals(foo, n.owner);
+ Expect.equals(foo, o.owner);
+ Expect.equals(foo, p.owner);
+
+ Expect.equals(v, field.type);
+ Expect.equals(v, getter.returnType);
+ Expect.equals(w, m.returnType);
+ Expect.equals(v, n.returnType);
+ Expect.equals(w, o.parameters.single.type);
+ Expect.equals(1, p.returnType.typeArguments.length);
+ Expect.equals(v, p.returnType.typeArguments[0]);
+
+ Expect.equals(v, setter.parameters.single.type);
+}
+
+main() {
+ testInstance();
+ testOriginalDeclaration();
+}
« no previous file with comments | « test/codegen/lib/mirrors/generic_superclass_test.dart ('k') | test/codegen/lib/mirrors/generics_double_substitution_test.dart » ('j') | no next file with comments »

Powered by Google App Engine