Jump to content

Module:Annotated link/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fred Gandt (talk | contribs) at 19:00, 27 January 2023 (more lang tests). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:AnnotatedLink]]. 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:test__no_name_param()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main}}', '<strong class="error">ERROR with invocation of [[Module:AnnotatedLink]]: a page name (including namespace) MUST be provided</strong>', { nowiki = 1 })
end

function p:test__no_name_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=}}', '<strong class="error">ERROR with invocation of [[Module:AnnotatedLink]]: a page name (including namespace) MUST be provided</strong>', { nowiki = 1 })
end

function p:test__no_display_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|display=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_quote_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|quote=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_abbr_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_abbr_value__abbr_title()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=|abbr_title=Abbreviation}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_abbr__no_abbr_title_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=|abbr_title=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_aka_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|aka=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_wedge_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|wedge=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_dash_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|dash=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_desc_first_letter_case_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|desc_first_letter_case=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__no_link_lang_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|link_lang=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

-- tests for empty |link_lang_italic= |link_lang_nocat= |link_lang_size= |link_lang_cat= |link_lang_rtl= ?

function p:test__no_aka_lang_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|aka_lang=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

-- tests for empty |aka_lang_italic= |aka_lang_nocat= |aka_lang_size= |aka_lang_cat= |aka_lang_rtl= ?

function p:test__no_wedge_lang_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|wedge_lang=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

-- tests for empty |wedge_lang_italic= |wedge_lang_nocat= |wedge_lang_size= |wedge_lang_cat= |wedge_lang_rtl= ?

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

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

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

--[[ unknown param ]]

function p:test__no_unknown_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|unknown=}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

function p:test__unknown_value()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|unknown=unknown}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

--[[ none but name ]]

function p:test__short_description_exists()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] – explicit short description")
end

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

--[[ name and display ]]

function p:test__display__short_description_exists()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|display=Test page}}', "[[:User:Fred Gandt/sandbox/explicit short description|Test page]] – explicit short description")
end

function p:test__display__short_description_does_not_exist()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|display=Test page}}', "[[:User:Fred Gandt/sandbox/no explicit short description|Test page]]")
end

--[[ name and quote ]]

function p:test__quote__short_description_exists()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|quote=yes}}', '"[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]]" – explicit short description')
end

function p:test__quote__short_description_does_not_exist()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|quote=yes}}', '"[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]]"')
end

--[[ name and abbr ]]

function p:test__abbr__short_description_exists()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=ESD}}', '[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] (<abbr>ESD</abbr>) – explicit short description', { nowiki = 1 })
end

function p:test__abbr__short_description_does_not_exist()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|abbr=NESD}}', '[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]] (<abbr>NESD</abbr>)', { nowiki = 1 })
end

--[[ name, abbr and abbr_title ]]

function p:test__abbr__abbr_title__short_description_exists()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=ESD|abbr_title=Explicit Short Description}}', '[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] (<abbr title="Explicit Short Description">ESD</abbr>) – explicit short description', { nowiki = 1 })
end

function p:test__abbr__abbr_title__short_description_does_not_exist()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|abbr=NESD|abbr_title=No Explicit Short Description}}', '[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]] (<abbr title="No Explicit Short Description">NESD</abbr>)', { nowiki = 1 })
end

--[[ name and aka ]]

function p:test__aka__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|aka=Fred's test page}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]], also known as Fred's test page – explicit short description")
end

function p:test__aka__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|aka=Fred's test page}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]], also known as Fred's test page")
end

--[[ name and wedge ]]

function p:test__wedge__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]], [[Tight Fit]] – explicit short description")
end

function p:test__wedge__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]], [[Tight Fit]]")
end

--[[ name, abbr and aka ]]

function p:test__abbr__aka__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=ESD|aka=Fred's test page}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] (<abbr>ESD</abbr>), also known as Fred's test page – explicit short description", { nowiki = 1 })
end

function p:test__abbr__aka__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|abbr=NESD|aka=Fred's test page}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]] (<abbr>NESD</abbr>), also known as Fred's test page", { nowiki = 1 })
end

