mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
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:
@@ -10,11 +10,11 @@ local exc_exec = helpers.exc_exec
|
||||
local feed_command = helpers.feed_command
|
||||
local insert = helpers.insert
|
||||
local NIL = helpers.NIL
|
||||
local meth_pcall = helpers.meth_pcall
|
||||
local command = helpers.command
|
||||
local bufmeths = helpers.bufmeths
|
||||
local feed = helpers.feed
|
||||
local expect_err = helpers.expect_err
|
||||
local pcall_err = helpers.pcall_err
|
||||
|
||||
describe('api/buf', function()
|
||||
before_each(clear)
|
||||
@@ -191,11 +191,8 @@ describe('api/buf', function()
|
||||
|
||||
it('fails correctly when input is not valid', function()
|
||||
eq(1, curbufmeths.get_number())
|
||||
local err, emsg = pcall(bufmeths.set_lines, 1, 1, 2, false, {'b\na'})
|
||||
eq(false, err)
|
||||
local exp_emsg = 'String cannot contain newlines'
|
||||
-- Expected {filename}:{lnum}: {exp_emsg}
|
||||
eq(': ' .. exp_emsg, emsg:sub(-#exp_emsg - 2))
|
||||
expect_err([[String cannot contain newlines]],
|
||||
bufmeths.set_lines, 1, 1, 2, false, {'b\na'})
|
||||
end)
|
||||
|
||||
it("fails if 'nomodifiable'", function()
|
||||
@@ -407,8 +404,8 @@ describe('api/buf', function()
|
||||
eq(16, get_offset(3))
|
||||
eq(24, get_offset(4))
|
||||
eq(29, get_offset(5))
|
||||
eq({false,'Index out of bounds'}, meth_pcall(get_offset, 6))
|
||||
eq({false,'Index out of bounds'}, meth_pcall(get_offset, -1))
|
||||
eq('Index out of bounds', pcall_err(get_offset, 6))
|
||||
eq('Index out of bounds', pcall_err(get_offset, -1))
|
||||
|
||||
curbufmeths.set_option('eol', false)
|
||||
curbufmeths.set_option('fixeol', false)
|
||||
@@ -441,15 +438,15 @@ describe('api/buf', function()
|
||||
eq(1, funcs.exists('b:lua'))
|
||||
curbufmeths.del_var('lua')
|
||||
eq(0, funcs.exists('b:lua'))
|
||||
eq({false, 'Key not found: lua'}, meth_pcall(curbufmeths.del_var, 'lua'))
|
||||
eq( 'Key not found: lua', pcall_err(curbufmeths.del_var, 'lua'))
|
||||
curbufmeths.set_var('lua', 1)
|
||||
command('lockvar b:lua')
|
||||
eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.del_var, 'lua'))
|
||||
eq({false, 'Key is locked: lua'}, meth_pcall(curbufmeths.set_var, 'lua', 1))
|
||||
eq({false, 'Key is read-only: changedtick'},
|
||||
meth_pcall(curbufmeths.del_var, 'changedtick'))
|
||||
eq({false, 'Key is read-only: changedtick'},
|
||||
meth_pcall(curbufmeths.set_var, 'changedtick', 1))
|
||||
eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua'))
|
||||
eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1))
|
||||
eq('Key is read-only: changedtick',
|
||||
pcall_err(curbufmeths.del_var, 'changedtick'))
|
||||
eq('Key is read-only: changedtick',
|
||||
pcall_err(curbufmeths.set_var, 'changedtick', 1))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user