Module:ja-headword/sandbox/testcases

All tests passed. (refresh)

Text Expected Actual
test_get_historical_hira_categories:
Passed 味わう:
あじわい (ajiwai) ← あぢはひ (adifafi)
Japanese terms in which may have changed to Japanese terms in which may have changed to
Passed 味わい:
あじわう (ajiwau) ← あぢはふ (adifafu)
Japanese terms in which may have changed to Japanese terms in which may have changed to
Passed :
きょう (kyō) ← きやう (kyau)
Japanese terms that underwent monophthongization Japanese terms that underwent monophthongization
Passed :
しょう (shō) ← しやう (syau)
Japanese terms that underwent monophthongization Japanese terms that underwent monophthongization

local tests = require "Module:UnitTests"
local m_ja_headword = require "Module:ja-headword/sandbox"
local m_ja = require "Module:ja"
local kanji_pattern = require "Module:scripts/data".Hani.characters
local hira_pattern = require "Module:scripts/data".Hira.characters

local function show_word(word, is_historical)
	local tr
	if not mw.ustring.find(word, "[" .. kanji_pattern .. "]") then
		tr = m_ja.kana_to_romaji(word, is_historical and { hist = true } or nil)
	end
	
	return '<span class="Jpan" lang="ja">[[' .. word .. '#Japanese|' .. word .. ']]</span>'
		.. (tr and ' (' .. tr .. ')' or '')
end

local function format_modern_historical_title(modern, historical, title)
	return (title and show_word(title) .. ":<br>" or "")
		.. show_word(modern) .. " &larr; " .. show_word(historical, true)
end

local function format_categories(categories)
	local ret = mw.ustring.gsub(
		table.concat(categories, ", "),
		"[" .. hira_pattern .. "]+",
		'<span class="Hira" lang="ja">%0</span>')
	return ret
end

function tests:test_get_historical_hira_categories()
	local examples = {
		-- modern, historical, categories, page title
		{ "あじわい", "あぢはひ", { "Japanese terms in which は may have changed to わ" }, "味わう" },
		{ "あじわう", "あぢはふ", { "Japanese terms in which は may have changed to わ" }, "味わい" },
		{ "きょう", "きやう", { "Japanese terms that underwent monophthongization" }, "京" }, -- Better category name?
		{ "しょう", "しやう", { "Japanese terms that underwent monophthongization" }, "荘" },
	}
	
	self:iterate(
		examples,
		function (self, modern, historical, categories, title)
			self:equals(
				format_modern_historical_title(modern, historical, title),
				format_categories(m_ja_headword.get_historical_hira_categories(modern, historical)),
				format_categories(categories))
		end)
end

return tests