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"; |
| 11 import 'dart:uri'; |
11 | 12 |
12 var topLevelField; | 13 var topLevelField; |
13 | 14 |
14 class Class<T> { | 15 class Class<T> { |
15 Class() { this.field = "default value"; } | 16 Class() { this.field = "default value"; } |
16 Class.withInitialValue(this.field); | 17 Class.withInitialValue(this.field); |
17 var field; | 18 var field; |
18 static var staticField; | 19 static var staticField; |
19 m(a, b, c) => {"a": a, "b": b, "c": c}; | 20 m(a, b, c) => {"a": a, "b": b, "c": c}; |
20 } | 21 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 145 |
145 expect(methodMirror.simpleName, equals(const Symbol('testNames'))); | 146 expect(methodMirror.simpleName, equals(const Symbol('testNames'))); |
146 expect(methodMirror.qualifiedName, | 147 expect(methodMirror.qualifiedName, |
147 equals(const Symbol('MirrorsTest.testNames'))); | 148 equals(const Symbol('MirrorsTest.testNames'))); |
148 | 149 |
149 expect(variableMirror.simpleName, equals(const Symbol('field'))); | 150 expect(variableMirror.simpleName, equals(const Symbol('field'))); |
150 expect(variableMirror.qualifiedName, | 151 expect(variableMirror.qualifiedName, |
151 equals(const Symbol('MirrorsTest.Class.field'))); | 152 equals(const Symbol('MirrorsTest.Class.field'))); |
152 } | 153 } |
153 | 154 |
| 155 testLibraryUri(var value, bool check(Uri)) { |
| 156 var valueMirror = reflect(value); |
| 157 ClassMirror valueClass = valueMirror.type; |
| 158 LibraryMirror valueLibrary = valueClass.owner; |
| 159 expect(check(valueLibrary.uri), isTrue); |
| 160 } |
| 161 |
154 main() { | 162 main() { |
155 var mirrors = currentMirrorSystem(); | 163 var mirrors = currentMirrorSystem(); |
156 test("Test reflective method invocation", () { testInvoke(mirrors); }); | 164 test("Test reflective method invocation", () { testInvoke(mirrors); }); |
157 test("Test field access", () { testFieldAccess(mirrors); }); | 165 test("Test field access", () { testFieldAccess(mirrors); }); |
158 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); | 166 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
159 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); | 167 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |
160 test("Test reflect type", () { testReflectClass(mirrors); }); | 168 test("Test reflect type", () { testReflectClass(mirrors); }); |
161 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 169 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 170 test("Test current library uri", () { |
| 171 testLibraryUri(new Class(), |
| 172 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
| 173 }); |
| 174 test("Test dart library uri", () { |
| 175 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
| 176 }); |
162 } | 177 } |
OLD | NEW |