local p = require "Module:UnitTests"local Unicode_data = require(mw.title.getCurrentTitle.subpageText
local U = mw.ustring.charlocal get_codepoint = mw.ustring.codepointlocal function show(codepoint) if Unicode_data.is_printable(codepoint) then local printed_codepoint = U(codepoint) if mw.ustring.toNFC(printed_codepoint) ~= printed_codepoint then printed_codepoint = ("%X;"):format(codepoint) end if Unicode_data.is_combining(codepoint) then printed_codepoint = "◌" .. printed_codepoint end return ("U+%04X: %s"):format(codepoint, printed_codepoint) else return ("U+%04X"):format(codepoint) endend
local function show_codepoint_and_name(codepoint) return ("%s (%s)"):format(show(codepoint), Unicode_data.lookup_name(codepoint))end
function p:test_lookup_name local examples = self:iterate(examples, function (self, codepoint, name) self:equals(show(codepoint), Unicode_data.lookup_name(codepoint), name) end)end
function p:test_lookup_age local examples = self:iterate(examples, function (self, codepoint, age) -- Remove pcall when this function is added to . pcall(function self:equals(show(codepoint), Unicode_data.lookup_age(codepoint), age) end) end)end
function p:test_is_combining local examples = self:iterate(examples, function (self, codepoint, expected) self:equals(show_codepoint_and_name(codepoint), Unicode_data.is_combining(codepoint), expected) end)end
function p:test_is_default_ignorable local examples = self:iterate(examples, function (self, codepoint, expected) -- Remove pcall when this function is added to . pcall(function self:equals(show_codepoint_and_name(codepoint), Unicode_data.is_default_ignorable(codepoint), expected) end) end)end
function p:test_lookup_script local examples = self:iterate(examples, function (self, codepoint, expected) self:equals(show_codepoint_and_name(codepoint), Unicode_data.lookup_script(codepoint), expected) end)end
function p:test_lookup_category local examples = self:iterate(examples, function (self, codepoint, expected) self:equals(show_codepoint_and_name(codepoint), Unicode_data.lookup_category(codepoint), expected) end)end
local fun = require "Module:Fun"local m_table = require "Module:TableTools"
local script_to_count_mt = setmetatable(script_to_count_mt, script_to_count_mt)
local script_counts = setmetatable
local script_examples =
local ends_in_punctuation = setmetatablelocal function show_script_example(script_example) local separator = ": " -- If last character is punctuation, place script counts on their own line -- Could use Unicode_data.lookup_category, but that is more memory-intensive. if ends_in_punctuation[script_example] then separator = "
• " end return script_example:gsub('\n', '
') .. separator .. script_counts[script_example]end
function p:test_get_best_script self:iterate(script_examples, function (self, str, expected) self:equals(show_script_example(str), Unicode_data.get_best_script(str), expected) end)end
function p:test_is_Latin self:iterate(script_examples, function (self, str, best_script, is_Latin) self:equals(show_script_example(str), Unicode_data.is_Latin(str), is_Latin or best_script
function p:test_lookup_block local examples = self:iterate(examples, function (self, codepoint, block_name) self:equals(show(codepoint), Unicode_data.lookup_block(codepoint), block_name) end)end
function p:test_is_rtl local examples = self:iterate(examples, function (self, str, expected) self:equals(str, Unicode_data.is_rtl(str), expected) end)end
-- Change function names into more readable headers for the testcases tables.for k, v in m_table.sortedPairs(p) do if type(k)
%1
") if new_k ~= k then p[k] = nil p[new_k] = v end endendreturn p