Documentation[créer] [purger]
-- Test unitaire pour [[Module:Sport/Bac à sable]]. Cliquer sur « Discussion » pour voir le résultat du test.
local p = require('Module:UnitTests')

-- TODO Déplacer dans Module:Sport/test et gérer à la fois l'original et le bac à sable
local modulename = mw.title.getCurrentTitle().baseText
local Sport = require( 'Module:' .. modulename )
local TestWikicode = require('Module:Test wikicode')
local frame

--[[
	Retourne une table contenant uniquement les clés keys de la table tbl
]]--
local function intersectKeys(tbl, keys)
	local newTbl = {}
	for k, v in pairs(tbl) do
		for i, key in ipairs(keys) do
			if k == key then
				newTbl[k] = v
				break
			end
		end
	end
	return newTbl
end

local function identity(...) return ... end

local function preprocessModuleAndTemplate(moduleFunction, templateName, args, useData)
	if not frame then frame = mw.getCurrentFrame() end
	useData = useData and (' |usedata=' .. useData) or ''
	if mw.text.trim(args):sub(0, 1) ~= '|' then args = ' |' .. args end
	local moduleCode = '{{#invoke:' .. modulename .. ' |' .. moduleFunction .. args .. useData .. '}}'
	local templateCode = '{{' .. templateName .. args .. '}}'
	return moduleCode, templateCode, frame:preprocess(moduleCode), frame:preprocess(templateCode)
end

local function getTestPrefix(args, moduleCode, templateCode, moduleRes, templateRes, useData, addIntro)
	local testPrefix = ''
	if addIntro then
		testPrefix =
			'!colspan=4 style="border-top-width:4px;padding-top:1em;padding-bottom:1em;"|<big>Paramètres : ' .. '<code>' .. mw.text.nowiki(args) .. '</code></big>\n|-\n' ..
			'|colspan=2|Code\n' ..
			'|style="vertical-align:top;"|<pre>' .. mw.text.nowiki(templateCode) .. '</pre>\n' ..
			'|style="vertical-align:top;"|<pre>' .. mw.text.nowiki(moduleCode) .. '</pre>\n|-\n'
	end
	if not useData then
		testPrefix = testPrefix .. '!colspan=4 style="text-align:left;"|En utilisant les données prioritaires\n|-\n'
	elseif useData == 'template' then
		testPrefix = testPrefix .. '!colspan=4 style="text-align:left;"|En utilisant les données des modèles\n|-\n'
	elseif useData == 'module' then
		testPrefix = testPrefix .. '!colspan=4 style="text-align:left;"|En utilisant les données des modules\n|-\n'
	end
	testPrefix = testPrefix ..
		'|colspan=2|Résultat\n' ..
		'|style="vertical-align:top;"|' .. templateCode .. '<br /><pre>' .. mw.text.nowiki(templateRes) .. '</pre>\n' ..
		'|style="vertical-align:top;"|' .. moduleCode .. '<br /><pre>' .. mw.text.nowiki(moduleRes) .. '</pre>\n|-\n'
	return testPrefix
end

--[[
	Compare une fonction du module avec un template.
	La comparaison se fait sur la structure du wikicode (via TestWikicode.extract).
]]--
function p:compareModuleToTemplateWikicode(moduleFunction, templateName)
	local function test(args, items, transformers, useData, addIntro)
		local moduleCode, templateCode, moduleRes, templateRes = preprocessModuleAndTemplate(moduleFunction, templateName, args, useData)
		local testPrefix = getTestPrefix(args, moduleCode, templateCode, moduleRes, templateRes, useData, addIntro)
		
		local moduleExtracts = TestWikicode.extract(moduleRes, items)
		local templateExtracts = TestWikicode.extract(templateRes, items)
		p:equals('Structure (<code>' .. table.concat(items, ', ') .. '</code>)', moduleExtracts ~= nil, templateExtracts ~= nil, {
			before = testPrefix
		})
		for k, transformer in ipairs(transformers or {}) do
			if transformer then
				local index, label, fun = unpack(transformer)
				p:equals_deep(
					label,
					moduleExtracts ~= nil and fun(moduleExtracts[index]) or nil,
					templateExtracts ~= nil and fun(templateExtracts[index]) or nil
				)
			end
		end
	end
	
	--[[
		items est une sequence passée à TestWikicode.extract.
		transformers est une sequence de sequences du type {index, label, fonction} permettant
		de comparer certains items parmi les résultats extraits :
		* index est l'index de l'item à comparer ;
		* label est un intitulé pour cet item ;
		* fonction permet de transformer l'item avant la comparaison.
	]]--
	return function (args, items, transformers)
		test(args, items, transformers, nil, true)
		test(args, items, transformers, 'template')
		test(args, items, transformers, 'module')
	end
