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

Side by Side Diff: tests/lib/mirrors/initializing_formals_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.initializing_formals;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10 class Class<T> {
11 int intField;
12 bool boolField;
13 String stringField;
14 T tField;
15 dynamic _privateField;
gbracha 2013/10/03 23:20:01 Any reason for using dynamic rather than var? This
rmacnak 2013/10/04 01:17:36 Just being systematic with explicit types.
16
17 Class.nongeneric(this.intField);
18 Class.named({this.boolField});
19 Class.optPos([this.stringField = 'default']);
20 Class.generic(this.tField);
21 Class.private(this._privateField);
22 }
23
24 class Constant {
25 final value;
26 const Constant(this.value);
27 }
28
29 main() {
30 ParameterMirror pm;
31
32 pm = reflectClass(Class).constructors[#Class.nongeneric].parameters.single;
33 Expect.equals(#intField, pm.simpleName);
34 Expect.equals(reflectClass(int), pm.type); /// 01: ok
35 Expect.isFalse(pm.isNamed);
36 Expect.isFalse(pm.isFinal);
37 Expect.isFalse(pm.isOptional);
38 Expect.isFalse(pm.hasDefaultValue);
39 Expect.isFalse(pm.isPrivate);
40 Expect.isFalse(pm.isStatic);
41 Expect.isFalse(pm.isTopLevel);
42
43 pm = reflectClass(Class).constructors[#Class.named].parameters.single;
44 Expect.equals(#boolField, pm.simpleName);
45 Expect.equals(reflectClass(bool), pm.type); /// 01: ok
46 Expect.isTrue(pm.isNamed);
47 Expect.isFalse(pm.isFinal);
48 Expect.isTrue(pm.isOptional);
49 Expect.isFalse(pm.hasDefaultValue);
50 Expect.isFalse(pm.isPrivate);
51 Expect.isFalse(pm.isStatic);
52 Expect.isFalse(pm.isTopLevel);
53
54 pm = reflectClass(Class).constructors[#Class.optPos].parameters.single;
55 Expect.equals(#stringField, pm.simpleName);
56 Expect.equals(reflectClass(String), pm.type); /// 01: ok
57 Expect.isFalse(pm.isNamed);
58 Expect.isFalse(pm.isFinal);
59 Expect.isTrue(pm.isOptional);
60 Expect.isTrue(pm.hasDefaultValue);
61 Expect.equals('default', pm.defaultValue.reflectee);
62 Expect.isFalse(pm.isPrivate);
63 Expect.isFalse(pm.isStatic);
64 Expect.isFalse(pm.isTopLevel);
65
66 pm = reflectClass(Class).constructors[#Class.generic].parameters.single;
67 Expect.equals(#tField, pm.simpleName);
68 Expect.equals(reflectClass(Class).typeVariables.single, pm.type); /// 01: ok
69 Expect.isFalse(pm.isNamed);
70 Expect.isFalse(pm.isFinal);
71 Expect.isFalse(pm.isOptional);
72 Expect.isFalse(pm.hasDefaultValue);
73 Expect.isFalse(pm.isPrivate);
74 Expect.isFalse(pm.isStatic);
75 Expect.isFalse(pm.isTopLevel);
76
77 pm = reflectClass(Class).constructors[#Class.private].parameters.single;
78 Expect.equals(#_privateField, pm.simpleName);
79 Expect.equals(currentMirrorSystem().dynamicType, pm.type);
80 Expect.isFalse(pm.isNamed);
81 Expect.isFalse(pm.isFinal);
82 Expect.isFalse(pm.isOptional);
83 Expect.isFalse(pm.hasDefaultValue);
84 Expect.isTrue(pm.isPrivate);
85 Expect.isFalse(pm.isStatic);
86 Expect.isFalse(pm.isTopLevel);
87
88 pm = reflectClass(Constant).constructors[#Constant].parameters.single;
89 Expect.equals(#value, pm.simpleName);
90 Expect.equals(currentMirrorSystem().dynamicType, pm.type);
91 Expect.isFalse(pm.isNamed);
92 Expect.isTrue(pm.isFinal); /// 01: ok
gbracha 2013/10/03 23:20:01 Hm, this seems a bit speculative.
rmacnak 2013/10/04 01:17:36 Fixed and added case where it really is final.
93 Expect.isFalse(pm.isOptional);
94 Expect.isFalse(pm.hasDefaultValue);
95 Expect.isFalse(pm.isPrivate);
96 Expect.isFalse(pm.isStatic);
97 Expect.isFalse(pm.isTopLevel);
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698