Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Unified Diff: test/resolve_test.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« pubspec.yaml ('K') | « pubspec.yaml ('k') | test/resource_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ });
+}
« pubspec.yaml ('K') | « pubspec.yaml ('k') | test/resource_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698