end

--[[
	Compare une fonction du module avec un template.
	La comparaison se fait sur le résultat brut.
]]--
function p:compareModuleToTemplateSimple(moduleFunction, templateName)
	local function test(args, transformer, useData, addIntro)
		local moduleCode, templateCode, moduleRes, templateRes = preprocessModuleAndTemplate(moduleFunction, templateName, args, useData)
		local testPrefix = getTestPrefix(args, moduleCode, templateCode, moduleRes, templateRes, useData, addIntro)
		transformer = transformer or identity
		p:equals_deep('Valeur', transformer(moduleRes), transformer(templateRes), {
			before = testPrefix
		})
	end
	return function (args, transformer)
		test(args, transformer, nil, true)
		test(args, transformer, 'template')
		test(args, transformer, 'module')
	end
end

local function testFlag(moduleFunction, templateName)
	local validate = p:compareModuleToTemplateWikicode(moduleFunction, templateName)
	return function (args)
		local items = {'image'}
		local validators = {
			{1, 'Image', function (image)
				return intersectKeys(image, {'src', 'size', 'format'})
			end},
			{3, 'Lien', identity},
		}
		validate(args, items, validators)
	end
end
local function testFlagLink(moduleFunction, templateName)
	local validate = p:compareModuleToTemplateWikicode(moduleFunction, templateName)
	return function (args)
		local items = {'image', '-', 'link'}
		local validators = {
			{1, 'Image', function (image)
				return intersectKeys(image, {'src', 'size', 'format'})
			end},
			{3, 'Lien', identity},
		}
		validate(args, items, validators)
	end
end
local function testSimpleTrimLink(moduleFunction, templateName)
	local validate = p:compareModuleToTemplateSimple(moduleFunction, templateName)
	return function (args)
		validate(args, TestWikicode.parseLink)
	end
end

-- Test {{drapeau2|...|domaine=Gymnastique CIO}}
function p:test_drapeau2_domaine_gymnastique_cio()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=Gymnastique CIO')
	test('Suisse|domaine=Gymnastique CIO')
	test('Afrique du Sud|domaine=Gymnastique CIO')
end

-- Test {{drapeau2|...|domaine=JO}}
function p:test_drapeau2_domaine_jo()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=JO')
	test('France|domaine=JO|genre=para')
	test('France|domaine=JO|nombre=2008')
	test('France|domaine=JO|genre=para|nombre=2008')
end

-- Test {{drapeau2|...|domaine=JO CIO}}
function p:test_drapeau2_domaine_jo_cio()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=JO CIO')
	test('France|domaine=JO CIO|genre=para')
	test('France|domaine=JO CIO|nombre=2008')
	test('France|domaine=JO CIO|genre=para|nombre=2008')
end

-- Test {{drapeau2|...|domaine=Sport}}
function p:test_drapeau2_domaine_sport()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=Sport')
	test('Maroc|domaine=Sport')
	test('Serbie|domaine=Sport')
	test('Danemark|domaine=Sport')
end

-- Test {{drapeau2|...|domaine=Sport CIO}}
function p:test_drapeau2_domaine_sport_cio()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=Sport CIO')
	test('Irlande|domaine=Sport CIO')
	test('Norvège|domaine=Sport CIO')
end

-- Test {{drapeau2|...|domaine=bandy}}
function p:test_drapeau2_domaine_bandy()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=bandy')
	test('France|domaine=bandy|genre=féminin')
end

-- Test {{drapeau2|...|domaine=baseball}}
function p:test_drapeau2_domaine_baseball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=baseball')
	test('France|domaine=baseball|genre=féminin')
end

-- Test {{drapeau2|...|domaine=basket-ball}}
function p:test_drapeau2_domaine_basket_ball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=basket-ball')
	test('France|domaine=basket-ball|genre=féminin')
	test('France|domaine=basket-ball|nombre=3')
	test('France|domaine=basket-ball|genre=féminin|nombre=3')
end

-- Test {{drapeau2|...|domaine=basket-ball à trois}}
function p:test_drapeau2_domaine_basket_ball_a_trois()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=basket-ball à trois')
	test('France|domaine=basket-ball à trois|genre=féminin')
end

-- Test {{drapeau2|...|domaine=beach soccer}}
function p:test_drapeau2_domaine_beach_soccer()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=beach soccer')
	test('France|domaine=beach soccer|genre=féminin')
	test('France|domaine=beach soccer|nombre=-21')
	test('France|domaine=beach soccer|nombre=-20')
	test('France|domaine=beach soccer|nombre=-17')
	test('France|domaine=beach soccer|genre=féminin|nombre=-21')
	test('Chine|domaine=beach soccer')