--[[ name, abbr and wedge ]]

function p:test__abbr__wedge__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=ESD|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] (<abbr>ESD</abbr>), [[Tight Fit]] – explicit short description", { nowiki = 1 })
end

function p:test__abbr__wedge__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|abbr=NESD|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]] (<abbr>NESD</abbr>), [[Tight Fit]]", { nowiki = 1 })
end

--[[ name, abbr, aka and wedge ]]

function p:test__abbr__aka__wedge__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|abbr=ESD|aka=Fred's test page|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]] (<abbr>ESD</abbr>), also known as Fred's test page, [[Tight Fit]] – explicit short description", { nowiki = 1 })
end

function p:test__abbr__aka__wedge__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|abbr=NESD|aka=Fred's test page|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]] (<abbr>NESD</abbr>), also known as Fred's test page, [[Tight Fit]]", { nowiki = 1 })
end

--[[ name, aka and wedge ]]

function p:test__aka__wedge__short_description_exists()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/explicit short description|aka=Fred's test page|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]], also known as Fred's test page, [[Tight Fit]] – explicit short description")
end

function p:test__aka__wedge__short_description_does_not_exist()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|aka=Fred's test page|wedge=[[Tight Fit]]}}", "[[:User:Fred Gandt/sandbox/no explicit short description|User:Fred Gandt/sandbox/no explicit short description]], also known as Fred's test page, [[Tight Fit]]")
end

-- lang tests are not examples of proper usage; we're just testing the functionality

--[[ name and link_lang ]]

function p:test__link_lang_en()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|link_lang=en}}', "[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]]")
end

function p:test__link_lang_fr()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|link_lang=fr}}', '<span title="French-language text"><i lang="fr">[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]]</i></span>', { nowiki = 1 })
end

--[[ name, display and link_lang ]]

function p:test__display__link_lang_fr()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|display=Test page|link_lang=fr}}', '<span title="French-language text"><i lang="fr">[[:User:Fred Gandt/sandbox/explicit short description|Test page]]</i></span>', { nowiki = 1 })
end

--[[ name, quote and link_lang ]]

function p:test__quote__link_lang_fr()
	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|quote=yes|link_lang=fr}}', '"<span title="French-language text"><i lang="fr">[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]]</i></span>"', { nowiki = 1 })
end

--[[ name, aka and aka_lang ]]

function p:test__aka__aka_lang_ja()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|aka=フレッドのテストページ|aka_lang=ja}}", '[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]], also known as <span title="Japanese-language text"><i lang="ja">フレッドのテストページ</i></span>', { nowiki = 1 })
end

--[[ name, wedge and wedge_lang ]]

function p:test__wedge__wedge_lang_ja()
	self:preprocess_equals("{{#invoke:AnnotatedLink|main|name=User:Fred Gandt/sandbox/no explicit short description|wedge=フレッドのテストページ|wedge_lang=ja}}", '[[:User:Fred Gandt/sandbox/explicit short description|User:Fred Gandt/sandbox/explicit short description]], <span title="Japanese-language text"><i lang="ja">フレッドのテストページ</i></span>', { nowiki = 1 })
end



--[[

|name= |display= |quote= |abbr= |abbr_title= |aka= |wedge= |dash= |desc_first_letter_case=

|link_lang= |link_lang_italic= |link_lang_nocat= |link_lang_size= |link_lang_cat= |link_lang_rtl=

|aka_lang= |aka_lang_italic= |aka_lang_nocat= |aka_lang_size= |aka_lang_cat= |aka_lang_rtl=

|wedge_lang= |wedge_lang_italic= |wedge_lang_nocat= |wedge_lang_size= |wedge_lang_cat= |wedge_lang_rtl=

|only= |prefer= |fallback=

|desc_lang_italic= |desc_lang_nocat= |desc_lang_size= |desc_lang_cat= |desc_lang_rtl= |desc_lang_no=

]]

--[[ test the test; sanity check; should fail ]]

--function p:test_the_test()
--	self:preprocess_equals('{{#invoke:AnnotatedLink|main|name=Example}}', "test the test")
--end

return p