Jump to content

Module:Sensitive IP addresses/blocktext/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 08:05, 8 October 2018 (put expected values first). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:Sensitive IP addresses/blocktext]]

local mBlockText = require('Module:Sensitive IP addresses/blocktext')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local mBlockTextFunctions = mBlockText._exportFunctions()
local parseTitle = mBlockTextFunctions.parseTitle

function suite:test_parse_special_block_with_ipv4_address()
	self:assertEquals(
		'1.2.3.4',
		parseTitle(mw.title.new('Special:Block/1.2.3.4'))
	)
end

function suite:test_parse_special_block_with_ipv4_range()
	self:assertEquals(
		'1.2.3.0/24',
		parseTitle(mw.title.new('Special:Block/1.2.3.0/24'))
	)
end

function suite:test_parse_special_block_with_ipv6_address()
	self:assertEquals(
		'2001:db8::ff00:12:3456',
		parseTitle(mw.title.new('Special:Block/2001:db8::ff00:12:3456'))
	)
end

function suite:test_parse_special_block_with_ipv6_range()
	self:assertEquals(
		'2001:db8::ff00:12:0/122',
		parseTitle(mw.title.new('Special:Block/2001:db8::ff00:12:0/122'))
	)
end

function suite:test_parse_special_block_with_username()
	self:assertEquals(
		nil,
		parseTitle(mw.title.new('Special:Block/Example'))
	)
end

return suite