aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/vimscript')
-rw-r--r--test/functional/vimscript/api_functions_spec.lua3
-rw-r--r--test/functional/vimscript/eval_spec.lua2
-rw-r--r--test/functional/vimscript/executable_spec.lua15
-rw-r--r--test/functional/vimscript/execute_spec.lua4
-rw-r--r--test/functional/vimscript/functions_spec.lua2
-rw-r--r--test/functional/vimscript/has_spec.lua7
-rw-r--r--test/functional/vimscript/input_spec.lua14
-rw-r--r--test/functional/vimscript/lang_spec.lua1
-rw-r--r--test/functional/vimscript/let_spec.lua45
-rw-r--r--test/functional/vimscript/msgpack_functions_spec.lua6
-rw-r--r--test/functional/vimscript/reltime_spec.lua4
-rw-r--r--test/functional/vimscript/screenchar_spec.lua69
-rw-r--r--test/functional/vimscript/server_spec.lua55
-rw-r--r--test/functional/vimscript/setpos_spec.lua22
-rw-r--r--test/functional/vimscript/system_spec.lua109
-rw-r--r--test/functional/vimscript/timer_spec.lua10
16 files changed, 293 insertions, 75 deletions
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua
index d07e74d40e..8ca245f61a 100644
--- a/test/functional/vimscript/api_functions_spec.lua
+++ b/test/functional/vimscript/api_functions_spec.lua
@@ -49,7 +49,8 @@ describe('eval-API', function()
it('cannot change texts if textlocked', function()
command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])")
- eq('Vim(call):E5555: API call: E523: Not allowed here', pcall_err(command, "normal! yy"))
+ eq('Vim(call):E5555: API call: E565: Not allowed to change text or change window',
+ pcall_err(command, "normal! yy"))
end)
it("use buffer numbers and windows ids as handles", function()
diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua
index e1459ab5b8..0c2ca8de78 100644
--- a/test/functional/vimscript/eval_spec.lua
+++ b/test/functional/vimscript/eval_spec.lua
@@ -5,7 +5,7 @@
-- null_spec.lua
-- operators_spec.lua
--
--- Tests for the Vimscript |functions| library should live in:
+-- Tests for the Vimscript |builtin-functions| library should live in:
-- test/functional/vimscript/<funcname>_spec.lua
-- test/functional/vimscript/functions_spec.lua
diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua
index 048a65188d..b4162b2336 100644
--- a/test/functional/vimscript/executable_spec.lua
+++ b/test/functional/vimscript/executable_spec.lua
@@ -17,6 +17,21 @@ describe('executable()', function()
eq(1, call('executable', 'false'))
end)
+ if iswin() then
+ it('exepath respects shellslash', function()
+ command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
+ eq([[test\functional\fixtures\bin\null.CMD]], call('fnamemodify', call('exepath', 'null'), ':.'))
+ command('set shellslash')
+ eq('test/functional/fixtures/bin/null.CMD', call('fnamemodify', call('exepath', 'null'), ':.'))
+ end)
+
+ it('stdpath respects shellslash', function()
+ eq([[build\Xtest_xdg\share\nvim-data]], call('fnamemodify', call('stdpath', 'data'), ':.'))
+ command('set shellslash')
+ eq('build/Xtest_xdg/share/nvim-data', call('fnamemodify', call('stdpath', 'data'), ':.'))
+ end)
+ end
+
it('fails for invalid values', function()
for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
eq('Vim(call):E928: String required', exc_exec('call executable('..input..')'))
diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua
index e21c71dc7f..a733b098f5 100644
--- a/test/functional/vimscript/execute_spec.lua
+++ b/test/functional/vimscript/execute_spec.lua
@@ -153,7 +153,7 @@ describe('execute()', function()
function! Test3()
echo 1234
let x = execute('echoerr "abcdef"', 'silent!')
- echon 'ABCD'
+ echon 'ABCDXZYZ'
endfunction
" test 4: silenced echoerr goes as usual
@@ -214,7 +214,7 @@ describe('execute()', function()
~ |
~ |
~ |
- 1234ABCD |
+ 1234ABCDXZYZ |
]])
feed([[:call Test4()<cr>]])
diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua
index 0ad7fd8010..20c1400030 100644
--- a/test/functional/vimscript/functions_spec.lua
+++ b/test/functional/vimscript/functions_spec.lua
@@ -1,4 +1,4 @@
--- Tests for misc Vimscript |functions|.
+-- Tests for misc Vimscript |builtin-functions|.
--
-- If a function is non-trivial, consider moving its spec to:
-- test/functional/vimscript/<funcname>_spec.lua
diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua
index c03fd13e0c..4d9b226434 100644
--- a/test/functional/vimscript/has_spec.lua
+++ b/test/functional/vimscript/has_spec.lua
@@ -68,4 +68,11 @@ describe('has()', function()
eq(0, funcs.has('wsl'))
end
end)
+
+ it('does not change v:shell_error', function()
+ local nvim_prog = helpers.nvim_prog
+ funcs.system({nvim_prog, '-es', '+73cquit'})
+ funcs.has('python3') -- use a call whose implementation shells out
+ eq(73, funcs.eval('v:shell_error'))
+ end)
end)
diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua
index 14c02f9eb2..554d15e550 100644
--- a/test/functional/vimscript/input_spec.lua
+++ b/test/functional/vimscript/input_spec.lua
@@ -9,6 +9,7 @@ local source = helpers.source
local command = helpers.command
local exc_exec = helpers.exc_exec
local nvim_async = helpers.nvim_async
+local NIL = helpers.NIL
local screen
@@ -200,6 +201,15 @@ describe('input()', function()
feed(':let var = input({"cancelreturn": "BAR"})<CR>')
feed('<Esc>')
eq('BAR', meths.get_var('var'))
+ feed(':let var = input({"cancelreturn": []})<CR>')
+ feed('<Esc>')
+ eq({}, meths.get_var('var'))
+ feed(':let var = input({"cancelreturn": v:false})<CR>')
+ feed('<Esc>')
+ eq(false, meths.get_var('var'))
+ feed(':let var = input({"cancelreturn": v:null})<CR>')
+ feed('<Esc>')
+ eq(NIL, meths.get_var('var'))
end)
it('supports default string', function()
feed(':let var = input("", "DEF1")<CR>')
@@ -220,8 +230,6 @@ describe('input()', function()
eq('Vim(call):E730: using List as a String',
exc_exec('call input({"prompt": []})'))
eq('Vim(call):E730: using List as a String',
- exc_exec('call input({"cancelreturn": []})'))
- eq('Vim(call):E730: using List as a String',
exc_exec('call input({"default": []})'))
eq('Vim(call):E730: using List as a String',
exc_exec('call input({"completion": []})'))
@@ -418,8 +426,6 @@ describe('inputdialog()', function()
eq('Vim(call):E730: using List as a String',
exc_exec('call inputdialog({"prompt": []})'))
eq('Vim(call):E730: using List as a String',
- exc_exec('call inputdialog({"cancelreturn": []})'))
- eq('Vim(call):E730: using List as a String',
exc_exec('call inputdialog({"default": []})'))
eq('Vim(call):E730: using List as a String',
exc_exec('call inputdialog({"completion": []})'))
diff --git a/test/functional/vimscript/lang_spec.lua b/test/functional/vimscript/lang_spec.lua
index d5254986ab..90437f2ee1 100644
--- a/test/functional/vimscript/lang_spec.lua
+++ b/test/functional/vimscript/lang_spec.lua
@@ -11,6 +11,7 @@ describe('vimscript', function()
return
end
source([[
+ let s:foo = 1
func! <sid>_dummy_function()
echo 1
endfunc
diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua
index 4ff4090a18..ca1b5e8907 100644
--- a/test/functional/vimscript/let_spec.lua
+++ b/test/functional/vimscript/let_spec.lua
@@ -5,9 +5,10 @@ local clear = helpers.clear
local command = helpers.command
local eval = helpers.eval
local meths = helpers.meths
+local exec = helpers.exec
local exec_capture = helpers.exec_capture
local source = helpers.source
-local nvim_dir = helpers.nvim_dir
+local testprg = helpers.testprg
before_each(clear)
@@ -47,33 +48,33 @@ describe(':let', function()
end)
it("multibyte env var #8398 #9267", function()
- command("let $NVIM_TEST = 'AìaB'")
- eq('AìaB', eval('$NVIM_TEST'))
- command("let $NVIM_TEST = 'AaあB'")
- eq('AaあB', eval('$NVIM_TEST'))
+ command("let $NVIM_TEST_LET = 'AìaB'")
+ eq('AìaB', eval('$NVIM_TEST_LET'))
+ command("let $NVIM_TEST_LET = 'AaあB'")
+ eq('AaあB', eval('$NVIM_TEST_LET'))
local mbyte = [[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]]
- command("let $NVIM_TEST = '"..mbyte.."'")
- eq(mbyte, eval('$NVIM_TEST'))
+ command("let $NVIM_TEST_LET = '"..mbyte.."'")
+ eq(mbyte, eval('$NVIM_TEST_LET'))
end)
it("multibyte env var to child process #8398 #9267", function()
- local cmd_get_child_env = "let g:env_from_child = system(['"..nvim_dir.."/printenv-test', 'NVIM_TEST'])"
- command("let $NVIM_TEST = 'AìaB'")
+ local cmd_get_child_env = ("let g:env_from_child = system(['%s', 'NVIM_TEST_LET'])"):format(testprg('printenv-test'))
+ command("let $NVIM_TEST_LET = 'AìaB'")
command(cmd_get_child_env)
- eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
+ eq(eval('$NVIM_TEST_LET'), eval('g:env_from_child'))
- command("let $NVIM_TEST = 'AaあB'")
+ command("let $NVIM_TEST_LET = 'AaあB'")
command(cmd_get_child_env)
- eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
+ eq(eval('$NVIM_TEST_LET'), eval('g:env_from_child'))
local mbyte = [[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ
.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]]
- command("let $NVIM_TEST = '"..mbyte.."'")
+ command("let $NVIM_TEST_LET = '"..mbyte.."'")
command(cmd_get_child_env)
- eq(eval('$NVIM_TEST'), eval('g:env_from_child'))
+ eq(eval('$NVIM_TEST_LET'), eval('g:env_from_child'))
end)
it("release of list assigned to l: variable does not trigger assertion #12387, #12430", function()
@@ -91,3 +92,19 @@ describe(':let', function()
eq(1, eval('1'))
end)
end)
+
+describe(':let and :const', function()
+ it('have the same output when called without arguments', function()
+ eq(exec_capture('let'), exec_capture('const'))
+ end)
+
+ it('can be used in sandbox', function()
+ exec([[
+ func Func()
+ let l:foo = 'foo'
+ const l:bar = 'bar'
+ endfunc
+ sandbox call Func()
+ ]])
+ end)
+end)
diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua
index 837b629858..cab67d77e4 100644
--- a/test/functional/vimscript/msgpack_functions_spec.lua
+++ b/test/functional/vimscript/msgpack_functions_spec.lua
@@ -5,6 +5,7 @@ local eval, eq = helpers.eval, helpers.eq
local command = helpers.command
local nvim = helpers.nvim
local exc_exec = helpers.exc_exec
+local iswin = helpers.iswin
describe('msgpack*() functions', function()
before_each(clear)
@@ -466,6 +467,11 @@ describe('msgpackparse() function', function()
eval(cmd)
eval(cmd) -- do it again (try to force segfault)
local api_info = eval(cmd) -- do it again
+ if iswin() then
+ helpers.assert_alive()
+ pending('msgpackparse() has a bug on windows')
+ return
+ end
eq({'error_types', 'functions', 'types',
'ui_events', 'ui_options', 'version'}, api_info)
end)
diff --git a/test/functional/vimscript/reltime_spec.lua b/test/functional/vimscript/reltime_spec.lua
index d87943e485..6d661402a6 100644
--- a/test/functional/vimscript/reltime_spec.lua
+++ b/test/functional/vimscript/reltime_spec.lua
@@ -12,7 +12,7 @@ describe('reltimestr(), reltimefloat()', function()
local later = reltime()
local elapsed = reltime(now)
- neq(reltimestr(elapsed), '0.0')
+ neq('0.0', reltimestr(elapsed))
ok(reltimefloat(elapsed) > 0.0)
-- original vim test for < 0.1, but easily fails on travis
ok(nil ~= string.match(reltimestr(elapsed), "0%."))
@@ -26,7 +26,7 @@ describe('reltimestr(), reltimefloat()', function()
eq(0.0, reltimefloat(same))
local differs = reltime(now, later)
- neq(reltimestr(differs), '0.0')
+ neq('0.0', reltimestr(differs))
ok(reltimefloat(differs) > 0.0)
-- original vim test for < 0.1, but easily fails on travis
ok(nil ~= string.match(reltimestr(differs), "0%."))
diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua
new file mode 100644
index 0000000000..767e3c57ef
--- /dev/null
+++ b/test/functional/vimscript/screenchar_spec.lua
@@ -0,0 +1,69 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq
+local command, meths, funcs = helpers.command, helpers.meths, helpers.funcs
+local tbl_deep_extend = helpers.tbl_deep_extend
+
+-- Set up two overlapping floating windows
+local setup_floating_windows = function()
+ local base_opts = {
+ relative = 'editor',
+ height = 1,
+ width = 2,
+ anchor = 'NW',
+ style = 'minimal',
+ border = 'none',
+ }
+
+ local bufnr_1 = meths.create_buf(false, true)
+ meths.buf_set_lines(bufnr_1, 0, -1, true, { 'aa' })
+ local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts)
+ meths.open_win(bufnr_1, false, opts_1)
+
+ local bufnr_2 = meths.create_buf(false, true)
+ meths.buf_set_lines(bufnr_2, 0, -1, true, { 'bb' })
+ local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts)
+ meths.open_win(bufnr_2, false, opts_2)
+
+ command('redraw')
+end
+
+describe('screenchar() and family respect floating windows', function()
+ before_each(function()
+ clear()
+ -- These commands result into visible text `aabc`.
+ -- `aab` - from floating windows, `c` - from text in regular window.
+ meths.buf_set_lines(0, 0, -1, true, { 'cccc' })
+ setup_floating_windows()
+ end)
+
+ it('screenattr()', function()
+ local attr_1 = funcs.screenattr(1, 1)
+ local attr_2 = funcs.screenattr(1, 2)
+ local attr_3 = funcs.screenattr(1, 3)
+ local attr_4 = funcs.screenattr(1, 4)
+ eq(attr_1, attr_2)
+ eq(attr_1, attr_3)
+ neq(attr_1, attr_4)
+ end)
+
+ it('screenchar()', function()
+ eq(97, funcs.screenchar(1, 1))
+ eq(97, funcs.screenchar(1, 2))
+ eq(98, funcs.screenchar(1, 3))
+ eq(99, funcs.screenchar(1, 4))
+ end)
+
+ it('screenchars()', function()
+ eq({ 97 }, funcs.screenchars(1, 1))
+ eq({ 97 }, funcs.screenchars(1, 2))
+ eq({ 98 }, funcs.screenchars(1, 3))
+ eq({ 99 }, funcs.screenchars(1, 4))
+ end)
+
+ it('screenstring()', function()
+ eq('a', funcs.screenstring(1, 1))
+ eq('a', funcs.screenstring(1, 2))
+ eq('b', funcs.screenstring(1, 3))
+ eq('c', funcs.screenstring(1, 4))
+ end)
+end)
diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua
index 238d1aeb0f..6e95459630 100644
--- a/test/functional/vimscript/server_spec.lua
+++ b/test/functional/vimscript/server_spec.lua
@@ -1,11 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
-local command = helpers.command
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
local iswin = helpers.iswin
local ok = helpers.ok
local matches = helpers.matches
local pcall_err = helpers.pcall_err
+local mkdir = helpers.mkdir
local function clear_serverlist()
for _, server in pairs(funcs.serverlist()) do
@@ -14,29 +14,38 @@ local function clear_serverlist()
end
describe('server', function()
- before_each(clear)
+ it('serverstart() stores sockets in $XDG_RUNTIME_DIR', function()
+ local dir = 'Xtest_xdg_run'
+ mkdir(dir)
+ clear({ env={ XDG_RUNTIME_DIR=dir } })
+ matches(dir, funcs.stdpath('run'))
+ if not iswin() then
+ matches(dir, funcs.serverstart())
+ end
+ end)
- it('serverstart() sets $NVIM_LISTEN_ADDRESS on first invocation', function()
- -- Unset $NVIM_LISTEN_ADDRESS
- command('let $NVIM_LISTEN_ADDRESS = ""')
+ it('serverstart(), serverstop() does not set $NVIM', function()
+ clear()
local s = eval('serverstart()')
assert(s ~= nil and s:len() > 0, "serverstart() returned empty")
- eq(s, eval('$NVIM_LISTEN_ADDRESS'))
+ eq('', eval('$NVIM'))
+ eq('', eval('$NVIM_LISTEN_ADDRESS'))
eq(1, eval("serverstop('"..s.."')"))
eq('', eval('$NVIM_LISTEN_ADDRESS'))
end)
it('sets new v:servername if $NVIM_LISTEN_ADDRESS is invalid', function()
clear({env={NVIM_LISTEN_ADDRESS='.'}})
- eq('.', eval('$NVIM_LISTEN_ADDRESS'))
+ -- Cleared on startup.
+ eq('', eval('$NVIM_LISTEN_ADDRESS'))
local servers = funcs.serverlist()
eq(1, #servers)
- ok(string.len(servers[1]) > 4) -- Like /tmp/nvim…/… or \\.\pipe\…
+ ok(string.len(servers[1]) > 4) -- "~/.local/state/nvim…/…" or "\\.\pipe\…"
end)
- it('sets v:servername at startup or if all servers were stopped',
- function()
+ it('sets v:servername at startup or if all servers were stopped', function()
+ clear()
local initial_server = meths.get_vvar('servername')
assert(initial_server ~= nil and initial_server:len() > 0,
'v:servername was not initialized')
@@ -55,19 +64,23 @@ describe('server', function()
eq(1, funcs.serverstop(funcs.serverlist()[1]))
eq('', meths.get_vvar('servername'))
- -- v:servername will take the next available server.
+ -- v:servername and $NVIM take the next available server.
local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]]
- or 'Xtest-functional-server-socket')
+ or './Xtest-functional-server-socket')
funcs.serverstart(servername)
eq(servername, meths.get_vvar('servername'))
+ -- Not set in the current process, only in children.
+ eq('', eval('$NVIM'))
end)
it('serverstop() returns false for invalid input', function()
+ clear()
eq(0, eval("serverstop('')"))
eq(0, eval("serverstop('bogus-socket-name')"))
end)
- it('parses endpoints correctly', function()
+ it('parses endpoints', function()
+ clear()
clear_serverlist()
eq({}, funcs.serverlist())
@@ -102,19 +115,24 @@ describe('server', function()
eq(expected, funcs.serverlist())
clear_serverlist()
+ -- Address without slashes is a "name" which is appended to a generated path. #8519
+ matches([[.*[/\\]xtest1%.2%.3%.4[^/\\]*]], funcs.serverstart('xtest1.2.3.4'))
+ clear_serverlist()
+
eq('Vim:Failed to start server: invalid argument',
pcall_err(funcs.serverstart, '127.0.0.1:65536')) -- invalid port
eq({}, funcs.serverlist())
end)
it('serverlist() returns the list of servers', function()
+ clear()
-- There should already be at least one server.
local n = eval('len(serverlist())')
-- Add some servers.
local servs = (iswin()
and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] }
- or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] })
+ or { [[./Xtest-pipe0934]], [[./Xtest-pipe4324]] })
for _, s in ipairs(servs) do
eq(s, eval("serverstart('"..s.."')"))
end
@@ -136,7 +154,6 @@ end)
describe('startup --listen', function()
it('validates', function()
clear()
-
local cmd = { unpack(helpers.nvim_argv) }
table.insert(cmd, '--listen')
matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd))
@@ -148,9 +165,13 @@ describe('startup --listen', function()
it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function()
local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]]
- or 'Xtest-listen-pipe')
- clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' },
+ or './Xtest-listen-pipe')
+ clear({ env={ NVIM_LISTEN_ADDRESS='./Xtest-env-pipe' },
args={ '--listen', addr } })
eq(addr, meths.get_vvar('servername'))
+
+ -- Address without slashes is a "name" which is appended to a generated path. #8519
+ clear({ args={ '--listen', 'test-name' } })
+ matches([[.*[/\\]test%-name[^/\\]*]], meths.get_vvar('servername'))
end)
end)
diff --git a/test/functional/vimscript/setpos_spec.lua b/test/functional/vimscript/setpos_spec.lua
index 935f387bcc..02e550dcc0 100644
--- a/test/functional/vimscript/setpos_spec.lua
+++ b/test/functional/vimscript/setpos_spec.lua
@@ -24,41 +24,41 @@ describe('setpos() function', function()
end)
it('can set the current cursor position', function()
setpos(".", {0, 2, 1, 0})
- eq(getpos("."), {0, 2, 1, 0})
+ eq({0, 2, 1, 0}, getpos("."))
setpos(".", {2, 1, 1, 0})
- eq(getpos("."), {0, 1, 1, 0})
+ eq({0, 1, 1, 0}, getpos("."))
local ret = exc_exec('call setpos(".", [1, 1, 1, 0])')
eq(0, ret)
end)
it('can set lowercase marks in the current buffer', function()
setpos("'d", {0, 2, 1, 0})
- eq(getpos("'d"), {0, 2, 1, 0})
+ eq({0, 2, 1, 0}, getpos("'d"))
command('undo')
command('call setpos("\'d", [2, 3, 1, 0])')
- eq(getpos("'d"), {0, 3, 1, 0})
+ eq({0, 3, 1, 0}, getpos("'d"))
end)
it('can set lowercase marks in other buffers', function()
local retval = setpos("'d", {1, 2, 1, 0})
eq(0, retval)
setpos("'d", {1, 2, 1, 0})
- eq(getpos("'d"), {0, 0, 0, 0})
+ eq({0, 0, 0, 0}, getpos("'d"))
command('wincmd w')
- eq(eval('bufnr("%")'), 1)
- eq(getpos("'d"), {0, 2, 1, 0})
+ eq(1, eval('bufnr("%")'))
+ eq({0, 2, 1, 0}, getpos("'d"))
end)
it("fails when setting a mark in a buffer that doesn't exist", function()
local retval = setpos("'d", {3, 2, 1, 0})
eq(-1, retval)
- eq(getpos("'d"), {0, 0, 0, 0})
+ eq({0, 0, 0, 0}, getpos("'d"))
retval = setpos("'D", {3, 2, 1, 0})
eq(-1, retval)
- eq(getpos("'D"), {0, 0, 0, 0})
+ eq({0, 0, 0, 0}, getpos("'D"))
end)
it('can set uppercase marks', function()
setpos("'D", {2, 2, 3, 0})
- eq(getpos("'D"), {2, 2, 3, 0})
+ eq({2, 2, 3, 0}, getpos("'D"))
-- Can set a mark in another buffer
setpos("'D", {1, 2, 2, 0})
- eq(getpos("'D"), {1, 2, 2, 0})
+ eq({1, 2, 2, 0}, getpos("'D"))
end)
end)
diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua
index 24a1f05390..c915556c57 100644
--- a/test/functional/vimscript/system_spec.lua
+++ b/test/functional/vimscript/system_spec.lua
@@ -1,11 +1,13 @@
local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive
-local nvim_dir = helpers.nvim_dir
+local testprg = helpers.testprg
local eq, call, clear, eval, feed_command, feed, nvim =
helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command,
helpers.feed, helpers.nvim
local command = helpers.command
+local insert = helpers.insert
+local expect = helpers.expect
local exc_exec = helpers.exc_exec
local iswin = helpers.iswin
local os_kill = helpers.os_kill
@@ -30,10 +32,6 @@ describe('system()', function()
before_each(clear)
describe('command passed as a List', function()
- local function printargs_path()
- return nvim_dir..'/printargs-test' .. (iswin() and '.exe' or '')
- end
-
it('throws error if cmd[0] is not executable', function()
eq("Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable",
pcall_err(call, 'system', { 'this-should-not-exist' }))
@@ -66,23 +64,23 @@ describe('system()', function()
it('quotes arguments correctly #5280', function()
local out = call('system',
- { printargs_path(), [[1]], [[2 "3]], [[4 ' 5]], [[6 ' 7']] })
+ { testprg('printargs-test'), [[1]], [[2 "3]], [[4 ' 5]], [[6 ' 7']] })
eq(0, eval('v:shell_error'))
eq([[arg1=1;arg2=2 "3;arg3=4 ' 5;arg4=6 ' 7';]], out)
- out = call('system', { printargs_path(), [['1]], [[2 "3]] })
+ out = call('system', { testprg('printargs-test'), [['1]], [[2 "3]] })
eq(0, eval('v:shell_error'))
eq([[arg1='1;arg2=2 "3;]], out)
- out = call('system', { printargs_path(), "A\nB" })
+ out = call('system', { testprg('printargs-test'), "A\nB" })
eq(0, eval('v:shell_error'))
eq("arg1=A\nB;", out)
end)
it('calls executable in $PATH', function()
- if 0 == eval("executable('python')") then pending("missing `python`") end
- eq("foo\n", eval([[system(['python', '-c', 'print("foo")'])]]))
+ if 0 == eval("executable('python3')") then pending("missing `python3`") end
+ eq("foo\n", eval([[system(['python3', '-c', 'print("foo")'])]]))
eq(0, eval('v:shell_error'))
end)
@@ -167,7 +165,7 @@ describe('system()', function()
end
end)
- it('works with powershell', function()
+ it('with powershell', function()
helpers.set_shell_powershell()
eq('a\nb\n', eval([[system('Write-Output a b')]]))
eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]]))
@@ -175,12 +173,11 @@ describe('system()', function()
end)
end
- it('works with powershell w/ UTF-8 text (#13713)', function()
+ it('powershell w/ UTF-8 text #13713', function()
if not helpers.has_powershell() then
- pending("not tested; powershell was not found", function() end)
+ pending("powershell not found", function() end)
return
end
- -- Should work with recommended config used in helper
helpers.set_shell_powershell()
eq('ああ\n', eval([[system('Write-Output "ああ"')]]))
-- Sanity test w/ default encoding
@@ -268,7 +265,7 @@ describe('system()', function()
:call system("for /L %I in (1,0,2) do @echo y") |]]
or [[
:call system("yes") |]]))
- feed('<c-c>')
+ feed('foo<c-c>')
screen:expect([[
^ |
~ |
@@ -286,6 +283,49 @@ describe('system()', function()
Type :qa and press <Enter> to exit Nvim |
]])
end)
+
+ it('`yes` interrupted with mapped CTRL-C', function()
+ command('nnoremap <C-C> i')
+ feed(':call system("' .. (iswin()
+ and 'for /L %I in (1,0,2) do @echo y'
+ or 'yes') .. '")<cr>')
+ screen:expect([[
+ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+]] .. (iswin()
+ and [[
+ :call system("for /L %I in (1,0,2) do @echo y") |]]
+ or [[
+ :call system("yes") |]]))
+ feed('foo<c-c>')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ end)
end)
describe('passing no input', function()
@@ -387,7 +427,7 @@ describe('system()', function()
end)
it("with a program that doesn't close stdout will exit properly after passing input", function()
- local out = eval(string.format("system('%s', 'clip-data')", nvim_dir..'/streams-test'))
+ local out = eval(string.format("system('%s', 'clip-data')", testprg('streams-test')))
assert(out:sub(0, 5) == 'pid: ', out)
os_kill(out:match("%d+"))
end)
@@ -527,7 +567,7 @@ describe('systemlist()', function()
end)
-- Unlike `system()` which uses SOH to represent NULs, with `systemlist()`
- -- input and ouput are the same.
+ -- input and output are the same.
describe('with linefeed characters inside list items', function()
it('converts linefeed characters to NULs', function()
eq({'l1\np2', 'line2\na\nb', 'l3'},
@@ -566,17 +606,16 @@ describe('systemlist()', function()
end)
it("with a program that doesn't close stdout will exit properly after passing input", function()
- local out = eval(string.format("systemlist('%s', 'clip-data')", nvim_dir..'/streams-test'))
+ local out = eval(string.format("systemlist('%s', 'clip-data')", testprg('streams-test')))
assert(out[1]:sub(0, 5) == 'pid: ', out)
os_kill(out[1]:match("%d+"))
end)
- it('works with powershell w/ UTF-8 text (#13713)', function()
+ it('powershell w/ UTF-8 text #13713', function()
if not helpers.has_powershell() then
- pending("not tested; powershell was not found", function() end)
+ pending("powershell not found", function() end)
return
end
- -- Should work with recommended config used in helper
helpers.set_shell_powershell()
eq({iswin() and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]]))
-- Sanity test w/ default encoding
@@ -587,3 +626,31 @@ describe('systemlist()', function()
end)
end)
+
+describe('shell :!', function()
+ before_each(clear)
+
+ it(':{range}! with powershell filter/redirect #16271', function()
+ local screen = Screen.new(500, 8)
+ screen:attach()
+ local found = helpers.set_shell_powershell(true)
+ insert([[
+ 3
+ 1
+ 4
+ 2]])
+ feed(':4verbose %!sort<cr>')
+ screen:expect{
+ any=[[Executing command: .?Start%-Process sort %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]]
+ }
+ feed('<CR>')
+ if found then
+ -- Not using fake powershell, so we can test the result.
+ expect([[
+ 1
+ 2
+ 3
+ 4]])
+ end
+ end)
+end)
diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua
index e45b64422f..5463cfb234 100644
--- a/test/functional/vimscript/timer_spec.lua
+++ b/test/functional/vimscript/timer_spec.lua
@@ -96,7 +96,7 @@ describe('timers', function()
nvim_async("command", "let g:val = 0 | let g:c = getchar()")
retry(nil, nil, function()
local val = eval("g:val")
- ok(val >= 2, "expected >= 2, got: "..tostring(val))
+ ok(val >= 2, '>= 2', tostring(val))
eq(0, eval("getchar(1)"))
end)
feed("c")
@@ -272,4 +272,12 @@ describe('timers', function()
]]
eq("Vim(call):E48: Not allowed in sandbox", exc_exec("sandbox call timer_start(0, 'Scary')"))
end)
+
+ it('can be triggered after an empty string <expr> mapping #17257', function()
+ local screen = Screen.new(40, 6)
+ screen:attach()
+ command([=[imap <expr> <F2> [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=])
+ feed('i<F2>')
+ screen:expect({any='E605: Exception not caught: x'})
+ end)
end)