|
| 1 | +--[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +6.6 – Table Manipulation, |
| 6 | +https://www.lua.org/manual/5.3/manual.html#6.6 |
| 7 | +
|
| 8 | +Synopsis: table.move(a1, f, e, t [,a2]) |
| 9 | +]] |
| 10 | + |
| 11 | +local luzer = require("luzer") |
| 12 | +local test_lib = require("lib") |
| 13 | + |
| 14 | +if test_lib.lua_current_version_lt_than(5, 3) and |
| 15 | + test_lib.lua_version == "PUC Rio Lua" then |
| 16 | + print("Unsupported version.") |
| 17 | + os.exit(0) |
| 18 | +end |
| 19 | + |
| 20 | +local function TestOneInput(buf, _size) |
| 21 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 22 | + local count = fdp:consume_integer(0, test_lib.MAX_INT) |
| 23 | + local a1 = fdp:consume_strings(test_lib.MAX_STR_LEN, count) |
| 24 | + local a2 = {} |
| 25 | + -- Move random items from the table `a1` to the table `a2`. |
| 26 | + -- Beware, `table.move()` works too slow with huge numbers. |
| 27 | + local MAX_N = 1000 |
| 28 | + local f = fdp:consume_integer(-MAX_N, MAX_N) |
| 29 | + local e = fdp:consume_integer(-MAX_N, MAX_N) |
| 30 | + local t = fdp:consume_integer(-MAX_N, MAX_N) |
| 31 | + local res = table.move(a1, f, e, t, a2) |
| 32 | + assert(test_lib.tables_equal(a2, res)) |
| 33 | +end |
| 34 | + |
| 35 | +local args = { |
| 36 | + artifact_prefix = "table_move_", |
| 37 | +} |
| 38 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments