lune/tests/stdio/prompt.luau

50 lines
1.2 KiB
Lua
Raw Normal View History

2023-02-06 17:59:48 +00:00
-- NOTE: This test is intentionally not included in the
-- automated tests suite since it requires user input
local passed = false
task.delay(0.2, function()
if passed then
task.spawn(error, "Prompt must not block other lua threads")
process.exit(1)
else
-- stdio.ewrite("Hello from concurrent task!")
end
end)
2023-02-06 17:59:48 +00:00
-- Text prompt
local text = stdio.prompt("text", "Type some text")
assert(#text > 0, "Did not get any text")
print(`Got text '{text}'\n`)
passed = true
2023-02-06 17:59:48 +00:00
-- Confirmation prompt
local confirmed = stdio.prompt("confirm", "Please confirm", true)
assert(type(confirmed) == "boolean", "Did not get a boolean as result")
2023-02-06 17:59:48 +00:00
print(if confirmed then "Confirmed\n" else "Did not confirm\n")
-- Selection prompt
local option = stdio.prompt(
"select",
"Please select the first option from the list",
{ "one", "two", "three", "four" }
)
assert(option == 1, "Did not get the first option as result")
print(`Got option #{option}\n`)
2023-02-06 17:59:48 +00:00
-- Multi-selection prompt
local options = stdio.prompt(
"multiselect",
"Please select options two and four",
{ "one", "two", "three", "four", "five" }
)
assert(
options ~= nil and table.find(options, 2) and table.find(options, 4),
"Did not get options 2 and 4 as result"
)
print(`Got option(s) {stdio.format(options)}\n`)