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

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

Issue 2344933002: Fix recently introduced strong-mode errors (Closed)
Patch Set: Created 4 years, 3 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
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 analyzer.test.source.package_map_resolver_test; 5 library analyzer.test.source.package_map_resolver_test;
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 }, throws); 55 }, throws);
56 } 56 }
57 57
58 void test_resolve_multiple_folders() { 58 void test_resolve_multiple_folders() {
59 const pkgFileA = '/part1/lib/libA.dart'; 59 const pkgFileA = '/part1/lib/libA.dart';
60 const pkgFileB = '/part2/lib/libB.dart'; 60 const pkgFileB = '/part2/lib/libB.dart';
61 provider.newFile(pkgFileA, 'library lib_a'); 61 provider.newFile(pkgFileA, 'library lib_a');
62 provider.newFile(pkgFileB, 'library lib_b'); 62 provider.newFile(pkgFileB, 'library lib_b');
63 PackageMapUriResolver resolver = 63 PackageMapUriResolver resolver =
64 new PackageMapUriResolver(provider, <String, List<Folder>>{ 64 new PackageMapUriResolver(provider, <String, List<Folder>>{
65 'pkg': [ 65 'pkg': <Folder>[
66 provider.getResource('/part1/lib/'), 66 provider.getResource('/part1/lib/'),
67 provider.getResource('/part2/lib/') 67 provider.getResource('/part2/lib/')
68 ] 68 ]
69 }); 69 });
70 { 70 {
71 Uri uri = Uri.parse('package:pkg/libA.dart'); 71 Uri uri = Uri.parse('package:pkg/libA.dart');
72 Source result = resolver.resolveAbsolute(uri); 72 Source result = resolver.resolveAbsolute(uri);
73 expect(result, isNotNull); 73 expect(result, isNotNull);
74 expect(result.exists(), isTrue); 74 expect(result.exists(), isTrue);
75 expect(result.uriKind, UriKind.PACKAGE_URI); 75 expect(result.uriKind, UriKind.PACKAGE_URI);
(...skipping 16 matching lines...) Expand all
92 expect(result, isNull); 92 expect(result, isNull);
93 } 93 }
94 94
95 void test_resolve_OK() { 95 void test_resolve_OK() {
96 const pkgFileA = '/pkgA/lib/libA.dart'; 96 const pkgFileA = '/pkgA/lib/libA.dart';
97 const pkgFileB = '/pkgB/lib/libB.dart'; 97 const pkgFileB = '/pkgB/lib/libB.dart';
98 provider.newFile(pkgFileA, 'library lib_a;'); 98 provider.newFile(pkgFileA, 'library lib_a;');
99 provider.newFile(pkgFileB, 'library lib_b;'); 99 provider.newFile(pkgFileB, 'library lib_b;');
100 PackageMapUriResolver resolver = 100 PackageMapUriResolver resolver =
101 new PackageMapUriResolver(provider, <String, List<Folder>>{ 101 new PackageMapUriResolver(provider, <String, List<Folder>>{
102 'pkgA': [provider.getResource('/pkgA/lib/')], 102 'pkgA': <Folder>[provider.getResource('/pkgA/lib/')],
103 'pkgB': [provider.getResource('/pkgB/lib/')] 103 'pkgB': <Folder>[provider.getResource('/pkgB/lib/')]
104 }); 104 });
105 { 105 {
106 Uri uri = Uri.parse('package:pkgA/libA.dart'); 106 Uri uri = Uri.parse('package:pkgA/libA.dart');
107 Source result = resolver.resolveAbsolute(uri); 107 Source result = resolver.resolveAbsolute(uri);
108 expect(result, isNotNull); 108 expect(result, isNotNull);
109 expect(result.exists(), isTrue); 109 expect(result.exists(), isTrue);
110 expect(result.uriKind, UriKind.PACKAGE_URI); 110 expect(result.uriKind, UriKind.PACKAGE_URI);
111 expect(result.fullName, pkgFileA); 111 expect(result.fullName, pkgFileA);
112 } 112 }
113 { 113 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 expect(result.uri.toString(), 'package:analyzer/analyzer.dart'); 151 expect(result.uri.toString(), 'package:analyzer/analyzer.dart');
152 } 152 }
153 153
154 void test_restoreAbsolute() { 154 void test_restoreAbsolute() {
155 const pkgFileA = '/pkgA/lib/libA.dart'; 155 const pkgFileA = '/pkgA/lib/libA.dart';
156 const pkgFileB = '/pkgB/lib/src/libB.dart'; 156 const pkgFileB = '/pkgB/lib/src/libB.dart';
157 provider.newFile(pkgFileA, 'library lib_a;'); 157 provider.newFile(pkgFileA, 'library lib_a;');
158 provider.newFile(pkgFileB, 'library lib_b;'); 158 provider.newFile(pkgFileB, 'library lib_b;');
159 PackageMapUriResolver resolver = 159 PackageMapUriResolver resolver =
160 new PackageMapUriResolver(provider, <String, List<Folder>>{ 160 new PackageMapUriResolver(provider, <String, List<Folder>>{
161 'pkgA': [provider.getResource('/pkgA/lib/')], 161 'pkgA': <Folder>[provider.getResource('/pkgA/lib/')],
162 'pkgB': [provider.getResource('/pkgB/lib/')] 162 'pkgB': <Folder>[provider.getResource('/pkgB/lib/')]
163 }); 163 });
164 { 164 {
165 Source source = _createFileSource('/pkgA/lib/libA.dart'); 165 Source source = _createFileSource('/pkgA/lib/libA.dart');
166 Uri uri = resolver.restoreAbsolute(source); 166 Uri uri = resolver.restoreAbsolute(source);
167 expect(uri, isNotNull); 167 expect(uri, isNotNull);
168 expect(uri.toString(), 'package:pkgA/libA.dart'); 168 expect(uri.toString(), 'package:pkgA/libA.dart');
169 } 169 }
170 { 170 {
171 Source source = _createFileSource('/pkgB/lib/src/libB.dart'); 171 Source source = _createFileSource('/pkgB/lib/src/libB.dart');
172 Uri uri = resolver.restoreAbsolute(source); 172 Uri uri = resolver.restoreAbsolute(source);
173 expect(uri, isNotNull); 173 expect(uri, isNotNull);
174 expect(uri.toString(), 'package:pkgB/src/libB.dart'); 174 expect(uri.toString(), 'package:pkgB/src/libB.dart');
175 } 175 }
176 { 176 {
177 Source source = _createFileSource('/no/such/file'); 177 Source source = _createFileSource('/no/such/file');
178 Uri uri = resolver.restoreAbsolute(source); 178 Uri uri = resolver.restoreAbsolute(source);
179 expect(uri, isNull); 179 expect(uri, isNull);
180 } 180 }
181 } 181 }
182 182
183 void test_restoreAbsolute_ambiguous() { 183 void test_restoreAbsolute_ambiguous() {
184 const file1 = '/foo1/lib/bar.dart'; 184 const file1 = '/foo1/lib/bar.dart';
185 const file2 = '/foo2/lib/bar.dart'; 185 const file2 = '/foo2/lib/bar.dart';
186 provider.newFile(file1, 'library bar'); 186 provider.newFile(file1, 'library bar');
187 provider.newFile(file2, 'library bar'); 187 provider.newFile(file2, 'library bar');
188 PackageMapUriResolver resolver = 188 PackageMapUriResolver resolver =
189 new PackageMapUriResolver(provider, <String, List<Folder>>{ 189 new PackageMapUriResolver(provider, <String, List<Folder>>{
190 'foo': [ 190 'foo': <Folder>[
191 provider.getResource('/foo1/lib'), 191 provider.getResource('/foo1/lib'),
192 provider.getResource('/foo2/lib') 192 provider.getResource('/foo2/lib')
193 ] 193 ]
194 }); 194 });
195 // Restoring file1 should yield a package URI, and that package URI should 195 // Restoring file1 should yield a package URI, and that package URI should
196 // resolve back to file1. 196 // resolve back to file1.
197 Source source1 = _createFileSource(file1); 197 Source source1 = _createFileSource(file1);
198 Uri uri1 = resolver.restoreAbsolute(source1); 198 Uri uri1 = resolver.restoreAbsolute(source1);
199 expect(uri1.toString(), 'package:foo/bar.dart'); 199 expect(uri1.toString(), 'package:foo/bar.dart');
200 expect(resolver.resolveAbsolute(uri1).fullName, file1); 200 expect(resolver.resolveAbsolute(uri1).fullName, file1);
201 // Restoring file2 should not yield a package URI, because there is no URI 201 // Restoring file2 should not yield a package URI, because there is no URI
202 // that resolves to file2. 202 // that resolves to file2.
203 Source source2 = _createFileSource(file2); 203 Source source2 = _createFileSource(file2);
204 expect(resolver.restoreAbsolute(source2), isNull); 204 expect(resolver.restoreAbsolute(source2), isNull);
205 } 205 }
206 206
207 void test_restoreAbsolute_longestMatch() { 207 void test_restoreAbsolute_longestMatch() {
208 const file1 = '/foo1/bar1/lib.dart'; 208 const file1 = '/foo1/bar1/lib.dart';
209 const file2 = '/foo2/bar2/lib.dart'; 209 const file2 = '/foo2/bar2/lib.dart';
210 provider.newFile(file1, 'library lib'); 210 provider.newFile(file1, 'library lib');
211 provider.newFile(file2, 'library lib'); 211 provider.newFile(file2, 'library lib');
212 PackageMapUriResolver resolver = 212 PackageMapUriResolver resolver =
213 new PackageMapUriResolver(provider, <String, List<Folder>>{ 213 new PackageMapUriResolver(provider, <String, List<Folder>>{
214 'pkg1': [ 214 'pkg1': <Folder>[
215 provider.getResource('/foo1'), 215 provider.getResource('/foo1'),
216 provider.getResource('/foo2/bar2') 216 provider.getResource('/foo2/bar2')
217 ], 217 ],
218 'pkg2': [ 218 'pkg2': <Folder>[
219 provider.getResource('/foo1/bar1'), 219 provider.getResource('/foo1/bar1'),
220 provider.getResource('/foo2') 220 provider.getResource('/foo2')
221 ] 221 ]
222 }); 222 });
223 // Restoring file1 should yield a package URI for pkg2, since pkg2's match 223 // Restoring file1 should yield a package URI for pkg2, since pkg2's match
224 // for the file path (/foo1/bar1) is longer than pkg1's match (/foo1). 224 // for the file path (/foo1/bar1) is longer than pkg1's match (/foo1).
225 Source source1 = _createFileSource(file1); 225 Source source1 = _createFileSource(file1);
226 Uri uri1 = resolver.restoreAbsolute(source1); 226 Uri uri1 = resolver.restoreAbsolute(source1);
227 expect(uri1.toString(), 'package:pkg2/lib.dart'); 227 expect(uri1.toString(), 'package:pkg2/lib.dart');
228 // Restoring file2 should yield a package URI for pkg1, since pkg1's match 228 // Restoring file2 should yield a package URI for pkg1, since pkg1's match
229 // for the file path (/foo2/bar2) is longer than pkg2's match (/foo2). 229 // for the file path (/foo2/bar2) is longer than pkg2's match (/foo2).
230 Source source2 = _createFileSource(file2); 230 Source source2 = _createFileSource(file2);
231 Uri uri2 = resolver.restoreAbsolute(source2); 231 Uri uri2 = resolver.restoreAbsolute(source2);
232 expect(uri2.toString(), 'package:pkg1/lib.dart'); 232 expect(uri2.toString(), 'package:pkg1/lib.dart');
233 } 233 }
234 234
235 Source _createFileSource(String path) { 235 Source _createFileSource(String path) {
236 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); 236 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI);
237 } 237 }
238 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698