| 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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 expect(entry2.getState(result3), CacheState.VALID); | 615 expect(entry2.getState(result3), CacheState.VALID); |
| 616 expect(entry1.getValue(result1), 111); | 616 expect(entry1.getValue(result1), 111); |
| 617 expect(entry2.getValue(result2), 222); | 617 expect(entry2.getValue(result2), 222); |
| 618 expect(entry2.getValue(result3), 333); | 618 expect(entry2.getValue(result3), 333); |
| 619 // invalidate result1, remove entry1 & entry2 | 619 // invalidate result1, remove entry1 & entry2 |
| 620 entry1.setState(result1, CacheState.INVALID); | 620 entry1.setState(result1, CacheState.INVALID); |
| 621 expect(cache.get(target1), isNull); | 621 expect(cache.get(target1), isNull); |
| 622 expect(cache.get(target2), isNull); | 622 expect(cache.get(target2), isNull); |
| 623 } | 623 } |
| 624 | 624 |
| 625 test_setState_invalid_withDelta_keepDependency() { |
| 626 Source target = new TestSource('/test.dart'); |
| 627 CacheEntry entry = new CacheEntry(target); |
| 628 cache.put(entry); |
| 629 ResultDescriptor result1 = new ResultDescriptor('result1', -1); |
| 630 ResultDescriptor result2 = new ResultDescriptor('result2', -2); |
| 631 ResultDescriptor result3 = new ResultDescriptor('result3', -3); |
| 632 // set results, all of them are VALID |
| 633 entry.setValue(result1, 111, TargetedResult.EMPTY_LIST); |
| 634 entry.setValue(result2, 222, [new TargetedResult(target, result1)]); |
| 635 entry.setValue(result3, 333, [new TargetedResult(target, result2)]); |
| 636 expect(entry.getState(result1), CacheState.VALID); |
| 637 expect(entry.getState(result2), CacheState.VALID); |
| 638 expect(entry.getState(result3), CacheState.VALID); |
| 639 // result2 depends on result1 |
| 640 expect(entry.getResultData(result1).dependentResults, |
| 641 unorderedEquals([new TargetedResult(target, result2)])); |
| 642 expect(entry.getResultData(result2).dependedOnResults, |
| 643 unorderedEquals([new TargetedResult(target, result1)])); |
| 644 // invalidate result2 with Delta: keep result2, invalidate result3 |
| 645 entry.setState(result2, CacheState.INVALID, |
| 646 delta: new _KeepContinueDelta(target, result2)); |
| 647 expect(entry.getState(result1), CacheState.VALID); |
| 648 expect(entry.getState(result2), CacheState.VALID); |
| 649 expect(entry.getState(result3), CacheState.INVALID); |
| 650 // result2 still depends on result1 |
| 651 expect(entry.getResultData(result1).dependentResults, |
| 652 unorderedEquals([new TargetedResult(target, result2)])); |
| 653 expect(entry.getResultData(result2).dependedOnResults, |
| 654 unorderedEquals([new TargetedResult(target, result1)])); |
| 655 } |
| 656 |
| 625 test_setState_valid() { | 657 test_setState_valid() { |
| 626 AnalysisTarget target = new TestSource(); | 658 AnalysisTarget target = new TestSource(); |
| 627 ResultDescriptor result = new ResultDescriptor('test', null); | 659 ResultDescriptor result = new ResultDescriptor('test', null); |
| 628 CacheEntry entry = new CacheEntry(target); | 660 CacheEntry entry = new CacheEntry(target); |
| 629 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 661 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
| 630 } | 662 } |
| 631 | 663 |
| 632 test_setValue() { | 664 test_setValue() { |
| 633 AnalysisTarget target = new TestSource(); | 665 AnalysisTarget target = new TestSource(); |
| 634 ResultDescriptor result = new ResultDescriptor('test', null); | 666 ResultDescriptor result = new ResultDescriptor('test', null); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 // result2 is removed from result1 | 1082 // result2 is removed from result1 |
| 1051 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); | 1083 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); |
| 1052 } | 1084 } |
| 1053 } | 1085 } |
| 1054 | 1086 |
| 1055 class _InternalAnalysisContextMock extends TypedMock | 1087 class _InternalAnalysisContextMock extends TypedMock |
| 1056 implements InternalAnalysisContext { | 1088 implements InternalAnalysisContext { |
| 1057 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1089 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1058 } | 1090 } |
| 1059 | 1091 |
| 1092 /** |
| 1093 * Keep the given [keepDescriptor], invalidate all the other results. |
| 1094 */ |
| 1095 class _KeepContinueDelta implements Delta { |
| 1096 final Source source; |
| 1097 final ResultDescriptor keepDescriptor; |
| 1098 |
| 1099 _KeepContinueDelta(this.source, this.keepDescriptor); |
| 1100 |
| 1101 @override |
| 1102 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, |
| 1103 ResultDescriptor descriptor) { |
| 1104 if (descriptor == keepDescriptor) { |
| 1105 return DeltaResult.KEEP_CONTINUE; |
| 1106 } |
| 1107 return DeltaResult.INVALIDATE; |
| 1108 } |
| 1109 } |
| 1110 |
| 1060 class _TestAnalysisTarget implements AnalysisTarget { | 1111 class _TestAnalysisTarget implements AnalysisTarget { |
| 1061 @override | 1112 @override |
| 1062 Source get source => null; | 1113 Source get source => null; |
| 1063 } | 1114 } |
| OLD | NEW |