Skip to content

Commit 4171260

Browse files
committed
tests/lapi: utf8 tests
1 parent bfac9d7 commit 4171260

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

tests/lapi/utf8_char_test.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.5 – UTF-8 Support
6+
https://www.lua.org/manual/5.3/manual.html#6.5
7+
8+
'utf8.codes' does not raise an error on spurious continuation bytes,
9+
https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
10+
11+
Synopsis: utf8.char(...)
12+
]]
13+
14+
local luzer = require("luzer")
15+
local test_lib = require("lib")
16+
local MAX_INT = test_lib.MAX_INT
17+
18+
if test_lib.lua_version() == "LuaJIT" then
19+
os.exit()
20+
end
21+
22+
-- The function is introduced in Lua 5.3.
23+
if test_lib.lua_current_version_lt_than(5, 3) then
24+
os.exit()
25+
end
26+
27+
local unpack = unpack or table.unpack
28+
29+
local function TestOneInput(buf)
30+
local fdp = luzer.FuzzedDataProvider(buf)
31+
local n = fdp:consume_integer(1, MAX_INT)
32+
local ch = fdp:consume_integers(0, MAX_INT, n)
33+
os.setlocale(test_lib.random_locale(fdp), "all")
34+
utf8.char(unpack(ch))
35+
end
36+
37+
local args = {
38+
artifact_prefix = "utf8_char_",
39+
}
40+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/utf8_codepoint_test.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--[=[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.5 – UTF-8 Support
6+
https://www.lua.org/manual/5.3/manual.html#6.5
7+
8+
'utf8.codes' does not raise an error on spurious continuation bytes,
9+
https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
10+
11+
Synopsis: utf8.codepoint(s [, i [, j [, lax]]])
12+
]]=]
13+
14+
local luzer = require("luzer")
15+
local test_lib = require("lib")
16+
local MAX_INT = test_lib.MAX_INT
17+
18+
-- The function is introduced in Lua 5.3.
19+
if test_lib.lua_current_version_lt_than(5, 3) then
20+
os.exit()
21+
end
22+
23+
local function TestOneInput(buf)
24+
local fdp = luzer.FuzzedDataProvider(buf)
25+
local max_len = fdp:consume_integer(1, MAX_INT)
26+
local s = fdp:consume_string(max_len)
27+
local i = fdp:consume_integer(0, MAX_INT)
28+
local j = fdp:consume_integer(0, MAX_INT)
29+
local lax = fdp:consume_integer(1, MAX_INT)
30+
os.setlocale(test_lib.random_locale(fdp), "all")
31+
pcall(utf8.codepoint, s, i, j, lax)
32+
end
33+
34+
local args = {
35+
artifact_prefix = "utf8_codepoint_",
36+
}
37+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/utf8_codes_test.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.5 – UTF-8 Support
6+
https://www.lua.org/manual/5.3/manual.html#6.5
7+
8+
'utf8.codes' does not raise an error on spurious continuation bytes,
9+
https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
10+
11+
Synopsis: utf8.codes(s [, lax])
12+
]]
13+
14+
local luzer = require("luzer")
15+
local test_lib = require("lib")
16+
local MAX_INT = test_lib.MAX_INT
17+
18+
-- The function is introduced in Lua 5.3.
19+
if test_lib.lua_current_version_lt_than(5, 3) then
20+
os.exit()
21+
end
22+
23+
local function TestOneInput(buf)
24+
local fdp = luzer.FuzzedDataProvider(buf)
25+
local max_len = fdp:consume_integer(1, MAX_INT)
26+
local s = fdp:consume_string(max_len)
27+
local lax = fdp:consume_integer(0, MAX_INT)
28+
os.setlocale(test_lib.random_locale(fdp), "all")
29+
utf8.codes(s, lax)
30+
end
31+
32+
local args = {
33+
artifact_prefix = "utf8_codes_",
34+
}
35+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/utf8_len_test.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--[=[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.5 – UTF-8 Support
6+
https://www.lua.org/manual/5.3/manual.html#6.5
7+
8+
'utf8.codes' does not raise an error on spurious continuation bytes,
9+
https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
10+
11+
Synopsis: utf8.len(s [, i [, j [, lax]]])
12+
]]=]
13+
14+
local luzer = require("luzer")
15+
local test_lib = require("lib")
16+
local MAX_INT = test_lib.MAX_INT
17+
18+
-- The function is introduced in Lua 5.3.
19+
if test_lib.lua_current_version_lt_than(5, 3) then
20+
os.exit()
21+
end
22+
23+
local function TestOneInput(buf)
24+
local fdp = luzer.FuzzedDataProvider(buf)
25+
local max_len = fdp:consume_integer(1, MAX_INT)
26+
local s = fdp:consume_string(max_len)
27+
local i = fdp:consume_integer(0, MAX_INT)
28+
local j = fdp:consume_integer(0, MAX_INT)
29+
local lax = fdp:consume_integer(0, MAX_INT)
30+
os.setlocale(test_lib.random_locale(fdp), "all")
31+
pcall(utf8.len, s, i, j, lax)
32+
end
33+
34+
local args = {
35+
artifact_prefix = "utf8_len_",
36+
}
37+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/utf8_offset_test.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.5 – UTF-8 Support
6+
https://www.lua.org/manual/5.3/manual.html#6.5
7+
8+
'utf8.codes' does not raise an error on spurious continuation bytes,
9+
https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
10+
11+
Synopsis: utf8.offset(s, n [, i])
12+
]]
13+
14+
local luzer = require("luzer")
15+
local test_lib = require("lib")
16+
local MAX_INT = test_lib.MAX_INT
17+
local MIN_INT = test_lib.MIN_INT
18+
19+
-- The function is introduced in Lua 5.3.
20+
if test_lib.lua_current_version_lt_than(5, 3) then
21+
os.exit()
22+
end
23+
24+
local function TestOneInput(buf)
25+
local fdp = luzer.FuzzedDataProvider(buf)
26+
local max_len = fdp:consume_integer(0, MAX_INT)
27+
local s = fdp:consume_string(max_len)
28+
local n = fdp:consume_integer(MIN_INT, MAX_INT)
29+
local i = fdp:consume_integer(1, MAX_INT)
30+
os.setlocale(test_lib.random_locale(fdp), "all")
31+
utf8.offset(s, n, i)
32+
end
33+
34+
local args = {
35+
artifact_prefix = "utf8_offset_",
36+
}
37+
luzer.Fuzz(TestOneInput, nil, args)

0 commit comments

Comments
 (0)