Files
fs25-adsmartpickup/tests/test_adNames.lua
T

21 lines
1.1 KiB
Lua

-- Kør: luajit tests/test_adNames.lua (fra repo-roden)
dofile("FS25_ADSmartPickup/adNames.lua")
local failures = 0
local function check(name, actual, expected)
if actual == expected then print("OK " .. name) else
failures = failures + 1
print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual)))
end
end
local byId = ADNames.fromRecords({{id = "placeableA", name = "Gårdsilo 10"}, {id = "", name = "x"}, {id = "placeableB", name = " "}, {id = "placeableC"}})
check("navn indlæst", byId.placeableA, "Gårdsilo 10")
check("tomt id springes over", byId[""], nil)
check("blankt navn springes over", byId.placeableB, nil)
check("manglende navn springes over", byId.placeableC, nil)
ADNames.byId = byId
check("opslag på bygning", ADNames.forPlaceable({uniqueId = "placeableA"}), "Gårdsilo 10")
check("bygning uden eget navn", ADNames.forPlaceable({uniqueId = "placeableZ"}), nil)
check("uden uniqueId", ADNames.forPlaceable({}), nil)
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)