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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/byte_store_test.dart

Issue 2653203005: Add NullByteStore, that does not store any data. (Closed)
Patch Set: Created 3 years, 10 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/dart/analysis/byte_store.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 5 import 'package:analyzer/src/dart/analysis/byte_store.dart';
6 import 'package:test/test.dart'; 6 import 'package:test/test.dart';
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; 7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8 import 'package:typed_mock/typed_mock.dart'; 8 import 'package:typed_mock/typed_mock.dart';
9 9
10 main() { 10 main() {
11 defineReflectiveSuite(() { 11 defineReflectiveSuite(() {
12 defineReflectiveTests(MemoryCachingByteStoreTest); 12 defineReflectiveTests(MemoryCachingByteStoreTest);
13 defineReflectiveTests(NullByteStoreTest);
13 }); 14 });
14 } 15 }
15 16
17 List<int> _b(int length) {
Brian Wilkerson 2017/01/26 14:51:18 This is only used in one place. Please consider in
18 return new List<int>(length);
19 }
20
16 @reflectiveTest 21 @reflectiveTest
17 class MemoryCachingByteStoreTest { 22 class MemoryCachingByteStoreTest {
18 test_get_notFound_evict() { 23 test_get_notFound_evict() {
19 var store = new _TestByteStore(); 24 var store = new _TestByteStore();
20 var cachingStore = new MemoryCachingByteStore(store, 100); 25 var cachingStore = new MemoryCachingByteStore(store, 100);
21 26
22 // Request '1'. Nothing found. 27 // Request '1'. Nothing found.
23 cachingStore.get('1'); 28 cachingStore.get('1');
24 29
25 // Add enough data to the store to force an eviction. 30 // Add enough data to the store to force an eviction.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 expect(cachingStore.get('1'), hasLength(10)); 97 expect(cachingStore.get('1'), hasLength(10));
93 expect(cachingStore.get('2'), hasLength(80)); 98 expect(cachingStore.get('2'), hasLength(80));
94 99
95 // 10 + 80 + 30 > 100 100 // 10 + 80 + 30 > 100
96 // So, '1' and '2' are evicted. 101 // So, '1' and '2' are evicted.
97 cachingStore.put('3', _b(30)); 102 cachingStore.put('3', _b(30));
98 expect(cachingStore.get('1'), isNull); 103 expect(cachingStore.get('1'), isNull);
99 expect(cachingStore.get('2'), isNull); 104 expect(cachingStore.get('2'), isNull);
100 expect(cachingStore.get('3'), hasLength(30)); 105 expect(cachingStore.get('3'), hasLength(30));
101 } 106 }
107 }
102 108
103 static List<int> _b(int length) { 109 @reflectiveTest
104 return new List<int>(length); 110 class NullByteStoreTest {
111 test_get() {
112 var store = new NullByteStore();
113
114 expect(store.get('1'), isNull);
115
116 store.put('1', _b(10));
117 expect(store.get('1'), isNull);
105 } 118 }
106 } 119 }
107 120
108 class _TestByteStore extends TypedMock implements ByteStore {} 121 class _TestByteStore extends TypedMock implements ByteStore {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/byte_store.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698