Module:GetShortDescription/testcases: Difference between revisions

Content deleted Content added
saving in incomplete state due to need to shut computer down
few fixes
 
(44 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')
 
--[[ empty params ]]
function p:no_name_param()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main}}', "ERROR with invocation of Module:GetShortDescription: a page name (including namespace) MUST be provided")
function p:test__no_name_param()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes}}', '<span style="color:#d33">[[Module:GetShortDescription]] requires a page name (including namespace).</span>[[Category:Pages displaying alarming 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:explicit_existstest__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:explicit_does_not_exist__wikidata_existstest__no_prefer_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleTemplate:GetShortDescription/explicit short description|prefer=}}', "WikimediaExplicit disambiguationshort pagedescription")
end
 
function p:explicit_does_not_exist__wikidata_does_not_existtest__no_objectify_alarm_value()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Useryes|objectify_alarm=}}', '<span style="color:#d33">[[Module:FredGetShortDescription]] Gandt/sandboxrequires a page name (including namespace).</nospan>[[Category:Pages explicitdisplaying shortalarming description}}messages about Module:GetShortDescription]]', ""{nowiki = 1})
end
 
--[[ nonexistent page name ]]
function p:only_explicit__explicit_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=explicit}}', "explicit short description")
function p:test__nonexistent_page_name()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Intentionally permanent red link}}', '')
end
 
--[[ unknown param offered ]]
function p:only_explict__explicit_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|only=explicit}}', "")
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:only_wikidata__wikidata_existstest__unknown_param_with_value_offered()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleTemplate:GetShortDescription/explicit short description|onlyunknown=wikidataunknown}}', "WikimediaExplicit disambiguationshort pagedescription")
end
 
--[[ unknown param found ]]
function p:only_wikidata__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=wikidata}}', "")
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:prefer_explicit__explicit_exists__wikidata_existstest__complex_unknown_params_found()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Wikipediayes|prefername=Template:GetShortDescription/explicit short description with complex unknown params}}', "FreeExplicit multilingual,short online,description with complex crowdsourcedunknown encyclopediaparams")
end
 
--[[ multiple short descriptions ]]
function p:prefer_explicit__explicit_exists__wikidata_does_not_exist()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=explicit}}', "explicit short description")
--[[ temporarily disabled re other solution required
 
function p:test__two_short_descriptions_numbered_after()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/two explicit short descriptions numbered after}}', "Explicit short description numbered second (used)")
end
 
function p:test__two_short_descriptions_numbered_before()
function p:prefer_explicit__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=Template:GetShortDescription/two explicit short descriptions numbered before}}', "WikimediaExplicit short description unnumbered disambiguationsecond page(used)")
end
 
]]
function p:prefer_wikidata__wikidata_exists__explicit_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|prefer=wikidata}}', "Free multilingual, online, crowdsourced encyclopedia")
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:prefer_wikidata__wikidata_exists__explicit_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=wikidataTemplate:GetShortDescription/two explicit short description templates first noreplace}}', "WikimediaExplicit short description disambiguationsecond page(used)")
end
 
function p:test__two_short_description_templates__second_noreplace()
------------------------
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/two explicit short description templates second noreplace}}', "Explicit short description first (used)")
end
 
function p:test__three_short_description_templates__second_noreplace()
function p:fallback__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/three explicit short description templates second noreplace}}', "explicitExplicit short description third (used)")
end
 
function p:test__three_short_description_templates__second_none__third_noreplace()
function p:fallback__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/three explicit short description templates second none third noreplace}}', "explicitExplicit short description first (used)")
end
 
--[[ none but name ]]
function p:fallback__explicit_does_not_exist__wikidata_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example}}', "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()
function p:fallback__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/no explicit short description}}', "")
end
 
function p:only_explicit__fallback__explicit_existstest__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/explicit short descriptionyes|onlyname=explicitWikipedia}}', "explicitFree online shortcrowdsourced descriptionencyclopedia")
end
 
function p:only_explict__fallback__explicit_does_not_existtest__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=User:Fred Gandt/sandbox/no explicit short descriptionyes|onlyname=explicitExample}}', "Wikimedia disambiguation page")
end
 
