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 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
10 import 'package:analyzer/source/package_map_resolver.dart'; | 10 import 'package:analyzer/source/package_map_resolver.dart'; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 expect(_excludeSdk(file.importedFiles), isEmpty); | 307 expect(_excludeSdk(file.importedFiles), isEmpty); |
308 expect(file.exportedFiles, isEmpty); | 308 expect(file.exportedFiles, isEmpty); |
309 expect(file.partedFiles, isEmpty); | 309 expect(file.partedFiles, isEmpty); |
310 expect(_excludeSdk(file.directReferencedFiles), isEmpty); | 310 expect(_excludeSdk(file.directReferencedFiles), isEmpty); |
311 expect(file.isPart, isFalse); | 311 expect(file.isPart, isFalse); |
312 expect(file.library, isNull); | 312 expect(file.library, isNull); |
313 expect(file.unlinked, isNotNull); | 313 expect(file.unlinked, isNotNull); |
314 expect(file.unlinked.classes, isEmpty); | 314 expect(file.unlinked.classes, isEmpty); |
315 } | 315 } |
316 | 316 |
| 317 test_getFileForPath_emptyUri() { |
| 318 String path = _p('/test.dart'); |
| 319 provider.newFile( |
| 320 path, |
| 321 r''' |
| 322 import ''; |
| 323 export ''; |
| 324 part ''; |
| 325 '''); |
| 326 |
| 327 FileState file = fileSystemState.getFileForPath(path); |
| 328 _assertIsUnresolvedFile(file.importedFiles[0]); |
| 329 _assertIsUnresolvedFile(file.exportedFiles[0]); |
| 330 _assertIsUnresolvedFile(file.partedFiles[0]); |
| 331 } |
| 332 |
317 test_getFileForPath_hasLibraryDirective_hasPartOfDirective() { | 333 test_getFileForPath_hasLibraryDirective_hasPartOfDirective() { |
318 String a = _p('/test/lib/a.dart'); | 334 String a = _p('/test/lib/a.dart'); |
319 provider.newFile( | 335 provider.newFile( |
320 a, | 336 a, |
321 r''' | 337 r''' |
322 library L; | 338 library L; |
323 part of L; | 339 part of L; |
324 '''); | 340 '''); |
325 FileState file = fileSystemState.getFileForPath(a); | 341 FileState file = fileSystemState.getFileForPath(a); |
326 expect(file.isPart, isFalse); | 342 expect(file.isPart, isFalse); |
327 } | 343 } |
328 | 344 |
329 test_getFileForPath_import_invalidUri() { | 345 test_getFileForPath_invalidUri() { |
330 String a = _p('/aaa/lib/a.dart'); | 346 String a = _p('/aaa/lib/a.dart'); |
331 String a1 = _p('/aaa/lib/a1.dart'); | 347 String a1 = _p('/aaa/lib/a1.dart'); |
332 String a2 = _p('/aaa/lib/a2.dart'); | 348 String a2 = _p('/aaa/lib/a2.dart'); |
333 String a3 = _p('/aaa/lib/a3.dart'); | 349 String a3 = _p('/aaa/lib/a3.dart'); |
334 String content_a1 = r''' | 350 String content_a1 = r''' |
335 import 'package:aaa/a1.dart'; | 351 import 'package:aaa/a1.dart'; |
336 import '[invalid uri]'; | 352 import '[invalid uri]'; |
337 | 353 |
| 354 export 'package:aaa/a2.dart'; |
338 export '[invalid uri]'; | 355 export '[invalid uri]'; |
339 export 'package:aaa/a2.dart'; | |
340 | 356 |
341 part 'a3.dart'; | 357 part 'a3.dart'; |
342 part '[invalid uri]'; | 358 part '[invalid uri]'; |
343 '''; | 359 '''; |
344 provider.newFile(a, content_a1); | 360 provider.newFile(a, content_a1); |
345 | 361 |
346 FileState file = fileSystemState.getFileForPath(a); | 362 FileState file = fileSystemState.getFileForPath(a); |
347 | 363 |
348 expect(_excludeSdk(file.importedFiles), hasLength(1)); | 364 expect(_excludeSdk(file.importedFiles), hasLength(2)); |
349 expect(file.importedFiles[0].path, a1); | 365 expect(file.importedFiles[0].path, a1); |
350 expect(file.importedFiles[0].uri, Uri.parse('package:aaa/a1.dart')); | 366 expect(file.importedFiles[0].uri, Uri.parse('package:aaa/a1.dart')); |
351 expect(file.importedFiles[0].source, isNotNull); | 367 expect(file.importedFiles[0].source, isNotNull); |
| 368 _assertIsUnresolvedFile(file.importedFiles[1]); |
352 | 369 |
353 expect(_excludeSdk(file.exportedFiles), hasLength(1)); | 370 expect(_excludeSdk(file.exportedFiles), hasLength(2)); |
354 expect(file.exportedFiles[0].path, a2); | 371 expect(file.exportedFiles[0].path, a2); |
355 expect(file.exportedFiles[0].uri, Uri.parse('package:aaa/a2.dart')); | 372 expect(file.exportedFiles[0].uri, Uri.parse('package:aaa/a2.dart')); |
356 expect(file.exportedFiles[0].source, isNotNull); | 373 expect(file.exportedFiles[0].source, isNotNull); |
| 374 _assertIsUnresolvedFile(file.exportedFiles[1]); |
357 | 375 |
358 expect(_excludeSdk(file.partedFiles), hasLength(1)); | 376 expect(_excludeSdk(file.partedFiles), hasLength(2)); |
359 expect(file.partedFiles[0].path, a3); | 377 expect(file.partedFiles[0].path, a3); |
360 expect(file.partedFiles[0].uri, Uri.parse('package:aaa/a3.dart')); | 378 expect(file.partedFiles[0].uri, Uri.parse('package:aaa/a3.dart')); |
361 expect(file.partedFiles[0].source, isNotNull); | 379 expect(file.partedFiles[0].source, isNotNull); |
| 380 _assertIsUnresolvedFile(file.partedFiles[1]); |
362 } | 381 } |
363 | 382 |
364 test_getFileForPath_library() { | 383 test_getFileForPath_library() { |
365 String a1 = _p('/aaa/lib/a1.dart'); | 384 String a1 = _p('/aaa/lib/a1.dart'); |
366 String a2 = _p('/aaa/lib/a2.dart'); | 385 String a2 = _p('/aaa/lib/a2.dart'); |
367 String a3 = _p('/aaa/lib/a3.dart'); | 386 String a3 = _p('/aaa/lib/a3.dart'); |
368 String a4 = _p('/aaa/lib/a4.dart'); | 387 String a4 = _p('/aaa/lib/a4.dart'); |
369 String b1 = _p('/bbb/lib/b1.dart'); | 388 String b1 = _p('/bbb/lib/b1.dart'); |
370 String b2 = _p('/bbb/lib/b2.dart'); | 389 String b2 = _p('/bbb/lib/b2.dart'); |
371 String content_a1 = r''' | 390 String content_a1 = r''' |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) { | 801 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) { |
783 var actual = fileSystemState.test.filesWithoutTransitiveFiles; | 802 var actual = fileSystemState.test.filesWithoutTransitiveFiles; |
784 expect(_excludeSdk(actual), unorderedEquals(expected)); | 803 expect(_excludeSdk(actual), unorderedEquals(expected)); |
785 } | 804 } |
786 | 805 |
787 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) { | 806 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) { |
788 var actual = fileSystemState.test.filesWithoutTransitiveSignature; | 807 var actual = fileSystemState.test.filesWithoutTransitiveSignature; |
789 expect(_excludeSdk(actual), unorderedEquals(expected)); | 808 expect(_excludeSdk(actual), unorderedEquals(expected)); |
790 } | 809 } |
791 | 810 |
| 811 void _assertIsUnresolvedFile(FileState file) { |
| 812 expect(file.path, isNull); |
| 813 expect(file.uri, isNull); |
| 814 expect(file.source, isNull); |
| 815 } |
| 816 |
792 void _assertTransitiveFiles(FileState file, List<FileState> expected) { | 817 void _assertTransitiveFiles(FileState file, List<FileState> expected) { |
793 expect(_excludeSdk(file.transitiveFiles), unorderedEquals(expected)); | 818 expect(_excludeSdk(file.transitiveFiles), unorderedEquals(expected)); |
794 } | 819 } |
795 | 820 |
796 List<T> _excludeSdk<T>(Iterable<T> files) { | 821 List<T> _excludeSdk<T>(Iterable<T> files) { |
797 return files.where((Object file) { | 822 return files.where((Object file) { |
798 if (file is FileState) { | 823 if (file is FileState) { |
799 return file.uri.scheme != 'dart'; | 824 return file.uri?.scheme != 'dart'; |
800 } else { | 825 } else { |
801 return !(file as String).startsWith(_p('/sdk')); | 826 return !(file as String).startsWith(_p('/sdk')); |
802 } | 827 } |
803 }).toList(); | 828 }).toList(); |
804 } | 829 } |
805 | 830 |
806 String _p(String path) => provider.convertPath(path); | 831 String _p(String path) => provider.convertPath(path); |
807 | 832 |
808 static String _md5(String content) { | 833 static String _md5(String content) { |
809 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 834 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
810 } | 835 } |
811 } | 836 } |
812 | 837 |
813 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} | 838 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} |
814 | 839 |
815 class _SourceMock extends TypedMock implements Source {} | 840 class _SourceMock extends TypedMock implements Source {} |
OLD | NEW |