| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 Source part1 = new TestSource('part1.dart'); | 138 Source part1 = new TestSource('part1.dart'); |
| 139 Source part2 = new TestSource('part2.dart'); | 139 Source part2 = new TestSource('part2.dart'); |
| 140 Source part3 = new TestSource('part3.dart'); | 140 Source part3 = new TestSource('part3.dart'); |
| 141 Source library1 = new TestSource('library1.dart'); | 141 Source library1 = new TestSource('library1.dart'); |
| 142 Source library2 = new TestSource('library2.dart'); | 142 Source library2 = new TestSource('library2.dart'); |
| 143 manager.partLibrariesMap[part1] = [library1, library2]; | 143 manager.partLibrariesMap[part1] = [library1, library2]; |
| 144 manager.partLibrariesMap[part2] = [library2]; | 144 manager.partLibrariesMap[part2] = [library2]; |
| 145 manager.partLibrariesMap[part3] = [library1]; | 145 manager.partLibrariesMap[part3] = [library1]; |
| 146 manager.libraryPartsMap[library1] = [part1, part3]; | 146 manager.libraryPartsMap[library1] = [part1, part3]; |
| 147 manager.libraryPartsMap[library2] = [part1, part2]; | 147 manager.libraryPartsMap[library2] = [part1, part2]; |
| 148 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); |
| 149 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
| 148 // change library1 | 150 // change library1 |
| 149 manager.applyChange([], [library1], []); | 151 manager.applyChange([], [library1], []); |
| 150 expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); | 152 expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); |
| 151 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 153 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 152 expect(manager.partLibrariesMap[part3], unorderedEquals([])); | 154 expect(manager.partLibrariesMap[part3], unorderedEquals([])); |
| 153 expect(manager.libraryPartsMap[library1], isNull); | 155 expect(manager.libraryPartsMap[library1], isNull); |
| 154 expect(manager.libraryPartsMap[library2], [part1, part2]); | 156 expect(manager.libraryPartsMap[library2], [part1, part2]); |
| 157 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void test_applyChange_updatePartsLibraries_changePart() { | 160 void test_applyChange_updatePartsLibraries_changePart() { |
| 158 Source part1 = new TestSource('part1.dart'); | 161 Source part1 = new TestSource('part1.dart'); |
| 159 Source part2 = new TestSource('part2.dart'); | 162 Source part2 = new TestSource('part2.dart'); |
| 160 Source part3 = new TestSource('part3.dart'); | 163 Source part3 = new TestSource('part3.dart'); |
| 161 Source library1 = new TestSource('library1.dart'); | 164 Source library1 = new TestSource('library1.dart'); |
| 162 Source library2 = new TestSource('library2.dart'); | 165 Source library2 = new TestSource('library2.dart'); |
| 163 manager.partLibrariesMap[part1] = [library1, library2]; | 166 manager.partLibrariesMap[part1] = [library1, library2]; |
| 164 manager.partLibrariesMap[part2] = [library2]; | 167 manager.partLibrariesMap[part2] = [library2]; |
| 165 manager.partLibrariesMap[part3] = [library1]; | 168 manager.partLibrariesMap[part3] = [library1]; |
| 166 manager.libraryPartsMap[library1] = [part1, part3]; | 169 manager.libraryPartsMap[library1] = [part1, part3]; |
| 167 manager.libraryPartsMap[library2] = [part1, part2]; | 170 manager.libraryPartsMap[library2] = [part1, part2]; |
| 171 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); |
| 172 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
| 168 // change part1 | 173 // change part1 |
| 169 manager.applyChange([], [part1], []); | 174 manager.applyChange([], [part1], []); |
| 170 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 175 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 171 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 176 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
| 172 expect(manager.libraryPartsMap[library1], [part1, part3]); | 177 expect(manager.libraryPartsMap[library1], [part1, part3]); |
| 173 expect(manager.libraryPartsMap[library2], [part1, part2]); | 178 expect(manager.libraryPartsMap[library2], [part1, part2]); |
| 179 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
| 180 } |
| 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; |
| 174 } | 189 } |
| 175 | 190 |
| 176 void test_applyChange_updatePartsLibraries_removeLibrary() { | 191 void test_applyChange_updatePartsLibraries_removeLibrary() { |
| 177 Source part1 = new TestSource('part1.dart'); | 192 Source part1 = new TestSource('part1.dart'); |
| 178 Source part2 = new TestSource('part2.dart'); | 193 Source part2 = new TestSource('part2.dart'); |
| 179 Source part3 = new TestSource('part3.dart'); | 194 Source part3 = new TestSource('part3.dart'); |
| 180 Source library1 = new TestSource('library1.dart'); | 195 Source library1 = new TestSource('library1.dart'); |
| 181 Source library2 = new TestSource('library2.dart'); | 196 Source library2 = new TestSource('library2.dart'); |
| 182 manager.partLibrariesMap[part1] = [library1, library2]; | 197 manager.partLibrariesMap[part1] = [library1, library2]; |
| 183 manager.partLibrariesMap[part2] = [library2]; | 198 manager.partLibrariesMap[part2] = [library2]; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 453 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); |
| 439 // PARSED_UNIT is ready, set errors | 454 // PARSED_UNIT is ready, set errors |
| 440 manager.resultsComputed( | 455 manager.resultsComputed( |
| 441 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); | 456 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); |
| 442 // all of the errors are included | 457 // all of the errors are included |
| 443 ChangeNoticeImpl notice = context.getNotice(source1); | 458 ChangeNoticeImpl notice = context.getNotice(source1); |
| 444 expect(notice.errors, unorderedEquals([error1, error2])); | 459 expect(notice.errors, unorderedEquals([error1, error2])); |
| 445 expect(notice.lineInfo, lineInfo); | 460 expect(notice.lineInfo, lineInfo); |
| 446 } | 461 } |
| 447 | 462 |
| 448 void test_resultsComputed_includedParts_turnLibraryIntoPart() { | |
| 449 when(context.shouldErrorsBeAnalyzed(anyObject, null)).thenReturn(true); | |
| 450 Source library = new TestSource('library.dart'); | |
| 451 Source part = new TestSource('part.dart'); | |
| 452 // library "library" (real) | |
| 453 manager.resultsComputed(library, {SOURCE_KIND: SourceKind.LIBRARY}); | |
| 454 CacheEntry libraryEntry = new CacheEntry(library); | |
| 455 cache.put(libraryEntry); | |
| 456 libraryEntry.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | |
| 457 // library "part" (speculative) | |
| 458 manager.resultsComputed(part, {SOURCE_KIND: SourceKind.LIBRARY}); | |
| 459 CacheEntry partEntry = new CacheEntry(part); | |
| 460 cache.put(partEntry); | |
| 461 partEntry.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | |
| 462 // unit "part in part" (speculative) | |
| 463 AnalysisTarget partInPartTarget = new LibrarySpecificUnit(part, part); | |
| 464 CacheEntry partInPartEntry = new CacheEntry(partInPartTarget); | |
| 465 cache.put(partInPartEntry); | |
| 466 // so far we consider "part" a library | |
| 467 expect(manager.librarySourceQueue, contains(part)); | |
| 468 expect(partEntry.getValue(SOURCE_KIND), SourceKind.LIBRARY); | |
| 469 expect(cache.get(partInPartTarget), isNotNull); | |
| 470 // "part" is used as a part in "library" | |
| 471 manager.resultsComputed(library, {INCLUDED_PARTS: [part]}); | |
| 472 expect(manager.partLibrariesMap[part], [library]); | |
| 473 expect(manager.libraryPartsMap[library], [part]); | |
| 474 // now we know that "part" is not a library | |
| 475 expect(manager.librarySourceQueue, isNot(contains(part))); | |
| 476 expect(partEntry.getValue(SOURCE_KIND), SourceKind.PART); | |
| 477 expect(cache.get(partInPartTarget), isNull); | |
| 478 } | |
| 479 | |
| 480 void test_resultsComputed_includedParts_updatePartLibraries() { | 463 void test_resultsComputed_includedParts_updatePartLibraries() { |
| 481 Source part1 = new TestSource('part1.dart'); | 464 Source part1 = new TestSource('part1.dart'); |
| 482 Source part2 = new TestSource('part2.dart'); | 465 Source part2 = new TestSource('part2.dart'); |
| 483 Source part3 = new TestSource('part3.dart'); | 466 Source part3 = new TestSource('part3.dart'); |
| 484 Source library1 = new TestSource('library1.dart'); | 467 Source library1 = new TestSource('library1.dart'); |
| 485 Source library2 = new TestSource('library2.dart'); | 468 Source library2 = new TestSource('library2.dart'); |
| 469 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); |
| 470 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
| 486 // library1 parts | 471 // library1 parts |
| 487 manager.resultsComputed(library1, {INCLUDED_PARTS: [part1, part2]}); | 472 manager.resultsComputed(library1, {INCLUDED_PARTS: [part1, part2]}); |
| 488 expect(manager.partLibrariesMap[part1], [library1]); | 473 expect(manager.partLibrariesMap[part1], [library1]); |
| 489 expect(manager.partLibrariesMap[part2], [library1]); | 474 expect(manager.partLibrariesMap[part2], [library1]); |
| 490 expect(manager.partLibrariesMap[part3], isNull); | 475 expect(manager.partLibrariesMap[part3], isNull); |
| 491 expect(manager.libraryPartsMap[library1], [part1, part2]); | 476 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 492 expect(manager.libraryPartsMap[library2], isNull); | 477 expect(manager.libraryPartsMap[library2], isNull); |
| 493 // library2 parts | 478 // library2 parts |
| 494 manager.resultsComputed(library2, {INCLUDED_PARTS: [part2, part3]}); | 479 manager.resultsComputed(library2, {INCLUDED_PARTS: [part2, part3]}); |
| 495 expect(manager.partLibrariesMap[part1], [library1]); | 480 expect(manager.partLibrariesMap[part1], [library1]); |
| 496 expect(manager.partLibrariesMap[part2], [library1, library2]); | 481 expect(manager.partLibrariesMap[part2], [library1, library2]); |
| 497 expect(manager.partLibrariesMap[part3], [library2]); | 482 expect(manager.partLibrariesMap[part3], [library2]); |
| 498 expect(manager.libraryPartsMap[library1], [part1, part2]); | 483 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 499 expect(manager.libraryPartsMap[library2], [part2, part3]); | 484 expect(manager.libraryPartsMap[library2], [part2, part3]); |
| 485 // part1 CONTAINING_LIBRARIES |
| 486 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
| 500 } | 487 } |
| 501 | 488 |
| 502 void test_resultsComputed_noSourceKind() { | 489 void test_resultsComputed_noSourceKind() { |
| 503 manager.unknownSourceQueue.addAll([source1, source2]); | 490 manager.unknownSourceQueue.addAll([source1, source2]); |
| 504 manager.resultsComputed(source1, {}); | 491 manager.resultsComputed(source1, {}); |
| 505 expect_librarySourceQueue([]); | 492 expect_librarySourceQueue([]); |
| 506 expect_unknownSourceQueue([source1, source2]); | 493 expect_unknownSourceQueue([source1, source2]); |
| 507 } | 494 } |
| 508 | 495 |
| 509 void test_resultsComputed_notDart() { | 496 void test_resultsComputed_notDart() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 563 } |
| 577 | 564 |
| 578 @override | 565 @override |
| 579 ChangeNoticeImpl getNotice(Source source) { | 566 ChangeNoticeImpl getNotice(Source source) { |
| 580 return _pendingNotices.putIfAbsent( | 567 return _pendingNotices.putIfAbsent( |
| 581 source, () => new ChangeNoticeImpl(source)); | 568 source, () => new ChangeNoticeImpl(source)); |
| 582 } | 569 } |
| 583 | 570 |
| 584 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 571 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 585 } | 572 } |
| OLD | NEW |