Add tests for patch() where patching raises an error

develop
lethosor 2021-04-17 00:59:56 -04:00
parent ee8e10429d
commit 403f822520
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 45 additions and 0 deletions

@ -99,6 +99,51 @@ function test.patch_callback_return_value()
expect.eq(b, 4)
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()
local t = {k = 1}
mock.restore(t, 'k', function()