Module:Sandbox/Mr. Stradivarius/Check ISO 639-1/testcases
Appearance
This is the test cases page for the module Module:Sandbox/Mr. Stradivarius/Check ISO 639-1. Results of the test cases. |
-- Unit tests for [[Module:Check ISO 639-1]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local isoModule = require('Module:Sandbox/Mr. Stradivarius/Check ISO 639-1') -- the module to be tested
local checkISO = isoModule.main
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
function suite.makeError(input)
return mw.ustring.format('<strong class="error">Error: invalid input "%s"; please use an [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', input)
end
function suite.makeCat(sort)
return mw.ustring.format('[[Category:Pages with invalid ISO 639-1 language codes|%s]]', sort)
end
function suite.makeErrorAndCat(input)
return suite.makeError(input) .. suite.makeCat(input)
end
function suite:testCodes()
self:assertEquals('en', checkISO{'en'})
self:assertEquals('en', checkISO{'EN'})
self:assertEquals('en', checkISO{' en '})
self:assertEquals('en', checkISO{' EN '})
self:assertEquals('en', checkISO{'en', nocat='true'})
self:assertEquals('en', checkISO{'en', nocat='yes'})
self:assertEquals('en', checkISO{'en', nocat='y'})
self:assertEquals('en', checkISO{'en', nocat='1'})
self:assertEquals('en', checkISO{'en', nocat=' yes '})
self:assertEquals('en', checkISO{'en', nocat=true})
self:assertEquals(suite.makeErrorAndCat('eng'), checkISO{'eng'})
self:assertEquals(suite.makeErrorAndCat('eng'), checkISO{' eng '})
self:assertEquals(suite.makeErrorAndCat('den'), checkISO{'den'})
self:assertEquals(suite.makeErrorAndCat('fiu-vro'), checkISO{'fiu-vro'})
end
function suite:testNames()
self:assertEquals('en', checkISO{'English'})
self:assertEquals('fr', checkISO{'French'})
self:assertEquals('ja', checkISO{'Japanese'})
self:assertEquals(suite.makeErrorAndCat('Anglais'), checkISO{'Anglais'})
self:assertEquals(suite.makeErrorAndCat('Deutsch'), checkISO{'Deutsch'})
self:assertEquals(suite.makeErrorAndCat('Foobar'), checkISO{'Foobar'})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = 'true'})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = 'yes'})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = 'y'})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = '1'})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = ' yes '})
self:assertEquals(suite.makeError('Foobar'), checkISO{'Foobar', nocat = true})
self:assertEquals(suite.makeErrorAndCat('Foobar'), checkISO{'Foobar', nocat = false})
self:assertEquals(suite.makeErrorAndCat('Foobar'), checkISO{'Foobar', nocat = 'no'})
self:assertEquals(suite.makeErrorAndCat('Foobar'), checkISO{'Foobar', nocat = 'foo'})
end
function suite:testBlank()
self:assertEquals('', checkISO{''})
self:assertEquals('', checkISO{' '})
self:assertEquals('', checkISO{{}})
self:assertEquals('', checkISO{true})
self:assertEquals('', checkISO{nil})
end
return suite