Skip to content

Commit 35b6dc8

Browse files
committed
tests/lapi: add table.clear test
The patch adds a test for `table.clear()` function that is present in LuaJIT. Follows up the commit ee032e7 ("tests/lapi: add table tests"). Follows up #142
1 parent 2d00c57 commit 35b6dc8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/lapi/table_clear_test.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
Double-emitting of IR_NEWREF for the same key on the snap replay,
6+
https://github.com/LuaJIT/LuaJIT/issues/1128
7+
8+
X86/X64 load fusion conflict detection doesn't detect table.clear,
9+
https://github.com/LuaJIT/LuaJIT/issues/1117
10+
11+
Problem of HREFK with table.clear,
12+
https://github.com/LuaJIT/LuaJIT/issues/792
13+
14+
Add support for freeing memory manually,
15+
https://github.com/LuaJIT/LuaJIT/issues/620
16+
17+
Synopsis: table.clear(tbl)
18+
]]
19+
20+
local luzer = require("luzer")
21+
local test_lib = require("lib")
22+
23+
if test_lib.lua_version() ~= "LuaJIT" then
24+
print("Unsupported version.")
25+
os.exit(0)
26+
end
27+
28+
local table_clear = require("table.clear")
29+
30+
local function TestOneInput(buf)
31+
local fdp = luzer.FuzzedDataProvider(buf)
32+
local count = fdp:consume_integer(0, test_lib.MAX_INT64)
33+
local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)
34+
table_clear(tbl)
35+
-- Make sure the table is empty.
36+
local n_items = 0
37+
for _ in pairs(tbl) do
38+
n_items = n_items + 1
39+
end
40+
assert(n_items == 0)
41+
end
42+
43+
local args = {
44+
artifact_prefix = "table_clear_",
45+
}
46+
luzer.Fuzz(TestOneInput, nil, args)

0 commit comments

Comments
 (0)