File: 00base.t

package info (click to toggle)
libcache-lru-perl 0.04-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 1,432; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;

use Test::More;

BEGIN {
    use_ok("Cache::LRU");
};

my $cache = Cache::LRU->new(
    size => 3,
);

ok ! defined $cache->get('a');

is $cache->set(a => 1), 1;
is $cache->get('a'), 1;

is $cache->set(b => 2), 2;
is $cache->get('a'), 1;
is $cache->get('b'), 2;

is $cache->set(c => 3), 3;
is $cache->get('a'), 1;
is $cache->get('b'), 2;
is $cache->get('c'), 3;

is $cache->set(b => 4), 4;
is $cache->get('a'), 1;
is $cache->get('b'), 4;
is $cache->get('c'), 3;

my $keep;
is +($keep = $cache->get('a')), 1; # the order is now a => c => b
is $cache->set(d => 5), 5;
is $cache->get('a'), 1;
ok ! defined $cache->get('b');
is $cache->get('c'), 3;
is $cache->get('d'), 5; # the order is now d => c => a

is $cache->set('e', 6), 6;
ok ! defined $cache->get('a');
ok ! defined $cache->get('b');
is $cache->get('c'), 3;
is $cache->get('d'), 5;
is $cache->get('e'), 6;

is $cache->remove('d'), 5;
is $cache->get('c'), 3;
ok ! defined $cache->get('d');
is $cache->get('e'), 6;

$cache->clear;
ok ! defined $cache->get('c');
ok ! defined $cache->get('e');

done_testing;