aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index a16d557b..29cb05d5 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -359,6 +359,38 @@ end
359assert(n == 5) 359assert(n == 5)
360 360
361 361
362do
363 print("testing next x GC of deleted keys")
364 -- bug in 5.4.1
365 local co = coroutine.wrap(function (t)
366 for k, v in pairs(t) do
367 local k1 = next(t) -- all previous keys were deleted
368 assert(k == k1) -- current key is the first in the table
369 t[k] = nil
370 local expected = (type(k) == "table" and k[1] or
371 type(k) == "function" and k() or
372 string.sub(k, 1, 1))
373 assert(expected == v)
374 coroutine.yield(v)
375 end
376 end)
377 local t = {}
378 t[{1}] = 1 -- add several unanchored, collectable keys
379 t[{2}] = 2
380 t[string.rep("a", 50)] = "a" -- long string
381 t[string.rep("b", 50)] = "b"
382 t[{3}] = 3
383 t[string.rep("c", 10)] = "c" -- short string
384 t[function () return 10 end] = 10
385 local count = 7
386 while co(t) do
387 collectgarbage("collect") -- collect dead keys
388 count = count - 1
389 end
390 assert(count == 0 and next(t) == nil) -- traversed the whole table
391end
392
393
362local function test (a) 394local function test (a)
363 assert(not pcall(table.insert, a, 2, 20)); 395 assert(not pcall(table.insert, a, 2, 20));
364 table.insert(a, 10); table.insert(a, 2, 20); 396 table.insert(a, 10); table.insert(a, 2, 20);