| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 9 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 10 import 'package:front_end/compiler_options.dart'; |
| 11 import 'package:front_end/incremental_resolved_ast_generator.dart'; |
| 12 import 'package:front_end/memory_file_system.dart'; |
| 13 import 'package:path/path.dart' as pathos; |
| 14 import 'package:test/test.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 16 |
| 17 main() { |
| 18 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(IncrementalResolvedAstGeneratorTest); |
| 20 }); |
| 21 } |
| 22 |
| 23 final _sdkSummary = _readSdkSummary(); |
| 24 |
| 25 List<int> _readSdkSummary() { |
| 26 var resourceProvider = PhysicalResourceProvider.INSTANCE; |
| 27 var sdk = new FolderBasedDartSdk(resourceProvider, |
| 28 FolderBasedDartSdk.defaultSdkDirectory(resourceProvider)) |
| 29 ..useSummary = true; |
| 30 var path = resourceProvider.pathContext |
| 31 .join(sdk.directory.path, 'lib', '_internal', 'strong.sum'); |
| 32 return resourceProvider.getFile(path).readAsBytesSync(); |
| 33 } |
| 34 |
| 35 @reflectiveTest |
| 36 class IncrementalResolvedAstGeneratorTest { |
| 37 static final sdkSummaryUri = Uri.parse('special:sdk_summary'); |
| 38 |
| 39 /// Virtual filesystem for testing. |
| 40 final fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///')); |
| 41 |
| 42 /// The object under test. |
| 43 IncrementalResolvedAstGenerator incrementalResolvedAstGenerator; |
| 44 |
| 45 Future<Map<Uri, ResolvedLibrary>> getInitialProgram(Uri startingUri) async { |
| 46 fileSystem.entityForUri(sdkSummaryUri).writeAsBytesSync(_sdkSummary); |
| 47 incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( |
| 48 startingUri, |
| 49 new CompilerOptions() |
| 50 ..fileSystem = fileSystem |
| 51 ..chaseDependencies = true |
| 52 ..sdkSummary = sdkSummaryUri |
| 53 ..packagesFileUri = new Uri()); |
| 54 return (await incrementalResolvedAstGenerator.computeDelta()).newState; |
| 55 } |
| 56 |
| 57 test_emptyProgram() async { |
| 58 writeFiles({'/foo.dart': 'main() {}'}); |
| 59 var fooUri = Uri.parse('file:///foo.dart'); |
| 60 var initialProgram = await getInitialProgram(fooUri); |
| 61 expect(initialProgram.keys, unorderedEquals([fooUri])); |
| 62 var unit = initialProgram[fooUri].definingCompilationUnit; |
| 63 expect(unit.declarations, hasLength(1)); |
| 64 expect(unit.declarations[0], new isInstanceOf<FunctionDeclaration>()); |
| 65 var main = unit.declarations[0] as FunctionDeclaration; |
| 66 expect(main.name.name, 'main'); |
| 67 // TODO(paulberry): test that stuff is actually resolved. |
| 68 // TODO(paulberry): test parts. |
| 69 } |
| 70 |
| 71 /// Write the given file contents to the virtual filesystem. |
| 72 void writeFiles(Map<String, String> contents) { |
| 73 contents.forEach((path, text) { |
| 74 fileSystem |
| 75 .entityForUri(Uri.parse('file://$path')) |
| 76 .writeAsStringSync(text); |
| 77 }); |
| 78 } |
| 79 } |
| OLD | NEW |