65 lines
2.9 KiB
Lua
Executable File
65 lines
2.9 KiB
Lua
Executable File
-- Run from the repository root with Lua 5.1 or LuaJIT.
|
|
local formspec, starts = "", 0
|
|
local saved = {name = "", address = "other.example", remote_port = "12345"}
|
|
DIR_DELIM = "/"
|
|
gamedata = {errormessage = "Server said: [no;thanks]", reconnect_requested = true}
|
|
Settings = function(path)
|
|
assert(path == "builtin/mainmenu/server.conf")
|
|
return {get = function(_, key)
|
|
return ({address = "luanti.eom.dev", port = "30000"})[key]
|
|
end}
|
|
end
|
|
core = {
|
|
get_mainmenu_path = function() return "builtin/mainmenu" end,
|
|
settings = {
|
|
get = function(_, key) return saved[key] end,
|
|
set = function(_, key, value) saved[key] = value end,
|
|
},
|
|
formspec_escape = function(value)
|
|
return (tostring(value):gsub("([\\%[%];,])", "\\%1"))
|
|
end,
|
|
colorize = function(_, text) return text end,
|
|
set_background = function() end,
|
|
set_clouds = function(enabled) assert(not enabled) end,
|
|
set_topleft_text = function() end,
|
|
update_formspec = function(value) formspec = value end,
|
|
start = function() starts = starts + 1 end,
|
|
}
|
|
|
|
dofile("menu/init.lua")
|
|
assert(formspec:find("#1e1e2e", 1, true), "Mocha background missing")
|
|
assert(formspec:find("Make yourself at home.", 1, true), "Community welcome missing")
|
|
assert(formspec:find("Sign in to play", 1, true), "Login heading missing")
|
|
assert(formspec:find("connect;Connect to the world", 1, true), "Connect action missing")
|
|
assert(formspec:find("playername;;", 1, true), "Player-name field missing")
|
|
assert(formspec:find(";both;#1e1e2e", 1, true), "Fullscreen Mocha background missing")
|
|
assert(formspec:find("field,pwdfield;border=false", 1, true), "Stock input skin must be hidden")
|
|
assert(formspec:find("luanti.eom.dev:30000", 1, true))
|
|
assert(formspec:find("\\[no\\;thanks\\]", 1, true), "Error not escaped")
|
|
assert(not formspec:find("te_address", 1, true))
|
|
assert(not formspec:find("tabheader", 1, true))
|
|
|
|
core.button_handler({connect = true, playername = ""})
|
|
assert(starts == 0)
|
|
assert(formspec:find("Enter a username", 1, true))
|
|
core.event_handler("MenuQuit")
|
|
assert(starts == 0)
|
|
|
|
core.button_handler({connect = true, playername = "Player", password = "secret",
|
|
te_address = "attacker.example", te_port = "12345", selected_world = 42})
|
|
assert(starts == 1)
|
|
assert(gamedata.mode == "join" and not gamedata.singleplayer)
|
|
assert(gamedata.address == "luanti.eom.dev" and gamedata.port == 30000)
|
|
assert(gamedata.selected_world == 0 and gamedata.worldindex == 0)
|
|
assert(gamedata.password == "secret" and saved.password == nil)
|
|
assert(saved.name == "Player")
|
|
assert(not gamedata.reconnect_requested and not gamedata.do_reconnect)
|
|
|
|
gamedata.errormessage = "Disconnected [again]"
|
|
core.event_handler("Refresh")
|
|
assert(formspec:find("Disconnected \\[again\\]", 1, true))
|
|
assert(not formspec:find("secret", 1, true), "Password leaked into formspec")
|
|
core.button_handler({key_enter = true, password = "new-secret"})
|
|
assert(starts == 2 and gamedata.password == "new-secret")
|
|
print("Menu tests passed")
|