Module:User:Kutchkutch/mr-decl/testcases

local tests = require('Module:UnitTests')

local m_links = require("Module:links") local lang = require("Module:languages").getByCode("mr") local m_scripts = require("Module:scripts") local m_decl_noun = require('Module:User:Kutchkutch/mr-decl')

local frame = mw.getCurrentFrame local ti = table.insert local gsub = mw.ustring.gsub

local dialect_name = { mr = 'Marathi', } -- local casetc = {'nom. s.', 'nom. p.', 'obl. s.', 'obl. p.'} local casetc = {dirs = 'nom. s.', dirp = 'nom. p,', obls = 'obl. s.', oblp = 'obl. p.', dats = 'dat. s.', datp = 'dat. s.', ergs = 'erg. s.', ergp = 'erg. p.', inss = 'ins. s.', insp = 'ins. p.', locs = 'loc. s.', locp = 'loc. p.', vocs = 'voc. s.', vocp = 'voc. p.', gso = 'gen. obl. s.', gpo = 'gen. obl. p.', -- I hope the numbers are the right way round! gsns = 'gen. s. n. s.', gsms = 'gen. s. m. s.', gsfs = 'gen. s. f. s.', gsnp = 'gen. s. n. p.', gsmp = 'gen. s. m. p.', gsfp = 'gen. s. f. p.', gpns = 'gen. p. n. s.', gpms = 'gen. p. m. s.', gpfs = 'gen. p. f. s.', gpnp = 'gen. p. n. p.', gpmp = 'gen. p. m. p.', gpfp = 'gen. p. f. p.', } local detail_items = { -- First element is one of the following: -- 'dialect' selects dialect to be tested. -- 'm', 'f' or 'n', which gives word and gender. -- Case form code, which selects case and number to compare and -- gives expected form, both native script and Wiktionary Romanisation. {"dialect", "mr"}, {'heading', "test tests"}, {'datp', {"गागा", "zebra"}}, --Deliberately wrong, to test tests.

{'heading', "Primary Tags"}, {'heading', "marked masc cons-stem"}, {"m", "हात"}, {'dirs', {"हात", "hāt"}}, {'dirp', {"हात", "hāt"}}, {'obls', {"हाता", "hātā"}}, {'dats', {"हाताला", "hātālā"}}, {'datp', {"हातांना", "hātānnā"}}, {'ergs', {"हाताने", "hātāne"}}, {'ergp', {"हातांनी", "hātānnī"}}, {'gsns', {"हाताच़े", "hātāċe"}, {"हाताच़ं", "hātāċa"}}, {'gpns', {"हातांच़े", "hātāñċe"}, {"हातांच़ं", "hātāñċa"}}, {'heading', "marked fem-e cons-stem"}, {"f-e", "वाट"}, {'dirs', {"वाट", "vāṭ"}}, {'dirp', {"वाटा", "vāṭā"}}, {'obls', {"वाटे", "vāṭe"}}, {'oblp', {"वाटां", "vāṭā̃"}}, {'heading', "marked fem cons-stem"}, {"f", "नात"}, {'dirs', {"नात", "nāt"}}, {'dirp', {"नाती", "nātī"}}, {'obls', {"नाती", "nātī"}}, {'oblp', {"नातीं", "nātī̃"}}, {'heading', "marked neut cons-stem"}, {"n", "घर"}, {'dirs', {"घर", "ghar"}}, {'dirp', {"घरे", "ghare"}, {"घरं", "ghara"}}, {'obls', {"घरा", "gharā"}}, {'oblp', {"घरां", "gharā̃"}}, {'heading', "marked masc ā-stem"}, {"m", "माळा"}, {'dirs', {"माळा", "māḷā"}}, {'dirp', {"माळे", "māḷe"}}, {'obls', {"माळ्या", "māḷyā"}}, {'oblp', {"माळ्यां", "māḷyā̃"}}, {'heading', "marked fem ā-stem"}, {"f", "शाळा"}, {'dirs', {"शाळा", "śāḷā"}}, {'dirp', {"शाळा", "śāḷā"}}, {'obls', {"शाळे", "śāḷe"}}, {'oblp', {"शाळां", "śāḷā̃"}}, {'heading', "marked masc ī-stem"}, {"m", "शिंपी"}, {'dirs', {"शिंपी", "śimpī"}}, {'dirp', {"शिंपी", "śimpī"}}, {'obls', {"शिंप्या", "śimpyā"}}, {'oblp', {"शिंप्यां", "śimpyā̃"}}, {'heading', "marked feminine ī-stem"}, {"f", "गाडी"}, {'dirs', {"गाडी", "gāḍī"}}, {'dirp', {"गाड्या", "gāḍyā"}}, {'obls', {"गाडी", "gāḍī"}}, {'oblp', {"गाड्यां", "gāḍyā̃"}}, {'heading', "marked neut ī-stem"}, {"n", "दही"}, {'dirs', {"दही", "dahī"}}, {'dirp', {"दही", "dahī"}}, {'obls', {"दह्या", "dahyā"}}, {'oblp', {"दह्यां", "dahyā̃"}}, {'heading', "marked masc ū-stem"}, {"m", "नातू"}, {'dirs', {"नातू", "nātū"}}, {'dirp', {"नातू", "nātū"}}, {'obls', {"नातवा", "nātvā"}}, {'oblp', {"नातवां", "nātvā̃"}}, {'heading', "marked fem ū-stem (obsolete)"}, {"f", "सासू"}, {'dirs', {"सासू", "sāsū"}}, {'dirp', {"सासवा", "sāsvā"}}, {'obls', {"सासवे", "sāsve"}}, {'oblp', {"सासवां", "sāsvā̃"}}, {'heading', "marked neut ū-stem"}, {"n", "तारू"}, {'dirs', {"तारू", "tārū"}}, {'dirp', {"तारवे", "tārve"}, {"तारवं", "tārva"}}, {'obls', {"तारवा", "tārvā"}}, {'oblp', {"तारवां", "tārvā̃"}}, {'heading', "masc r-stem"}, {"m", "भर्तृ"}, {'dirs', {"भर्तृ", "bhartru"}}, {'dirp', {"भर्तृ", "bhartru"}}, {'obls', {"भर्तृ", "bhartru"}}, {'oblp', {"भर्तृं", "bhartrũ"}}, {'heading', "feminine r-stem"}, {"f", "मातृ"}, {'dirs', {"मातृ", "mātru"}}, {'dirp', {"मातृ", "mātru"}}, {'obls', {"मातृ", "mātru"}}, {'oblp', {"मातृं", "mātrũ"}}, {'heading', "fem ai-stem"}, {"f", "पै"}, {'dirs', {"पै", "pai"}}, {'dirp', {"पया", "payā"}}, {'obls', {"पया", "payā"}}, {'oblp', {"पयां", "payā̃"}}, {'heading', "masc o-stem"}, {"m", "धनको"}, {'dirs', {"धनको", "dhanko"}}, {'dirp', {"धनको", "dhanko"}}, {'obls', {"धनको", "dhanko"}}, {'oblp', {"धनकों", "dhankõ"}}, {'heading', "feminine o-stem"}, {"f", "बायको"}, {'dirs', {"बायको", "bāyko"}}, {'dirp', {"बायका", "bāykā"}}, {'obls', {"बायको", "bāyko"}}, {'oblp', {"बायकां", "bāykā̃"}},

{'heading', "Subtags of masc cons-stem"}, {'heading', "masc unmarked dependent-ī cons-stem (monosyllabic)"}, {"m", "वीर"}, {'dirs', {"वीर", "vīr"}}, {'dirp', {"वीर", "vīr"}}, {'obls', {"वीरा", "vīrā"}}, {'oblp', {"वीरां", "vīrā̃"}}, {'heading', "masc weakened dependent-ī cons-stem (polysyllabic)"}, {"m", "वकील", {["weaken_iu"] = "true"}}, {'dirs', {"वकील", "vakīl"}}, {'dirp', {"वकील", "vakīl"}}, {'obls', {"वकिला", "vakilā"}}, {'oblp', {"वकिलां", "vakilā̃"}}, {'heading', "masc unmarked dependent-ū cons-stem (monosyllabic)"}, {"m", "शूर"}, {'dirs', {"शूर", "śūr"}}, {'dirp', {"शूर", "śūr"}}, {'obls', {"शूरा", "śūrā"}}, {'oblp', {"शूरां", "śūrā̃"}}, {'heading', "masc weakened dependent-ū cons-stem (polysyllabic)"}, {"m", "कारकून", {["weaken_iu"] = "true"}}, {'dirs', {"कारकून", "kārkūn"}}, {'dirp', {"कारकून", "kārkūn"}}, {'obls', {"कारकुना", "kārkunā"}}, {'oblp', {"कारकुनां", "kārkunā̃"}}, {'heading', "masc weakened independent-ī cons-stem"}, {"m", "पाईक", {["weaken_iu"] = "true"}}, {'dirs', {"पाईक", "pāīk"}}, {'dirp', {"पाईक", "pāīk"}}, {'obls', {"पाइका", "pāikā"}}, {'oblp', {"पाइकां", "pāikā̃"}}, {'heading', "masc weakened independent-ī cons-stem (polysyllabic)"}, {"m", "नातेवाईक", {["weaken_iu"] = "true"}}, {'dirs', {"नातेवाईक", "nātevāīk"}}, {'dirp', {"नातेवाईक", "nātevāīk"}}, {'obls', {"नातेवाइका", "nātevāikā"}}, {'oblp', {"नातेवाइकां", "nātevāikā̃"}}, {'heading', "masc weakened independent-ū cons-stem (monosyllabic)"}, {"m", "ऊस", {["weaken_iu"] = "true"}}, {'dirs', {"ऊस", "ūs"}}, {'dirp', {"ऊस", "ūs"}}, {'obls', {"उसा", "usā"}}, {'oblp', {"उसां", "usā̃"}}, {'heading', "masc weakened independent-ū cons-stem"}, {"m", "राऊत", {["weaken_iu"] = "true"}}, {'dirs', {"राऊत", "rāūt"}}, {'dirp', {"राऊत", "rāūt"}}, {'obls', {"राउता", "rāutā"}}, {'oblp', {"राउतां", "rāutā̃"}},

{'heading', "Subtags of fem-e cons-stem"}, {'heading', "fem-e weakened dependent-ī cons-stem (polysyllabic)"}, {"f-e", "मोहीम", {["weaken_iu"] = "true"}}, {'dirs', {"मोहीम", "mohīm"}}, {'dirp', {"मोहिमा", "mohimā"}}, {'obls', {"मोहिमे", "mohime"}}, {'oblp', {"मोहिमां", "mohimā̃"}}, {'heading', "fem-e weakened independent-ī cons-stem (monosyllabic)"}, {"f-e", "ईद", {["weaken_iu"] = "true"}}, {'dirs', {"ईद", "īd"}}, {'dirp', {"इदा", "idā"}}, {'obls', {"इदे", "ide"}}, {'oblp', {"इदां", "idā̃"}},

{'heading', "Subtags of fem cons-stem"}, {'heading', "fem weakened dependent-ū cons-stem (polysyllabic)"}, {"f", "कसूर", {["weaken_iu"] = "true"}}, {'dirs', {"कसूर", "kasūr"}}, {'dirp', {"कसुरी", "kasurī"}}, {'obls', {"कसुरी", "kasurī"}}, {'oblp', {"कसुरीं", "kasurī̃"}}, {'heading', "fem weakened independent-ī cons-stem (monosyllabic)"}, {"f", "ईद", {["weaken_iu"] = "true"}}, {'dirs', {"ईद", "īd"}}, {'dirp', {"इदी", "idī"}}, {'obls', {"इदी", "idī"}}, {'oblp', {"इदीं", "idī̃"}}, {'heading', "fem weakened independent-ī cons-stem (monosyllabic)"}, {"f", "पंचाईत", {["weaken_iu"] = "true"}}, {'dirs', {"पंचाईत", "pañcāīt"}}, {'dirp', {"पंचाइती", "pañcāitī"}}, {'obls', {"पंचाइती", "pañcāitī"}}, {'oblp', {"पंचाइतीं", "pañcāitī̃"}},

{'heading', "Subtags of neut cons-stem"}, {'heading', "neut unmarked dependent-ī cons-stem (polysyllabic)"}, {"n", "गणित"}, {'dirs', {"गणित", "gaṇit"}}, {'dirp', {"गणिते", "gaṇite"}, {"गणितं", "gaṇita"}}, {'obls', {"गणिता", "gaṇitā"}}, {'oblp', {"गणितां", "gaṇitā̃"}}, {'heading', "neut weakened dependent-ī cons-stem (polysyllabic)"}, {"n", "बक्षीस", {["weaken_iu"] = "true"}}, {'dirs', {"बक्षीस", "bakṣīs"}}, {'dirp', {"बक्षिसे", "bakṣise"}, {"बक्षिसं", "bakṣisa"}}, {'obls', {"बक्षिसा", "bakṣisā"}}, {'oblp', {"बक्षिसां", "bakṣisā̃"}}, {'heading', "neut weakened dependent-ū cons-stem (polysyllabic)"}, {"n", "वारूळ", {["weaken_iu"] = "true"}}, {'dirs', {"वारूळ", "vārūḷ"}}, {'dirp', {"वारुळे", "vāruḷe"}, {"वारुळं", "vāruḷa"}}, {'obls', {"वारुळा", "vāruḷā"}}, {'oblp', {"वारुळां", "vāruḷā̃"}}, {'heading', "neut weakened independent-ī cons-stem (polysyllabic)"}, {"n", "गिऱ्हाईक", {["weaken_iu"] = "true"}}, {'dirs', {"गिऱ्हाईक", "girhāīk"}}, {'dirp', {"गिऱ्हाइके", "girhāike"}, {"गिऱ्हाइकं", "girhāika"}}, {'obls', {"गिऱ्हाइका", "girhāikā"}}, {'oblp', {"गिऱ्हाइकां", "girhāikā̃"}},

{'heading', "Subtags of masc ā-stem"}, {'heading', "sg-only masc ā-stem"}, {"m", "गोवा", {["number"] = "sg-only"}}, {'dirs', {"गोवा", "govā"}}, {'dirp', {"-", "-"}}, {'obls', {"गोव्या", "govyā"}}, {'oblp', {"-", "-"}}, {'heading', "masc rā-stem"}, {"m", "मोगरा"}, {'dirs', {"मोगरा", "mogrā"}}, {'dirp', {"मोगरे", "mogre"}}, {'obls', {"मोगऱ्या", "mogaryā"}}, {'oblp', {"मोगऱ्यां", "mogaryā̃"}}, }

