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'; | 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/byte_store.dart'; | 9 import 'package:front_end/src/incremental/byte_store.dart'; |
10 import 'package:front_end/src/incremental/file_state.dart'; | 10 import 'package:front_end/src/incremental/file_state.dart'; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 FileState b = await fsState.getFile(bUri); | 484 FileState b = await fsState.getFile(bUri); |
485 FileState c = await fsState.getFile(cUri); | 485 FileState c = await fsState.getFile(cUri); |
486 | 486 |
487 List<LibraryCycle> order = c.topologicalOrder; | 487 List<LibraryCycle> order = c.topologicalOrder; |
488 expect(order, hasLength(3)); | 488 expect(order, hasLength(3)); |
489 expect(order[0].libraries, contains(core)); | 489 expect(order[0].libraries, contains(core)); |
490 expect(order[1].libraries, unorderedEquals([a])); | 490 expect(order[1].libraries, unorderedEquals([a])); |
491 expect(order[2].libraries, unorderedEquals([b, c])); | 491 expect(order[2].libraries, unorderedEquals([b, c])); |
492 } | 492 } |
493 | 493 |
| 494 test_transitiveFiles() async { |
| 495 var a = writeFile('/a.dart', ""); |
| 496 var b = writeFile('/b.dart', ""); |
| 497 var c = writeFile('/c.dart', "import 'b.dart';"); |
| 498 |
| 499 FileState aFile = await fsState.getFile(a); |
| 500 FileState bFile = await fsState.getFile(b); |
| 501 FileState cFile = await fsState.getFile(c); |
| 502 |
| 503 // Only c.dart and b.dart are in the transitive closure. |
| 504 expect(cFile.transitiveFiles, contains(cFile)); |
| 505 expect(cFile.transitiveFiles, contains(bFile)); |
| 506 expect(cFile.transitiveFiles, isNot(contains(aFile))); |
| 507 expect(bFile.transitiveFiles, isNot(contains(aFile))); |
| 508 |
| 509 // Import a.dart into b.dart, changes c.dart transitive closure. |
| 510 writeFile('/b.dart', "import 'a.dart';"); |
| 511 await bFile.refresh(); |
| 512 expect(cFile.transitiveFiles, contains(cFile)); |
| 513 expect(cFile.transitiveFiles, contains(bFile)); |
| 514 expect(cFile.transitiveFiles, contains(aFile)); |
| 515 expect(bFile.transitiveFiles, contains(aFile)); |
| 516 |
| 517 // Stop importing a.dart into b.dart, changes c.dart transitive closure. |
| 518 writeFile('/b.dart', ""); |
| 519 await bFile.refresh(); |
| 520 expect(cFile.transitiveFiles, contains(cFile)); |
| 521 expect(cFile.transitiveFiles, contains(bFile)); |
| 522 expect(cFile.transitiveFiles, isNot(contains(aFile))); |
| 523 expect(bFile.transitiveFiles, isNot(contains(aFile))); |
| 524 } |
| 525 |
494 /// Write the given [text] of the file with the given [path] into the | 526 /// Write the given [text] of the file with the given [path] into the |
495 /// virtual filesystem. Return the URI of the file. | 527 /// virtual filesystem. Return the URI of the file. |
496 Uri writeFile(String path, String text) { | 528 Uri writeFile(String path, String text) { |
497 Uri uri = Uri.parse('file://$path'); | 529 Uri uri = Uri.parse('file://$path'); |
498 fileSystem.entityForUri(uri).writeAsStringSync(text); | 530 fileSystem.entityForUri(uri).writeAsStringSync(text); |
499 return uri; | 531 return uri; |
500 } | 532 } |
501 | 533 |
502 void _assertImportedUris(FileState file, List<Uri> expectedUris) { | 534 void _assertImportedUris(FileState file, List<Uri> expectedUris) { |
503 Iterable<Uri> importedUris = _toUris(file.importedLibraries); | 535 Iterable<Uri> importedUris = _toUris(file.importedLibraries); |
504 expect(importedUris, unorderedEquals(expectedUris)); | 536 expect(importedUris, unorderedEquals(expectedUris)); |
505 } | 537 } |
506 | 538 |
507 Iterable<Uri> _toUris(List<FileState> files) { | 539 Iterable<Uri> _toUris(List<FileState> files) { |
508 return files.map((f) => f.uri); | 540 return files.map((f) => f.uri); |
509 } | 541 } |
510 | 542 |
511 Uri _writeFileDirectives(String path, | 543 Uri _writeFileDirectives(String path, |
512 {List<String> imports: const [], List<String> exports: const []}) { | 544 {List<String> imports: const [], List<String> exports: const []}) { |
513 return writeFile( | 545 return writeFile( |
514 path, | 546 path, |
515 ''' | 547 ''' |
516 ${imports.map((uri) => 'import "$uri";').join('\n')} | 548 ${imports.map((uri) => 'import "$uri";').join('\n')} |
517 ${exports.map((uri) => 'export "$uri";').join('\n')} | 549 ${exports.map((uri) => 'export "$uri";').join('\n')} |
518 '''); | 550 '''); |
519 } | 551 } |
520 } | 552 } |
OLD | NEW |