| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 125 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 126 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); | 126 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); |
| 127 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 127 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 128 entry1.setValue(LIBRARY_ERRORS_READY, false, []); | 128 entry1.setValue(LIBRARY_ERRORS_READY, false, []); |
| 129 entry3.setValue(LIBRARY_ERRORS_READY, false, []); | 129 entry3.setValue(LIBRARY_ERRORS_READY, false, []); |
| 130 // change source2, schedule source1 and source3 | 130 // change source2, schedule source1 and source3 |
| 131 manager.applyChange([], [source2], []); | 131 manager.applyChange([], [source2], []); |
| 132 expect_librarySourceQueue([source1, source3]); | 132 expect_librarySourceQueue([source1, source3]); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void test_applyChange_updatePartsLibraries_changeLibrary() { |
| 136 Source part1 = new TestSource('part1.dart'); |
| 137 Source part2 = new TestSource('part2.dart'); |
| 138 Source part3 = new TestSource('part3.dart'); |
| 139 Source library1 = new TestSource('library1.dart'); |
| 140 Source library2 = new TestSource('library2.dart'); |
| 141 manager.partLibrariesMap[part1] = [library1, library2]; |
| 142 manager.partLibrariesMap[part2] = [library2]; |
| 143 manager.partLibrariesMap[part3] = [library1]; |
| 144 manager.libraryPartsMap[library1] = [part1, part3]; |
| 145 manager.libraryPartsMap[library2] = [part1, part2]; |
| 146 // change library1 |
| 147 manager.applyChange([], [library1], []); |
| 148 expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); |
| 149 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 150 expect(manager.partLibrariesMap[part3], unorderedEquals([])); |
| 151 expect(manager.libraryPartsMap[library1], isNull); |
| 152 expect(manager.libraryPartsMap[library2], [part1, part2]); |
| 153 } |
| 154 |
| 155 void test_applyChange_updatePartsLibraries_changePart() { |
| 156 Source part1 = new TestSource('part1.dart'); |
| 157 Source part2 = new TestSource('part2.dart'); |
| 158 Source part3 = new TestSource('part3.dart'); |
| 159 Source library1 = new TestSource('library1.dart'); |
| 160 Source library2 = new TestSource('library2.dart'); |
| 161 manager.partLibrariesMap[part1] = [library1, library2]; |
| 162 manager.partLibrariesMap[part2] = [library2]; |
| 163 manager.partLibrariesMap[part3] = [library1]; |
| 164 manager.libraryPartsMap[library1] = [part1, part3]; |
| 165 manager.libraryPartsMap[library2] = [part1, part2]; |
| 166 // change part1 |
| 167 manager.applyChange([], [part1], []); |
| 168 expect(manager.partLibrariesMap[part1], isNull); |
| 169 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 170 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
| 171 expect(manager.libraryPartsMap[library1], [part3]); |
| 172 expect(manager.libraryPartsMap[library2], [part2]); |
| 173 } |
| 174 |
| 175 void test_applyChange_updatePartsLibraries_removeLibrary() { |
| 176 Source part1 = new TestSource('part1.dart'); |
| 177 Source part2 = new TestSource('part2.dart'); |
| 178 Source part3 = new TestSource('part3.dart'); |
| 179 Source library1 = new TestSource('library1.dart'); |
| 180 Source library2 = new TestSource('library2.dart'); |
| 181 manager.partLibrariesMap[part1] = [library1, library2]; |
| 182 manager.partLibrariesMap[part2] = [library2]; |
| 183 manager.partLibrariesMap[part3] = [library1]; |
| 184 manager.libraryPartsMap[library1] = [part1, part3]; |
| 185 manager.libraryPartsMap[library2] = [part1, part2]; |
| 186 // remove library1 |
| 187 manager.applyChange([], [], [library1]); |
| 188 expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); |
| 189 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 190 expect(manager.partLibrariesMap[part3], unorderedEquals([])); |
| 191 expect(manager.libraryPartsMap[library1], isNull); |
| 192 expect(manager.libraryPartsMap[library2], [part1, part2]); |
| 193 } |
| 194 |
| 195 void test_applyChange_updatePartsLibraries_removePart() { |
| 196 Source part1 = new TestSource('part1.dart'); |
| 197 Source part2 = new TestSource('part2.dart'); |
| 198 Source part3 = new TestSource('part3.dart'); |
| 199 Source library1 = new TestSource('library1.dart'); |
| 200 Source library2 = new TestSource('library2.dart'); |
| 201 manager.partLibrariesMap[part1] = [library1, library2]; |
| 202 manager.partLibrariesMap[part2] = [library2]; |
| 203 manager.partLibrariesMap[part3] = [library1]; |
| 204 manager.libraryPartsMap[library1] = [part1, part3]; |
| 205 manager.libraryPartsMap[library2] = [part1, part2]; |
| 206 // remove part1 |
| 207 manager.applyChange([], [], [part1]); |
| 208 expect(manager.partLibrariesMap[part1], isNull); |
| 209 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 210 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
| 211 expect(manager.libraryPartsMap[library1], [part3]); |
| 212 expect(manager.libraryPartsMap[library2], [part2]); |
| 213 } |
| 214 |
| 135 void test_applyPriorityTargets_library() { | 215 void test_applyPriorityTargets_library() { |
| 136 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 216 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 137 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 217 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 138 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 218 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 139 manager.priorityResultQueue | 219 manager.priorityResultQueue |
| 140 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 220 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); |
| 141 manager.priorityResultQueue | 221 manager.priorityResultQueue |
| 142 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 222 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); |
| 143 // -source1 +source3 | 223 // -source1 +source3 |
| 144 manager.applyPriorityTargets([source2, source3]); | 224 manager.applyPriorityTargets([source2, source3]); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 LineInfo lineInfo = new LineInfo([0]); | 259 LineInfo lineInfo = new LineInfo([0]); |
| 180 entry1.setValue(LINE_INFO, lineInfo, []); | 260 entry1.setValue(LINE_INFO, lineInfo, []); |
| 181 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 261 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
| 182 context.getCacheEntry(new LibrarySpecificUnit(source2, source1)).setValue( | 262 context.getCacheEntry(new LibrarySpecificUnit(source2, source1)).setValue( |
| 183 VERIFY_ERRORS, <AnalysisError>[error2], []); | 263 VERIFY_ERRORS, <AnalysisError>[error2], []); |
| 184 AnalysisErrorInfo errorInfo = manager.getErrors(source1); | 264 AnalysisErrorInfo errorInfo = manager.getErrors(source1); |
| 185 expect(errorInfo.errors, unorderedEquals([error1, error2])); | 265 expect(errorInfo.errors, unorderedEquals([error1, error2])); |
| 186 expect(errorInfo.lineInfo, lineInfo); | 266 expect(errorInfo.lineInfo, lineInfo); |
| 187 } | 267 } |
| 188 | 268 |
| 269 void test_getLibrariesContainingPart() { |
| 270 Source part1 = new TestSource('part1.dart'); |
| 271 Source part2 = new TestSource('part2.dart'); |
| 272 Source part3 = new TestSource('part3.dart'); |
| 273 Source library1 = new TestSource('library1.dart'); |
| 274 Source library2 = new TestSource('library2.dart'); |
| 275 manager.partLibrariesMap[part1] = [library1, library2]; |
| 276 manager.partLibrariesMap[part2] = [library2]; |
| 277 manager.libraryPartsMap[library1] = [part1]; |
| 278 manager.libraryPartsMap[library2] = [part1, part2]; |
| 279 // getLibrariesContainingPart |
| 280 expect(manager.getLibrariesContainingPart(part1), |
| 281 unorderedEquals([library1, library2])); |
| 282 expect( |
| 283 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); |
| 284 expect(manager.getLibrariesContainingPart(part3), isEmpty); |
| 285 } |
| 286 |
| 189 void test_getNextResult_hasLibraries_firstIsError() { | 287 void test_getNextResult_hasLibraries_firstIsError() { |
| 190 entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]); | 288 entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]); |
| 191 manager.librarySourceQueue.addAll([source1, source2]); | 289 manager.librarySourceQueue.addAll([source1, source2]); |
| 192 TargetedResult request = manager.getNextResult(); | 290 TargetedResult request = manager.getNextResult(); |
| 193 expect(request.target, source2); | 291 expect(request.target, source2); |
| 194 expect(request.result, LIBRARY_ERRORS_READY); | 292 expect(request.result, LIBRARY_ERRORS_READY); |
| 195 // source1 is out, source2 is waiting | 293 // source1 is out, source2 is waiting |
| 196 expect_librarySourceQueue([source2]); | 294 expect_librarySourceQueue([source2]); |
| 197 } | 295 } |
| 198 | 296 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 context.getCacheEntry(unitTarget).setValue( | 437 context.getCacheEntry(unitTarget).setValue( |
| 340 VERIFY_ERRORS, <AnalysisError>[error2], []); | 438 VERIFY_ERRORS, <AnalysisError>[error2], []); |
| 341 // notify about Source specific errors | 439 // notify about Source specific errors |
| 342 manager.resultsComputed(source1, {SCAN_ERRORS: []}); | 440 manager.resultsComputed(source1, {SCAN_ERRORS: []}); |
| 343 // all of the errors are included | 441 // all of the errors are included |
| 344 ChangeNoticeImpl notice = context.getNotice(source1); | 442 ChangeNoticeImpl notice = context.getNotice(source1); |
| 345 expect(notice.errors, unorderedEquals([error1, error2])); | 443 expect(notice.errors, unorderedEquals([error1, error2])); |
| 346 expect(notice.lineInfo, lineInfo); | 444 expect(notice.lineInfo, lineInfo); |
| 347 } | 445 } |
| 348 | 446 |
| 447 void test_resultsComputed_includedParts() { |
| 448 Source part1 = new TestSource('part1.dart'); |
| 449 Source part2 = new TestSource('part2.dart'); |
| 450 Source part3 = new TestSource('part3.dart'); |
| 451 Source library1 = new TestSource('library1.dart'); |
| 452 Source library2 = new TestSource('library2.dart'); |
| 453 // library1 parts |
| 454 manager.resultsComputed(library1, {INCLUDED_PARTS: [part1, part2]}); |
| 455 expect(manager.partLibrariesMap[part1], [library1]); |
| 456 expect(manager.partLibrariesMap[part2], [library1]); |
| 457 expect(manager.partLibrariesMap[part3], isNull); |
| 458 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 459 expect(manager.libraryPartsMap[library2], isNull); |
| 460 // library2 parts |
| 461 manager.resultsComputed(library2, {INCLUDED_PARTS: [part2, part3]}); |
| 462 expect(manager.partLibrariesMap[part1], [library1]); |
| 463 expect(manager.partLibrariesMap[part2], [library1, library2]); |
| 464 expect(manager.partLibrariesMap[part3], [library2]); |
| 465 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 466 expect(manager.libraryPartsMap[library2], [part2, part3]); |
| 467 } |
| 468 |
| 349 void test_resultsComputed_noSourceKind() { | 469 void test_resultsComputed_noSourceKind() { |
| 350 manager.unknownSourceQueue.addAll([source1, source2]); | 470 manager.unknownSourceQueue.addAll([source1, source2]); |
| 351 manager.resultsComputed(source1, {}); | 471 manager.resultsComputed(source1, {}); |
| 352 expect_librarySourceQueue([]); | 472 expect_librarySourceQueue([]); |
| 353 expect_unknownSourceQueue([source1, source2]); | 473 expect_unknownSourceQueue([source1, source2]); |
| 354 } | 474 } |
| 355 | 475 |
| 356 void test_resultsComputed_notDart() { | 476 void test_resultsComputed_notDart() { |
| 357 manager.unknownSourceQueue.addAll([source1, source2]); | 477 manager.unknownSourceQueue.addAll([source1, source2]); |
| 358 manager.resultsComputed(new TestSource('test.html'), {}); | 478 manager.resultsComputed(new TestSource('test.html'), {}); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 542 } |
| 423 | 543 |
| 424 @override | 544 @override |
| 425 ChangeNoticeImpl getNotice(Source source) { | 545 ChangeNoticeImpl getNotice(Source source) { |
| 426 return _pendingNotices.putIfAbsent( | 546 return _pendingNotices.putIfAbsent( |
| 427 source, () => new ChangeNoticeImpl(source)); | 547 source, () => new ChangeNoticeImpl(source)); |
| 428 } | 548 } |
| 429 | 549 |
| 430 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 550 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 431 } | 551 } |
| OLD | NEW |