local tests = require("Module:UnitTests")
local languages = require("Module:languages/cache")
local format_categories = require("Module:utilities").format_categories
local currentTitle
local function specialGetCurrentTitle()
return currentTitle
end
function tests:test_format_categories()
local examples = {
{ "English lemmas", "en", "cliché", "[[Category:English lemmas|CLICHE]]" },
{ "English lemmas", "en", "Reconstruction:Proto-Indo-European/dn̥ǵʰwéh₂s", "[[Category:English lemmas|DN̥ǴʰWEH₂S]]" },
{ "English lemmas", "en", "Appendix:English doublets", "[[Category:English lemmas|ENGLISH DOUBLETS]]" },
{ "English lemmas", "en", "Citations:word", "[[Category:English lemmas|WORD]]" },
{ "English lemmas", "en", "Wiktionary:Grease pit", "" },
}
local actualGetCurrentTitle = mw.title.getCurrentTitle
mw.title.getCurrentTitle = specialGetCurrentTitle
local options = { display = mw.text.nowiki }
self:iterate(examples,
function (self, category, lang, title, expected)
currentTitle = mw.title.new(title)
self:equals(
category .. " (" .. lang .. ", [[" .. title .. "]])",
format_categories({ category }, languages[lang]),
expected,
options)
end)
mw.title.getCurrentTitle = actualGetCurrentTitle
end
return tests