Mercurial > prosody-hg
comparison 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 |
| parents | 3259653512e7 |
| children | c4337ff4f1c4 |
comparison
equal
deleted
inserted
replaced
| 11365:5eb817cdd5cd | 11366:618ab9bba1c2 |
|---|---|
| 309 assert.are.equal(c5:set("e", 5), true); -- "b" evicted (cb returned true) | 309 assert.are.equal(c5:set("e", 5), true); -- "b" evicted (cb returned true) |
| 310 assert.are.equal(c5:set("f", 6), false); -- "c" won't evict (cb returned false) | 310 assert.are.equal(c5:set("f", 6), false); -- "c" won't evict (cb returned false) |
| 311 | 311 |
| 312 expect_kv("e", 5, c5:head()); | 312 expect_kv("e", 5, c5:head()); |
| 313 expect_kv("c", 3, c5:tail()); | 313 expect_kv("c", 3, c5:tail()); |
| 314 | |
| 315 end); | |
| 316 | |
| 317 (_VERSION=="Lua 5.1" and pending or it)(":table works", function () | |
| 318 local t = cache.new(3):table(); | |
| 319 assert.is.table(t); | |
| 320 t["a"] = "1"; | |
| 321 assert.are.equal(t["a"], "1"); | |
| 322 t["b"] = "2"; | |
| 323 assert.are.equal(t["b"], "2"); | |
| 324 t["c"] = "3"; | |
| 325 assert.are.equal(t["c"], "3"); | |
| 326 t["d"] = "4"; | |
| 327 assert.are.equal(t["d"], "4"); | |
| 328 assert.are.equal(t["a"], nil); | |
| 329 | |
| 330 local i = spy.new(function () end); | |
| 331 for k, v in pairs(t) do | |
| 332 i(k,v) | |
| 333 end | |
| 334 assert.spy(i).was_called(); | |
| 335 assert.spy(i).was_called_with("b", "2"); | |
| 336 assert.spy(i).was_called_with("c", "3"); | |
| 337 assert.spy(i).was_called_with("d", "4"); | |
| 314 end); | 338 end); |
| 315 end); | 339 end); |
| 316 end); | 340 end); |
