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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 manager.libraryPartsMap[library2] = [part1, part2]; | 212 manager.libraryPartsMap[library2] = [part1, part2]; |
213 // remove part1 | 213 // remove part1 |
214 manager.applyChange([], [], [part1]); | 214 manager.applyChange([], [], [part1]); |
215 expect(manager.partLibrariesMap[part1], isNull); | 215 expect(manager.partLibrariesMap[part1], isNull); |
216 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 216 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
217 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 217 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
218 expect(manager.libraryPartsMap[library1], [part1, part3]); | 218 expect(manager.libraryPartsMap[library1], [part1, part3]); |
219 expect(manager.libraryPartsMap[library2], [part1, part2]); | 219 expect(manager.libraryPartsMap[library2], [part1, part2]); |
220 } | 220 } |
221 | 221 |
222 void test_applyPriorityTargets_library() { | 222 void test_applyPriorityTargets_isLibrary_computeErrors() { |
| 223 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); |
| 224 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true); |
223 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 225 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
224 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 226 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
225 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 227 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
226 manager.priorityResultQueue | 228 manager.priorityResultQueue |
227 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 229 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); |
228 manager.priorityResultQueue | 230 manager.priorityResultQueue |
229 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 231 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); |
230 // -source1 +source3 | 232 // -source1 +source3 |
231 manager.applyPriorityTargets([source2, source3]); | 233 manager.applyPriorityTargets([source2, source3]); |
232 expect(manager.priorityResultQueue, unorderedEquals([ | 234 expect(manager.priorityResultQueue, unorderedEquals([ |
233 new TargetedResult(source2, LIBRARY_ERRORS_READY), | 235 new TargetedResult(source2, LIBRARY_ERRORS_READY), |
234 new TargetedResult(source3, LIBRARY_ERRORS_READY) | 236 new TargetedResult(source3, LIBRARY_ERRORS_READY) |
235 ])); | 237 ])); |
236 // get next request | 238 // get next request |
237 TargetedResult request = manager.getNextResult(); | 239 TargetedResult request = manager.getNextResult(); |
238 expect(request.target, source2); | 240 expect(request.target, source2); |
239 expect(request.result, LIBRARY_ERRORS_READY); | 241 expect(request.result, LIBRARY_ERRORS_READY); |
240 } | 242 } |
241 | 243 |
242 void test_applyPriorityTargets_part() { | 244 void test_applyPriorityTargets_isLibrary_computeUnit() { |
| 245 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); |
| 246 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(false); |
| 247 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 248 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 249 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 250 manager.priorityResultQueue |
| 251 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); |
| 252 manager.priorityResultQueue |
| 253 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); |
| 254 // -source1 +source3 |
| 255 manager.applyPriorityTargets([source2, source3]); |
| 256 expect(manager.priorityResultQueue, unorderedEquals([ |
| 257 new TargetedResult( |
| 258 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT), |
| 259 new TargetedResult( |
| 260 new LibrarySpecificUnit(source3, source3), RESOLVED_UNIT), |
| 261 ])); |
| 262 } |
| 263 |
| 264 void test_applyPriorityTargets_isPart() { |
243 entry1.setValue(SOURCE_KIND, SourceKind.PART, []); | 265 entry1.setValue(SOURCE_KIND, SourceKind.PART, []); |
244 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 266 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
245 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 267 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
246 // +source2 +source3 | 268 // +source2 +source3 |
247 when(context.getLibrariesContaining(source1)) | 269 when(context.getLibrariesContaining(source1)) |
248 .thenReturn([source2, source3]); | 270 .thenReturn([source2, source3]); |
249 manager.applyPriorityTargets([source1]); | 271 manager.applyPriorityTargets([source1]); |
250 expect(manager.priorityResultQueue, unorderedEquals([ | 272 expect(manager.priorityResultQueue, unorderedEquals([ |
251 new TargetedResult(source2, LIBRARY_ERRORS_READY), | 273 new TargetedResult(source2, LIBRARY_ERRORS_READY), |
252 new TargetedResult(source3, LIBRARY_ERRORS_READY) | 274 new TargetedResult(source3, LIBRARY_ERRORS_READY) |
253 ])); | 275 ])); |
254 // get next request | 276 // get next request |
255 TargetedResult request = manager.getNextResult(); | 277 TargetedResult request = manager.getNextResult(); |
256 expect(request.target, source2); | 278 expect(request.target, source2); |
257 expect(request.result, LIBRARY_ERRORS_READY); | 279 expect(request.result, LIBRARY_ERRORS_READY); |
258 } | 280 } |
259 | 281 |
| 282 void test_applyPriorityTargets_isUnknown() { |
| 283 manager.applyPriorityTargets([source2, source3]); |
| 284 expect(manager.priorityResultQueue, unorderedEquals([ |
| 285 new TargetedResult(source2, SOURCE_KIND), |
| 286 new TargetedResult(source3, SOURCE_KIND) |
| 287 ])); |
| 288 // get next request |
| 289 TargetedResult request = manager.getNextResult(); |
| 290 expect(request.target, source2); |
| 291 expect(request.result, SOURCE_KIND); |
| 292 } |
| 293 |
260 void test_getErrors() { | 294 void test_getErrors() { |
261 AnalysisError error1 = | 295 AnalysisError error1 = |
262 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 296 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
263 AnalysisError error2 = | 297 AnalysisError error2 = |
264 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 298 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
265 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 299 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
266 LineInfo lineInfo = new LineInfo([0]); | 300 LineInfo lineInfo = new LineInfo([0]); |
267 entry1.setValue(LINE_INFO, lineInfo, []); | 301 entry1.setValue(LINE_INFO, lineInfo, []); |
268 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 302 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
269 context.getCacheEntry(new LibrarySpecificUnit(source2, source1)).setValue( | 303 context.getCacheEntry(new LibrarySpecificUnit(source2, source1)).setValue( |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 manager.resultsComputed( | 597 manager.resultsComputed( |
564 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); | 598 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); |
565 ChangeNoticeImpl notice = context.getNotice(source2); | 599 ChangeNoticeImpl notice = context.getNotice(source2); |
566 expect(notice.parsedDartUnit, isNull); | 600 expect(notice.parsedDartUnit, isNull); |
567 expect(notice.resolvedDartUnit, unit); | 601 expect(notice.resolvedDartUnit, unit); |
568 expect(notice.lineInfo, lineInfo); | 602 expect(notice.lineInfo, lineInfo); |
569 } | 603 } |
570 | 604 |
571 void test_resultsComputed_sourceKind_isLibrary() { | 605 void test_resultsComputed_sourceKind_isLibrary() { |
572 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 606 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 607 when(context.prioritySources).thenReturn(<Source>[]); |
573 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 608 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); |
574 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 609 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
575 expect_librarySourceQueue([source2]); | 610 expect_librarySourceQueue([source2]); |
576 expect_unknownSourceQueue([source1, source3]); | 611 expect_unknownSourceQueue([source1, source3]); |
577 } | 612 } |
578 | 613 |
| 614 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() { |
| 615 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 616 when(context.prioritySources).thenReturn(<Source>[source2]); |
| 617 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); |
| 618 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 619 expect_unknownSourceQueue([source1, source3]); |
| 620 expect(manager.priorityResultQueue, |
| 621 unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)])); |
| 622 } |
| 623 |
| 624 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() { |
| 625 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 626 when(context.prioritySources).thenReturn(<Source>[source2]); |
| 627 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); |
| 628 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 629 expect_unknownSourceQueue([source1, source3]); |
| 630 expect(manager.priorityResultQueue, unorderedEquals([ |
| 631 new TargetedResult( |
| 632 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT) |
| 633 ])); |
| 634 } |
| 635 |
579 void test_resultsComputed_sourceKind_isPart() { | 636 void test_resultsComputed_sourceKind_isPart() { |
580 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 637 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
581 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); | 638 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); |
582 expect_librarySourceQueue([]); | 639 expect_librarySourceQueue([]); |
583 expect_unknownSourceQueue([source1, source3]); | 640 expect_unknownSourceQueue([source1, source3]); |
584 } | 641 } |
585 | 642 |
586 CacheEntry _getOrCreateEntry(Source source) { | 643 CacheEntry _getOrCreateEntry(Source source) { |
587 CacheEntry entry = cache.get(source); | 644 CacheEntry entry = cache.get(source); |
588 if (entry == null) { | 645 if (entry == null) { |
(...skipping 30 matching lines...) Expand all Loading... |
619 } | 676 } |
620 | 677 |
621 @override | 678 @override |
622 ChangeNoticeImpl getNotice(Source source) { | 679 ChangeNoticeImpl getNotice(Source source) { |
623 return _pendingNotices.putIfAbsent( | 680 return _pendingNotices.putIfAbsent( |
624 source, () => new ChangeNoticeImpl(source)); | 681 source, () => new ChangeNoticeImpl(source)); |
625 } | 682 } |
626 | 683 |
627 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 684 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
628 } | 685 } |
OLD | NEW |