diff options
Diffstat (limited to 'test/functional/eval')
-rw-r--r-- | test/functional/eval/api_functions_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/eval/buf_functions_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/eval/ctx_functions_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/eval/environ_spec.lua | 1 | ||||
-rw-r--r-- | test/functional/eval/fnamemodify_spec.lua | 119 | ||||
-rw-r--r-- | test/functional/eval/input_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/eval/let_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/eval/map_functions_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/eval/null_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/eval/sort_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/eval/system_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/eval/timer_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/eval/uniq_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/eval/wait_spec.lua | 7 |
14 files changed, 180 insertions, 34 deletions
diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/eval/api_functions_spec.lua index 4fbd08f102..ccd97fc8c7 100644 --- a/test/functional/eval/api_functions_spec.lua +++ b/test/functional/eval/api_functions_spec.lua @@ -44,7 +44,7 @@ describe('eval-API', function() eq('Vim(call):E5555: API call: Wrong type for argument 1, expecting Buffer', err) err = exc_exec('call nvim_buf_line_count(17)') - eq('Vim(call):E5555: API call: Invalid buffer id', err) + eq('Vim(call):E5555: API call: Invalid buffer id: 17', err) end) @@ -144,7 +144,6 @@ describe('eval-API', function() {5:~ }| | ]]) - screen:detach() end) it('cannot be called from sandbox', function() diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/eval/buf_functions_spec.lua index 37f4c89bfd..06841a4521 100644 --- a/test/functional/eval/buf_functions_spec.lua +++ b/test/functional/eval/buf_functions_spec.lua @@ -31,10 +31,12 @@ for _, func in ipairs({'bufname(%s)', 'bufnr(%s)', 'bufwinnr(%s)', it('errors out when receives v:true/v:false/v:null', function() -- Not compatible with Vim: in Vim it always results in buffer not found -- without any error messages. - for _, var in ipairs({'v:true', 'v:false', 'v:null'}) do - eq('Vim(call):E5300: Expected a Number or a String', + 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))) end + eq('Vim(call):E5300: Expected a Number or a String', + exc_exec('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', diff --git a/test/functional/eval/ctx_functions_spec.lua b/test/functional/eval/ctx_functions_spec.lua index c81dad9645..f23adbc556 100644 --- a/test/functional/eval/ctx_functions_spec.lua +++ b/test/functional/eval/ctx_functions_spec.lua @@ -6,7 +6,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local map = helpers.map +local map = helpers.tbl_map local nvim = helpers.nvim local parse_context = helpers.parse_context local redir_exec = helpers.redir_exec diff --git a/test/functional/eval/environ_spec.lua b/test/functional/eval/environ_spec.lua index 4c2adcf1bf..54d2dc960b 100644 --- a/test/functional/eval/environ_spec.lua +++ b/test/functional/eval/environ_spec.lua @@ -10,6 +10,7 @@ describe('environment variables', function() eq("", environ()['EMPTY_VAR']) eq(nil, environ()['DOES_NOT_EXIST']) end) + it('exists() handles empty env variable', function() clear({env={EMPTY_VAR=""}}) eq(1, exists('$EMPTY_VAR')) diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index fe6b50a544..d54a6db417 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -3,8 +3,14 @@ local clear = helpers.clear local eq = helpers.eq local iswin = helpers.iswin local fnamemodify = helpers.funcs.fnamemodify +local getcwd = helpers.funcs.getcwd local command = helpers.command local write_file = helpers.write_file +local alter_slashes = helpers.alter_slashes + +local function eq_slashconvert(expected, got) + eq(alter_slashes(expected), alter_slashes(got)) +end describe('fnamemodify()', function() setup(function() @@ -17,7 +23,7 @@ describe('fnamemodify()', function() os.remove('Xtest-fnamemodify.txt') end) - it('works', function() + it('handles the root path', function() local root = helpers.pathroot() eq(root, fnamemodify([[/]], ':p:h')) eq(root, fnamemodify([[/]], ':p')) @@ -36,4 +42,115 @@ describe('fnamemodify()', function() it(':8 works', function() eq('Xtest-fnamemodify.txt', fnamemodify([[Xtest-fnamemodify.txt]], ':8')) end) + + it('handles examples from ":help filename-modifiers"', function() + local filename = "src/version.c" + local cwd = getcwd() + + eq_slashconvert(cwd .. '/src/version.c', fnamemodify(filename, ':p')) + + eq_slashconvert('src/version.c', fnamemodify(filename, ':p:.')) + eq_slashconvert(cwd .. '/src', fnamemodify(filename, ':p:h')) + eq_slashconvert(cwd .. '', fnamemodify(filename, ':p:h:h')) + eq('version.c', fnamemodify(filename, ':p:t')) + eq_slashconvert(cwd .. '/src/version', fnamemodify(filename, ':p:r')) + + eq_slashconvert(cwd .. '/src/main.c', fnamemodify(filename, ':s?version?main?:p')) + + local converted_cwd = cwd:gsub('/', '\\') + eq(converted_cwd .. '\\src\\version.c', fnamemodify(filename, ':p:gs?/?\\\\?')) + + eq('src', fnamemodify(filename, ':h')) + eq('version.c', fnamemodify(filename, ':t')) + eq_slashconvert('src/version', fnamemodify(filename, ':r')) + eq('version', fnamemodify(filename, ':t:r')) + eq('c', fnamemodify(filename, ':e')) + + eq_slashconvert('src/main.c', fnamemodify(filename, ':s?version?main?')) + end) + + it('handles advanced examples from ":help filename-modifiers"', function() + local filename = "src/version.c.gz" + + eq('gz', fnamemodify(filename, ':e')) + eq('c.gz', fnamemodify(filename, ':e:e')) + eq('c.gz', fnamemodify(filename, ':e:e:e')) + + eq('c', fnamemodify(filename, ':e:e:r')) + + eq_slashconvert('src/version.c', fnamemodify(filename, ':r')) + eq('c', fnamemodify(filename, ':r:e')) + + eq_slashconvert('src/version', fnamemodify(filename, ':r:r')) + eq_slashconvert('src/version', fnamemodify(filename, ':r:r:r')) + end) + + it('handles :h', function() + eq('.', fnamemodify('hello.txt', ':h')) + + eq_slashconvert('path/to', fnamemodify('path/to/hello.txt', ':h')) + end) + + it('handles :t', function() + eq('hello.txt', fnamemodify('hello.txt', ':t')) + eq_slashconvert('hello.txt', fnamemodify('path/to/hello.txt', ':t')) + end) + + it('handles :r', function() + eq('hello', fnamemodify('hello.txt', ':r')) + eq_slashconvert('path/to/hello', fnamemodify('path/to/hello.txt', ':r')) + end) + + it('handles :e', function() + eq('txt', fnamemodify('hello.txt', ':e')) + eq_slashconvert('txt', fnamemodify('path/to/hello.txt', ':e')) + end) + + it('handles regex replacements', function() + eq('content-there-here.txt', fnamemodify('content-here-here.txt', ':s/here/there/')) + eq('content-there-there.txt', fnamemodify('content-here-here.txt', ':gs/here/there/')) + end) + + it('handles shell escape', function() + local expected + + if iswin() then + -- we expand with double-quotes on Windows + expected = [["hello there! quote ' newline]] .. '\n' .. [["]] + else + expected = [['hello there! quote '\'' newline]] .. '\n' .. [[']] + end + + eq(expected, fnamemodify("hello there! quote ' newline\n", ':S')) + end) + + it('can combine :e and :r', function() + -- simple, single extension filename + eq('c', fnamemodify('a.c', ':e')) + eq('c', fnamemodify('a.c', ':e:e')) + eq('c', fnamemodify('a.c', ':e:e:r')) + eq('c', fnamemodify('a.c', ':e:e:r:r')) + + -- multi extension filename + eq('rb', fnamemodify('a.spec.rb', ':e:r')) + eq('rb', fnamemodify('a.spec.rb', ':e:r:r')) + + eq('spec', fnamemodify('a.spec.rb', ':e:e:r')) + eq('spec', fnamemodify('a.spec.rb', ':e:e:r:r')) + + eq('spec', fnamemodify('a.b.spec.rb', ':e:e:r')) + eq('b.spec', fnamemodify('a.b.spec.rb', ':e:e:e:r')) + eq('b', fnamemodify('a.b.spec.rb', ':e:e:e:r:r')) + + eq('spec', fnamemodify('a.b.spec.rb', ':r:e')) + eq('b', fnamemodify('a.b.spec.rb', ':r:r:e')) + + -- extraneous :e expansions + eq('c', fnamemodify('a.b.c.d.e', ':r:r:e')) + eq('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e')) + + -- :e never includes the whole filename, so "a.b":e:e:e --> "b" + eq('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e')) + eq('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e:e')) + end) end) diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index e774b939f7..14c02f9eb2 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -462,7 +462,7 @@ describe('confirm()', function() -- With shortmess-=F command('set shortmess-=F') feed(':edit foo<cr>') - check_and_clear('"foo" [New File] |\n') + check_and_clear('"foo" [New] |\n') -- With shortmess+=F command('set shortmess+=F') diff --git a/test/functional/eval/let_spec.lua b/test/functional/eval/let_spec.lua index 63e18f943f..5bc703b567 100644 --- a/test/functional/eval/let_spec.lua +++ b/test/functional/eval/let_spec.lua @@ -59,10 +59,6 @@ describe(':let', function() end) it("multibyte env var to child process #8398 #9267", function() - if (not helpers.iswin()) and helpers.isCI() then - -- Fails on non-Windows CI. Buffering/timing issue? - pending('fails on unix CI', function() end) - end local cmd_get_child_env = "let g:env_from_child = system(['"..nvim_dir.."/printenv-test', 'NVIM_TEST'])" command("let $NVIM_TEST = 'AìaB'") command(cmd_get_child_env) @@ -79,4 +75,19 @@ describe(':let', function() command(cmd_get_child_env) eq(eval('$NVIM_TEST'), eval('g:env_from_child')) end) + + it("release of list assigned to l: variable does not trigger assertion #12387, #12430", function() + source([[ + func! s:f() + let l:x = [1] + let g:x = l: + endfunc + for _ in range(2) + call s:f() + endfor + call garbagecollect() + call feedkeys('i', 't') + ]]) + eq(1, eval('1')) + end) end) diff --git a/test/functional/eval/map_functions_spec.lua b/test/functional/eval/map_functions_spec.lua index 2747a94570..275c72d212 100644 --- a/test/functional/eval/map_functions_spec.lua +++ b/test/functional/eval/map_functions_spec.lua @@ -13,6 +13,7 @@ describe('maparg()', function() local foo_bar_map_table = { lhs='foo', + script=0, silent=0, rhs='bar', expr=0, @@ -147,6 +148,7 @@ describe('maparg()', function() mode = 'n', noremap = 1, nowait = 0, + script=0, sid = 0, silent = 0, lnum = 0, diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index afe999e1fa..db0a706319 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -47,10 +47,8 @@ describe('NULL', function() -- Subjectable behaviour - -- FIXME Should return 1 - null_expr_test('is equal to empty list', 'L == []', 0, 0) - -- FIXME Should return 1 - null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) + null_expr_test('is equal to empty list', 'L == []', 0, 1) + null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 1) -- Correct behaviour null_expr_test('can be indexed with error message for empty list', 'L[0]', diff --git a/test/functional/eval/sort_spec.lua b/test/functional/eval/sort_spec.lua index 82557575ce..e1cc2c2924 100644 --- a/test/functional/eval/sort_spec.lua +++ b/test/functional/eval/sort_spec.lua @@ -14,7 +14,7 @@ before_each(clear) describe('sort()', function() it('errors out when sorting special values', function() - eq('Vim(call):E907: Using a special value as a Float', + eq('Vim(call):E362: Using a boolean value as a Float', exc_exec('call sort([v:true, v:false], "f")')) end) @@ -30,6 +30,7 @@ describe('sort()', function() errors[err] = true end eq({ + ['E362: Using a boolean value as a Float']=true, ['E891: Using a Funcref as a Float']=true, ['E892: Using a String as a Float']=true, ['E893: Using a List as a Float']=true, diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 0a478fd05c..8b18eff451 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -8,6 +8,7 @@ local command = helpers.command local exc_exec = helpers.exc_exec local iswin = helpers.iswin local os_kill = helpers.os_kill +local pcall_err = helpers.pcall_err local Screen = require('test.functional.ui.screen') @@ -32,8 +33,9 @@ describe('system()', function() return nvim_dir..'/printargs-test' .. (iswin() and '.exe' or '') end - it('sets v:shell_error if cmd[0] is not executable', function() - call('system', { 'this-should-not-exist' }) + 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' })) eq(-1, eval('v:shell_error')) end) @@ -48,7 +50,8 @@ describe('system()', function() eq(0, eval('v:shell_error')) -- Provoke a non-zero v:shell_error. - call('system', { 'this-should-not-exist' }) + eq("Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable", + pcall_err(call, 'system', { 'this-should-not-exist' })) local old_val = eval('v:shell_error') eq(-1, old_val) @@ -84,7 +87,7 @@ describe('system()', function() it('does NOT run in shell', function() if iswin() then - eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'echo', '%PATH%'])")) + eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'Write-Output', '%PATH%'])")) else eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) end @@ -121,10 +124,6 @@ describe('system()', function() screen:attach() end) - after_each(function() - screen:detach() - end) - if iswin() then local function test_more() eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]])) @@ -133,7 +132,7 @@ describe('system()', function() eval([[system('"ping" "-n" "1" "127.0.0.1"')]]) eq(0, eval('v:shell_error')) eq('"a b"\n', eval([[system('cmd /s/c "cmd /s/c "cmd /s/c "echo "a b""""')]])) - eq('"a b"\n', eval([[system('powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command echo ''\^"a b\^"''')]])) + eq('"a b"\n', eval([[system('powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command Write-Output ''\^"a b\^"''')]])) end it('with shell=cmd.exe', function() @@ -169,9 +168,9 @@ describe('system()', function() it('works with powershell', function() helpers.set_shell_powershell() - eq('a\nb\n', eval([[system('echo a b')]])) + eq('a\nb\n', eval([[system('Write-Output a b')]])) eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]])) - eq('a b\n', eval([[system('echo "a b"')]])) + eq('a b\n', eval([[system('Write-Output "a b"')]])) end) end diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index 2ccb9cfbac..ef7df69fdb 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -111,7 +111,13 @@ describe('timers', function() curbufmeths.set_lines(0, -1, true, {"ITEM 1", "ITEM 2"}) source([[ + let g:cont = 0 func! AddItem(timer) + if !g:cont + return + endif + call timer_stop(a:timer) + call nvim_buf_set_lines(0, 2, 2, v:true, ['ITEM 3']) " Meant to test for what Vim tests in Test_peek_and_get_char. @@ -121,7 +127,7 @@ describe('timers', function() endfunc ]]) nvim_async("command", "let g:c2 = getchar()") - nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem')") + nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})") screen:expect([[ ITEM 1 | @@ -131,6 +137,7 @@ describe('timers', function() {1:~ }| ^ | ]]) + nvim_async("command", "let g:cont = 1") screen:expect([[ ITEM 1 | @@ -222,12 +229,17 @@ describe('timers', function() source([[ let g:val = 0 func! MyHandler(timer) + while !g:val + return + endwhile + call timer_stop(a:timer) + echo "evil" redraw - let g:val = 1 + let g:val = 2 endfunc ]]) - command("call timer_start(100, 'MyHandler', {'repeat': 1})") + command("call timer_start(100, 'MyHandler', {'repeat': -1})") feed(":good") screen:expect([[ | @@ -237,6 +249,7 @@ describe('timers', function() {0:~ }| :good^ | ]]) + command('let g:val = 1') screen:expect{grid=[[ | @@ -247,6 +260,6 @@ describe('timers', function() :good^ | ]], intermediate=true, timeout=load_adjust(200)} - eq(1, eval('g:val')) + eq(2, eval('g:val')) end) end) diff --git a/test/functional/eval/uniq_spec.lua b/test/functional/eval/uniq_spec.lua index 0e7a013e32..5cdba0a0f6 100644 --- a/test/functional/eval/uniq_spec.lua +++ b/test/functional/eval/uniq_spec.lua @@ -11,7 +11,7 @@ before_each(clear) describe('uniq()', function() it('errors out when processing special values', function() - eq('Vim(call):E907: Using a special value as a Float', + eq('Vim(call):E362: Using a boolean value as a Float', exc_exec('call uniq([v:true, v:false], "f")')) end) diff --git a/test/functional/eval/wait_spec.lua b/test/functional/eval/wait_spec.lua index ad7d1574cb..ee95e02a7f 100644 --- a/test/functional/eval/wait_spec.lua +++ b/test/functional/eval/wait_spec.lua @@ -58,8 +58,11 @@ describe('wait()', function() endfunction ]]) - nvim('set_var', 'counter', 0) - eq(-1, call('wait', 20, 'Count() >= 5', 99999)) + -- XXX: flaky (#11137) + helpers.retry(nil, nil, function() + nvim('set_var', 'counter', 0) + eq(-1, call('wait', 20, 'Count() >= 5', 99999)) + end) nvim('set_var', 'counter', 0) eq(0, call('wait', 10000, 'Count() >= 5', 5)) |