local p = require "Module:UnitTests"local parse_IETF = require "Module:Sandbox/Erutuon".parse_IETFlocal fun = require "Module:Fun"
local show =
show.script = show.languageshow.region = show.languageshow.private_use = show.variant
local items = -- "invalid" is handled together with "error".
local mt = mt.__index = tablelocal function show_parsed_subtags(parsed_subtags) if not parsed_subtags then return 'nil' end local result = setmetatable(mt) for _, key in ipairs(items) do result:insert(show[key](parsed_subtags, key)) end return result:concat("; ")end
function p:test_parse_IETF local examples = local index = fun.indexOf("errors", examples) table.insert(examples, index, "case-insensitivity") for i = 1, index - 1 do -- Insert testcases for capitalized versions of the valid tags. local upper_example = mw.clone(examples[i]) upper_example[1] = upper_example[1]:upper table.insert(examples, index + i, upper_example) end self:iterate(examples, function (self, IETF_code, expected) self:equals(('%s
'):format(IETF_code), show_parsed_subtags(parse_IETF(IETF_code)), show_parsed_subtags(expected)) end)end
-- Change function names into more readable headers for the testcases tables.for k, v in require "Module:TableTools".sortedPairs(p) do if type(k)
%1
") if new_k ~= k then p[k] = nil p[new_k] = v end endendreturn p