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

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