diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-03 22:51:45 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-09-06 17:19:07 -0700 |
commit | af946046b922dc5d5285a70a23d11916d8389a5d (patch) | |
tree | 090d68a1dd675b5ad6e99abc829be0daafe2a7d9 /test/functional/api/buffer_spec.lua | |
parent | 638f2b6dee7439de303bea12dec80240617e8034 (diff) | |
download | rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.tar.gz rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.tar.bz2 rneovim-af946046b922dc5d5285a70a23d11916d8389a5d.zip |
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.
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 849fbedd01..1322daa64d 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -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) |