OLD | NEW |
---|---|
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; | 8 library MirrorsTest; |
9 import "dart:mirrors"; | 9 import "dart:mirrors"; |
10 import "../../../pkg/unittest/lib/unittest.dart"; | 10 import "../../../pkg/unittest/lib/unittest.dart"; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 })); | 97 })); |
98 | 98 |
99 instMirror.setFieldAsync(const Symbol('field'), 44); | 99 instMirror.setFieldAsync(const Symbol('field'), 44); |
100 future = instMirror.getFieldAsync(const Symbol('field')); | 100 future = instMirror.getFieldAsync(const Symbol('field')); |
101 future.then(expectAsync1((resultMirror) { | 101 future.then(expectAsync1((resultMirror) { |
102 expect(resultMirror.reflectee, equals(44)); | 102 expect(resultMirror.reflectee, equals(44)); |
103 expect(instance.field, equals(44)); | 103 expect(instance.field, equals(44)); |
104 })); | 104 })); |
105 } | 105 } |
106 | 106 |
107 testClosureMirrors(mirrors) { | 107 testClosureMirrors(mirrors) { |
kasperl
2013/05/24 06:46:01
Add a TODO here to add tests for optional paramete
ahe
2013/05/24 11:57:37
Done.
| |
108 var closure = (x, y, z) { return x + y + z; }; | 108 var closure = (x, y, z) { return x + y + z; }; |
109 | 109 |
110 var mirror = reflect(closure); | 110 var mirror = reflect(closure); |
111 expect(mirror is ClosureMirror, equals(true)); | 111 expect(mirror is ClosureMirror, equals(true)); |
112 | 112 |
113 var funcMirror = mirror.function; | 113 var funcMirror = mirror.function; |
114 expect(funcMirror is MethodMirror, equals(true)); | 114 expect(funcMirror is MethodMirror, equals(true)); |
115 expect(funcMirror.parameters.length, equals(3)); | 115 expect(funcMirror.parameters.length, equals(3)); |
116 | 116 |
117 expect(mirror.apply([7, 8, 9]).reflectee, equals(24)); | 117 expect(mirror.apply([7, 8, 9]).reflectee, equals(24)); |
118 | 118 |
119 var future = mirror.applyAsync([2, 4, 8]); | 119 var future = mirror.applyAsync([2, 4, 8]); |
kasperl
2013/05/24 06:46:01
Should this be rewritten (not in this CL) to use a
ahe
2013/05/24 06:56:56
Not sure if you're suggesting a change to dart:mir
| |
120 future.then(expectAsync1((resultMirror) { | 120 future.then(expectAsync1((resultMirror) { |
121 expect(resultMirror.reflectee, equals(14)); | 121 expect(resultMirror.reflectee, equals(14)); |
122 })); | 122 })); |
123 } | 123 } |
124 | 124 |
125 testInvokeConstructor(mirrors) { | 125 testInvokeConstructor(mirrors) { |
126 var classMirror = reflectClass(Class); | 126 var classMirror = reflectClass(Class); |
127 | 127 |
128 var instanceMirror = classMirror.newInstance(const Symbol(''),[]); | 128 var instanceMirror = classMirror.newInstance(const Symbol(''),[]); |
129 expect(instanceMirror.reflectee is Class, equals(true)); | 129 expect(instanceMirror.reflectee is Class, equals(true)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 LibraryMirror valueLibrary = valueClass.owner; | 197 LibraryMirror valueLibrary = valueClass.owner; |
198 expect(check(valueLibrary.uri), isTrue); | 198 expect(check(valueLibrary.uri), isTrue); |
199 } | 199 } |
200 | 200 |
201 mainWithArgument({bool isDart2js}) { | 201 mainWithArgument({bool isDart2js}) { |
202 var mirrors = currentMirrorSystem(); | 202 var mirrors = currentMirrorSystem(); |
203 test("Test reflective method invocation", () { testInvoke(mirrors); }); | 203 test("Test reflective method invocation", () { testInvoke(mirrors); }); |
204 test("Test instance field access", () { testInstanceFieldAccess(mirrors); }); | 204 test("Test instance field access", () { testInstanceFieldAccess(mirrors); }); |
205 test('Test intercepted objects', () { testIntercepted(mirrors); }); | 205 test('Test intercepted objects', () { testIntercepted(mirrors); }); |
206 test("Test field access", () { testFieldAccess(mirrors); }); | 206 test("Test field access", () { testFieldAccess(mirrors); }); |
207 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); | |
207 if (isDart2js) return; | 208 if (isDart2js) return; |
208 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); | |
209 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); | 209 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |
210 test("Test reflect type", () { testReflectClass(mirrors); }); | 210 test("Test reflect type", () { testReflectClass(mirrors); }); |
211 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 211 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
212 test("Test current library uri", () { | 212 test("Test current library uri", () { |
213 testLibraryUri(new Class(), | 213 testLibraryUri(new Class(), |
214 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 214 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
215 }); | 215 }); |
216 test("Test dart library uri", () { | 216 test("Test dart library uri", () { |
217 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 217 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
218 }); | 218 }); |
219 } | 219 } |
220 | 220 |
221 main() { | 221 main() { |
222 mainWithArgument(isDart2js: false); | 222 mainWithArgument(isDart2js: false); |
223 } | 223 } |
OLD | NEW |