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

Side by Side Diff: tests/lib/mirrors/generics_substitution_test.dart

Issue 25945002: More mirror tests: initializing formals and substituted types in instantiated generics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: also test substituion of a field's type 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 library test.generics_substitution;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10 class SuperGeneric<R, S> {
11 R r;
12 s(S s) {}
13 }
14
15 class Generic<T> extends SuperGeneric<T, int> {
16 T t() {}
17 }
18
19 main() {
20 ClassMirror genericDecl = reflectClass(Generic);
21 ClassMirror genericOfString = reflect(new Generic<String>()).type;
22 ClassMirror superGenericDecl = reflectClass(SuperGeneric);
23 ClassMirror superOfTAndInt = genericDecl.superclass;
24 ClassMirror superOfStringAndInt = genericOfString.superclass;
25
26 Expect.isTrue(genericDecl.isOriginalDeclaration);
27 Expect.isFalse(genericOfString.isOriginalDeclaration);
28 Expect.isTrue(superGenericDecl.isOriginalDeclaration);
29 Expect.isFalse(superOfTAndInt.isOriginalDeclaration);
30 Expect.isFalse(superOfStringAndInt.isOriginalDeclaration);
31
32 Symbol r(ClassMirror cm) => cm.variables[#r].type.simpleName;
33 Symbol s(ClassMirror cm) => cm.methods[#s].parameters[0].type.simpleName;
34 Symbol t(ClassMirror cm) => cm.methods[#t].returnType.simpleName;
35
36 Expect.equals(#R, r(genericDecl.superclass));
37 Expect.equals(#S, s(genericDecl.superclass));
gbracha 2013/10/03 23:20:01 These two are wrong. The first is T, the second is
rmacnak 2013/10/04 01:17:36 Done.
38 Expect.equals(#T, t(genericDecl));
39
40 Expect.equals(#String, r(genericOfString.superclass));
41 Expect.equals(#int, s(genericOfString.superclass));
42 Expect.equals(#T, t(genericOfString));
gbracha 2013/10/03 23:20:01 Should be string
rmacnak 2013/10/04 01:17:36 Done.
43
44 Expect.equals(#R, r(superGenericDecl));
45 Expect.equals(#S, s(superGenericDecl));
46
47 Expect.equals(#T, r(superOfTAndInt));
48 Expect.equals(#int, s(superOfTAndInt));
49
50 Expect.equals(#String, r(superOfStringAndInt));
51 Expect.equals(#int, t(superOfStringAndInt));
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698