Module:accel/grc/testcases

local tests = require "Module:UnitTests" local m_accel = require "Module:accel" local m_grc_accel = require "Module:accel/grc" local m_fun = require "Module:fun" local m_table = require "Module:table" local sorted_pairs = m_table.sortedPairs local invert = m_table.invert local grc = require "Module:languages".getByCode "grc" local full_link = require "Module:links".full_link local Array = require "Module:array"

local examples = { {		{ target = "βελτῑ́ων", form = "comparative", pos = "adjective", origin = "ᾰ̓γᾰθός" }, {			pronunc = "", pos_header = "Adjective", head = "", def = "", declension = "", },	},	{		{ target = "βέλτῐστος", form = "superlative", pos = "adjective", origin = "ᾰ̓γᾰθός" }, {			pronunc = "", pos_header = "Adjective", head = "", def = "", declension = "", },	},	{		{ target = "βεβηκώς", form = "m|perf|part", pos = "verb", origin = "βαίνω" }, {			pronunc = "", pos_header = "Participle", head = "", def = "", declension = "", },	},	{		{ target = "βεβηκυῖᾰ", form = "f|perf|part", pos = "verb", origin = "βαίνω" }, {			pronunc = "", pos_header = "Participle", head = "", def = "", },	}, }

-- So that fields in "entry" are displayed in the same order in which they will -- appear in the resulting entry. local param_order = m_table.invert { "pronunc", "pos_header", "head", "def", -- entry "inflection", "declension", "conjugation", "mutation" }

local function compare_entry_params(param1, param2) return param_order[param1] < param_order[param2] end

local function format(entry) local output = Array for k, v in sorted_pairs(entry, compare_entry_params) do output:insert(k .. ": " .. mw.text.nowiki(v)) end return mw.ustring.toNFC(output:concat "\n") end

-- Put wikitext in code tags. Replace newlines with br tags. local function display(entry_printed) mw.log(entry_printed) entry_printed = entry_printed:gsub("%f[^\n%z](.-: )([^\n]+)", "%1 ") entry_printed = table.concat(		m_fun.map( function (entry) return '' .. entry .. ' '			end, mw.text.split(entry_printed, "\n"))) return entry_printed end

local function tag_and_link(word) return full_link { lang = grc, term = word, tr = "-" } end

-- Link origin and target. local function show_params(params) return ("%s (%s) &rarr; %s ") :format(tag_and_link(params.origin), params.pos,			tag_and_link(params.target), params.form) end

local options = { display = display }

function tests:test self:iterate(		examples,		function (self, params, expected_entry)			params.lang = "grc"			params.target_pagename = (grc:makeEntryName(params.target))			local entry = m_accel.default_entry(params)			m_grc_accel.generate(params, entry)			mw.logObject(entry)			self:equals(show_params(params), format(entry), format(expected_entry), options)		end) end

return tests