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 // 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 })); | 102 })); |
| 103 | 103 |
| 104 future = classMirror.newInstanceAsync(new Symbol('withInitialValue'), [45]); | 104 future = classMirror.newInstanceAsync(new Symbol('withInitialValue'), [45]); |
| 105 future.then(expectAsync1((resultMirror) { | 105 future.then(expectAsync1((resultMirror) { |
| 106 var instance = resultMirror.reflectee; | 106 var instance = resultMirror.reflectee; |
| 107 expect(instance is Class, equals(true)); | 107 expect(instance is Class, equals(true)); |
| 108 expect(instance.field, equals(45)); | 108 expect(instance.field, equals(45)); |
| 109 })); | 109 })); |
| 110 } | 110 } |
| 111 | 111 |
| 112 testReflectClass(mirrors) { | |
| 113 var classMirror = reflectClass(Class); | |
| 114 expect(classMirror is ClassMirror, equals(true)); | |
| 115 var symbolClassMirror = reflectClass(Symbol); | |
| 116 var symbolMirror = symbolClassMirror.newInstance(const Symbol(''), | |
| 117 ['withInitialValue']); | |
| 118 var objectMirror = classMirror.newInstance(symbolMirror.reflectee,[1234]); | |
|
ahe
2013/04/17 10:40:17
I'm not sure why you created a symbol mirror here,
ahe
2013/04/17 10:40:17
Missing space after ,
| |
| 119 expect(objectMirror.reflectee is Class, equals(true)); | |
| 120 expect(objectMirror.reflectee.field, equals(1234)); | |
| 121 } | |
| 122 | |
| 112 testNames(mirrors) { | 123 testNames(mirrors) { |
| 113 var libMirror = mirrors.libraries[const Symbol('MirrorsTest')]; | 124 var libMirror = mirrors.libraries[const Symbol('MirrorsTest')]; |
| 114 var classMirror = libMirror.classes[const Symbol('Class')]; | 125 var classMirror = libMirror.classes[const Symbol('Class')]; |
| 115 var typedefMirror = libMirror.members[const Symbol('Typedef')]; | 126 var typedefMirror = libMirror.members[const Symbol('Typedef')]; |
| 116 var methodMirror = libMirror.functions[const Symbol('testNames')]; | 127 var methodMirror = libMirror.functions[const Symbol('testNames')]; |
| 117 var variableMirror = classMirror.variables[const Symbol('field')]; | 128 var variableMirror = classMirror.variables[const Symbol('field')]; |
| 118 | 129 |
| 119 expect(libMirror.simpleName, equals(const Symbol('MirrorsTest'))); | 130 expect(libMirror.simpleName, equals(const Symbol('MirrorsTest'))); |
| 120 expect(libMirror.qualifiedName, equals(const Symbol('MirrorsTest'))); | 131 expect(libMirror.qualifiedName, equals(const Symbol('MirrorsTest'))); |
| 121 | 132 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 139 expect(variableMirror.qualifiedName, | 150 expect(variableMirror.qualifiedName, |
| 140 equals(const Symbol('MirrorsTest.Class.field'))); | 151 equals(const Symbol('MirrorsTest.Class.field'))); |
| 141 } | 152 } |
| 142 | 153 |
| 143 main() { | 154 main() { |
| 144 var mirrors = currentMirrorSystem(); | 155 var mirrors = currentMirrorSystem(); |
| 145 test("Test reflective method invocation", () { testInvoke(mirrors); }); | 156 test("Test reflective method invocation", () { testInvoke(mirrors); }); |
| 146 test("Test field access", () { testFieldAccess(mirrors); }); | 157 test("Test field access", () { testFieldAccess(mirrors); }); |
| 147 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); | 158 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
| 148 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); | 159 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |
| 160 test("Test reflect type", () { testReflectClass(mirrors); }); | |
| 149 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 161 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 150 } | 162 } |
| OLD | NEW |