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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Issue 2826243002: Add FileSystemState.knownFilesSetChanges stream. (Closed)
Patch Set: Created 3 years, 8 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) 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:async';
5 import 'dart:convert'; 6 import 'dart:convert';
6 import 'dart:typed_data'; 7 import 'dart:typed_data';
7 8
8 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/file_system/memory_file_system.dart'; 10 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 11 import 'package:analyzer/source/package_map_resolver.dart';
11 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 12 import 'package:analyzer/src/dart/analysis/byte_store.dart';
12 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog; 13 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog;
13 import 'package:analyzer/src/dart/analysis/file_state.dart'; 14 import 'package:analyzer/src/dart/analysis/file_state.dart';
14 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; 15 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 when(generatedSource.fullName).thenReturn(generatedPath); 556 when(generatedSource.fullName).thenReturn(generatedPath);
556 when(generatedSource.uri).thenReturn(uri); 557 when(generatedSource.uri).thenReturn(uri);
557 558
558 when(generatedUriResolver.resolveAbsolute(uri, uri)) 559 when(generatedUriResolver.resolveAbsolute(uri, uri))
559 .thenReturn(generatedSource); 560 .thenReturn(generatedSource);
560 561
561 expect(fileSystemState.hasUri(templatePath), isFalse); 562 expect(fileSystemState.hasUri(templatePath), isFalse);
562 expect(fileSystemState.hasUri(generatedPath), isTrue); 563 expect(fileSystemState.hasUri(generatedPath), isTrue);
563 } 564 }
564 565
566 test_knownFilesSetChanges() async {
567 fileSystemState.test.knownFilesDelay = new Duration(milliseconds: 5);
568
569 String a = _p('/test/lib/a.dart');
570 String b = _p('/test/lib/b.dart');
571 String c = _p('/test/lib/c.dart');
572 provider.newFile(
573 a,
574 r'''
575 import 'b.dart';
576 ''');
577 provider.newFile(b, '');
578 provider.newFile(c, '');
579
580 Stream<KnownFilesSetChange> broadcastEvents =
581 fileSystemState.knownFilesSetChanges.asBroadcastStream();
582
583 FileState file = fileSystemState.getFileForPath(a);
584 {
585 KnownFilesSetChange event = await broadcastEvents.first;
586 expect(event.added, contains(a));
587 expect(event.added, contains(b));
588 expect(event.removed, isEmpty);
589 }
590
591 // Update a.dart to import c.dart and refresh.
592 // So, c.dart should be reported as added in the next change event.
593 provider.newFile(
594 a,
595 r'''
596 import 'b.dart';
597 import 'c.dart';
598 ''');
599 file.refresh();
600 {
601 KnownFilesSetChange event = await broadcastEvents.first;
602 expect(event.added, contains(c));
603 expect(event.removed, isEmpty);
604 }
605 }
606
565 test_referencedNames() { 607 test_referencedNames() {
566 String path = _p('/aaa/lib/a.dart'); 608 String path = _p('/aaa/lib/a.dart');
567 provider.newFile( 609 provider.newFile(
568 path, 610 path,
569 r''' 611 r'''
570 A foo(B p) { 612 A foo(B p) {
571 foo(null); 613 foo(null);
572 C c = new C(p); 614 C c = new C(p);
573 return c; 615 return c;
574 } 616 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 String _p(String path) => provider.convertPath(path); 873 String _p(String path) => provider.convertPath(path);
832 874
833 static String _md5(String content) { 875 static String _md5(String content) {
834 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 876 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
835 } 877 }
836 } 878 }
837 879
838 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} 880 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {}
839 881
840 class _SourceMock extends TypedMock implements Source {} 882 class _SourceMock extends TypedMock implements Source {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698