| 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'; |
| 11 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 11 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 12 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog; | 12 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog; |
| 13 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 13 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 14 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 14 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart' | 15 import 'package:analyzer/src/generated/engine.dart' |
| 16 show AnalysisOptions, AnalysisOptionsImpl; | 16 show AnalysisOptions, AnalysisOptionsImpl; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/util/fast_uri.dart'; | |
| 19 import 'package:convert/convert.dart'; | 18 import 'package:convert/convert.dart'; |
| 20 import 'package:crypto/crypto.dart'; | 19 import 'package:crypto/crypto.dart'; |
| 21 import 'package:test/test.dart'; | 20 import 'package:test/test.dart'; |
| 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 21 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 23 import 'package:typed_mock/typed_mock.dart'; | 22 import 'package:typed_mock/typed_mock.dart'; |
| 24 | 23 |
| 25 import '../../context/mock_sdk.dart'; | 24 import '../../context/mock_sdk.dart'; |
| 26 | 25 |
| 27 main() { | 26 main() { |
| 28 defineReflectiveSuite(() { | 27 defineReflectiveSuite(() { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 part of lib; | 254 part of lib; |
| 256 class A2 {} | 255 class A2 {} |
| 257 '''); | 256 '''); |
| 258 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']); | 257 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']); |
| 259 } | 258 } |
| 260 | 259 |
| 261 test_getFileForPath_doesNotExist() { | 260 test_getFileForPath_doesNotExist() { |
| 262 String path = _p('/aaa/lib/a.dart'); | 261 String path = _p('/aaa/lib/a.dart'); |
| 263 FileState file = fileSystemState.getFileForPath(path); | 262 FileState file = fileSystemState.getFileForPath(path); |
| 264 expect(file.path, path); | 263 expect(file.path, path); |
| 265 expect(file.uri, FastUri.parse('package:aaa/a.dart')); | 264 expect(file.uri, Uri.parse('package:aaa/a.dart')); |
| 266 expect(file.content, ''); | 265 expect(file.content, ''); |
| 267 expect(file.contentHash, _md5('')); | 266 expect(file.contentHash, _md5('')); |
| 268 expect(_excludeSdk(file.importedFiles), isEmpty); | 267 expect(_excludeSdk(file.importedFiles), isEmpty); |
| 269 expect(file.exportedFiles, isEmpty); | 268 expect(file.exportedFiles, isEmpty); |
| 270 expect(file.partedFiles, isEmpty); | 269 expect(file.partedFiles, isEmpty); |
| 271 expect(_excludeSdk(file.directReferencedFiles), isEmpty); | 270 expect(_excludeSdk(file.directReferencedFiles), isEmpty); |
| 272 expect(file.isPart, isFalse); | 271 expect(file.isPart, isFalse); |
| 273 expect(file.library, isNull); | 272 expect(file.library, isNull); |
| 274 expect(file.unlinked, isNotNull); | 273 expect(file.unlinked, isNotNull); |
| 275 expect(file.unlinked.classes, isEmpty); | 274 expect(file.unlinked.classes, isEmpty); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 299 expect(file.contentHash, _md5(content_a1)); | 298 expect(file.contentHash, _md5(content_a1)); |
| 300 | 299 |
| 301 expect(file.isPart, isFalse); | 300 expect(file.isPart, isFalse); |
| 302 expect(file.library, isNull); | 301 expect(file.library, isNull); |
| 303 expect(file.unlinked, isNotNull); | 302 expect(file.unlinked, isNotNull); |
| 304 expect(file.unlinked.classes, hasLength(1)); | 303 expect(file.unlinked.classes, hasLength(1)); |
| 305 expect(file.unlinked.classes[0].name, 'A1'); | 304 expect(file.unlinked.classes[0].name, 'A1'); |
| 306 | 305 |
| 307 expect(_excludeSdk(file.importedFiles), hasLength(2)); | 306 expect(_excludeSdk(file.importedFiles), hasLength(2)); |
| 308 expect(file.importedFiles[0].path, a2); | 307 expect(file.importedFiles[0].path, a2); |
| 309 expect(file.importedFiles[0].uri, FastUri.parse('package:aaa/a2.dart')); | 308 expect(file.importedFiles[0].uri, Uri.parse('package:aaa/a2.dart')); |
| 310 expect(file.importedFiles[0].source, isNotNull); | 309 expect(file.importedFiles[0].source, isNotNull); |
| 311 expect(file.importedFiles[1].path, b1); | 310 expect(file.importedFiles[1].path, b1); |
| 312 expect(file.importedFiles[1].uri, FastUri.parse('package:bbb/b1.dart')); | 311 expect(file.importedFiles[1].uri, Uri.parse('package:bbb/b1.dart')); |
| 313 expect(file.importedFiles[1].source, isNotNull); | 312 expect(file.importedFiles[1].source, isNotNull); |
| 314 | 313 |
| 315 expect(file.exportedFiles, hasLength(2)); | 314 expect(file.exportedFiles, hasLength(2)); |
| 316 expect(file.exportedFiles[0].path, b2); | 315 expect(file.exportedFiles[0].path, b2); |
| 317 expect(file.exportedFiles[0].uri, FastUri.parse('package:bbb/b2.dart')); | 316 expect(file.exportedFiles[0].uri, Uri.parse('package:bbb/b2.dart')); |
| 318 expect(file.exportedFiles[0].source, isNotNull); | 317 expect(file.exportedFiles[0].source, isNotNull); |
| 319 expect(file.exportedFiles[1].path, a3); | 318 expect(file.exportedFiles[1].path, a3); |
| 320 expect(file.exportedFiles[1].uri, FastUri.parse('package:aaa/a3.dart')); | 319 expect(file.exportedFiles[1].uri, Uri.parse('package:aaa/a3.dart')); |
| 321 expect(file.exportedFiles[1].source, isNotNull); | 320 expect(file.exportedFiles[1].source, isNotNull); |
| 322 | 321 |
| 323 expect(file.partedFiles, hasLength(1)); | 322 expect(file.partedFiles, hasLength(1)); |
| 324 expect(file.partedFiles[0].path, a4); | 323 expect(file.partedFiles[0].path, a4); |
| 325 expect(file.partedFiles[0].uri, FastUri.parse('package:aaa/a4.dart')); | 324 expect(file.partedFiles[0].uri, Uri.parse('package:aaa/a4.dart')); |
| 326 | 325 |
| 327 expect(_excludeSdk(file.directReferencedFiles), hasLength(5)); | 326 expect(_excludeSdk(file.directReferencedFiles), hasLength(5)); |
| 328 | 327 |
| 329 expect(fileSystemState.getFilesForPath(a1), [file]); | 328 expect(fileSystemState.getFilesForPath(a1), [file]); |
| 330 } | 329 } |
| 331 | 330 |
| 332 test_getFileForPath_onlyDartFiles() { | 331 test_getFileForPath_onlyDartFiles() { |
| 333 String not_dart = _p('/test/lib/not_dart.txt'); | 332 String not_dart = _p('/test/lib/not_dart.txt'); |
| 334 String a = _p('/test/lib/a.dart'); | 333 String a = _p('/test/lib/a.dart'); |
| 335 String b = _p('/test/lib/b.dart'); | 334 String b = _p('/test/lib/b.dart'); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 '''); | 367 '''); |
| 369 provider.newFile( | 368 provider.newFile( |
| 370 a2, | 369 a2, |
| 371 r''' | 370 r''' |
| 372 part of a1; | 371 part of a1; |
| 373 class A2 {} | 372 class A2 {} |
| 374 '''); | 373 '''); |
| 375 | 374 |
| 376 FileState file_a2 = fileSystemState.getFileForPath(a2); | 375 FileState file_a2 = fileSystemState.getFileForPath(a2); |
| 377 expect(file_a2.path, a2); | 376 expect(file_a2.path, a2); |
| 378 expect(file_a2.uri, FastUri.parse('package:aaa/a2.dart')); | 377 expect(file_a2.uri, Uri.parse('package:aaa/a2.dart')); |
| 379 | 378 |
| 380 expect(file_a2.unlinked, isNotNull); | 379 expect(file_a2.unlinked, isNotNull); |
| 381 expect(file_a2.unlinked.classes, hasLength(1)); | 380 expect(file_a2.unlinked.classes, hasLength(1)); |
| 382 expect(file_a2.unlinked.classes[0].name, 'A2'); | 381 expect(file_a2.unlinked.classes[0].name, 'A2'); |
| 383 | 382 |
| 384 expect(_excludeSdk(file_a2.importedFiles), isEmpty); | 383 expect(_excludeSdk(file_a2.importedFiles), isEmpty); |
| 385 expect(file_a2.exportedFiles, isEmpty); | 384 expect(file_a2.exportedFiles, isEmpty); |
| 386 expect(file_a2.partedFiles, isEmpty); | 385 expect(file_a2.partedFiles, isEmpty); |
| 387 expect(_excludeSdk(file_a2.directReferencedFiles), isEmpty); | 386 expect(_excludeSdk(file_a2.directReferencedFiles), isEmpty); |
| 388 | 387 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 415 | 414 |
| 416 test_getFileForPath_samePath() { | 415 test_getFileForPath_samePath() { |
| 417 String path = _p('/aaa/lib/a.dart'); | 416 String path = _p('/aaa/lib/a.dart'); |
| 418 FileState file1 = fileSystemState.getFileForPath(path); | 417 FileState file1 = fileSystemState.getFileForPath(path); |
| 419 FileState file2 = fileSystemState.getFileForPath(path); | 418 FileState file2 = fileSystemState.getFileForPath(path); |
| 420 expect(file2, same(file1)); | 419 expect(file2, same(file1)); |
| 421 } | 420 } |
| 422 | 421 |
| 423 test_getFileForUri_packageVsFileUri() { | 422 test_getFileForUri_packageVsFileUri() { |
| 424 String path = _p('/aaa/lib/a.dart'); | 423 String path = _p('/aaa/lib/a.dart'); |
| 425 var packageUri = FastUri.parse('package:aaa/a.dart'); | 424 var packageUri = Uri.parse('package:aaa/a.dart'); |
| 426 var fileUri = provider.pathContext.toUri(path); | 425 var fileUri = provider.pathContext.toUri(path); |
| 427 | 426 |
| 428 // The files with `package:` and `file:` URIs are different. | 427 // The files with `package:` and `file:` URIs are different. |
| 429 FileState filePackageUri = fileSystemState.getFileForUri(packageUri); | 428 FileState filePackageUri = fileSystemState.getFileForUri(packageUri); |
| 430 FileState fileFileUri = fileSystemState.getFileForUri(fileUri); | 429 FileState fileFileUri = fileSystemState.getFileForUri(fileUri); |
| 431 expect(filePackageUri, isNot(same(fileFileUri))); | 430 expect(filePackageUri, isNot(same(fileFileUri))); |
| 432 | 431 |
| 433 expect(filePackageUri.path, path); | 432 expect(filePackageUri.path, path); |
| 434 expect(filePackageUri.uri, packageUri); | 433 expect(filePackageUri.uri, packageUri); |
| 435 | 434 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 String _p(String path) => provider.convertPath(path); | 719 String _p(String path) => provider.convertPath(path); |
| 721 | 720 |
| 722 static String _md5(String content) { | 721 static String _md5(String content) { |
| 723 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 722 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 724 } | 723 } |
| 725 } | 724 } |
| 726 | 725 |
| 727 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} | 726 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} |
| 728 | 727 |
| 729 class _SourceMock extends TypedMock implements Source {} | 728 class _SourceMock extends TypedMock implements Source {} |
| OLD | NEW |