|
|
@ -99,6 +99,51 @@ function test.patch_callback_return_value()
|
|
|
|
expect.eq(b, 4)
|
|
|
|
expect.eq(b, 4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_invalid_value()
|
|
|
|
|
|
|
|
dfhack.with_temp_object(df.new('int8_t'), function(i)
|
|
|
|
|
|
|
|
i.value = 1
|
|
|
|
|
|
|
|
local called = false
|
|
|
|
|
|
|
|
expect.error_match('integer expected', function()
|
|
|
|
|
|
|
|
mock.patch(i, 'value', 2, function()
|
|
|
|
|
|
|
|
expect.eq(i.value, 2)
|
|
|
|
|
|
|
|
called = true
|
|
|
|
|
|
|
|
i.value = 'a'
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.true_(called)
|
|
|
|
|
|
|
|
expect.eq(i.value, 1)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_invalid_value_initial()
|
|
|
|
|
|
|
|
dfhack.with_temp_object(df.new('int8_t'), function(i)
|
|
|
|
|
|
|
|
i.value = 1
|
|
|
|
|
|
|
|
expect.error_match('integer expected', function()
|
|
|
|
|
|
|
|
mock.patch(i, 'value', 'a', function()
|
|
|
|
|
|
|
|
expect.fail('patch() callback called unexpectedly')
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.eq(i.value, 1)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test.patch_invalid_value_initial_multiple()
|
|
|
|
|
|
|
|
dfhack.with_temp_object(df.new('int8_t', 2), function(i)
|
|
|
|
|
|
|
|
i[0] = 1
|
|
|
|
|
|
|
|
i[1] = 2
|
|
|
|
|
|
|
|
expect.error_match('integer expected', function()
|
|
|
|
|
|
|
|
mock.patch({
|
|
|
|
|
|
|
|
{i, 0, 3},
|
|
|
|
|
|
|
|
{i, 1, 'a'},
|
|
|
|
|
|
|
|
}, function()
|
|
|
|
|
|
|
|
expect.fail('patch() callback called unexpectedly')
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
expect.eq(i[0], 1)
|
|
|
|
|
|
|
|
expect.eq(i[1], 2)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function test.restore_single()
|
|
|
|
function test.restore_single()
|
|
|
|
local t = {k = 1}
|
|
|
|
local t = {k = 1}
|
|
|
|
mock.restore(t, 'k', function()
|
|
|
|
mock.restore(t, 'k', function()
|
|
|
|