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

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

Issue 26772002: Mirror tests for type bounds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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: tests/lib/mirrors/generic_bounded_by_type_parameter_test.dart
diff --git a/tests/lib/mirrors/generic_bounded_by_type_parameter_test.dart b/tests/lib/mirrors/generic_bounded_by_type_parameter_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2391aa5153b66d52663a1028432d67d9b2265451
--- /dev/null
+++ b/tests/lib/mirrors/generic_bounded_by_type_parameter_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.generic_bounded_by_type_parameter;
+
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+import 'generics_test.dart';
+
+class Super<T, R extends T> {}
+
+class Fixed extends Super<num, int> {}
+class Generic<X, Y> extends Super<X, Y> {}
+class Malbounded extends Super<num, String> {} /// 01: static type warning
ahe 2013/10/10 15:22:51 The problem here is <num, String>, so I think this
+
+main() {
+ ClassMirror superDecl = reflectClass(Super);
+ ClassMirror superOfNumAndInt = reflectClass(Fixed).superclass;
+ ClassMirror genericDecl = reflectClass(Generic);
+ ClassMirror superOfXAndY = genericDecl.superclass;
+ ClassMirror genericOfNumAndDouble = reflect(new Generic<num, double>()).type;
+ ClassMirror superOfNumAndDouble = genericOfNumAndDouble.superclass;
+ ClassMirror genericOfNumAndBool = reflect(new Generic<num, bool>()).type; /// 02: static type warning, dynamic type error
ahe 2013/10/10 15:22:51 This is a long line, and it is hard to see what th
+ ClassMirror superOfNumAndBool = genericOfNumAndBool.superclass; /// 02: continued
ahe 2013/10/10 15:22:51 Then you don't need continued here.
+ ClassMirror superOfNumAndString = reflectClass(Malbounded).superclass; /// 01: continued
ahe 2013/10/10 15:22:51 Ditto.
+
+ Expect.isTrue(superDecl.isOriginalDeclaration);
+ Expect.isFalse(superOfNumAndInt.isOriginalDeclaration);
+ Expect.isTrue(genericDecl.isOriginalDeclaration);
+ Expect.isFalse(superOfXAndY.isOriginalDeclaration);
+ Expect.isFalse(genericOfNumAndDouble.isOriginalDeclaration);
+ Expect.isFalse(superOfNumAndDouble.isOriginalDeclaration);
+ Expect.isFalse(genericOfNumAndBool.isOriginalDeclaration); /// 02: continued
+ Expect.isFalse(superOfNumAndBool.isOriginalDeclaration); /// 02: continued
+ Expect.isFalse(superOfNumAndString.isOriginalDeclaration); /// 01: continued
ahe 2013/10/10 15:22:51 The three "continued" comments above are not neede
+
+ TypeVariableMirror tFromSuper = superDecl.typeVariables[0];
+ TypeVariableMirror rFromSuper = superDecl.typeVariables[1];
+ TypeVariableMirror xFromGeneric = genericDecl.typeVariables[0];
+ TypeVariableMirror yFromGeneric = genericDecl.typeVariables[1];
+
+ Expect.equals(reflectClass(Object), tFromSuper.upperBound);
+ Expect.equals(tFromSuper, rFromSuper.upperBound);
+ Expect.equals(reflectClass(Object), xFromGeneric.upperBound);
+ Expect.equals(reflectClass(Object), yFromGeneric.upperBound);
+
+ typeParameters(superDecl, [#T, #R]);
+ typeParameters(superOfNumAndInt, [#T, #R]);
+ typeParameters(genericDecl, [#X, #Y]);
+ typeParameters(superOfXAndY, [#T, #R]);
+ typeParameters(genericOfNumAndDouble, [#X, #Y]);
+ typeParameters(superOfNumAndDouble, [#T, #R]);
+ typeParameters(genericOfNumAndBool, [#X, #Y]); /// 02: continued
+ typeParameters(superOfNumAndBool, [#T, #R]); /// 02: continued
+ typeParameters(superOfNumAndString, [#T, #R]); /// 01: continued
ahe 2013/10/10 15:22:51 Ditto.
+
+ typeArguments(superDecl, []);
+ typeArguments(superOfNumAndInt, [reflectClass(num), reflectClass(int)]);
+ typeArguments(genericDecl, []);
+ typeArguments(superOfXAndY, [xFromGeneric, yFromGeneric]);
+ typeArguments(genericOfNumAndDouble, [reflectClass(num), reflectClass(double)]);
ahe 2013/10/10 15:22:51 Long line.
+ typeArguments(superOfNumAndDouble, [reflectClass(num), reflectClass(double)]);
+ typeArguments(genericOfNumAndBool, [reflectClass(num), reflectClass(bool)]); /// 02: continued
ahe 2013/10/10 15:22:51 Long line. Also, I feel this would give better tes
+ typeArguments(superOfNumAndBool, [reflectClass(num), reflectClass(bool)]); /// 02: continued
ahe 2013/10/10 15:22:51 Ditto.
+ typeArguments(superOfNumAndString, [reflectClass(num), reflectClass(String)]); /// 01: continued
ahe 2013/10/10 15:22:51 Ditto.
+}

Powered by Google App Engine
This is Rietveld 408576698