Module:Template translation/testcases

From Bonkipedia
< Module:Template translation
Revision as of 12:46, 25 August 2019 by [[mw:]]>Tacsipacsi (Created page with "-- Example Unit tests for Module:Bananas. Click talk page to run tests. local test = require('Module:UnitTests') local p = require('Module:Template translation') function...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

3 tests failed.

test_checkLanguage:

Text Expected Actual
Yes en en en
Yes en-us en-us en-us
Yes sr-cyrl sr-cyrl sr-cyrl
Yes fr-brai-ca fr-brai-ca fr-brai-ca
Yes de-ch de-ch de-ch
Yes a en en
Yes en--gb fr fr
Yes én es es
Yes en> nil nil

test_getFrameLanguageSubpage:

Text Expected Actual
N MediaWiki en
Yes MediaWiki/fr fr fr
Yes MediaWiki/de_ de de

test_getLanguageSubpage:

Text Expected Actual
N subpage en

test_getTranslatedTemplate:

Text Expected Actual
Yes Extension Template:Extension/en Template:Extension/en
N Extension/de Template:Extension/de Template:Extension/en
Yes Extension/de-ch Template:Extension/en Template:Extension/en
Yes Extension123 Extension123 Extension123

-- Example Unit tests for [[Module:Bananas]]. Click talk page to run tests.
local test = require('Module:UnitTests')
local p = require('Module:Template translation')

function test:test_checkLanguage()
	self:equals('en', p.checkLanguage('en', 'de'), 'en')
	self:equals('en-us', p.checkLanguage('en-us', 'en'), 'en-us')
	self:equals('sr-cyrl', p.checkLanguage('sr-cyrl', 'en'), 'sr-cyrl')
	self:equals('fr-brai-ca', p.checkLanguage('fr-brai-ca', 'en'), 'fr-brai-ca')
	self:equals('de-ch', p.checkLanguage('de-ch', 'en'), 'de-ch')
	self:equals('a', p.checkLanguage('a', 'en'), 'en')
	self:equals('en--gb', p.checkLanguage('en--gb', 'fr'), 'fr')
	self:equals('én', p.checkLanguage('én', 'es'), 'es')
	self:equals('en>', p.checkLanguage('en>', nil), nil)
end

function test:test_getLanguageSubpage()
	self:equals('subpage', p.getLanguageSubpage(), '')
end

function test:test_getFrameLanguageSubpage()
	local function doTest(title)
		return p.getFrameLanguageSubpage(mw.getCurrentFrame():newChild{title = title}:newChild{})
	end
	self:equals('MediaWiki', doTest('MediaWiki'), '')
	self:equals('MediaWiki/fr', doTest('MediaWiki/fr'), 'fr')
	self:equals('MediaWiki/de_', doTest('MediaWiki/de_'), 'de')
end

function test:test_getTranslatedTemplate()
	local function doTest(args)
		return p.getTranslatedTemplate(mw.getCurrentFrame():newChild{args = args})
	end
	self:equals('Extension', doTest{template = 'Extension'}, 'Template:Extension/en')
	self:equals('Extension/de', doTest{template = 'Extension', uselang = 'de'}, 'Template:Extension/de')
	self:equals('Extension/de-ch', doTest{template = 'Extension', uselang = 'de-ch'}, 'Template:Extension/en')
	self:equals('Extension123', doTest{template = 'Extension123'}, 'Extension123')
end

return test