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

Side by Side Diff: pkg/analyzer/test/src/task/dart_work_manager_test.dart

Issue 2184243002: Add a couple of new tests for DartWorkManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « pkg/analyzer/lib/src/task/dart_work_manager.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.test.src.task.dart_work_manager_test; 5 library analyzer.test.src.task.dart_work_manager_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/src/context/cache.dart'; 8 import 'package:analyzer/src/context/cache.dart';
9 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; 9 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode;
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 manager.libraryPartsMap[library1] = [part1]; 340 manager.libraryPartsMap[library1] = [part1];
341 manager.libraryPartsMap[library2] = [part1, part2]; 341 manager.libraryPartsMap[library2] = [part1, part2];
342 // getLibrariesContainingPart 342 // getLibrariesContainingPart
343 expect(manager.getLibrariesContainingPart(part1), 343 expect(manager.getLibrariesContainingPart(part1),
344 unorderedEquals([library1, library2])); 344 unorderedEquals([library1, library2]));
345 expect( 345 expect(
346 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); 346 manager.getLibrariesContainingPart(part2), unorderedEquals([library2]));
347 expect(manager.getLibrariesContainingPart(part3), isEmpty); 347 expect(manager.getLibrariesContainingPart(part3), isEmpty);
348 } 348 }
349 349
350 void test_getLibrariesContainingPart_askResultProvider() {
351 Source part1 = new TestSource('part1.dart');
352 Source part2 = new TestSource('part2.dart');
353 Source part3 = new TestSource('part3.dart');
354 Source library1 = new TestSource('library1.dart');
355 Source library2 = new TestSource('library2.dart');
356 // configure AnalysisContext mock
357 when(context.aboutToComputeResult(anyObject, CONTAINING_LIBRARIES))
358 .thenInvoke((CacheEntry entry, ResultDescriptor result) {
359 if (entry.target == part1) {
360 entry.setValue(result, <Source>[library1, library2], []);
361 return true;
362 }
363 if (entry.target == part2) {
364 entry.setValue(result, <Source>[library2], []);
365 return true;
366 }
367 return false;
368 });
369 // getLibrariesContainingPart
370 expect(manager.getLibrariesContainingPart(part1),
371 unorderedEquals([library1, library2]));
372 expect(
373 manager.getLibrariesContainingPart(part2), unorderedEquals([library2]));
374 expect(manager.getLibrariesContainingPart(part3), isEmpty);
375 }
376
350 void test_getLibrariesContainingPart_inSDK() { 377 void test_getLibrariesContainingPart_inSDK() {
351 Source part = new _SourceMock('part.dart'); 378 Source part = new _SourceMock('part.dart');
352 when(part.isInSystemLibrary).thenReturn(true); 379 when(part.isInSystemLibrary).thenReturn(true);
353 // SDK work manager 380 // SDK work manager
354 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock(); 381 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock();
355 when(sdkDartWorkManagerMock.getLibrariesContainingPart(part)) 382 when(sdkDartWorkManagerMock.getLibrariesContainingPart(part))
356 .thenReturn([source2, source3]); 383 .thenReturn([source2, source3]);
357 // SDK context mock 384 // SDK context mock
358 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock(); 385 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock();
359 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]); 386 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 785
759 void test_resultsComputed_updatePartsLibraries_partParsed() { 786 void test_resultsComputed_updatePartsLibraries_partParsed() {
760 Source part = new TestSource('part.dart'); 787 Source part = new TestSource('part.dart');
761 expect(manager.libraryPartsMap, isEmpty); 788 expect(manager.libraryPartsMap, isEmpty);
762 // part.dart parsed, no changes is the map of libraries 789 // part.dart parsed, no changes is the map of libraries
763 manager.resultsComputed( 790 manager.resultsComputed(
764 part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]}); 791 part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]});
765 expect(manager.libraryPartsMap, isEmpty); 792 expect(manager.libraryPartsMap, isEmpty);
766 } 793 }
767 794
795 void test_unitIncrementallyResolved() {
796 manager.unitIncrementallyResolved(source1, source2);
797 expect_librarySourceQueue([source1]);
798 }
799
768 CacheEntry _getOrCreateEntry(Source source, [bool explicit = true]) { 800 CacheEntry _getOrCreateEntry(Source source, [bool explicit = true]) {
769 CacheEntry entry = cache.get(source); 801 CacheEntry entry = cache.get(source);
770 if (entry == null) { 802 if (entry == null) {
771 entry = new CacheEntry(source); 803 entry = new CacheEntry(source);
772 entry.explicitlyAdded = explicit; 804 entry.explicitlyAdded = explicit;
773 cache.put(entry); 805 cache.put(entry);
774 } 806 }
775 return entry; 807 return entry;
776 } 808 }
777 } 809 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 class _SourceFactoryMock extends TypedMock implements SourceFactory {} 854 class _SourceFactoryMock extends TypedMock implements SourceFactory {}
823 855
824 class _SourceMock extends TypedMock implements Source { 856 class _SourceMock extends TypedMock implements Source {
825 final String shortName; 857 final String shortName;
826 _SourceMock(this.shortName); 858 _SourceMock(this.shortName);
827 @override 859 @override
828 String get fullName => '/' + shortName; 860 String get fullName => '/' + shortName;
829 @override 861 @override
830 String toString() => fullName; 862 String toString() => fullName;
831 } 863 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart_work_manager.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698