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

Side by Side Diff: test/package_root_info_test.dart

Issue 2132443003: Add package implementation. (Closed) Base URL: git@github.com:dart-lang/package_resolver@master
Patch Set: Code review changes Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « test/package_config_info_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 'dart:io';
6
7 import 'package:path/path.dart' as p;
8 import 'package:test/test.dart';
9
10 import 'package:package_resolver/package_resolver.dart';
11
12 void main() {
13 var resolver;
14 setUp(() {
15 resolver = new SyncPackageResolver.root("file:///foo/bar");
16 });
17
18 group("constructor", () {
19 test("with a URI object", () {
20 var resolver =
21 new SyncPackageResolver.root(Uri.parse("file:///foo/bar/"));
22 expect(resolver.packageRoot, equals(Uri.parse("file:///foo/bar/")));
23 });
24
25 test("with an invalid URI type", () {
26 expect(() => new SyncPackageResolver.root(12), throwsArgumentError);
27 });
28 });
29
30 test("exposes a null config map", () {
31 expect(resolver.packageConfigMap, isNull);
32 });
33
34 test("exposes a null config URI", () {
35 expect(resolver.packageConfigUri, isNull);
36 });
37
38 test("exposes the root root", () {
39 expect(resolver.packageRoot, equals(Uri.parse("file:///foo/bar/")));
40 });
41
42 test("processArgument uses --package-root", () {
43 expect(resolver.processArgument, equals("--package-root=file:///foo/bar/"));
44 });
45
46 group("resolveUri", () {
47 test("with a package", () {
48 expect(resolver.resolveUri("package:baz/bang/qux.dart"),
49 equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart")));
50 });
51
52 test("with a package with no path", () {
53 expect(resolver.resolveUri("package:baz"), isNull);
54 });
55
56 test("with a package with an empty path", () {
57 expect(resolver.resolveUri("package:baz/"),
58 equals(Uri.parse("file:///foo/bar/baz/")));
59 });
60
61 test("with a URI object", () {
62 expect(resolver.resolveUri(Uri.parse("package:baz/bang/qux.dart")),
63 equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart")));
64 });
65
66 test("with an invalid argument type", () {
67 expect(() => resolver.resolveUri(12), throwsArgumentError);
68 });
69
70 test("with a non-package URI", () {
71 expect(() => resolver.resolveUri("file:///zip/zap"),
72 throwsFormatException);
73 });
74
75 test("with an invalid package URI", () {
76 expect(() => resolver.resolveUri("package:"), throwsFormatException);
77 });
78 });
79
80 group("urlFor", () {
81 test("with no path", () {
82 expect(resolver.urlFor("baz"), equals(Uri.parse("file:///foo/bar/baz/")));
83 });
84
85 test("with a path", () {
86 expect(resolver.urlFor("baz", "bang/qux.dart"),
87 equals(Uri.parse("file:///foo/bar/baz/bang/qux.dart")));
88 });
89 });
90
91 group("packageUriFor", () {
92 test("converts a matching URI to a package:", () {
93 expect(resolver.packageUriFor("file:///foo/bar/bang/qux.dart"),
94 equals(Uri.parse("package:bang/qux.dart")));
95 });
96
97 test("converts a matching URI with no path", () {
98 expect(resolver.packageUriFor("file:///foo/bar/baz"),
99 equals(Uri.parse("package:baz/")));
100 expect(resolver.packageUriFor("file:///foo/bar/baz/"),
101 equals(Uri.parse("package:baz/")));
102 });
103
104 test("with a URI object", () {
105 expect(resolver.packageUriFor(Uri.parse("file:///foo/bar/bang/qux.dart")),
106 equals(Uri.parse("package:bang/qux.dart")));
107 });
108
109 test("with an invalid argument type", () {
110 expect(() => resolver.packageUriFor(12), throwsArgumentError);
111 });
112 });
113
114 group("packagePath", () {
115 var sandbox;
116 setUp(() async {
117 sandbox = (await Directory.systemTemp.createTemp("package_resolver_test"))
118 .path;
119 });
120
121 tearDown(() async {
122 await new Directory(sandbox).delete(recursive: true);
123 });
124
125 test("with a file: scheme", () async {
126 var packageLib = p.join(sandbox, "foo/lib");
127 await new Directory(packageLib).create(recursive: true);
128
129 var packagesDir = p.join(sandbox, "packages");
130 var fooLink = p.join(packagesDir, "foo");
131 await new Link(fooLink).create(packageLib, recursive: true);
132
133 var packagesLink = p.join(sandbox, "foo/packages");
134 await new Link(packagesLink).create(packagesDir);
135
136 var resolver = new SyncPackageResolver.root(p.toUri(packagesLink));
137
138 expect(resolver.packagePath("foo"), equals(p.join(sandbox, "foo")));
139 expect(resolver.packagePath("bar"), isNull);
140 });
141
142 test("without a file: scheme", () {
143 var resolver = new SyncPackageResolver.root("http://dartlang.org/bar");
144 expect(resolver.packagePath("foo"), isNull);
145 });
146 });
147 }
OLDNEW
« no previous file with comments | « test/package_config_info_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698