1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +00:00
OpenMW/scripts/data/morrowind_tests/global_mwscript.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.9 KiB
Lua
Raw Normal View History

2024-06-17 20:06:53 +00:00
local testing = require('testing_util')
local core = require('openmw.core')
local world = require('openmw.world')
function iterateOverVariables(variables)
local first = nil
local last = nil
local count = 0
for k, _ in pairs(variables) do
first = first or k
last = k
count = count + 1
end
return first, last, count
end
return {
2024-06-18 15:55:01 +00:00
{'Should support iteration over an empty set of script variables', function()
2024-06-17 20:06:53 +00:00
local mainVars = world.mwscript.getGlobalScript('main').variables
local first, last, count = iterateOverVariables(mainVars)
testing.expectEqual(first, nil)
testing.expectEqual(last, nil)
testing.expectEqual(count, 0)
testing.expectEqual(count, #mainVars)
2024-06-18 15:55:01 +00:00
end},
2024-06-18 20:19:24 +00:00
{'Should support iteration of script variables', function()
2024-06-17 20:06:53 +00:00
local jiub = world.getObjectByFormId(core.getFormId('Morrowind.esm', 172867))
local jiubVars = world.mwscript.getLocalScript(jiub).variables
2024-06-18 15:55:01 +00:00
local first, last, count = iterateOverVariables(jiubVars)
2024-06-17 20:06:53 +00:00
testing.expectEqual(first, 'state')
testing.expectEqual(last, 'timer')
testing.expectEqual(count, 3)
testing.expectEqual(count, #jiubVars)
2024-06-18 20:19:24 +00:00
end},
{'Should support numeric and string indices for getting and setting', function()
local jiub = world.getObjectByFormId(core.getFormId('Morrowind.esm', 172867))
local jiubVars = world.mwscript.getLocalScript(jiub).variables
2024-06-18 15:55:01 +00:00
2024-06-17 20:06:53 +00:00
testing.expectEqual(jiubVars[1], jiubVars.state)
testing.expectEqual(jiubVars[2], jiubVars.wandering)
testing.expectEqual(jiubVars[3], jiubVars.timer)
2024-06-18 15:55:01 +00:00
jiubVars[1] = 123;
testing.expectEqual(jiubVars.state, 123)
jiubVars.wandering = 42;
testing.expectEqual(jiubVars[2], 42)
jiubVars[3] = 1.25;
testing.expectEqual(jiubVars.timer, 1.25)
2024-06-17 20:06:53 +00:00
end},
}