Skip to content

Commit 9188875

Browse files
committed
xxx
1 parent 0646686 commit 9188875

17 files changed

+71
-50
lines changed

tests/lapi/lib.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ local MIN_INT64 = math.mininteger or -0x8000000000000000
5151
local MAX_INT = 0x7fffffff
5252
local MIN_INT = -0x80000000
5353

54+
local MAX_STR_LEN = 4096
55+
5456
local function bitwise_op(op_name)
5557
return function(...)
5658
local n = select("#", ...)
@@ -100,6 +102,7 @@ return {
100102
MIN_INT64 = MIN_INT64,
101103
MAX_INT = MAX_INT,
102104
MIN_INT = MIN_INT,
105+
MAX_STR_LEN = MAX_STR_LEN,
103106

104107
-- FDP.
105108
random_locale = random_locale,

tests/lapi/string_byte_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ local test_lib = require("lib")
1717
local function TestOneInput(buf, _size)
1818
local fdp = luzer.FuzzedDataProvider(buf)
1919
os.setlocale(test_lib.random_locale(fdp), "all")
20-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
21-
local str = fdp:consume_string(max_len)
20+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
2221
local i = fdp:consume_integer(0, test_lib.MAX_INT)
2322
local j = fdp:consume_integer(0, test_lib.MAX_INT)
23+
-- `string.byte()` is the same as `str:byte()`.
2424
assert(string.byte(str, i, j) == str:byte(i, j))
2525
local char_code = string.byte(str, i, j)
2626
if char_code then

tests/lapi/string_dump_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ local test_lib = require("lib")
2020
local function TestOneInput(buf, _size)
2121
local fdp = luzer.FuzzedDataProvider(buf)
2222
os.setlocale(test_lib.random_locale(fdp), "all")
23-
local max_len = fdp:consume_string(1, test_lib.MAX_INT)
24-
local str = fdp:consume_string(1, max_len)
23+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
2524
local strip = fdp:consume_boolean()
2625
local ok, func = pcall(loadstring, str)
2726
if not ok or func == nil then

tests/lapi/string_find_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ local test_lib = require("lib")
2323
local function TestOneInput(buf, _size)
2424
local fdp = luzer.FuzzedDataProvider(buf)
2525
os.setlocale(test_lib.random_locale(fdp), "all")
26-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
27-
local str = fdp:consume_string(max_len)
28-
local pattern = fdp:consume_string(max_len)
26+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
27+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2928
local init = fdp:consume_integer(0, test_lib.MAX_INT)
3029
local plain = fdp:consume_boolean()
3130
-- Avoid errors like "malformed pattern (missing ']')".

tests/lapi/string_format_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ local function TestOneInput(buf, _size)
6767
local fdp = luzer.FuzzedDataProvider(buf)
6868
local spec = fdp:oneof(specifiers)
6969
local format_string = ("%%%s"):format(spec)
70-
local max_len = fdp:consume_integer(1, 10000)
71-
local str = fdp:consume_string(1, max_len)
70+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
7271

7372
os.setlocale(test_lib.random_locale(fdp), "all")
7473
local ok, res = pcall(string.format, format_string, str)

tests/lapi/string_gmatch_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ local test_lib = require("lib")
2121
local function TestOneInput(buf, _size)
2222
local fdp = luzer.FuzzedDataProvider(buf)
2323
os.setlocale(test_lib.random_locale(fdp), "all")
24-
local len = fdp:consume_integer(0, test_lib.MAX_INT)
25-
local s = fdp:consume_string(len)
26-
local pattern = fdp:consume_string(len)
24+
local s = fdp:consume_string(test_lib.MAX_STR_LEN)
25+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2726
local init = fdp:consume_integer(0, test_lib.MAX_INT)
2827
string.gmatch(s, pattern, init)
2928
end

tests/lapi/string_gsub_test.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ local test_lib = require("lib")
2323

2424
local function TestOneInput(buf, _size)
2525
local fdp = luzer.FuzzedDataProvider(buf)
26-
local max_len = fdp:consume_string(0, test_lib.MAX_INT)
27-
local str = fdp:consume_string(0, max_len)
28-
local pattern = fdp:consume_string(0, max_len)
29-
local repl = fdp:consume_string(0, max_len)
26+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
27+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
28+
local repl = fdp:consume_string(test_lib.MAX_STR_LEN)
3029
local n = fdp:consume_integer(0, test_lib.MAX_INT)
3130

3231
os.setlocale(test_lib.random_locale(fdp), "all")

tests/lapi/string_len_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ local test_lib = require("lib")
1414
local function TestOneInput(buf, _size)
1515
local fdp = luzer.FuzzedDataProvider(buf)
1616
os.setlocale(test_lib.random_locale(fdp), "all")
17-
local str_len = fdp:consume_integer(0, test_lib.MAX_INT)
18-
local str = fdp:consume_string(str_len)
17+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
1918
assert(string.len(str) == #str)
2019
end
2120

tests/lapi/string_lower_test.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ local test_lib = require("lib")
1414
local function TestOneInput(buf, _)
1515
local fdp = luzer.FuzzedDataProvider(buf)
1616
os.setlocale(test_lib.random_locale(fdp), "all")
17-
local ch_uppercase = string.char(fdp:consume_integer(65, 65 + 25))
17+
local lower_bound = string.byte("A")
18+
local upper_bound = string.byte("A") + 25
19+
local ch_code = fdp:consume_integer(lower_bound, upper_bound)
20+
local ch_uppercase = string.char(ch_code)
1821
local ch = string.upper(string.lower(ch_uppercase))
1922
assert(ch == ch_uppercase)
23+
24+
local str = fdp:consume_string(1, test_lib.MAX_STR_LEN)
25+
local str_lowercase = str:lower()
26+
assert(str_lowercase == str_lowercase:upper():lower())
2027
end
2128

2229
local args = {

tests/lapi/string_match_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ local test_lib = require("lib")
1414
local function TestOneInput(buf, _size)
1515
local fdp = luzer.FuzzedDataProvider(buf)
1616
os.setlocale(test_lib.random_locale(fdp), "all")
17-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
18-
local str = fdp:consume_string(max_len)
19-
local pattern = fdp:consume_string(max_len)
17+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
18+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2019
local init = fdp:consume_integer(0, test_lib.MAX_INT)
2120
-- Avoid errors like "malformed pattern (ends with '%')".
2221
local ok, res = pcall(string.match, str, pattern, init)

0 commit comments

Comments
 (0)