Jump to content

Module:Sandbox/Mr. Stradivarius/Check ISO 639-1/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 15:34, 13 December 2013 (add a couple of test cases that don't use English). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:Check ISO 639-1]]. Click talk page to run tests.
local p = require('Module:UnitTests')

local isoModule = require('Module:Check ISO 639-1') -- the module to be tested
local checkISO = isoModule.main
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testMain()
	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('<strong class="error">Error: "eng" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|eng]]', checkISO{'eng'})
	self:assertEquals('<strong class="error">Error: "eng" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|eng]]', checkISO{'  eng  '})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|English]]', checkISO{'English'})
	self:assertEquals('<strong class="error">Error: "den" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|den]]', checkISO{'den'})
	self:assertEquals('<strong class="error">Error: "fiu-vro" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|fiu-vro]]', checkISO{'fiu-vro'})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat='true'})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat='yes'})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat='y'})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat='1'})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat='  yes  '})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>', checkISO{'English', nocat=true})
	self:assertEquals('<strong class="error">Error: "English" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>[[Category:Pages with invalid ISO 639-1 language codes|English]]', checkISO{'English', nocat='false'})
	self:assertEquals('', checkISO{''})
	self:assertEquals('', checkISO{'  '})
	self:assertEquals('', checkISO{{}})
	self:assertEquals('', checkISO{true})
	self:assertEquals('', checkISO{nil})
end

local codes = {
	'aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av',
	'ay', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bn', 'bo', 'br',
	'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv', 'cy',
	'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es', 'et',
	'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd',
	'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr', 'ht',
	'hu', 'hy', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'io', 'is',
	'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj', 'kk', 'kl',
	'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw', 'ky', 'la',
	'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'mg', 'mh',
	'mi', 'mk', 'ml', 'mn', 'mo', 'mr', 'ms', 'mt', 'my', 'na',
	'nb', 'nd', 'ng', 'ne', 'nl', 'nn', 'no', 'nr', 'nv', 'ny',
	'oc', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps', 'pt', 'qu',
	'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd', 'se', 'sk',
	'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv',
	'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'tr',
	'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi',
	'vo', 'yi', 'yo', 'za', 'zh', 'za'
}

function suite.getAllCodeOutput()
	local ret = {}
	for _, code in ipairs(codes) do
		ret[#ret + 1] = 'code: "' .. code .. '"; result: "' .. checkISO{code, nocat=true} .. '"'
	end
	return '# ' .. table.concat(ret, '\n# ')
end

return suite