local unicode_tests = {
= { "uclc", "Ꞻ", "ꞻ" },
= { "uclc", "Ꟶ", "ꟶ" },
= { "uclc", "Ꟙ", "ꟙ" },
= { "pattern", "%a", "𑼅" },
= { "pattern", "%a", "" },
= { "uclc", "", "" },
}
local export = {}
local unpack = unpack or table.unpack -- Lua 5.2 compatibility
function test_version(v)
if v == "uclc" then
local u, l = select(2, unpack(v))
return mw.ustring.upper(l) == u and mw.ustring.lower(u) == l
elseif v == "pattern" then
local pat, m = select(2, unpack(v))
return mw.ustring.match(m, pat) ~= nil
else
error("unsupported test type " .. v)
end
end
function export.get_unicode_version()
local current = nil
for k, v in pairs(unicode_tests) do
if current == nil or k > current then
if test_version(v) then
current = k
end
end
end
return current
end
function export.main(frame)
local tests = require('Module:UnitTests')
local sorted_unicode_tests = {}
for k, v in pairs(unicode_tests) do
table.insert(sorted_unicode_tests, { k, unpack(v) })
end
table.sort(sorted_unicode_tests, function (a, b) return a < b end)
function tests:test_unicode_version()
for _, t in ipairs(sorted_unicode_tests) do
local version, testtype = unpack(t)
if testtype == "uclc" then
local uc, lc = select(3, unpack(t))
self:equals(
version .. " upper->lower",
mw.ustring.lower(uc),
lc
)
self:equals(
version .. " lower->upper",
mw.ustring.upper(lc),
uc
)
elseif testtype == "pattern" then
local pat, m = select(3, unpack(t))
self:equals(
version .. " pattern match",
mw.ustring.match(m, pat) or "",
m
)
end
end
end
return tests.run_tests(frame)
end
return export