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

Side by Side Diff: pkg/front_end/test/src/base/uri_resolver_test.dart

Issue 2577503002: Implement URI resolution in the front end. (Closed)
Patch Set: Add TODO Created 4 years 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 | « pkg/front_end/lib/src/base/uri_resolver.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 'package:front_end/src/base/uri_resolver.dart';
6 import 'package:path/path.dart' as p;
7 import 'package:test/test.dart';
8 import 'package:test_reflective_loader/test_reflective_loader.dart';
9
10 main() {
11 defineReflectiveSuite(() {
12 defineReflectiveTests(UriResolverTestNative);
13 defineReflectiveTests(UriResolverTestPosix);
14 defineReflectiveTests(UriResolverTestWindows);
15 });
16 }
17
18 /// Generic URI resolver tests which do not depend on the particular path
19 /// context in use.
20 abstract class UriResolverTest {
21 p.Context get pathContext;
22
23 void test_badScheme() {
24 _expectResolution('foo:bar/baz.dart', null);
25 }
26
27 void test_dart() {
28 _expectResolution('dart:core', _p('sdk/lib/core/core.dart'));
29 _expectResolution('dart:async', _p('sdk/lib/async/async.dart'));
30 }
31
32 void test_dartLeadingSlash() {
33 _expectResolution('dart:/core', null);
34 }
35
36 void test_dartLeadingSlash2() {
37 _expectResolution('dart://core', null);
38 }
39
40 void test_dartLeadingSlash3() {
41 _expectResolution('dart:///core', null);
42 }
43
44 void test_dartPart() {
45 _expectResolution('dart:core/bool.dart', _p('sdk/lib/core/bool.dart'));
46 }
47
48 void test_file() {
49 _expectResolution('file:///foo.dart', _p('foo.dart'));
50 }
51
52 void test_fileLongPath() {
53 _expectResolution('file:///foo/bar.dart', _p('foo/bar.dart'));
54 }
55
56 void test_noSchemeAbsolute() {
57 _expectResolution('/foo.dart', null);
58 }
59
60 void test_noSchemeRelative() {
61 _expectResolution('foo.dart', null);
62 }
63
64 void test_package() {
65 _expectResolution('package:foo/bar.dart', _p('packages/foo/lib/bar.dart'));
66 _expectResolution('package:bar/baz.dart', _p('packages/bar/lib/baz.dart'));
67 }
68
69 void test_packageLeadingSlash() {
70 _expectResolution('package:/foo', null);
71 }
72
73 void test_packageLeadingSlash2() {
74 _expectResolution('package://foo', null);
75 }
76
77 void test_packageLeadingSlash3() {
78 _expectResolution('package:///foo', null);
79 }
80
81 void test_packageLongPath() {
82 _expectResolution(
83 'package:foo/bar/baz.dart', _p('packages/foo/lib/bar/baz.dart'));
84 }
85
86 void test_packageNoPath() {
87 // In practice "package:foo/" is meaningless. But the VM treats it as
88 // resolving to the package's lib directory (and then later reports the
89 // error when trying to open that directory as a file), so for consistency
90 // we do the same.
91 _expectResolution('package:foo/', _p('packages/foo/lib/'));
92 }
93
94 void test_packageNoSlash() {
95 _expectResolution('package:foo', null);
96 }
97
98 void test_packageUnmatchedName() {
99 _expectResolution('package:doesNotExist/foo.dart', null);
100 }
101
102 /// Verifies that the resolution of [uriString] produces the path
103 /// [expectedResult].
104 void _expectResolution(String uriString, String expectedResult) {
105 var packages = {
106 'foo': _u('packages/foo/lib/'),
107 'bar': _u('packages/bar/lib/')
108 };
109 var sdkLibraries = {
110 'core': _u('sdk/lib/core/core.dart'),
111 'async': _u('sdk/lib/async/async.dart')
112 };
113 var uriResolver = new UriResolver(packages, sdkLibraries, pathContext);
114 expect(uriResolver.resolve(Uri.parse(uriString)), expectedResult);
115 }
116
117 /// Converts a posix style path into a path appropriate for the current path
118 /// context.
119 String _p(String posixPath) {
120 return pathContext.fromUri(_u(posixPath));
121 }
122
123 /// Converts a posix style path into a file URI.
124 Uri _u(String posixPath) => Uri.parse('file:///$posixPath');
125 }
126
127 /// Override of [UriResolverTest] which uses the native path context for the
128 /// platform the test is running on.
129 @reflectiveTest
130 class UriResolverTestNative extends UriResolverTest {
131 final p.Context pathContext = p.context;
132 }
133
134 /// Override of [UriResolverTest] which uses a posix path context, regardless of
135 /// the platform the test is running on.
136 @reflectiveTest
137 class UriResolverTestPosix extends UriResolverTest {
138 final p.Context pathContext = p.posix;
139 }
140
141 /// Override of [UriResolverTest] which uses a windows path context, regardless
142 /// of the platform the test is running on.
143 @reflectiveTest
144 class UriResolverTestWindows extends UriResolverTest {
145 final p.Context pathContext = p.windows;
146
147 void test_fileWindowsLocal() {
148 _expectResolution('file:///C:/foo/bar.dart', r'C:\foo\bar.dart');
149 }
150
151 void test_fileWindowsUNC() {
152 _expectResolution(
153 'file://computer/directory/foo.dart', r'\\computer\directory\foo.dart');
154 }
155 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/base/uri_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698