انتقل إلى المحتوى

وحدة:ar-nominals/testcases

من ويكاموس، القاموس الحر

-- Unit tests for [[Module:ar-nominals]]. Refresh page to run tests.
local tests = require('Module:UnitTests')
local ar_nominals = require('Module:ar-nominals')

local full_link = require('Module:links').full_link
local Arabic = require("Module:languages").getByCode("ar")
local rsub = mw.ustring.gsub
local u = mw.ustring.char

local BOGUS_CHAR = u(0xFFFD)
local HAMZA_PH = u(0xFFF0)

local function link(form)
	return full_link{term = form, lang = Arabic}
end

local function canon_hamza(form)
	form = rsub(form, "آ", HAMZA_PH .. "َا")
	form = rsub(form, "[ءأئؤ]", HAMZA_PH)
	return form
end

function tests:check_gen_plural(sg, form, outform)
	-- For given singular, detect the declension type ...
	local sgform, sgtype = ar_nominals.stem_and_type(sg, "", "", false, "sg", "noun")
	-- .. then pass in when we need to generate the plural
	local oform, oclass = ar_nominals.stem_and_type(form, sgform, sgtype, false, "pl", "noun")
	return self:equals(form .. " for " .. link(sg), oform, canon_hamza(outform) .. "/" .. ((Arabic:transliterate(outform)) or BOGUS_CHAR))
end

function tests:check_detect(form, outclass, ispl)
	local oform, oclass = ar_nominals.stem_and_type(form, "", "", false, ispl and "pl" or "sg", "noun")
	return self:equals((ispl and "plural " or "singular ") .. link(form), oclass, outclass)
end

function tests:test_decl_arabic()
	local examples1 = {
		{ "مرْآة", "sfp", "مرْأَيَات" },
		{ "مراة", "sfp", "مرَيَات" },
		{ "مَرَاة", "sfp", "مَرَيَات" },
		{ "مُسْتَشْفًى", "sfp", "مُسْتَشْفَيَات" },
		{ "كَاتٍ", "sfp", "كَاتِيَات" },
		{ "ذِكْرَى", "sfp", "ذِكْرَيَات" },
		{ "دُنْيَا", "sfp", "دُنْيَيَات" },
		{ "كَامِيرَا", "sfp", "كَامِيرَات" },
		{ "كُبْء", "sfp", "كُبْآت" },
		{ "كُوب", "sfp", "كُوبَات" },
	
		{ "كَاتٍ", "smp", "كَاتُون" },
		{ "كَتَأ", "smp", "كَتَؤُون" },
		{ "كَتِئ", "smp", "كَتِئُون" },
		{ "كُبْء", "smp", "كُبْؤُون" },
		{ "مُسْلِم", "smp", "مُسْلِمُون" },
	
		{ "كَتًى", "awnp", "كَتَوْن" },
	}
	
	self:iterate(examples1, "check_gen_plural")

	local examples2 = {
		{ "دُنْيَا", "inv" }, -- dunyā "world"
		{ "هَدَايَا", "inv", true }, -- hadāyā "gifts"
		{ "ذِكْرَى", "inv" }, -- ḏikrā "remembrance"
		{ "لِيبِيَا", "inv" }, -- lībiyā "Libya"
		{ "كَامِيرَا", "lwinv" }, -- kāmērā "camera"
		{ "لَيَالٍ", "diin", true }, -- layālin "nights"
		{ "مَآسٍ", "diin", true }, -- maʾāsin "tragedies, dramas"
		{ "أَيْدٍ", "triin", true }, -- ʾaydin "hands"
		{ "وَادٍ", "triin" }, -- wādin "valley"
		{ "مُسْتَشْفًى", "an" }, -- mustašfan "hospital"
		{ "عَصًا", "an" }, -- ʿaṣan "stick"
		{ "أَدْنَوْن", "awnp", true }, -- ʾadnawn "nearer (masc. pl.)"
		{ "أَدْنَوْنَ", "awnp", true }, -- ʾadnawna "nearer (masc. pl.)"
		{ "مُسْلِمُون", "smp", true }, -- muslimūn "Muslims"
		{ "مُسْلِمُونَ", "smp", true }, -- muslimūna "Muslims"
		{ "مُسْلِمَة", "tri" }, -- muslima "Muslim (fem.)"
		{ "مُسْلِمَةٌ", "tri" }, -- muslimatun "Muslim (fem.)"
		{ "مُسْلِمَات", "sfp", true }, -- muslimāt "Muslims (fem.)"
		{ "مُسْلِمَاتٌ", "sfp", true }, -- muslimāti "Muslims (fem.)"
		{ "فَوَاكِه", "di", true }, -- fawākih "fruits"
		{ "فَوَاكِهُ", "di", true }, -- fawākihu "fruits"
		{ "مَفَاتِيح", "di", true }, -- mafātīḥ "keys"
		{ "مَقَامّ", "di", true }, -- maqāmm "brooms"
		{ "مَقَامُّ", "di", true }, -- maqāmmu "brooms"
		{ "وُزَرَاء", "di", true }, -- wuzarāʾ "ministers"
		{ "أَصْدِقَاء", "di", true }, -- ʾaṣdiqāʾ "friends"
		{ "أَقِلَّاء", "di", true }, -- ʾaqillāʾ "small (masc. pl.)"
		{ "كَسْلَان", "di" }, -- kaslān "lazy"
		{ "قَمْرَاء", "di" }, -- qamrāʾ "moon-white, moonlight"
		{ "لَفَّاء", "di" }, -- laffāʾ "plump (fem.)"
		{ "أَحْمَر", "di" }, -- ʾaḥmar "red"
		{ "أَلَفّ", "di" }, -- ʾalaff "plump"
		{ "آلَم", "di" }, -- ʾālam "more painful"
		{ "كِتَاب", "tri" }, -- kitāb "book"
		{ "كُتُب", "tri", true }, -- kutub "books"
		{ "أَفْلَام", "tri", true }, -- ʾaflām "films"
	}
	self:iterate(examples2, "check_detect")
end
 
return tests