| 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'; | 18 import 'package:analyzer/src/util/fast_uri.dart'; |
| 19 import 'package:convert/convert.dart'; | 19 import 'package:convert/convert.dart'; |
| 20 import 'package:crypto/crypto.dart'; | 20 import 'package:crypto/crypto.dart'; |
| 21 import 'package:test/test.dart'; | 21 import 'package:test/test.dart'; |
| 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 23 import 'package:typed_mock/typed_mock.dart'; |
| 23 | 24 |
| 24 import '../../context/mock_sdk.dart'; | 25 import '../../context/mock_sdk.dart'; |
| 25 | 26 |
| 26 main() { | 27 main() { |
| 27 defineReflectiveSuite(() { | 28 defineReflectiveSuite(() { |
| 28 defineReflectiveTests(FileSystemStateTest); | 29 defineReflectiveTests(FileSystemStateTest); |
| 29 }); | 30 }); |
| 30 } | 31 } |
| 31 | 32 |
| 32 @reflectiveTest | 33 @reflectiveTest |
| 33 class FileSystemStateTest { | 34 class FileSystemStateTest { |
| 34 final MemoryResourceProvider provider = new MemoryResourceProvider(); | 35 final MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 35 MockSdk sdk; | 36 MockSdk sdk; |
| 36 | 37 |
| 37 final ByteStore byteStore = new MemoryByteStore(); | 38 final ByteStore byteStore = new MemoryByteStore(); |
| 38 final FileContentOverlay contentOverlay = new FileContentOverlay(); | 39 final FileContentOverlay contentOverlay = new FileContentOverlay(); |
| 39 | 40 |
| 40 final StringBuffer logBuffer = new StringBuffer(); | 41 final StringBuffer logBuffer = new StringBuffer(); |
| 42 final UriResolver generatedUriResolver = new _GeneratedUriResolverMock(); |
| 41 SourceFactory sourceFactory; | 43 SourceFactory sourceFactory; |
| 42 PerformanceLog logger; | 44 PerformanceLog logger; |
| 43 | 45 |
| 44 FileSystemState fileSystemState; | 46 FileSystemState fileSystemState; |
| 45 | 47 |
| 46 void setUp() { | 48 void setUp() { |
| 47 logger = new PerformanceLog(logBuffer); | 49 logger = new PerformanceLog(logBuffer); |
| 48 sdk = new MockSdk(resourceProvider: provider); | 50 sdk = new MockSdk(resourceProvider: provider); |
| 49 sourceFactory = new SourceFactory([ | 51 sourceFactory = new SourceFactory([ |
| 50 new DartUriResolver(sdk), | 52 new DartUriResolver(sdk), |
| 53 generatedUriResolver, |
| 51 new PackageMapUriResolver(provider, <String, List<Folder>>{ | 54 new PackageMapUriResolver(provider, <String, List<Folder>>{ |
| 52 'aaa': [provider.getFolder(_p('/aaa/lib'))], | 55 'aaa': [provider.getFolder(_p('/aaa/lib'))], |
| 53 'bbb': [provider.getFolder(_p('/bbb/lib'))], | 56 'bbb': [provider.getFolder(_p('/bbb/lib'))], |
| 54 }), | 57 }), |
| 55 new ResourceUriResolver(provider) | 58 new ResourceUriResolver(provider) |
| 56 ], null, provider); | 59 ], null, provider); |
| 57 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() | 60 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() |
| 58 ..strongMode = true; | 61 ..strongMode = true; |
| 59 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, | 62 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, |
| 60 provider, sourceFactory, analysisOptions, new Uint32List(0)); | 63 provider, sourceFactory, analysisOptions, new Uint32List(0)); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 expect(_excludeSdk(file.importedFiles), isEmpty); | 268 expect(_excludeSdk(file.importedFiles), isEmpty); |
| 266 expect(file.exportedFiles, isEmpty); | 269 expect(file.exportedFiles, isEmpty); |
| 267 expect(file.partedFiles, isEmpty); | 270 expect(file.partedFiles, isEmpty); |
| 268 expect(_excludeSdk(file.directReferencedFiles), isEmpty); | 271 expect(_excludeSdk(file.directReferencedFiles), isEmpty); |
| 269 expect(file.isPart, isFalse); | 272 expect(file.isPart, isFalse); |
| 270 expect(file.library, isNull); | 273 expect(file.library, isNull); |
| 271 expect(file.unlinked, isNotNull); | 274 expect(file.unlinked, isNotNull); |
| 272 expect(file.unlinked.classes, isEmpty); | 275 expect(file.unlinked.classes, isEmpty); |
| 273 } | 276 } |
| 274 | 277 |
| 278 test_getFileForPath_generatedFile() { |
| 279 Uri uri = Uri.parse('package:aaa/foo.dart'); |
| 280 String templatePath = _p('/aaa/lib/foo.dart'); |
| 281 String generatedPath = _p('/generated/aaa/lib/foo.dart'); |
| 282 |
| 283 Source generatedSource = new _SourceMock(); |
| 284 when(generatedSource.fullName).thenReturn(generatedPath); |
| 285 when(generatedSource.uri).thenReturn(uri); |
| 286 |
| 287 when(generatedUriResolver.resolveAbsolute(uri, uri)) |
| 288 .thenReturn(generatedSource); |
| 289 |
| 290 FileState generatedFile = fileSystemState.getFileForUri(uri); |
| 291 expect(generatedFile.path, generatedPath); |
| 292 expect(generatedFile.uri, uri); |
| 293 |
| 294 FileState templateFile = fileSystemState.getFileForPath(templatePath); |
| 295 expect(templateFile.path, templatePath); |
| 296 expect(templateFile.uri, uri); |
| 297 |
| 298 expect(fileSystemState.getFilesForPath(templatePath), [templateFile]); |
| 299 } |
| 300 |
| 275 test_getFileForPath_library() { | 301 test_getFileForPath_library() { |
| 276 String a1 = _p('/aaa/lib/a1.dart'); | 302 String a1 = _p('/aaa/lib/a1.dart'); |
| 277 String a2 = _p('/aaa/lib/a2.dart'); | 303 String a2 = _p('/aaa/lib/a2.dart'); |
| 278 String a3 = _p('/aaa/lib/a3.dart'); | 304 String a3 = _p('/aaa/lib/a3.dart'); |
| 279 String a4 = _p('/aaa/lib/a4.dart'); | 305 String a4 = _p('/aaa/lib/a4.dart'); |
| 280 String b1 = _p('/bbb/lib/b1.dart'); | 306 String b1 = _p('/bbb/lib/b1.dart'); |
| 281 String b2 = _p('/bbb/lib/b2.dart'); | 307 String b2 = _p('/bbb/lib/b2.dart'); |
| 282 String content_a1 = r''' | 308 String content_a1 = r''' |
| 283 import 'package:aaa/a2.dart'; | 309 import 'package:aaa/a2.dart'; |
| 284 import 'package:bbb/b1.dart'; | 310 import 'package:bbb/b1.dart'; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 723 } |
| 698 }).toList(); | 724 }).toList(); |
| 699 } | 725 } |
| 700 | 726 |
| 701 String _p(String path) => provider.convertPath(path); | 727 String _p(String path) => provider.convertPath(path); |
| 702 | 728 |
| 703 static String _md5(String content) { | 729 static String _md5(String content) { |
| 704 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 730 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 705 } | 731 } |
| 706 } | 732 } |
| 733 |
| 734 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} |
| 735 |
| 736 class _SourceMock extends TypedMock implements Source {} |
| OLD | NEW |