Module:TaxonItalics/testcases

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 &#x3c;span style=\"font-style:normal;\"&#x3e;subg.&#x3c;/span&#x3e; Pinus" }, { "Pinus subgenus Pinus", "Pinus &#x3c;span style=\"font-style:normal;\"&#x3e;subg.&#x3c;/span&#x3e; Pinus" }, { "P. subg. Pinus", "P. &#x3c;span style=\"font-style:normal;\"&#x3e;subg.&#x3c;/span&#x3e; Pinus" }, { "Passiflora supersect. Tacsonia", "Passiflora &#x3c;span style=\"font-style:normal;\"&#x3e;supersect.&#x3c;/span&#x3e; Tacsonia" }, { "Pinus sect. Pinus", "Pinus &#x3c;span style=\"font-style:normal;\"&#x3e;sect.&#x3c;/span&#x3e; Pinus" }, { "Pinus section Pinus", "Pinus &#x3c;span style=\"font-style:normal;\"&#x3e;sect.&#x3c;/span&#x3e; Pinus" }, { "P. sect. Pinus", "P. &#x3c;span style=\"font-style:normal;\"&#x3e;sect.&#x3c;/span&#x3e; Pinus" }, { "Pinus subsect. Pinus", "Pinus &#x3c;span style=\"font-style:normal;\"&#x3e;subsect.&#x3c;/span&#x3e; Pinus" }, { "P. subsect. Pinus", "P. &#x3c;span style=\"font-style:normal;\"&#x3e;subsect.&#x3c;/span&#x3e; Pinus" }, { "Quercus series Virentes", "Quercus &#x3c;span style=\"font-style:normal;\"&#x3e;ser.&#x3c;/span&#x3e; Virentes" }, { "Banksia subser. Banksia", "Banksia &#x3c;span style=\"font-style:normal;\"&#x3e;subser.&#x3c;/span&#x3e; Banksia" }, { "Banksia subseries Banksia", "Banksia &#x3c;span style=\"font-style:normal;\"&#x3e;subser.&#x3c;/span&#x3e; Banksia" }, { "Lyria (Mitraelyria)", "Lyria &#x3c;span style=\"font-style:normal;\"&#x3e;(&#x3c;/span&#x3e;Mitraelyria&#x3c;span style=\"font-style:normal;\"&#x3e;)&#x3c;/span&#x3e;" }, "Below species", { "Acer tataricum subsp. ginnala", "Acer tataricum &#x3c;span style=\"font-style:normal;\"&#x3e;subsp.&#x3c;/span&#x3e; ginnala" }, { "Aster ericoides var. ericoides", "Aster ericoides &#x3c;span style=\"font-style:normal;\"&#x3e;var.&#x3c;/span&#x3e; ericoides" }, { "A. ericoides varietas ericoides", "A. ericoides &#x3c;span style=\"font-style:normal;\"&#x3e;var.&#x3c;/span&#x3e; ericoides" }, { "A. e. subvar. ericoides", "A. e. &#x3c;span style=\"font-style:normal;\"&#x3e;subvar.&#x3c;/span&#x3e; ericoides" }, "Hybrid symbol", {			"Fragaria × ananassa", ''Fragaria & },		{			"Fragaria &#x26;times; ananassa", ''Fragaria & },		{			"Fragaria &#x26;#215; ananassa", ''Fragaria & },		{			"× Sorbopyrus", ''& },		{			"× Sorbopyrus auricularis", ''& },		"Already italicized", { "Pinus subsp. Pinus", "Pinus subsp. Pinus" }, { "Pinus subsp. Pinus", "Pinus subsp. Pinus" }, -- Incorrect example! { "Pinus sylvestris", "Pinus sylvestris" }, { "&#x3c;i&#x3e;Pinus&#x3c;/i&#x3e; subsp. &#x3c;i&#x3e;Pinus&#x3c;/i&#x3e;", "Pinus subsp. Pinus" }, { "&#x3c;i&#x3e;Pinus sylvestris&#x3c;/i&#x3e;", "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 &#x3c;code&#x3e;italicizeTaxonName&#x3c;/code&#x3e;"] = p.test_italicizeTaxonName p.test_italicizeTaxonName = nil

return p