OLD | NEW |
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 test.src.task.dart_work_manager_test; | 5 library test.src.task.dart_work_manager_test; |
6 | 6 |
7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
10 show | 10 show |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 172 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
173 // change part1 | 173 // change part1 |
174 manager.applyChange([], [part1], []); | 174 manager.applyChange([], [part1], []); |
175 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 175 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
176 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 176 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
177 expect(manager.libraryPartsMap[library1], [part1, part3]); | 177 expect(manager.libraryPartsMap[library1], [part1, part3]); |
178 expect(manager.libraryPartsMap[library2], [part1, part2]); | 178 expect(manager.libraryPartsMap[library2], [part1, part2]); |
179 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 179 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
180 } | 180 } |
181 | 181 |
182 CacheEntry _getOrCreateEntry(Source source) { | |
183 CacheEntry entry = cache.get(source); | |
184 if (entry == null) { | |
185 entry = new CacheEntry(source); | |
186 cache.put(entry); | |
187 } | |
188 return entry; | |
189 } | |
190 | |
191 void test_applyChange_updatePartsLibraries_removeLibrary() { | 182 void test_applyChange_updatePartsLibraries_removeLibrary() { |
192 Source part1 = new TestSource('part1.dart'); | 183 Source part1 = new TestSource('part1.dart'); |
193 Source part2 = new TestSource('part2.dart'); | 184 Source part2 = new TestSource('part2.dart'); |
194 Source part3 = new TestSource('part3.dart'); | 185 Source part3 = new TestSource('part3.dart'); |
195 Source library1 = new TestSource('library1.dart'); | 186 Source library1 = new TestSource('library1.dart'); |
196 Source library2 = new TestSource('library2.dart'); | 187 Source library2 = new TestSource('library2.dart'); |
197 manager.partLibrariesMap[part1] = [library1, library2]; | 188 manager.partLibrariesMap[part1] = [library1, library2]; |
198 manager.partLibrariesMap[part2] = [library2]; | 189 manager.partLibrariesMap[part2] = [library2]; |
199 manager.partLibrariesMap[part3] = [library1]; | 190 manager.partLibrariesMap[part3] = [library1]; |
200 manager.libraryPartsMap[library1] = [part1, part3]; | 191 manager.libraryPartsMap[library1] = [part1, part3]; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 404 |
414 void test_getNextResultPriority_hasUnknown() { | 405 void test_getNextResultPriority_hasUnknown() { |
415 manager.unknownSourceQueue.addAll([source1]); | 406 manager.unknownSourceQueue.addAll([source1]); |
416 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 407 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
417 } | 408 } |
418 | 409 |
419 void test_getNextResultPriority_nothingToDo() { | 410 void test_getNextResultPriority_nothingToDo() { |
420 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 411 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
421 } | 412 } |
422 | 413 |
| 414 void test_onAnalysisOptionsChanged() { |
| 415 when(context.exists(anyObject)).thenReturn(true); |
| 416 // set cache values |
| 417 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); |
| 418 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
| 419 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
| 420 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
| 421 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
| 422 // configure LibrarySpecificUnit |
| 423 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
| 424 CacheEntry unitEntry = new CacheEntry(unitTarget); |
| 425 cache.put(unitEntry); |
| 426 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); |
| 427 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); |
| 428 // notify |
| 429 manager.onAnalysisOptionsChanged(); |
| 430 // resolution is invalidated |
| 431 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); |
| 432 // ...but URIs are still value |
| 433 expect(entry1.getState(PARSED_UNIT), CacheState.VALID); |
| 434 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); |
| 435 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); |
| 436 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); |
| 437 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); |
| 438 } |
| 439 |
| 440 void test_onSourceFactoryChanged() { |
| 441 when(context.exists(anyObject)).thenReturn(true); |
| 442 // set cache values |
| 443 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); |
| 444 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
| 445 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
| 446 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
| 447 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
| 448 // configure LibrarySpecificUnit |
| 449 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
| 450 CacheEntry unitEntry = new CacheEntry(unitTarget); |
| 451 cache.put(unitEntry); |
| 452 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); |
| 453 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); |
| 454 // notify |
| 455 manager.onSourceFactoryChanged(); |
| 456 // resolution is invalidated |
| 457 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); |
| 458 // ...and URIs resolution too |
| 459 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); |
| 460 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); |
| 461 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); |
| 462 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); |
| 463 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); |
| 464 } |
| 465 |
423 void test_resultsComputed_errors_forLibrarySpecificUnit() { | 466 void test_resultsComputed_errors_forLibrarySpecificUnit() { |
424 AnalysisError error1 = | 467 AnalysisError error1 = |
425 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 468 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
426 AnalysisError error2 = | 469 AnalysisError error2 = |
427 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 470 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
428 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 471 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
429 LineInfo lineInfo = new LineInfo([0]); | 472 LineInfo lineInfo = new LineInfo([0]); |
430 entry1.setValue(LINE_INFO, lineInfo, []); | 473 entry1.setValue(LINE_INFO, lineInfo, []); |
431 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 474 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
432 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); | 475 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 expect_librarySourceQueue([source2]); | 575 expect_librarySourceQueue([source2]); |
533 expect_unknownSourceQueue([source1, source3]); | 576 expect_unknownSourceQueue([source1, source3]); |
534 } | 577 } |
535 | 578 |
536 void test_resultsComputed_sourceKind_isPart() { | 579 void test_resultsComputed_sourceKind_isPart() { |
537 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 580 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
538 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); | 581 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); |
539 expect_librarySourceQueue([]); | 582 expect_librarySourceQueue([]); |
540 expect_unknownSourceQueue([source1, source3]); | 583 expect_unknownSourceQueue([source1, source3]); |
541 } | 584 } |
| 585 |
| 586 CacheEntry _getOrCreateEntry(Source source) { |
| 587 CacheEntry entry = cache.get(source); |
| 588 if (entry == null) { |
| 589 entry = new CacheEntry(source); |
| 590 cache.put(entry); |
| 591 } |
| 592 return entry; |
| 593 } |
542 } | 594 } |
543 | 595 |
544 class _InternalAnalysisContextMock extends TypedMock | 596 class _InternalAnalysisContextMock extends TypedMock |
545 implements InternalAnalysisContext { | 597 implements InternalAnalysisContext { |
546 @override | 598 @override |
| 599 CachePartition privateAnalysisCachePartition; |
| 600 |
| 601 @override |
547 AnalysisCache analysisCache; | 602 AnalysisCache analysisCache; |
548 | 603 |
549 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 604 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
550 | 605 |
551 _InternalAnalysisContextMock() { | 606 _InternalAnalysisContextMock() { |
552 analysisCache = new AnalysisCache([new UniversalCachePartition(this)]); | 607 privateAnalysisCachePartition = new UniversalCachePartition(this); |
| 608 analysisCache = new AnalysisCache([privateAnalysisCachePartition]); |
553 } | 609 } |
554 | 610 |
555 @override | 611 @override |
556 CacheEntry getCacheEntry(AnalysisTarget target) { | 612 CacheEntry getCacheEntry(AnalysisTarget target) { |
557 CacheEntry entry = analysisCache.get(target); | 613 CacheEntry entry = analysisCache.get(target); |
558 if (entry == null) { | 614 if (entry == null) { |
559 entry = new CacheEntry(target); | 615 entry = new CacheEntry(target); |
560 analysisCache.put(entry); | 616 analysisCache.put(entry); |
561 } | 617 } |
562 return entry; | 618 return entry; |
563 } | 619 } |
564 | 620 |
565 @override | 621 @override |
566 ChangeNoticeImpl getNotice(Source source) { | 622 ChangeNoticeImpl getNotice(Source source) { |
567 return _pendingNotices.putIfAbsent( | 623 return _pendingNotices.putIfAbsent( |
568 source, () => new ChangeNoticeImpl(source)); | 624 source, () => new ChangeNoticeImpl(source)); |
569 } | 625 } |
570 | 626 |
571 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 627 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
572 } | 628 } |
OLD | NEW |