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/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
9 show CacheState, InternalAnalysisContext; | 10 show CacheState, ChangeNoticeImpl, InternalAnalysisContext; |
10 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 11 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 13 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
12 import 'package:analyzer/src/task/dart.dart'; | 14 import 'package:analyzer/src/task/dart.dart'; |
13 import 'package:analyzer/src/task/dart_work_manager.dart'; | 15 import 'package:analyzer/src/task/dart_work_manager.dart'; |
14 import 'package:analyzer/src/task/driver.dart'; | 16 import 'package:analyzer/src/task/driver.dart'; |
15 import 'package:analyzer/task/dart.dart'; | 17 import 'package:analyzer/task/dart.dart'; |
16 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
17 import 'package:typed_mock/typed_mock.dart'; | 19 import 'package:typed_mock/typed_mock.dart'; |
18 import 'package:unittest/unittest.dart'; | 20 import 'package:unittest/unittest.dart'; |
19 | 21 |
20 import '../../generated/test_support.dart'; | 22 import '../../generated/test_support.dart'; |
21 import '../../reflective_tests.dart'; | 23 import '../../reflective_tests.dart'; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 276 |
275 void test_getNextResultPriority_hasUnknown() { | 277 void test_getNextResultPriority_hasUnknown() { |
276 manager.unknownSourceQueue.addAll([source1]); | 278 manager.unknownSourceQueue.addAll([source1]); |
277 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 279 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
278 } | 280 } |
279 | 281 |
280 void test_getNextResultPriority_nothingToDo() { | 282 void test_getNextResultPriority_nothingToDo() { |
281 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 283 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
282 } | 284 } |
283 | 285 |
284 void test_resultsComputed_isLibrary() { | |
285 manager.unknownSourceQueue.addAll([source1, source2, source3]); | |
286 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | |
287 expect_librarySourceQueue([source2]); | |
288 expect_unknownSourceQueue([source1, source3]); | |
289 } | |
290 | |
291 void test_resultsComputed_isPart() { | |
292 manager.unknownSourceQueue.addAll([source1, source2, source3]); | |
293 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); | |
294 expect_librarySourceQueue([]); | |
295 expect_unknownSourceQueue([source1, source3]); | |
296 } | |
297 | |
298 void test_resultsComputed_noSourceKind() { | 286 void test_resultsComputed_noSourceKind() { |
299 manager.unknownSourceQueue.addAll([source1, source2]); | 287 manager.unknownSourceQueue.addAll([source1, source2]); |
300 manager.resultsComputed(source1, {}); | 288 manager.resultsComputed(source1, {}); |
301 expect_librarySourceQueue([]); | 289 expect_librarySourceQueue([]); |
302 expect_unknownSourceQueue([source1, source2]); | 290 expect_unknownSourceQueue([source1, source2]); |
303 } | 291 } |
304 | 292 |
305 void test_resultsComputed_notDart() { | 293 void test_resultsComputed_notDart() { |
306 manager.unknownSourceQueue.addAll([source1, source2]); | 294 manager.unknownSourceQueue.addAll([source1, source2]); |
307 manager.resultsComputed(new TestSource('test.html'), {}); | 295 manager.resultsComputed(new TestSource('test.html'), {}); |
308 expect_librarySourceQueue([]); | 296 expect_librarySourceQueue([]); |
309 expect_unknownSourceQueue([source1, source2]); | 297 expect_unknownSourceQueue([source1, source2]); |
310 } | 298 } |
| 299 |
| 300 void test_resultsComputed_parsedUnit() { |
| 301 CompilationUnit unit = AstFactory.compilationUnit(); |
| 302 manager.resultsComputed(source1, {PARSED_UNIT: unit}); |
| 303 expect(context.getNotice(source1).parsedDartUnit, unit); |
| 304 expect(context.getNotice(source1).resolvedDartUnit, isNull); |
| 305 } |
| 306 |
| 307 void test_resultsComputed_resolvedUnit() { |
| 308 CompilationUnit unit = AstFactory.compilationUnit(); |
| 309 manager.resultsComputed( |
| 310 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); |
| 311 expect(context.getNotice(source2).parsedDartUnit, isNull); |
| 312 expect(context.getNotice(source2).resolvedDartUnit, unit); |
| 313 } |
| 314 |
| 315 void test_resultsComputed_sourceKind_isLibrary() { |
| 316 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 317 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 318 expect_librarySourceQueue([source2]); |
| 319 expect_unknownSourceQueue([source1, source3]); |
| 320 } |
| 321 |
| 322 void test_resultsComputed_sourceKind_isPart() { |
| 323 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 324 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); |
| 325 expect_librarySourceQueue([]); |
| 326 expect_unknownSourceQueue([source1, source3]); |
| 327 } |
311 } | 328 } |
312 | 329 |
313 class _InternalAnalysisContextMock extends TypedMock | 330 class _InternalAnalysisContextMock extends TypedMock |
314 implements InternalAnalysisContext { | 331 implements InternalAnalysisContext { |
315 @override | 332 @override |
316 AnalysisCache analysisCache; | 333 AnalysisCache analysisCache; |
317 | 334 |
| 335 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
| 336 |
318 _InternalAnalysisContextMock() { | 337 _InternalAnalysisContextMock() { |
319 analysisCache = new AnalysisCache([new UniversalCachePartition(this)]); | 338 analysisCache = new AnalysisCache([new UniversalCachePartition(this)]); |
320 } | 339 } |
321 | 340 |
322 @override | 341 @override |
323 CacheEntry getCacheEntry(AnalysisTarget target) { | 342 CacheEntry getCacheEntry(AnalysisTarget target) { |
324 CacheEntry entry = analysisCache.get(target); | 343 CacheEntry entry = analysisCache.get(target); |
325 if (entry == null) { | 344 if (entry == null) { |
326 entry = new CacheEntry(target); | 345 entry = new CacheEntry(target); |
327 analysisCache.put(entry); | 346 analysisCache.put(entry); |
328 } | 347 } |
329 return entry; | 348 return entry; |
330 } | 349 } |
331 | 350 |
| 351 @override |
| 352 ChangeNoticeImpl getNotice(Source source) { |
| 353 return _pendingNotices.putIfAbsent( |
| 354 source, () => new ChangeNoticeImpl(source)); |
| 355 } |
| 356 |
332 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 357 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
333 } | 358 } |
OLD | NEW |