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

Unified Diff: tests/lib/mirrors/mirrors_test.dart

Issue 14044007: Add synchronous mirror API. Resurrects invoke, apply, newInstance, getField and setField as synchro… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/mirrors/mirrors.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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); });
« no previous file with comments | « sdk/lib/mirrors/mirrors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698