Annotate

tests/test_util_cache.lua @ 7035:085a286e2873

certs/Makefile: Fix generating cert from only a key (no config then)
author Kim Alvefur <zash@zash.se>
date Thu, 24 Dec 2015 10:39:13 +0100
parent 7016:e0a0af42b09f
child 7289:42e7545d5ae3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6946
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 function new(new)
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local c = new(5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 assert_equal(c:count(), 0);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 c:set("one", 1)
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 assert_equal(c:count(), 1);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 c:set("two", 2)
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 c:set("three", 3)
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 c:set("four", 4)
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 c:set("five", 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 c:set("foo", nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert_equal(c:get("one"), 1);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 assert_equal(c:get("two"), 2);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 assert_equal(c:get("three"), 3);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 assert_equal(c:get("foo"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 assert_equal(c:get("bar"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 c:set("six", 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 assert_equal(c:get("two"), 2);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 assert_equal(c:get("three"), 3);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 c:set("three", nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 assert_equal(c:count(), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 assert_equal(c:get("two"), 2);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 c:set("seven", 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 assert_equal(c:get("two"), 2);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 c:set("eight", 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 c:set("four", 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 assert_equal(c:get("five"), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 c:set("nine", 9);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 assert_equal(c:get("four"), 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 assert_equal(c:get("five"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 assert_equal(c:get("nine"), 9);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 local keys = { "nine", "four", "eight", "seven", "six" };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 local values = { 9, 4, 8, 7, 6 };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 local i = 0;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 for k, v in c:items() do
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 i = i + 1;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 assert_equal(k, keys[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 assert_equal(v, values[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 end
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 assert_equal(i, 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 c:set("four", "2+2");
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 assert_equal(c:get("four"), "2+2");
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 assert_equal(c:get("five"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 assert_equal(c:get("nine"), 9);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 local keys = { "four", "nine", "eight", "seven", "six" };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 local values = { "2+2", 9, 8, 7, 6 };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 local i = 0;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 for k, v in c:items() do
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 i = i + 1;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 assert_equal(k, keys[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 assert_equal(v, values[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 end
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 assert_equal(i, 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 c:set("foo", nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 assert_equal(c:count(), 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 assert_equal(c:get("four"), "2+2");
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 assert_equal(c:get("five"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 assert_equal(c:get("nine"), 9);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 local keys = { "four", "nine", "eight", "seven", "six" };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 local values = { "2+2", 9, 8, 7, 6 };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 local i = 0;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 for k, v in c:items() do
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 i = i + 1;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 assert_equal(k, keys[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 assert_equal(v, values[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 end
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 assert_equal(i, 5);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 c:set("four", nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 assert_equal(c:get("one"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 assert_equal(c:get("two"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 assert_equal(c:get("three"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 assert_equal(c:get("four"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 assert_equal(c:get("five"), nil);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 assert_equal(c:get("six"), 6);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 assert_equal(c:get("seven"), 7);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 assert_equal(c:get("eight"), 8);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 assert_equal(c:get("nine"), 9);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 local keys = { "nine", "eight", "seven", "six" };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 local values = { 9, 8, 7, 6 };
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 local i = 0;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 for k, v in c:items() do
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 i = i + 1;
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 assert_equal(k, keys[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 assert_equal(v, values[i]);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 end
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 assert_equal(i, 4);
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172
7016
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
173 local evicted_key, evicted_value;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
174 local c = new(3, function (_key, _value)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
175 evicted_key, evicted_value = _key, _value;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
176 end);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
177 local function set(k, v, should_evict_key, should_evict_value)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
178 evicted_key, evicted_value = nil, nil;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
179 c:set(k, v);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
180 assert_equal(evicted_key, should_evict_key);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
181 assert_equal(evicted_value, should_evict_value);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
182 end
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
183 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
184 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
185 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
186 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
187 set("a", 1)
6946
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188
7016
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
189 set("b", 2)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
190 set("c", 3)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
191 set("b", 2)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
192 set("d", 4, "a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
193 set("e", 5, "c", 3)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
194
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
195
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
196 local evicted_key, evicted_value;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
197 local c3 = new(1, function (_key, _value, c3)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
198 evicted_key, evicted_value = _key, _value;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
199 if _key == "a" then
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
200 -- Put it back in...
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
201 -- Check that the newest key/value was set before on_evict was called
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
202 assert_equal(c3:get("b"), 2);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
203 -- Sanity check for what we're evicting
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
204 assert_equal(_key, "a");
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
205 assert_equal(_value, 1);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
206 -- Re-insert the evicted key (causes this evict function to run again with "b",2)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
207 c3:set(_key, _value)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
208 assert_equal(c3:get(_key), _value)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
209 end
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
210 end);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
211 local function set(k, v, should_evict_key, should_evict_value)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
212 evicted_key, evicted_value = nil, nil;
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
213 c3:set(k, v);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
214 assert_equal(evicted_key, should_evict_key);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
215 assert_equal(evicted_value, should_evict_value);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
216 end
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
217 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
218 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
219 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
220 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
221 set("a", 1)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
222
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
223 -- The evict handler re-inserts "a"->1, so "b" gets evicted:
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
224 set("b", 2, "b", 2)
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
225 -- Check the final state is what we expect
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
226 assert_equal(c3:get("a"), 1);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
227 assert_equal(c3:get("b"), nil);
e0a0af42b09f util.cache (and tests): Call on_evict after insertion of the new key, so inside on_evict we can be more certain about the current state of the cache (i.e. full, new item added, old item removed)
Matthew Wild <mwild1@gmail.com>
parents: 6946
diff changeset
228 assert_equal(c3:count(), 1);
6946
31fb9eb9edce tests: Add tests for util.cache
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 end