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

@@ -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)