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"; |
| 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 } | 20 } |
| 20 | 21 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 109 |
| 109 expect(methodMirror.simpleName, equals(const Symbol('testNames'))); | 110 expect(methodMirror.simpleName, equals(const Symbol('testNames'))); |
| 110 expect(methodMirror.qualifiedName, | 111 expect(methodMirror.qualifiedName, |
| 111 equals(const Symbol('MirrorsTest.testNames'))); | 112 equals(const Symbol('MirrorsTest.testNames'))); |
| 112 | 113 |
| 113 expect(variableMirror.simpleName, equals(const Symbol('field'))); | 114 expect(variableMirror.simpleName, equals(const Symbol('field'))); |
| 114 expect(variableMirror.qualifiedName, | 115 expect(variableMirror.qualifiedName, |
| 115 equals(const Symbol('MirrorsTest.Class.field'))); | 116 equals(const Symbol('MirrorsTest.Class.field'))); |
| 116 } | 117 } |
| 117 | 118 |
| 119 testLibraryUri(var value, bool check(Uri)) { | |
| 120 var valueMirror = reflect(value); | |
| 121 ClassMirror valueClass = valueMirror.type; | |
| 122 LibraryMirror valueLibrary = valueClass.owner; | |
| 123 expect(check(valueLibrary.uri), isTrue); | |
| 124 } | |
| 125 | |
| 118 main() { | 126 main() { |
| 119 var mirrors = currentMirrorSystem(); | 127 var mirrors = currentMirrorSystem(); |
| 120 | 128 |
| 121 test("Test field access", () { testFieldAccess(mirrors); }); | 129 test("Test field access", () { testFieldAccess(mirrors); }); |
| 122 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); | 130 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
| 123 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); | 131 test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |
| 124 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 132 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 133 test("Test current library uri", () { | |
| 134 testLibraryUri(new Class(), | |
| 135 (Uri uri) => uri.path.endsWith('mirrors_test.dart')); | |
|
ahe
2013/04/17 10:47:32
Add leading slash?
Johnni Winther
2013/04/22 09:27:18
Done.
| |
| 136 }); | |
| 137 test("Test dart library uri", () { | |
| 138 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | |
| 139 }); | |
| 125 } | 140 } |
| OLD | NEW |