# HG changeset patch # User Matthew Wild # Date 1458242098 0 # Node ID 688a7f5d3624ec48ee743bda057603def7bddf10 # Parent 70ab13e81cf5ead17fe6eb8522abb928b1e65a2c tests: util.cache: Tests for different return values of on_evict diff -r 70ab13e81cf5 -r 688a7f5d3624 tests/test_util_cache.lua --- a/tests/test_util_cache.lua Thu Mar 17 19:08:42 2016 +0000 +++ b/tests/test_util_cache.lua Thu Mar 17 19:14:58 2016 +0000 @@ -271,4 +271,28 @@ expect_kv("c", 3, c4:head()); expect_kv("a", 1, c4:tail()); + local c5 = new(3, function (k, v) + if k == "a" then + return nil; + elseif k == "b" then + return true; + end + return false; + end); + + assert_equal(c5:set("a", 1), true); + assert_equal(c5:set("a", 1), true); + assert_equal(c5:set("a", 1), true); + assert_equal(c5:set("a", 1), true); + assert_equal(c5:set("b", 2), true); + assert_equal(c5:set("c", 3), true); + assert_equal(c5:set("d", 4), true); -- "a" evicted (cb returned nil) + assert_equal(c5:set("d", 4), true); -- nop + assert_equal(c5:set("d", 4), true); -- nop + assert_equal(c5:set("e", 5), true); -- "b" evicted (cb returned true) + assert_equal(c5:set("f", 6), false); -- "c" won't evict (cb returned false) + + expect_kv("e", 5, c5:head()); + expect_kv("c", 3, c5:tail()); + end