end

-- Test {{drapeau2|...|domaine=cricket}}
function p:test_drapeau2_domaine_cricket()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=cricket')
	test('Indes occidentales|domaine=cricket')
end

-- Test {{drapeau2|...|domaine=crosse}}
function p:test_drapeau2_domaine_crosse()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=crosse')
end

-- Test {{drapeau2|...|domaine=cyclisme sur route}}
function p:test_drapeau2_domaine_cyclisme_sur_route()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=cyclisme sur route')
	test('France|domaine=cyclisme sur route|genre=masculin')
	test('France|domaine=cyclisme sur route|genre=féminin')
	test('France|domaine=cyclisme sur route|nombre=u23')
	test('France|domaine=cyclisme sur route|nombre=u19')
end

-- Test {{drapeau2|...|domaine=floorball}}
function p:test_drapeau2_domaine_floorball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=floorball')
	test('France|domaine=floorball|genre=féminin')
	test('France|domaine=floorball|nombre=-19')
end

-- Test {{drapeau2|...|domaine=football}}
function p:test_drapeau2_domaine_football()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=football')
	test('France|domaine=football|genre=féminin')
	test('France|domaine=football|nombre=-21')
	test('France|domaine=football|nombre=-20')
	test('France|domaine=football|nombre=-17')
	test('France|domaine=football|genre=féminin|nombre=-21')
	test('Chinese Taipei|domaine=football')
	
	test('France|domaine=football|compétition=Coupe du monde')
	test('France|domaine=football|compétition=Coupe du monde|année=1998')
	test('France|domaine=football|compétition=Euro|année=2000')
	test('France|domaine=football|année=2000')
	test('France|domaine=football|année=2010')
end

-- Test {{drapeau2|...|domaine=football américain}}
function p:test_drapeau2_domaine_football_americain()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=football américain')
end

-- Test {{drapeau2|...|domaine=football australien}}
function p:test_drapeau2_domaine_football_australien()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=football australien')
end

-- Test {{drapeau2|...|domaine=football de plage}}
function p:test_drapeau2_domaine_football_de_plage()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=football de plage')
	test('France|domaine=football de plage|genre=féminin')
	test('France|domaine=football de plage|nombre=-21')
	test('France|domaine=football de plage|nombre=-20')
	test('France|domaine=football de plage|nombre=-17')
	test('France|domaine=football de plage|genre=féminin|nombre=-21')
	test('Chine|domaine=football de plage')
end

-- Test {{drapeau2|...|domaine=futsal}}
function p:test_drapeau2_domaine_futsal()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=futsal')
end

-- Test {{drapeau2|...|domaine=gymnastique artistique féminine}}
function p:test_drapeau2_domaine_gymnastique_artistique_feminine()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=gymnastique artistique féminine')
	test('France|domaine=gymnastique artistique féminine|nombre=-21')
	test('France|domaine=gymnastique artistique féminine|nombre=-20')
	test('France|domaine=gymnastique artistique féminine|nombre=-17')
end

-- Test {{drapeau2|...|domaine=gymnastique artistique masculine}}
function p:test_drapeau2_domaine_gymnastique_artistique_masculine()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=gymnastique artistique masculine')
	test('France|domaine=gymnastique artistique masculine|nombre=-21')
	test('France|domaine=gymnastique artistique masculine|nombre=-20')
	test('France|domaine=gymnastique artistique masculine|nombre=-17')
end

-- Test {{drapeau2|...|domaine=handball}}
function p:test_drapeau2_domaine_handball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=handball')
	test('France|domaine=handball|genre=masculin')
	test('France|domaine=handball|genre=féminin')
end

-- Test {{drapeau2|...|domaine=hockey sur gazon}}
function p:test_drapeau2_domaine_hockey_sur_gazon()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=hockey sur gazon')
	test('France|domaine=hockey sur gazon|genre=féminin')
end

-- Test {{drapeau2|...|domaine=hockey sur glace}}
function p:test_drapeau2_domaine_hockey_sur_glace()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=hockey sur glace')
	test('France|domaine=hockey sur glace|genre=féminin')
	test('France|domaine=hockey sur glace|nombre=-21')
	test('France|domaine=hockey sur glace|nombre=-20')
	test('France|domaine=hockey sur glace|nombre=-17')
	test('France|domaine=hockey sur glace|genre=féminin|nombre=-21')
end

-- Test {{drapeau2|...|domaine=korfbal}}
function p:test_drapeau2_domaine_korfbal()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=korfbal')
end

-- Test {{drapeau2|...|domaine=korfball}}
function p:test_drapeau2_domaine_korfball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=korfball')
end

