Chromium Code Reviews| 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 library MirrorsTest; | 5 library MirrorsTest; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import '../../light_unittest.dart'; | 9 import '../../light_unittest.dart'; |
| 10 | 10 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 expect(instanceMirror.reflectee is Class, equals(true)); | 189 expect(instanceMirror.reflectee is Class, equals(true)); |
| 190 expect(instanceMirror.reflectee.field, equals(16)); | 190 expect(instanceMirror.reflectee.field, equals(16)); |
| 191 | 191 |
| 192 instanceMirror = classMirror.newInstance(const Symbol('faktory'), | 192 instanceMirror = classMirror.newInstance(const Symbol('faktory'), |
| 193 [9]); | 193 [9]); |
| 194 expect(instanceMirror.reflectee is Class, equals(true)); | 194 expect(instanceMirror.reflectee is Class, equals(true)); |
| 195 expect(instanceMirror.reflectee.field, equals(27)); | 195 expect(instanceMirror.reflectee.field, equals(27)); |
| 196 | 196 |
| 197 instanceMirror = classMirror.newInstance(const Symbol('redirectingFactory'), | 197 instanceMirror = classMirror.newInstance(const Symbol('redirectingFactory'), |
| 198 [10]); | 198 [10]); |
| 199 if (!isDart2js) { | 199 expect(instanceMirror.reflectee is Class, equals(true)); |
| 200 expect(instanceMirror.reflectee is Class, equals(true)); | 200 expect(instanceMirror.reflectee.field, equals(30)); |
| 201 expect(instanceMirror.reflectee.field, equals(30)); | |
| 202 } | |
| 203 | 201 |
| 204 | 202 |
| 205 var future = classMirror.newInstanceAsync(const Symbol(''), []); | 203 var future = classMirror.newInstanceAsync(const Symbol(''), []); |
| 206 future.then(expectAsync1((resultMirror) { | 204 future.then(expectAsync1((resultMirror) { |
| 207 var instance = resultMirror.reflectee; | 205 var instance = resultMirror.reflectee; |
| 208 expect(instance is Class, equals(true)); | 206 expect(instance is Class, equals(true)); |
| 209 expect(instance.field, equals("default value")); | 207 expect(instance.field, equals("default value")); |
| 210 })); | 208 })); |
| 211 | 209 |
| 212 future = classMirror.newInstanceAsync(const Symbol('withInitialValue'), [45]); | 210 future = classMirror.newInstanceAsync(const Symbol('withInitialValue'), [45]); |
| 213 future.then(expectAsync1((resultMirror) { | 211 future.then(expectAsync1((resultMirror) { |
| 214 var instance = resultMirror.reflectee; | 212 var instance = resultMirror.reflectee; |
| 215 expect(instance is Class, equals(true)); | 213 expect(instance is Class, equals(true)); |
| 216 expect(instance.field, equals(45)); | 214 expect(instance.field, equals(45)); |
| 217 })); | 215 })); |
| 218 } | 216 } |
| 219 | 217 |
| 220 testReflectClass(mirrors) { | 218 testReflectClass(mirrors) { |
| 221 var classMirror = reflectClass(Class); | 219 var classMirror = reflectClass(Class); |
| 222 expect(classMirror is ClassMirror, equals(true)); | 220 expect(classMirror is ClassMirror, equals(true)); |
| 223 var symbolClassMirror = reflectClass(Symbol); | 221 var symbolClassMirror = reflectClass(Symbol); |
| 224 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), | 222 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), |
| 225 ['withInitialValue']); | 223 ['withInitialValue']); |
| 226 if (isDart2js) return; | 224 if (isDart2js) return; |
|
ahe
2013/09/17 10:06:03
Can you remove this one as well?
ngeoffray
2013/09/17 12:02:24
Done.
| |
| 227 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); | 225 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); |
| 228 expect(objectMirror.reflectee is Class, equals(true)); | 226 expect(objectMirror.reflectee is Class, equals(true)); |
| 229 expect(objectMirror.reflectee.field, equals(1234)); | 227 expect(objectMirror.reflectee.field, equals(1234)); |
| 230 } | 228 } |
| 231 | 229 |
| 232 testNames(mirrors) { | 230 testNames(mirrors) { |
| 233 var libMirror = mirrors.findLibrary(const Symbol("MirrorsTest")).single; | 231 var libMirror = mirrors.findLibrary(const Symbol("MirrorsTest")).single; |
| 234 var classMirror = libMirror.classes[const Symbol('Class')]; | 232 var classMirror = libMirror.classes[const Symbol('Class')]; |
| 235 var typedefMirror = libMirror.members[const Symbol('Typedef')]; | 233 var typedefMirror = libMirror.members[const Symbol('Typedef')]; |
| 236 var methodMirror = libMirror.functions[const Symbol('testNames')]; | 234 var methodMirror = libMirror.functions[const Symbol('testNames')]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 test("Test current library uri", () { | 283 test("Test current library uri", () { |
| 286 testLibraryUri(new Class(), | 284 testLibraryUri(new Class(), |
| 287 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 285 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
| 288 }); | 286 }); |
| 289 test("Test dart library uri", () { | 287 test("Test dart library uri", () { |
| 290 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 288 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
| 291 }); | 289 }); |
| 292 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 290 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 293 test("Test reflect type", () { testReflectClass(mirrors); }); | 291 test("Test reflect type", () { testReflectClass(mirrors); }); |
| 294 } | 292 } |
| OLD | NEW |