Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: pkg/analyzer/test/src/context/cache_test.dart

Issue 2052553003: Add AnalysisCache.flush() utility method. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 analyzer.test.src.context.cache_test; 5 library analyzer.test.src.context.cache_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 import 'package:analyzer/src/generated/java_engine.dart'; 9 import 'package:analyzer/src/generated/java_engine.dart';
10 import 'package:analyzer/src/generated/sdk_io.dart'; 10 import 'package:analyzer/src/generated/sdk_io.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 when(context.analysisCache).thenReturn(cache); 45 when(context.analysisCache).thenReturn(cache);
46 } 46 }
47 } 47 }
48 48
49 @reflectiveTest 49 @reflectiveTest
50 class AnalysisCacheTest extends AbstractCacheTest { 50 class AnalysisCacheTest extends AbstractCacheTest {
51 void test_creation() { 51 void test_creation() {
52 expect(cache, isNotNull); 52 expect(cache, isNotNull);
53 } 53 }
54 54
55 test_flush() {
56 AnalysisTarget target = new TestSource();
57 ResultDescriptor resultA = new ResultDescriptor('A', null);
58 ResultDescriptor resultB = new ResultDescriptor('B', null);
59 CacheEntry entry = new CacheEntry(target);
60 cache.put(entry);
61 // put values
62 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST);
63 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST);
64 expect(cache.getState(target, resultA), CacheState.VALID);
65 expect(cache.getState(target, resultB), CacheState.VALID);
66 expect(cache.getValue(target, resultA), 'a');
67 expect(cache.getValue(target, resultB), 'b');
68 // flush A
69 cache.flush((target, result) => result == resultA);
70 expect(cache.getState(target, resultA), CacheState.FLUSHED);
71 expect(cache.getState(target, resultB), CacheState.VALID);
72 expect(cache.getValue(target, resultA), isNull);
73 expect(cache.getValue(target, resultB), 'b');
74 }
75
55 void test_get() { 76 void test_get() {
56 AnalysisTarget target = new TestSource(); 77 AnalysisTarget target = new TestSource();
57 expect(cache.get(target), isNull); 78 expect(cache.get(target), isNull);
58 } 79 }
59 80
60 void test_getContextFor() { 81 void test_getContextFor() {
61 AnalysisTarget target = new TestSource(); 82 AnalysisTarget target = new TestSource();
62 expect(cache.getContextFor(target), context); 83 expect(cache.getContextFor(target), context);
63 } 84 }
64 85
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 311
291 test_fixExceptionState_noError_noException() { 312 test_fixExceptionState_noError_noException() {
292 AnalysisTarget target = new TestSource(); 313 AnalysisTarget target = new TestSource();
293 ResultDescriptor result = new ResultDescriptor('test', null); 314 ResultDescriptor result = new ResultDescriptor('test', null);
294 CacheEntry entry = new CacheEntry(target); 315 CacheEntry entry = new CacheEntry(target);
295 entry.fixExceptionState(); 316 entry.fixExceptionState();
296 expect(entry.getState(result), CacheState.INVALID); 317 expect(entry.getState(result), CacheState.INVALID);
297 expect(entry.exception, isNull); 318 expect(entry.exception, isNull);
298 } 319 }
299 320
321 test_flush() {
322 AnalysisTarget target = new TestSource();
323 ResultDescriptor resultA = new ResultDescriptor('A', null);
324 ResultDescriptor resultB = new ResultDescriptor('B', null);
325 CacheEntry entry = new CacheEntry(target);
326 cache.put(entry);
327 // put values
328 entry.setValue(resultA, 'a', TargetedResult.EMPTY_LIST);
329 entry.setValue(resultB, 'b', TargetedResult.EMPTY_LIST);
330 expect(entry.getState(resultA), CacheState.VALID);
331 expect(entry.getState(resultB), CacheState.VALID);
332 expect(entry.getValue(resultA), 'a');
333 expect(entry.getValue(resultB), 'b');
334 // flush A
335 entry.flush((target, result) => result == resultA);
336 expect(entry.getState(resultA), CacheState.FLUSHED);
337 expect(entry.getState(resultB), CacheState.VALID);
338 expect(entry.getValue(resultA), isNull);
339 expect(entry.getValue(resultB), 'b');
340 }
341
300 test_getState() { 342 test_getState() {
301 AnalysisTarget target = new TestSource(); 343 AnalysisTarget target = new TestSource();
302 ResultDescriptor result = new ResultDescriptor('test', null); 344 ResultDescriptor result = new ResultDescriptor('test', null);
303 CacheEntry entry = new CacheEntry(target); 345 CacheEntry entry = new CacheEntry(target);
304 expect(entry.getState(result), CacheState.INVALID); 346 expect(entry.getState(result), CacheState.INVALID);
305 } 347 }
306 348
307 test_getValue_default() { 349 test_getValue_default() {
308 AnalysisTarget target = new TestSource(); 350 AnalysisTarget target = new TestSource();
309 String defaultValue = 'value'; 351 String defaultValue = 'value';
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 return DeltaResult.KEEP_CONTINUE; 1183 return DeltaResult.KEEP_CONTINUE;
1142 } 1184 }
1143 return DeltaResult.INVALIDATE; 1185 return DeltaResult.INVALIDATE;
1144 } 1186 }
1145 } 1187 }
1146 1188
1147 class _TestAnalysisTarget implements AnalysisTarget { 1189 class _TestAnalysisTarget implements AnalysisTarget {
1148 @override 1190 @override
1149 Source get source => null; 1191 Source get source => null;
1150 } 1192 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698