function tests:test_details local word = "माळा" local sc = m_scripts.findBestScript(word, lang) local forms, translit_forms, stem, actual, exp local dialect = "mr" local gender ='m'; local options = local forms_got = false local formno forms = m_decl_noun.forms(word, gender) forms = m_decl_noun.forms('गागा', 'm') -- Just to get list of forms. for i, v in ipairs(detail_items) do		if v[1] == 'dialect' then dialect = v[2] forms_got = false elseif v[1] == 'heading' then tests:heading(v[2]) elseif v[1] == 'm' or v[1] == 'f' or v[1] == 'f-e' or v[1] == 'n' then gender = v[1] word = v[2] options = v[3] forms, translit_forms = m_decl_noun.forms(word, gender, options) -- Just in case nouns sometimes lack forms and -- this is not expressed by an empty list. forms_got = true elseif forms[v[1]] then formno = v[1] exp = {} for j = 2, #v do				if j ~= 2 then ti(exp, 'or ') end ti(exp, v[j][1]) ti(exp, ' (')				ti(exp, v[j][2]) -- Do we actually want to check transliterations?				ti(exp, ') ') end exp = table.concat(exp)

if not forms_got then forms, translit_forms = m_decl_noun.forms(word, gender) forms_got = true -- Local optimisation end actual = {} for j = 1, #forms[v[1]] do				if j ~= 1 then ti(actual, 'or ') end ti(actual, forms[v[1]][j]) ti(actual, ' (')				ti(actual, translit_forms[v[1]][j])				ti(actual, ') ') end actual = table.concat(actual) local name = {} ti(name, )			ti(name, lang:transliterate(word, sc))			ti(name, ) ti(name, ' ') ti(name, casetc[formno]) name = table.concat(name) -- Compare and report. -- Method summary: equals(name, actual, expected, options) tests:equals(name, actual, exp, {show_difference = true}) else error('Test item '..i..' has invalid first element '..v[1]) end end end

return tests