Module:la-verb/testcases

local export = {}

local Array = require "Module:array"

local function get_tab_separated_words(text) local res = Array for line in text:gmatch "[^\n]+" do		local words = Array res:insert(words) for word in line:gmatch "[^\t]+" do			words:insert(word) end end return res end

-- COMBINING MACRON: \204\132 -- COMBINING BREVE: \204\134 local function strip_macrons_and_breves(term) return mw.ustring.toNFC(mw.ustring.toNFD(term):gsub("\204[\132\134]", "")) end

local function ends_with(str, pattern) return str:find(pattern .. "$") ~= nil end

local has_perf_in_s_or_x = {} has_perf_in_s_or_x[1] = function (pres_stem, perf_stem) if pres_stem == perf_stem then return false end local perf_without_s_or_x, replacements = perf_stem:gsub("[sx]$", "") return replacements == 1 and strip_macrons_and_breves(pres_stem) :find(strip_macrons_and_breves(perf_without_s_or_x), 1, true) == 1 end

has_perf_in_s_or_x[2] = function (pres_stem, perf_stem) if pres_stem == perf_stem then return false end return ends_with(perf_stem, "[sx]") end

has_perf_in_s_or_x[3] = function (pres_stem, perf_stem) if pres_stem == perf_stem then return false end return ends_with(perf_stem, "[sx]") and not ends_with(pres_stem, "[sx]") end

function export.show(frame) local pres_and_perf_list = require "Module:la-verb/testcases/data" local output = Array for _, pres_and_perf in pairs(pres_and_perf_list) do		local pres, perf = unpack(pres_and_perf) local matches = Array for i, rule in ipairs(has_perf_in_s_or_x) do			if rule(pres, perf) then matches:insert(i) end end if #matches > 0 then output:insert("* " .. pres .. ", " .. perf .. " (" .. matches:concat ", " .. ")")		end end return output:concat "\n" end

return export