Module:Template translation/testcases
Appearance
All tests passed.
test_checkLanguage:
Text | Expected | Actual | |
---|---|---|---|
en | en | en | |
en-us | en-us | en-us | |
sr-cyrl | sr-cyrl | sr-cyrl | |
fr-brai-ca | fr-brai-ca | fr-brai-ca | |
de-ch | de-ch | de-ch | |
a | en | en | |
en--gb | fr | fr | |
én | es | es | |
en> | nil | nil |
test_getFrameLanguageSubpage:
Text | Expected | Actual | |
---|---|---|---|
MediaWiki | |||
MediaWiki/fr | fr | fr | |
MediaWiki/de_ | de | de |
test_getLanguageSubpage:
Text | Expected | Actual | |
---|---|---|---|
subpage |
test_getTranslatedTemplate:
Text | Expected | Actual | |
---|---|---|---|
Extension | Template:Extension/en | Template:Extension/en | |
Extension/de | Template:Extension/de | Template:Extension/de | |
Extension/de-ch | Template:Extension/en | Template:Extension/en | |
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