-- Test {{drapeau2|...|domaine=netball}}
function p:test_drapeau2_domaine_netball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=netball')
end

-- Test {{drapeau2|...|domaine=pelote basque}}
function p:test_drapeau2_domaine_pelote_basque()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=pelote basque')
	test('France|domaine=pelote basque|genre=féminin')
end

-- Test {{drapeau2|...|domaine=polo}}
function p:test_drapeau2_domaine_polo()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=polo')
end

-- Test {{drapeau2|...|domaine=racquetball}}
function p:test_drapeau2_domaine_racquetball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=racquetball')
end

-- Test {{drapeau2|...|domaine=rugby}}
function p:test_drapeau2_domaine_rugby()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=rugby')
	test('France|domaine=rugby|genre=féminin')
	test('France|domaine=rugby|nombre=13')
	test('France|domaine=rugby|nombre=7')
	test('France|domaine=rugby|nombre=touch')
	test('France|domaine=rugby|genre=féminin|nombre=13')
	test('Irlande|domaine=rugby')
end

-- Test {{drapeau2|...|domaine=soccer}}
function p:test_drapeau2_domaine_soccer()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('États-Unis|domaine=soccer')
	test('Canada|domaine=soccer|genre=féminin')
end

-- Test {{drapeau2|...|domaine=softball}}
function p:test_drapeau2_domaine_softball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=softball')
	test('France|domaine=softball|genre=féminin')
end

-- Test {{drapeau2|...|domaine=tennis}}
function p:test_drapeau2_domaine_tennis()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=tennis')
	test('France|domaine=tennis|genre=féminin')
end

-- Test {{drapeau2|...|domaine=volley-ball}}
function p:test_drapeau2_domaine_volley_ball()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=volley-ball')
	test('France|domaine=volley-ball|genre=féminin')
end

-- Test {{drapeau2|...|domaine=water-polo}}
function p:test_drapeau2_domaine_water_polo()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('France|domaine=water-polo')
	test('France|domaine=water-polo|genre=masculin')
	test('France|domaine=water-polo|genre=féminin')
end

-- Test {{drapeau2/Libellé}}
function p:test_drapeau2_libelle()
	local test = testSimpleTrimLink('libelle', 'drapeau2/Libellé')
	test('France')
	test('Bahamas')
	test('Vatican')
end

-- Test {{drapeau2/Libellé/CIO}}
function p:test_drapeau2_libelle_cio()
	local test = testSimpleTrimLink('libelle_cio', 'drapeau2/Libellé/CIO')
	test('France')
	test('Bahamas')
	test('Vatican')
end

-- Test {{drapeau2/Libellé/Sport}}
function p:test_drapeau2_libelle_sport()
	local test = testSimpleTrimLink('libelle_sport', 'drapeau2/Libellé/Sport')
	test('France')
	test('Allemagne')
	test('Irlande')
	test('Grande-Bretagne')
	test('Royaume-Uni')
end

-- Test {{drapeau2/Libellé/Sport CIO}}
function p:test_drapeau2_libelle_sport_cio()
	local test = testSimpleTrimLink('libelle_sport_cio', 'drapeau2/Libellé/Sport CIO')
	test('France')
	test('Bahamas')
	test('Vatican')
end

-- Test {{drapeau2/Libellé/JO}}
function p:test_drapeau2_libelle_jo()
	local test = testSimpleTrimLink('libelle_jo', 'drapeau2/Libellé/JO')
	test('France')
	test('France|genre=para')
	test('France|nombre=2008')
	test('France|nombre=2006')
	test('France|genre=para|nombre=2008')
	test('France|nombre=été 1960')
	test('France|nombre=hiver 1960')
end

-- Test {{drapeau2/Libellé/JO CIO}}
function p:test_drapeau2_libelle_jo_cio()
	local test = testSimpleTrimLink('libelle_jo_cio', 'drapeau2/Libellé/JO CIO')
	test('France')
	test('Bahamas')
	test('Vatican')
	test('France|genre=para')
	test('France|nombre=2008')
	test('France|nombre=2006')
	test('France|genre=para|nombre=2008')
	test('France|nombre=été 1960')
	test('France|nombre=hiver 1960')
end

-- Test {{drapeau2/Libellé/bandy}}
function p:test_drapeau2_libelle_bandy()
	local test = testSimpleTrimLink('libelle_bandy', 'drapeau2/Libellé/bandy')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/baseball}}
function p:test_drapeau2_libelle_baseball()
	local test = testSimpleTrimLink('libelle_baseball', 'drapeau2/Libellé/baseball')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/basket-ball}}
