Jump to content

Module:fun/testcases

Wiktionary වෙතින්

All tests passed. (refresh)

TextExpectedActual
test_is_callable:
Passed
3
falsefalse
Passed
function#1
truetrue
Passed
table#1 {
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
truetrue
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = true
}
falsefalse
Passed
table#1 {
}
falsefalse
Passed
table#1 {
    metatable = 5
}
falsefalse
Passed
table#1 {
    metatable = function#1
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
truetrue
Passed
table#1 {
    metatable = table#2
}
falsefalse
Passed
table#1 {
    metatable = true
}
falsefalse
Passed
table#1 {
}
falsefalse
Passed
table#1 {
    metatable = 5
}
falsefalse
Passed
table#1 {
    metatable = function#1
}
falsefalse
Passed
table#1 {
    metatable = table#2
}
truetrue
Passed
table#1 {
    metatable = table#2
}
falsefalse

local tests = require("Module:UnitTests")

local highlight = require("Module:debug").highlight{ lang = "text"}
local is_callable = require("Module:fun").is_callable

function tests:check_is_callable(obj, expected)
	tests:equals(highlight(mw.dumpObject(obj)), is_callable(obj), expected)
end

function tests:test_is_callable()
	local example = setmetatable({}, {__call = function() end})
	
	local examples = {
		{3, false},
		{function() end, true},
		{{}, false},
		{setmetatable({}, {}), false},
		{setmetatable({}, {__index = {}}), false},
		{example, true},
		{setmetatable({}, {__call = {}}), false},
		{setmetatable({}, {__call = example}), false},
		{setmetatable({}, setmetatable({}, {__index = {__call = function() end}})), false},
		{setmetatable({}, {__metatable = {}}), false},
		{setmetatable({}, {__metatable = true}), false},
		{setmetatable({}, {__metatable = false}), false},
		{setmetatable({}, {__metatable = 5}), false},
		{setmetatable({}, {__metatable = function() end}), false},
		{setmetatable({}, setmetatable({__call = function() end}, {__index = {__metatable = false}})), true},
		{setmetatable({}, {__call = function() end, __metatable = {}}), false},
		{setmetatable({}, {__call = function() end, __metatable = true}), false},
		{setmetatable({}, {__call = function() end, __metatable = false}), false},
		{setmetatable({}, {__call = function() end, __metatable = 5}), false},
		{setmetatable({}, {__call = function() end, __metatable = function() end}), false},
		{setmetatable({}, {__call = function() end, __metatable = {__call = function() end}}), true},
		{setmetatable({}, setmetatable({}, {__index = {__call = function() end, __metatable = false}})), false},
	}

	self:iterate(examples, "check_is_callable")
end

return tests
"https://si.wiktionary.org/w/index.php?title=Module:fun/testcases&oldid=197284" වෙතින් සම්ප්‍රවේශනය කෙරිණි