OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 library quiver.cache.map_cache_test; |
| 16 |
| 17 import 'dart:async'; |
| 18 import 'package:test/test.dart'; |
| 19 import 'package:quiver/cache.dart'; |
| 20 |
| 21 main() { |
| 22 group('MapCache', () { |
| 23 MapCache cache; |
| 24 |
| 25 setUp(() { |
| 26 cache = new MapCache(); |
| 27 }); |
| 28 |
| 29 test("should return null for a non-existent key", () { |
| 30 return cache.get('foo').then((value) { |
| 31 expect(value, isNull); |
| 32 }); |
| 33 }); |
| 34 |
| 35 test("should return a previously set key/value pair", () { |
| 36 return cache |
| 37 .set('foo', 'bar') |
| 38 .then((_) => cache.get('foo')) |
| 39 .then((value) { |
| 40 expect(value, 'bar'); |
| 41 }); |
| 42 }); |
| 43 |
| 44 test("should invalidate a key", () { |
| 45 return cache |
| 46 .set('foo', 'bar') |
| 47 .then((_) => cache.invalidate('foo')) |
| 48 .then((_) => cache.get('foo')) |
| 49 .then((value) { |
| 50 expect(value, null); |
| 51 }); |
| 52 }); |
| 53 |
| 54 test("should load a value given a synchronous loader", () { |
| 55 return cache.get('foo', ifAbsent: (k) => k + k).then((value) { |
| 56 expect(value, 'foofoo'); |
| 57 }); |
| 58 }); |
| 59 |
| 60 test("should load a value given an asynchronous loader", () { |
| 61 return cache |
| 62 .get('foo', ifAbsent: (k) => new Future.value(k + k)) |
| 63 .then((value) { |
| 64 expect(value, 'foofoo'); |
| 65 }); |
| 66 }); |
| 67 }); |
| 68 } |
OLD | NEW |