aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_util_cache.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-03-17 19:07:40 +0000
committerMatthew Wild <mwild1@gmail.com>2016-03-17 19:07:40 +0000
commit7070585c169306ee8226d23afa73e7f3f1251984 (patch)
tree90c54b1687e391173590ef727202ceeb70988fe0 /tests/test_util_cache.lua
parent379b127825254207f3163b6c2a00e0676fd6a136 (diff)
downloadprosody-7070585c169306ee8226d23afa73e7f3f1251984.tar.gz
prosody-7070585c169306ee8226d23afa73e7f3f1251984.zip
util.cache: Add head() and tail() methods (and tests)
Diffstat (limited to 'tests/test_util_cache.lua')
-rw-r--r--tests/test_util_cache.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_util_cache.lua b/tests/test_util_cache.lua
index 72cb5a85..ecdc2dc0 100644
--- a/tests/test_util_cache.lua
+++ b/tests/test_util_cache.lua
@@ -1,21 +1,44 @@
-
function new(new)
local c = new(5);
+ local function expect_kv(key, value, actual_key, actual_value)
+ assert_equal(key, actual_key, "key incorrect");
+ assert_equal(value, actual_value, "value incorrect");
+ end
+
+ expect_kv(nil, nil, c:head());
+ expect_kv(nil, nil, c:tail());
+
assert_equal(c:count(), 0);
c:set("one", 1)
assert_equal(c:count(), 1);
+ expect_kv("one", 1, c:head());
+ expect_kv("one", 1, c:tail());
+
c:set("two", 2)
+ expect_kv("two", 2, c:head());
+ expect_kv("one", 1, c:tail());
+
c:set("three", 3)
+ expect_kv("three", 3, c:head());
+ expect_kv("one", 1, c:tail());
+
c:set("four", 4)
c:set("five", 5);
assert_equal(c:count(), 5);
+ expect_kv("five", 5, c:head());
+ expect_kv("one", 1, c:tail());
c:set("foo", nil);
assert_equal(c:count(), 5);
+ expect_kv("five", 5, c:head());
+ expect_kv("one", 1, c:tail());
assert_equal(c:get("one"), 1);
+ expect_kv("five", 5, c:head());
+ expect_kv("one", 1, c:tail());
+
assert_equal(c:get("two"), 2);
assert_equal(c:get("three"), 3);
assert_equal(c:get("four"), 4);
@@ -26,6 +49,8 @@ function new(new)
c:set("six", 6);
assert_equal(c:count(), 5);
+ expect_kv("six", 6, c:head());
+ expect_kv("two", 2, c:tail());
assert_equal(c:get("one"), nil);
assert_equal(c:get("two"), 2);