Split UTF-8 tests on chars and strings cases

This commit is contained in:
elsid 2024-06-22 02:46:38 +02:00
parent 5553b00b84
commit 1dd15613dd
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625

View file

@ -136,6 +136,7 @@ local function testRecordStores()
testRecordStore(types.NPC.races,"races") testRecordStore(types.NPC.races,"races")
testRecordStore(types.Player.birthSigns,"birthSigns") testRecordStore(types.Player.birthSigns,"birthSigns")
end end
local function testRecordCreation() local function testRecordCreation()
local newLight = { local newLight = {
isCarriable = true, isCarriable = true,
@ -160,9 +161,10 @@ local function testRecordCreation()
testing.expectEqual(record[key],value) testing.expectEqual(record[key],value)
end end
end end
local function testUTF8()
local utf8char = "😀" local function testUTF8Chars()
local utf8str = "Hello, 你好, 🌎!" testing.expectEqual(utf8.codepoint("😀"), 0x1F600)
local chars = {} local chars = {}
for codepoint = 0, 0x10FFFF do for codepoint = 0, 0x10FFFF do
@ -185,6 +187,10 @@ local function testUTF8()
testing.expectEqual(utf8.codepoint(char), codepoint) testing.expectEqual(utf8.codepoint(char), codepoint)
testing.expectEqual(utf8.len(char), 1) testing.expectEqual(utf8.len(char), 1)
end end
end
local function testUTF8Strings()
local utf8str = "Hello, 你好, 🌎!"
local str = "" local str = ""
for utf_char in utf8str:gmatch(utf8.charpattern) do for utf_char in utf8str:gmatch(utf8.charpattern) do
@ -192,10 +198,10 @@ local function testUTF8()
end end
testing.expectEqual(str, utf8str) testing.expectEqual(str, utf8str)
testing.expectEqual(utf8.codepoint(utf8char), 128512)
testing.expectEqual(utf8.len(utf8str), 13) testing.expectEqual(utf8.len(utf8str), 13)
testing.expectEqual(utf8.offset(utf8str, 9), 11) testing.expectEqual(utf8.offset(utf8str, 9), 11)
end end
local function initPlayer() local function initPlayer()
player:teleport('', util.vector3(4096, 4096, 867.237), util.transform.identity) player:teleport('', util.vector3(4096, 4096, 867.237), util.transform.identity)
coroutine.yield() coroutine.yield()
@ -243,7 +249,8 @@ tests = {
{'getGMST', testGetGMST}, {'getGMST', testGetGMST},
{'recordStores', testRecordStores}, {'recordStores', testRecordStores},
{'recordCreation', testRecordCreation}, {'recordCreation', testRecordCreation},
{'utf8', testUTF8}, {'utf8Chars', testUTF8Chars},
{'utf8Strings', testUTF8Strings},
{'mwscript', testMWScript}, {'mwscript', testMWScript},
} }