OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library test.source.package_map_resolver; | 5 library test.source.package_map_resolver; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
9 import 'package:analyzer/source/package_map_resolver.dart'; | 9 import 'package:analyzer/source/package_map_resolver.dart'; |
10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:path/path.dart'; |
11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
12 | 13 |
13 import '../reflective_tests.dart'; | 14 import '../reflective_tests.dart'; |
14 | 15 |
15 main() { | 16 main() { |
16 groupSep = ' | '; | 17 groupSep = ' | '; |
17 runReflectiveTests(_PackageMapUriResolverTest); | 18 runReflectiveTests(_PackageMapUriResolverTest); |
18 } | 19 } |
19 | 20 |
20 @reflectiveTest | 21 @reflectiveTest |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 Source result = resolver.resolveAbsolute(uri); | 138 Source result = resolver.resolveAbsolute(uri); |
138 expect(result, isNull); | 139 expect(result, isNull); |
139 } | 140 } |
140 | 141 |
141 void test_resolve_package_notInMap() { | 142 void test_resolve_package_notInMap() { |
142 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); | 143 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP); |
143 Uri uri = Uri.parse('package:analyzer/analyzer.dart'); | 144 Uri uri = Uri.parse('package:analyzer/analyzer.dart'); |
144 Source result = resolver.resolveAbsolute(uri); | 145 Source result = resolver.resolveAbsolute(uri); |
145 expect(result, isNotNull); | 146 expect(result, isNotNull); |
146 expect(result.exists(), isFalse); | 147 expect(result.exists(), isFalse); |
147 expect(result.fullName, 'package:analyzer/analyzer.dart'); | 148 expect(result.fullName, 'analyzer.dart'); |
| 149 expect(result.uri.toString(), 'package:analyzer/analyzer.dart'); |
148 } | 150 } |
149 | 151 |
150 void test_restoreAbsolute() { | 152 void test_restoreAbsolute() { |
151 const pkgFileA = '/pkgA/lib/libA.dart'; | 153 const pkgFileA = '/pkgA/lib/libA.dart'; |
152 const pkgFileB = '/pkgB/lib/src/libB.dart'; | 154 const pkgFileB = '/pkgB/lib/src/libB.dart'; |
153 provider.newFile(pkgFileA, 'library lib_a;'); | 155 provider.newFile(pkgFileA, 'library lib_a;'); |
154 provider.newFile(pkgFileB, 'library lib_b;'); | 156 provider.newFile(pkgFileB, 'library lib_b;'); |
155 PackageMapUriResolver resolver = new PackageMapUriResolver(provider, | 157 PackageMapUriResolver resolver = new PackageMapUriResolver(provider, |
156 <String, List<Folder>>{ | 158 <String, List<Folder>>{ |
157 'pkgA': [provider.getResource('/pkgA/lib/')], | 159 'pkgA': [provider.getResource('/pkgA/lib/')], |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 Uri uri1 = resolver.restoreAbsolute(source1); | 224 Uri uri1 = resolver.restoreAbsolute(source1); |
223 expect(uri1.toString(), 'package:pkg2/lib.dart'); | 225 expect(uri1.toString(), 'package:pkg2/lib.dart'); |
224 // Restoring file2 should yield a package URI for pkg1, since pkg1's match | 226 // Restoring file2 should yield a package URI for pkg1, since pkg1's match |
225 // for the file path (/foo2/bar2) is longer than pkg2's match (/foo2). | 227 // for the file path (/foo2/bar2) is longer than pkg2's match (/foo2). |
226 Source source2 = _createFileSource(file2); | 228 Source source2 = _createFileSource(file2); |
227 Uri uri2 = resolver.restoreAbsolute(source2); | 229 Uri uri2 = resolver.restoreAbsolute(source2); |
228 expect(uri2.toString(), 'package:pkg1/lib.dart'); | 230 expect(uri2.toString(), 'package:pkg1/lib.dart'); |
229 } | 231 } |
230 | 232 |
231 Source _createFileSource(String path) { | 233 Source _createFileSource(String path) { |
232 return new NonExistingSource(path, UriKind.FILE_URI); | 234 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); |
233 } | 235 } |
234 } | 236 } |
OLD | NEW |