Yiɣi chaŋ yɛligu maŋamaŋa puuni

Module:TaxonItalics/testcases

Diyila Dagbani Wikipedia

Documentation for this module may be created at Module:TaxonItalics/testcases/doc

local p = require('Module:UnitTests')

local function clean(input)
	local orig = input
	local result = input:gsub("''( ?)(.-)( ?)''", "%1''%2''%3")
	result = mw.text.decode(result)
	if orig ~= result then
		mw.log(orig, result, "\n")
	end
	return result
end

function p:test_italicizeTaxonName()
	local examples = {
		"Below genus",
		{ "Pinus subg. Pinus", "''Pinus <span style=\"font-style:normal;\">subg.</span> Pinus''" },
		{ "Pinus subgenus Pinus", "''Pinus <span style=\"font-style:normal;\">subg.</span> Pinus''" },
		{ "P. subg. Pinus", "''P. <span style=\"font-style:normal;\">subg.</span> Pinus''" },
		{ "Passiflora supersect. Tacsonia", "''Passiflora <span style=\"font-style:normal;\">supersect.</span> Tacsonia''" },
		{ "Pinus sect. Pinus", "''Pinus <span style=\"font-style:normal;\">sect.</span> Pinus''" },
		{ "Pinus section Pinus", "''Pinus <span style=\"font-style:normal;\">sect.</span> Pinus''" },
		{ "P. sect. Pinus", "''P. <span style=\"font-style:normal;\">sect.</span> Pinus''" },
		{ "Pinus subsect. Pinus", "''Pinus <span style=\"font-style:normal;\">subsect.</span> Pinus''" },
		{ "P. subsect. Pinus", "''P. <span style=\"font-style:normal;\">subsect.</span> Pinus''" },
		{ "Quercus series Virentes", "''Quercus <span style=\"font-style:normal;\">ser.</span> Virentes''" },
		{ "Banksia subser. Banksia", "''Banksia <span style=\"font-style:normal;\">subser.</span> Banksia''" },
		{ "Banksia subseries Banksia", "''Banksia <span style=\"font-style:normal;\">subser.</span> Banksia''" },
		{ "Lyria (Mitraelyria)", "''Lyria <span style=\"font-style:normal;\">(</span>Mitraelyria<span style=\"font-style:normal;\">)</span>''" },
		"Below species",
		{ "Acer tataricum subsp. ginnala", "''Acer tataricum <span style=\"font-style:normal;\">subsp.</span> ginnala''" },
		{ "Aster ericoides var. ericoides", "''Aster ericoides <span style=\"font-style:normal;\">var.</span> ericoides''" },
		{ "A. ericoides varietas ericoides", "''A. ericoides <span style=\"font-style:normal;\">var.</span> ericoides''" },
		{ "A. e. subvar. ericoides", "''A. e. <span style=\"font-style:normal;\">subvar.</span> ericoides''" },
		"Hybrid symbol",
		{
			"Fragaria × ananassa",
			[[''Fragaria <span style="font-style:normal;">×</span> ananassa'']]
		},
		{
			"Fragaria &times; ananassa",
			[[''Fragaria <span style="font-style:normal;">×</span> ananassa'']]
		},
		{
			"Fragaria &#215; ananassa",
			[[''Fragaria <span style="font-style:normal;">×</span> ananassa'']]
		},
		{
			"× Sorbopyrus",
			[[''<span style="font-style:normal;">×</span> Sorbopyrus'']]
		},
		{
			"× Sorbopyrus auricularis",
			[[''<span style="font-style:normal;">×</span> Sorbopyrus auricularis'']]
		},
		"Already italicized",
		{ "''Pinus'' subsp. ''Pinus''", "''Pinus'' subsp. ''Pinus''" },
		{ "''Pinus subsp. Pinus''", "''Pinus subsp. Pinus''" }, -- Incorrect example!
		{ "''Pinus sylvestris''", "''Pinus sylvestris''" },
		{ "<i>Pinus</i> subsp. <i>Pinus</i>", "''Pinus'' subsp. ''Pinus''" },
		{ "<i>Pinus sylvestris</i>", "''Pinus sylvestris''" },
		"Easy examples",
		{ "Pinus", "''Pinus''" },
		{ "Pinus sylvestris", "''Pinus sylvestris''" },
		"Incorrect strings",
		{
			"Fragaria vesca subsp. vesca f. semperflorens",
			"''Fragaria vesca subsp. vesca f. semperflorens''"
		},
	}
	
	local italicizeTaxonName = require "Module:TaxonItalics".italicizeTaxonName
	
	self:iterate(examples,
		function (self, input, expected)
			output = clean(italicizeTaxonName(input))
			
			--[[
			if output ~= expected then
				mw.log(expected, output)
			end
			--]]
			
			self:equals(input, output, expected)
		end)
end

p["testcases for <code>italicizeTaxonName</code>"] = p.test_italicizeTaxonName
p.test_italicizeTaxonName = nil

return p