Module:Taxonavigation/sandbox/testcases
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Module:Taxonavigation/sandbox (talk · edit · hist · links · doc · subpages · tests / results · sandbox · all modules)
- Usage
- This module is a testcases of Module:Taxonavigation/sandbox
Code
-- Unit tests for [[Module:BiologyList/sandbox]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local module = 'Taxonavigation/sandbox'
-- Copy from here to Module:Taxonavigation/sandbox/testcases
function p:test_articleExists()
-- Test articleExists() - Standard cases
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_articleExists|Cinnamomum camphora}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_articleExists|Cinnamomum}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_articleExists|DoesNotExist}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_articleExists|}}', 'false') -- false is the default value
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_articleExists}}', 'false') -- false is the default value
end
function p:test_calcItalicTitle()
-- Test calcItalicTitle()
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_calcItalicTitle|Bombus (disamb)}}', mw.text.nowiki("Module_talk:''Bombus'' <small>(disamb)</small>"))
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_calcItalicTitle|Bombus (Psithyrus)}}', mw.text.nowiki("Module_talk:''Bombus'' <small>(Psithyrus)</small>"))
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_calcItalicTitle|genus (subgenus) species}}', mw.text.nowiki("Module_talk:''genus (subgenus) species''"))
end
function p:test_categoryExists()
-- Test categoryExists() - Standard cases
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|Cinnamomum camphora}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|Cinnamomum}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|DoesNotExist}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|Category:Cinnamomum camphora}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|Category:Cinnamomum}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|Category:DoesNotExist}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists|}}', 'false') -- false is the default value
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_categoryExists}}', 'false') -- false is the default value
end
function p:test_doesSingularLatinRankExist()
-- Test doesSingularLatinRankExist() - Standard cases true
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|genus}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|species}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|(unranked)}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|???}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|⇒}}', 'true')
-- Test doesSingularLatinRankExist() - Standard cases false
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|unranked}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|whatever}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|impossiblevalue}}', 'false')
-- Test doesSingularLatinRankExist() - Strange cases
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist|}}', 'false') -- false is the default value
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_doesSingularLatinRankExist}}', 'false') -- false is the default value
end
function p:test_findCurrentPageTaxonRank()
-- Test findCurrentPageTaxonRank()
self:preprocess_equals('{{#invoke:' .. module .. '|findCurrentPageTaxonRank|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Cinnamomum camphora}}', 'Species')
self:preprocess_equals('{{#invoke:' .. module .. '|findCurrentPageTaxonRank|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Cinnamomum}}', 'Genus')
self:preprocess_equals('{{#invoke:' .. module .. '|findCurrentPageTaxonRank|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Lauraceae}}', 'Familia')
self:preprocess_equals('{{#invoke:' .. module .. '|findCurrentPageTaxonRank|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=NotPresent}}', '')
end
function p:test_rankNeedsItalic()
-- Test rankNeedsItalic() - Standard cases true
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|genus}}', 'true')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|species}}', 'true')
-- Test rankNeedsItalic() - Standard cases false
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|familia}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|subfamilia}}', 'false')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|ordo}}', 'false')
-- Test rankNeedsItalic() - Strange cases
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|whatever}}', 'true') -- true is the default value
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic|}}', 'true') -- true is the default value
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_rankNeedsItalic}}', 'true') -- true is the default value
end
function p:test_serializeCurrentParameters()
-- Test serializeCurrentParameters()
self:preprocess_equals('{{#invoke:' .. module .. '|serializeCurrentParameters|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Cinnamomum camphora}}', '{"ordo":"Laurales","familia":"Lauraceae","species":"Cinnamomum camphora","CurrentPageTaxonRank":"Species","genus":"Cinnamomum"}')
self:preprocess_equals('{{#invoke:' .. module .. '|serializeCurrentParameters|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Cinnamomum}}', '{"ordo":"Laurales","familia":"Lauraceae","species":"Cinnamomum camphora","CurrentPageTaxonRank":"Genus","genus":"Cinnamomum"}')
self:preprocess_equals('{{#invoke:' .. module .. '|serializeCurrentParameters|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=Lauraceae}}', '{"ordo":"Laurales","familia":"Lauraceae","species":"Cinnamomum camphora","CurrentPageTaxonRank":"Familia","genus":"Cinnamomum"}')
self:preprocess_equals('{{#invoke:' .. module .. '|serializeCurrentParameters|Ordo|Laurales|Familia|Lauraceae|Genus|Cinnamomum|Species|Cinnamomum camphora|pagenameForDebug=NotPresent}}', '{"species":"Cinnamomum camphora","ordo":"Laurales","familia":"Lauraceae","genus":"Cinnamomum"}')
end
function p:test_stringTrim()
-- Test stringTrim() - Standard cases
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_stringTrim|string}}', 'string')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_stringTrim| string }}', 'string')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_stringTrim|}}', '')
self:preprocess_equals('{{#invoke:' .. module .. '|testcase_stringTrim}}', 'nil')
end
return p