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

Side by Side Diff: tests/lib/mirrors/mirrors_test.dart

Issue 10834056: Added InterfaceMirror.newInstance(). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // TODO(rmacnak): Move the existing mirror tests here (a place for 5 // TODO(rmacnak): Move the existing mirror tests here (a place for
6 // cross-implementation tests). 6 // cross-implementation tests).
7 7
8 #library("MirrorsTest.dart"); 8 #library("MirrorsTest.dart");
9 #import("dart:mirrors"); 9 #import("dart:mirrors");
10 #import("../../../lib/unittest/unittest.dart"); 10 #import("../../../lib/unittest/unittest.dart");
11 11
12 var topLevelField; 12 var topLevelField;
13 13
14 class Class { 14 class Class {
15 Class() { this.field = "default value"; }
16 Class.withInitialValue(this.field);
15 var field; 17 var field;
16 static var staticField; 18 static var staticField;
17 } 19 }
18 20
19 testFieldAccess(mirrors) { 21 testFieldAccess(mirrors) {
20 var instance = new Class(); 22 var instance = new Class();
21 23
22 var libMirror = mirrors.libraries()["MirrorsTest.dart"]; 24 var libMirror = mirrors.libraries()["MirrorsTest.dart"];
23 var classMirror = libMirror.classes()["Class"]; 25 var classMirror = libMirror.classes()["Class"];
24 var instMirror = mirrors.mirrorOf(instance); 26 var instMirror = mirrors.mirrorOf(instance);
(...skipping 29 matching lines...) Expand all
54 var funcMirror = mirror.function(); 56 var funcMirror = mirror.function();
55 expect(funcMirror is MethodMirror, equals(true)); 57 expect(funcMirror is MethodMirror, equals(true));
56 expect(funcMirror.parameters().length, equals(3)); 58 expect(funcMirror.parameters().length, equals(3));
57 59
58 var future = mirror.apply([2, 4, 8]); 60 var future = mirror.apply([2, 4, 8]);
59 future.then(expectAsync1((resultMirror) { 61 future.then(expectAsync1((resultMirror) {
60 expect(resultMirror.reflectee, equals(14)); 62 expect(resultMirror.reflectee, equals(14));
61 })); 63 }));
62 } 64 }
63 65
66 testInvokeConstructor(mirrors) {
67 var libMirror = mirrors.libraries()["MirrorsTest.dart"];
68 var classMirror = libMirror.classes()["Class"];
69
70 var future = classMirror.newInstance('', []);
71 future.then(expectAsync1((resultMirror) {
72 var instance = resultMirror.reflectee;
73 expect(instance is Class, equals(true));
74 expect(instance.field, equals("default value"));
75 }));
76
77 future = classMirror.newInstance('withInitialValue', [45]);
78 future.then(expectAsync1((resultMirror) {
79 var instance = resultMirror.reflectee;
80 expect(instance is Class, equals(true));
81 expect(instance.field, equals(45));
82 }));
83 }
84
64 main() { 85 main() {
65 var mirrors = currentMirrorSystem(); 86 var mirrors = currentMirrorSystem();
66 87
67 test("Test field access", () { testFieldAccess(mirrors); }); 88 test("Test field access", () { testFieldAccess(mirrors); });
68 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); 89 test("Test closure mirrors", () { testClosureMirrors(mirrors); });
90 test("Test invoke constructor", () { testInvokeConstructor(mirrors); });
69 } 91 }
70 92
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698