OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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:async'; |
| 6 |
5 import 'package:front_end/memory_file_system.dart'; | 7 import 'package:front_end/memory_file_system.dart'; |
6 import 'package:front_end/src/fasta/translate_uri.dart'; | 8 import 'package:front_end/src/fasta/translate_uri.dart'; |
7 import 'package:front_end/src/incremental/file_state.dart'; | 9 import 'package:front_end/src/incremental/file_state.dart'; |
8 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
10 | 12 |
11 import 'mock_sdk.dart'; | 13 import 'mock_sdk.dart'; |
12 | 14 |
13 main() { | 15 main() { |
14 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
15 defineReflectiveTests(FileSystemStateTest); | 17 defineReflectiveTests(FileSystemStateTest); |
16 }); | 18 }); |
17 } | 19 } |
18 | 20 |
19 @reflectiveTest | 21 @reflectiveTest |
20 class FileSystemStateTest { | 22 class FileSystemStateTest { |
21 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); | 23 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
22 final TranslateUri uriTranslator = new TranslateUri({}, {}, {}); | 24 final TranslateUri uriTranslator = new TranslateUri({}, {}, {}); |
23 FileSystemState fsState; | 25 FileSystemState fsState; |
24 | 26 |
25 Uri _coreUri; | 27 Uri _coreUri; |
26 | 28 |
27 void setUp() { | 29 void setUp() { |
28 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); | 30 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); |
29 uriTranslator.dartLibraries.addAll(dartLibraries); | 31 uriTranslator.dartLibraries.addAll(dartLibraries); |
30 _coreUri = Uri.parse('dart:core'); | 32 _coreUri = Uri.parse('dart:core'); |
31 expect(_coreUri, isNotNull); | 33 expect(_coreUri, isNotNull); |
32 fsState = new FileSystemState(fileSystem, uriTranslator); | 34 fsState = new FileSystemState(fileSystem, uriTranslator, <int>[]); |
| 35 } |
| 36 |
| 37 test_apiSignature() async { |
| 38 var path = '/a.dart'; |
| 39 var uri = writeFile(path, ''); |
| 40 FileState file = await fsState.getFile(uri); |
| 41 |
| 42 List<int> lastSignature = file.apiSignature; |
| 43 |
| 44 /// Assert that the given [newCode] has the same API signature as |
| 45 /// the last computed. |
| 46 Future<Null> assertSameSignature(String newCode) async { |
| 47 writeFile(path, newCode); |
| 48 await file.refresh(); |
| 49 List<int> newSignature = file.apiSignature; |
| 50 expect(newSignature, lastSignature); |
| 51 } |
| 52 |
| 53 /// Assert that the given [newCode] does not have the same API signature as |
| 54 /// the last computed, and update the last signature to the new one. |
| 55 Future<Null> assertNotSameSignature(String newCode) async { |
| 56 writeFile(path, newCode); |
| 57 await file.refresh(); |
| 58 List<int> newSignature = file.apiSignature; |
| 59 expect(newSignature, isNot(lastSignature)); |
| 60 lastSignature = newSignature; |
| 61 } |
| 62 |
| 63 await assertNotSameSignature(''' |
| 64 var v = 1; |
| 65 foo() { |
| 66 print(2); |
| 67 } |
| 68 bar() { |
| 69 print(3); |
| 70 } |
| 71 baz() => 4; |
| 72 '''); |
| 73 |
| 74 // [S] Add comments. |
| 75 await assertSameSignature(''' |
| 76 var v = 1; // comment |
| 77 /// comment 1 |
| 78 /// comment 2 |
| 79 foo() { |
| 80 print(2); |
| 81 } |
| 82 bar() { |
| 83 print(3); |
| 84 } |
| 85 /** |
| 86 * Comment |
| 87 */ |
| 88 baz() => 4; |
| 89 '''); |
| 90 |
| 91 // [S] Remove comments. |
| 92 await assertSameSignature(''' |
| 93 var v = 1; |
| 94 foo() { |
| 95 print(2); |
| 96 } |
| 97 bar() { |
| 98 print(3); |
| 99 } |
| 100 baz() => 4; |
| 101 '''); |
| 102 |
| 103 // [NS] Change the top-level variable initializer. |
| 104 await assertNotSameSignature(''' |
| 105 var v = 11; |
| 106 foo() { |
| 107 print(2); |
| 108 } |
| 109 bar() { |
| 110 print(3); |
| 111 } |
| 112 baz() => 4; |
| 113 '''); |
| 114 |
| 115 // [S] Change in a block function body. |
| 116 await assertSameSignature(''' |
| 117 var v = 11; |
| 118 foo() { |
| 119 print(22); |
| 120 } |
| 121 bar() { |
| 122 print(33); |
| 123 } |
| 124 baz() => 4; |
| 125 '''); |
| 126 |
| 127 // [NS] Change in an expression function body. |
| 128 await assertNotSameSignature(''' |
| 129 var v = 11; |
| 130 foo() { |
| 131 print(22); |
| 132 } |
| 133 bar() { |
| 134 print(33); |
| 135 } |
| 136 baz() => 44; |
| 137 '''); |
33 } | 138 } |
34 | 139 |
35 test_getFile() async { | 140 test_getFile() async { |
36 var a = writeFile('/a.dart', ''); | 141 var a = writeFile('/a.dart', ''); |
37 var b = writeFile('/b.dart', ''); | 142 var b = writeFile('/b.dart', ''); |
38 var c = writeFile('/c.dart', ''); | 143 var c = writeFile('/c.dart', ''); |
39 var d = writeFile( | 144 var d = writeFile( |
40 '/d.dart', | 145 '/d.dart', |
41 r''' | 146 r''' |
42 import "a.dart"; | 147 import "a.dart"; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 Uri _writeFileDirectives(String path, | 309 Uri _writeFileDirectives(String path, |
205 {List<String> imports: const [], List<String> exports: const []}) { | 310 {List<String> imports: const [], List<String> exports: const []}) { |
206 return writeFile( | 311 return writeFile( |
207 path, | 312 path, |
208 ''' | 313 ''' |
209 ${imports.map((uri) => 'import "$uri";').join('\n')} | 314 ${imports.map((uri) => 'import "$uri";').join('\n')} |
210 ${exports.map((uri) => 'export "$uri";').join('\n')} | 315 ${exports.map((uri) => 'export "$uri";').join('\n')} |
211 '''); | 316 '''); |
212 } | 317 } |
213 } | 318 } |
OLD | NEW |