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

@@ -10,7 +10,7 @@ local meths = helpers.meths
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs
local run = helpers.run
local meth_pcall = helpers.meth_pcall
local pcall_err = helpers.pcall_err
describe('floating windows', function()
before_each(function()
@@ -636,26 +636,26 @@ describe('floating windows', function()
it('API has proper error messages', function()
local buf = meths.create_buf(false,false)
eq({false, "Invalid key 'bork'"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,bork=true}))
eq({false, "'win' key is only valid with relative='win'"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0}))
eq({false, "Only one of 'relative' and 'external' must be used"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true}))
eq({false, "Invalid value of 'relative' key"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0}))
eq({false, "Invalid value of 'anchor' key"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'}))
eq({false, "All of 'relative', 'row', and 'col' has to be specified at once"},
meth_pcall(meths.open_win,buf, false, {width=20,height=2,relative='editor'}))
eq({false, "'width' key must be a positive Integer"},
meth_pcall(meths.open_win,buf, false, {width=-1,height=2,relative='editor'}))
eq({false, "'height' key must be a positive Integer"},
meth_pcall(meths.open_win,buf, false, {width=20,height=-1,relative='editor'}))
eq({false, "'height' key must be a positive Integer"},
meth_pcall(meths.open_win,buf, false, {width=20,height=0,relative='editor'}))
eq({false, "Must specify 'width' and 'height'"},
meth_pcall(meths.open_win,buf, false, {relative='editor'}))
eq("Invalid key 'bork'",
pcall_err(meths.open_win,buf, false, {width=20,height=2,bork=true}))
eq("'win' key is only valid with relative='win'",
pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0}))
eq("Only one of 'relative' and 'external' must be used",
pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true}))
eq("Invalid value of 'relative' key",
pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0}))
eq("Invalid value of 'anchor' key",
pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'}))
eq("All of 'relative', 'row', and 'col' has to be specified at once",
pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor'}))
eq("'width' key must be a positive Integer",
pcall_err(meths.open_win,buf, false, {width=-1,height=2,relative='editor'}))
eq("'height' key must be a positive Integer",
pcall_err(meths.open_win,buf, false, {width=20,height=-1,relative='editor'}))
eq("'height' key must be a positive Integer",
pcall_err(meths.open_win,buf, false, {width=20,height=0,relative='editor'}))
eq("Must specify 'width' and 'height'",
pcall_err(meths.open_win,buf, false, {relative='editor'}))
end)
it('can be placed relative window or cursor', function()
@@ -4528,8 +4528,8 @@ describe('floating windows', function()
{0:~ }|
]], float_pos=expected_pos}
else
eq({false, "UI doesn't support external windows"},
meth_pcall(meths.win_set_config, 0, {external=true, width=30, height=2}))
eq("UI doesn't support external windows",
pcall_err(meths.win_set_config, 0, {external=true, width=30, height=2}))
return
end
@@ -4844,8 +4844,8 @@ describe('floating windows', function()
{0:~ }|
]], float_pos=expected_pos}
else
eq({false, "UI doesn't support external windows"},
meth_pcall(meths.win_set_config, 0, {external=true, width=65, height=4}))
eq("UI doesn't support external windows",
pcall_err(meths.win_set_config, 0, {external=true, width=65, height=4}))
end
feed(":tabnext<cr>")