function p:test_drapeau2_libelle_basket_ball()
	local test = testSimpleTrimLink('libelle_basket_ball', 'drapeau2/Libellé/basket-ball')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=3')
	test('France|genre=féminin|nombre=3')
end

-- Test {{drapeau2/Libellé/basket-ball à trois}}
function p:test_drapeau2_libelle_basket_ball_a_trois()
	local test = testSimpleTrimLink('libelle_basket_ball_a_trois', 'drapeau2/Libellé/basket-ball à trois')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/beach soccer}}
function p:test_drapeau2_libelle_beach_soccer()
	local test = testSimpleTrimLink('libelle_beach_soccer', 'drapeau2/Libellé/beach soccer')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=-21')
	test('France|nombre=-20')
	test('France|nombre=-17')
	test('France|genre=féminin|nombre=-21')
	test('Chine')
end

-- Test {{drapeau2/Libellé/cricket}}
function p:test_drapeau2_libelle_cricket()
	local test = testSimpleTrimLink('libelle_cricket', 'drapeau2/Libellé/cricket')
	test('France')
	test('Indes occidentales')
end

-- Test {{drapeau2/Libellé/crosse}}
function p:test_drapeau2_libelle_crosse()
	local test = testSimpleTrimLink('libelle_crosse', 'drapeau2/Libellé/crosse')
	test('France')
end

-- Test {{drapeau2/Libellé/cyclisme sur route}}
function p:test_drapeau2_libelle_cyclisme_sur_route()
	local test = testSimpleTrimLink('libelle_cyclisme_sur_route', 'drapeau2/Libellé/cyclisme sur route')
	test('France')
	test('France|genre=masculin')
	test('France|genre=féminin')
	test('France|nombre=u23')
	test('France|nombre=u19')
end

-- Test {{drapeau2/Libellé/floorball}}
function p:test_drapeau2_libelle_floorball()
	local test = testSimpleTrimLink('libelle_floorball', 'drapeau2/Libellé/floorball')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=-19')
end

-- Test {{drapeau2/Libellé/football}}
function p:test_drapeau2_libelle_football()
	local test = testSimpleTrimLink('libelle_football', 'drapeau2/Libellé/football')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=-21')
	test('France|nombre=-20')
	test('France|nombre=-17')
	test('France|genre=féminin|nombre=-21')
	test('Chinese Taipei')
	
	test('France|compétition=Coupe du monde')
	test('France|compétition=Coupe du monde|année=1998')
	test('France|compétition=Euro|année=2000')
	test('France|année=2000')
	test('France|année=2010')
end

-- Test {{drapeau2/Libellé/football américain}}
function p:test_drapeau2_libelle_football_americain()
	local test = testSimpleTrimLink('libelle_football_americain', 'drapeau2/Libellé/football américain')
	test('France')
end

-- Test {{drapeau2/Libellé/football australien}}
function p:test_drapeau2_libelle_football_australien()
	local test = testSimpleTrimLink('libelle_football_australien', 'drapeau2/Libellé/football australien')
	test('France')
end

-- Test {{drapeau2/Libellé/futsal}}
function p:test_drapeau2_libelle_futsal()
	local test = testSimpleTrimLink('libelle_futsal', 'drapeau2/Libellé/futsal')
	test('France')
end

-- Test {{drapeau2/Libellé/gymnastique artistique féminine}}
function p:test_drapeau2_libelle_gymnastique_artistique_feminine()
	local test = testSimpleTrimLink('libelle_gymnastique_artistique_feminine', 'drapeau2/Libellé/gymnastique artistique féminine')
	test('France')
	test('France|nombre=-21')
	test('France|nombre=-20')
	test('France|nombre=-17')
end

-- Test {{drapeau2/Libellé/gymnastique artistique masculine}}
function p:test_drapeau2_libelle_gymnastique_artistique_masculine()
	local test = testSimpleTrimLink('libelle_gymnastique_artistique_masculine', 'drapeau2/Libellé/gymnastique artistique masculine')
	test('France')
	test('France|nombre=-21')
	test('France|nombre=-20')
	test('France|nombre=-17')
end

-- Test {{drapeau2/Libellé/handball}}
function p:test_drapeau2_libelle_handball()
	local test = testSimpleTrimLink('libelle_handball', 'drapeau2/Libellé/handball')
	test('France')
	test('France|genre=masculin')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/hockey sur gazon}}
function p:test_drapeau2_libelle_hockey_sur_gazon()
	local test = testSimpleTrimLink('libelle_hockey_sur_gazon', 'drapeau2/Libellé/hockey sur gazon')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/hockey sur glace}}
function p:test_drapeau2_libelle_hockey_sur_glace()
	local test = testSimpleTrimLink('libelle_hockey_sur_glace', 'drapeau2/Libellé/hockey sur glace')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=-21')
	test('France|nombre=-20')
	test('France|nombre=-17')
	test('France|genre=féminin|nombre=-21')
