Chromium Code Reviews| Index: tests/lib/mirrors/initializing_formals_test.dart |
| diff --git a/tests/lib/mirrors/initializing_formals_test.dart b/tests/lib/mirrors/initializing_formals_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0f1f03d78d679343e209fbd1aeb7aecfbd8f47b6 |
| --- /dev/null |
| +++ b/tests/lib/mirrors/initializing_formals_test.dart |
| @@ -0,0 +1,98 @@ |
| +// 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.initializing_formals; |
| + |
| +import 'dart:mirrors'; |
| +import 'package:expect/expect.dart'; |
| + |
| +class Class<T> { |
| + int intField; |
| + bool boolField; |
| + String stringField; |
| + T tField; |
| + 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.
|
| + |
| + Class.nongeneric(this.intField); |
| + Class.named({this.boolField}); |
| + Class.optPos([this.stringField = 'default']); |
| + Class.generic(this.tField); |
| + Class.private(this._privateField); |
| +} |
| + |
| +class Constant { |
| + final value; |
| + const Constant(this.value); |
| +} |
| + |
| +main() { |
| + ParameterMirror pm; |
| + |
| + pm = reflectClass(Class).constructors[#Class.nongeneric].parameters.single; |
| + Expect.equals(#intField, pm.simpleName); |
| + Expect.equals(reflectClass(int), pm.type); /// 01: ok |
| + Expect.isFalse(pm.isNamed); |
| + Expect.isFalse(pm.isFinal); |
| + Expect.isFalse(pm.isOptional); |
| + Expect.isFalse(pm.hasDefaultValue); |
| + Expect.isFalse(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| + |
| + pm = reflectClass(Class).constructors[#Class.named].parameters.single; |
| + Expect.equals(#boolField, pm.simpleName); |
| + Expect.equals(reflectClass(bool), pm.type); /// 01: ok |
| + Expect.isTrue(pm.isNamed); |
| + Expect.isFalse(pm.isFinal); |
| + Expect.isTrue(pm.isOptional); |
| + Expect.isFalse(pm.hasDefaultValue); |
| + Expect.isFalse(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| + |
| + pm = reflectClass(Class).constructors[#Class.optPos].parameters.single; |
| + Expect.equals(#stringField, pm.simpleName); |
| + Expect.equals(reflectClass(String), pm.type); /// 01: ok |
| + Expect.isFalse(pm.isNamed); |
| + Expect.isFalse(pm.isFinal); |
| + Expect.isTrue(pm.isOptional); |
| + Expect.isTrue(pm.hasDefaultValue); |
| + Expect.equals('default', pm.defaultValue.reflectee); |
| + Expect.isFalse(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| + |
| + pm = reflectClass(Class).constructors[#Class.generic].parameters.single; |
| + Expect.equals(#tField, pm.simpleName); |
| + Expect.equals(reflectClass(Class).typeVariables.single, pm.type); /// 01: ok |
| + Expect.isFalse(pm.isNamed); |
| + Expect.isFalse(pm.isFinal); |
| + Expect.isFalse(pm.isOptional); |
| + Expect.isFalse(pm.hasDefaultValue); |
| + Expect.isFalse(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| + |
| + pm = reflectClass(Class).constructors[#Class.private].parameters.single; |
| + Expect.equals(#_privateField, pm.simpleName); |
| + Expect.equals(currentMirrorSystem().dynamicType, pm.type); |
| + Expect.isFalse(pm.isNamed); |
| + Expect.isFalse(pm.isFinal); |
| + Expect.isFalse(pm.isOptional); |
| + Expect.isFalse(pm.hasDefaultValue); |
| + Expect.isTrue(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| + |
| + pm = reflectClass(Constant).constructors[#Constant].parameters.single; |
| + Expect.equals(#value, pm.simpleName); |
| + Expect.equals(currentMirrorSystem().dynamicType, pm.type); |
| + Expect.isFalse(pm.isNamed); |
| + 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.
|
| + Expect.isFalse(pm.isOptional); |
| + Expect.isFalse(pm.hasDefaultValue); |
| + Expect.isFalse(pm.isPrivate); |
| + Expect.isFalse(pm.isStatic); |
| + Expect.isFalse(pm.isTopLevel); |
| +} |