| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 cache.remove(source1); | 230 cache.remove(source1); |
| 231 expect(cache.sources, unorderedEquals([source2])); | 231 expect(cache.sources, unorderedEquals([source2])); |
| 232 // remove source2 | 232 // remove source2 |
| 233 cache.remove(source2); | 233 cache.remove(source2); |
| 234 expect(cache.sources, isEmpty); | 234 expect(cache.sources, isEmpty); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 @reflectiveTest | 238 @reflectiveTest |
| 239 class CacheEntryTest extends AbstractCacheTest { | 239 class CacheEntryTest extends AbstractCacheTest { |
| 240 test_dispose() { |
| 241 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); |
| 242 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); |
| 243 AnalysisTarget target1 = new TestSource('1.dart'); |
| 244 AnalysisTarget target2 = new TestSource('2.dart'); |
| 245 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
| 246 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
| 247 CacheEntry entry1 = new CacheEntry(target1); |
| 248 CacheEntry entry2 = new CacheEntry(target2); |
| 249 cache.put(entry1); |
| 250 cache.put(entry2); |
| 251 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 252 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
| 253 // target2 is listed as dependent in target1 |
| 254 expect( |
| 255 entry1.getResultData(descriptor1).dependentResults, contains(result2)); |
| 256 // dispose entry2, result2 is removed from result1 |
| 257 entry2.dispose(); |
| 258 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); |
| 259 } |
| 260 |
| 240 test_explicitlyAdded() { | 261 test_explicitlyAdded() { |
| 241 AnalysisTarget target = new TestSource(); | 262 AnalysisTarget target = new TestSource(); |
| 242 CacheEntry entry = new CacheEntry(target); | 263 CacheEntry entry = new CacheEntry(target); |
| 243 expect(entry.explicitlyAdded, false); | 264 expect(entry.explicitlyAdded, false); |
| 244 entry.explicitlyAdded = true; | 265 entry.explicitlyAdded = true; |
| 245 expect(entry.explicitlyAdded, true); | 266 expect(entry.explicitlyAdded, true); |
| 246 } | 267 } |
| 247 | 268 |
| 248 test_fixExceptionState_error_exception() { | 269 test_fixExceptionState_error_exception() { |
| 249 AnalysisTarget target = new TestSource(); | 270 AnalysisTarget target = new TestSource(); |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 expect(partition.isResponsibleFor(target), isTrue); | 997 expect(partition.isResponsibleFor(target), isTrue); |
| 977 } | 998 } |
| 978 } | 999 } |
| 979 | 1000 |
| 980 @reflectiveTest | 1001 @reflectiveTest |
| 981 class UniversalCachePartitionTest extends CachePartitionTest { | 1002 class UniversalCachePartitionTest extends CachePartitionTest { |
| 982 CachePartition createPartition() { | 1003 CachePartition createPartition() { |
| 983 return new UniversalCachePartition(null); | 1004 return new UniversalCachePartition(null); |
| 984 } | 1005 } |
| 985 | 1006 |
| 1007 test_dispose() { |
| 1008 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| 1009 CachePartition partition1 = new UniversalCachePartition(context); |
| 1010 CachePartition partition2 = new UniversalCachePartition(context); |
| 1011 AnalysisCache cache = new AnalysisCache([partition1, partition2]); |
| 1012 when(context.analysisCache).thenReturn(cache); |
| 1013 // configure |
| 1014 // prepare entries |
| 1015 ResultDescriptor descriptor1 = new ResultDescriptor('result1', -1); |
| 1016 ResultDescriptor descriptor2 = new ResultDescriptor('result2', -2); |
| 1017 AnalysisTarget target1 = new TestSource('1.dart'); |
| 1018 AnalysisTarget target2 = new TestSource('2.dart'); |
| 1019 TargetedResult result1 = new TargetedResult(target1, descriptor1); |
| 1020 TargetedResult result2 = new TargetedResult(target2, descriptor2); |
| 1021 CacheEntry entry1 = new CacheEntry(target1); |
| 1022 CacheEntry entry2 = new CacheEntry(target2); |
| 1023 partition1.put(entry1); |
| 1024 partition2.put(entry2); |
| 1025 entry1.setValue(descriptor1, 1, TargetedResult.EMPTY_LIST); |
| 1026 entry2.setValue(descriptor2, 2, <TargetedResult>[result1]); |
| 1027 // target2 is listed as dependent in target1 |
| 1028 expect( |
| 1029 entry1.getResultData(descriptor1).dependentResults, contains(result2)); |
| 1030 // dispose |
| 1031 partition2.dispose(); |
| 1032 expect(partition1.get(target1), same(entry1)); |
| 1033 expect(partition2.get(target2), isNull); |
| 1034 // result2 is removed from result1 |
| 1035 expect(entry1.getResultData(descriptor1).dependentResults, isEmpty); |
| 1036 } |
| 1037 |
| 986 void test_contains() { | 1038 void test_contains() { |
| 987 UniversalCachePartition partition = new UniversalCachePartition(null); | 1039 UniversalCachePartition partition = new UniversalCachePartition(null); |
| 988 TestSource source = new TestSource(); | 1040 TestSource source = new TestSource(); |
| 989 expect(partition.isResponsibleFor(source), isTrue); | 1041 expect(partition.isResponsibleFor(source), isTrue); |
| 990 } | 1042 } |
| 991 } | 1043 } |
| 992 | 1044 |
| 993 class _InternalAnalysisContextMock extends TypedMock | 1045 class _InternalAnalysisContextMock extends TypedMock |
| 994 implements InternalAnalysisContext { | 1046 implements InternalAnalysisContext { |
| 995 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1047 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 996 } | 1048 } |
| 997 | 1049 |
| 998 class _TestAnalysisTarget implements AnalysisTarget { | 1050 class _TestAnalysisTarget implements AnalysisTarget { |
| 999 @override | 1051 @override |
| 1000 Source get source => null; | 1052 Source get source => null; |
| 1001 } | 1053 } |
| OLD | NEW |