モジュール:サンドボックス/likibp/GraphemeSplitter/testcases
表示
これはモジュール「モジュール:サンドボックス/likibp/GraphemeSplitterのテストケースページです。テストケースの結果を参照してください。 |
--[[
This is the test code for GraphemeSplitter.
This code is a port of the original source found at:
https://github.com/taisukef/GraphemeSplitter/blob/master/GraphemeSplitterTest/TestStringExtensions.cs
The source code is licensed under the MIT license:
https://opensource.org/licenses/MIT
Note: This source code, when used on or obtained from a wiki site operated by the Wikimedia Foundation,
is additionally licensed under the Creative Commons Attribution-ShareAlike License:
https://creativecommons.org/licenses/by-sa/4.0/deed
--]]
local ScribuntoUnit = require('Module:ScribuntoUnit')
--local gsplit = require('Module:GraphemeSplitter')
local gsplit = require('モジュール:サンドボックス/likibp/GraphemeSplitter')
local suite = ScribuntoUnit:new()
--- Tests the functionality of the `GraphemeSplitter.split` method for splitting strings into grapheme clusters.
--- Firstly, it checks if each item in the `expectedGraphemes` list is indeed a single grapheme cluster.
--- Next, it splits the test string `inputString` and verifies the split results against the `expectedGraphemes` list.
---@param inputString string The test string to be split into grapheme clusters.
---@param ... string #expectedGraphemes table: A list of expected grapheme clusters after splitting the test string.
function suite:graphemesSplitTest(inputString, ...)
local expectedGraphemes = { ... }
for _, currentGrapheme in ipairs(expectedGraphemes) do
local splitResult = gsplit.split(currentGrapheme)
self:assertFalse((not splitResult) and (#splitResult ~= 1),
"The letter `" .. splitResult .. "` in expectedGraphemes is not a single Grapheme cluster.")
end
local actualGraphemes = gsplit.split(inputString)
self:assertEquals(#expectedGraphemes, #actualGraphemes,
"The number of elements in the `actualGraphemes` array (" ..
#actualGraphemes .. ") and the `actualGraphemes` array (" .. #expectedGraphemes .. ") is not identical.")
self:assertDeepEquals(expectedGraphemes, actualGraphemes,
"Mismatch detected: `actualGraphemes` is not the same as `actualGraphemes`.")
end
function suite:testGraphemesSingleUtf16()
self:graphemesSplitTest("aáαℵАあ亜", "a", "á", "α", "ℵ", "А", "あ", "亜")
end
function suite:testGraphemesSingleCodePoint()
self:graphemesSplitTest("🐭👩𩸽👪", "🐭", "👩", "𩸽", "👪")
end
function suite:testGraphemesCombining()
self:graphemesSplitTest("Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞",
"Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍", "A̴̵̜̰͔ͫ͗͢", "L̠ͨͧͩ͘", "G̴̻͈͍͔̹̑͗̎̅͛́",
"Ǫ̵̹̻̝̳͂̌̌͘", "!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞")
end
function suite:testGraphemesEmojiSkinTone()
self:graphemesSplitTest("👩🏻👩🏼👩🏽👩🏾👩🏿👨🏻👨🏼👨🏽👨🏾👨🏿", "👩🏻", "👩🏼",
"👩🏽", "👩🏾", "👩🏿", "👨🏻", "👨🏼", "👨🏽", "👨🏾", "👨🏿")
end
function suite:testGraphemesZwjEmoji()
self:graphemesSplitTest("👩👩👩👩👩👩👩👩👩👩👩👩👧👧👩👩👧👩👧",
"👩👩👩👩👩👩👩👩👩👩", "👩👩👧👧", "👩👩👧",
"👩👧")
end
function suite:testGraphemesZwjEmojiSkinTone()
self:graphemesSplitTest("👨🏽👨🏿👨🏿👩🏿👩🏾👩🏼👨🏼👨🏾👩🏿👩🏾👨🏽👩🏽👩🏾👩🏻👨🏿👨👨👧👦👩👩👧👦👨👨👧👦",
"👨🏽👨🏿👨🏿👩🏿👩🏾", "👩🏼👨🏼👨🏾👩🏿👩🏾",
"👨🏽👩🏽👩🏾👩🏻👨🏿", "👨👨👧👦", "👩👩👧👦",
"👨👨👧👦")
end
function suite:testGraphemesVariationSelector()
self:graphemesSplitTest("吉󠄀𠮟󠄀葛葛󠄀葛󠄁", "吉󠄀", "𠮟󠄀", "葛", "葛󠄀", "葛󠄁");
end
function suite:testGraphemesHangul()
self:graphemesSplitTest("안녕하세요", "안", "녕", "하", "세", "요");
end
return suite