Jump to content

Module:GetShortDescription/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fred Gandt (talk | contribs) at 19:14, 26 January 2023 (all the unusual testcases?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module: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")
end

function p:no_name_value()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=}}', "ERROR with invocation of Module:GetShortDescription: a page name (including namespace) MUST be provided")
end

function p:no_only_value()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=}}', "explicit short description")
end

function p:no_prefer_value()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=}}', "explicit short description")
end

function p:no_fallback_value()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|fallback=}}', "")
end

--[[ none but name ]]

function p:explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description}}', "explicit short description")
end

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}}', "")
end

function p:explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example}}', "Wikimedia disambiguation page")
end

--[[ name and only ]]

function p:only_explicit__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=explicit}}', "explicit short description")
end

function p:only_wikidata__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=wikidata}}', "")
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}}', "")
end

function p:only_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|only=wikidata}}', "")
end

function p:only_explicit__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=explicit}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:only_wikidata__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=wikidata}}', "free multilingual online encyclopedia")
end

function p:only_explicit__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=explicit}}', "")
end

function p:only_wikidata__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=wikidata}}', "Wikimedia disambiguation page")
end

--[[ name and prefer ]]

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")
end

function p:prefer_wikidata__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=wikidata}}', "explicit short description")
end

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}}', "")
end

function p:prefer_wikidata__explicit_does_not_exist__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|prefer=wikidata}}', "")
end

function p:prefer_explicit__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|prefer=explicit}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:prefer_wikidata__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|prefer=wikidata}}', "free multilingual online encyclopedia")
end

function p:prefer_explicit__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|prefer=explicit}}', "Wikimedia disambiguation page")
end

function p:prefer_wikidata__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|prefer=wikidata}}', "Wikimedia disambiguation page")
end

--[[ name and fallback ]]

function p:fallback__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|fallback=fallback}}', "explicit short description")
end

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")
end

function p:fallback__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|fallback=fallback}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:fallback__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|fallback=fallback}}', "Wikimedia disambiguation page")
end

--[[ name, only and fallback ]]

function p:only_explicit__fallback__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=explicit|fallback=fallback}}', "explicit short description")
end

function p:only_wikidata__fallback__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=wikidata|fallback=fallback}}', "fallback")
end

function p:only_explicit__fallback__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|fallback=fallback}}', "fallback")
end

function p:only_wikidata__fallback__explicit_does_not_exist__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|only=wikidata|fallback=fallback}}', "fallback")
end

function p:only_explicit__fallback__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=explicit|fallback=fallback}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:only_wikidata__fallback__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=wikidata|fallback=fallback}}', "free multilingual online encyclopedia")
end

function p:only_explicit__fallback__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=explicit|fallback=fallback}}', "fallback")
end

function p:only_wikidata__fallback__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=wikidata|fallback=fallback}}', "Wikimedia disambiguation page")
end

--[[ name, prefer and fallback ]]

function p:prefer_explicit__fallback__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=explicit|fallback=fallback}}', "explicit short description")
end

function p:prefer_wikidata__fallback__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|prefer=wikidata|fallback=fallback}}', "explicit short description")
end

function p:prefer_explicit__fallback__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|fallback=fallback}}', "fallback")
end

function p:prefer_wikidata__fallback__explicit_does_not_exist__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/no explicit short description|prefer=wikidata|fallback=fallback}}', "fallback")
end

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")
end

function p:prefer_wikidata__fallback__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|prefer=wikidata|fallback=fallback}}', "free multilingual online encyclopedia")
end

function p:prefer_explicit__fallback__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|prefer=explicit|fallback=fallback}}', "Wikimedia disambiguation page")
end

function p:prefer_wikidata__fallback__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|prefer=wikidata|fallback=fallback}}', "Wikimedia disambiguation page")
end

--[[ conflicting params ]]

--[[ only=explicit and prefer=wikidata ]]

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|only=explicit|prefer=wikidata}}', "explicit short description")
end

function p:conflicting__only_explicit__prefer_wikidata__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|prefer=wikidata}}', "")
end

function p:conflicting__only_explicit__prefer_wikidata__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=explicit|prefer=wikidata}}', "Free multilingual, online, crowdsourced encyclopedia")
end

function p:conflicting__only_explicit__prefer_wikidata__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=explicit|prefer=wikidata}}', "")
end

--[[ only=wikidata and prefer=explicit ]]

function p:conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_does_not_exist()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description|only=wikidata|prefer=explicit}}', "")
end

function p:conflicting__only_wikidata__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|only=wikidata|prefer=explicit}}', "")
end

function p:conflicting__only_wikidata__prefer_explicit__explicit_exists__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Wikipedia|only=wikidata|prefer=explicit}}', "free multilingual online encyclopedia")
end

function p:conflicting__only_wikidata__prefer_explicit__explicit_does_not_exist__wikidata_exists()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=Example|only=wikidata|prefer=explicit}}', "Wikimedia disambiguation page")
end

--[[ unusual explicit descriptions ]]

function p:only_explicit__undefined()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description undefined|only=explicit}}', "")
end

function p:only_explicit__empty()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description empty|only=explicit}}', "")
end

function p:only_explicit__none()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description none|only=explicit}}', "")
end

function p:only_explicit__whitespace()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description whitespace|only=explicit}}', "")
end

function p:only_explicit__numbered()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description numbered|only=explicit}}', "explicit short description numbered")
end

function p:only_explicit__complex()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex|only=explicit}}', "explicit short description complex")
end

function p:only_explicit__complex__numbered()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/User:Fred Gandt/sandbox/explicit short description complex numbered|only=explicit}}', "explicit short description complex numbered")
end

function p:only_explicit__numbered__empty()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description numbered empty|only=explicit}}', "")
end

function p:only_explicit__numbered__none()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description numbered none|only=explicit}}', "")
end

function p:only_explicit__numbered__whitespace()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description numbered whitespace|only=explicit}}', "")
end

function p:only_explicit__complex__empty()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex empty|only=explicit}}', "")
end

function p:only_explicit__complex__none()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex none|only=explicit}}', "")
end

function p:only_explicit__complex__whitespace()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex whitespace|only=explicit}}', "")
end

function p:only_explicit__complex__numbered__empty()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex numbered empty|only=explicit}}', "")
end

function p:only_explicit__complex__numbered__none()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex numbered none|only=explicit}}', "")
end

function p:only_explicit__complex__numbered__whitespace()
	self:preprocess_equals('{{#invoke:GetShortDescription|main|name=User:Fred Gandt/sandbox/explicit short description complex numbered whitespace|only=explicit}}', "")
end

--[[ test the test ]]

--function p:test_the_test()
--	self:preprocess_equals('{{#invoke:GetShortDescription|main|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

return p