| 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() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 void test_dartLeadingSlash3() { | 40 void test_dartLeadingSlash3() { |
| 41 _expectResolution('dart:///core', null); | 41 _expectResolution('dart:///core', null); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void test_dartPart() { | 44 void test_dartPart() { |
| 45 _expectResolution('dart:core/bool.dart', _p('sdk/lib/core/bool.dart')); | 45 _expectResolution('dart:core/bool.dart', _p('sdk/lib/core/bool.dart')); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void test_file() { | 48 void test_file() { |
| 49 _expectResolution('file:///foo.dart', _p('foo.dart')); | 49 _expectResolution(_fileUri('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(_fileUri('foo/bar.dart'), _p('foo/bar.dart')); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void test_noSchemeAbsolute() { | 56 void test_noSchemeAbsolute() { |
| 57 _expectResolutionUri('/foo.dart', Uri.parse('/foo.dart')); | 57 _expectResolutionUri('/foo.dart', Uri.parse('/foo.dart')); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void test_noSchemeRelative() { | 60 void test_noSchemeRelative() { |
| 61 _expectResolution('foo.dart', 'foo.dart'); | 61 _expectResolution('foo.dart', 'foo.dart'); |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 'bar': _u('packages/bar/lib/') | 114 'bar': _u('packages/bar/lib/') |
| 115 }; | 115 }; |
| 116 var sdkLibraries = { | 116 var sdkLibraries = { |
| 117 'core': _u('sdk/lib/core/core.dart'), | 117 'core': _u('sdk/lib/core/core.dart'), |
| 118 'async': _u('sdk/lib/async/async.dart') | 118 'async': _u('sdk/lib/async/async.dart') |
| 119 }; | 119 }; |
| 120 var uriResolver = new UriResolver(packages, sdkLibraries); | 120 var uriResolver = new UriResolver(packages, sdkLibraries); |
| 121 expect(uriResolver.resolve(Uri.parse(uriString)), expectedResult); | 121 expect(uriResolver.resolve(Uri.parse(uriString)), expectedResult); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /// Prepends "file:///", plus a Windows drive letter if applicable, to the |
| 125 /// given path. |
| 126 String _fileUri(String pathPart) { |
| 127 if (pathContext.separator == '/') { |
| 128 return 'file:///$pathPart'; |
| 129 } else { |
| 130 return 'file:///C:/$pathPart'; |
| 131 } |
| 132 } |
| 133 |
| 124 /// Converts a posix style path into a path appropriate for the current path | 134 /// Converts a posix style path into a path appropriate for the current path |
| 125 /// context. | 135 /// context. |
| 126 String _p(String posixPath) { | 136 String _p(String posixPath) { |
| 127 return pathContext.fromUri(_u(posixPath)); | 137 if (!posixPath.startsWith('/')) posixPath = '/$posixPath'; |
| 138 if (pathContext.separator == '/') return posixPath; |
| 139 // Windows |
| 140 return 'C:${posixPath.replaceAll('/', pathContext.separator)}'; |
| 128 } | 141 } |
| 129 | 142 |
| 130 /// Converts a posix style path into a file URI. | 143 /// Converts a posix style path into a file URI. |
| 131 Uri _u(String posixPath) => Uri.parse('file:///$posixPath'); | 144 Uri _u(String posixPath) => pathContext.toUri(_p(posixPath)); |
| 132 } | 145 } |
| 133 | 146 |
| 134 /// Override of [UriResolverTest] which uses the native path context for the | 147 /// Override of [UriResolverTest] which uses the native path context for the |
| 135 /// platform the test is running on. | 148 /// platform the test is running on. |
| 136 @reflectiveTest | 149 @reflectiveTest |
| 137 class UriResolverTestNative extends UriResolverTest { | 150 class UriResolverTestNative extends UriResolverTest { |
| 138 final p.Context pathContext = p.context; | 151 final p.Context pathContext = p.context; |
| 139 } | 152 } |
| 140 | 153 |
| 141 /// Override of [UriResolverTest] which uses a posix path context, regardless of | 154 /// Override of [UriResolverTest] which uses a posix path context, regardless of |
| (...skipping 11 matching lines...) Expand all Loading... |
| 153 | 166 |
| 154 void test_fileWindowsLocal() { | 167 void test_fileWindowsLocal() { |
| 155 _expectResolution('file:///C:/foo/bar.dart', r'C:\foo\bar.dart'); | 168 _expectResolution('file:///C:/foo/bar.dart', r'C:\foo\bar.dart'); |
| 156 } | 169 } |
| 157 | 170 |
| 158 void test_fileWindowsUNC() { | 171 void test_fileWindowsUNC() { |
| 159 _expectResolution( | 172 _expectResolution( |
| 160 'file://computer/directory/foo.dart', r'\\computer\directory\foo.dart'); | 173 'file://computer/directory/foo.dart', r'\\computer\directory\foo.dart'); |
| 161 } | 174 } |
| 162 } | 175 } |
| OLD | NEW |