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

Side by Side Diff: pkg/analyzer/test/source/package_map_resolver_test.dart

Issue 953863004: When converting files to package URI's, favor longer directory matches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/source/package_map_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
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';
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 Source source1 = _createFileSource(file1); 193 Source source1 = _createFileSource(file1);
194 Uri uri1 = resolver.restoreAbsolute(source1); 194 Uri uri1 = resolver.restoreAbsolute(source1);
195 expect(uri1.toString(), 'package:foo/bar.dart'); 195 expect(uri1.toString(), 'package:foo/bar.dart');
196 expect(resolver.resolveAbsolute(uri1).fullName, file1); 196 expect(resolver.resolveAbsolute(uri1).fullName, file1);
197 // Restoring file2 should not yield a package URI, because there is no URI 197 // Restoring file2 should not yield a package URI, because there is no URI
198 // that resolves to file2. 198 // that resolves to file2.
199 Source source2 = _createFileSource(file2); 199 Source source2 = _createFileSource(file2);
200 expect(resolver.restoreAbsolute(source2), isNull); 200 expect(resolver.restoreAbsolute(source2), isNull);
201 } 201 }
202 202
203 void test_restoreLongestMatch() {
204 const file1 = '/foo1/bar1/lib.dart';
205 const file2 = '/foo2/bar2/lib.dart';
206 provider.newFile(file1, 'library lib');
207 provider.newFile(file2, 'library lib');
208 PackageMapUriResolver resolver =
209 new PackageMapUriResolver(provider, <String, List<Folder>>{
210 'pkg1': [
211 provider.getResource('/foo1'),
212 provider.getResource('/foo2/bar2')],
213 'pkg2': [
214 provider.getResource('/foo1/bar1'),
215 provider.getResource('/foo2')]
216 });
217 // Restoring file1 should yield a package URI for pkg2, since pkg2's match
218 // for the file path (/foo1/bar1) is longer than pkg1's match (/foo1).
219 Source source1 = _createFileSource(file1);
220 Uri uri1 = resolver.restoreAbsolute(source1);
221 expect(uri1.toString(), 'package:pkg2/lib.dart');
222 // Restoring file2 should yield a package URI for pkg1, since pkg1's match
223 // for the file path (/foo2/bar2) is longer than pkg2's match (/foo2).
224 Source source2 = _createFileSource(file2);
225 Uri uri2 = resolver.restoreAbsolute(source2);
226 expect(uri2.toString(), 'package:pkg1/lib.dart');
227 }
228
203 Source _createFileSource(String path) { 229 Source _createFileSource(String path) {
204 return new NonExistingSource(path, UriKind.FILE_URI); 230 return new NonExistingSource(path, UriKind.FILE_URI);
205 } 231 }
206 } 232 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/source/package_map_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698