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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 equals('[null, null, null, null, null, null, null, null, null, null,' | 95 equals('[null, null, null, null, null, null, null, null, null, null,' |
96 ' null, null, null, null, null, null, null, null, null, null,' | 96 ' null, null, null, null, null, null, null, null, null, null,' |
97 ' null, null, null, null, null, null, null, null, null, null,' | 97 ' null, null, null, null, null, null, null, null, null, null,' |
98 ' null, null, null, null, null, null, null, null, null, null,' | 98 ' null, null, null, null, null, null, null, null, null, null,' |
99 ' null, null, null, null]')); | 99 ' null, null, null, null]')); |
100 } | 100 } |
101 | 101 |
102 testFieldAccess(mirrors) { | 102 testFieldAccess(mirrors) { |
103 var instance = new Class(); | 103 var instance = new Class(); |
104 | 104 |
105 var libMirror = mirrors.findLibrary(#MirrorsTest).single; | 105 var libMirror = mirrors.findLibrary(#MirrorsTest); |
106 var classMirror = libMirror.classes[#Class]; | 106 var classMirror = libMirror.classes[#Class]; |
107 var instMirror = reflect(instance); | 107 var instMirror = reflect(instance); |
108 var fieldMirror = classMirror.members[#field]; | 108 var fieldMirror = classMirror.members[#field]; |
109 var future; | 109 var future; |
110 | 110 |
111 expect(fieldMirror is VariableMirror, isTrue); | 111 expect(fieldMirror is VariableMirror, isTrue); |
112 expect(fieldMirror.type, equals(mirrors.dynamicType)); | 112 expect(fieldMirror.type, equals(mirrors.dynamicType)); |
113 | 113 |
114 libMirror.setField(#topLevelField, [91]); | 114 libMirror.setField(#topLevelField, [91]); |
115 expect(libMirror.getField(#topLevelField).reflectee, | 115 expect(libMirror.getField(#topLevelField).reflectee, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 expect(classMirror is ClassMirror, equals(true)); | 211 expect(classMirror is ClassMirror, equals(true)); |
212 var symbolClassMirror = reflectClass(Symbol); | 212 var symbolClassMirror = reflectClass(Symbol); |
213 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), | 213 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), |
214 ['withInitialValue']); | 214 ['withInitialValue']); |
215 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); | 215 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); |
216 expect(objectMirror.reflectee is Class, equals(true)); | 216 expect(objectMirror.reflectee is Class, equals(true)); |
217 expect(objectMirror.reflectee.field, equals(1234)); | 217 expect(objectMirror.reflectee.field, equals(1234)); |
218 } | 218 } |
219 | 219 |
220 testNames(mirrors) { | 220 testNames(mirrors) { |
221 var libMirror = mirrors.findLibrary(#MirrorsTest).single; | 221 var libMirror = mirrors.findLibrary(#MirrorsTest); |
222 var classMirror = libMirror.classes[#Class]; | 222 var classMirror = libMirror.classes[#Class]; |
223 var typedefMirror = libMirror.members[#Typedef]; | 223 var typedefMirror = libMirror.members[#Typedef]; |
224 var methodMirror = libMirror.functions[#testNames]; | 224 var methodMirror = libMirror.functions[#testNames]; |
225 var variableMirror = classMirror.variables[#field]; | 225 var variableMirror = classMirror.variables[#field]; |
226 | 226 |
227 expect(libMirror.simpleName, equals(#MirrorsTest)); | 227 expect(libMirror.simpleName, equals(#MirrorsTest)); |
228 expect(libMirror.qualifiedName, equals(#MirrorsTest)); | 228 expect(libMirror.qualifiedName, equals(#MirrorsTest)); |
229 | 229 |
230 expect(classMirror.simpleName, equals(#Class)); | 230 expect(classMirror.simpleName, equals(#Class)); |
231 expect(classMirror.qualifiedName, equals(#MirrorsTest.Class)); | 231 expect(classMirror.qualifiedName, equals(#MirrorsTest.Class)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 test("Test current library uri", () { | 273 test("Test current library uri", () { |
274 testLibraryUri(new Class(), | 274 testLibraryUri(new Class(), |
275 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 275 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
276 }); | 276 }); |
277 test("Test dart library uri", () { | 277 test("Test dart library uri", () { |
278 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 278 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
279 }); | 279 }); |
280 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 280 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
281 test("Test reflect type", () { testReflectClass(mirrors); }); | 281 test("Test reflect type", () { testReflectClass(mirrors); }); |
282 } | 282 } |
OLD | NEW |