refactor(test): drop deprecated exc_exec #39242

This commit is contained in:
Justin M. Keyes
2026-04-20 14:16:41 -04:00
committed by GitHub
parent faa7c15b5a
commit 4ceca862fc
77 changed files with 1009 additions and 799 deletions

View File

@@ -29,7 +29,6 @@ local next_msg = n.next_msg
local tmpname = t.tmpname
local write_file = t.write_file
local exec_lua = n.exec_lua
local exc_exec = n.exc_exec
local insert = n.insert
local skip = t.skip
@@ -3655,7 +3654,7 @@ describe('API', function()
eq(
'Vim(echo):E5555: API call: Vim:E220: Missing }.',
exc_exec("echo nvim_get_runtime_file('{', v:false)")
pcall_err(command, "echo nvim_get_runtime_file('{', v:false)")
)
end)
it('preserves order of runtimepath', function()

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local command = n.command
local eq = t.eq
local pcall_err = t.pcall_err
local eval = n.eval
local request = n.request
local is_os = t.is_os

View File

@@ -6,7 +6,6 @@ local tt = require('test.functional.testterm')
local clear = n.clear
local eq = t.eq
local eval = n.eval
local exc_exec = n.exc_exec
local feed_command = n.feed_command
local feed = n.feed
local insert = n.insert
@@ -1328,7 +1327,7 @@ describe('jobs', function()
-- Can't wait for the next message in case this test fails, if it fails
-- there won't be any more messages, and the test would hang.
vim.uv.sleep(100)
local err = exc_exec('call jobpid(j)')
local err = pcall_err(command, 'call jobpid(j)')
eq('Vim(call):E900: Invalid channel id', err)
-- cleanup

View File

@@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen')
local uv = vim.uv
local eq = t.eq
local pcall_err = t.pcall_err
local matches = t.matches
local feed = n.feed
local eval = n.eval

View File

@@ -2,9 +2,9 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear
local api = n.api
local exc_exec = n.exc_exec
local fn = n.fn
local rmdir = n.rmdir
local write_file = t.write_file
@@ -38,7 +38,7 @@ describe('spellfile', function()
-- │ │ ┌ Condition regex (missing!)
.. '\000\001\001')
api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E758: Truncated spell file', exc_exec('set spell'))
t.matches('Vim%(set%):E758: Truncated spell file', pcall_err(n.command, 'set spell'))
end)
it('errors out when prefcond regexp contains NUL byte', function()
api.nvim_set_option_value('runtimepath', testdir, {})
@@ -58,7 +58,7 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
t.matches('Vim%(set%):E759: Format error in spell file', pcall_err(n.command, 'set spell'))
end)
it('errors out when region contains NUL byte', function()
api.nvim_set_option_value('runtimepath', testdir, {})
@@ -75,7 +75,7 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
t.matches('Vim%(set%):E759: Format error in spell file', pcall_err(n.command, 'set spell'))
end)
it('errors out when SAL section contains NUL byte', function()
api.nvim_set_option_value('runtimepath', testdir, {})
@@ -99,13 +99,16 @@ describe('spellfile', function()
-- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
t.matches('Vim%(set%):E759: Format error in spell file', pcall_err(n.command, 'set spell'))
end)
it('errors out when spell header contains NUL bytes', function()
api.nvim_set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000')
api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell'))
t.matches(
'Vim%(set%):E757: This does not look like a spell file',
pcall_err(n.command, 'set spell')
)
end)
it('can be set to a relative path', function()
@@ -133,13 +136,13 @@ describe('spellfile', function()
n.command('set spell')
fn.writefile({ '' }, testdir .. '/xdg_data')
n.insert('abc')
eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
eq("Vim(normal):E764: Option 'spellfile' is not set", pcall_err(n.command, 'normal! zg'))
end)
it("is not set if 'spelllang' is not set", function()
n.command('set spell spelllang=')
n.insert('abc')
eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
eq("Vim(normal):E764: Option 'spellfile' is not set", pcall_err(n.command, 'normal! zg'))
end)
it('accepts overwrites on midword and syllable section, errors on memory leak', function()

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')

View File

@@ -4,7 +4,6 @@ local n = require('test.functional.testnvim')()
local clear, insert, eq = n.clear, n.insert, t.eq
local command, expect = n.command, n.expect
local feed, eval = n.feed, n.eval
local exc_exec = n.exc_exec
describe('gu and gU', function()
before_each(clear)
@@ -21,8 +20,7 @@ describe('gu and gU', function()
describe('works in Turkish locale', function()
clear()
local err = exc_exec('lang ctype tr_TR.UTF-8')
if err ~= 0 then
if not pcall(n.command, 'lang ctype tr_TR.UTF-8') then
pending('Locale tr_TR.UTF-8 not supported', function() end)
return
end

View File

@@ -4,10 +4,10 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local call = n.call
local clear = n.clear
local command = n.command
local exc_exec = n.exc_exec
local pathsep = n.get_pathsep()
local skip = t.skip
local is_os = t.is_os
@@ -251,34 +251,34 @@ for _, cmd in ipairs { 'getcwd', 'haslocaldir' } do
-- Test invalid argument types
local err474 = 'Vim(call):E474: Invalid argument'
it('fails on string', function()
eq(err474, exc_exec('call ' .. cmd .. '("some string")'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '("some string")'))
end)
it('fails on float', function()
eq(err474, exc_exec('call ' .. cmd .. '(1.0)'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '(1.0)'))
end)
it('fails on list', function()
eq(err474, exc_exec('call ' .. cmd .. '([1, 2])'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '([1, 2])'))
end)
it('fails on dictionary', function()
eq(err474, exc_exec('call ' .. cmd .. '({"key": "value"})'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '({"key": "value"})'))
end)
it('fails on funcref', function()
eq(err474, exc_exec('call ' .. cmd .. '(function("tr"))'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '(function("tr"))'))
end)
-- Test invalid numbers
it('fails on number less than -1', function()
eq(err474, exc_exec('call ' .. cmd .. '(-2)'))
eq(err474, pcall_err(command, 'call ' .. cmd .. '(-2)'))
end)
local err5001 = 'Vim(call):E5001: Higher scope cannot be -1 if lower scope is >= 0.'
it('fails on -1 if previous arg is >=0', function()
eq(err5001, exc_exec('call ' .. cmd .. '(0, -1)'))
eq(err5001, pcall_err(command, 'call ' .. cmd .. '(0, -1)'))
end)
-- Test wrong number of arguments
local err118 = 'Vim(call):E118: Too many arguments for function: ' .. cmd
it('fails to parse more than one argument', function()
eq(err118, exc_exec('call ' .. cmd .. '(0, 0, 0)'))
eq(err118, pcall_err(command, 'call ' .. cmd .. '(0, 0, 0)'))
end)
end)
end

View File

@@ -5,12 +5,12 @@ local Screen = require('test.functional.ui.screen')
local clear = n.clear
local feed = n.feed
local eq = t.eq
local pcall_err = t.pcall_err
local expect = n.expect
local eval = n.eval
local fn = n.fn
local insert = n.insert
local write_file = t.write_file
local exc_exec = n.exc_exec
local command = n.command
describe('mappings with <Cmd>', function()
@@ -285,9 +285,9 @@ describe('mappings with <Cmd>', function()
:normal ,x |
]])
eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec('normal ,f'))
eq('very error', exc_exec('normal ,e'))
eq('Vim(echoerr):The message.', exc_exec('normal ,m'))
eq('Vim:E492: Not an editor command: nosuchcommand', pcall_err(command, 'normal ,f'))
eq('very error', pcall_err(command, 'normal ,e'))
eq('Vim(echoerr):The message.', pcall_err(command, 'normal ,m'))
feed('w')
screen:expect([[
some ^short lines |
@@ -299,7 +299,7 @@ describe('mappings with <Cmd>', function()
]])
command(':%d')
eq('Vim(echoerr):Err', exc_exec('normal ,w'))
eq('Vim(echoerr):Err', pcall_err(command, 'normal ,w'))
screen:expect([[
^ |
0 |

View File

@@ -7,7 +7,6 @@ local api = n.api
local insert = n.insert
local eq, next_msg = t.eq, n.next_msg
local matches = t.matches
local exc_exec = n.exc_exec
local exec_lua = n.exec_lua
local command = n.command
local eval = n.eval
@@ -321,7 +320,7 @@ describe('Vimscript dictionary notifications', function()
]])
eq(
'Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"',
exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")')
pcall_err(command, 'call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")')
)
end)
@@ -341,14 +340,14 @@ describe('Vimscript dictionary notifications', function()
it('fails to remove if no watcher with matching callback is found', function()
eq(
"Vim(call):Couldn't find a watcher matching key and callback",
exc_exec('call dictwatcherdel(g:, "key", "g:Watcher1")')
pcall_err(command, 'call dictwatcherdel(g:, "key", "g:Watcher1")')
)
end)
it('fails to remove if no watcher with matching key is found', function()
eq(
"Vim(call):Couldn't find a watcher matching key and callback",
exc_exec('call dictwatcherdel(g:, "invalid_key", "g:Watcher2")')
pcall_err(command, 'call dictwatcherdel(g:, "invalid_key", "g:Watcher2")')
)
end)
@@ -360,16 +359,16 @@ describe('Vimscript dictionary notifications', function()
it('fails to remove watcher from v:_null_dict', function()
eq(
"Vim(call):Couldn't find a watcher matching key and callback",
exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")')
pcall_err(command, 'call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")')
)
end)
--[[
[ it("fails to add/remove if the callback doesn't exist", function()
[ eq("Vim(call):Function g:InvalidCb doesn't exist",
[ exc_exec('call dictwatcheradd(g:, "key", "g:InvalidCb")'))
[ pcall_err(command, 'call dictwatcheradd(g:, "key", "g:InvalidCb")'))
[ eq("Vim(call):Function g:InvalidCb doesn't exist",
[ exc_exec('call dictwatcherdel(g:, "key", "g:InvalidCb")'))
[ pcall_err(command, 'call dictwatcherdel(g:, "key", "g:InvalidCb")'))
[ end)
]]

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local NIL = vim.NIL
local eval = n.eval
local clear = n.clear
@@ -10,7 +11,6 @@ local fn = n.fn
local source = n.source
local dedent = t.dedent
local command = n.command
local exc_exec = n.exc_exec
local exec_capture = n.exec_capture
local matches = t.matches
@@ -308,7 +308,7 @@ describe(':echo :echon :echomsg :echoerr', function()
it('does not error when dumping recursive lists', function()
api.nvim_set_var('l', {})
eval('add(l, l)')
eq(0, exc_exec('echo String(l)'))
command('echo String(l)')
end)
it('dumps recursive lists without error', function()
@@ -338,7 +338,7 @@ describe(':echo :echon :echomsg :echoerr', function()
it('does not error when dumping recursive dictionaries', function()
api.nvim_set_var('d', { d = 1 })
eval('extend(d, {"d": d})')
eq(0, exc_exec('echo String(d)'))
command('echo String(d)')
end)
it('dumps recursive dictionaries without the error', function()

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local clear, feed = n.clear, n.feed

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local command = n.command
local eq = t.eq
local pcall_err = t.pcall_err
local fn = n.fn
local api = n.api
local mkdir = t.mkdir

View File

@@ -1,13 +1,15 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local eq, command = t.eq, n.command
local clear = n.clear
local eval, exc_exec = n.eval, n.exc_exec
local eval = n.eval
local exec = n.exec
local fn = n.fn
local api = n.api
local command = n.command
describe(':highlight', function()
before_each(function()
@@ -18,16 +20,16 @@ describe(':highlight', function()
it('invalid color name', function()
eq(
'Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818',
exc_exec('highlight normal ctermfg=#181818')
pcall_err(command, 'highlight normal ctermfg=#181818')
)
eq(
'Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818',
exc_exec('highlight normal ctermbg=#181818')
pcall_err(command, 'highlight normal ctermbg=#181818')
)
end)
it('invalid group name', function()
eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec('highlight foo'))
eq('Vim(highlight):E411: Highlight group not found: foo', pcall_err(command, 'highlight foo'))
end)
it('"Normal" foreground with red', function()

View File

@@ -4,6 +4,7 @@ local t_lsp = require('test.functional.plugin.lsp.testutil')
local clear = n.clear
local eq = t.eq
local pcall_err = t.pcall_err
local exec_lua = n.exec_lua
local create_server_definition = t_lsp.create_server_definition

View File

@@ -4,10 +4,10 @@ local Screen = require('test.functional.ui.screen')
local feed = n.feed
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear
local fn = n.fn
local command = n.command
local exc_exec = n.exc_exec
local write_file = t.write_file
local api = n.api
local source = n.source
@@ -83,7 +83,7 @@ for _, c in ipairs({ 'l', 'c' }) do
api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
eq(
('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd),
exc_exec(('%s %s'):format(filecmd, file))
pcall_err(command, ('%s %s'):format(filecmd, file))
)
write_file(
@@ -218,7 +218,7 @@ end)
it(':vimgrep can specify Unicode pattern without delimiters', function()
eq(
'Vim(vimgrep):E480: No match: →',
exc_exec('vimgrep → test/functional/fixtures/tty-test.c')
pcall_err(command, 'vimgrep → test/functional/fixtures/tty-test.c')
)
local screen = Screen.new(40, 6)
screen:set_default_attr_ids({

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local neq = t.neq
local command = n.command
local exec_capture = n.exec_capture
@@ -9,7 +10,6 @@ local write_file = t.write_file
local api = n.api
local clear = n.clear
local dedent = t.dedent
local exc_exec = n.exc_exec
local missing_provider = n.missing_provider
local tmpfile = 'X_ex_cmds_script'
@@ -46,9 +46,12 @@ describe('script_get-based command', function()
if check_neq then
neq(
0,
exc_exec(dedent([[
pcall_err(
command,
dedent([[
%s %s
]])):format(cmd, garbage)
]])
):format(cmd, garbage)
)
end
end)

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local command = n.command
local insert = n.insert
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear
local api = n.api
local fn = n.fn
@@ -12,7 +13,6 @@ local feed_command = n.feed_command
local write_file = t.write_file
local tmpname = t.tmpname
local exec = n.exec
local exc_exec = n.exc_exec
local exec_lua = n.exec_lua
local eval = n.eval
local exec_capture = n.exec_capture
@@ -110,7 +110,7 @@ describe(':source', function()
eq('0zBEEFCAFE', exec_capture('echo d'))
exec('set cpoptions+=C')
eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec('source'))
matches("Vim%(let%):E723: Missing end of Dictionary '%}'", pcall_err(command, 'source'))
end)
it('selection in current buffer', function()
@@ -134,7 +134,7 @@ describe(':source', function()
-- Source last line only
feed_command(':$source')
eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()'))
matches('Vim%(echo%):E117: Unknown function: s:C', pcall_err(command, 'echo D()'))
-- Source from 2nd line to end of file
feed('ggjVG')
@@ -148,7 +148,7 @@ describe(':source', function()
eq('<SNR>1_C()', exec_capture('echo D()'))
exec('set cpoptions+=C')
eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec("'<,'>source"))
matches("Vim%(let%):E723: Missing end of Dictionary '%}'", pcall_err(command, "'<,'>source"))
end)
it('does not break if current buffer is modified while sourced', function()

View File

@@ -2,8 +2,9 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear
local exc_exec = n.exc_exec
local command = n.command
describe(':syntax', function()
before_each(clear)
@@ -12,7 +13,7 @@ describe(':syntax', function()
it('does not crash when group name contains unprintable characters', function()
eq(
'Vim(syntax):E669: Unprintable character in group name',
exc_exec('syntax keyword \024 foo bar')
pcall_err(command, 'syntax keyword \024 foo bar')
)
end)
end)

View File

@@ -1,13 +1,11 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local clear = n.clear
local insert = n.insert
local feed = n.feed
local expect = n.expect
local feed_command = n.feed_command
local exc_exec = n.exc_exec
local command = n.command
describe(':undojoin command', function()
before_each(function()
@@ -33,7 +31,6 @@ describe(':undojoin command', function()
Line of text 2]])
end)
it('does not raise an error when called twice', function()
local ret = exc_exec('undojoin | undojoin')
eq(0, ret)
command('undojoin | undojoin')
end)
end)

View File

@@ -173,7 +173,7 @@ describe(':write', function()
eq(true, os.remove(fname_bak))
end
write_file(fname_bak, 'TTYX')
skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]])
skip(is_os('win'), [[FIXME: pcall_err(command, 'write!') outputs 0 in Windows]])
vim.uv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname)
eq("Vim(write):E166: Can't open linked file for writing", pcall_err(command, 'write!'))
end)

View File

@@ -1,11 +1,11 @@
-- Tests for :sort command.
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local insert, command, clear, expect, eq, poke_eventloop =
n.insert, n.command, n.clear, n.expect, t.eq, n.poke_eventloop
local exc_exec = n.exc_exec
describe(':sort', function()
local text = [[
@@ -619,7 +619,7 @@ describe(':sort', function()
it('fails with wrong arguments', function()
insert(text)
-- This should fail with "E474: Invalid argument".
eq('Vim(sort):E474: Invalid argument', exc_exec('sort no'))
eq('Vim(sort):E474: Invalid argument', pcall_err(command, 'sort no'))
expect(text)
end)

View File

@@ -1,11 +1,12 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local api, call = n.api, n.call
local clear, eq = n.clear, t.eq
local source, command = n.source, n.command
local exc_exec = n.exc_exec
local eval = n.eval
local command = n.command
local function expected_errors(errors)
eq(errors, api.nvim_get_vvar('errors'))
@@ -70,9 +71,9 @@ describe('assert function:', function()
call assert_equal(s:w, '')
endfunction
]])
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call CheckAssert()')
t.matches(
'Vim%(call%):E724: unable to correctly dump variable with self%-referencing container',
pcall_err(command, 'call CheckAssert()')
)
end)
end)

View File

@@ -1,9 +1,9 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local clear, source = n.clear, n.source
local eq, eval, command = t.eq, n.eval, n.command
local exc_exec = n.exc_exec
describe('Test for delete()', function()
before_each(clear)
@@ -64,7 +64,7 @@ describe('Test for delete()', function()
end)
it('gives correct emsgs', function()
eq('Vim(call):E474: Invalid argument', exc_exec("call delete('')"))
eq('Vim(call):E15: Invalid expression: "0"', exc_exec("call delete('foo', 0)"))
eq('Vim(call):E474: Invalid argument', pcall_err(command, "call delete('')"))
eq('Vim(call):E15: Invalid expression: "0"', pcall_err(command, "call delete('foo', 0)"))
end)
end)

View File

@@ -8,8 +8,8 @@ local feed, insert, source = n.feed, n.insert, n.source
local clear, command, expect = n.clear, n.command, n.expect
local eq, eval, write_file = t.eq, n.eval, t.write_file
local poke_eventloop = n.poke_eventloop
local exc_exec = n.exc_exec
local dedent = t.dedent
local pcall_err = t.pcall_err
describe('eval', function()
setup(function()
@@ -679,28 +679,37 @@ describe('eval', function()
it('function name not starting with a capital', function()
eq(
'Vim(function):E128: Function name must start with a capital or "s:": g:test()\\nendfunction',
exc_exec(dedent([[
'Vim(function):E128: Function name must start with a capital or "s:": g:test()\nendfunction',
t.pcall_err(
command,
dedent([[
function! g:test()
endfunction]]))
endfunction]])
)
)
end)
it('Function name followed by #', function()
eq(
'Vim(function):E128: Function name must start with a capital or "s:": test2() "#\\nendfunction',
exc_exec(dedent([[
'Vim(function):E128: Function name must start with a capital or "s:": test2() "#\nendfunction',
t.pcall_err(
command,
dedent([[
function! test2() "#
endfunction]]))
endfunction]])
)
)
end)
it('function name includes a colon', function()
eq(
'Vim(function):E884: Function name cannot contain a colon: b:test()\\nendfunction',
exc_exec(dedent([[
'Vim(function):E884: Function name cannot contain a colon: b:test()\nendfunction',
t.pcall_err(
command,
dedent([[
function! b:test()
endfunction]]))
endfunction]])
)
)
end)
@@ -747,7 +756,7 @@ describe('eval', function()
it("using $ instead of '$' must give an error", function()
eq(
'Vim(call):E116: Invalid arguments for function append',
exc_exec('call append($, "foobar")')
t.pcall_err(command, 'call append($, "foobar")')
)
end)

View File

@@ -2,11 +2,12 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local neq = t.neq
local eval = n.eval
local clear = n.clear
local source = n.source
local exc_exec = n.exc_exec
local command = n.command
describe('sort', function()
before_each(clear)
@@ -53,6 +54,6 @@ describe('sort', function()
eq({ '2', 'A', 'AA', 'a', 1, 3.3 }, eval([[sort([3.3, 1, "2", "A", "a", "AA"], '')]]))
eq({ '2', 'A', 'AA', 'a', 1, 3.3 }, eval('sort([3.3, 1, "2", "A", "a", "AA"], 0)'))
eq({ '2', 'A', 'a', 'AA', 1, 3.3 }, eval('sort([3.3, 1, "2", "A", "a", "AA"], 1)'))
neq(nil, exc_exec('call sort([3.3, 1, "2"], 3)'):find('E474:'))
neq(nil, pcall_err(command, 'call sort([3.3, 1, "2"], 3)'):find('E474:'))
end)
end)

View File

@@ -5,10 +5,11 @@ local Screen = require('test.functional.ui.screen')
local clear, feed = n.clear, n.feed
local expect = n.expect
local eq = t.eq
local pcall_err = t.pcall_err
local poke_eventloop = n.poke_eventloop
local exc_exec = n.exc_exec
local feed_command = n.feed_command
local exec = n.exec
local command = n.command
before_each(clear)
@@ -57,7 +58,10 @@ describe(':highlight', function()
feed_command('hi clear')
feed_command('hi Group3')
feed('<cr>')
eq("Vim(highlight):E475: Invalid argument: cterm='asdf", exc_exec([[hi Crash cterm='asdf]]))
eq(
"Vim(highlight):E475: Invalid argument: cterm='asdf",
pcall_err(command, [[hi Crash cterm='asdf]])
)
feed_command('redir END')
-- Filter ctermfg and ctermbg, the numbers depend on the terminal

View File

@@ -5,8 +5,8 @@ local Screen = require('test.functional.ui.screen')
local command, clear = n.command, n.clear
local source, expect = n.source, n.expect
local exc_exec = n.exc_exec
local matches = t.matches
local pcall_err = t.pcall_err
describe('options', function()
setup(clear)
@@ -40,7 +40,7 @@ describe('set', function()
below sp | wincmd _
below sp
]])
matches('E36: Not enough room', exc_exec('set wmh=1'))
matches('E36: Not enough room', pcall_err(command, 'set wmh=1'))
end)
it('winminheight works with tabline', function()
@@ -53,7 +53,7 @@ describe('set', function()
split
tabnew
]])
matches('E36: Not enough room', exc_exec('set wmh=1'))
matches('E36: Not enough room', pcall_err(command, 'set wmh=1'))
end)
it('scroll works', function()
@@ -74,7 +74,7 @@ describe('set', function()
end)
it('foldcolumn and signcolumn to empty string is disallowed', function()
matches('E474: Invalid argument: fdc=', exc_exec('set fdc='))
matches('E474: Invalid argument: scl=', exc_exec('set scl='))
matches('E474: Invalid argument: fdc=', pcall_err(command, 'set fdc='))
matches('E474: Invalid argument: scl=', pcall_err(command, 'set scl='))
end)
end)

View File

@@ -11,6 +11,7 @@ local expect = n.expect
local poke_eventloop = n.poke_eventloop
local api = n.api
local eq = t.eq
local pcall_err = t.pcall_err
local neq = t.neq
local exec_lua = n.exec_lua

View File

@@ -3,8 +3,8 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local eq = t.eq
local pcall_err = t.pcall_err
local eval = n.eval
local exc_exec = n.exc_exec
local expect = n.expect
local insert = n.insert
local source = n.source
@@ -49,9 +49,9 @@ describe("'tagcase' option", function()
-- Verify that the local setting accepts <empty> but that the global setting
-- does not. The first of these (setting the local value to <empty>) should
-- succeed; the other two should fail.
eq(0, exc_exec('setl tc='))
eq('Vim(setglobal):E474: Invalid argument: tc=', exc_exec('setg tc='))
eq('Vim(set):E474: Invalid argument: tc=', exc_exec('set tc='))
n.command('setl tc=')
eq('Vim(setglobal):E474: Invalid argument: tc=', pcall_err(n.command, 'setg tc='))
eq('Vim(set):E474: Invalid argument: tc=', pcall_err(n.command, 'set tc='))
end)
it("should work with 'ignorecase' correctly in all combinations", function()

View File

@@ -2,7 +2,6 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local exc_exec = n.exc_exec
local remove_trace = t.remove_trace
local fn = n.fn
local clear = n.clear
@@ -123,9 +122,12 @@ describe('luaeval(vim.api.…)', function()
-- API strings from Blobs can work as NUL-terminated C strings
eq(
'Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
exc_exec('call nvim_eval(v:_null_blob)')
pcall_err(n.command, 'call nvim_eval(v:_null_blob)')
)
eq(
'Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
pcall_err(n.command, 'call nvim_eval(0z)')
)
eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', exc_exec('call nvim_eval(0z)'))
eq(1, eval('nvim_eval(0z31)'))
eq(0, eval([[type(luaeval('vim.api.nvim__id(1)'))]]))
@@ -303,77 +305,92 @@ describe('luaeval(vim.api.…)', function()
it('validation', function()
-- Conversion errors
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'obj': Cannot convert given Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
)
-- Errors in number of arguments
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 1 argument',
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 1 argument',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id()")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 1 argument',
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 1 argument',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id(1, 2)")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 2 arguments',
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 2 arguments',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
)
-- Error in argument types
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'name': Expected Lua string]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'name': Expected Lua string]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'start': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'start': Number is not integral]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'win': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'start': Expected Lua number]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])
pcall_err(n.command, [[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'start': Number is not integral]],
remove_trace(
pcall_err(n.command, [[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'win': Expected Lua number]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'flt': Expected Lua number]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_float('test')")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'flt': Expected Float-like Lua table]],
remove_trace(
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'arr': Expected Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_array(1)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'arr': Expected Array-like Lua table]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dict(1)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'dct': Expected Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_dict(1)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'dct': Expected Dict-like Lua table]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_dict({[vim.type_idx]=vim.types.array})")]])
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_dict({[vim.type_idx]=vim.types.array})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected Lua table]],
remove_trace(
pcall_err(n.command, [[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])
)
)
-- TODO: check for errors with Tabpage argument

View File

@@ -16,7 +16,6 @@ local fn = n.fn
local source = n.source
local dedent = t.dedent
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local write_file = t.write_file
local remove_trace = t.remove_trace
@@ -63,18 +62,18 @@ describe(':lua', function()
pcall_err(command, 'lua ()')
)
eq(
[[Vim(lua):E5108: Lua: [string ":lua"]:1: TEST]],
remove_trace(exc_exec('lua error("TEST")'))
[[Vim(lua):E5108: Lua: [string ":lua"]:0: TEST]],
remove_trace(pcall_err(command, 'lua error("TEST")'))
)
eq(
[[Vim(lua):E5108: Lua: [string ":lua"]:1: Invalid buffer id: -10]],
remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
[[Vim(lua):E5108: Lua: [string ":lua"]:0: Invalid buffer id: -10]],
remove_trace(pcall_err(command, 'lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
)
eq({ '' }, api.nvim_buf_get_lines(0, 0, 100, false))
end)
it('works with NULL errors', function()
eq([=[Vim(lua):E5108: Lua: [NULL]]=], exc_exec('lua error(nil)'))
eq([=[Vim(lua):E5108: Lua: [NULL]]=], pcall_err(command, 'lua error(nil)'))
end)
it('accepts embedded NLs without heredoc', function()
@@ -144,10 +143,8 @@ describe(':lua', function()
remove_trace(eval('v:errmsg'))
)
local status, err = pcall(command, 'lua error("some error\\nin a\\nAPI command")')
local expected = 'Vim(lua):E5108: Lua: [string ":lua"]:1: some error\nin a\nAPI command'
eq(false, status)
eq(expected, string.sub(remove_trace(err), -string.len(expected)))
local expected = 'Vim(lua):E5108: Lua: [string ":lua"]:0: some error\nin a\nAPI command'
eq(expected, remove_trace(pcall_err(command, 'lua error("some error\\nin a\\nAPI command")')))
feed(':messages<cr>')
screen:expect([[
@@ -284,7 +281,7 @@ describe(':luado command', function()
end)
it('works with NULL errors', function()
eq([=[Vim(luado):E5111: Lua: [NULL]]=], exc_exec('luado error(nil)'))
eq([=[Vim(luado):E5111: Lua: [NULL]]=], pcall_err(command, 'luado error(nil)'))
end)
it('fails in sandbox when needed', function()
@@ -334,19 +331,19 @@ describe(':luafile', function()
write_file(fname, '()')
eq(
("Vim(luafile):E5112: Lua chunk: %s:1: unexpected symbol near ')'"):format(fname),
exc_exec('luafile ' .. fname)
pcall_err(command, 'luafile ' .. fname)
)
write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})')
eq(
("Vim(luafile):E5113: Lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(
fname
),
remove_trace(exc_exec('luafile ' .. fname))
remove_trace(pcall_err(command, 'luafile ' .. fname))
)
end)
it('works with NULL errors', function()
write_file(fname, 'error(nil)')
eq([=[Vim(luafile):E5113: Lua chunk: [NULL]]=], exc_exec('luafile ' .. fname))
eq([=[Vim(luafile):E5113: Lua chunk: [NULL]]=], pcall_err(command, 'luafile ' .. fname))
end)
end)

View File

@@ -4,7 +4,6 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local pcall_err = t.pcall_err
local exc_exec = n.exc_exec
local remove_trace = t.remove_trace
local exec_lua = n.exec_lua
local command = n.command
@@ -198,11 +197,17 @@ describe('luaeval()', function()
it('failure modes', function()
eq(
'Vim(call):E5100: Cannot convert given Lua table: table should contain either only integer keys or only string keys',
exc_exec('call luaeval("{1, foo=2}")')
pcall_err(command, 'call luaeval("{1, foo=2}")')
)
startswith('Vim(call):E5107: Lua: [string "luaeval()"]:', exc_exec('call luaeval("1, 2, 3")'))
startswith('Vim(call):E5108: Lua: [string "luaeval()"]:', exc_exec('call luaeval("(nil)()")'))
startswith(
'Vim(call):E5107: Lua: [string "luaeval()"]:',
pcall_err(command, 'call luaeval("1, 2, 3")')
)
startswith(
'Vim(call):E5108: Lua: [string "luaeval()"]:',
pcall_err(command, 'call luaeval("(nil)()")')
)
end)
it('handles sending lua functions to viml', function()
@@ -482,21 +487,24 @@ describe('luaeval()', function()
it('fails when doing incorrect things in lua', function()
-- Conversion errors
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
remove_trace(exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
remove_trace(pcall_err(command, [[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: ERROR',
remove_trace(exc_exec([[call luaeval("error('ERROR')")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: ERROR',
remove_trace(pcall_err(command, [[call luaeval("error('ERROR')")]]))
)
eq(
'Vim(call):E5108: Lua: [NULL]',
remove_trace(pcall_err(command, [[call luaeval("error(nil)")]]))
)
eq('Vim(call):E5108: Lua: [NULL]', remove_trace(exc_exec([[call luaeval("error(nil)")]])))
end)
it('does not leak memory when called with too long line', function()
local s = ('x'):rep(65536)
eq(
'Vim(call):E5107: Lua: [string "luaeval()"]:1: unexpected symbol near \')\'',
exc_exec([[call luaeval("(']] .. s .. [[' + )")]])
'Vim(call):E5107: Lua: [string "luaeval()"]:0: unexpected symbol near \')\'',
pcall_err(command, [[call luaeval("(']] .. s .. [[' + )")]])
)
eq(s, fn.luaeval('"' .. s .. '"'))
end)

View File

@@ -1,5 +1,6 @@
local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local pcall_err = t.pcall_err
local skip_integ = os.getenv('NVIM_TEST_INTEG') ~= '1'
local exec_lua = n.exec_lua

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local exec_lua = n.exec_lua
local eq = t.eq
local pcall_err = t.pcall_err
local function system_sync(cmd, opts)
return exec_lua(function()

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local eq = t.eq
local pcall_err = t.pcall_err
describe('vim.text', function()
describe('indent()', function()

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local ok = t.ok
local exec_lua = n.exec_lua
local clear = n.clear

View File

@@ -10,10 +10,10 @@ local Screen = require('test.functional.ui.screen')
local assert_alive = n.assert_alive
local assert_log = t.assert_log
local pcall_err = t.pcall_err
local api = n.api
local command = n.command
local clear = n.clear
local exc_exec = n.exc_exec
local eval = n.eval
local eq = t.eq
local ok = t.ok
@@ -916,11 +916,17 @@ describe('stdpath()', function()
it('failure modes', function()
clear()
eq('Vim(call):E6100: "capybara" is not a valid stdpath', exc_exec('call stdpath("capybara")'))
eq('Vim(call):E6100: "" is not a valid stdpath', exc_exec('call stdpath("")'))
eq('Vim(call):E6100: "23" is not a valid stdpath', exc_exec('call stdpath(23)'))
eq('Vim(call):E731: Using a Dictionary as a String', exc_exec('call stdpath({"eris": 23})'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call stdpath([23])'))
eq(
'Vim(call):E6100: "capybara" is not a valid stdpath',
pcall_err(command, 'call stdpath("capybara")')
)
eq('Vim(call):E6100: "" is not a valid stdpath', pcall_err(command, 'call stdpath("")'))
eq('Vim(call):E6100: "23" is not a valid stdpath', pcall_err(command, 'call stdpath(23)'))
eq(
'Vim(call):E731: Using a Dictionary as a String',
pcall_err(command, 'call stdpath({"eris": 23})')
)
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call stdpath([23])'))
end)
it('$NVIM_APPNAME', function()

View File

@@ -5,7 +5,7 @@ local command = n.command
local clear = n.clear
local eval = n.eval
local eq = t.eq
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local feed = n.feed
local scroll = function(direction)
@@ -25,11 +25,11 @@ describe("'mousescroll'", function()
local digit_expected = 'Vim(set):E5080: Digit expected: mousescroll='
local function should_fail(val, errorstr)
eq(errorstr .. val, exc_exec('set mousescroll=' .. val))
eq(errorstr .. val, pcall_err(command, 'set mousescroll=' .. val))
end
local function should_succeed(val)
eq(0, exc_exec('set mousescroll=' .. val))
command('set mousescroll=' .. val)
end
before_each(function()

View File

@@ -1,5 +1,6 @@
local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local pcall_err = t.pcall_err
local clear = n.clear
local exec_lua = n.exec_lua

View File

@@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen')
local t_lsp = require('test.functional.plugin.lsp.testutil')
local eq = t.eq
local pcall_err = t.pcall_err
local dedent = t.dedent
local exec_lua = n.exec_lua
local insert = n.insert

View File

@@ -4,9 +4,9 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local api = n.api
local eq = t.eq
local pcall_err = t.pcall_err
local nvim_eval = n.eval
local nvim_command = n.command
local exc_exec = n.exc_exec
local ok = t.ok
local NIL = vim.NIL
@@ -674,39 +674,63 @@ describe('autoload/msgpack.vim', function()
end)
it('errors out when needed', function()
eq('empty:Parsed string is empty', exc_exec('call msgpack#eval("", {})'))
eq('unknown:Invalid non-space character: ^', exc_exec('call msgpack#eval("^", {})'))
eq(
"char-invalid:Invalid integer character literal format: ''",
exc_exec('call msgpack#eval("\'\'", {})')
t.matches(
'empty:Parsed string is empty',
pcall_err(nvim_command, 'call msgpack#eval("", {})')
)
eq(
"char-invalid:Invalid integer character literal format: 'ab'",
exc_exec('call msgpack#eval("\'ab\'", {})')
t.matches(
'unknown:Invalid non%-space character: %^',
pcall_err(nvim_command, 'call msgpack#eval("^", {})')
)
eq(
"char-invalid:Invalid integer character literal format: '",
exc_exec('call msgpack#eval("\'", {})')
t.matches(
"char%-invalid:Invalid integer character literal format: ''",
pcall_err(nvim_command, 'call msgpack#eval("\'\'", {})')
)
eq('"-invalid:Invalid string: "', exc_exec('call msgpack#eval("\\"", {})'))
eq('"-invalid:Invalid string: ="', exc_exec('call msgpack#eval("=\\"", {})'))
eq('"-invalid:Invalid string: +(0)"', exc_exec('call msgpack#eval("+(0)\\"", {})'))
eq(
'0.-nodigits:Decimal dot must be followed by digit(s): .e1',
exc_exec('call msgpack#eval("0.e1", {})')
t.matches(
"char%-invalid:Invalid integer character literal format: 'ab'",
pcall_err(nvim_command, 'call msgpack#eval("\'ab\'", {})')
)
eq(
'0x-long:Must have at most 16 hex digits: FEDCBA98765432100',
exc_exec('call msgpack#eval("0xFEDCBA98765432100", {})')
t.matches(
"char%-invalid:Invalid integer character literal format: '",
pcall_err(nvim_command, 'call msgpack#eval("\'", {})')
)
t.matches(
'"%-invalid:Invalid string: "',
pcall_err(nvim_command, 'call msgpack#eval("\\"", {})')
)
t.matches(
'"%-invalid:Invalid string: ="',
pcall_err(nvim_command, 'call msgpack#eval("=\\"", {})')
)
t.matches(
'"%-invalid:Invalid string: %+%(0%)"',
pcall_err(nvim_command, 'call msgpack#eval("+(0)\\"", {})')
)
t.matches(
'0%.%-nodigits:Decimal dot must be followed by digit%(s%): %.e1',
pcall_err(nvim_command, 'call msgpack#eval("0.e1", {})')
)
t.matches(
'0x%-long:Must have at most 16 hex digits: FEDCBA98765432100',
pcall_err(nvim_command, 'call msgpack#eval("0xFEDCBA98765432100", {})')
)
t.matches(
'0x%-empty:Must have number after 0x: ',
pcall_err(nvim_command, 'call msgpack#eval("0x", {})')
)
t.matches(
'name%-unknown:Unknown name FOO: FOO',
pcall_err(nvim_command, 'call msgpack#eval("FOO", {})')
)
eq('0x-empty:Must have number after 0x: ', exc_exec('call msgpack#eval("0x", {})'))
eq('name-unknown:Unknown name FOO: FOO', exc_exec('call msgpack#eval("FOO", {})'))
eq(
'name-unknown:Unknown name py3: py3 print(sys.version_info)',
exc_exec('call msgpack#eval("py3 print(sys.version_info)", {})')
t.matches(
'name%-unknown:Unknown name py3: py3 print%(sys%.version_info%)',
pcall_err(nvim_command, 'call msgpack#eval("py3 print(sys.version_info)", {})')
)
t.matches(
'name%-unknown:Unknown name o: o',
pcall_err(nvim_command, 'call msgpack#eval("-info", {})')
)
eq('name-unknown:Unknown name o: o', exc_exec('call msgpack#eval("-info", {})'))
end)
end)
end)

View File

@@ -4,9 +4,9 @@ local Screen = require('test.functional.ui.screen')
local t_shada = require('test.functional.shada.testutil')
local clear = n.clear
local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed =
t.eq, n.api, n.eval, n.command, n.exc_exec, n.fn, n.feed
local eq, api, nvim_eval, nvim_command, fn, nvim_feed = t.eq, n.api, n.eval, n.command, n.fn, n.feed
local neq = t.neq
local pcall_err = t.pcall_err
local read_file = t.read_file
local get_shada_rw = t_shada.get_shada_rw
@@ -92,25 +92,28 @@ describe('autoload/shada.vim', function()
{ type = 1, timestamp = 5, length = 1, data = 7 },
{ type = 1, timestamp = 10, length = 1, data = 5 },
}, nvim_eval(mpack2sd('[1, 5, 1, 7, 1, 10, 1, 5]')))
eq(
'zero-uint:Entry 1 has type element which is zero',
exc_exec('call ' .. mpack2sd('[0, 5, 1, 7]'))
t.matches(
'zero%-uint:Entry 1 has type element which is zero',
pcall_err(nvim_command, 'call ' .. mpack2sd('[0, 5, 1, 7]'))
)
eq(
'zero-uint:Entry 1 has type element which is zero',
exc_exec('call ' .. mpack2sd(('[%s, 5, 1, 7]'):format(sp('integer', '[1, 0, 0, 0]'))))
t.matches(
'zero%-uint:Entry 1 has type element which is zero',
pcall_err(
nvim_command,
'call ' .. mpack2sd(('[%s, 5, 1, 7]'):format(sp('integer', '[1, 0, 0, 0]')))
)
)
eq(
'not-uint:Entry 1 has timestamp element which is not an unsigned integer',
exc_exec('call ' .. mpack2sd('[1, -1, 1, 7]'))
t.matches(
'not%-uint:Entry 1 has timestamp element which is not an unsigned integer',
pcall_err(nvim_command, 'call ' .. mpack2sd('[1, -1, 1, 7]'))
)
eq(
'not-uint:Entry 1 has length element which is not an unsigned integer',
exc_exec('call ' .. mpack2sd('[1, 1, -1, 7]'))
t.matches(
'not%-uint:Entry 1 has length element which is not an unsigned integer',
pcall_err(nvim_command, 'call ' .. mpack2sd('[1, 1, -1, 7]'))
)
eq(
'not-uint:Entry 1 has type element which is not an unsigned integer',
exc_exec('call ' .. mpack2sd('["", 1, -1, 7]'))
t.matches(
'not%-uint:Entry 1 has type element which is not an unsigned integer',
pcall_err(nvim_command, 'call ' .. mpack2sd('["", 1, -1, 7]'))
)
end)
end)
@@ -2941,8 +2944,8 @@ describe('plugin/shada.vim', function()
end)
wshada('\004\000\006\146\000\196\002ab')
wshada_tmp('\004\001\006\146\000\196\002bc')
eq(0, exc_exec('source ' .. fname))
eq(0, exc_exec('source ' .. fname_tmp))
nvim_command('source ' .. fname)
nvim_command('source ' .. fname_tmp)
eq('bc', fn.histget(':', -1))
eq('ab', fn.histget(':', -2))
end)

View File

@@ -5,7 +5,6 @@ local assert_alive = n.assert_alive
local clear = n.clear
local command = n.command
local eq = t.eq
local exc_exec = n.exc_exec
local expect = n.expect
local feed = n.feed
local feed_command = n.feed_command
@@ -121,13 +120,13 @@ describe('rubyeval()', function()
end)
it('errors out when given non-string', function()
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(10)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_dict)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_list)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(0.0)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(function("tr"))'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:true)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:false)'))
eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:null)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(10)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:_null_dict)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:_null_list)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(0.0)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(function("tr"))'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:true)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:false)'))
eq('Vim(call):E474: Invalid argument', pcall_err(command, 'call rubyeval(v:null)'))
end)
end)

View File

@@ -4,7 +4,6 @@ local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local nvim_command, fn, eq = n.command, n.fn, t.eq
local exc_exec = n.exc_exec
local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
local read_shada_file = t_shada.read_shada_file
@@ -26,7 +25,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with search pattern item with BOOL unknown (sX) key value', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -37,7 +36,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('silent! /---/')
nvim_command('wshada ' .. shada_fname)
@@ -58,7 +57,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with s/search pattern item with BOOL unknown (sX) key value', function()
wshada('\002\001\015\131\162sX\194\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -69,7 +68,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('silent! s/--/---/ge')
nvim_command('wshada ' .. shada_fname)
@@ -90,7 +89,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with replacement item with BOOL additional value in list', function()
wshada('\003\000\005\146\196\001-\194')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -102,7 +101,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('silent! s/--/---/ge')
nvim_command('wshada ' .. shada_fname)
@@ -141,7 +140,7 @@ describe('ShaDa forward compatibility support code', function()
eq('' .. mock_file_path .. 'c', fn.bufname('%'))
fn.setline('.', { '1', '2', '3' })
wshada(v.mpack)
eq(0, exc_exec(sdrcmd(true)))
nvim_command(sdrcmd(true))
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -153,7 +152,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
nvim_command('bwipeout!')
fn.setpos("'A", { 0, 1, 1, 0 })
os.remove(shada_fname)
@@ -186,7 +185,7 @@ describe('ShaDa forward compatibility support code', function()
:gsub('n.$', 'n\003')
:gsub('' .. mock_file_path .. 'c', '' .. mock_file_path2 .. 'f')
)
eq(0, exc_exec(sdrcmd(true)))
nvim_command(sdrcmd(true))
nvim_command('wshada ' .. shada_fname)
local found = 0
for i, subv in ipairs(read_shada_file(shada_fname)) do
@@ -224,7 +223,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with register item with BOOL unknown (rX) key', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -234,7 +233,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('let @a = "Test"')
nvim_command('wshada ' .. shada_fname)
@@ -254,7 +253,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with register item with <C-a> name', function()
wshada('\005\001\015\131\161n\001\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd(true)))
nvim_command(sdrcmd(true))
nvim_command('wshada ' .. shada_fname)
local found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
@@ -290,7 +289,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with register item with type 10', function()
wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010')
eq(0, exc_exec(sdrcmd(true)))
nvim_command(sdrcmd(true))
eq({}, fn.getreg('a', 1, 1))
eq('', fn.getregtype('a'))
nvim_command('wshada ' .. shada_fname)
@@ -329,7 +328,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with buffer list item with BOOL unknown (bX) key', function()
nvim_command('set shada+=%')
wshada('\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
eq(2, fn.bufnr('$'))
eq('' .. mock_file_path .. 'c', fn.bufname(2))
os.remove(shada_fname)
@@ -341,7 +340,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('buffer 2')
nvim_command('edit!')
@@ -363,7 +362,7 @@ describe('ShaDa forward compatibility support code', function()
it('works with history item with BOOL additional value in list', function()
wshada('\004\000\006\147\000\196\001-\194')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
nvim_command('wshada ' .. shada_fname)
local found = false
@@ -375,7 +374,7 @@ describe('ShaDa forward compatibility support code', function()
end
end
eq(true, found)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
os.remove(shada_fname)
fn.histadd(':', '--')
fn.histadd(':', '-')
@@ -397,9 +396,9 @@ describe('ShaDa forward compatibility support code', function()
it('works with history item with type 10', function()
wshada('\004\000\006\147\010\196\001-\194')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
nvim_command('wshada ' .. shada_fname)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
local found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then
@@ -434,9 +433,9 @@ describe('ShaDa forward compatibility support code', function()
it('works with item with 100 type', function()
wshada('\100\000\006\147\010\196\001-\194')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
nvim_command('wshada ' .. shada_fname)
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
local found = 0
for i, v in ipairs(read_shada_file(shada_fname)) do
if i == 1 then

View File

@@ -3,7 +3,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local nvim_command, eq, exc_exec = n.command, t.eq, n.exc_exec
local nvim_command, eq = n.command, t.eq
local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-errors.shada')
@@ -22,14 +22,14 @@ describe('ShaDa error handling', function()
it('does not fail on empty file', function()
wshada('')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
end)
it('fails on zero', function()
wshada('\000')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 1, but got nothing',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -37,7 +37,7 @@ describe('ShaDa error handling', function()
wshada('\000\000\000')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 0 that must not be there: Missing items are for internal uses only',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -45,21 +45,21 @@ describe('ShaDa error handling', function()
wshada('\254\000\000')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 0',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
it('does not fail on header with zero length', function()
-- Header items are skipped when reading.
wshada('\001\000\000')
eq(0, exc_exec(sdrcmd()))
nvim_command(sdrcmd())
end)
it('fails on search pattern item with zero length', function()
wshada('\002\000\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -67,7 +67,7 @@ describe('ShaDa error handling', function()
wshada('\002\254\000')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 1',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -75,7 +75,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\254')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 2',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -83,7 +83,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\002\000')
eq(
'Vim(rshada):E576: Error while reading ShaDa file: last entry specified that it occupies 2 bytes, but file ended earlier',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -93,7 +93,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\001\193')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -101,7 +101,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\001\129')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has key value which is not a string',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -109,7 +109,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\005\129\162sX\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has no pattern',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -117,7 +117,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\002\128\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has no pattern',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -125,7 +125,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -134,7 +134,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\013\131\162sp\196\001a\162sX\192\160\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has empty key',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -142,7 +142,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sm\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sm key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -150,7 +150,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sc\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sc key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -158,7 +158,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sb\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sb key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -166,7 +166,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sl\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sl key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -174,7 +174,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162se\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has se key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -182,7 +182,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162su\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has su key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -190,7 +190,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162ss\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has ss key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -198,7 +198,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sh\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sh key value which is not a boolean',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -206,7 +206,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162so\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has so key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -214,7 +214,7 @@ describe('ShaDa error handling', function()
wshada('\002\000\009\130\162sX\192\162sp\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sp key value which is not a binary',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -228,7 +228,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -237,7 +237,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\012\131\161f\196\001/\162mX\192\160\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has empty key',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -245,7 +245,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\008\130\162mX\192\161l\001')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is missing file name',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -253,7 +253,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161l\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -261,7 +261,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161l\255')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -269,7 +269,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161c\255')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid column number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -277,7 +277,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\011\130\162mX\192\161n\163spa')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has n key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -285,7 +285,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\010\130\162mX\192\161l\162sp')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has l key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -293,7 +293,7 @@ describe('ShaDa error handling', function()
wshada(v.mpack .. '\000\010\130\162mX\192\161c\162sp')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has c key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
end
@@ -302,7 +302,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -311,7 +311,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\014\131\162rc\145\196\001a\162rX\192\160\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has empty key',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -319,7 +319,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\009\130\162rX\192\162rt\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rt key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -327,7 +327,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\009\130\162rX\192\162rw\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rw key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -335,7 +335,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\009\130\162rX\192\162rc\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with non-array value',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -343,7 +343,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\009\130\162rX\192\162rc\144')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with missing or empty array',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -351,7 +351,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\013\130\162rX\192\162rc\146\196\001a\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc array with non-binary value',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -359,7 +359,7 @@ describe('ShaDa error handling', function()
wshada('\005\000\009\129\162rX\146\196\001a\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with missing or empty array',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -367,7 +367,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -375,7 +375,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\001\144')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -383,7 +383,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\002\145\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -391,7 +391,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\003\146\192\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history type type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -399,7 +399,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\003\146\000\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history string type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -407,7 +407,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\007\146\000\196\003ab\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 contains string with zero byte inside',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -415,7 +415,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\007\146\001\196\003abc')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 does not have separator character',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -423,7 +423,7 @@ describe('ShaDa error handling', function()
wshada('\004\000\007\147\001\196\002ab\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 has wrong history separator type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -431,7 +431,7 @@ describe('ShaDa error handling', function()
wshada('\006\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -439,7 +439,7 @@ describe('ShaDa error handling', function()
wshada('\006\000\001\144')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -447,7 +447,7 @@ describe('ShaDa error handling', function()
wshada('\006\000\002\145\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -455,7 +455,7 @@ describe('ShaDa error handling', function()
wshada('\006\000\003\146\192\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable name type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -463,7 +463,7 @@ describe('ShaDa error handling', function()
wshada('\006\000\007\147\196\001\065\196\000\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -471,7 +471,7 @@ describe('ShaDa error handling', function()
wshada('\003\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -479,7 +479,7 @@ describe('ShaDa error handling', function()
wshada('\003\000\001\144')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 is not an array with enough elements',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -487,7 +487,7 @@ describe('ShaDa error handling', function()
wshada('\003\000\002\145\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 has wrong sub string type',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -496,7 +496,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\001\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list entry at position 0 is not an array',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -505,7 +505,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\008\146\129\161f\196\001/\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that is not a dict',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -514,7 +514,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\008\146\129\161f\196\001/\128')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that does not have a file name',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -523,7 +523,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that has l key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -532,7 +532,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\000')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -541,7 +541,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\255')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -550,7 +550,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161c\255')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid column number',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -559,7 +559,7 @@ describe('ShaDa error handling', function()
wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161c\192')
eq(
'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that has c key value which is not an integer',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
@@ -635,39 +635,39 @@ $
]])
eq(
'Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
eq(
'Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(nvim_command, 'wshada ' .. shada_fname)
)
eq(0, exc_exec('wshada! ' .. shada_fname))
nvim_command('wshada! ' .. shada_fname)
end)
it('fails on invalid ShaDa file (wrapper script)', function()
wshada('#!/bin/sh\n\npowerline "$@" 2>&1 | tee -a powerline\n')
eq(
'Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
eq(
'Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(nvim_command, 'wshada ' .. shada_fname)
)
eq(0, exc_exec('wshada! ' .. shada_fname))
nvim_command('wshada! ' .. shada_fname)
end)
it('fails on invalid ShaDa file (failing skip in second item)', function()
wshada('\001\000\001\128#!/')
eq(
'Vim(rshada):E576: Reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
eq(
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(nvim_command, 'wshada ' .. shada_fname)
)
eq(0, exc_exec('wshada! ' .. shada_fname))
nvim_command('wshada! ' .. shada_fname)
end)
it('errors with too large items', function()
@@ -855,7 +855,7 @@ $
})
eq(
'Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 93 that is stated to be too long',
exc_exec(sdrcmd())
t.pcall_err(nvim_command, sdrcmd())
)
end)
end)

View File

@@ -1,12 +1,14 @@
-- ShaDa marks saving/reading support
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local api, nvim_command, fn, eq = n.api, n.command, n.fn, t.eq
local feed = n.feed
local exc_exec, exec_capture = n.exc_exec, n.exec_capture
local exec_capture = n.exec_capture
local expect_exit = n.expect_exit
local command = n.command
local reset, clear = t_shada.reset, t_shada.clear
@@ -143,8 +145,8 @@ describe('ShaDa support code', function()
nvim_command('wshada')
reset()
nvim_command('language C')
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `0'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `A'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `0'))
end)
it("restores global and numbered marks even with `'0` and `f0` in shada", function()
@@ -351,7 +353,7 @@ describe('ShaDa support code', function()
}
eq('', p:output())
eq(0, p.status)
eq(0, exc_exec('rshada'))
command('rshada')
end)
it('does not create incorrect file for non-existent buffers opened from -c', function()
@@ -371,7 +373,7 @@ describe('ShaDa support code', function()
}
eq('', p:output())
eq(0, p.status)
eq(0, exc_exec('rshada'))
command('rshada')
end)
it('updates deleted marks with :delmarks', function()
@@ -392,9 +394,9 @@ describe('ShaDa support code', function()
reset()
nvim_command('edit ' .. testfilename)
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `A'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `a'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `.'))
end)
it('updates deleted marks with :delmarks!', function()
@@ -413,8 +415,8 @@ describe('ShaDa support code', function()
reset()
nvim_command('edit ' .. testfilename)
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `a'))
eq('Vim(normal):E20: Mark not set', pcall_err(command, 'normal! `.'))
-- Make sure that uppercase marks aren't deleted.
nvim_command('normal! `A')
end)

View File

@@ -4,8 +4,9 @@ local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local nvim_command, fn, eq = n.command, n.fn, t.eq
local exc_exec, exec_capture = n.exc_exec, n.exec_capture
local exec_capture = n.exec_capture
local api = n.api
local command = n.command
local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
local read_shada_file = t_shada.read_shada_file
@@ -26,11 +27,11 @@ describe('ShaDa history merging code', function()
it('takes item with greater timestamp from Neovim instance when reading', function()
wshada('\004\001\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
command('wshada! ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -44,11 +45,11 @@ describe('ShaDa history merging code', function()
it('takes item with equal timestamp from Neovim instance when reading', function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
command('wshada! ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -62,11 +63,11 @@ describe('ShaDa history merging code', function()
it('takes item with greater timestamp from ShaDa when reading', function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\001\009\147\000\196\002ab\196\001b')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
command('wshada! ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -80,9 +81,9 @@ describe('ShaDa history merging code', function()
it('takes item with greater timestamp from Neovim instance when writing', function()
wshada('\004\001\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -96,9 +97,9 @@ describe('ShaDa history merging code', function()
it('takes item with equal timestamp from Neovim instance when writing', function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\000\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -112,9 +113,9 @@ describe('ShaDa history merging code', function()
it('takes item with greater timestamp from ShaDa when writing', function()
wshada('\004\000\009\147\000\196\002ab\196\001a')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\004\001\009\147\000\196\002ab\196\001b')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
@@ -134,9 +135,9 @@ describe('ShaDa history merging code', function()
.. '\004\100\009\147\000\196\002ae\196\001a'
.. '\004\090\009\147\000\196\002af\196\001a'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
os.remove(shada_fname)
eq(0, exc_exec('wshada! ' .. shada_fname))
command('wshada! ' .. shada_fname)
local items = { 'ad', 'ab', 'ac', 'af', 'ae' }
for i, v in ipairs(items) do
eq(v, fn.histget(':', i))
@@ -160,7 +161,7 @@ describe('ShaDa history merging code', function()
.. '\004\100\009\147\000\196\002ae\196\001a'
.. '\004\090\009\147\000\196\002af\196\001a'
)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local items = { 'ad', 'ab', 'ac', 'af', 'ae' }
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
@@ -189,7 +190,7 @@ describe('ShaDa history merging code', function()
.. '\004\007\009\147\000\196\002ah\196\001a'
.. '\004\008\009\147\000\196\002ai\196\001a'
)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local items = { 'ab', 'ad', 'ac', 'af', 'ae', 'ag', 'ah', 'ai' }
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
@@ -214,7 +215,7 @@ describe('ShaDa history merging code', function()
.. '\004\007\009\147\000\196\002ah\196\001a'
.. '\004\008\009\147\000\196\002ai\196\001a'
)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local items = { 'ab', 'ac', 'ad', 'af', 'ae', 'ag', 'ah', 'ai' }
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
@@ -237,42 +238,42 @@ describe('ShaDa search pattern support code', function()
it('uses last search pattern with gt timestamp from instance when reading', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162sX\194\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('/'))
end)
it('uses last search pattern with gt tstamp from file when reading with bang', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162sX\194\162sp\196\001?')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
eq('?', fn.getreg('/'))
end)
it('uses last search pattern with eq timestamp from instance when reading', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\001\011\130\162sX\194\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('/'))
end)
it('uses last search pattern with gt timestamp from file when reading', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\002\011\130\162sX\194\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('?', fn.getreg('/'))
end)
it('uses last search pattern with gt timestamp from instance when writing', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162sX\194\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '-' then
@@ -284,10 +285,10 @@ describe('ShaDa search pattern support code', function()
it('uses last search pattern with eq timestamp from instance when writing', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\001\011\130\162sX\194\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '-' then
@@ -299,10 +300,10 @@ describe('ShaDa search pattern support code', function()
it('uses last search pattern with gt timestamp from file when writing', function()
wshada('\002\001\011\130\162sX\194\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\002\011\130\162sX\194\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '?' then
@@ -314,42 +315,42 @@ describe('ShaDa search pattern support code', function()
it('uses last s/ pattern with gt timestamp from instance when reading', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162ss\195\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('/'))
end)
it('uses last s/ pattern with gt timestamp from file when reading with !', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162ss\195\162sp\196\001?')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
eq('?', fn.getreg('/'))
end)
it('uses last s/ pattern with eq timestamp from instance when reading', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\001\011\130\162ss\195\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('/'))
end)
it('uses last s/ pattern with gt timestamp from file when reading', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\002\011\130\162ss\195\162sp\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('?', fn.getreg('/'))
end)
it('uses last s/ pattern with gt timestamp from instance when writing', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\000\011\130\162ss\195\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '-' then
@@ -361,10 +362,10 @@ describe('ShaDa search pattern support code', function()
it('uses last s/ pattern with eq timestamp from instance when writing', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\001\011\130\162ss\195\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '-' then
@@ -376,10 +377,10 @@ describe('ShaDa search pattern support code', function()
it('uses last s/ pattern with gt timestamp from file when writing', function()
wshada('\002\001\011\130\162ss\195\162sp\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\002\002\011\130\162ss\195\162sp\196\001?')
eq('-', fn.getreg('/'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 2 and v.value.sp == '?' then
@@ -399,9 +400,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with gt timestamp from instance when reading', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\000\004\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('s/.*/~')
eq('-', fn.getline('.'))
nvim_command('bwipeout!')
@@ -409,9 +410,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with gt timestamp from file when reading with bang', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\000\004\145\196\001?')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
nvim_command('s/.*/~')
eq('?', fn.getline('.'))
nvim_command('bwipeout!')
@@ -419,9 +420,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with eq timestamp from instance when reading', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\001\004\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('s/.*/~')
eq('-', fn.getline('.'))
nvim_command('bwipeout!')
@@ -429,9 +430,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with gt timestamp from file when reading', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\002\004\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('s/.*/~')
eq('?', fn.getline('.'))
nvim_command('bwipeout!')
@@ -439,9 +440,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with gt timestamp from instance when writing', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\000\004\145\196\001?')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 3 and v.value[1] == '-' then
@@ -453,9 +454,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with eq timestamp from instance when writing', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\001\004\145\196\001?')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 3 and v.value[1] == '-' then
@@ -467,9 +468,9 @@ describe('ShaDa replacement string support code', function()
it('uses last replacement with gt timestamp from file when writing', function()
wshada('\003\001\004\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\003\002\004\145\196\001?')
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 3 and v.value[1] == '?' then
@@ -489,19 +490,19 @@ describe('ShaDa marks support code', function()
it('uses last A mark with gt timestamp from instance when reading', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `A')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
end)
it('can merge with file with mark 9 as the only numeric mark', function()
wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `9oabc')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f == mock_file_path .. '-' then
@@ -521,8 +522,8 @@ describe('ShaDa marks support code', function()
.. mock_file_path
.. '-\161n9'
)
eq(0, exc_exec(sdrcmd()))
eq(0, exc_exec('wshada ' .. shada_fname))
command(sdrcmd())
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f == mock_file_path .. '-' then
@@ -569,8 +570,8 @@ describe('ShaDa marks support code', function()
.. mock_file_path
.. 'k\161n9'
)
eq(0, exc_exec(sdrcmd()))
eq(0, exc_exec('wshada ' .. shada_fname))
command(sdrcmd())
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f:sub(1, #mock_file_path) == mock_file_path then
@@ -616,8 +617,8 @@ describe('ShaDa marks support code', function()
.. mock_file_path
.. 'k\161n9'
)
eq(0, exc_exec(sdrcmd()))
eq(0, exc_exec('wshada ' .. shada_fname))
command(sdrcmd())
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f:sub(1, #mock_file_path) == mock_file_path then
@@ -629,38 +630,38 @@ describe('ShaDa marks support code', function()
it('uses last A mark with gt timestamp from file when reading with !', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
nvim_command('normal! `A')
eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
end)
it('uses last A mark with eq timestamp from instance when reading', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `A')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
end)
it('uses last A mark with gt timestamp from file when reading', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `A')
eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
end)
it('uses last A mark with gt timestamp from instance when writing', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f == mock_file_path .. '-' then
@@ -673,11 +674,11 @@ describe('ShaDa marks support code', function()
it('uses last A mark with eq timestamp from instance when writing', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f == mock_file_path .. '-' then
@@ -690,11 +691,11 @@ describe('ShaDa marks support code', function()
it('uses last A mark with gt timestamp from file when writing', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 then
@@ -711,9 +712,9 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `a')
eq('-', fn.getline('.'))
end)
@@ -722,9 +723,9 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
nvim_command('normal! `a')
eq('?', fn.getline('.'))
end)
@@ -733,9 +734,9 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `a')
eq('-', fn.getline('.'))
end)
@@ -744,9 +745,9 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
nvim_command('normal! `a')
eq('?', fn.getline('.'))
end)
@@ -755,11 +756,11 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
nvim_command('normal! `a')
eq('-', fn.getline('.'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if
@@ -778,11 +779,11 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
nvim_command('normal! `a')
eq('-', fn.getline('.'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if
@@ -801,11 +802,11 @@ describe('ShaDa marks support code', function()
nvim_command('edit ' .. mock_file_path .. '-')
fn.setline(1, { '-', '?' })
wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
nvim_command('normal! `a')
eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if
@@ -830,42 +831,42 @@ describe('ShaDa registers support code', function()
it('uses last a register with gt timestamp from instance when reading', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('a'))
end)
it('uses last a register with gt timestamp from file when reading with !', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
eq(0, exc_exec(sdrcmd(true)))
command(sdrcmd(true))
eq('?', fn.getreg('a'))
end)
it('uses last a register with eq timestamp from instance when reading', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('-', fn.getreg('a'))
end)
it('uses last a register with gt timestamp from file when reading', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('?', fn.getreg('a'))
end)
it('uses last a register with gt timestamp from instance when writing', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
eq('-', fn.getreg('a'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 5 and v.value.n == ('a'):byte() then
@@ -878,10 +879,10 @@ describe('ShaDa registers support code', function()
it('uses last a register with eq timestamp from instance when writing', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?')
eq('-', fn.getreg('a'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 5 and v.value.n == ('a'):byte() then
@@ -894,10 +895,10 @@ describe('ShaDa registers support code', function()
it('uses last a register with gt timestamp from file when writing', function()
wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?')
eq('-', fn.getreg('a'))
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 5 and v.value.n == ('a'):byte() then
@@ -928,7 +929,7 @@ describe('ShaDa jumps support code', function()
.. mock_file_path
.. 'e\161l\002'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada(
'\008\001\018\131\162mX\195\161f\196\006'
.. mock_file_path
@@ -940,7 +941,7 @@ describe('ShaDa jumps support code', function()
.. mock_file_path
.. 'f\161l\002'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq('', api.nvim_buf_get_name(0))
eq(
' jump line col file/text\n'
@@ -976,7 +977,7 @@ describe('ShaDa jumps support code', function()
.. mock_file_path
.. 'e\161l\002'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada(
'\008\001\018\131\162mX\195\161f\196\006'
.. mock_file_path
@@ -988,7 +989,7 @@ describe('ShaDa jumps support code', function()
.. mock_file_path
.. 'f\161l\002'
)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local jumps = {
{ file = '' .. mock_file_path .. 'c', line = 2 },
{ file = '' .. mock_file_path .. 'd', line = 2 },
@@ -1016,7 +1017,7 @@ describe('ShaDa jumps support code', function()
jumps[i] = { file = '' .. mock_file_path .. 'c', line = i }
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
shada = ''
for i = 1, 101 do
local _t = i * 2
@@ -1029,7 +1030,7 @@ describe('ShaDa jumps support code', function()
{ file = '' .. mock_file_path .. 'c', line = _t }
end
wshada(shada)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local shift = #jumps - 100
for i = 1, 100 do
jumps[i] = jumps[i + shift]
@@ -1067,7 +1068,7 @@ describe('ShaDa changes support code', function()
.. mock_file_path
.. 'c\161l\003'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada(
'\011\001\018\131\162mX\194\161f\196\006'
.. mock_file_path
@@ -1079,7 +1080,7 @@ describe('ShaDa changes support code', function()
.. mock_file_path
.. 'c\161l\004'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
eq(
'change line col text\n'
.. ' 5 1 0 0\n'
@@ -1106,7 +1107,7 @@ describe('ShaDa changes support code', function()
.. mock_file_path
.. 'c\161l\003'
)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
wshada(
'\011\001\018\131\162mX\194\161f\196\006'
.. mock_file_path
@@ -1118,7 +1119,7 @@ describe('ShaDa changes support code', function()
.. mock_file_path
.. 'c\161l\004'
)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local changes = {
{ line = 1 },
{ line = 2 },
@@ -1147,7 +1148,7 @@ describe('ShaDa changes support code', function()
changes[i] = { line = i }
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
shada = ''
for i = 1, 101 do
local _t = i * 2
@@ -1159,7 +1160,7 @@ describe('ShaDa changes support code', function()
changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t }
end
wshada(shada)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local shift = #changes - 100
for i = 1, 100 do
changes[i] = changes[i + shift]
@@ -1187,7 +1188,7 @@ describe('ShaDa changes support code', function()
)
end
wshada(shada)
eq(0, exc_exec(sdrcmd()))
command(sdrcmd())
shada = ''
for i = 1, 100 do
shada = shada
@@ -1202,7 +1203,7 @@ describe('ShaDa changes support code', function()
changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t }
end
wshada(shada)
eq(0, exc_exec('wshada ' .. shada_fname))
command('wshada ' .. shada_fname)
local shift = #changes - 100
for i = 1, 100 do
changes[i] = changes[i + shift]

View File

@@ -4,9 +4,10 @@ local n = require('test.functional.testnvim')()
local t_shada = require('test.functional.shada.testutil')
local uv = vim.uv
local paths = t.paths
local pcall_err = t.pcall_err
local api, nvim_command, fn, eq = n.api, n.command, n.fn, t.eq
local write_file, set_session, exc_exec = t.write_file, n.set_session, n.exc_exec
local write_file, set_session = t.write_file, n.set_session
local is_os = t.is_os
local skip = t.skip
@@ -33,7 +34,7 @@ describe('ShaDa support code', function()
.. '\100\000\207\000\000\000\000\000\000\004\001\218\003\254'
.. ('-'):rep(1025 - 3)
)
eq(0, exc_exec('wshada ' .. shada_fname))
n.command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 100 then
@@ -41,8 +42,8 @@ describe('ShaDa support code', function()
end
end
eq(2, found)
eq(0, exc_exec('set shada-=s10 shada+=s1'))
eq(0, exc_exec('wshada ' .. shada_fname))
n.command('set shada-=s10 shada+=s1')
n.command('wshada ' .. shada_fname)
found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 100 then
@@ -58,7 +59,7 @@ describe('ShaDa support code', function()
nvim_command('set shada-=s10 shada+=s1')
fn.histadd(':', hist1)
fn.histadd(':', hist2)
eq(0, exc_exec('wshada ' .. shada_fname))
n.command('wshada ' .. shada_fname)
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 4 then
@@ -73,7 +74,7 @@ describe('ShaDa support code', function()
wshada('Some text file')
eq(
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(n.command, 'wshada ' .. shada_fname)
)
eq(1, read_shada_file(shada_fname .. '.tmp.a')[1].type)
end)
@@ -82,7 +83,7 @@ describe('ShaDa support code', function()
'does not leave .tmp.a in-place when there is error in original ShaDa, but writing with bang',
function()
wshada('Some text file')
eq(0, exc_exec('wshada! ' .. shada_fname))
n.command('wshada! ' .. shada_fname)
eq(1, read_shada_file(shada_fname)[1].type)
eq(nil, uv.fs_stat(shada_fname .. '.tmp.a'))
end
@@ -92,11 +93,11 @@ describe('ShaDa support code', function()
wshada('Some text file')
eq(
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(n.command, 'wshada ' .. shada_fname)
)
eq(
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(n.command, 'wshada ' .. shada_fname)
)
eq(1, read_shada_file(shada_fname .. '.tmp.a')[1].type)
eq(1, read_shada_file(shada_fname .. '.tmp.b')[1].type)
@@ -113,7 +114,7 @@ describe('ShaDa support code', function()
end
eq(
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(n.command, 'wshada ' .. shada_fname)
)
eq(1, read_shada_file(shada_fname .. '.tmp.z')[1].type)
end
@@ -128,7 +129,7 @@ describe('ShaDa support code', function()
end
eq(
'Vim(wshada):E138: All Xtest-functional-shada-shada.shada.tmp.X files exist, cannot write ShaDa file!',
exc_exec('wshada ' .. shada_fname)
t.pcall_err(n.command, 'wshada ' .. shada_fname)
)
end)
@@ -143,7 +144,7 @@ describe('ShaDa support code', function()
local s = '\100'
local e = '\001\192'
wshada(s .. table.concat(msgpack, e .. s) .. e)
eq(0, exc_exec('wshada ' .. shada_fname))
n.command('wshada ' .. shada_fname)
local found = 0
local typ = vim.mpack.decode(s)
for _, v in ipairs(read_shada_file(shada_fname)) do
@@ -255,11 +256,14 @@ describe('ShaDa support code', function()
end)
it('setting &shada gives proper error message on missing number', function()
eq([[Vim(set):E526: Missing number after <">: shada="]], exc_exec([[set shada=\"]]))
eq(
[[Vim(set):E526: Missing number after <">: shada="]],
t.pcall_err(n.command, [[set shada=\"]])
)
for _, c in ipairs({ "'", '/', ':', '<', '@', 's' }) do
eq(
([[Vim(set):E526: Missing number after <%s>: shada=%s]]):format(c, c),
exc_exec(([[set shada=%s]]):format(c))
t.pcall_err(n.command, ([[set shada=%s]]):format(c))
)
end
end)
@@ -293,7 +297,7 @@ describe('ShaDa support code', function()
'Vim(wshada):E886: System error while opening ShaDa file '
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
.. 'before writing it: permission denied',
exc_exec('wshada')
t.pcall_err(n.command, 'wshada')
)
api.nvim_set_option_value('shada', '', {})
end)

View File

@@ -11,6 +11,7 @@ local fn = n.fn
local api = n.api
local exec_lua = n.exec_lua
local retry = t.retry
local pcall_err = t.pcall_err
local ok = t.ok
local command = n.command
local skip = t.skip

View File

@@ -10,6 +10,7 @@ local Screen = require('test.functional.ui.screen')
local tt = require('test.functional.testterm')
local eq = t.eq
local pcall_err = t.pcall_err
local feed_data = tt.feed_data
local clear = n.clear
local command = n.command

View File

@@ -9,6 +9,7 @@ local SocketStream = uv_stream.SocketStream
local ProcStream = uv_stream.ProcStream
local check_cores = t.check_cores
local pcall_err = t.pcall_err
local check_logs = t.check_logs
local dedent = t.dedent
local eq = t.eq
@@ -864,20 +865,6 @@ function M.rmdir(path)
end
end
--- @deprecated Use `t.pcall_err()` to check failure, or `n.command()` to check success.
function M.exc_exec(cmd)
M.command(([[
try
execute "%s"
catch
let g:__exception = v:exception
endtry
]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0')))
local ret = M.eval('get(g:, "__exception", 0)')
M.command('unlet! g:__exception')
return ret
end
function M.exec(code)
M.api.nvim_exec2(code, {})
end

View File

@@ -5,6 +5,7 @@ local Screen = require('test.functional.ui.screen')
local clear, feed = n.clear, n.feed
local eval = n.eval
local eq = t.eq
local pcall_err = t.pcall_err
local neq = t.neq
local command = n.command
local set_method_error = n.set_method_error
@@ -14,7 +15,6 @@ local nvim_prog = n.nvim_prog
local testprg = n.testprg
local exec = n.exec
local exec_capture = n.exec_capture
local exc_exec = n.exc_exec
local exec_lua = n.exec_lua
local poke_eventloop = n.poke_eventloop
local assert_alive = n.assert_alive
@@ -2517,7 +2517,7 @@ describe('ui/msg_puts_printf', function()
cmd = 'chcp 932 > NUL & '
end
else
if exc_exec('lang ja_JP.UTF-8') ~= 0 then
if not pcall(n.command, 'lang ja_JP.UTF-8') then
pending('Locale ja_JP.UTF-8 not supported', function() end)
return
end

View File

@@ -4,12 +4,13 @@ local Screen = require('test.functional.ui.screen')
local neq, eq, command = t.neq, t.eq, n.command
local clear = n.clear
local exc_exec, expect, eval = n.exc_exec, n.expect, n.eval
local expect, eval = n.expect, n.eval
local exec_lua = n.exec_lua
local insert, pcall_err = n.insert, t.pcall_err
local matches = t.matches
local api = n.api
local feed = n.feed
local command = n.command
describe('eval-API', function()
before_each(clear)
@@ -32,31 +33,31 @@ describe('eval-API', function()
end)
it('throw errors for invalid arguments', function()
local err = exc_exec('call nvim_get_current_buf("foo")')
local err = pcall_err(command, 'call nvim_get_current_buf("foo")')
eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err)
err = exc_exec('call nvim_set_option_value("hlsearch")')
err = pcall_err(command, 'call nvim_set_option_value("hlsearch")')
eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err)
err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])')
err = pcall_err(command, 'call nvim_buf_set_lines(1, 0, -1, [], ["list"])')
eq(
'Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean',
err
)
err = exc_exec('call nvim_buf_set_lines(0, 0, -1, v:true, "string")')
err = pcall_err(command, 'call nvim_buf_set_lines(0, 0, -1, v:true, "string")')
eq(
'Vim(call):E5555: API call: Wrong type for argument 5 when calling nvim_buf_set_lines, expecting ArrayOf(String)',
err
)
err = exc_exec('call nvim_buf_get_number("0")')
err = pcall_err(command, 'call nvim_buf_get_number("0")')
eq(
'Vim(call):E5555: API call: Wrong type for argument 1 when calling nvim_buf_get_number, expecting Buffer',
err
)
err = exc_exec('call nvim_buf_line_count(17)')
err = pcall_err(command, 'call nvim_buf_line_count(17)')
eq('Vim(call):E5555: API call: Invalid buffer id: 17', err)
end)
@@ -166,20 +167,20 @@ describe('eval-API', function()
it('that are FUNC_ATTR_NOEVAL cannot be called', function()
-- Deprecated vim_ prefix is not exported.
local err = exc_exec('call vim_get_current_buffer("foo")')
local err = pcall_err(command, 'call vim_get_current_buffer("foo")')
eq('Vim(call):E117: Unknown function: vim_get_current_buffer', err)
-- Deprecated buffer_ prefix is not exported.
err = exc_exec('call buffer_line_count(0)')
err = pcall_err(command, 'call buffer_line_count(0)')
eq('Vim(call):E117: Unknown function: buffer_line_count', err)
-- Functions deprecated before the api functions became available
-- in vimscript are not exported.
err = exc_exec('call buffer_get_line(0, 1)')
err = pcall_err(command, 'call buffer_get_line(0, 1)')
eq('Vim(call):E117: Unknown function: buffer_get_line', err)
-- some api functions are only useful from a msgpack-rpc channel
err = exc_exec('call nvim_set_client_info()')
err = pcall_err(command, 'call nvim_set_client_info()')
eq('Vim(call):E117: Unknown function: nvim_set_client_info', err)
end)

View File

@@ -6,7 +6,6 @@ local clear = n.clear
local fn = n.fn
local api = n.api
local command = n.command
local exc_exec = n.exc_exec
local get_pathsep = n.get_pathsep
local rmdir = n.rmdir
local pcall_err = t.pcall_err
@@ -34,30 +33,30 @@ for _, func in ipairs({
for _, var in ipairs({ 'v:true', 'v:false' }) do
eq(
'Vim(call):E5299: Expected a Number or a String, Boolean found',
exc_exec('call ' .. func:format(var))
pcall_err(command, 'call ' .. func:format(var))
)
end
eq(
'Vim(call):E5300: Expected a Number or a String',
exc_exec('call ' .. func:format('v:null'))
pcall_err(command, 'call ' .. func:format('v:null'))
)
end)
it('errors out when receives invalid argument', function()
eq(
'Vim(call):E745: Expected a Number or a String, List found',
exc_exec('call ' .. func:format('[]'))
pcall_err(command, 'call ' .. func:format('[]'))
)
eq(
'Vim(call):E728: Expected a Number or a String, Dictionary found',
exc_exec('call ' .. func:format('{}'))
pcall_err(command, 'call ' .. func:format('{}'))
)
eq(
'Vim(call):E805: Expected a Number or a String, Float found',
exc_exec('call ' .. func:format('0.0'))
pcall_err(command, 'call ' .. func:format('0.0'))
)
eq(
'Vim(call):E703: Expected a Number or a String, Funcref found',
exc_exec('call ' .. func:format('function("tr")'))
pcall_err(command, 'call ' .. func:format('function("tr")'))
)
end)
end)
@@ -267,17 +266,17 @@ end)
describe('setbufvar() function', function()
it('throws the error or ignores the input when buffer was not found', function()
command('file ' .. fname)
eq(0, exc_exec('call setbufvar(2, "&autoindent", 0)'))
command('call setbufvar(2, "&autoindent", 0)')
eq(
'Vim(call):E94: No matching buffer for non-existent-buffer',
exc_exec('call setbufvar("non-existent-buffer", "&autoindent", 0)')
pcall_err(command, 'call setbufvar("non-existent-buffer", "&autoindent", 0)')
)
eq(0, exc_exec('call setbufvar("#", "&autoindent", 0)'))
command('call setbufvar("#", "&autoindent", 0)')
command('edit ' .. fname2)
eq(2, fn.bufnr('%'))
eq(
'Vim(call):E93: More than one match for X',
exc_exec('call setbufvar("X", "&autoindent", 0)')
pcall_err(command, 'call setbufvar("X", "&autoindent", 0)')
)
end)
it('may set options, including window-local and global values', function()
@@ -300,7 +299,7 @@ describe('setbufvar() function', function()
eq(false, api.nvim_get_option_value('autoindent', { buf = buf1 }))
fn.setbufvar(1, '&autoindent', true)
eq(true, api.nvim_get_option_value('autoindent', { buf = buf1 }))
eq('Vim(call):E355: Unknown option: xxx', exc_exec('call setbufvar(1, "&xxx", 0)'))
eq('Vim(call):E355: Unknown option: xxx', pcall_err(command, 'call setbufvar(1, "&xxx", 0)'))
end)
it('may set variables', function()
local buf1 = api.nvim_get_current_buf()
@@ -309,7 +308,7 @@ describe('setbufvar() function', function()
eq(2, api.nvim_buf_get_number(0))
fn.setbufvar(1, 'number', true)
eq(true, api.nvim_buf_get_var(buf1, 'number'))
eq('Vim(call):E461: Illegal variable name: b:', exc_exec('call setbufvar(1, "", 0)'))
eq('Vim(call):E461: Illegal variable name: b:', pcall_err(command, 'call setbufvar(1, "", 0)'))
eq(true, api.nvim_buf_get_var(buf1, 'number'))
eq(
'Vim:E46: Cannot change read-only variable "b:changedtick"',

View File

@@ -8,7 +8,6 @@ local clear = n.clear
local fn = n.fn
local api = n.api
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local exec_capture = n.exec_capture
@@ -34,7 +33,7 @@ describe('b:changedtick', function()
eq(2, changedtick())
fn.setline(1, 'hello')
eq(3, changedtick())
eq(0, exc_exec('undo'))
command('undo')
-- Somehow undo counts as two changes
eq(5, changedtick())
end)
@@ -55,7 +54,7 @@ describe('b:changedtick', function()
it('fails to be changed by user', function()
local ct = changedtick()
local ctn = ct + 100500
eq(0, exc_exec('let d = b:'))
command('let d = b:')
eq(
'Vim(let):E46: Cannot change read-only variable "b:changedtick"',
pcall_err(command, 'let b:changedtick = ' .. ctn)
@@ -116,7 +115,7 @@ describe('b:changedtick', function()
eq('b:changedtick #2', exec_capture(':let b:'))
end)
it('fails to unlock b:changedtick', function()
eq(0, exc_exec('let d = b:'))
command('let d = b:')
eq(0, fn.islocked('b:changedtick'))
eq(0, fn.islocked('d.changedtick'))
eq(

View File

@@ -4,7 +4,7 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local command = n.command
local eq = t.eq
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local get_win_var = n.api.nvim_win_get_var
describe('setqflist()', function()
@@ -13,15 +13,15 @@ describe('setqflist()', function()
before_each(clear)
it('requires a list for {list}', function()
eq('Vim(call):E714: List required', exc_exec('call setqflist("foo")'))
eq('Vim(call):E714: List required', exc_exec('call setqflist(5)'))
eq('Vim(call):E714: List required', exc_exec('call setqflist({})'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist("foo")'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist(5)'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setqflist({})'))
end)
it('requires a string for {action}', function()
eq('Vim(call):E928: String required', exc_exec('call setqflist([], 5)'))
eq('Vim(call):E928: String required', exc_exec('call setqflist([], [])'))
eq('Vim(call):E928: String required', exc_exec('call setqflist([], {})'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], 5)'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], [])'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setqflist([], {})'))
end)
it('sets w:quickfix_title', function()
@@ -41,7 +41,7 @@ describe('setqflist()', function()
it('requires a dict for {what}', function()
eq(
'Vim(call):E715: Dictionary required',
exc_exec('call setqflist([], "r", function("function"))')
pcall_err(command, 'call setqflist([], "r", function("function"))')
)
end)
end)
@@ -52,15 +52,15 @@ describe('setloclist()', function()
before_each(clear)
it('requires a list for {list}', function()
eq('Vim(call):E714: List required', exc_exec('call setloclist(0, "foo")'))
eq('Vim(call):E714: List required', exc_exec('call setloclist(0, 5)'))
eq('Vim(call):E714: List required', exc_exec('call setloclist(0, {})'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, "foo")'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, 5)'))
eq('Vim(call):E714: List required', pcall_err(command, 'call setloclist(0, {})'))
end)
it('requires a string for {action}', function()
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], 5)'))
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], [])'))
eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], {})'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], 5)'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], [])'))
eq('Vim(call):E928: String required', pcall_err(command, 'call setloclist(0, [], {})'))
end)
it('sets w:quickfix_title for the correct window', function()

View File

@@ -14,10 +14,10 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local mkdir = t.mkdir
local pcall_err = t.pcall_err
local clear = n.clear
local eq = t.eq
local exec = n.exec
local exc_exec = n.exc_exec
local exec_lua = n.exec_lua
local exec_capture = n.exec_capture
local eval = n.eval
@@ -42,7 +42,8 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
local rep = n.fn['repeat']
local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,'
eq(expected, printf(rep('%d,', max_func_args - 1), unpack(range(2, max_func_args))))
local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)')
local ret =
pcall_err(command, 'call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)')
eq('Vim(call):E740: Too many arguments for function printf', ret)
end)
@@ -50,7 +51,10 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
local rpcnotify = n.fn.rpcnotify
local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args)))
eq(1, ret)
ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)')
ret = pcall_err(
command,
'call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)'
)
eq('Vim(call):E740: Too many arguments for function rpcnotify', ret)
end)
end)
@@ -158,7 +162,7 @@ describe('uncaught exception', function()
it('is not forgotten #13490', function()
command('autocmd BufWinEnter * throw "i am error"')
eq('i am error', exc_exec('try | new | endtry'))
t.matches('i am error', pcall_err(command, 'try | new | endtry'))
-- Like Vim, throwing here aborts the processing of the script, but does not stop :runtime!
-- from processing the others.
@@ -180,7 +184,7 @@ describe('uncaught exception', function()
end)
command('set runtimepath+=. | let result = ""')
eq('throw1', exc_exec('try | runtime! throw*.vim | endtry'))
t.matches('throw1', pcall_err(command, 'try | runtime! throw*.vim | endtry'))
eq('123', eval('result'))
end)

View File

@@ -2,9 +2,9 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq, clear, call, write_file, command = t.eq, n.clear, n.call, t.write_file, n.command
local exc_exec = n.exc_exec
local eval = n.eval
local is_os = t.is_os
local pcall_err = t.pcall_err
describe('executable()', function()
before_each(clear)
@@ -55,14 +55,14 @@ describe('executable()', function()
for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do
eq(
'Vim(call):E1174: String required for argument 1',
exc_exec('call executable(' .. input .. ')')
pcall_err(command, 'call executable(' .. input .. ')')
)
end
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do
eq(
'Vim(call):E1174: String required for argument 1',
exc_exec('call executable(' .. input .. ')')
pcall_err(command, 'call executable(' .. input .. ')')
)
end
end)

View File

@@ -6,7 +6,6 @@ local eq = t.eq
local eval = n.eval
local clear = n.clear
local source = n.source
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local fn = n.fn
local command = n.command
@@ -89,19 +88,19 @@ describe('execute()', function()
it('returns empty string if the argument list is empty', function()
eq('', fn.execute({}))
eq(0, exc_exec('let g:ret = execute(v:_null_list)'))
command('let g:ret = execute(v:_null_list)')
eq('', eval('g:ret'))
end)
it('captures errors', function()
local ret
ret = exc_exec('call execute(v:_null_dict)')
ret = pcall_err(command, 'call execute(v:_null_dict)')
eq('Vim(call):E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(function("tr"))')
ret = pcall_err(command, 'call execute(function("tr"))')
eq('Vim(call):E729: Using a Funcref as a String', ret)
ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])')
ret = pcall_err(command, 'call execute(["echo 42", v:_null_dict, "echo 44"])')
eq('Vim:E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])')
ret = pcall_err(command, 'call execute(["echo 42", function("tr"), "echo 44"])')
eq('Vim:E729: Using a Funcref as a String', ret)
end)
@@ -305,31 +304,31 @@ describe('execute()', function()
end)
it('suppresses errors for "silent!"', function()
eq(0, exc_exec('let g:mes = execute(0.0, "silent!")'))
command('let g:mes = execute(0.0, "silent!")')
eq('', eval('g:mes'))
eq(0, exc_exec('let g:mes = execute("echon add(1, 1)", "silent!")'))
command('let g:mes = execute("echon add(1, 1)", "silent!")')
eq('1', eval('g:mes'))
eq(0, exc_exec('let g:mes = execute(["echon 42", "echon add(1, 1)"], "silent!")'))
command('let g:mes = execute(["echon 42", "echon add(1, 1)"], "silent!")')
eq('421', eval('g:mes'))
end)
it('propagates errors for "" and "silent"', function()
local ret
ret = exc_exec('call execute(v:_null_dict, "silent")')
ret = pcall_err(command, 'call execute(v:_null_dict, "silent")')
eq('Vim(call):E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute("echo add(1, 1)", "")')
ret = pcall_err(command, 'call execute("echo add(1, 1)", "")')
eq('Vim(echo):E897: List or Blob required', ret)
ret = exc_exec('call execute(["echon 42", "echo add(1, 1)"], "")')
ret = pcall_err(command, 'call execute(["echon 42", "echo add(1, 1)"], "")')
eq('Vim(echo):E897: List or Blob required', ret)
ret = exc_exec('call execute("echo add(1, 1)", "silent")')
ret = pcall_err(command, 'call execute("echo add(1, 1)", "silent")')
eq('Vim(echo):E897: List or Blob required', ret)
ret = exc_exec('call execute(["echon 42", "echo add(1, 1)"], "silent")')
ret = pcall_err(command, 'call execute(["echon 42", "echo add(1, 1)"], "silent")')
eq('Vim(echo):E897: List or Blob required', ret)
end)
end)

View File

@@ -3,8 +3,8 @@ local n = require('test.functional.testnvim')()
local eq, clear, call = t.eq, n.clear, n.call
local command = n.command
local exc_exec = n.exc_exec
local matches = t.matches
local pcall_err = t.pcall_err
local is_os = t.is_os
local set_shell_powershell = n.set_shell_powershell
local eval = n.eval
@@ -25,15 +25,18 @@ describe('exepath()', function()
for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do
eq(
'Vim(call):E1174: String required for argument 1',
exc_exec('call exepath(' .. input .. ')')
pcall_err(command, 'call exepath(' .. input .. ')')
)
end
eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")'))
eq(
'Vim(call):E1175: Non-empty string required for argument 1',
pcall_err(command, 'call exepath("")')
)
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do
eq(
'Vim(call):E1174: String required for argument 1',
exc_exec('call exepath(' .. input .. ')')
pcall_err(command, 'call exepath(' .. input .. ')')
)
end
end)

View File

@@ -3,12 +3,12 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local eq = t.eq
local pcall_err = t.pcall_err
local feed = n.feed
local api = n.api
local clear = n.clear
local source = n.source
local command = n.command
local exc_exec = n.exc_exec
local async_meths = n.async_meths
local NIL = vim.NIL
@@ -205,16 +205,25 @@ describe('input()', function()
eq('DEF2', api.nvim_get_var('var'))
end)
it('errors out on invalid inputs', function()
eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", [])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", "", [])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"prompt": []})'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"default": []})'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"completion": []})'))
eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call input({}, "default")'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call input([])'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call input("", [])'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call input("", "", [])'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call input({"prompt": []})'))
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call input({"default": []})')
)
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call input({"completion": []})')
)
eq(
'Vim(call):E5050: {opts} must be the only argument',
pcall_err(command, 'call input({}, "default")')
)
eq(
'Vim(call):E118: Too many arguments for function: input',
exc_exec('call input("prompt> ", "default", "file", "extra")')
pcall_err(command, 'call input("prompt> ", "default", "file", "extra")')
)
end)
it('supports highlighting', function()
@@ -378,19 +387,31 @@ describe('inputdialog()', function()
eq('DEF2', api.nvim_get_var('var'))
end)
it('errors out on invalid inputs', function()
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", [])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", "", [])'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"prompt": []})'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"default": []})'))
eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"completion": []})'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call inputdialog([])'))
eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call inputdialog("", [])'))
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call inputdialog("", "", [])')
)
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call inputdialog({"prompt": []})')
)
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call inputdialog({"default": []})')
)
eq(
'Vim(call):E730: Using a List as a String',
pcall_err(command, 'call inputdialog({"completion": []})')
)
eq(
'Vim(call):E5050: {opts} must be the only argument',
exc_exec('call inputdialog({}, "default")')
pcall_err(command, 'call inputdialog({}, "default")')
)
eq(
'Vim(call):E118: Too many arguments for function: inputdialog',
exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')
pcall_err(command, 'call inputdialog("prompt> ", "default", "file", "extra")')
)
end)
it('supports highlighting', function()

View File

@@ -5,9 +5,9 @@ local clear = n.clear
local fn = n.fn
local api = n.api
local eq = t.eq
local matches = t.matches
local eval = n.eval
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local NIL = vim.NIL
local source = n.source
@@ -92,21 +92,30 @@ describe('json_decode() function', function()
end)
it('fails to parse incomplete null, true, false', function()
eq('Vim(call):E474: Expected null: n', exc_exec('call json_decode("n")'))
eq('Vim(call):E474: Expected null: nu', exc_exec('call json_decode("nu")'))
eq('Vim(call):E474: Expected null: nul', exc_exec('call json_decode("nul")'))
eq('Vim(call):E474: Expected null: nul\n\t', exc_exec('call json_decode("nul\\n\\t")'))
eq('Vim(call):E474: Expected null: n', pcall_err(command, 'call json_decode("n")'))
eq('Vim(call):E474: Expected null: nu', pcall_err(command, 'call json_decode("nu")'))
eq('Vim(call):E474: Expected null: nul', pcall_err(command, 'call json_decode("nul")'))
matches(
'Vim%(call%):E474: Expected null: nul',
pcall_err(command, 'call json_decode("nul\\n\\t")')
)
eq('Vim(call):E474: Expected true: t', exc_exec('call json_decode("t")'))
eq('Vim(call):E474: Expected true: tr', exc_exec('call json_decode("tr")'))
eq('Vim(call):E474: Expected true: tru', exc_exec('call json_decode("tru")'))
eq('Vim(call):E474: Expected true: tru\t\n', exc_exec('call json_decode("tru\\t\\n")'))
eq('Vim(call):E474: Expected true: t', pcall_err(command, 'call json_decode("t")'))
eq('Vim(call):E474: Expected true: tr', pcall_err(command, 'call json_decode("tr")'))
eq('Vim(call):E474: Expected true: tru', pcall_err(command, 'call json_decode("tru")'))
matches(
'Vim%(call%):E474: Expected true: tru',
pcall_err(command, 'call json_decode("tru\\t\\n")')
)
eq('Vim(call):E474: Expected false: f', exc_exec('call json_decode("f")'))
eq('Vim(call):E474: Expected false: fa', exc_exec('call json_decode("fa")'))
eq('Vim(call):E474: Expected false: fal', exc_exec('call json_decode("fal")'))
eq('Vim(call):E474: Expected false: fal <', exc_exec('call json_decode(" fal <")'))
eq('Vim(call):E474: Expected false: fals', exc_exec('call json_decode("fals")'))
eq('Vim(call):E474: Expected false: f', pcall_err(command, 'call json_decode("f")'))
eq('Vim(call):E474: Expected false: fa', pcall_err(command, 'call json_decode("fa")'))
eq('Vim(call):E474: Expected false: fal', pcall_err(command, 'call json_decode("fal")'))
eq(
'Vim(call):E474: Expected false: fal <',
pcall_err(command, 'call json_decode(" fal <")')
)
eq('Vim(call):E474: Expected false: fals', pcall_err(command, 'call json_decode("fals")'))
end)
it('parses integer numbers', function()
@@ -119,40 +128,61 @@ describe('json_decode() function', function()
end)
it('fails to parse +numbers and .number', function()
eq('Vim(call):E474: Unidentified byte: +1000', exc_exec('call json_decode("+1000")'))
eq('Vim(call):E474: Unidentified byte: .1000', exc_exec('call json_decode(".1000")'))
eq('Vim(call):E474: Unidentified byte: +1000', pcall_err(command, 'call json_decode("+1000")'))
eq('Vim(call):E474: Unidentified byte: .1000', pcall_err(command, 'call json_decode(".1000")'))
end)
it('fails to parse numbers with leading zeroes', function()
eq('Vim(call):E474: Leading zeroes are not allowed: 00.1', exc_exec('call json_decode("00.1")'))
eq('Vim(call):E474: Leading zeroes are not allowed: 01', exc_exec('call json_decode("01")'))
eq('Vim(call):E474: Leading zeroes are not allowed: -01', exc_exec('call json_decode("-01")'))
eq(
'Vim(call):E474: Leading zeroes are not allowed: 00.1',
pcall_err(command, 'call json_decode("00.1")')
)
eq(
'Vim(call):E474: Leading zeroes are not allowed: 01',
pcall_err(command, 'call json_decode("01")')
)
eq(
'Vim(call):E474: Leading zeroes are not allowed: -01',
pcall_err(command, 'call json_decode("-01")')
)
eq(
'Vim(call):E474: Leading zeroes are not allowed: -001.0',
exc_exec('call json_decode("-001.0")')
pcall_err(command, 'call json_decode("-001.0")')
)
end)
it('fails to parse incomplete numbers', function()
eq('Vim(call):E474: Missing number after minus sign: -.1', exc_exec('call json_decode("-.1")'))
eq('Vim(call):E474: Missing number after minus sign: -', exc_exec('call json_decode("-")'))
eq('Vim(call):E474: Missing number after decimal dot: -1.', exc_exec('call json_decode("-1.")'))
eq('Vim(call):E474: Missing number after decimal dot: 0.', exc_exec('call json_decode("0.")'))
eq('Vim(call):E474: Missing exponent: 0.0e', exc_exec('call json_decode("0.0e")'))
eq('Vim(call):E474: Missing exponent: 0.0e+', exc_exec('call json_decode("0.0e+")'))
eq('Vim(call):E474: Missing exponent: 0.0e-', exc_exec('call json_decode("0.0e-")'))
eq('Vim(call):E474: Missing exponent: 0.0e-', exc_exec('call json_decode("0.0e-")'))
eq(
'Vim(call):E474: Missing number after minus sign: -.1',
pcall_err(command, 'call json_decode("-.1")')
)
eq(
'Vim(call):E474: Missing number after minus sign: -',
pcall_err(command, 'call json_decode("-")')
)
eq(
'Vim(call):E474: Missing number after decimal dot: -1.',
pcall_err(command, 'call json_decode("-1.")')
)
eq(
'Vim(call):E474: Missing number after decimal dot: 0.',
pcall_err(command, 'call json_decode("0.")')
)
eq('Vim(call):E474: Missing exponent: 0.0e', pcall_err(command, 'call json_decode("0.0e")'))
eq('Vim(call):E474: Missing exponent: 0.0e+', pcall_err(command, 'call json_decode("0.0e+")'))
eq('Vim(call):E474: Missing exponent: 0.0e-', pcall_err(command, 'call json_decode("0.0e-")'))
eq('Vim(call):E474: Missing exponent: 0.0e-', pcall_err(command, 'call json_decode("0.0e-")'))
eq(
'Vim(call):E474: Missing number after decimal dot: 1.e5',
exc_exec('call json_decode("1.e5")')
pcall_err(command, 'call json_decode("1.e5")')
)
eq(
'Vim(call):E474: Missing number after decimal dot: 1.e+5',
exc_exec('call json_decode("1.e+5")')
pcall_err(command, 'call json_decode("1.e+5")')
)
eq(
'Vim(call):E474: Missing number after decimal dot: 1.e+',
exc_exec('call json_decode("1.e+")')
pcall_err(command, 'call json_decode("1.e+")')
)
end)
@@ -193,21 +223,36 @@ describe('json_decode() function', function()
it('fails to parse numbers with spaces inside', function()
eq(
'Vim(call):E474: Missing number after minus sign: - 1000',
exc_exec('call json_decode("- 1000")')
pcall_err(command, 'call json_decode("- 1000")')
)
eq(
'Vim(call):E474: Missing number after decimal dot: 0. ',
pcall_err(command, 'call json_decode("0. ")')
)
eq('Vim(call):E474: Missing number after decimal dot: 0. ', exc_exec('call json_decode("0. ")'))
eq(
'Vim(call):E474: Missing number after decimal dot: 0. 0',
exc_exec('call json_decode("0. 0")')
pcall_err(command, 'call json_decode("0. 0")')
)
eq('Vim(call):E474: Missing exponent: 0.0e 1', pcall_err(command, 'call json_decode("0.0e 1")'))
eq(
'Vim(call):E474: Missing exponent: 0.0e+ 1',
pcall_err(command, 'call json_decode("0.0e+ 1")')
)
eq(
'Vim(call):E474: Missing exponent: 0.0e- 1',
pcall_err(command, 'call json_decode("0.0e- 1")')
)
eq('Vim(call):E474: Missing exponent: 0.0e 1', exc_exec('call json_decode("0.0e 1")'))
eq('Vim(call):E474: Missing exponent: 0.0e+ 1', exc_exec('call json_decode("0.0e+ 1")'))
eq('Vim(call):E474: Missing exponent: 0.0e- 1', exc_exec('call json_decode("0.0e- 1")'))
end)
it('fails to parse "," and ":"', function()
eq('Vim(call):E474: Comma not inside container: , ', exc_exec('call json_decode(" , ")'))
eq('Vim(call):E474: Colon not inside container: : ', exc_exec('call json_decode(" : ")'))
eq(
'Vim(call):E474: Comma not inside container: , ',
pcall_err(command, 'call json_decode(" , ")')
)
eq(
'Vim(call):E474: Colon not inside container: : ',
pcall_err(command, 'call json_decode(" : ")')
)
end)
it('parses empty containers', function()
@@ -216,89 +261,101 @@ describe('json_decode() function', function()
end)
it('fails to parse "[" and "{"', function()
eq('Vim(call):E474: Unexpected end of input: {', exc_exec('call json_decode("{")'))
eq('Vim(call):E474: Unexpected end of input: [', exc_exec('call json_decode("[")'))
eq('Vim(call):E474: Unexpected end of input: {', pcall_err(command, 'call json_decode("{")'))
eq('Vim(call):E474: Unexpected end of input: [', pcall_err(command, 'call json_decode("[")'))
end)
it('fails to parse "}" and "]"', function()
eq('Vim(call):E474: No container to close: ]', exc_exec('call json_decode("]")'))
eq('Vim(call):E474: No container to close: }', exc_exec('call json_decode("}")'))
eq('Vim(call):E474: No container to close: ]', pcall_err(command, 'call json_decode("]")'))
eq('Vim(call):E474: No container to close: }', pcall_err(command, 'call json_decode("}")'))
end)
it('fails to parse containers which are closed by different brackets', function()
eq(
'Vim(call):E474: Closing dictionary with square bracket: ]',
exc_exec('call json_decode("{]")')
pcall_err(command, 'call json_decode("{]")')
)
eq(
'Vim(call):E474: Closing list with curly bracket: }',
pcall_err(command, 'call json_decode("[}")')
)
eq('Vim(call):E474: Closing list with curly bracket: }', exc_exec('call json_decode("[}")'))
end)
it('fails to parse concat inside container', function()
eq(
'Vim(call):E474: Expected comma before list item: []]',
exc_exec('call json_decode("[[][]]")')
pcall_err(command, 'call json_decode("[[][]]")')
)
eq(
'Vim(call):E474: Expected comma before list item: {}]',
exc_exec('call json_decode("[{}{}]")')
pcall_err(command, 'call json_decode("[{}{}]")')
)
eq(
'Vim(call):E474: Expected comma before list item: ]',
pcall_err(command, 'call json_decode("[1 2]")')
)
eq('Vim(call):E474: Expected comma before list item: ]', exc_exec('call json_decode("[1 2]")'))
eq(
'Vim(call):E474: Expected comma before dictionary key: ": 4}',
exc_exec('call json_decode("{\\"1\\": 2 \\"3\\": 4}")')
pcall_err(command, 'call json_decode("{\\"1\\": 2 \\"3\\": 4}")')
)
eq(
'Vim(call):E474: Expected colon before dictionary value: , "3" 4}',
exc_exec('call json_decode("{\\"1\\" 2, \\"3\\" 4}")')
pcall_err(command, 'call json_decode("{\\"1\\" 2, \\"3\\" 4}")')
)
end)
it('fails to parse containers with leading comma or colon', function()
eq('Vim(call):E474: Leading comma: ,}', exc_exec('call json_decode("{,}")'))
eq('Vim(call):E474: Leading comma: ,]', exc_exec('call json_decode("[,]")'))
eq('Vim(call):E474: Using colon not in dictionary: :]', exc_exec('call json_decode("[:]")'))
eq('Vim(call):E474: Unexpected colon: :}', exc_exec('call json_decode("{:}")'))
eq('Vim(call):E474: Leading comma: ,}', pcall_err(command, 'call json_decode("{,}")'))
eq('Vim(call):E474: Leading comma: ,]', pcall_err(command, 'call json_decode("[,]")'))
eq(
'Vim(call):E474: Using colon not in dictionary: :]',
pcall_err(command, 'call json_decode("[:]")')
)
eq('Vim(call):E474: Unexpected colon: :}', pcall_err(command, 'call json_decode("{:}")'))
end)
it('fails to parse containers with trailing comma', function()
eq('Vim(call):E474: Trailing comma: ]', exc_exec('call json_decode("[1,]")'))
eq('Vim(call):E474: Trailing comma: }', exc_exec('call json_decode("{\\"1\\": 2,}")'))
eq('Vim(call):E474: Trailing comma: ]', pcall_err(command, 'call json_decode("[1,]")'))
eq('Vim(call):E474: Trailing comma: }', pcall_err(command, 'call json_decode("{\\"1\\": 2,}")'))
end)
it('fails to parse dictionaries with missing value', function()
eq('Vim(call):E474: Expected value after colon: }', exc_exec('call json_decode("{\\"1\\":}")'))
eq('Vim(call):E474: Expected value: }', exc_exec('call json_decode("{\\"1\\"}")'))
eq(
'Vim(call):E474: Expected value after colon: }',
pcall_err(command, 'call json_decode("{\\"1\\":}")')
)
eq('Vim(call):E474: Expected value: }', pcall_err(command, 'call json_decode("{\\"1\\"}")'))
end)
it('fails to parse containers with two commas or colons', function()
eq(
'Vim(call):E474: Duplicate comma: , "2": 2}',
exc_exec('call json_decode("{\\"1\\": 1,, \\"2\\": 2}")')
pcall_err(command, 'call json_decode("{\\"1\\": 1,, \\"2\\": 2}")')
)
eq(
'Vim(call):E474: Duplicate comma: , "2", 2]',
exc_exec('call json_decode("[\\"1\\", 1,, \\"2\\", 2]")')
pcall_err(command, 'call json_decode("[\\"1\\", 1,, \\"2\\", 2]")')
)
eq(
'Vim(call):E474: Duplicate colon: : 2}',
exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":: 2}")')
pcall_err(command, 'call json_decode("{\\"1\\": 1, \\"2\\":: 2}")')
)
eq(
'Vim(call):E474: Comma after colon: , 2}',
exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":, 2}")')
pcall_err(command, 'call json_decode("{\\"1\\": 1, \\"2\\":, 2}")')
)
eq(
'Vim(call):E474: Unexpected colon: : "2": 2}',
exc_exec('call json_decode("{\\"1\\": 1,: \\"2\\": 2}")')
pcall_err(command, 'call json_decode("{\\"1\\": 1,: \\"2\\": 2}")')
)
eq(
'Vim(call):E474: Unexpected colon: :, "2": 2}',
exc_exec('call json_decode("{\\"1\\": 1:, \\"2\\": 2}")')
pcall_err(command, 'call json_decode("{\\"1\\": 1:, \\"2\\": 2}")')
)
end)
it('fails to parse concat of two values', function()
eq('Vim(call):E474: Trailing characters: []', exc_exec('call json_decode("{}[]")'))
eq('Vim(call):E474: Trailing characters: []', pcall_err(command, 'call json_decode("{}[]")'))
end)
it('parses containers', function()
@@ -312,54 +369,60 @@ describe('json_decode() function', function()
end)
it('fails to parse incomplete strings', function()
eq('Vim(call):E474: Expected string end: \t"', exc_exec('call json_decode("\\t\\"")'))
eq('Vim(call):E474: Expected string end: \t"abc', exc_exec('call json_decode("\\t\\"abc")'))
eq(
'Vim(call):E474: Unfinished escape sequence: \t"abc\\',
exc_exec('call json_decode("\\t\\"abc\\\\")')
matches(
'Vim%(call%):E474: Expected string end:',
pcall_err(command, 'call json_decode("\\t\\"")')
)
eq(
'Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u',
exc_exec('call json_decode("\\t\\"abc\\\\u")')
matches(
'Vim%(call%):E474: Expected string end:',
pcall_err(command, 'call json_decode("\\t\\"abc")')
)
eq(
'Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u0',
exc_exec('call json_decode("\\t\\"abc\\\\u0")')
matches(
'Vim%(call%):E474: Unfinished escape sequence:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\")')
)
eq(
'Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u00',
exc_exec('call json_decode("\\t\\"abc\\\\u00")')
matches(
'Vim%(call%):E474: Unfinished unicode escape sequence:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u")')
)
eq(
'Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u000',
exc_exec('call json_decode("\\t\\"abc\\\\u000")')
matches(
'Vim%(call%):E474: Unfinished unicode escape sequence:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u0")')
)
matches(
'Vim%(call%):E474: Unfinished unicode escape sequence:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u00")')
)
matches(
'Vim%(call%):E474: Unfinished unicode escape sequence:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u000")')
)
eq(
'Vim(call):E474: Expected four hex digits after \\u: \\u" ',
exc_exec('call json_decode("\\t\\"abc\\\\u\\" ")')
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u\\" ")')
)
eq(
'Vim(call):E474: Expected four hex digits after \\u: \\u0" ',
exc_exec('call json_decode("\\t\\"abc\\\\u0\\" ")')
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u0\\" ")')
)
eq(
'Vim(call):E474: Expected four hex digits after \\u: \\u00" ',
exc_exec('call json_decode("\\t\\"abc\\\\u00\\" ")')
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u00\\" ")')
)
eq(
'Vim(call):E474: Expected four hex digits after \\u: \\u000" ',
exc_exec('call json_decode("\\t\\"abc\\\\u000\\" ")')
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u000\\" ")')
)
eq(
'Vim(call):E474: Expected string end: \t"abc\\u0000',
exc_exec('call json_decode("\\t\\"abc\\\\u0000")')
matches(
'Vim%(call%):E474: Expected string end:',
pcall_err(command, 'call json_decode("\\t\\"abc\\\\u0000")')
)
end)
it('fails to parse unknown escape sequences', function()
eq(
'Vim(call):E474: Unknown escape sequence: \\a"',
exc_exec('call json_decode("\\t\\"\\\\a\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\\\a\\"")')
)
end)
@@ -388,85 +451,85 @@ describe('json_decode() function', function()
it('fails on strings with invalid bytes', function()
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \255"',
exc_exec('call json_decode("\\t\\"\\xFF\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFF\\"")')
)
eq(
'Vim(call):E474: ASCII control characters cannot be present inside string: ',
exc_exec('call json_decode(["\\"\\n\\""])')
pcall_err(command, 'call json_decode(["\\"\\n\\""])')
)
-- 0xC2 starts 2-byte unicode character
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \194"',
exc_exec('call json_decode("\\t\\"\\xC2\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xC2\\"")')
)
-- 0xE0 0xAA starts 3-byte unicode character
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \224"',
exc_exec('call json_decode("\\t\\"\\xE0\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xE0\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \224\170"',
exc_exec('call json_decode("\\t\\"\\xE0\\xAA\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xE0\\xAA\\"")')
)
-- 0xF0 0x90 0x80 starts 4-byte unicode character
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \240"',
exc_exec('call json_decode("\\t\\"\\xF0\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF0\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \240\144"',
exc_exec('call json_decode("\\t\\"\\xF0\\x90\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF0\\x90\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \240\144\128"',
exc_exec('call json_decode("\\t\\"\\xF0\\x90\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF0\\x90\\x80\\"")')
)
-- 0xF9 0x80 0x80 0x80 starts 5-byte unicode character
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \249"',
exc_exec('call json_decode("\\t\\"\\xF9\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF9\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \249\128"',
exc_exec('call json_decode("\\t\\"\\xF9\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF9\\x80\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \249\128\128"',
exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF9\\x80\\x80\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \249\128\128\128"',
exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\"")')
)
-- 0xFC 0x90 0x80 0x80 0x80 starts 6-byte unicode character
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \252"',
exc_exec('call json_decode("\\t\\"\\xFC\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \252\144"',
exc_exec('call json_decode("\\t\\"\\xFC\\x90\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\x90\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \252\144\128"',
exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\x90\\x80\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \252\144\128\128"',
exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 strings allowed: \252\144\128\128\128"',
exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\"")')
)
-- Specification does not allow unquoted characters above 0x10FFFF
eq(
'Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \249\128\128\128\128"',
exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\x80\\"")')
)
eq(
'Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"',
exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\x80\\"")')
pcall_err(command, 'call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\x80\\"")')
)
-- '"\249\128\128\128\128"',
-- '"\252\144\128\128\128\128"',
@@ -598,15 +661,33 @@ describe('json_decode() function', function()
end)
it('fails to parse empty string', function()
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode("")'))
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode([])'))
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode([""])'))
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode(" ")'))
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode("\\t")'))
eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode("\\n")'))
eq(
'Vim(call):E474: Attempt to decode a blank string',
exc_exec('call json_decode(" \\t\\n \\n\\t\\t \\n\\t\\n \\n \\t\\n\\t ")')
pcall_err(command, 'call json_decode("")')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode([])')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode([""])')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode(" ")')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode("\\t")')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode("\\n")')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
pcall_err(command, 'call json_decode(" \\t\\n \\n\\t\\t \\n\\t\\n \\n \\t\\n\\t ")')
)
end)
@@ -663,15 +744,15 @@ describe('json_encode() function', function()
it('fails to dump NaN and infinite values', function()
eq(
'Vim(call):E474: Unable to represent NaN value in JSON',
exc_exec('call json_encode(str2float("nan"))')
pcall_err(command, 'call json_encode(str2float("nan"))')
)
eq(
'Vim(call):E474: Unable to represent infinity in JSON',
exc_exec('call json_encode(str2float("inf"))')
pcall_err(command, 'call json_encode(str2float("inf"))')
)
eq(
'Vim(call):E474: Unable to represent infinity in JSON',
exc_exec('call json_encode(-str2float("inf"))')
pcall_err(command, 'call json_encode(-str2float("inf"))')
)
end)
@@ -694,32 +775,47 @@ describe('json_encode() function', function()
command('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
command('call add(todump._VAL, [todumpv1, todumpv2])')
eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Invalid key in special dictionary',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('cannot dump generic mapping with ext key', function()
command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}')
eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Invalid key in special dictionary',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('cannot dump generic mapping with array key', function()
command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}')
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}')
eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Invalid key in special dictionary',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('cannot dump generic mapping with UINT64_MAX key', function()
command('let todump = {"_TYPE": v:msgpack_types.integer}')
command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]')
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}')
eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Invalid key in special dictionary',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('cannot dump generic mapping with floating-point key', function()
command('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}')
command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}')
eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Invalid key in special dictionary',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('can dump generic mapping with STR special key and NUL', function()
@@ -735,7 +831,10 @@ describe('json_encode() function', function()
it('cannot dump special ext mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
eq('Vim(call):E474: Unable to convert EXT string to JSON', exc_exec('call json_encode(todump)'))
eq(
'Vim(call):E474: Unable to convert EXT string to JSON',
pcall_err(command, 'call json_encode(todump)')
)
end)
it('can dump special array mapping', function()
@@ -773,7 +872,7 @@ describe('json_encode() function', function()
it('fails to dump a function reference', function()
eq(
'Vim(call):E474: Error while dumping encode_tv2json() argument, itself: attempt to dump function reference',
exc_exec('call json_encode(function("tr"))')
pcall_err(command, 'call json_encode(function("tr"))')
)
end)
@@ -781,14 +880,14 @@ describe('json_encode() function', function()
command('function T() dict\nendfunction')
eq(
'Vim(call):E474: Error while dumping encode_tv2json() argument, itself: attempt to dump function reference',
exc_exec('call json_encode(function("T", [1, 2], {}))')
pcall_err(command, 'call json_encode(function("T", [1, 2], {}))')
)
end)
it('fails to dump a function reference in a list', function()
eq(
'Vim(call):E474: Error while dumping encode_tv2json() argument, index 0: attempt to dump function reference',
exc_exec('call json_encode([function("tr")])')
pcall_err(command, 'call json_encode([function("tr")])')
)
end)
@@ -797,7 +896,7 @@ describe('json_encode() function', function()
command('call add(todump[0][0], todump)')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode(todump)')
pcall_err(command, 'call json_encode(todump)')
)
end)
@@ -806,7 +905,7 @@ describe('json_encode() function', function()
command('call extend(todump.d.d, {"d": todump})')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode([todump])')
pcall_err(command, 'call json_encode([todump])')
)
end)
@@ -827,7 +926,7 @@ describe('json_encode() function', function()
command('call add(todump._VAL, todump)')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode(todump)')
pcall_err(command, 'call json_encode(todump)')
)
end)
@@ -836,7 +935,7 @@ describe('json_encode() function', function()
command('call add(todump._VAL, ["", todump])')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode([todump])')
pcall_err(command, 'call json_encode([todump])')
)
end)
@@ -845,7 +944,7 @@ describe('json_encode() function', function()
command('call add(todump._VAL[0][1], todump._VAL)')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode(todump)')
pcall_err(command, 'call json_encode(todump)')
)
end)
@@ -854,21 +953,21 @@ describe('json_encode() function', function()
command('call add(todump._VAL, ["", todump._VAL])')
eq(
'Vim(call):E724: unable to correctly dump variable with self-referencing container',
exc_exec('call json_encode(todump)')
pcall_err(command, 'call json_encode(todump)')
)
end)
it('fails when called with no arguments', function()
eq(
'Vim(call):E119: Not enough arguments for function: json_encode',
exc_exec('call json_encode()')
pcall_err(command, 'call json_encode()')
)
end)
it('fails when called with two arguments', function()
eq(
'Vim(call):E118: Too many arguments for function: json_encode',
exc_exec('call json_encode(["", ""], 1)')
pcall_err(command, 'call json_encode(["", ""], 1)')
)
end)
@@ -881,11 +980,11 @@ describe('json_encode() function', function()
it('fails when using surrogate character in a UTF-8 string', function()
eq(
'Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \237\160\128',
exc_exec('call json_encode("\237\160\128")')
pcall_err(command, 'call json_encode("\237\160\128")')
)
eq(
'Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \237\175\191',
exc_exec('call json_encode("\237\175\191")')
pcall_err(command, 'call json_encode("\237\175\191")')
)
end)
@@ -917,11 +1016,11 @@ describe('json_encode() function', function()
it('fails to parse NULL strings and lists', function()
eq(
'Vim(call):E474: Attempt to decode a blank string',
exc_exec('call json_decode($XXX_UNEXISTENT_VAR_XXX)')
pcall_err(command, 'call json_decode($XXX_UNEXISTENT_VAR_XXX)')
)
eq(
'Vim(call):E474: Attempt to decode a blank string',
exc_exec('call json_decode(v:_null_list)')
pcall_err(command, 'call json_decode(v:_null_list)')
)
end)
end)

View File

@@ -2,13 +2,13 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local clear, eval, eq = n.clear, n.eval, t.eq
local exc_exec, source = n.exc_exec, n.source
local source = n.source
describe('vimscript', function()
before_each(clear)
it('parses `<SID>` with turkish locale', function()
if exc_exec('lang ctype tr_TR.UTF-8') ~= 0 then
if not pcall(n.command, 'lang ctype tr_TR.UTF-8') then
pending('Locale tr_TR.UTF-8 not supported')
return
end
@@ -23,7 +23,7 @@ describe('vimscript', function()
end)
it('str2float is not affected by locale', function()
if exc_exec('lang ctype sv_SE.UTF-8') ~= 0 then
if not pcall(n.command, 'lang ctype sv_SE.UTF-8') then
pending('Locale sv_SE.UTF-8 not supported')
return
end

View File

@@ -3,10 +3,10 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear
local fn = n.fn
local command = n.command
local exc_exec = n.exc_exec
before_each(clear)
@@ -87,15 +87,15 @@ describe('matchaddpos()', function()
command('hi clear PreProc')
eq(
'Vim(let):E5030: Empty list at position 0',
exc_exec('let val = matchaddpos("PreProc", [[]])')
pcall_err(command, 'let val = matchaddpos("PreProc", [[]])')
)
eq(
'Vim(let):E5030: Empty list at position 1',
exc_exec('let val = matchaddpos("PreProc", [1, v:_null_list])')
pcall_err(command, 'let val = matchaddpos("PreProc", [1, v:_null_list])')
)
eq(
'Vim(let):E5031: List or number required at position 1',
exc_exec('let val = matchaddpos("PreProc", [1, v:_null_dict])')
pcall_err(command, 'let val = matchaddpos("PreProc", [1, v:_null_dict])')
)
end)
it('works with 0 lnum', function()

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local clear = n.clear
@@ -6,7 +7,6 @@ local fn = n.fn
local eval, eq = n.eval, t.eq
local command = n.command
local api = n.api
local exc_exec = n.exc_exec
describe('msgpack*() functions', function()
setup(clear)
@@ -480,42 +480,42 @@ describe('msgpackparse() function', function()
it('fails when called with no arguments', function()
eq(
'Vim(call):E119: Not enough arguments for function: msgpackparse',
exc_exec('call msgpackparse()')
pcall_err(command, 'call msgpackparse()')
)
end)
it('fails when called with two arguments', function()
eq(
'Vim(call):E118: Too many arguments for function: msgpackparse',
exc_exec('call msgpackparse(["", ""], 1)')
pcall_err(command, 'call msgpackparse(["", ""], 1)')
)
end)
it('fails to parse a string', function()
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse("abcdefghijklmnopqrstuvwxyz")')
pcall_err(command, 'call msgpackparse("abcdefghijklmnopqrstuvwxyz")')
)
end)
it('fails to parse a number', function()
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(127)')
pcall_err(command, 'call msgpackparse(127)')
)
end)
it('fails to parse a dict', function()
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse({})')
pcall_err(command, 'call msgpackparse({})')
)
end)
it('fails to parse a funcref', function()
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(function("tr"))')
pcall_err(command, 'call msgpackparse(function("tr"))')
)
end)
@@ -523,29 +523,29 @@ describe('msgpackparse() function', function()
command('function! T() dict\nendfunction')
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(function("T", [1, 2], {}))')
pcall_err(command, 'call msgpackparse(function("T", [1, 2], {}))')
)
end)
it('fails to parse a float', function()
eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(0.0)')
pcall_err(command, 'call msgpackparse(0.0)')
)
end)
it('fails on incomplete msgpack string', function()
local expected = 'Vim(call):E475: Invalid argument: Incomplete msgpack string'
eq(expected, exc_exec([[call msgpackparse(["\xc4"])]]))
eq(expected, exc_exec([[call msgpackparse(["\xca", "\x02\x03"])]]))
eq(expected, exc_exec('call msgpackparse(0zc4)'))
eq(expected, exc_exec('call msgpackparse(0zca0a0203)'))
eq(expected, pcall_err(command, [[call msgpackparse(["\xc4"])]]))
eq(expected, pcall_err(command, [[call msgpackparse(["\xca", "\x02\x03"])]]))
eq(expected, pcall_err(command, 'call msgpackparse(0zc4)'))
eq(expected, pcall_err(command, 'call msgpackparse(0zca0a0203)'))
end)
it('fails when unable to parse msgpack string', function()
local expected = 'Vim(call):E475: Invalid argument: Failed to parse msgpack string'
eq(expected, exc_exec([[call msgpackparse(["\xc1"])]]))
eq(expected, exc_exec('call msgpackparse(0zc1)'))
eq(expected, pcall_err(command, [[call msgpackparse(["\xc1"])]]))
eq(expected, pcall_err(command, 'call msgpackparse(0zc1)'))
end)
end)
@@ -626,7 +626,7 @@ describe('msgpackdump() function', function()
command('let Todump = function("tr")')
eq(
'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])')
pcall_err(command, 'call msgpackdump([Todump])')
)
end)
@@ -635,7 +635,7 @@ describe('msgpackdump() function', function()
command('let Todump = function("T", [1, 2], {})')
eq(
'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])')
pcall_err(command, 'call msgpackdump([Todump])')
)
end)
@@ -643,7 +643,7 @@ describe('msgpackdump() function', function()
command('let todump = [function("tr")]')
eq(
'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, index 0: attempt to dump function reference',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -652,7 +652,7 @@ describe('msgpackdump() function', function()
command('call add(todump[0][0], todump)')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 0, index 0',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -661,7 +661,7 @@ describe('msgpackdump() function', function()
command('call extend(todump.d.d, {"d": todump})')
eq(
"Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 'd', key 'd', key 'd'",
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -682,7 +682,7 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL, todump)')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -691,7 +691,7 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL, [todump, 0])')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -700,7 +700,7 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL, [0, todump])')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 0 at index 0 from special map',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -709,7 +709,7 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL[0][0], todump._VAL)')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -718,7 +718,7 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL[0][1], todump._VAL)')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
@@ -727,46 +727,49 @@ describe('msgpackdump() function', function()
command('call add(todump._VAL, [0, todump._VAL])')
eq(
'Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 1',
exc_exec('call msgpackdump([todump])')
pcall_err(command, 'call msgpackdump([todump])')
)
end)
it('fails when called with no arguments', function()
eq(
'Vim(call):E119: Not enough arguments for function: msgpackdump',
exc_exec('call msgpackdump()')
pcall_err(command, 'call msgpackdump()')
)
end)
it('fails when called with three arguments', function()
eq(
'Vim(call):E118: Too many arguments for function: msgpackdump',
exc_exec('call msgpackdump(["", ""], 1, 2)')
pcall_err(command, 'call msgpackdump(["", ""], 1, 2)')
)
end)
it('fails to dump a string', function()
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump("abcdefghijklmnopqrstuvwxyz")')
pcall_err(command, 'call msgpackdump("abcdefghijklmnopqrstuvwxyz")')
)
end)
it('fails to dump a number', function()
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(127)')
pcall_err(command, 'call msgpackdump(127)')
)
end)
it('fails to dump a dict', function()
eq('Vim(call):E686: Argument of msgpackdump() must be a List', exc_exec('call msgpackdump({})'))
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
pcall_err(command, 'call msgpackdump({})')
)
end)
it('fails to dump a funcref', function()
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("tr"))')
pcall_err(command, 'call msgpackdump(function("tr"))')
)
end)
@@ -774,14 +777,14 @@ describe('msgpackdump() function', function()
command('function! T() dict\nendfunction')
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("T", [1, 2], {}))')
pcall_err(command, 'call msgpackdump(function("T", [1, 2], {}))')
)
end)
it('fails to dump a float', function()
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(0.0)')
pcall_err(command, 'call msgpackdump(0.0)')
)
end)
@@ -789,7 +792,7 @@ describe('msgpackdump() function', function()
for _, val in ipairs({ 'v:true', 'v:false', 'v:null' }) do
eq(
'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(' .. val .. ')')
pcall_err(command, 'call msgpackdump(' .. val .. ')')
)
end
end)

View File

@@ -1,7 +1,6 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local exc_exec = n.exc_exec
local command = n.command
local clear = n.clear
local api = n.api
@@ -35,7 +34,11 @@ describe('NULL', function()
end)
local null_test = function(name, cmd, err)
it(name, function()
eq(err, exc_exec(cmd))
if err == 0 then
command(cmd)
else
eq(err, t.pcall_err(command, cmd))
end
end)
end
local null_expr_test = function(name, expr, err, val, after)

View File

@@ -3,10 +3,11 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local eq = t.eq
local pcall_err = t.pcall_err
local eval = n.eval
local fn = n.fn
local api = n.api
local exc_exec = n.exc_exec
local command = n.command
describe('printf()', function()
setup(clear)
@@ -56,10 +57,13 @@ describe('printf()', function()
eq('0b00011 ', fn.printf("% '+#0-10.5b", 3))
end)
it('errors out when %b modifier is used for a list', function()
eq('Vim(call):E745: Using a List as a Number', exc_exec('call printf("%b", [])'))
eq('Vim(call):E745: Using a List as a Number', pcall_err(command, 'call printf("%b", [])'))
end)
it('errors out when %b modifier is used for a float', function()
eq('Vim(call):E805: Using a Float as a Number', exc_exec('call printf("%b", 3.1415926535)'))
eq(
'Vim(call):E805: Using a Float as a Number',
pcall_err(command, 'call printf("%b", 3.1415926535)')
)
end)
it('works with %p correctly', function()
local null_ret = nil
@@ -68,8 +72,8 @@ describe('printf()', function()
-- address after freeing unreferenced values.
api.nvim_set_var('__args', {})
local function check_printf(expr, is_null)
eq(0, exc_exec('call add(__args, ' .. expr .. ')'))
eq(0, exc_exec('let __result = printf("%p", __args[-1])'))
command('call add(__args, ' .. expr .. ')')
command('let __result = printf("%p", __args[-1])')
local id_ret = eval('id(__args[-1])')
eq(id_ret, api.nvim_get_var('__result'))
if is_null then

View File

@@ -8,7 +8,6 @@ local clear = n.clear
local command = n.command
local eval = n.eval
local eq = t.eq
local exc_exec = n.exc_exec
describe('setpos() function', function()
before_each(function()
@@ -28,8 +27,7 @@ describe('setpos() function', function()
eq({ 0, 2, 1, 0 }, getpos('.'))
setpos('.', { 2, 1, 1, 0 })
eq({ 0, 1, 1, 0 }, getpos('.'))
local ret = exc_exec('call setpos(".", [1, 1, 1, 0])')
eq(0, ret)
command('call setpos(".", [1, 1, 1, 0])')
end)
it('can set lowercase marks in the current buffer', function()
setpos("'d", { 0, 2, 1, 0 })

View File

@@ -8,7 +8,6 @@ local clear = n.clear
local api = n.api
local fn = n.fn
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
setup(clear)
@@ -17,7 +16,7 @@ describe('sort()', function()
it('errors out when sorting special values', function()
eq(
'Vim(call):E362: Using a boolean value as a Float',
exc_exec('call sort([v:true, v:false], "f")')
pcall_err(command, 'call sort([v:true, v:false], "f")')
)
end)

View File

@@ -1,12 +1,12 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local exc_exec = n.exc_exec
local command = n.command
local fn = n.fn
local clear = n.clear
local eval = n.eval
local eq = t.eq
local pcall_err = t.pcall_err
local api = n.api
local NIL = vim.NIL
@@ -23,7 +23,7 @@ describe('Special values', function()
endtry
endfunction
]])
eq(0, exc_exec('call Test()'))
command('call Test()')
end)
it('work with empty()', function()
@@ -113,17 +113,17 @@ describe('Special values', function()
api.nvim_set_var('false', false)
command('let null = v:null')
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1'))
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let false += 1'))
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let null += 1'))
eq('Vim(let):E734: Wrong variable type for +=', pcall_err(command, 'let true += 1'))
eq('Vim(let):E734: Wrong variable type for +=', pcall_err(command, 'let false += 1'))
eq('Vim(let):E734: Wrong variable type for +=', pcall_err(command, 'let null += 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let true -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let false -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let null -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', pcall_err(command, 'let true -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', pcall_err(command, 'let false -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', pcall_err(command, 'let null -= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let true .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let false .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let null .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', pcall_err(command, 'let true .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', pcall_err(command, 'let false .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', pcall_err(command, 'let null .= 1'))
end)
it('work with . (concat) properly', function()
@@ -155,9 +155,9 @@ describe('Special values', function()
end)
it('fails in index', function()
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:true[0]'))
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:false[0]'))
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:null[0]'))
eq('Vim(echo):E909: Cannot index a special variable', pcall_err(command, 'echo v:true[0]'))
eq('Vim(echo):E909: Cannot index a special variable', pcall_err(command, 'echo v:false[0]'))
eq('Vim(echo):E909: Cannot index a special variable', pcall_err(command, 'echo v:null[0]'))
end)
it('is accepted by assert_true and assert_false', function()

View File

@@ -6,7 +6,6 @@ local eq = t.eq
local command = n.command
local api = n.api
local eval = n.eval
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local fn = n.fn
local NIL = vim.NIL
@@ -237,7 +236,7 @@ describe('string() function', function()
eval('add(l, l)')
eq(
'Vim(echo):E724: unable to correctly dump variable with self-referencing container',
exc_exec('echo string(l)')
pcall_err(command, 'echo string(l)')
)
end)
@@ -276,7 +275,7 @@ describe('string() function', function()
eval('extend(d, {"d": d})')
eq(
'Vim(echo):E724: unable to correctly dump variable with self-referencing container',
exc_exec('echo string(d)')
pcall_err(command, 'echo string(d)')
)
end)

View File

@@ -11,7 +11,6 @@ local eq, call, clear, eval, feed_command, feed, api =
local command = n.command
local insert = n.insert
local expect = n.expect
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local is_os = t.is_os
@@ -357,7 +356,7 @@ describe('system()', function()
it('is treated as a buffer id', function()
command("put ='text in buffer 1'")
eq('\ntext in buffer 1\n', eval('system("cat", 1)'))
eq('Vim(echo):E86: Buffer 42 does not exist', exc_exec('echo system("cat", 42)'))
eq('Vim(echo):E86: Buffer 42 does not exist', pcall_err(command, 'echo system("cat", 42)'))
end)
end)

View File

@@ -5,10 +5,10 @@ local Screen = require('test.functional.ui.screen')
local feed, eq, eval, ok = n.feed, t.eq, n.eval, t.ok
local source, async_meths, run = n.source, n.async_meths, n.run
local clear, command, fn = n.clear, n.command, n.fn
local exc_exec = n.exc_exec
local api = n.api
local load_adjust = n.load_adjust
local retry = t.retry
local pcall_err = t.pcall_err
describe('timers', function()
before_each(function()
@@ -297,7 +297,10 @@ describe('timers', function()
call execute('echo ''execute() should be disallowed''', '')
endfunction
]]
eq('Vim(call):E48: Not allowed in sandbox', exc_exec("sandbox call timer_start(0, 'Scary')"))
eq(
'Vim(call):E48: Not allowed in sandbox',
pcall_err(command, "sandbox call timer_start(0, 'Scary')")
)
end)
it('can be triggered after an empty string <expr> mapping #17257', function()

View File

@@ -4,7 +4,6 @@ local n = require('test.functional.testnvim')()
local eq = t.eq
local clear = n.clear
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
setup(clear)
@@ -13,7 +12,7 @@ describe('uniq()', function()
it('errors out when processing special values', function()
eq(
'Vim(call):E362: Using a boolean value as a Float',
exc_exec('call uniq([v:true, v:false], "f")')
pcall_err(command, 'call uniq([v:true, v:false], "f")')
)
end)

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local clear, eval, eq = n.clear, n.eval, t.eq

View File

@@ -6,7 +6,6 @@ local clear = n.clear
local eq = t.eq
local fn = n.fn
local api = n.api
local exc_exec = n.exc_exec
local read_file = t.read_file
local write_file = t.write_file
local pcall_err = t.pcall_err
@@ -52,16 +51,16 @@ describe('writefile()', function()
end)
it('writes list with an empty string to a file', function()
eq(0, exc_exec(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s", "b")'):format(fname)))
command(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s", "b")'):format(fname))
eq('', read_file(fname))
eq(0, exc_exec(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s")'):format(fname)))
command(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s")'):format(fname))
eq('\n', read_file(fname))
end)
it('writes list with a null string to a file', function()
eq(0, exc_exec(('call writefile([v:_null_string], "%s", "b")'):format(fname)))
command(('call writefile([v:_null_string], "%s", "b")'):format(fname))
eq('', read_file(fname))
eq(0, exc_exec(('call writefile([v:_null_string], "%s")'):format(fname)))
command(('call writefile([v:_null_string], "%s")'):format(fname))
eq('\n', read_file(fname))
end)