|
1 | 1 | import 'dart:async'; |
2 | | -import 'dart:typed_data'; |
3 | 2 |
|
| 3 | +import 'package:flutter/foundation.dart'; |
4 | 4 | import 'package:flutter_svg/src/cache.dart'; |
5 | 5 | import 'package:flutter_test/flutter_test.dart'; |
6 | 6 |
|
@@ -77,4 +77,32 @@ void main() { |
77 | 77 | expect(cache.evict(2), false); |
78 | 78 | expect(cache.evict(3), true); |
79 | 79 | }); |
| 80 | + |
| 81 | + test('Adding beyond max with synchronous futures', () async { |
| 82 | + final Cache cache = Cache(); |
| 83 | + cache.maximumSize = 2; |
| 84 | + final Future<ByteData> completerA = |
| 85 | + SynchronousFuture<ByteData>(ByteData(1)); |
| 86 | + final Future<ByteData> completerB = |
| 87 | + SynchronousFuture<ByteData>(ByteData(2)); |
| 88 | + final Future<ByteData> completerC = |
| 89 | + SynchronousFuture<ByteData>(ByteData(3)); |
| 90 | + |
| 91 | + expect(cache.count, 0); |
| 92 | + |
| 93 | + cache.putIfAbsent(1, () => completerA); |
| 94 | + expect(cache.count, 1); |
| 95 | + |
| 96 | + cache.putIfAbsent(2, () => completerB); |
| 97 | + expect(cache.count, 2); |
| 98 | + |
| 99 | + cache.putIfAbsent(2, () => completerB); |
| 100 | + expect(cache.count, 2); |
| 101 | + |
| 102 | + cache.putIfAbsent(3, () => completerC); |
| 103 | + expect(cache.count, 2); |
| 104 | + |
| 105 | + cache.putIfAbsent(2, () => completerB); |
| 106 | + expect(cache.count, 2); |
| 107 | + }); |
80 | 108 | } |
0 commit comments