| 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 27 matching lines...) Expand all Loading... |
| 38 testInvoke(mirrors) { | 38 testInvoke(mirrors) { |
| 39 var instance = new Class(); | 39 var instance = new Class(); |
| 40 var instMirror = reflect(instance); | 40 var instMirror = reflect(instance); |
| 41 | 41 |
| 42 expect(instMirror.invoke(const Symbol("m"),['A', 'B', instance]).reflectee, | 42 expect(instMirror.invoke(const Symbol("m"),['A', 'B', instance]).reflectee, |
| 43 equals({"a": 'A', "b":'B', "c": instance})); | 43 equals({"a": 'A', "b":'B', "c": instance})); |
| 44 expect(instMirror.invoke(const Symbol("notDefined"), []).reflectee, | 44 expect(instMirror.invoke(const Symbol("notDefined"), []).reflectee, |
| 45 equals("DNU")); | 45 equals("DNU")); |
| 46 expect(instMirror.invoke(const Symbol("m"), []).reflectee, | 46 expect(instMirror.invoke(const Symbol("m"), []).reflectee, |
| 47 equals("DNU")); // Wrong arity. | 47 equals("DNU")); // Wrong arity. |
| 48 // TODO(rmacnak): Implement access to private members. | 48 // TODO(rmacnak): Implement access to private members. |
| 49 // expect(instMirror.invoke(const Symbol("_n"), [3, 4]).reflectee, | 49 // expect(instMirror.invoke(const Symbol("_n"), [3, 4]).reflectee, |
| 50 // equals(7)); | 50 // equals(7)); |
| 51 | 51 |
| 52 var classMirror = instMirror.type; | 52 var classMirror = instMirror.type; |
| 53 expect(classMirror.invoke(const Symbol("s"),['A', 'B', instance]).reflectee, | 53 expect(classMirror.invoke(const Symbol("s"),['A', 'B', instance]).reflectee, |
| 54 equals({"a": 'A', "b":'B', "c": instance})); | 54 equals({"a": 'A', "b":'B', "c": instance})); |
| 55 expect(() => classMirror.invoke(const Symbol("notDefined"), []).reflectee, | 55 expect(() => classMirror.invoke(const Symbol("notDefined"), []).reflectee, |
| 56 throws); | 56 throws); |
| 57 expect(() => classMirror.invoke(const Symbol("s"), []).reflectee, | 57 expect(() => classMirror.invoke(const Symbol("s"), []).reflectee, |
| 58 throws); // Wrong arity. | 58 throws); // Wrong arity. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 var methodMirror = libMirror.functions[const Symbol('testNames')]; | 233 var methodMirror = libMirror.functions[const Symbol('testNames')]; |
| 234 var variableMirror = classMirror.variables[const Symbol('field')]; | 234 var variableMirror = classMirror.variables[const Symbol('field')]; |
| 235 | 235 |
| 236 expect(libMirror.simpleName, equals(const Symbol('MirrorsTest'))); | 236 expect(libMirror.simpleName, equals(const Symbol('MirrorsTest'))); |
| 237 expect(libMirror.qualifiedName, equals(const Symbol('MirrorsTest'))); | 237 expect(libMirror.qualifiedName, equals(const Symbol('MirrorsTest'))); |
| 238 | 238 |
| 239 expect(classMirror.simpleName, equals(const Symbol('Class'))); | 239 expect(classMirror.simpleName, equals(const Symbol('Class'))); |
| 240 expect(classMirror.qualifiedName, equals(const Symbol('MirrorsTest.Class'))); | 240 expect(classMirror.qualifiedName, equals(const Symbol('MirrorsTest.Class'))); |
| 241 | 241 |
| 242 if (!isDart2js) { // TODO(ahe): Implement this in dart2js. | 242 if (!isDart2js) { // TODO(ahe): Implement this in dart2js. |
| 243 TypeVariableMirror typeVariable = classMirror.typeVariables.values.single; | 243 TypeVariableMirror typeVariable = classMirror.typeVariables.single; |
| 244 expect(typeVariable.simpleName, equals(const Symbol('T'))); | 244 expect(typeVariable.simpleName, equals(const Symbol('T'))); |
| 245 expect(typeVariable.qualifiedName, | 245 expect(typeVariable.qualifiedName, |
| 246 equals(const Symbol('MirrorsTest.Class.T'))); | 246 equals(const Symbol('MirrorsTest.Class.T'))); |
| 247 | 247 |
| 248 expect(typedefMirror.simpleName, equals(const Symbol('Typedef'))); | 248 expect(typedefMirror.simpleName, equals(const Symbol('Typedef'))); |
| 249 expect(typedefMirror.qualifiedName, | 249 expect(typedefMirror.qualifiedName, |
| 250 equals(const Symbol('MirrorsTest.Typedef'))); | 250 equals(const Symbol('MirrorsTest.Typedef'))); |
| 251 | 251 |
| 252 var typedefMirrorDeNovo = reflectClass(Typedef); | 252 var typedefMirrorDeNovo = reflectClass(Typedef); |
| 253 expect(typedefMirrorDeNovo.simpleName, equals(const Symbol('Typedef'))); | 253 expect(typedefMirrorDeNovo.simpleName, equals(const Symbol('Typedef'))); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 282 test("Test current library uri", () { | 282 test("Test current library uri", () { |
| 283 testLibraryUri(new Class(), | 283 testLibraryUri(new Class(), |
| 284 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 284 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
| 285 }); | 285 }); |
| 286 test("Test dart library uri", () { | 286 test("Test dart library uri", () { |
| 287 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 287 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
| 288 }); | 288 }); |
| 289 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 289 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 290 test("Test reflect type", () { testReflectClass(mirrors); }); | 290 test("Test reflect type", () { testReflectClass(mirrors); }); |
| 291 } | 291 } |
| OLD | NEW |