Index: tests/lib/mirrors/mirrors_test.dart |
diff --git a/tests/lib/mirrors/mirrors_test.dart b/tests/lib/mirrors/mirrors_test.dart |
index 33c57acc30fb10873ebbc8e8e60e53454d5b5b24..998f469af99cbdb41b1bbdd91c673fc96b710dd0 100644 |
--- a/tests/lib/mirrors/mirrors_test.dart |
+++ b/tests/lib/mirrors/mirrors_test.dart |
@@ -2,12 +2,14 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-// TODO(rmacnak): Move the existing mirror tests here (a place for |
+// TODO(rmacnak): Move the existing mirror tests here (a place for |
// cross-implementation tests). |
library MirrorsTest; |
import "dart:mirrors"; |
import "../../../pkg/unittest/lib/unittest.dart"; |
+import 'dart:io'; |
+import 'dart:uri'; |
var topLevelField; |
@@ -29,30 +31,30 @@ testFieldAccess(mirrors) { |
var future = libMirror.getFieldAsync('topLevelField'); |
future.then(expectAsync1((resultMirror) { |
expect(resultMirror.reflectee, equals(42)); |
- expect(topLevelField, equals(42)); |
+ expect(topLevelField, equals(42)); |
})); |
- |
+ |
classMirror.setFieldAsync('staticField', 43); |
future = classMirror.getFieldAsync('staticField'); |
future.then(expectAsync1((resultMirror) { |
expect(resultMirror.reflectee, equals(43)); |
- expect(Class.staticField, equals(43)); |
+ expect(Class.staticField, equals(43)); |
})); |
instMirror.setFieldAsync('field', 44); |
future = instMirror.getFieldAsync('field'); |
future.then(expectAsync1((resultMirror) { |
expect(resultMirror.reflectee, equals(44)); |
- expect(instance.field, equals(44)); |
+ expect(instance.field, equals(44)); |
})); |
} |
testClosureMirrors(mirrors) { |
var closure = (x, y, z) { return x + y + z; }; |
- |
+ |
var mirror = reflect(closure); |
expect(mirror is ClosureMirror, equals(true)); |
- |
+ |
var funcMirror = mirror.function; |
expect(funcMirror is MethodMirror, equals(true)); |
expect(funcMirror.parameters.length, equals(3)); |
@@ -66,7 +68,7 @@ testClosureMirrors(mirrors) { |
testInvokeConstructor(mirrors) { |
var libMirror = mirrors.libraries["MirrorsTest"]; |
var classMirror = libMirror.classes["Class"]; |
- |
+ |
var future = classMirror.newInstanceAsync('', []); |
future.then(expectAsync1((resultMirror) { |
var instance = resultMirror.reflectee; |
@@ -82,11 +84,30 @@ testInvokeConstructor(mirrors) { |
})); |
} |
+testLibraryUri(var value, Uri expectedUri) { |
+ var valueMirror = reflect(value); |
+ ClassMirror valueClass = valueMirror.type; |
+ LibraryMirror valueLibrary = valueClass.owner; |
+ expect(valueLibrary.uri, equals(expectedUri)); |
+} |
+ |
main() { |
var mirrors = currentMirrorSystem(); |
test("Test field access", () { testFieldAccess(mirrors); }); |
test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
test("Test invoke constructor", () { testInvokeConstructor(mirrors); }); |
+ test("Test current library uri", () { |
+ String appendSlash(String path) => path.endsWith('/') ? path : '$path/'; |
+ Uri cwd = new Uri.fromComponents( |
+ scheme: 'file', |
+ path: appendSlash(new Path(new File('.').fullPathSync()).toString())); |
ahe
2013/04/15 13:24:48
I'd be more comfortable if this test didn't requir
Johnni Winther
2013/04/17 09:40:33
Added two tests for testing file and package uris.
|
+ Uri uri = cwd.resolve(new Path(new Options().script).toString()); |
+ testLibraryUri(new Class(), uri); |
+ }); |
+ test("Test dart library uri", () { |
+ testLibraryUri("test", Uri.parse('dart:core')); |
+ }); |
+ // TODO(johnniwinther): Add a test of a package library uri. |
} |