Module:GetShortDescription/testcases: Difference between revisions

Content deleted Content added
another save for test
few fixes
 
(42 intermediate revisions by the same user not shown)
Line 1:
-- Unit tests for [[Module:{{ROOTPAGENAME}}GetShortDescription]]. Run all tests on the talk page.
-- Due to the changable nature of short descriptions; some of these tests may need to be updated before running them.
 
local p = require('Module:UnitTests')
Line 6:
--[[ empty params ]]
 
function p:no_name_paramtest__no_name_param()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes}}', "ERROR with invocation of'<span style="color:#d33">[[Module:GetShortDescription:]] requires a page name (including namespace).</span>[[Category:Pages MUSTdisplaying bealarming provided"messages about Module:GetShortDescription]]', {nowiki = 1})
end
 
function p:no_name_valuetest__no_name_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=}}', "ERROR with invocation of'<span style="color:#d33">[[Module:GetShortDescription:]] requires a page name (including namespace).</span>[[Category:Pages MUSTdisplaying bealarming provided"messages about Module:GetShortDescription]]', {nowiki = 1})
end
 
function p:no_only_valuetest__no_only_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/explicit short description|only=}}', "explicitExplicit short description")
end
 
function p:no_prefer_valuetest__no_prefer_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/explicit short description|prefer=}}', "explicitExplicit short description")
end
 
function p:no_fallback_valuetest__no_objectify_alarm_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/no explicit short descriptionyes|fallbackobjectify_alarm=}}', '<span style="color:#d33">[[Module:GetShortDescription]] requires a page name (including namespace).</span>[[Category:Pages displaying alarming messages about Module:GetShortDescription]]', {nowiki = 1})
end
 
--[[ nonenonexistent butpage name ]]
 
function p:explicit_exists__wikidata_does_not_existtest__nonexistent_page_name()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:FredIntentionally Gandt/sandbox/explicitpermanent shortred descriptionlink}}', "explicit short description"'')
end
 
--[[ unknown param offered ]]
function p:explicit_does_not_exist__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description}}', "")
function p:test__unknown_param_with_no_value_offered()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description|unknown=}}', "Explicit short description")
end
 
function p:explicit_exists__wikidata_existstest__unknown_param_with_value_offered()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=WikipediaTemplate:GetShortDescription/explicit short description|unknown=unknown}}', "Free multilingual, online,Explicit crowdsourcedshort encyclopediadescription")
end
 
--[[ unknown param found ]]
function p:explicit_does_not_exist__wikidata_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example}}', "Wikimedia disambiguation page")
function p:test__unknown_param_found()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description with unknown params}}', "Explicit short description with unknown params")
end
 
function p:test__complex_unknown_params_found()
--[[ name and only ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description with complex unknown params}}', "Explicit short description with complex unknown params")
end
 
--[[ multiple short descriptions ]]
 
--[[ temporarily disabled re other solution required
 
function p:test__two_short_descriptions_numbered_after()
function p:only_explicit__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/two explicit short description|only=explicitdescriptions numbered after}}', "explicitExplicit short description numbered second (used)")
end
 
function p:test__two_short_descriptions_numbered_before()
function p:only_wikidata__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/two explicit short description|only=wikidatadescriptions numbered before}}', "Explicit short description unnumbered second (used)")
end
 
]]
function p:only_explicit__explicit_does_not_exist__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|only=explicit}}', "")
function p:test__two_short_description_templates()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/two explicit short description templates}}', "Explicit short description second (used)")
end
 
function p:test__two_short_description_templates__first_noreplace()
function p:only_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred GandtGetShortDescription/sandbox/notwo explicit short description|only=wikidata templates first noreplace}}', "Explicit short description second (used)")
end
 
function p:test__two_short_description_templates__second_noreplace()
function p:only_explicit__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Wikipediayes|onlyname=Template:GetShortDescription/two explicit short description templates second noreplace}}', "FreeExplicit multilingual,short online,description crowdsourcedfirst encyclopedia(used)")
end
 
function p:test__three_short_description_templates__second_noreplace()
function p:only_wikidata__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Wikipediayes|onlyname=wikidataTemplate:GetShortDescription/three explicit short description templates second noreplace}}', "freeExplicit short multilingualdescription onlinethird encyclopedia(used)")
end
 
function p:test__three_short_description_templates__second_none__third_noreplace()
function p:only_explicit__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|onlyname=Template:GetShortDescription/three explicit short description templates second none third noreplace}}', "Explicit short description first (used)")
end
 
