parent
864c240cdd
commit
c9cabe622d
@ -1 +1 @@
|
||||
Subproject commit 34ee5de696c2c12d8ded5793f2c5504f2e6ee168
|
||||
Subproject commit c704056663b80f520109061161b868f9d1f17c54
|
||||
@ -18,7 +18,7 @@ local function run_test_with_different_metatables(name, ...)
|
||||
test.metatable[name](effil.table(), ...)
|
||||
end
|
||||
|
||||
test.metatable.index = function (metatable)
|
||||
test.metatable.index_p = function (metatable)
|
||||
local share = effil.table()
|
||||
metatable.__index = function(t, key)
|
||||
return "mt_" .. effil.rawget(t, key)
|
||||
@ -29,7 +29,7 @@ test.metatable.index = function (metatable)
|
||||
test.equal(share.table_key, "mt_table_value")
|
||||
end
|
||||
|
||||
test.metatable.new_index = function (metatable)
|
||||
test.metatable.new_index_p = function (metatable)
|
||||
local share = effil.table()
|
||||
metatable.__newindex = function(t, key, value)
|
||||
effil.rawset(t, "mt_" .. key, "mt_" .. value)
|
||||
@ -40,7 +40,7 @@ test.metatable.new_index = function (metatable)
|
||||
test.equal(share.mt_table_key, "mt_table_value")
|
||||
end
|
||||
|
||||
test.metatable.call = function (metatable)
|
||||
test.metatable.call_p = function (metatable)
|
||||
local share = effil.table()
|
||||
metatable.__call = function(t, val1, val2, val3)
|
||||
return tostring(val1) .. "_" .. tostring(val2), tostring(val2) .. "_" .. tostring(val3)
|
||||
@ -52,11 +52,11 @@ test.metatable.call = function (metatable)
|
||||
test.equal(second_ret, "val2_val3")
|
||||
end
|
||||
|
||||
run_test_with_different_metatables("index")
|
||||
run_test_with_different_metatables("new_index")
|
||||
run_test_with_different_metatables("call")
|
||||
run_test_with_different_metatables("index_p")
|
||||
run_test_with_different_metatables("new_index_p")
|
||||
run_test_with_different_metatables("call_p")
|
||||
|
||||
test.metatable.binary_op = function (metatable, metamethod, op, exp_value)
|
||||
test.metatable.binary_op_p = function (metatable, metamethod, op, exp_value)
|
||||
local testTable, operand = effil.table(), effil.table()
|
||||
metatable['__' .. metamethod] = function(left, right)
|
||||
left.was_called = true
|
||||
@ -73,7 +73,7 @@ test.metatable.binary_op = function (metatable, metamethod, op, exp_value)
|
||||
end
|
||||
|
||||
local function test_binary_op(...)
|
||||
run_test_with_different_metatables("binary_op", ...)
|
||||
run_test_with_different_metatables("binary_op_p", ...)
|
||||
end
|
||||
|
||||
test_binary_op("concat", function(a, b) return a .. b end)
|
||||
@ -88,7 +88,7 @@ test_binary_op("lt", function(a, b) return a < b end, true)
|
||||
test_binary_op("eq", function(a, b) return a == b end, true)
|
||||
|
||||
|
||||
test.metatable.unary_op = function(metatable, metamethod, op)
|
||||
test.metatable.unary_op_p = function(metatable, metamethod, op)
|
||||
local share = effil.table()
|
||||
metatable['__' .. metamethod] = function(t)
|
||||
t.was_called = true
|
||||
@ -103,7 +103,7 @@ test.metatable.unary_op = function(metatable, metamethod, op)
|
||||
end
|
||||
|
||||
local function test_unary_op(...)
|
||||
run_test_with_different_metatables("unary_op", ...)
|
||||
run_test_with_different_metatables("unary_op_p", ...)
|
||||
end
|
||||
|
||||
test_unary_op("unm", function(a) return -a end)
|
||||
@ -112,7 +112,7 @@ test_unary_op("len", function(a) return #a end)
|
||||
|
||||
test.shared_table_with_metatable.tear_down = default_tear_down
|
||||
|
||||
test.shared_table_with_metatable.iterators = function (iterator_type, iterator_trigger)
|
||||
test.shared_table_with_metatable.iterators_p = function (iterator_type, iterator_trigger)
|
||||
local share = effil.table()
|
||||
local iterator = iterator_type
|
||||
effil.setmetatable(share, {
|
||||
@ -147,12 +147,12 @@ test.shared_table_with_metatable.iterators = function (iterator_type, iterator_t
|
||||
test.equal(pow_iter, 2 ^ 11)
|
||||
end
|
||||
|
||||
test.shared_table_with_metatable.iterators("pairs", "effil")
|
||||
test.shared_table_with_metatable.iterators("ipairs", "effil")
|
||||
test.shared_table_with_metatable.iterators_p("pairs", "effil")
|
||||
test.shared_table_with_metatable.iterators_p("ipairs", "effil")
|
||||
|
||||
if LUA_VERSION > 51 then
|
||||
test.shared_table_with_metatable.iterators("pairs", "_G")
|
||||
test.shared_table_with_metatable.iterators("ipairs", "_G")
|
||||
test.shared_table_with_metatable.iterators_p("pairs", "_G")
|
||||
test.shared_table_with_metatable.iterators_p("ipairs", "_G")
|
||||
end -- LUA_VERSION > 51
|
||||
|
||||
test.shared_table_with_metatable.as_shared_table = function()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
require "bootstrap-tests"
|
||||
|
||||
local basic_type_mismatch_test = function(err_msg, wrong_arg_num, func_name , ...)
|
||||
local basic_type_mismatch_test_p = function(err_msg, wrong_arg_num, func_name , ...)
|
||||
local func_to_call = func_name
|
||||
if type(func_name) == "string" then
|
||||
func_to_call = effil
|
||||
@ -22,19 +22,19 @@ local basic_type_mismatch_test = function(err_msg, wrong_arg_num, func_name , ..
|
||||
test.equal(trunc_err, err_msg)
|
||||
end
|
||||
|
||||
test.type_mismatch.input_types_mismatch = function(wrong_arg_num, expected_type, func_name, ...)
|
||||
test.type_mismatch.input_types_mismatch_p = function(wrong_arg_num, expected_type, func_name, ...)
|
||||
local args = {...}
|
||||
local err_msg = "bad argument #" .. wrong_arg_num .. " to " ..
|
||||
(type(func_name) == "string" and "'effil." .. func_name or func_name.name) ..
|
||||
"' (" .. expected_type .. " expected, got " .. effil.type(args[wrong_arg_num]) .. ")"
|
||||
basic_type_mismatch_test(err_msg, wrong_arg_num, func_name, ...)
|
||||
basic_type_mismatch_test_p(err_msg, wrong_arg_num, func_name, ...)
|
||||
end
|
||||
|
||||
test.type_mismatch.unsupported_type = function(wrong_arg_num, func_name, ...)
|
||||
test.type_mismatch.unsupported_type_p = function(wrong_arg_num, func_name, ...)
|
||||
local args = {...}
|
||||
local err_msg = (type(func_name) == "string" and "effil." .. func_name or func_name.name)
|
||||
.. ": unable to store object of " .. effil.type(args[wrong_arg_num]) .. " type"
|
||||
basic_type_mismatch_test(err_msg, wrong_arg_num, func_name, ...)
|
||||
basic_type_mismatch_test_p(err_msg, wrong_arg_num, func_name, ...)
|
||||
end
|
||||
|
||||
local function generate_tests()
|
||||
@ -82,68 +82,68 @@ local function generate_tests()
|
||||
|
||||
-- effil.getmetatable
|
||||
if typename ~= "effil.table" then
|
||||
test.type_mismatch.input_types_mismatch(1, "effil.table", "getmetatable", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "effil.table", "getmetatable", type_instance)
|
||||
end
|
||||
|
||||
-- effil.setmetatable
|
||||
if typename ~= "table" and typename ~= "effil.table" then
|
||||
test.type_mismatch.input_types_mismatch(1, "table", "setmetatable", type_instance, 44)
|
||||
test.type_mismatch.input_types_mismatch(2, "table", "setmetatable", {}, type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "table", "setmetatable", type_instance, 44)
|
||||
test.type_mismatch.input_types_mismatch_p(2, "table", "setmetatable", {}, type_instance)
|
||||
end
|
||||
|
||||
if typename ~= "effil.table" then
|
||||
-- effil.rawset
|
||||
test.type_mismatch.input_types_mismatch(1, "effil.table", "rawset", type_instance, 44, 22)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "effil.table", "rawset", type_instance, 44, 22)
|
||||
-- effil.rawget
|
||||
test.type_mismatch.input_types_mismatch(1, "effil.table", "rawget", type_instance, 44)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "effil.table", "rawget", type_instance, 44)
|
||||
-- effil.ipairs
|
||||
test.type_mismatch.input_types_mismatch(1, "effil.table", "ipairs", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "effil.table", "ipairs", type_instance)
|
||||
-- effil.pairs
|
||||
test.type_mismatch.input_types_mismatch(1, "effil.table", "pairs", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "effil.table", "pairs", type_instance)
|
||||
end
|
||||
|
||||
-- effil.thread
|
||||
if typename ~= "function" then
|
||||
test.type_mismatch.input_types_mismatch(1, "function", "thread", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "function", "thread", type_instance)
|
||||
end
|
||||
|
||||
-- effil.sleep
|
||||
if typename ~= "number" then
|
||||
test.type_mismatch.input_types_mismatch(1, "number", "sleep", type_instance, "s")
|
||||
test.type_mismatch.input_types_mismatch_p(1, "number", "sleep", type_instance, "s")
|
||||
end
|
||||
if typename ~= "string" then
|
||||
test.type_mismatch.input_types_mismatch(2, "string", "sleep", 1, type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(2, "string", "sleep", 1, type_instance)
|
||||
end
|
||||
|
||||
if typename ~= "number" then
|
||||
-- effil.channel
|
||||
test.type_mismatch.input_types_mismatch(1, "number", "channel", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "number", "channel", type_instance)
|
||||
|
||||
-- effil.gc.step
|
||||
test.type_mismatch.input_types_mismatch(1, "number", "gc.step", type_instance)
|
||||
test.type_mismatch.input_types_mismatch_p(1, "number", "gc.step", type_instance)
|
||||
end
|
||||
end
|
||||
|
||||
-- Below presented tests which support everything except coroutines
|
||||
|
||||
-- effil.rawset
|
||||
test.type_mismatch.unsupported_type(2, "rawset", stable, lua_thread, 22)
|
||||
test.type_mismatch.unsupported_type(3, "rawset", stable, 44, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(2, "rawset", stable, lua_thread, 22)
|
||||
test.type_mismatch.unsupported_type_p(3, "rawset", stable, 44, lua_thread)
|
||||
|
||||
-- effil.rawget
|
||||
test.type_mismatch.unsupported_type(2, "rawget", stable, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(2, "rawget", stable, lua_thread)
|
||||
|
||||
-- effil.channel:push()
|
||||
test.type_mismatch.unsupported_type(1, channel_push_generator, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(1, channel_push_generator, lua_thread)
|
||||
|
||||
-- effil.thread()()
|
||||
test.type_mismatch.unsupported_type(1, thread_runner_generator, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(1, thread_runner_generator, lua_thread)
|
||||
|
||||
-- effil.table[key] = value
|
||||
test.type_mismatch.unsupported_type(1, table_set_value_generator, lua_thread, 2)
|
||||
test.type_mismatch.unsupported_type(2, table_set_value_generator, 2, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(1, table_set_value_generator, lua_thread, 2)
|
||||
test.type_mismatch.unsupported_type_p(2, table_set_value_generator, 2, lua_thread)
|
||||
-- effil.table[key]
|
||||
test.type_mismatch.unsupported_type(1, table_get_value_generator, lua_thread)
|
||||
test.type_mismatch.unsupported_type_p(1, table_get_value_generator, lua_thread)
|
||||
end
|
||||
|
||||
-- Put it to function to limit the lifetime of objects
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user