end

-- Test {{drapeau2/Libellé/korfbal}}
function p:test_drapeau2_libelle_korfbal()
	local test = testSimpleTrimLink('libelle_korfbal', 'drapeau2/Libellé/korfbal')
	test('France')
end

-- Test {{drapeau2/Libellé/netball}}
function p:test_drapeau2_libelle_netball()
	local test = testSimpleTrimLink('libelle_netball', 'drapeau2/Libellé/netball')
	test('France')
end

-- Test {{drapeau2/Libellé/pelote basque}}
function p:test_drapeau2_libelle_pelote_basque()
	local test = testSimpleTrimLink('libelle_pelote_basque', 'drapeau2/Libellé/pelote basque')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/polo}}
function p:test_drapeau2_libelle_polo()
	local test = testSimpleTrimLink('libelle_polo', 'drapeau2/Libellé/polo')
	test('France')
end

-- Test {{drapeau2/Libellé/racquetball}}
function p:test_drapeau2_libelle_racquetball()
	local test = testSimpleTrimLink('libelle_racquetball', 'drapeau2/Libellé/racquetball')
	test('France')
end

-- Test {{drapeau2/Libellé/rugby}}
function p:test_drapeau2_libelle_rugby()
	local test = testSimpleTrimLink('libelle_rugby', 'drapeau2/Libellé/rugby')
	test('France')
	test('France|genre=féminin')
	test('France|nombre=13')
	test('France|nombre=7')
	test('France|nombre=touch')
	test('France|genre=féminin|nombre=13')
	test('Irlande')
end

-- Test {{drapeau2/Libellé/soccer}}
function p:test_drapeau2_libelle_soccer()
	local test = testSimpleTrimLink('libelle_soccer', 'drapeau2/Libellé/soccer')
	test('États-Unis')
	test('Canada|genre=féminin')
end

-- Test {{drapeau2/Libellé/softball}}
function p:test_drapeau2_libelle_softball()
	local test = testSimpleTrimLink('libelle_softball', 'drapeau2/Libellé/softball')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/tennis}}
function p:test_drapeau2_libelle_tennis()
	local test = testSimpleTrimLink('libelle_tennis', 'drapeau2/Libellé/tennis')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/volley-ball}}
function p:test_drapeau2_libelle_volley_ball()
	local test = testSimpleTrimLink('libelle_volley_ball', 'drapeau2/Libellé/volley-ball')
	test('France')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/water-polo}}
function p:test_drapeau2_libelle_water_polo()
	local test = testSimpleTrimLink('libelle_water_polo', 'drapeau2/Libellé/water-polo')
	test('France')
	test('France|genre=masculin')
	test('France|genre=féminin')
end

-- Test {{drapeau2/Libellé/Compétition}}
function p:test_drapeau2_libelle_competition()
	local test = testSimpleTrimLink('libelle_competition', 'drapeau2/Libellé/Compétition')
	test('')
	test('euro')
	test('euro|2000')
	test('Coupe du monde|1998')
	test('JO|hiver 1992')
	test('|1998')
end

-- Test {{drapeau2/Libellé/Délégation}}
function p:test_drapeau2_libelle_delegation()
	local test = testSimpleTrimLink('libelle_delegation', 'drapeau2/Libellé/Délégation')
	test('France|aux Jeux paralympiques')
	test('Bahamas|aux Jeux olympiques')
end

-- Test {{drapeau2/Libellé/Équipe}}
function p:test_drapeau2_libelle_equipe()
	local test = testSimpleTrimLink('libelle_equipe', 'drapeau2/Libellé/Équipe')
	test('France|de football')
	test('France|féminine de football')
	test('France|de rugby à XV')
	test('France|de pelote basque')
end

-- Test {{drapeau2/Libellé/JO/Olympiades}}
function p:test_drapeau2_libelle_jo_olympiades()
	local test = testSimpleTrimLink('libelle_jo_olympiades', 'drapeau2/Libellé/JO/Olympiades')
	test('')
	test('2008')
	test('2010')
	test('1906')
	test('1976')
	test('été 1976')
	test('hiver 1976')
	test('jeunesse 2010')
end

