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

Side by Side Diff: test/codegen/lib/mirrors/generic_bounded_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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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.generic_bounded;
6
7 import 'dart:mirrors';
8
9 import 'package:expect/expect.dart';
10
11 import 'generics_helper.dart';
12
13 class Super<T extends num> {}
14
15 class Fixed extends Super<int> {}
16 class Generic<R> extends Super<R> {} /// 02: static type warning
17 class Malbounded extends Super<String> {} /// 01: static type warning
18
19 bool inCheckedMode() {
20 try {
21 var s = 'string';
22 int i = s;
23 } catch(e) {
24 return true;
25 }
26 return false;
27 }
28
29 main() {
30 ClassMirror superDecl = reflectClass(Super);
31 ClassMirror superOfInt = reflectClass(Fixed).superclass;
32 ClassMirror genericDecl = reflectClass(Generic); /// 02: continued
33 ClassMirror superOfR = genericDecl.superclass; /// 02: continued
34 ClassMirror genericOfDouble = reflect(new Generic<double>()).type; /// 02: co ntinued
35 ClassMirror superOfDouble = genericOfDouble.superclass; /// 02: continued
36
37 try {
38 ClassMirror genericOfBool = reflect(new Generic<bool>()).type; /// 02: stat ic type warning
39 ClassMirror superOfBool = genericOfBool.superclass; /// 02: continued
40 Expect.isFalse(genericOfBool.isOriginalDeclaration); /// 02: continued
41 Expect.isFalse(superOfBool.isOriginalDeclaration); /// 02: continued
42 typeParameters(genericOfBool, [#R]); /// 02: continued
43 typeParameters(superOfBool, [#T]); /// 02: continued
44 typeArguments(genericOfBool, [reflectClass(bool)]); /// 02: continued
45 typeArguments(superOfBool, [reflectClass(bool)]); /// 02: continued
46 Expect.isFalse(inCheckedMode()); /// 02: continued
47 } on TypeError catch(e) {
48 Expect.isTrue(inCheckedMode());
49 }
50
51 ClassMirror superOfString = reflectClass(Malbounded).superclass; /// 01: cont inued
52
53 Expect.isTrue(superDecl.isOriginalDeclaration);
54 Expect.isFalse(superOfInt.isOriginalDeclaration);
55 Expect.isTrue(genericDecl.isOriginalDeclaration); /// 02: continued
56 Expect.isFalse(superOfR.isOriginalDeclaration); /// 02: continued
57 Expect.isFalse(genericOfDouble.isOriginalDeclaration); /// 02: continued
58 Expect.isFalse(superOfDouble.isOriginalDeclaration); /// 02: continued
59
60 Expect.isFalse(superOfString.isOriginalDeclaration); /// 01: continued
61
62 TypeVariableMirror tFromSuper = superDecl.typeVariables.single;
63 TypeVariableMirror rFromGeneric = genericDecl.typeVariables.single; /// 02: c ontinued
64
65 Expect.equals(reflectClass(num), tFromSuper.upperBound);
66 Expect.equals(reflectClass(Object), rFromGeneric.upperBound); /// 02: continu ed
67
68 typeParameters(superDecl, [#T]);
69 typeParameters(superOfInt, [#T]);
70 typeParameters(genericDecl, [#R]); /// 02: continued
71 typeParameters(superOfR, [#T]); /// 02: continued
72 typeParameters(genericOfDouble, [#R]); /// 02: continued
73 typeParameters(superOfDouble, [#T]); /// 02: continued
74 typeParameters(superOfString, [#T]); /// 01: continued
75
76 typeArguments(superDecl, []);
77 typeArguments(superOfInt, [reflectClass(int)]);
78 typeArguments(genericDecl, []); /// 02: continued
79 typeArguments(superOfR, [rFromGeneric]); /// 02: continued
80 typeArguments(genericOfDouble, [reflectClass(double)]); /// 02: continued
81 typeArguments(superOfDouble, [reflectClass(double)]); /// 02: continued
82 typeArguments(superOfString, [reflectClass(String)]); /// 01: continued
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698