Module:km-pron/testcases

local tests = require('Module:UnitTests') local km_pron = require('Module:km-pron') local test_data = require('Module:km-pron/testcases/data')

local function tag_IPA(IPA) return ' ' .. IPA .. ' ' end local function tag_khmer(Khmer) return ' ' .. Khmer .. ' ' end

local function link(khmer, respelling) return tag_khmer("" .. khmer .. "") .. (respelling and " (respelling: " .. tag_khmer(respelling) .. ") " or "") end

function tests:do_test_syllabify(khmer, syllabified, respelling) self:equals(link(khmer, respelling), tag_khmer(km_pron.syllabify(respelling or khmer)), tag_khmer(syllabified)) end

function tests:do_test_ipa(khmer, pronunciation, respelling) self:equals(link(khmer, respelling), tag_IPA(km_pron.convert(respelling or khmer, "ipa")), tag_IPA(pronunciation)) end

function tests:do_test_transcript(khmer, transcription, respelling) self:equals(link(khmer, respelling), tag_IPA(km_pron.convert(respelling or khmer, "tc")), tag_IPA(transcription)) end

function tests:test_syllabify for _, data in pairs(test_data) do		self:do_test_syllabify(data.word, data.syllabified, data.respelling) end end

function tests:test_ipa for _, data in pairs(test_data) do		self:do_test_ipa(data.word, data.ipa, data.respelling) end end

function tests:test_transcript for _, data in pairs(test_data) do		self:do_test_transcript(data.word, data.transcription, data.respelling) end end

return tests