Software /
code /
prosody
Diff
spec/util_cache_spec.lua @ 11366:618ab9bba1c2
util.cache: Add test for :table (fails on Lua 5.1)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 05 Feb 2021 16:14:06 +0100 |
parent | 9323:3259653512e7 |
child | 12571:c4337ff4f1c4 |
line wrap: on
line diff
--- a/spec/util_cache_spec.lua Fri Feb 05 15:52:46 2021 +0100 +++ b/spec/util_cache_spec.lua Fri Feb 05 16:14:06 2021 +0100 @@ -311,6 +311,30 @@ expect_kv("e", 5, c5:head()); expect_kv("c", 3, c5:tail()); + + end); + + (_VERSION=="Lua 5.1" and pending or it)(":table works", function () + local t = cache.new(3):table(); + assert.is.table(t); + t["a"] = "1"; + assert.are.equal(t["a"], "1"); + t["b"] = "2"; + assert.are.equal(t["b"], "2"); + t["c"] = "3"; + assert.are.equal(t["c"], "3"); + t["d"] = "4"; + assert.are.equal(t["d"], "4"); + assert.are.equal(t["a"], nil); + + local i = spy.new(function () end); + for k, v in pairs(t) do + i(k,v) + end + assert.spy(i).was_called(); + assert.spy(i).was_called_with("b", "2"); + assert.spy(i).was_called_with("c", "3"); + assert.spy(i).was_called_with("d", "4"); end); end); end);