test: Rename meth_pcall to pcall_err

- Rename `meth_pcall`.
- Make `pcall_err` raise an error if the function does not fail.
- Add `vim.pesc()` to treat a string as literal where a Lua pattern is
  expected.
This commit is contained in:
Justin M. Keyes
2019-09-03 22:51:45 +02:00
parent 638f2b6dee
commit af946046b9
13 changed files with 124 additions and 112 deletions

View File

@@ -8,10 +8,10 @@ local curwinmeths = helpers.curwinmeths
local funcs = helpers.funcs
local request = helpers.request
local NIL = helpers.NIL
local meth_pcall = helpers.meth_pcall
local meths = helpers.meths
local command = helpers.command
local expect_err = helpers.expect_err
local pcall_err = helpers.pcall_err
-- check if str is visible at the beginning of some line
local function is_visible(str)
@@ -74,8 +74,7 @@ describe('API/win', function()
it('does not leak memory when using invalid window ID with invalid pos',
function()
eq({false, 'Invalid window id'},
meth_pcall(meths.win_set_cursor, 1, {"b\na"}))
eq('Invalid window id', pcall_err(meths.win_set_cursor, 1, {"b\na"}))
end)
it('updates the screen, and also when the window is unfocused', function()
@@ -185,11 +184,11 @@ describe('API/win', function()
eq(1, funcs.exists('w:lua'))
curwinmeths.del_var('lua')
eq(0, funcs.exists('w:lua'))
eq({false, 'Key not found: lua'}, meth_pcall(curwinmeths.del_var, 'lua'))
eq('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua'))
curwinmeths.set_var('lua', 1)
command('lockvar w:lua')
eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.del_var, 'lua'))
eq({false, 'Key is locked: lua'}, meth_pcall(curwinmeths.set_var, 'lua', 1))
eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua'))
eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1))
end)
it('window_set_var returns the old value', function()
@@ -222,7 +221,8 @@ describe('API/win', function()
eq('', nvim('get_option', 'statusline'))
command("set modified")
command("enew") -- global-local: not preserved in new buffer
eq({false, "Failed to get value for option 'statusline'"}, meth_pcall(curwin, 'get_option', 'statusline'))
eq("Failed to get value for option 'statusline'",
pcall_err(curwin, 'get_option', 'statusline'))
eq('', eval('&l:statusline')) -- confirm local value was not copied
end)
end)
@@ -317,8 +317,8 @@ describe('API/win', function()
insert('text')
command('new')
local newwin = meths.get_current_win()
eq({false,"Vim:E37: No write since last change (add ! to override)"},
meth_pcall(meths.win_close, oldwin,false))
eq("Vim:E37: No write since last change (add ! to override)",
pcall_err(meths.win_close, oldwin,false))
eq({newwin,oldwin}, meths.list_wins())
end)