Add unit tests

pull/3236/head
Evil Eye 6 months ago
parent 2adaf33fa2
commit 0f20e47e0e

@ -203,13 +203,13 @@ namespace MWLua
if (index >= size)
return sol::nullopt;
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]);
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]);
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 sol::nullopt;
});

@ -24,6 +24,7 @@ end
local testModules = {
'global_issues',
'global_dialogues',
'global_mwscript',
}
return {

@ -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…
Cancel
Save