--[[ name and only ]]
function p:only_wikidata__fallback__wikidata_exists()
 
self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=wikidata}}', "Wikimedia disambiguation page")
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:only_wikidata__fallback__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=UserTemplate:Fred Gandt/sandboxGetShortDescription/explicit short description|only=wikidata}}', "")
end
 
function p:test__only_explicit__explicit_does_not_exist__wikidata_does_not_exist()
function p:prefer_explicit__fallback__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_explicit__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=explicitwikidata}}', "explicit short description")
end
 
function p:test__only_explicit__explicit_exists__wikidata_exists()
function p:prefer_explicit__fallback__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__fallback__wikidata_exists__explicit_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Wikipedia|preferonly=wikidata}}', "Freefree multilingual, online, crowdsourced encyclopedia")
end
 
function p:test__only_explicit__explicit_does_not_exist__wikidata_exists()
function p:prefer_wikidata__fallback__wikidata_exists__explicit_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|preferonly=wikidataexplicit}}', "Wikimedia disambiguation page")
end
 
function p:test__only_wikidata__explicit_does_not_exist__wikidata_exists()
------------------------
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|only=wikidata}}', "Wikimedia disambiguation page")
end
 
--[[ name and prefer ]]
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")
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: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|onlyprefer=wikidata}}', "WikimediaExplicit disambiguationshort pagedescription")
end
 
function p:test__prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
function p:conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|namestringify=Exampleyes|prefername=wikidataTemplate:GetShortDescription/no explicit short description|onlyprefer=explicit}}', "")
end
 
function p:test__prefer_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
--[[ we would need something on Wikidata with no description to test these
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:prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleWikipedia|prefer=explicit}}', "Free online crowdsourced encyclopedia")
end
 
function p:test__prefer_wikidata__explicit_exists__wikidata_exists()
function p:prefer_wikidata__wikidata_does_not_exist__explicit_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=ExampleWikipedia|prefer=wikidata}}', "free multilingual online encyclopedia")
end
 
function p:test__prefer_explicit__explicit_does_not_exist__wikidata_exists()
function p:prefer_wikidata__wikidata_does_not_exist__explicit_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|prefer=wikidataexplicit}}', "Wikimedia disambiguation page")
end
 
function p:test__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
function p:conflicting__only_wikidata__prefer_explicit__wikidata_does_not_exist__explicit_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|prefer=explicit|only=wikidata}}', "Wikimedia disambiguation page")
end
 
--[[ conflicting params ]]
]]
--[[ only=explicit and prefer=wikidata ]]
 
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()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/no explicit short description|only=explicit|prefer=wikidata}}', "")
end
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Wikipedia|only=explicit|prefer=wikidata}}', "Free online crowdsourced encyclopedia")
end
 
function p:test__conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|only=explicit|prefer=wikidata}}', "")
end
 
--[[ only=wikidata and prefer=explicit ]]
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description|only=wikidata|prefer=explicit}}', "")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_does_not_exist__wikidata_does_not_exist()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/no explicit short description|only=wikidata|prefer=explicit}}', "")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Wikipedia|only=wikidata|prefer=explicit}}', "free multilingual online encyclopedia")
end
 
function p:test__conflicting__only_wikidata__prefer_explicit__explicit_does_not_exist__wikidata_exists()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Example|only=wikidata|prefer=explicit}}', "Wikimedia disambiguation page")
end
 
--[[ unusual explicit descriptions ]]
 
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()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description empty|only=explicit}}', "")
end
 
function p:test__only_explicit__none()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description none|only=explicit}}', "none")
end
 
function p:test__only_explicit__numbered()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description numbered|only=explicit}}', "Explicit short description numbered")
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()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex none|only=explicit}}', "none")
end
 
function p:test__only_explicit__complex__numbered__empty()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template:GetShortDescription/explicit short description complex numbered empty|only=explicit}}', "")
end
 
function p:test__only_explicit__complex__numbered__none()
self:preprocess_equals('{{#invoke:GetShortDescription|main|stringify=yes|name=Template: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