| Index: pkg/analysis_server/test/index/lru_cache_test.dart
|
| diff --git a/pkg/analysis_server/test/index/lru_cache_test.dart b/pkg/analysis_server/test/index/lru_cache_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a1a448961ee0d8fce721bcdf1d5f47667b9c65a6
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/test/index/lru_cache_test.dart
|
| @@ -0,0 +1,74 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library test.index.lru_cache;
|
| +
|
| +import 'package:analysis_server/src/index/lru_cache.dart';
|
| +import 'package:unittest/unittest.dart';
|
| +
|
| +import '../reflective_tests.dart';
|
| +
|
| +
|
| +main() {
|
| + groupSep = ' | ';
|
| + group('FixedStringCodecTest', () {
|
| + runReflectiveTests(_LRUCacheTest);
|
| + });
|
| +}
|
| +
|
| +
|
| +@ReflectiveTestCase()
|
| +class _LRUCacheTest {
|
| + LRUCache<int, String> cache = new LRUCache<int, String>(3);
|
| +
|
| + void test_evict() {
|
| + List<int> evictedKeys = new List<int>();
|
| + List<String> evictedValues = new List<String>();
|
| + cache = new LRUCache<int, String>(3, (int key, String value) {
|
| + evictedKeys.add(key);
|
| + evictedValues.add(value);
|
| + });
|
| + // fill
|
| + cache.put(1, 'A');
|
| + cache.put(2, 'B');
|
| + cache.put(3, 'C');
|
| + // access '1' and '3'
|
| + cache.get(1);
|
| + cache.get(3);
|
| + // put '4', evict '2'
|
| + cache.put(4, 'D');
|
| + expect(cache.get(1), 'A');
|
| + expect(cache.get(2), isNull);
|
| + expect(cache.get(3), 'C');
|
| + expect(cache.get(4), 'D');
|
| + // check eviction listener
|
| + expect(evictedKeys, contains(2));
|
| + expect(evictedValues, contains('B'));
|
| + }
|
| +
|
| + void test_putGet() {
|
| + // fill
|
| + cache.put(1, 'A');
|
| + cache.put(2, 'B');
|
| + cache.put(3, 'C');
|
| + // check
|
| + expect(cache.get(1), 'A');
|
| + expect(cache.get(2), 'B');
|
| + expect(cache.get(3), 'C');
|
| + expect(cache.get(4), isNull);
|
| + }
|
| +
|
| + void test_remove() {
|
| + cache.put(1, 'A');
|
| + cache.put(2, 'B');
|
| + cache.put(3, 'C');
|
| + // remove
|
| + cache.remove(1);
|
| + cache.remove(3);
|
| + // check
|
| + expect(cache.get(1), isNull);
|
| + expect(cache.get(2), 'B');
|
| + expect(cache.get(3), isNull);
|
| + }
|
| +}
|
|
|