Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: pkg/front_end/test/src/incremental/file_state_test.dart

Issue 2931183003: Implement promised watch behaviour for used == true. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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'; 5 import 'dart:async';
6 6
7 import 'package:front_end/memory_file_system.dart'; 7 import 'package:front_end/memory_file_system.dart';
8 import 'package:front_end/src/fasta/translate_uri.dart'; 8 import 'package:front_end/src/fasta/translate_uri.dart';
9 import 'package:front_end/src/incremental/file_state.dart'; 9 import 'package:front_end/src/incremental/file_state.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; 11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 12
13 import 'mock_sdk.dart'; 13 import 'mock_sdk.dart';
14 14
15 main() { 15 main() {
16 defineReflectiveSuite(() { 16 defineReflectiveSuite(() {
17 defineReflectiveTests(FileSystemStateTest); 17 defineReflectiveTests(FileSystemStateTest);
18 }); 18 });
19 } 19 }
20 20
21 @reflectiveTest 21 @reflectiveTest
22 class FileSystemStateTest { 22 class FileSystemStateTest {
23 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 23 final fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
24 final TranslateUri uriTranslator = new TranslateUri({}, {}, {}); 24 final TranslateUri uriTranslator = new TranslateUri({}, {}, {});
25 FileSystemState fsState; 25 FileSystemState fsState;
26 26
27 Uri _coreUri; 27 Uri _coreUri;
28 List<Uri> _newFileUris = <Uri>[];
28 29
29 void setUp() { 30 void setUp() {
30 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); 31 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem);
31 uriTranslator.dartLibraries.addAll(dartLibraries); 32 uriTranslator.dartLibraries.addAll(dartLibraries);
32 _coreUri = Uri.parse('dart:core'); 33 _coreUri = Uri.parse('dart:core');
33 expect(_coreUri, isNotNull); 34 expect(_coreUri, isNotNull);
34 fsState = new FileSystemState(fileSystem, uriTranslator, <int>[]); 35 fsState = new FileSystemState(fileSystem, uriTranslator, <int>[], (uri) {
36 _newFileUris.add(uri);
37 return new Future.value();
38 });
35 } 39 }
36 40
37 test_apiSignature() async { 41 test_apiSignature() async {
38 var path = '/a.dart'; 42 var path = '/a.dart';
39 var uri = writeFile(path, ''); 43 var uri = writeFile(path, '');
40 FileState file = await fsState.getFile(uri); 44 FileState file = await fsState.getFile(uri);
41 45
42 List<int> lastSignature = file.apiSignature; 46 List<int> lastSignature = file.apiSignature;
43 47
44 /// Assert that the given [newCode] has the same API signature as 48 /// Assert that the given [newCode] has the same API signature as
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 expect(export_.combinators[1].names, unorderedEquals(['C'])); 229 expect(export_.combinators[1].names, unorderedEquals(['C']));
226 expect(export_.combinators[2].isShow, isTrue); 230 expect(export_.combinators[2].isShow, isTrue);
227 expect(export_.combinators[2].names, unorderedEquals(['A', 'D'])); 231 expect(export_.combinators[2].names, unorderedEquals(['A', 'D']));
228 expect(export_.isExposed('A'), isTrue); 232 expect(export_.isExposed('A'), isTrue);
229 expect(export_.isExposed('B'), isFalse); 233 expect(export_.isExposed('B'), isFalse);
230 expect(export_.isExposed('C'), isFalse); 234 expect(export_.isExposed('C'), isFalse);
231 expect(export_.isExposed('D'), isTrue); 235 expect(export_.isExposed('D'), isTrue);
232 } 236 }
233 } 237 }
234 238
239 test_newFileListener() async {
240 var a = writeFile('/a.dart', '');
241 var b = writeFile('/b.dart', '');
242 var c = writeFile(
243 '/c.dart',
244 r'''
245 import 'a.dart';
246 ''');
247
248 FileState cFile = await fsState.getFile(c);
249
250 // c.dart uses c.dart and a.dart, but not b.dart yet.
251 expect(_newFileUris, contains(c));
252 expect(_newFileUris, contains(a));
253 expect(_newFileUris, isNot(contains(b)));
254 _newFileUris.clear();
255
256 // Update c.dart to use b.dart too.
257 writeFile(
258 '/c.dart',
259 r'''
260 import 'a.dart';
261 import 'b.dart';
262 ''');
263 await cFile.refresh();
264
265 // b.dart is the only new file.
266 expect(_newFileUris, [b]);
267 }
268
235 test_topologicalOrder_cycleBeforeTarget() async { 269 test_topologicalOrder_cycleBeforeTarget() async {
236 var aUri = _writeFileDirectives('/a.dart'); 270 var aUri = _writeFileDirectives('/a.dart');
237 var bUri = _writeFileDirectives('/b.dart', imports: ['c.dart']); 271 var bUri = _writeFileDirectives('/b.dart', imports: ['c.dart']);
238 var cUri = _writeFileDirectives('/c.dart', imports: ['b.dart']); 272 var cUri = _writeFileDirectives('/c.dart', imports: ['b.dart']);
239 var dUri = _writeFileDirectives('/d.dart', imports: ['a.dart', 'b.dart']); 273 var dUri = _writeFileDirectives('/d.dart', imports: ['a.dart', 'b.dart']);
240 274
241 FileState core = await fsState.getFile(_coreUri); 275 FileState core = await fsState.getFile(_coreUri);
242 FileState a = await fsState.getFile(aUri); 276 FileState a = await fsState.getFile(aUri);
243 FileState b = await fsState.getFile(bUri); 277 FileState b = await fsState.getFile(bUri);
244 FileState c = await fsState.getFile(cUri); 278 FileState c = await fsState.getFile(cUri);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 Uri _writeFileDirectives(String path, 343 Uri _writeFileDirectives(String path,
310 {List<String> imports: const [], List<String> exports: const []}) { 344 {List<String> imports: const [], List<String> exports: const []}) {
311 return writeFile( 345 return writeFile(
312 path, 346 path,
313 ''' 347 '''
314 ${imports.map((uri) => 'import "$uri";').join('\n')} 348 ${imports.map((uri) => 'import "$uri";').join('\n')}
315 ${exports.map((uri) => 'export "$uri";').join('\n')} 349 ${exports.map((uri) => 'export "$uri";').join('\n')}
316 '''); 350 ''');
317 } 351 }
318 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698