| Index: test/resolve_test.dart
|
| diff --git a/test/resolve_test.dart b/test/resolve_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c84bda56f0d0e2ceeab49d849829f6c80767a203
|
| --- /dev/null
|
| +++ b/test/resolve_test.dart
|
| @@ -0,0 +1,76 @@
|
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
| +// 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.
|
| +
|
| +import 'package:resource/resource.dart';
|
| +import 'package:test/test.dart';
|
| +
|
| +main() {
|
| + pkguri(path) => new Uri(scheme: "package", path: path);
|
| +
|
| + group("root resolver", () {
|
| + var resolver =
|
| + new PackageResolver.fromRoot(Uri.parse("file:///path/root/"));
|
| + resolve(string) => resolver.resolve(pkguri(string));
|
| +
|
| + test("resolve invalid package: URIs", () {
|
| + expect(() => resolve("/nopkgname"), throws);
|
| + expect(() => resolve("nopkgpath"), throws);
|
| + expect(() => resolve("//auth/x/y"), throws);
|
| + expect(() => resolve("x/y?query"), throws);
|
| + expect(() => resolve("x/y#fragment"), throws);
|
| + });
|
| + test("resolve package: URIs", () {
|
| + expect(resolve("foo/bar/baz"),
|
| + Uri.parse("file:///path/root/foo/bar/baz"));
|
| + expect(resolve("foo/"),
|
| + Uri.parse("file:///path/root/foo/"));
|
| + });
|
| + test("resolve non-pkgUri", () {
|
| + unchanged(string) {
|
| + var uri = Uri.parse(string);
|
| + expect(resolver.resolve(uri), uri);
|
| + } unchanged("file://localhost/something?x#y");
|
| + unchanged("http://auth/something?x#y");
|
| + unchanged("https://auth/something?x#y");
|
| + unchanged("unknown:/something");
|
| + });
|
| + });
|
| +
|
| + group("map resolver", () {
|
| + var fooRoot = Uri.parse("file:///files/foo/");
|
| + var barRoot = Uri.parse("http://example.com/files/bar/");
|
| + var resolver =
|
| + new PackageResolver.fromMap({"foo": fooRoot, "bar": barRoot });
|
| + resolve(string) => resolver.resolve(pkguri(string));
|
| +
|
| + test("resolve invalid package: URIs", () {
|
| + expect(() => resolve("/nopkgname"), throws);
|
| + expect(() => resolve("nopkgpath"), throws);
|
| + expect(() => resolve("//auth/x/y"), throws);
|
| + expect(() => resolve("x/y?query"), throws);
|
| + expect(() => resolve("x/y#fragment"), throws);
|
| + });
|
| + test("resolve existing package: URIs", () {
|
| + expect(resolve("foo/foo1/foo.dart"), fooRoot.resolve("foo1/foo.dart"));
|
| + expect(resolve("bar/bar1/bar.dart"), barRoot.resolve("bar1/bar.dart"));
|
| + });
|
| + test("resolve non-existing package: URIs", () {
|
| + expect(resolve("baz/baz1/baz.dart"), isNull);
|
| + });
|
| + test("resolve non-pkgUri", () {
|
| + unchanged(string) {
|
| + var uri = Uri.parse(string);
|
| + expect(resolver.resolve(uri), uri);
|
| + } unchanged("file://localhost/something?x#y");
|
| + unchanged("http://auth/something?x#y");
|
| + unchanged("https://auth/something?x#y");
|
| + unchanged("unknown:/something");
|
| + });
|
| + });
|
| +
|
| + group("default resolver", () async {
|
| + var resolver = await PackageResolver.current;
|
| + expect(resolver.resolve("resource/resource.dart"), isNotNull);
|
| + });
|
| +}
|
|
|