Jump to content

Module:Bad title suggestion/testcases

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Dinoguy1000 (talk | contribs) at 01:47, 27 June 2025 (add a testcase that outputs both the "main" and the "substitute" DYM boxes; make an attempt to get testcases to pass (still doesn't work, idk)). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Unit tests for [[Module:Bad title suggestion]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_basic()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|>|Foobar&#62;}}', '<div class="mw-parser-output">{{Did you mean box|Foobar}}</div>')
end

function p:test_namespaced()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|}|Wikipedia:Village pump&#125;&#125;}}', '<div class="mw-parser-output">{{Did you mean box|Wikipedia:Village pump}}</div>')
end

function p:test_pipe()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|||Main Page&#124;title text}}', '<div class="mw-parser-output">{{Did you mean box|Main Page}}</div>')
end

function p:test_missing()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|>|This page absolutely does not exist&#62;}}', '')
end

function p:test_category()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|>|Category:Contents&#62;}}', '<div class="mw-parser-output">{{Did you mean box|Category:Contents}}</div>')
end

function p:test_first_invalid()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|<|&60;Foobar&#62;}}', '')
end

function p:test_main_and_substitute()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|>|M&#62;Train}}', '<div class="mw-parser-output">{{Did you mean box|M-Train}}{{Did you mean box|M}}</div>')
end

function p:test_empty()
	self:preprocess_equals_preprocess('{{#invoke:Bad title suggestion|main|>|}}', '')
end

return p