|
|
@ -33,8 +33,8 @@ function test.patch_multiple()
|
|
|
|
expect.eq(test_table.func1(), 1)
|
|
|
|
expect.eq(test_table.func1(), 1)
|
|
|
|
expect.eq(test_table.func2(), 2)
|
|
|
|
expect.eq(test_table.func2(), 2)
|
|
|
|
mock.patch({
|
|
|
|
mock.patch({
|
|
|
|
[{test_table, 'func1'}] = function() return 3 end,
|
|
|
|
{test_table, 'func1', function() return 3 end},
|
|
|
|
[{test_table, 'func2'}] = function() return 4 end,
|
|
|
|
{test_table, 'func2', function() return 4 end},
|
|
|
|
}, function()
|
|
|
|
}, function()
|
|
|
|
expect.eq(test_table.func1(), 3)
|
|
|
|
expect.eq(test_table.func1(), 3)
|
|
|
|
expect.eq(test_table.func2(), 4)
|
|
|
|
expect.eq(test_table.func2(), 4)
|
|
|
@ -43,3 +43,50 @@ function test.patch_multiple()
|
|
|
|
expect.eq(test_table.func2(), 2)
|
|
|
|
expect.eq(test_table.func2(), 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_nil_old_value()
|
|
|
|
|
|
|
|
local t = {}
|
|
|
|
|
|
|
|
mock.patch(t, 1, 2, function()
|
|
|
|
|
|
|
|
expect.eq(t[1], 2)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.eq(t[1], nil)
|
|
|
|
|
|
|
|
expect.eq(#t, 0)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_nil_new_value()
|
|
|
|
|
|
|
|
local t = {2}
|
|
|
|
|
|
|
|
mock.patch(t, 1, nil, function()
|
|
|
|
|
|
|
|
expect.eq(t[1], nil)
|
|
|
|
|
|
|
|
expect.eq(#t, 0)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.eq(t[1], 2)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_nil_key()
|
|
|
|
|
|
|
|
local called = false
|
|
|
|
|
|
|
|
expect.error_match('table index is nil', function()
|
|
|
|
|
|
|
|
mock.patch({}, nil, 'value', function()
|
|
|
|
|
|
|
|
called = true
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.false_(called)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_nil_table()
|
|
|
|
|
|
|
|
local called = false
|
|
|
|
|
|
|
|
expect.error(function()
|
|
|
|
|
|
|
|
mock.patch(nil, 1, 2, function()
|
|
|
|
|
|
|
|
called = true
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.false_(called)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_complex_key()
|
|
|
|
|
|
|
|
local key = {'key'}
|
|
|
|
|
|
|
|
local t = {[key] = 'value'}
|
|
|
|
|
|
|
|
expect.eq(t[key], 'value')
|
|
|
|
|
|
|
|
mock.patch(t, key, 2, function()
|
|
|
|
|
|
|
|
expect.eq(t[key], 2)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.eq(t[key], 'value')
|
|
|
|
|
|
|
|
end
|
|
|
|