Jump to content

Module:Highest archive number/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 12:58, 2 October 2019 (add test cases for Module:Highest archive number). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Unit tests for [[Module:Highest archive number]]. Click on the talk page to
-- run the tests.

local han = require('Module:Highest archive number/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

-- Monkey patch mw.title.new
local existingPages = {}
mw.title.new = function(page)
	return {exists = existingPages[page] ~= nil}
end

function suite:testNoArchives()
	existingPages = {}
	self:assertEquals(han._main("Talk:Foo/Archive "), nil)
end

function suite:testArchivesStartingFromOne()
	existingPages = {
		["Talk:Foo/Archive 1"] = true,
		["Talk:Foo/Archive 2"] = true,
		["Talk:Foo/Archive 3"] = true,
		["Talk:Foo/Archive 4"] = true,
		["Talk:Foo/Archive 5"] = true,
	}
	self:assertEquals(han._main("Talk:Foo/Archive "), 5)
end

function suite:testArchivesStartingFromThreeWithCustomStart()
	existingPages = {
		["Talk:Foo/Archive 3"] = true,
		["Talk:Foo/Archive 4"] = true,
		["Talk:Foo/Archive 5"] = true,
	}
	self:assertEquals(han._main("Talk:Foo/Archive ", 3), 5)
end

function suite:testMain()
	existingPages = {
		["Talk:Foo/Archive 3"] = true,
		["Talk:Foo/Archive 4"] = true,
		["Talk:Foo/Archive 5"] = true,
	}
	self:assertEquals(han.main{"Talk:Foo/Archive ", start="3"}, 5)
end
	
return suite