OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'package:resource/resource.dart'; |
| 6 import 'package:test/test.dart'; |
| 7 |
| 8 main() { |
| 9 pkguri(path) => new Uri(scheme: "package", path: path); |
| 10 |
| 11 group("root resolver", () { |
| 12 var resolver = |
| 13 new PackageResolver.fromRoot(Uri.parse("file:///path/root/")); |
| 14 resolve(string) => resolver.resolve(pkguri(string)); |
| 15 |
| 16 test("resolve invalid package: URIs", () { |
| 17 expect(() => resolve("/nopkgname"), throws); |
| 18 expect(() => resolve("nopkgpath"), throws); |
| 19 expect(() => resolve("//auth/x/y"), throws); |
| 20 expect(() => resolve("x/y?query"), throws); |
| 21 expect(() => resolve("x/y#fragment"), throws); |
| 22 }); |
| 23 test("resolve package: URIs", () { |
| 24 expect(resolve("foo/bar/baz"), |
| 25 Uri.parse("file:///path/root/foo/bar/baz")); |
| 26 expect(resolve("foo/"), |
| 27 Uri.parse("file:///path/root/foo/")); |
| 28 }); |
| 29 test("resolve non-pkgUri", () { |
| 30 unchanged(string) { |
| 31 var uri = Uri.parse(string); |
| 32 expect(resolver.resolve(uri), uri); |
| 33 } unchanged("file://localhost/something?x#y"); |
| 34 unchanged("http://auth/something?x#y"); |
| 35 unchanged("https://auth/something?x#y"); |
| 36 unchanged("unknown:/something"); |
| 37 }); |
| 38 }); |
| 39 |
| 40 group("map resolver", () { |
| 41 var fooRoot = Uri.parse("file:///files/foo/"); |
| 42 var barRoot = Uri.parse("http://example.com/files/bar/"); |
| 43 var resolver = |
| 44 new PackageResolver.fromMap({"foo": fooRoot, "bar": barRoot }); |
| 45 resolve(string) => resolver.resolve(pkguri(string)); |
| 46 |
| 47 test("resolve invalid package: URIs", () { |
| 48 expect(() => resolve("/nopkgname"), throws); |
| 49 expect(() => resolve("nopkgpath"), throws); |
| 50 expect(() => resolve("//auth/x/y"), throws); |
| 51 expect(() => resolve("x/y?query"), throws); |
| 52 expect(() => resolve("x/y#fragment"), throws); |
| 53 }); |
| 54 test("resolve existing package: URIs", () { |
| 55 expect(resolve("foo/foo1/foo.dart"), fooRoot.resolve("foo1/foo.dart")); |
| 56 expect(resolve("bar/bar1/bar.dart"), barRoot.resolve("bar1/bar.dart")); |
| 57 }); |
| 58 test("resolve non-existing package: URIs", () { |
| 59 expect(resolve("baz/baz1/baz.dart"), isNull); |
| 60 }); |
| 61 test("resolve non-pkgUri", () { |
| 62 unchanged(string) { |
| 63 var uri = Uri.parse(string); |
| 64 expect(resolver.resolve(uri), uri); |
| 65 } unchanged("file://localhost/something?x#y"); |
| 66 unchanged("http://auth/something?x#y"); |
| 67 unchanged("https://auth/something?x#y"); |
| 68 unchanged("unknown:/something"); |
| 69 }); |
| 70 }); |
| 71 |
| 72 group("default resolver", () async { |
| 73 var resolver = await PackageResolver.current; |
| 74 expect(resolver.resolve("resource/resource.dart"), isNotNull); |
| 75 }); |
| 76 } |
OLD | NEW |