OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:front_end/src/base/uri_resolver.dart'; | 5 import 'package:front_end/src/base/uri_resolver.dart'; |
6 import 'package:path/path.dart' as p; | 6 import 'package:path/path.dart' as p; |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
9 | 9 |
10 main() { | 10 main() { |
11 defineReflectiveSuite(() { | 11 defineReflectiveSuite(() { |
12 defineReflectiveTests(UriResolverTestNative); | 12 defineReflectiveTests(UriResolverTestNative); |
13 defineReflectiveTests(UriResolverTestPosix); | 13 defineReflectiveTests(UriResolverTestPosix); |
14 defineReflectiveTests(UriResolverTestWindows); | 14 defineReflectiveTests(UriResolverTestWindows); |
15 }); | 15 }); |
16 } | 16 } |
17 | 17 |
18 /// Generic URI resolver tests which do not depend on the particular path | 18 /// Generic URI resolver tests which do not depend on the particular path |
19 /// context in use. | 19 /// context in use. |
20 abstract class UriResolverTest { | 20 abstract class UriResolverTest { |
21 p.Context get pathContext; | 21 p.Context get pathContext; |
22 | 22 |
23 void test_badScheme() { | 23 void test_badScheme() { |
24 _expectResolution('foo:bar/baz.dart', null); | 24 _expectResolutionUri('foo:bar/baz.dart', Uri.parse('foo:bar/baz.dart')); |
25 } | 25 } |
26 | 26 |
27 void test_dart() { | 27 void test_dart() { |
28 _expectResolution('dart:core', _p('sdk/lib/core/core.dart')); | 28 _expectResolution('dart:core', _p('sdk/lib/core/core.dart')); |
29 _expectResolution('dart:async', _p('sdk/lib/async/async.dart')); | 29 _expectResolution('dart:async', _p('sdk/lib/async/async.dart')); |
30 } | 30 } |
31 | 31 |
32 void test_dartLeadingSlash() { | 32 void test_dartLeadingSlash() { |
33 _expectResolution('dart:/core', null); | 33 _expectResolution('dart:/core', null); |
34 } | 34 } |
(...skipping 12 matching lines...) Expand all Loading... |
47 | 47 |
48 void test_file() { | 48 void test_file() { |
49 _expectResolution('file:///foo.dart', _p('foo.dart')); | 49 _expectResolution('file:///foo.dart', _p('foo.dart')); |
50 } | 50 } |
51 | 51 |
52 void test_fileLongPath() { | 52 void test_fileLongPath() { |
53 _expectResolution('file:///foo/bar.dart', _p('foo/bar.dart')); | 53 _expectResolution('file:///foo/bar.dart', _p('foo/bar.dart')); |
54 } | 54 } |
55 | 55 |
56 void test_noSchemeAbsolute() { | 56 void test_noSchemeAbsolute() { |
57 _expectResolution('/foo.dart', null); | 57 _expectResolutionUri('/foo.dart', Uri.parse('/foo.dart')); |
58 } | 58 } |
59 | 59 |
60 void test_noSchemeRelative() { | 60 void test_noSchemeRelative() { |
61 _expectResolution('foo.dart', null); | 61 _expectResolution('foo.dart', 'foo.dart'); |
62 } | 62 } |
63 | 63 |
64 void test_package() { | 64 void test_package() { |
65 _expectResolution('package:foo/bar.dart', _p('packages/foo/lib/bar.dart')); | 65 _expectResolution('package:foo/bar.dart', _p('packages/foo/lib/bar.dart')); |
66 _expectResolution('package:bar/baz.dart', _p('packages/bar/lib/baz.dart')); | 66 _expectResolution('package:bar/baz.dart', _p('packages/bar/lib/baz.dart')); |
67 } | 67 } |
68 | 68 |
69 void test_packageLeadingSlash() { | 69 void test_packageLeadingSlash() { |
70 _expectResolution('package:/foo', null); | 70 _expectResolution('package:/foo', null); |
71 } | 71 } |
(...skipping 23 matching lines...) Expand all Loading... |
95 _expectResolution('package:foo', null); | 95 _expectResolution('package:foo', null); |
96 } | 96 } |
97 | 97 |
98 void test_packageUnmatchedName() { | 98 void test_packageUnmatchedName() { |
99 _expectResolution('package:doesNotExist/foo.dart', null); | 99 _expectResolution('package:doesNotExist/foo.dart', null); |
100 } | 100 } |
101 | 101 |
102 /// Verifies that the resolution of [uriString] produces the path | 102 /// Verifies that the resolution of [uriString] produces the path |
103 /// [expectedResult]. | 103 /// [expectedResult]. |
104 void _expectResolution(String uriString, String expectedResult) { | 104 void _expectResolution(String uriString, String expectedResult) { |
| 105 _expectResolutionUri(uriString, |
| 106 expectedResult == null ? null : pathContext.toUri(expectedResult)); |
| 107 } |
| 108 |
| 109 /// Verifies that the resolution of [uriString] produces the URI |
| 110 /// [expectedResult]. |
| 111 void _expectResolutionUri(String uriString, Uri expectedResult) { |
105 var packages = { | 112 var packages = { |
106 'foo': _u('packages/foo/lib/'), | 113 'foo': _u('packages/foo/lib/'), |
107 'bar': _u('packages/bar/lib/') | 114 'bar': _u('packages/bar/lib/') |
108 }; | 115 }; |
109 var sdkLibraries = { | 116 var sdkLibraries = { |
110 'core': _u('sdk/lib/core/core.dart'), | 117 'core': _u('sdk/lib/core/core.dart'), |
111 'async': _u('sdk/lib/async/async.dart') | 118 'async': _u('sdk/lib/async/async.dart') |
112 }; | 119 }; |
113 var uriResolver = new UriResolver(packages, sdkLibraries, pathContext); | 120 var uriResolver = new UriResolver(packages, sdkLibraries, pathContext); |
114 expect(uriResolver.resolve(Uri.parse(uriString)), expectedResult); | 121 expect(uriResolver.resolve(Uri.parse(uriString)), expectedResult); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 153 |
147 void test_fileWindowsLocal() { | 154 void test_fileWindowsLocal() { |
148 _expectResolution('file:///C:/foo/bar.dart', r'C:\foo\bar.dart'); | 155 _expectResolution('file:///C:/foo/bar.dart', r'C:\foo\bar.dart'); |
149 } | 156 } |
150 | 157 |
151 void test_fileWindowsUNC() { | 158 void test_fileWindowsUNC() { |
152 _expectResolution( | 159 _expectResolution( |
153 'file://computer/directory/foo.dart', r'\\computer\directory\foo.dart'); | 160 'file://computer/directory/foo.dart', r'\\computer\directory\foo.dart'); |
154 } | 161 } |
155 } | 162 } |
OLD | NEW |