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

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

Issue 11598006: Concept of how dart:mirrors LibraryMirror, ClassMirror can be implemented in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added enough closure support to get tests/lib/mirrors/mirrors_test.dart pass. Created 7 years, 12 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 | « tests/lib/lib.status ('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
diff --git a/tests/lib/mirrors/mirrors_test.dart b/tests/lib/mirrors/mirrors_test.dart
index 14ab43649a7933f3098ddcaf701621ae8865c29d..41d86d991220fbd584562fca37f2e1ede3f69a62 100644
--- a/tests/lib/mirrors/mirrors_test.dart
+++ b/tests/lib/mirrors/mirrors_test.dart
@@ -7,7 +7,8 @@
library MirrorsTest;
import "dart:mirrors";
-import "../../../pkg/unittest/lib/unittest.dart";
+
+import '../../compiler/dart2js_extra/async_helper.dart';
var topLevelField;
@@ -18,75 +19,115 @@ class Class {
static var staticField;
}
-testFieldAccess(mirrors) {
+void testFieldAccess(mirrors) {
+ var dummyInstance = new Class.withInitialValue(123);
+
var instance = new Class();
var libMirror = mirrors.libraries["MirrorsTest"];
var classMirror = libMirror.classes["Class"];
var instMirror = reflect(instance);
- libMirror.setField('topLevelField', 42);
- var future = libMirror.getField('topLevelField');
- future.then(expectAsync1((resultMirror) {
- expect(resultMirror.reflectee, equals(42));
- expect(topLevelField, equals(42));
- }));
+ asyncTest((onDone) {
+ libMirror.setField('topLevelField', 42).then(
+ (result) {
+ libMirror.getField('topLevelField').then(
+ (resultMirror) {
+ Expect.equals(42, resultMirror.reflectee);
+ Expect.equals(42, topLevelField);
+ onDone(true);
+ });
+ });
+ });
- classMirror.setField('staticField', 43);
- future = classMirror.getField('staticField');
- future.then(expectAsync1((resultMirror) {
- expect(resultMirror.reflectee, equals(43));
- expect(Class.staticField, equals(43));
- }));
-
- instMirror.setField('field', 44);
- future = instMirror.getField('field');
- future.then(expectAsync1((resultMirror) {
- expect(resultMirror.reflectee, equals(44));
- expect(instance.field, equals(44));
- }));
+ asyncTest((onDone) {
+ classMirror.setField('staticField', 43).then(
+ (result) {
+ classMirror.getField('staticField').then(
+ (resultMirror) {
+ Expect.equals(43, resultMirror.reflectee);
+ Expect.equals(43, Class.staticField);
+ onDone(true);
+ });
+ });
+ });
+
+ asyncTest((onDone) {
+ instMirror.setField('field', 44).then(
+ (result) {
+ instMirror.getField('field').then(
+ (resultMirror) {
+ Expect.equals(44, resultMirror.reflectee);
+ Expect.equals(44, instance.field);
+ onDone(true);
+ });
+ });
+ });
}
testClosureMirrors(mirrors) {
var closure = (x, y, z) { return x + y + z; };
var mirror = reflect(closure);
- expect(mirror is ClosureMirror, equals(true));
+ Expect.isTrue(mirror is ClosureMirror);
var funcMirror = mirror.function;
- expect(funcMirror is MethodMirror, equals(true));
- expect(funcMirror.parameters.length, equals(3));
+ Expect.isTrue(funcMirror is MethodMirror);
+ Expect.equals(3, funcMirror.parameters.length);
- var future = mirror.apply([2, 4, 8]);
- future.then(expectAsync1((resultMirror) {
- expect(resultMirror.reflectee, equals(14));
- }));
+ asyncTest((onDone) {
+ mirror.apply([2, 4, 8]).then(
+ (resultMirror) {
+ Expect.equals(14, resultMirror.reflectee);
+ onDone(true);
+ });
+ });
}
testInvokeConstructor(mirrors) {
var libMirror = mirrors.libraries["MirrorsTest"];
var classMirror = libMirror.classes["Class"];
- var future = classMirror.newInstance('', []);
- future.then(expectAsync1((resultMirror) {
- var instance = resultMirror.reflectee;
- expect(instance is Class, equals(true));
- expect(instance.field, equals("default value"));
- }));
-
- future = classMirror.newInstance('withInitialValue', [45]);
- future.then(expectAsync1((resultMirror) {
- var instance = resultMirror.reflectee;
- expect(instance is Class, equals(true));
- expect(instance.field, equals(45));
- }));
+ asyncTest((onDone) {
+ classMirror.newInstance('', []).then(
+ (resultMirror) {
+ var instance = resultMirror.reflectee;
+ Expect.isTrue(instance is Class);
+ Expect.equals("default value", instance.field);
+ onDone(true);
+ });
+ });
+
+ asyncTest((onDone) {
+ classMirror.newInstance('withInitialValue', [45]).then(
+ (resultMirror) {
+ var instance = resultMirror.reflectee;
+ Expect.isTrue(instance is Class);
+ Expect.equals(45, instance.field);
+ onDone(true);
+ });
+ });
}
main() {
+ print("""
+
+This program is using an experimental feature called \"mirrors\". As
+currently implemented, mirrors do not work with minification, and will
+cause spurious errors depending on how code was optimized.
+
+The authors of this program are aware of these problems and have
+decided the thrill of using an experimental feature is outweighing the
+risks. Furthermore, the authors of this program understand that
+long-term, to fix the problems mentioned above, mirrors may have
+negative impact on size and performance of Dart programs compiled to
+JavaScript.
+""");
+
var mirrors = currentMirrorSystem();
- test("Test field access", () { testFieldAccess(mirrors); });
- test("Test closure mirrors", () { testClosureMirrors(mirrors); });
- test("Test invoke constructor", () { testInvokeConstructor(mirrors); });
+ testFieldAccess(mirrors);
+ testClosureMirrors(mirrors);
+ testInvokeConstructor(mirrors);
}
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698