| OLD | NEW |
| 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/file_system/file_system.dart'; | |
| 6 import 'package:analyzer/src/generated/source.dart'; | 5 import 'package:analyzer/src/generated/source.dart'; |
| 7 import 'package:analyzer/src/summary/idl.dart'; | 6 import 'package:analyzer/src/summary/idl.dart'; |
| 8 import 'package:analyzer/src/summary/incremental_cache.dart'; | 7 import 'package:analyzer/src/summary/incremental_cache.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 10 | 9 |
| 11 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| 12 import '../abstract_single_unit.dart'; | 11 import '../abstract_single_unit.dart'; |
| 13 | 12 |
| 14 main() { | 13 main() { |
| 15 groupSep = ' | '; | 14 groupSep = ' | '; |
| 16 runReflectiveTests(LibraryBundleCacheTest); | 15 runReflectiveTests(IncrementalCacheTest); |
| 17 } | 16 } |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * TODO(scheglov) write more tests for invalidation. | 19 * TODO(scheglov) write more tests for invalidation. |
| 21 */ | 20 */ |
| 22 @reflectiveTest | 21 @reflectiveTest |
| 23 class LibraryBundleCacheTest extends AbstractSingleUnitTest { | 22 class IncrementalCacheTest extends AbstractSingleUnitTest { |
| 24 Folder cacheFolder; | 23 _TestCacheStorage storage = new _TestCacheStorage(); |
| 25 LibraryBundleCache cache; | 24 IncrementalCache cache; |
| 26 | 25 |
| 27 @override | 26 @override |
| 28 void setUp() { | 27 void setUp() { |
| 29 super.setUp(); | 28 super.setUp(); |
| 30 cacheFolder = resourceProvider.newFolder('/cache'); | 29 cache = new IncrementalCache(storage, context, <int>[]); |
| 31 cache = new LibraryBundleCache('pid.tmp', cacheFolder, context, <int>[]); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 void test_getSourceKind_library() { | 32 void test_getSourceKind_library() { |
| 35 resolveTestUnit(r''' | 33 resolveTestUnit(r''' |
| 36 main() {} | 34 main() {} |
| 37 '''); | 35 '''); |
| 38 cache.putLibrary(testLibraryElement); | 36 cache.putLibrary(testLibraryElement); |
| 39 expect(cache.getSourceKind(testSource), SourceKind.LIBRARY); | 37 expect(cache.getSourceKind(testSource), SourceKind.LIBRARY); |
| 40 } | 38 } |
| 41 | 39 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 121 } |
| 124 | 122 |
| 125 void test_readBundle_withoutDependencies() { | 123 void test_readBundle_withoutDependencies() { |
| 126 resolveTestUnit('main() {}'); | 124 resolveTestUnit('main() {}'); |
| 127 cache.putLibrary(testLibraryElement); | 125 cache.putLibrary(testLibraryElement); |
| 128 // has bundle | 126 // has bundle |
| 129 PackageBundle bundle = cache.readBundle(testSource); | 127 PackageBundle bundle = cache.readBundle(testSource); |
| 130 expect(bundle, isNotNull); | 128 expect(bundle, isNotNull); |
| 131 } | 129 } |
| 132 } | 130 } |
| 131 |
| 132 /** |
| 133 * A [Map] based [CacheStorage]. |
| 134 */ |
| 135 class _TestCacheStorage implements CacheStorage { |
| 136 final Map<String, List<int>> map = <String, List<int>>{}; |
| 137 |
| 138 @override |
| 139 List<int> get(String key) { |
| 140 return map[key]; |
| 141 } |
| 142 |
| 143 @override |
| 144 void put(String key, List<int> bytes) { |
| 145 map[key] = bytes; |
| 146 } |
| 147 } |
| OLD | NEW |