1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-06 09:39:49 +00:00

Merge branch 'fix_lua_utf8_tests' into 'master'

Format Lua tests code and split UTF-8 tests

See merge request OpenMW/openmw!4197
This commit is contained in:
psi29a 2024-07-15 07:08:17 +00:00
commit 41f4c54cbc

View File

@ -29,7 +29,9 @@ local function testTimers()
ts2 = core.getSimulationTime() - startSimulationTime
end)
while not (ts1 and ts2 and th1 and th2) do coroutine.yield() end
while not (ts1 and ts2 and th1 and th2) do
coroutine.yield()
end
testing.expectGreaterOrEqual(th1, 36, 'async:newGameTimer failed')
testing.expectGreaterOrEqual(ts1, 0.5, 'async:newSimulationTimer failed')
@ -98,44 +100,47 @@ local function testMWScript()
testing.expectEqual(variableStoreCount, indexCheck)
end
local function testRecordStore(store,storeName,skipPairs)
local function testRecordStore(store, storeName, skipPairs)
testing.expect(store.records)
local firstRecord = store.records[1]
if not firstRecord then return end
testing.expectEqual(firstRecord.id,store.records[firstRecord.id].id)
if not firstRecord then
return
end
testing.expectEqual(firstRecord.id, store.records[firstRecord.id].id)
local status, _ = pcall(function()
for index, value in ipairs(store.records) do
if value.id == firstRecord.id then
testing.expectEqual(index,1,storeName)
testing.expectEqual(index, 1, storeName)
break
end
end
end)
testing.expectEqual(status,true,storeName)
testing.expectEqual(status, true, storeName)
end
local function testRecordStores()
for key, type in pairs(types) do
if type.records then
testRecordStore(type,key)
testRecordStore(type, key)
end
end
testRecordStore(core.magic.enchantments,"enchantments")
testRecordStore(core.magic.effects,"effects",true)
testRecordStore(core.magic.spells,"spells")
testRecordStore(core.magic.enchantments, "enchantments")
testRecordStore(core.magic.effects, "effects", true)
testRecordStore(core.magic.spells, "spells")
testRecordStore(core.stats.Attribute,"Attribute")
testRecordStore(core.stats.Skill,"Skill")
testRecordStore(core.stats.Attribute, "Attribute")
testRecordStore(core.stats.Skill, "Skill")
testRecordStore(core.sound,"sound")
testRecordStore(core.factions,"factions")
testRecordStore(core.sound, "sound")
testRecordStore(core.factions, "factions")
testRecordStore(types.NPC.classes,"classes")
testRecordStore(types.NPC.races,"races")
testRecordStore(types.Player.birthSigns,"birthSigns")
testRecordStore(types.NPC.classes, "classes")
testRecordStore(types.NPC.races, "races")
testRecordStore(types.Player.birthSigns, "birthSigns")
end
local function testRecordCreation()
local newLight = {
isCarriable = true,
@ -157,12 +162,13 @@ local function testRecordCreation()
local draft = types.Light.createRecordDraft(newLight)
local record = world.createRecord(draft)
for key, value in pairs(newLight) do
testing.expectEqual(record[key],value)
testing.expectEqual(record[key], value)
end
end
local function testUTF8()
local utf8char = "😀"
local utf8str = "Hello, 你好, 🌎!"
local function testUTF8Chars()
testing.expectEqual(utf8.codepoint("😀"), 0x1F600)
local chars = {}
for codepoint = 0, 0x10FFFF do
@ -185,6 +191,10 @@ local function testUTF8()
testing.expectEqual(utf8.codepoint(char), codepoint)
testing.expectEqual(utf8.len(char), 1)
end
end
local function testUTF8Strings()
local utf8str = "Hello, 你好, 🌎!"
local str = ""
for utf_char in utf8str:gmatch(utf8.charpattern) do
@ -192,10 +202,10 @@ local function testUTF8()
end
testing.expectEqual(str, utf8str)
testing.expectEqual(utf8.codepoint(utf8char), 128512)
testing.expectEqual(utf8.len(utf8str), 13)
testing.expectEqual(utf8.offset(utf8str, 9), 11)
end
local function initPlayer()
player:teleport('', util.vector3(4096, 4096, 867.237), util.transform.identity)
coroutine.yield()
@ -243,7 +253,8 @@ tests = {
{'getGMST', testGetGMST},
{'recordStores', testRecordStores},
{'recordCreation', testRecordCreation},
{'utf8', testUTF8},
{'utf8Chars', testUTF8Chars},
{'utf8Strings', testUTF8Strings},
{'mwscript', testMWScript},
}