Module:BiologyList/sandbox/testcases

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Module:BiologyList/sandbox (talk · edit · hist · links · doc · subpages · tests / results · sandbox · all modules)


Usage
This module is a testcases of Module:BiologyList/sandbox

Code

-- Unit tests for [[Module:BiologyList/sandbox]]. Click talk page to run tests.
local p = require('Module:UnitTests')

local module = 'BiologyList/sandbox'
local currentPage = 'BiologyList%2Fsandbox%2Ftestcases'
function formatResult(result, debugfunction, debugtext)
	return mw.text.nowiki(result) .. 'Debug: ' .. debugfunction .. ': ' .. mw.text.nowiki(debugtext) .. '<BR/>'
end

-- Copy from here to Module:BiologyList/sandbox/testcases
function p:test_checkDate()
	-- Test checkDate() - OK cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2015-1-1}}',
		formatResult('', 'checkDate', 'Perfect date: year=2015 month=1 day=1'))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2012-12-31}}',
		formatResult('', 'checkDate', 'Perfect date: year=2012 month=12 day=31'))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|1900-12-31}}', '')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2012-15-31}}', '')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2012-12-33}}', '')
	-- Test checkDate() - ERROR cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|Badformat|ignoreNamespace=true}}',
		mw.text.nowiki(" [[Template:Taxa|<span class=\"error\">Error: Incorrect date Badformat. Format: 'YYYY-MM-DD' like '2012-12-31'</span>]] [[Category:Pages with incorrect biology template usage|Date]] "))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|1900-12-31|ignoreNamespace=true}}',
		mw.text.nowiki(" [[Template:Taxa|<span class=\"error\">Error: Incorrect year 1900 in date 1900-12-31. Format: 'YYYY-MM-DD' like '2012-12-31'</span>]] [[Category:Pages with incorrect biology template usage|Date]] "))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2012-15-31|ignoreNamespace=true}}',
		mw.text.nowiki(" [[Template:Taxa|<span class=\"error\">Error: Incorrect month 15 in date 2012-15-31. Format: 'YYYY-MM-DD' like '2012-12-31'</span>]] [[Category:Pages with incorrect biology template usage|Date]] "))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_checkDate|templateNameForDoc=Taxa|2012-12-33|ignoreNamespace=true}}',
		mw.text.nowiki(" [[Template:Taxa|<span class=\"error\">Error: Incorrect day 33 in date 2012-12-33. Format: 'YYYY-MM-DD' like '2012-12-31'</span>]] [[Category:Pages with incorrect biology template usage|Date]] "))
end

function p:test_formatList()
	-- Test formatList()
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|italic=yes|aaa|bbb}}',   			mw.text.nowiki("<i>[[:Category:aaa|aaa]], [[:Category:bbb|bbb]]</i>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|italic=yes|aaa†|†bbb}}', 			mw.text.nowiki("<i></i>†<i>[[:Category:aaa|aaa]], </i>†<i>[[:Category:bbb|bbb]]</i>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|aaa|bbb|bbb=(disamb)}}',     mw.text.nowiki("aaa, bbb<small> (disamb)</small>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|aaa|bbb|bbb=bbb (disamb)}}', mw.text.nowiki("aaa, bbb<small> (disamb)</small>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|aaa|Viola|Viola=(Violaceae)}}', mw.text.nowiki("aaa, Viola<small> (Violaceae)</small>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|aaa|Viola|Viola=Viola (Violaceae)}}', mw.text.nowiki("aaa, Viola<small> (Violaceae)</small>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|aaa|bbb (disamb)}}',         mw.text.nowiki("aaa, bbb<small> (disamb)</small>"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|nameprefix=pref|displayprefix=dpref|aaa†|†bbb (disamb)}}', mw.text.nowiki("†[[:Category:pref aaa|dpref aaa]], †[[:Category:pref bbb (disamb)|dpref bbb<small> (disamb)</small>]]"))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_formatList|link=no|nameprefix=pref|displayprefix=dpref|aaa†|†bbb (disamb)}}', mw.text.nowiki("†dpref aaa, †dpref bbb<small> (disamb)</small>"))
end

function p:test_getSourceLink()
	-- Test getSourceLink() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getSourceLink|animalbase|whocares}}', 	 mw.text.nowiki('[http://www.animalbase.uni-goettingen.de/zooweb/servlet/AnimalBase/search AnimalBase]'))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getSourceLink|adw|myTaxon with spaces}}', mw.text.nowiki('[http://animaldiversity.ummz.umich.edu/site/search?category=Classification&SearchableText=myTaxon+with+spaces Animal Diversity Web (ADW)]'))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getSourceLink|adw}}', 					 mw.text.nowiki('[http://animaldiversity.ummz.umich.edu/site/search?category=Classification&SearchableText=' .. currentPage .. ' Animal Diversity Web (ADW)]'))
end

function p:test_getSourceLinks()
	-- Test getSourceLinks() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getSourceLinks|animalbase & adw|whocares}}', formatResult('[http://animaldiversity.ummz.umich.edu/site/search?category=Classification&SearchableText=' .. currentPage .. ' Animal Diversity Web (ADW)]&nbsp;&&nbsp;[http://www.animalbase.uni-goettingen.de/zooweb/servlet/AnimalBase/search AnimalBase]&nbsp;&&nbsp;whocares', 'getSourceLink', "Unknown source 'whocares'"))
end

function p:test_getTaxonNameOutOfTitle()
	-- Test testcase_getTaxonNameOutOfTitle() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getTaxonNameOutOfTitle|Canistrum (Bromeliaceae)}}',   'Canistrum')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getTaxonNameOutOfTitle|Genera of Bromeliaceae}}',     'Bromeliaceae')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getTaxonNameOutOfTitle|Subtribes of Bromeliaceae}}',  'Bromeliaceae')
	-- Test testcase_getTaxonNameOutOfTitle() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getTaxonNameOutOfTitle| Canistrum (Bromeliaceae) }}', 'Canistrum')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_getTaxonNameOutOfTitle| Canistrum(Bromeliaceae) }}',  'Canistrum')
end

function p:test_suppressNothospeciesX()
	-- Test suppressNothospeciesX() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|suppressNothospeciesX|Cattleya × ballantiniana}}',   'Cattleya ballantiniana')
	self:preprocess_equals('{{#invoke:' .. module .. '|suppressNothospeciesX|Cattleya ×ballantiniana}}',   'Cattleya ballantiniana')
	self:preprocess_equals('{{#invoke:' .. module .. '|suppressNothospeciesX|Cattleya×ballantiniana}}',   'Cattleya ballantiniana')
	-- Test suppressNothospeciesX() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|suppressNothospeciesX|Whatever whatever}}',   'Whatever whatever')
	self:preprocess_equals('{{#invoke:' .. module .. '|suppressNothospeciesX}}',   '')
end

function p:test_isEmptyOrNumeric()
	-- Test isEmptyOrNumeric() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|isEmptyOrNumeric}}',   	'1')
	self:preprocess_equals('{{#invoke:' .. module .. '|isEmptyOrNumeric|}}',   	'1')
	self:preprocess_equals('{{#invoke:' .. module .. '|isEmptyOrNumeric|2015}}', '1')
	self:preprocess_equals('{{#invoke:' .. module .. '|isEmptyOrNumeric|tata}}', '')
end

return p