--[[ none but name ]]
function p:only_wikidata__explicit_does_not_exist__wikidata_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=wikidata}}', "Wikimedia disambiguation page")
function p:test__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description}}', "Explicit short description")
end
 
function p:test__explicit_does_not_exist__wikidata_does_not_exist()
--[[ name and prefer ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/no explicit short description}}', "")
end
 
function p:test__explicit_exists__wikidata_exists()
function p:prefer_explicit__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/explicit short descriptionyes|prefername=explicitWikipedia}}', "explicitFree online shortcrowdsourced descriptionencyclopedia")
end
 
function p:test__explicit_does_not_exist__wikidata_exists()
function p:prefer_wikidata__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/explicit short descriptionyes|prefername=wikidataExample}}', "explicitWikimedia shortdisambiguation descriptionpage")
end
 
--[[ name and only ]]
function p:prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|prefer=explicit}}', "")
function p:test__only_explicit__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description|only=explicit}}', "Explicit short description")
end
 
function p:test__only_wikidata__explicit_exists__wikidata_does_not_exist()
function p:prefer_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred GandtGetShortDescription/sandbox/no explicit short description|preferonly=wikidata}}', "")
end
 
function p:test__only_explicit__explicit_does_not_exist__wikidata_does_not_exist()
function p:prefer_explicit__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=WikipediaTemplate:GetShortDescription/no explicit short description|preferonly=explicit}}', "Free multilingual, online, crowdsourced encyclopedia")
end
 
function p:test__only_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
function p:prefer_wikidata__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=WikipediaTemplate:GetShortDescription/no explicit short description|preferonly=wikidata}}', "free multilingual online encyclopedia")
end
 
function p:test__only_explicit__explicit_exists__wikidata_exists()
function p:prefer_explicit__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleWikipedia|preferonly=explicit}}', "WikimediaFree online disambiguationcrowdsourced pageencyclopedia")
end
 
function p:test__only_wikidata__explicit_exists__wikidata_exists()
function p:prefer_wikidata__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleWikipedia|preferonly=wikidata}}', "Wikimediafree multilingual disambiguationonline pageencyclopedia")
end
 
function p:test__only_explicit__explicit_does_not_exist__wikidata_exists()
--[[ name and fallback ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|only=explicit}}', "")
end
 
function p:test__only_wikidata__explicit_does_not_exist__wikidata_exists()
function p:fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/explicit short descriptionExample|fallbackonly=fallbackwikidata}}', "explicitWikimedia shortdisambiguation descriptionpage")
end
 
--[[ name and prefer ]]
function p:fallback__explicit_does_not_exist__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|fallback=fallback}}', "fallback")
function p:test__prefer_explicit__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description|prefer=explicit}}', "Explicit short description")
end
 
function p:test__prefer_wikidata__explicit_exists__wikidata_does_not_exist()
function p:fallback__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=WikipediaTemplate:GetShortDescription/explicit short description|fallbackprefer=fallbackwikidata}}', "Free multilingual, online,Explicit crowdsourcedshort encyclopediadescription")
end
 
function p:test__prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
function p:fallback__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleTemplate:GetShortDescription/no explicit short description|fallbackprefer=fallbackexplicit}}', "Wikimedia disambiguation page")
end
 
function p:test__prefer_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
--[[ name, only and fallback ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/no explicit short description|prefer=wikidata}}', "")
end
 
function p:test__prefer_explicit__explicit_exists__wikidata_exists()
function p:only_explicit__fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/explicit short descriptionWikipedia|onlyprefer=explicit|fallback=fallback}}', "explicitFree online shortcrowdsourced descriptionencyclopedia")
end
 
function p:test__prefer_wikidata__explicit_exists__wikidata_exists()
function p:only_wikidata__fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/explicit short descriptionyes|onlyname=wikidataWikipedia|fallbackprefer=fallbackwikidata}}', "fallbackfree multilingual online encyclopedia")
end
 
function p:test__prefer_explicit__explicit_does_not_exist__wikidata_exists()
function p:only_explicit__fallback__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/no explicit short descriptionExample|onlyprefer=explicit|fallback=fallback}}', "fallbackWikimedia disambiguation page")
end
 
function p:test__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
function p:only_wikidata__fallback__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/no explicit short descriptionExample|onlyprefer=wikidata|fallback=fallback}}', "fallbackWikimedia disambiguation page")
end
 
