Module:Template translation/testcases

-- 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