Module:User:Surjection/unicodetest

Hello, you have come here looking for the meaning of the word Module:User:Surjection/unicodetest. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Surjection/unicodetest, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Surjection/unicodetest in singular and plural. Everything you need to know about the word Module:User:Surjection/unicodetest you have here. The definition of the word Module:User:Surjection/unicodetest will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Surjection/unicodetest, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


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