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

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

Issue 13942008: - Add synchronous mirror API. Resurrects invoke, apply, newInstance, (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 21575)
+++ tests/lib/mirrors/mirrors_test.dart (working copy)
@@ -16,10 +16,19 @@
Class.withInitialValue(this.field);
var field;
static var staticField;
+ m(a, b, c) => {"a": a, "b": b, "c": c};
}
typedef Typedef();
+testInvoke(mirrors) {
+ var instance = new Class();
+ var instMirror = reflect(instance);
+
+ expect(instMirror.invoke(const Symbol("m"),['A', 'B', instance]).reflectee,
+ equals({"a": 'A', "b":'B', "c": instance}));
+}
+
testFieldAccess(mirrors) {
var instance = new Class();
@@ -27,6 +36,11 @@
var classMirror = libMirror.classes[const Symbol("Class")];
var instMirror = reflect(instance);
+ libMirror.setField(const Symbol('topLevelField'), [91]);
+ expect(libMirror.getField(const Symbol('topLevelField')).reflectee,
+ equals([91]));
+ expect(topLevelField, equals([91]));
+
libMirror.setFieldAsync(new Symbol('topLevelField'), 42);
var future = libMirror.getFieldAsync(new Symbol('topLevelField'));
future.then(expectAsync1((resultMirror) {
@@ -59,6 +73,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));
@@ -69,6 +85,15 @@
var libMirror = mirrors.libraries[const Symbol("MirrorsTest")];
var classMirror = libMirror.classes[const Symbol("Class")];
+ var instanceMirror = classMirror.newInstance(const Symbol(''),[]);
+ expect(instanceMirror.reflectee is Class, equals(true));
+ expect(instanceMirror.reflectee.field, equals("default value"));
+
+ instanceMirror = classMirror.newInstance(const Symbol('withInitialValue'),
+ [45]);
+ expect(instanceMirror.reflectee is Class, equals(true));
+ expect(instanceMirror.reflectee.field, equals(45));
+
var future = classMirror.newInstanceAsync(new Symbol(''), []);
future.then(expectAsync1((resultMirror) {
var instance = resultMirror.reflectee;
@@ -117,7 +142,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