Module:User:Chernorizets/bg-orthography/testcases

From Wiktionary, the free dictionary
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

All tests passed. (refresh)

TextExpectedActual
test_is_valid:
is_valid(nil, nil)
Passedreturn valuefalsefalse
Passedfailed ruleno inputno input
is_valid(, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(nil, { nil_is_valid })
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(колан, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(Станислав, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(КОРЕКОМ, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(бърЗовар, nil)
Passedreturn valuefalsefalse
Passedfailed rulevalid letter casevalid letter case
is_valid(ОрангутаН, nil)
Passedreturn valuefalsefalse
Passedfailed rulevalid letter casevalid letter case
is_valid(траЛалаЛА, nil)
Passedreturn valuefalsefalse
Passedfailed rulevalid letter casevalid letter case
is_valid(БЬОРК, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(Бьорк, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(миньор, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(бельо, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(Ьордан, nil)
Passedreturn valuefalsefalse
Passedfailed rulecorrect use of ьЬcorrect use of ьЬ
is_valid(ьерархия, nil)
Passedreturn valuefalsefalse
Passedfailed rulecorrect use of ьЬcorrect use of ьЬ
is_valid(конь, nil)
Passedreturn valuefalsefalse
Passedfailed rulecorrect use of ьЬcorrect use of ьЬ
is_valid(коьот, nil)
Passedreturn valuefalsefalse
Passedfailed rulecorrect use of ьЬcorrect use of ьЬ
is_valid(ваььар, nil)
Passedreturn valuefalsefalse
Passedfailed rulecorrect use of ьЬcorrect use of ьЬ
is_valid(Facebook, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(VIP, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(TOEFL, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(Туитър, nil)
Passedreturn valuetruetrue
Passedfailed rule(nil)(nil)
is_valid(Fейсбук, nil)
Passedreturn valuefalsefalse
Passedfailed ruleno alphabet mixingno alphabet mixing
is_valid(VIП, nil)
Passedreturn valuefalsefalse
Passedfailed ruleno alphabet mixingno alphabet mixing
is_valid(караванaта, nil)
Passedreturn valuefalsefalse
Passedfailed ruleno alphabet mixingno alphabet mixing
is_valid(окoкорихме, nil)
Passedreturn valuefalsefalse
Passedfailed ruleno alphabet mixingno alphabet mixing
TextExpectedActual
test_malformed_input:
Passedis_valid(3.14): error{message="Input must be a string!", status=false}{message="Input must be a string!", status=false}
Passedis_valid(true): error{message="Input must be a string!", status=false}{message="Input must be a string!", status=false}
Passedis_valid(function): error{message="Input must be a string!", status=false}{message="Input must be a string!", status=false}
Passedis_valid(table): error{message="Input must be a string!", status=false}{message="Input must be a string!", status=false}

local tests = require("Module:UnitTests")

local m_ortho = require("Module:User:Chernorizets/bg-orthography")
local is_valid = m_ortho.is_valid

local test_cases = {
	{ word = nil, expected_ret = false, expected_rule = "no input" },
	{ word = "", expected_ret = true, expected_rule = nil },

	{
		word = nil,
		opts = { nil_is_valid = true },
		opts_hint = "{ nil_is_valid }",
		expected_ret = true,
		expected_rule = nil
	},

	-- Valid letter case.
	{ word = "колан", expected_ret = true, expected_rule = nil },
	{ word = "Станислав", expected_ret = true, expected_rule = nil },
	{ word = "КОРЕКОМ", expected_ret = true, expected_rule = nil },

	-- Invalid letter case
	{ word = "бърЗовар", expected_ret = false, expected_rule = "valid letter case" },
	{ word = "ОрангутаН", expected_ret = false, expected_rule = "valid letter case" },
	{ word = "траЛалаЛА", expected_ret = false, expected_rule = "valid letter case" },
	
	-- Valid use of Ьь
	{ word = "БЬОРК", expected_ret = true, expected_rule = nil },
	{ word = "Бьорк", expected_ret = true, expected_rule = nil },
	{ word = "миньор", expected_ret = true, expected_rule = nil },
	{ word = "бельо", expected_ret = true, expected_rule = nil },
	
	-- Invalid use of Ьь
	{ word = "Ьордан", expected_ret = false, expected_rule = "correct use of ьЬ" },
	{ word = "ьерархия", expected_ret = false, expected_rule = "correct use of ьЬ" },
	{ word = "конь", expected_ret = false, expected_rule = "correct use of ьЬ" },
	{ word = "коьот", expected_ret = false, expected_rule = "correct use of ьЬ" },
	{ word = "ваььар", expected_ret = false, expected_rule = "correct use of ьЬ" },
	
	-- No alphabet mixing.
	{ word = "Facebook", expected_ret = true, expected_rule = nil },
	{ word = "VIP", expected_ret = true, expected_rule = nil },
	{ word = "TOEFL", expected_ret = true, expected_rule = nil },
	{ word = "Туитър", expected_ret = true, expected_rule = nil },
	
	-- Some alphabet mixing
	{ word = "Fейсбук", expected_ret = false, expected_rule = "no alphabet mixing" },
	{ word = "VIП", expected_ret = false, expected_rule = "no alphabet mixing" },
	-- Some of the a's and o's below are Latin vs. Cyrillic (tough to spot)
	{ word = "караванaта", expected_ret = false, expected_rule = "no alphabet mixing" },
	{ word = "окoкорихме", expected_ret = false, expected_rule = "no alphabet mixing" },
}

local function make_heading(test_case)
	local word, opts = test_case.word, test_case.opts
	local word_arg = word and word or "nil"
	local opts_arg = opts and test_case.opts_hint or "nil"
	
	return ("is_valid(%s, %s)"):format(word_arg, opts_arg)
end

function tests:check_single_case(test_case)
	local ret, rule = is_valid(test_case.word, test_case.opts)
	
	tests:header(make_heading(test_case))
	tests:equals("return value", ret, test_case.expected_ret)
	tests:equals("failed rule", rule, test_case.expected_rule)
end

function tests:test_is_valid()
	for _, test_case in ipairs(test_cases) do
		tests:check_single_case(test_case)
	end
end

local malformed_input_cases = {
	3.14, -- number
	true, -- boolean
	function(a, b) return a + b end, -- function
	{}, -- table
}

function tests:check_malformed_input(input)
	local status, message = pcall(is_valid, input)
	
	local ret = {
		status = status,
		message = mw.ustring.gsub(message, "(.-): (.*)", "%2")
	}
	
	tests:equals_deep("is_valid(" .. tostring(input) .. "): error", ret, {
		status = false,
		message = "Input must be a string!"
	})
end

function tests:test_malformed_input()
	for _, input in ipairs(malformed_input_cases) do
		tests:check_malformed_input(input)
	end
end

return tests