Jump to content

Module:User:Erutuon/patterns/testcases

From Wiktionary, the free dictionary

All tests passed. (refresh)

TextExpectedActual
test canUseString:
Passed"(%=%=+)([^%=]+)%=%=+"🗸true🗸true
Passed"αειου"🗸true🗸true
Passed"[αειου]"🗴false🗴false
Passed"%[%%%s%]"🗴false🗴false
Passed"%[αειου%]"🗸true🗸true
Passed"[ae][ʊɪ]"🗴false🗴false
Passed"a?"🗸true🗸true
Passed"α?"🗴false🗴false
Passed"a*"🗸true🗸true
Passed"α*"🗴false🗴false
Passed"a-"🗸true🗸true
Passed"α-"🗴false🗴false
Passed"a+"🗸true🗸true
Passed"α+"🗴false🗴false
Passed"a.b"🗴false🗴false

local tests = require("Module:UnitTests")

local canUseString = require("Module:User:Erutuon/patterns").canUseString

local highlight = require("Module:debug").highlight

highlight = highlight{ inline = true }
local function LuaString(text)
	return highlight('"' .. text .. '"')
end

local function displayBoolean(text)
	local color, emoji
	if text == "false" then
		color = "red"
		emoji = "🗴"
	elseif text == "true" then
		color = "green"
		emoji = "🗸"
	end
	return emoji .. '<code><span style="color: ' .. (color or '') .. ';">' .. text .. '</span></code>'
end

local options = { display = displayBoolean }
function tests:check(example, expected)
	self:equals(LuaString(example), canUseString(example), expected, options)
end

tests["test canUseString"] = function (self)
	local examples = {
		{ "(%=%=+)([^%=]+)%=%=+", true }, -- section heading
		{ "αειου", true },
		{ "[αειου]", false }, -- Greek lowercase vowel letter
		{ "%[%%%s%]", false },
		{ "%[αειου%]", true },
		{ "[ae][ʊɪ]", false }, -- needs an actual example
		{ "a?", true },
		{ "α?", false },
		{ "a*", true },
		{ "α*", false },
		{ "a-", true },
		{ "α-", false },
		{ "a+", true },
		{ "α+", false },
		{ "a.b", false },
	}
	self:iterate(examples, "check")
end

return tests