mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 12:32:36 +00:00
Add unit tests
This commit is contained in:
parent
2adaf33fa2
commit
0f20e47e0e
@ -203,13 +203,13 @@ namespace MWLua
|
|||||||
if (index >= size)
|
if (index >= size)
|
||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
auto i = index++;
|
auto i = index++;
|
||||||
if (i <= locals.mShorts.size())
|
if (i < locals.mShorts.size())
|
||||||
return std::make_tuple<std::string_view, double>(compilerLocals.get('s')[i], locals.mShorts[i]);
|
return std::make_tuple<std::string_view, double>(compilerLocals.get('s')[i], locals.mShorts[i]);
|
||||||
i -= locals.mShorts.size();
|
i -= locals.mShorts.size();
|
||||||
if (i <= locals.mLongs.size())
|
if (i < locals.mLongs.size())
|
||||||
return std::make_tuple<std::string_view, double>(compilerLocals.get('l')[i], locals.mLongs[i]);
|
return std::make_tuple<std::string_view, double>(compilerLocals.get('l')[i], locals.mLongs[i]);
|
||||||
i -= locals.mLongs.size();
|
i -= locals.mLongs.size();
|
||||||
if (i <= locals.mFloats.size())
|
if (i < locals.mFloats.size())
|
||||||
return std::make_tuple<std::string_view, double>(compilerLocals.get('f')[i], locals.mFloats[i]);
|
return std::make_tuple<std::string_view, double>(compilerLocals.get('f')[i], locals.mFloats[i]);
|
||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
});
|
});
|
||||||
|
@ -24,6 +24,7 @@ end
|
|||||||
local testModules = {
|
local testModules = {
|
||||||
'global_issues',
|
'global_issues',
|
||||||
'global_dialogues',
|
'global_dialogues',
|
||||||
|
'global_mwscript',
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
38
scripts/data/morrowind_tests/global_mwscript.lua
Normal file
38
scripts/data/morrowind_tests/global_mwscript.lua
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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 {
|
||||||
|
{'Should support iteration over script variables', function()
|
||||||
|
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)
|
||||||
|
|
||||||
|
local jiub = world.getObjectByFormId(core.getFormId('Morrowind.esm', 172867))
|
||||||
|
local jiubVars = world.mwscript.getLocalScript(jiub).variables
|
||||||
|
first, last, count = iterateOverVariables(jiubVars)
|
||||||
|
print(first, last, count)
|
||||||
|
testing.expectEqual(first, 'state')
|
||||||
|
testing.expectEqual(last, 'timer')
|
||||||
|
testing.expectEqual(count, 3)
|
||||||
|
testing.expectEqual(count, #jiubVars)
|
||||||
|
testing.expectEqual(jiubVars[1], jiubVars.state)
|
||||||
|
testing.expectEqual(jiubVars[2], jiubVars.wandering)
|
||||||
|
testing.expectEqual(jiubVars[3], jiubVars.timer)
|
||||||
|
end},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user