-- Test des pays listés dans {{drapeau2/Image}}
--[[function p:test_drapeau2()
	local test = testFlagLink('drapeau_sport', 'drapeau2')
	test('Afghanistan')
	test('Afrique du Sud')
	test('Albanie')
	test('Algérie')
	test('Allemagne')
	test('Andorre')
	test('Angola')
	test('Antigua-et-Barbuda')
	test('Arabie saoudite')
	test('Argentine')
	test('Arménie')
	test('Australie')
	test('Autriche')
	test('Azerbaïdjan')
	
	test('Bahamas')
	test('Bahreïn')
	test('Bangladesh')
	test('Barbade')
	test('Belgique')
	test('Belize')
	test('Bénin')
	test('Bhoutan')
	test('Biélorussie')
	test('Birmanie')
	test('Myanmar')
	test('Bolivie')
	test('Bosnie-Herzégovine')
	test('Botswana')
	test('Brésil')
	test('Brunei')
	test('Bulgarie')
	test('Burkina Faso')
	test('Burundi')
	
	test('République khmère')
	test('Cambodge')
	test('Cameroun')
	test('Canada')
	test('Cap-Vert')
	test('Centrafrique')
	test('République centrafricaine')
	test('Chili')
	test('République populaire de Chine')
	test('Chine')
	test('Chypre')
	test('Colombie')
	test('Comores')
	test('Union des Comores')
	test('République démocratique du Congo')
	test('Congo-Brazzaville')
	test('République du Congo')
	test('Corée du Nord')
	test('Corée du Sud')
	test('Costa Rica')
	test("Côte d'Ivoire")
	test('Croatie')
	test('Cuba')
	
	test('Danemark')
	test('Djibouti')
	test('République dominicaine')
	test('Dominique')
	
	test('Égypte')
	test('Egypte')
	test('Émirats arabes unis')
	test('Emirats arabes unis')
	test('Équateur')
	test('Equateur')
	test('Érythrée')
	test('Erythrée')
	test('Espagne')
	test('Estonie')
	test('États-Unis')
	test('Etats-Unis')
	test("États-Unis d'Amérique")
	test('Éthiopie')
	test('Ethiopie')
	
	test('Fidji')
	test('Finlande')
	test('France')
	
	test('Gabon')
	test('Gambie')
	test('Géorgie')
	test('Ghana')
	test('Grèce')
	test('Grenade')
	test('Guatemala')
	test('Guinée')
	test('Guinée-Bissau')
	test('Guinée équatoriale')
	test('Guyana')
	
	test('Haïti')
	test('Honduras')
	test('Hongrie')
	
	test('Inde')
	test('Indonésie')
	test('Iraq')
	test('Irak')
	test('Irlande')
	test('Islande')
	test('Israël')
	test('Italie')
	
	test('Jamaïque')
	test('Japon')
	test('Jordanie')
	
	test('Kazakhstan')
	test('Kenya')
	test('Kirghizistan')
	test('Kiribati')
	test('Koweït')
	
	test('Laos')
	test('Lesotho')
	test('Lettonie')
	test('Liban')
	test('Liberia')
	test('Libye')
	test('Liechtenstein')
	test('Lituanie')
	test('Luxembourg')
	
	test('Macédoine du Nord')
	test('Madagascar')
	test('Malaisie')
	test('Malawi')
	test('Maldives')
	test('Mali')
	test('Malte')
	test('Maroc')
	test('Marshall')
	test('Maurice')
	test('Mauritanie')
	test('Mexique')
	test('États fédérés de Micronésie')
	test('Micronésie')
	test('Moldavie')
	test('Monaco')
	test('Mongolie')
	test('Monténégro')
	test('Mozambique')
	
	test('Namibie')
	test('Nauru')
	test('Népal')
	test('Nicaragua')
	test('Niger')
	test('Nigeria')
	test('Norvège')
	test('Nouvelle-Zélande')
	
	test('Oman')
	test('Ouganda')
	test('Ouzbékistan')
	
	test('Pakistan')
	test('Palaos')
	test('Panamá')
	test('Panama')
	test('Papouasie-Nouvelle-Guinée')
	test('Paraguay')
	test('Pays-Bas')
	test('Pérou')
	test('Philippines')
	test('Pologne')
	test('Portugal')
	
	test('Qatar')
	
	test('Roumanie')
	test('Grande-Bretagne')
	test('Royaume-Uni')
	test('Russie')
	test('Rwanda')
	
	test('Saint-Christophe-et-Niévès')
	test('Sainte-Lucie')
	test('Saint-Marin')
	test('Saint-Vincent-et-les-Grenadines')
	test('Saint-Vincent-et-les Grenadines')
	test('Salomon')
	test('Salvador')
	test('Samoa')
	test('Sao Tomé-et-Principe')
	test('Sénégal')
	test('Serbie')
	test('Seychelles')
	test('Sierra Leone')
	test('Singapour')
	test('Slovaquie')
	test('Slovénie')
	test('Somalie')
	test('Soudan')
	test('Sud-Soudan')
	test('Soudan du Sud')
	test('Ceylan')
	test('Sri Lanka')
	test('Suède')
	test('Suisse')
	test('Suriname')
	test('Swaziland')
	test('Eswatini')
	test('Syrie')
	
	test('Tadjikistan')
	test('Tanzanie')
	test('Tchad')
	test('République tchèque')
	test('Tchéquie')
	test('Thaïlande')
	test('Timor oriental')
	test('Togo')
	test('Tonga')
	test('Trinité-et-Tobago')
	test('Tunisie')
	test('Turkménistan')
	test('Turquie')
	test('Tuvalu')
	
	test('Ukraine')
	test('Uruguay')
	
	test('Vanuatu')
	test('Vatican')
	test('Venezuela')
	test('Viêt Nam')
	test('Vietnam')
	
	test('Yémen')
	
	test('Zambie')
	test('Zimbabwe')
	
	test('AASSE')
	test('Abou Dabi')
	test('Ajman')
	test('Akrotiri et Dhekelia')
	test('Anglesey')
	test('Anguilla')
	test('Bermudes')
	test('Chypre du Nord')
	test('Caïmans')
	test('Gibraltar')
	test('Guam')
	test('Falkland')
	test('Malouines')
	test('Kosovo')
	test('Montserrat')
	test('Nouvelle-Calédonie')
	test('Palestine')
	test('Pitcairn')
	test('Sainte-Hélène')
	test('République arabe sahraouie démocratique')
	test('Sahara occidental')
	test('Samoa américaines')
	test('République de Chine (Taïwan)')
	test('Taïwan')
	test('Tibet')
	test('Turques-et-Caïques')
	test('Vierges américaines')
	test('Vierges des États-Unis')
	test('Vierges britanniques')
	
	test('Åland')
	test('Aland')
	test('Aruba')
	test('Açores')
	test('Canaries')
	test('Ceuta')
	test('Christmas')
	test('Cocos')
	test('Cook')
	test('Curaçao')
	test('Féroé')
	test('Géorgie du Sud-et-les Îles Sandwich du Sud')
	test('Géorgie du Sud')
	test('Sandwich du Sud')
	test('Groenland')
	test('Guadeloupe')
	test('Guernesey')
	test('Guyane')
	test('Hong Kong')
	test('Jersey')
	test('Macao')
	test('Madère')
	test('Man')
	test('Mariannes du Nord')
	test('Martinique')
	test('Mayotte')
	test('Melilla')
	test('Niue')
	test('Norfolk')
	test('Île Norfolk')
	test('Polynésie française')
	test('Tahiti')
	test('Porto Rico')
	test('Réunion')
	test('Saint-Barthélemy')
	test('Saint-Martin')
	test('Sint-Maarten')
	test('Saint-Pierre-et-Miquelon')
	test("Territoire britannique de l'océan Indien")
	test('Tokelau')
	test('Wallis-et-Futuna')
	
	test('Abkhazie')
	test('Azawad')
	test('Gagaouzie')
	test('Haut-Karabagh')
	test('Ossétie du Sud')
	test('Somaliland')
	test('Transnistrie')
	test("Allemagne de l'Est")
	test("Allemagne de l'Ouest")
	test('Bohême')
	test('Communauté des États indépendants')
	test("Côte-de-l'Or britannique")
	test("Équipe unifiée d'Allemagne")
	test('Antilles néerlandaises')
	test('Autriche-Hongrie')
	test('Biafra')
	test('Bornéo du Nord')
	test('Dahomey')
	test('Honduras britannique')
	test('Empire ottoman')
	test('Macédoine')
	test('Nouvelles-Hébrides')
	test('Indes occidentales')
	test('République arabe unie')
	test('Rhodésie')
	test('Rhodésie du Nord')
	test('Rhodésie du Sud')
	test('Sarre')
	test('Serbie-et-Monténégro')
	test('Suède-Norvège')
	test('Tchécoslovaquie')
	test('URSS')
	test('Haute-Volta')
	test('Yémen du Nord')
	test('Yémen du Sud')
	test('Yougoslavie')
	test('Zaïre')
	
	test('Antarctique')
	test('Australasie')
	test('Europe')
	test('Union européenne')
	test('Nations unies')
	test('Angleterre')
	test('Écosse')
	test('Québec')
	test('Irlande du Nord')
	test('Pays de Galles')
	test('Catalogne')
	test('Chinese Taipei')
	test('Taipei chinois')
	test('Équipe unifiée')
	test('Équipe mixte')
	test('Participants indépendants')
	test('Athlètes indépendants')
	test('Athlètes réfugiés')
	test('ROC_2020')
	test('ROC')
	test('RPC')
	test('Pohnpei')
end]]--

return p