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

Unified Diff: tests/lib/mirrors/reflected_type_test.dart

Issue 22849015: Provide a way to get a Type back from a ClassMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: forgot to version the new test... Created 7 years, 4 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
« sdk/lib/mirrors/mirrors.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/reflected_type_test.dart
diff --git a/tests/lib/mirrors/reflected_type_test.dart b/tests/lib/mirrors/reflected_type_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..df4e578c26eb52d58e01931685e245f6447ffa91
--- /dev/null
+++ b/tests/lib/mirrors/reflected_type_test.dart
@@ -0,0 +1,69 @@
+// 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.
+
+library test.reflected_type_test;
+
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+class A<T> {}
+class B extends A {} // Same as class B extends A<dynamic>.
+class C extends A<num, int> {} // Same as class C extends A<dynamic>.
+class D extends A<int> {}
+class E<S> extends A<S> {}
+class F<R> extends A<int> {}
+class G {}
+class H<A,B,C> {}
+
+expectReflectedType(classMirror, expectedType) {
+ if (expectedType == null) {
+ Expect.isFalse(classMirror.hasReflectedType);
+ Expect.throws(() => classMirror.reflectedType,
+ (e) => e is UnsupportedError,
+ "Should not have a reflected type");
+ } else {
+ Expect.isTrue(classMirror.hasReflectedType);
+ Expect.equals(expectedType, classMirror.reflectedType);
+ }
+}
+
+main() {
+ // Declarations.
+ expectReflectedType(reflectClass(A), null);
+ expectReflectedType(reflectClass(B), B);
+ expectReflectedType(reflectClass(C), C);
+ expectReflectedType(reflectClass(D), D);
+ expectReflectedType(reflectClass(E), null);
+ expectReflectedType(reflectClass(F), null);
+ expectReflectedType(reflectClass(G), G);
+ expectReflectedType(reflectClass(H), null);
+
+ // Instantiations.
+ expectReflectedType(reflect(new A()).type, new A().runtimeType);
+ expectReflectedType(reflect(new B()).type, new B().runtimeType);
+ expectReflectedType(reflect(new C()).type, new C().runtimeType);
+ expectReflectedType(reflect(new D()).type, new D().runtimeType);
+ expectReflectedType(reflect(new E()).type, new E().runtimeType);
+ expectReflectedType(reflect(new F()).type, new F().runtimeType);
+ expectReflectedType(reflect(new G()).type, new G().runtimeType);
+ expectReflectedType(reflect(new H()).type, new H().runtimeType);
+
+ expectReflectedType(reflect(new A<num>()).type, new A<num>().runtimeType);
+ expectReflectedType(reflect(new B<num>()).type.superclass,
+ new A<dynamic>().runtimeType);
+ expectReflectedType(reflect(new C<num>()).type.superclass,
+ new A<dynamic>().runtimeType);
+ expectReflectedType(reflect(new D<num>()).type.superclass,
+ new A<int>().runtimeType);
+ expectReflectedType(reflect(new E<num>()).type, new E<num>().runtimeType);
+ // TODO(rmacnak): This requires some work to compute.
+ // expectReflectedType(reflect(new E<num>()).type.superclass,
+ // new A<num>().runtimeType);
+ expectReflectedType(reflect(new F<num>()).type.superclass,
+ new A<int>().runtimeType);
+ expectReflectedType(reflect(new F<num>()).type, new F<num>().runtimeType);
+ expectReflectedType(reflect(new H<num, num, num>()).type,
+ new H<num, num, num>().runtimeType);
+}
« sdk/lib/mirrors/mirrors.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698