Jump to content

Module:Official website/testcases

From Wikipedia, the free encyclopedia
local p = require('Module:UnitTests')


function p:test_module()
	self:preprocess_equals_many('{{#invoke:Official website|main | ', ' }}', {
		{
		'example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'//example.com',
		'<span class="official-website"><span class="url">[//example.com Official website]</span></span>'
		},
		{
		'',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'www.example.com/path?section=96',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'1= www.example.com/path?section=96',
		'<span class="official-website"><span class="url">[http://www.example.com/path?section=96 Official website]</span></span>'
		},
		{
		'url= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'URL= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http:/example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com/',
		'<span class="official-website"><span class="url">[http://example.com/ Official website]</span></span>'
		},
		{
		'http://www.example.com:80',
		'<span class="official-website"><span class="url">[http://www.example.com:80 Official website]</span></span>'
		},
		{
		'https://example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span>'
		},
		{
		'ftp://example.com',
		'<span class="official-website"><span class="url">[ftp://example.com Official website]</span></span>'
		},
		{
		'http://example.com | Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'url= http://example.com |name= Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'http://example.com |format= flash',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span>'
		},
		{
		'http://example.com |mobile= http://m.example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> (<span class="url">[http://m.example.com Mobile]</span>)'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>)'
		},
	} )
end

function p:test_module_nowiki()
	self:preprocess_equals_many('{{#invoke:Official website|main | ', ' }}', {
		{
		'example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'//example.com',
		'<span class="official-website"><span class="url">[//example.com Official website]</span></span>'
		},
		{
		'',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'www.example.com/path?section=96',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'1= www.example.com/path?section=96',
		'<span class="official-website"><span class="url">[http://www.example.com/path?section=96 Official website]</span></span>'
		},
		{
		'url= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'URL= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http:/example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com/',
		'<span class="official-website"><span class="url">[http://example.com/ Official website]</span></span>'
		},
		{
		'http://www.example.com:80',
		'<span class="official-website"><span class="url">[http://www.example.com:80 Official website]</span></span>'
		},
		{
		'https://example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span>'
		},
		{
		'ftp://example.com',
		'<span class="official-website"><span class="url">[ftp://example.com Official website]</span></span>'
		},
		{
		'http://example.com | Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'url= http://example.com |name= Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'http://example.com |format= flash',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span>'
		},
		{
		'http://example.com |mobile= http://m.example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> (<span class="url">[http://m.example.com Mobile]</span>)'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>)'
		},
	},{nowiki=1})
end

function p:test_sandbox()
	self:preprocess_equals_many('{{#invoke:Official website/sandbox|main | ', ' }}', {
		{
		'example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'//example.com',
		'<span class="official-website"><span class="url">[//example.com Official website]</span></span>'
		},
		{
		'',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'www.example.com/path?section=96',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'1= www.example.com/path?section=96',
		'<span class="official-website"><span class="url">[http://www.example.com/path?section=96 Official website]</span></span>'
		},
		{
		'url= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'URL= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http:/example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com/',
		'<span class="official-website"><span class="url">[http://example.com/ Official website]</span></span>'
		},
		{
		'http://www.example.com:80',
		'<span class="official-website"><span class="url">[http://www.example.com:80 Official website]</span></span>'
		},
		{
		'https://example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span>'
		},
		{
		'ftp://example.com',
		'<span class="official-website"><span class="url">[ftp://example.com Official website]</span></span>'
		},
		{
		'http://example.com | Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'url= http://example.com |name= Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'http://example.com |format= flash',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span>'
		},
		{
		'http://example.com |mobile= http://m.example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> (<span class="url">[http://m.example.com Mobile]</span>)'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>)'
		},
		{
		'http://example.jp | lang= jp',
		'<span class="official-website"><span class="url">[http://example.jp Official website]</span></span> <span class="languageicon">(in Japanese)</span>'
		},
		{
		'http://example.com | lang= en',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span class="languageicon">(in English)</span>'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com | lang= es',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>) <span class="languageicon">(in Spanish)</span>'
		},
	} )
end

function p:test_sandbox_nowiki()
	self:preprocess_equals_many('{{#invoke:Official website/sandbox|main | ', ' }}', {
		{
		'example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'//example.com',
		'<span class="official-website"><span class="url">[//example.com Official website]</span></span>'
		},
		{
		'',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'www.example.com/path?section=96',
		'<strong class="error">No URL found. Please specify a URL here or add one to Wikidata.</strong>'
		},
		{
		'1= www.example.com/path?section=96',
		'<span class="official-website"><span class="url">[http://www.example.com/path?section=96 Official website]</span></span>'
		},
		{
		'url= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'URL= example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http:/example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span>'
		},
		{
		'http://example.com/',
		'<span class="official-website"><span class="url">[http://example.com/ Official website]</span></span>'
		},
		{
		'http://www.example.com:80',
		'<span class="official-website"><span class="url">[http://www.example.com:80 Official website]</span></span>'
		},
		{
		'https://example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span>'
		},
		{
		'ftp://example.com',
		'<span class="official-website"><span class="url">[ftp://example.com Official website]</span></span>'
		},
		{
		'http://example.com | Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'url= http://example.com |name= Example',
		'<span class="official-website"><span class="url">[http://example.com Example]</span></span>'
		},
		{
		'http://example.com |format= flash',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span>'
		},
		{
		'http://example.com |mobile= http://m.example.com',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> (<span class="url">[http://m.example.com Mobile]</span>)'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>)'
		},
		{
		'http://example.jp | lang= jp',
		'<span class="official-website"><span class="url">[http://example.jp Official website]</span></span> <span class="languageicon">(in Japanese)</span>'
		},
		{
		'http://example.com | lang= en',
		'<span class="official-website"><span class="url">[http://example.com Official website]</span></span> <span class="languageicon">(in English)</span>'
		},
		{
		'https://example.com |format= flash |mobile= https://m.example.com | lang= es',
		'<span class="official-website"><span class="url">[https://example.com Official website]</span></span> <span style="color:#505050">(Requires [[Adobe Flash Player]])</span> (<span class="url">[https://m.example.com Mobile]</span>) <span class="languageicon">(in Spanish)</span>'
		},
	},{nowiki=1})
end

return p