Lua: fix key deletion in tables

This commit is contained in:
Zef Hemel
2025-10-09 09:19:58 +02:00
parent 34b143f5db
commit 18e78e5006
3 changed files with 20 additions and 4 deletions
+8 -1
View File
@@ -126,6 +126,13 @@ assert(table.includes(t, "three"))
assert(table.includes(t, true))
assert(not table.includes(t, "missing"))
-- Test using table as set
local s = {}
s["something"] = true
assertEqual(#table.keys(s), 1)
-- Remove from the map
s["something"] = nil
assertEqual(#table.keys(s), 0)
-- Error cases
local success, error = pcall(function()
@@ -147,4 +154,4 @@ local t = { 0, 1, 2, 3 }
local idx, two = table.find(t, function(v) return v == 2 end)
assertEqual(idx, 3)
assertEqual(two, 2)
assertEqual(table.find(t, function(v) return v == 4 end), nil)
assertEqual(table.find(t, function(v) return v == 4 end), nil)