--[[ conflicting params ]]
function p:only_explicit__fallback__explicit_exists__wikidata_exists()
--[[ only=explicit and prefer=wikidata ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=explicit|fallback=fallback}}', "Free multilingual, online, crowdsourced encyclopedia")
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description|only=explicit|prefer=wikidata}}', "Explicit short description")
end
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
function p:only_wikidata__fallback__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=WikipediaTemplate:GetShortDescription/no explicit short description|only=wikidataexplicit|fallbackprefer=fallbackwikidata}}', "free multilingual online encyclopedia")
end
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_exists__wikidata_exists()
function p:only_explicit__fallback__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleWikipedia|only=explicit|fallbackprefer=fallbackwikidata}}', "fallbackFree online crowdsourced encyclopedia")
end
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
function p:only_wikidata__fallback__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|only=wikidataexplicit|fallbackprefer=fallbackwikidata}}', "Wikimedia disambiguation page")
end
 
--[[ name, preferonly=wikidata and fallbackprefer=explicit ]]
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_does_not_exist()
function p:prefer_explicit__fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/explicit short description|only=wikidata|prefer=explicit|fallback=fallback}}', "explicit short description")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
function p:prefer_wikidata__fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:FredGetShortDescription/no Gandt/sandbox/explicit short description|preferonly=wikidata|fallbackprefer=fallbackexplicit}}', "explicit short description")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_exists()
function p:prefer_explicit__fallback__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/no explicit short descriptionWikipedia|preferonly=explicitwikidata|fallbackprefer=fallbackexplicit}}', "fallbackfree multilingual online encyclopedia")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_does_not_exist__wikidata_exists()
function p:prefer_wikidata__fallback__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=User:Fred Gandt/sandbox/no explicit short descriptionExample|preferonly=wikidata|fallbackprefer=fallbackexplicit}}', "fallbackWikimedia disambiguation page")
end
 
--[[ unusual explicit descriptions ]]
function p:prefer_explicit__fallback__explicit_exists__wikidata_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|prefer=explicit|fallback=fallback}}', "Free multilingual, online, crowdsourced encyclopedia")
function p:test__only_explicit__undefined()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description undefined|only=explicit}}', "")
end
 
function p:test__only_explicit__empty()
function p:prefer_wikidata__fallback__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Wikipediayes|prefername=wikidataTemplate:GetShortDescription/explicit short description empty|fallbackonly=fallbackexplicit}}', "free multilingual online encyclopedia")
end
 
function p:test__only_explicit__none()
function p:prefer_explicit__fallback__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=Template:GetShortDescription/explicit short description none|fallbackonly=fallbackexplicit}}', "Wikimedia disambiguation pagenone")
end
 
function p:test__only_explicit__numbered()
function p:prefer_wikidata__fallback__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=wikidataTemplate:GetShortDescription/explicit short description numbered|fallbackonly=fallbackexplicit}}', "WikimediaExplicit short disambiguationdescription pagenumbered")
end
 
function p:test__only_explicit__complex()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex|only=explicit}}', "Explicit short description complex")
end
 
function p:test__only_explicit__complex__numbered()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex numbered|only=explicit}}', "Explicit short description complex numbered")
end
 
function p:test__only_explicit__numbered__empty()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description numbered empty|only=explicit}}', "")
end
 
function p:test__only_explicit__numbered__none()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description numbered none|only=explicit}}', "none")
end
 
function p:test__only_explicit__complex__empty()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex empty|only=explicit}}', "")
end
 
function p:test__only_explicit__complex__none()
--[[ everything below here is being replaced ]]
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex none|only=explicit}}', "none")
 
function p:conflicting__only_explicit__prefer_wikidata__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=wikidata|only=explicit}}', "explicit short description")
end
 
function p:test__only_explicit__complex__numbered__empty()
function p:conflicting__only_wikidata__prefer_explicit__wikidata_exists__explicit_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=Template:GetShortDescription/explicit short description complex numbered empty|only=wikidataexplicit}}', "Wikimedia disambiguation page")
end
 
function p:test__only_explicit__complex__numbered__none()
function p:conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=wikidataTemplate:GetShortDescription/explicit short description complex numbered none|only=explicit}}', "none")
end
 
--[[ test the test; sanity check; should fail ]]
 
--function p:test__the_test()
-- self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example}}', "test the test")
--end
 
--[[ foreign language wikidata ]]
 
-- Testing |lang_italic= |lang_nocat= |lang_size= |lang_cat= |lang_rtl= |lang_no= will require a wikidata description in a language other than English to be returned