| 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.driver_test; | 5 library test.src.task.driver_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/engine.dart' | 8 import 'package:analyzer/src/generated/engine.dart' |
| 9 show | 9 show |
| 10 AnalysisContext, | 10 AnalysisContext, |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 test_setState_invalid() { | 485 test_setState_invalid() { |
| 486 AnalysisTarget target = new TestSource(); | 486 AnalysisTarget target = new TestSource(); |
| 487 ResultDescriptor result = new ResultDescriptor('test', 1); | 487 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 488 CacheEntry entry = new CacheEntry(target); | 488 CacheEntry entry = new CacheEntry(target); |
| 489 cache.put(entry); | 489 cache.put(entry); |
| 490 // set VALID | 490 // set VALID |
| 491 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); | 491 entry.setValue(result, 10, TargetedResult.EMPTY_LIST); |
| 492 expect(entry.getState(result), CacheState.VALID); | 492 expect(entry.getState(result), CacheState.VALID); |
| 493 expect(entry.getValue(result), 10); | 493 expect(entry.getValue(result), 10); |
| 494 // listen, expect "result" invalidation event |
| 495 int numberOfEvents = 0; |
| 496 cache.onResultInvalidated.listen((event) { |
| 497 numberOfEvents++; |
| 498 expect(event.entry, same(entry)); |
| 499 expect(event.descriptor, same(result)); |
| 500 }); |
| 494 // set INVALID | 501 // set INVALID |
| 495 entry.setState(result, CacheState.INVALID); | 502 entry.setState(result, CacheState.INVALID); |
| 496 expect(entry.getState(result), CacheState.INVALID); | 503 expect(entry.getState(result), CacheState.INVALID); |
| 497 expect(entry.getValue(result), 1); | 504 expect(entry.getValue(result), 1); |
| 505 expect(numberOfEvents, 1); |
| 498 } | 506 } |
| 499 | 507 |
| 500 test_setState_invalid_dependencyCycle() { | 508 test_setState_invalid_dependencyCycle() { |
| 501 AnalysisTarget target1 = new TestSource('/a.dart'); | 509 AnalysisTarget target1 = new TestSource('/a.dart'); |
| 502 AnalysisTarget target2 = new TestSource('/b.dart'); | 510 AnalysisTarget target2 = new TestSource('/b.dart'); |
| 503 CacheEntry entry1 = new CacheEntry(target1); | 511 CacheEntry entry1 = new CacheEntry(target1); |
| 504 CacheEntry entry2 = new CacheEntry(target2); | 512 CacheEntry entry2 = new CacheEntry(target2); |
| 505 cache.put(entry1); | 513 cache.put(entry1); |
| 506 cache.put(entry2); | 514 cache.put(entry2); |
| 507 ResultDescriptor result = new ResultDescriptor('result', -1); | 515 ResultDescriptor result = new ResultDescriptor('result', -1); |
| 508 // Set each result as VALID with a dependency on on the other. | 516 // Set each result as VALID with a dependency on on the other. |
| 509 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); | 517 entry1.setValue(result, 100, [new TargetedResult(target2, result)]); |
| 510 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); | 518 entry2.setValue(result, 200, [new TargetedResult(target1, result)]); |
| 511 expect(entry1.getState(result), CacheState.VALID); | 519 expect(entry1.getState(result), CacheState.VALID); |
| 512 expect(entry2.getState(result), CacheState.VALID); | 520 expect(entry2.getState(result), CacheState.VALID); |
| 521 // Listen, expect entry1.result and entry2.result invalidation events. |
| 522 int numberOfEvents = 0; |
| 523 bool wasEntry1 = false; |
| 524 bool wasEntry2 = false; |
| 525 cache.onResultInvalidated.listen((event) { |
| 526 numberOfEvents++; |
| 527 if (event.entry == entry1) wasEntry1 = true; |
| 528 if (event.entry == entry2) wasEntry2 = true; |
| 529 expect(event.descriptor, same(result)); |
| 530 }); |
| 513 // Invalidate entry1.result; this should cause entry2 to be also | 531 // Invalidate entry1.result; this should cause entry2 to be also |
| 514 // cleared without going into an infinite regress. | 532 // cleared without going into an infinite regress. |
| 515 entry1.setState(result, CacheState.INVALID); | 533 entry1.setState(result, CacheState.INVALID); |
| 516 expect(cache.get(target1), isNull); | 534 expect(cache.get(target1), isNull); |
| 517 expect(cache.get(target2), isNull); | 535 expect(cache.get(target2), isNull); |
| 536 expect(numberOfEvents, 2); |
| 537 expect(wasEntry1, isTrue); |
| 538 expect(wasEntry2, isTrue); |
| 518 } | 539 } |
| 519 | 540 |
| 520 test_setState_invalid_invalidateDependent() { | 541 test_setState_invalid_invalidateDependent() { |
| 521 AnalysisTarget target = new TestSource(); | 542 AnalysisTarget target = new TestSource(); |
| 522 CacheEntry entry = new CacheEntry(target); | 543 CacheEntry entry = new CacheEntry(target); |
| 523 cache.put(entry); | 544 cache.put(entry); |
| 524 ResultDescriptor result1 = new ResultDescriptor('result1', -1); | 545 ResultDescriptor result1 = new ResultDescriptor('result1', -1); |
| 525 ResultDescriptor result2 = new ResultDescriptor('result2', -2); | 546 ResultDescriptor result2 = new ResultDescriptor('result2', -2); |
| 526 ResultDescriptor result3 = new ResultDescriptor('result3', -3); | 547 ResultDescriptor result3 = new ResultDescriptor('result3', -3); |
| 527 ResultDescriptor result4 = new ResultDescriptor('result4', -4); | 548 ResultDescriptor result4 = new ResultDescriptor('result4', -4); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 992 |
| 972 class _InternalAnalysisContextMock extends TypedMock | 993 class _InternalAnalysisContextMock extends TypedMock |
| 973 implements InternalAnalysisContext { | 994 implements InternalAnalysisContext { |
| 974 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 995 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 975 } | 996 } |
| 976 | 997 |
| 977 class _TestAnalysisTarget implements AnalysisTarget { | 998 class _TestAnalysisTarget implements AnalysisTarget { |
| 978 @override | 999 @override |
| 979 Source get source => null; | 1000 Source get source => null; |
| 980 } | 1001 } |
| OLD | NEW |