Index: tests/lib/mirrors/mirrors_test.dart |
=================================================================== |
--- tests/lib/mirrors/mirrors_test.dart (revision 21243) |
+++ tests/lib/mirrors/mirrors_test.dart (working copy) |
@@ -16,8 +16,16 @@ |
Class.withInitialValue(this.field); |
var field; |
static var staticField; |
+ m(a, b, c) => {"a": a, "b": b, "c": c}; |
} |
+testInvoke(mirrors) { |
+ var instance = new Class(); |
+ var instMirror = reflect(instance); |
+ |
+ expect(instMirror.invoke("m",['A', 'B', instance]).reflectee, equals({"a": 'A', "b":'B', "c": instance})); |
+} |
+ |
testFieldAccess(mirrors) { |
var instance = new Class(); |
@@ -25,6 +33,10 @@ |
var classMirror = libMirror.classes["Class"]; |
var instMirror = reflect(instance); |
+ libMirror.setField('topLevelField', [91]); |
+ expect(libMirror.getField('topLevelField').reflectee, equals([91])); |
+ expect(topLevelField, equals([91])); |
+ |
libMirror.setFieldAsync('topLevelField', 42); |
var future = libMirror.getFieldAsync('topLevelField'); |
future.then(expectAsync1((resultMirror) { |
@@ -57,6 +69,8 @@ |
expect(funcMirror is MethodMirror, equals(true)); |
expect(funcMirror.parameters.length, equals(3)); |
+ expect(mirror.apply([7, 8, 9]).reflectee, equals(24)); |
+ |
var future = mirror.applyAsync([2, 4, 8]); |
future.then(expectAsync1((resultMirror) { |
expect(resultMirror.reflectee, equals(14)); |
@@ -67,6 +81,15 @@ |
var libMirror = mirrors.libraries["MirrorsTest"]; |
var classMirror = libMirror.classes["Class"]; |
+ var instanceMirror = classMirror.newInstance('',[]); |
+ expect(instanceMirror.reflectee is Class, equals(true)); |
+ expect(instanceMirror.reflectee.field, equals("default value")); |
+ |
+ instanceMirror = classMirror.newInstance('withInitialValue', [45]); |
+ expect(instanceMirror.reflectee is Class, equals(true)); |
+ expect(instanceMirror.reflectee.field, equals(45)); |
+ |
+ |
var future = classMirror.newInstanceAsync('', []); |
future.then(expectAsync1((resultMirror) { |
var instance = resultMirror.reflectee; |
@@ -84,7 +107,7 @@ |
main() { |
var mirrors = currentMirrorSystem(); |
- |
+ test("Test reflective method invocation", () { testInvoke(mirrors); }); |
test("Test field access", () { testFieldAccess(mirrors); }); |
test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |