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

return p