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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ' null, null, null, null, null, null, null, null, null, null,' | 84 ' null, null, null, null, null, null, null, null, null, null,' |
85 ' null, null, null, null, null, null, null, null, null, null,' | 85 ' null, null, null, null, null, null, null, null, null, null,' |
86 ' null, null, null, null, null, null, null, null, null, null,' | 86 ' null, null, null, null, null, null, null, null, null, null,' |
87 ' null, null, null, null]')); | 87 ' null, null, null, null]')); |
88 } | 88 } |
89 | 89 |
90 testFieldAccess(mirrors) { | 90 testFieldAccess(mirrors) { |
91 var instance = new Class(); | 91 var instance = new Class(); |
92 | 92 |
93 var libMirror = mirrors.findLibrary(#MirrorsTest); | 93 var libMirror = mirrors.findLibrary(#MirrorsTest); |
94 var classMirror = libMirror.classes[#Class]; | 94 var classMirror = libMirror.declarations[#Class]; |
95 var instMirror = reflect(instance); | 95 var instMirror = reflect(instance); |
96 var fieldMirror = classMirror.members[#field]; | 96 var fieldMirror = classMirror.declarations[#field]; |
97 var future; | 97 var future; |
98 | 98 |
99 expect(fieldMirror is VariableMirror, isTrue); | 99 expect(fieldMirror is VariableMirror, isTrue); |
100 expect(fieldMirror.type, equals(mirrors.dynamicType)); | 100 expect(fieldMirror.type, equals(mirrors.dynamicType)); |
101 | 101 |
102 libMirror.setField(#topLevelField, [91]); | 102 libMirror.setField(#topLevelField, [91]); |
103 expect(libMirror.getField(#topLevelField).reflectee, | 103 expect(libMirror.getField(#topLevelField).reflectee, |
104 equals([91])); | 104 equals([91])); |
105 expect(topLevelField, equals([91])); | 105 expect(topLevelField, equals([91])); |
106 } | 106 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 var symbolClassMirror = reflectClass(Symbol); | 159 var symbolClassMirror = reflectClass(Symbol); |
160 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), | 160 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), |
161 ['withInitialValue']); | 161 ['withInitialValue']); |
162 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); | 162 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); |
163 expect(objectMirror.reflectee is Class, equals(true)); | 163 expect(objectMirror.reflectee is Class, equals(true)); |
164 expect(objectMirror.reflectee.field, equals(1234)); | 164 expect(objectMirror.reflectee.field, equals(1234)); |
165 } | 165 } |
166 | 166 |
167 testNames(mirrors) { | 167 testNames(mirrors) { |
168 var libMirror = mirrors.findLibrary(#MirrorsTest); | 168 var libMirror = mirrors.findLibrary(#MirrorsTest); |
169 var classMirror = libMirror.classes[#Class]; | 169 var classMirror = libMirror.declarations[#Class]; |
170 var typedefMirror = libMirror.members[#Typedef]; | 170 var typedefMirror = libMirror.declarations[#Typedef]; |
171 var methodMirror = libMirror.functions[#testNames]; | 171 var methodMirror = libMirror.declarations[#testNames]; |
172 var variableMirror = classMirror.variables[#field]; | 172 var variableMirror = classMirror.declarations[#field]; |
173 | 173 |
174 expect(libMirror.simpleName, equals(#MirrorsTest)); | 174 expect(libMirror.simpleName, equals(#MirrorsTest)); |
175 expect(libMirror.qualifiedName, equals(#MirrorsTest)); | 175 expect(libMirror.qualifiedName, equals(#MirrorsTest)); |
176 | 176 |
177 expect(classMirror.simpleName, equals(#Class)); | 177 expect(classMirror.simpleName, equals(#Class)); |
178 expect(classMirror.qualifiedName, equals(#MirrorsTest.Class)); | 178 expect(classMirror.qualifiedName, equals(#MirrorsTest.Class)); |
179 | 179 |
180 TypeVariableMirror typeVariable = classMirror.typeVariables.single; | 180 TypeVariableMirror typeVariable = classMirror.typeVariables.single; |
181 expect(typeVariable.simpleName, equals(#T)); | 181 expect(typeVariable.simpleName, equals(#T)); |
182 expect(typeVariable.qualifiedName, | 182 expect(typeVariable.qualifiedName, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 test("Test current library uri", () { | 219 test("Test current library uri", () { |
220 testLibraryUri(new Class(), | 220 testLibraryUri(new Class(), |
221 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 221 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
222 }); | 222 }); |
223 test("Test dart library uri", () { | 223 test("Test dart library uri", () { |
224 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 224 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
225 }); | 225 }); |
226 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 226 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
227 test("Test reflect type", () { testReflectClass(mirrors); }); | 227 test("Test reflect type", () { testReflectClass(mirrors); }); |
228 } | 228 } |
OLD | NEW |