Module:Biology/sandbox/testcases

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

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

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


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

Code

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

local module = 'Biology/sandbox'
function formatResult(result,debugtext)
	return mw.text.nowiki(result) .. '<BR/>Debug:<BR/>- Lang fr: ' .. mw.text.nowiki(debugtext)
end

-- Copy from here to Module:Biology/sandbox/testcases

--------------------------------------------------------------------------------
-------------------- String utilities ------------------------------------------
--------------------------------------------------------------------------------
function p:test_string_startsWith()
	-- Test string.startsWith() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|string=test|start=te}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|string=test|start=ta}}', 'false')
	-- Test string.startsWith() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|string=test|start=test}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|string=test|start=}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|string=test}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith|start=test}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_startsWith}}', 'false')
end

function p:test_string_endsWith()
	-- Test string.endsWith() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=t}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=st}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=est}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=to}}', 'false')
	-- Test string.endsWith() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=test}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test|end=}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|string=test}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith|end=}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_endsWith}}', 'false')
end

function p:test_string_contains()
	-- Test string.contains() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=longer|small=long}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=muchlonger|small=long}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=muchlong|small=long}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=long|small=long}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=long|small=muchlonger}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=long|small=small}}', 'false')
	-- Test string.contains() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|small=small}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_contains|long=long}}', 'false')
end

function p:test_string_upperFirstLowerOthers()
	-- Test string.upperFirstLowerOthers() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirstLowerOthers|tOTO}}', 'Toto')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirstLowerOthers|tOtO}}', 'Toto')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirstLowerOthers|t}}', 'T')
	-- Test string.upperFirstLowerOthers() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirstLowerOthers|}}', '')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirstLowerOthers}}', 'nil')
end

function p:test_string_upperFirst()
	-- Test string.upperFirst() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirst|tOtO}}', 'TOtO')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirst|TOtO}}', 'TOtO')
	-- Test string.upperFirst() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirst|}}', '')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_upperFirst}}', 'nil')
end

function p:test_string_isTrue()
	-- Test string.isTrue() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|whatever}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|0}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|no}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|nO}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|false}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|fAlSe}}', 'false')
	-- Test string.isTrue() - Limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isTrue|}}', 'false')
end

function p:test_string_trimOrNullify()
	-- Test string.trimOrNullify() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_trimOrNullify|whatever}}', 'whatever')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_trimOrNullify|a}}', 'a')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_trimOrNullify|}}', 'nil')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_trimOrNullify}}', 'nil')
end

function p:test_string_isNilOrEmpty()
	-- Test string.isNilOrEmpty() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isNilOrEmpty|whatever}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isNilOrEmpty|}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_string_isNilOrEmpty}}', 'true')
end

--------------------------------------------------------------------------------
-------------------- Namespace/articleName utilities ---------------------------
--------------------------------------------------------------------------------
function p:test_namespace_getCurrentNamespace()
	-- Test getCurrentNamespace() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|getCurrentNamespace}}', 'module_talk')
end

function p:test_namespace_isCurrentNamespaceACategory()
	-- Test isCurrentNamespaceACategory() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|isCurrentNamespaceACategory}}', 'false')
end

function p:test_namespace_isCurrentNamespaceACategoryOrAGallery()
	-- Test isCurrentNamespaceACategoryOrAGallery() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|isCurrentNamespaceACategoryOrAGallery}}', 'false')
end

function p:test_namespace_isCurrentNamespaceACategoryOrAGalleryOrATemplate()
	-- Test isCurrentNamespaceACategoryOrAGalleryOrATemplate() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|isCurrentNamespaceACategoryOrAGalleryOrATemplate}}', 'false')
end

function p:test_namespace_suppressCategory()
	-- Test suppressCategory() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressCategory|whatever}}', 'whatever')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressCategory|Category:whatever}}', 'whatever')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressCategory|category:whatever}}', 'whatever')
end

function p:test_namespace_suppressDisambiguation()
	-- Test suppressDisambiguation() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressDisambiguation|Platanthera (genus)}}', 'Platanthera')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressDisambiguation|Platanthera}}', 'Platanthera')
	-- Test suppressDisambiguation() - limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressDisambiguation|Platanthera (}}', 'Platanthera (')
	-- Test suppressDisambiguation() - limit cases - could be improved
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressDisambiguation|Platanthera(genus)}}', 'Platanthera')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_suppressDisambiguation|(Platanthera)}}', '')
end

function p:test_namespace_pageNameCorrespondToSpeciesOrInfraspecies()
	-- Test pageNameCorrespondToSpeciesOrInfraspecies() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Category:Pantera tigris}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Pantera tigris subsp. tigris}}', 'true')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Category:Phyllosasa}}', 'false')
	-- Test suppressDisambiguation() - limit cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Category:× Phyllosasa}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|× Phyllosasa}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Rosa nothosect. Cinnastylae}}', 'false')
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_pageNameCorrespondToSpeciesOrInfraspecies|Rosa subg. Cinnastylae}}', 'false')
end

--------------------------------------------------------------------------------
-------------------- Error utilities -------------------------------------------
--------------------------------------------------------------------------------
function p:test_error_pageNameCorrespondToSpeciesOrInfraspecies()
	-- Test incorrectBiologyTemplateUsage() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsage|Sortkey|errorToDisplay|templateNameForDoc|true}}',
		mw.text.nowiki(' [[Template:templateNameForDoc|<span class="error">Error: errorToDisplay</span>]] [[Category:Pages with incorrect biology template usage|Sortkey]] '))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsage|Sortkey|errorToDisplay|ignoreNamespaceOrNil=true}}',
		mw.text.nowiki(' [[:Category:Pages with incorrect biology template usage|<span class="error">Error: errorToDisplay</span>]] [[Category:Pages with incorrect biology template usage|Sortkey]] '))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsage|Sortkey|errorToDisplay|templateNameForDoc}}', '')
end

function p:test_error_incorrectBiologyTemplateUsageNoLink()
	-- Test incorrectBiologyTemplateUsageNoLink() - Standard cases
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsageNoLink|Sortkey|errorToDisplay|templateNameForDoc|true}}',
		mw.text.nowiki(' <span class="error">Error: errorToDisplay</span> [[Category:Pages with incorrect biology template usage|Sortkey]] '))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsageNoLink|Sortkey|errorToDisplay|ignoreNamespaceOrNil=true}}',
		mw.text.nowiki(' <span class="error">Error: errorToDisplay</span> [[Category:Pages with incorrect biology template usage|Sortkey]] '))
	self:preprocess_equals('{{#invoke:' .. module .. '|testcase_incorrectBiologyTemplateUsageNoLink|Sortkey|errorToDisplay|templateNameForDoc}}', '')
end

return p