1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00
CC-Tweaked/src/test/resources/test-rom/spec/apis/textutils_spec.lua
SquidDev d4b8650d21 Use select('#', ...) instead of ipairs on varargs
This means we don't discard any value after nil, meaning that
calls such as colors.combine(nil, 1, 2, 3) will error, rather
than returning 0.
2019-06-01 10:12:10 +01:00

91 lines
3.7 KiB
Lua

describe("The textutils library", function()
describe("textutils.slowWrite", function()
it("validates arguments", function()
expect.error(textutils.slowWrite, nil, false):eq("bad argument #2 (expected number, got boolean)")
end)
end)
describe("textutils.formatTime", function()
it("validates arguments", function()
textutils.formatTime(0)
textutils.formatTime(0, false)
expect.error(textutils.formatTime, nil):eq("bad argument #1 (expected number, got nil)")
expect.error(textutils.formatTime, 1, 1):eq("bad argument #2 (expected boolean, got number)")
end)
end)
describe("textutils.pagedPrint", function()
it("validates arguments", function()
expect.error(textutils.pagedPrint, nil, false):eq("bad argument #2 (expected number, got boolean)")
end)
end)
describe("textutils.tabulate", function()
it("validates arguments", function()
term.redirect(window.create(term.current(), 1, 1, 5, 5, false))
textutils.tabulate()
textutils.tabulate({ "test" })
textutils.tabulate(colors.white)
expect.error(textutils.tabulate, nil):eq("bad argument #1 (expected number or table, got nil)")
expect.error(textutils.tabulate, { "test" }, nil):eq("bad argument #2 (expected number or table, got nil)")
end)
end)
describe("textutils.pagedTabulate", function()
it("validates arguments", function()
term.redirect(window.create(term.current(), 1, 1, 5, 5, false))
textutils.pagedTabulate()
textutils.pagedTabulate({ "test" })
textutils.pagedTabulate(colors.white)
expect.error(textutils.pagedTabulate, nil):eq("bad argument #1 (expected number or table, got nil)")
expect.error(textutils.pagedTabulate, { "test" }, nil):eq("bad argument #2 (expected number or table, got nil)")
end)
end)
describe("textutils.empty_json_array", function()
it("is immutable", function()
expect.error(function() textutils.empty_json_array[1] = true end)
:eq("textutils_spec.lua:51: attempt to mutate textutils.empty_json_array")
end)
end)
describe("textutils.unserialise", function()
it("validates arguments", function()
textutils.unserialise("")
expect.error(textutils.unserialise, nil):eq("bad argument #1 (expected string, got nil)")
end)
end)
describe("textutils.serialiseJSON", function()
it("validates arguments", function()
textutils.serialiseJSON("")
textutils.serialiseJSON(1)
textutils.serialiseJSON({})
textutils.serialiseJSON(false)
textutils.serialiseJSON("", true)
expect.error(textutils.serialiseJSON, nil):eq("bad argument #1 (expected table, string, number or boolean, got nil)")
expect.error(textutils.serialiseJSON, "", 1):eq("bad argument #2 (expected boolean, got number)")
end)
end)
describe("textutils.urlEncode", function()
it("validates arguments", function()
textutils.urlEncode("")
expect.error(textutils.urlEncode, nil):eq("bad argument #1 (expected string, got nil)")
end)
end)
describe("textutils.complete", function()
it("validates arguments", function()
textutils.complete("pri")
textutils.complete("pri", _G)
expect.error(textutils.complete, nil):eq("bad argument #1 (expected string, got nil)")
expect.error(textutils.complete, "", false):eq("bad argument #2 (expected table, got boolean)")
end)
end)
end)