aboutsummaryrefslogtreecommitdiff
path: root/test/functional/eval
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/eval')
-rw-r--r--test/functional/eval/api_functions_spec.lua1
-rw-r--r--test/functional/eval/environ_spec.lua1
-rw-r--r--test/functional/eval/fnamemodify_spec.lua119
-rw-r--r--test/functional/eval/let_spec.lua4
-rw-r--r--test/functional/eval/system_spec.lua12
-rw-r--r--test/functional/eval/timer_spec.lua21
-rw-r--r--test/functional/eval/wait_spec.lua7
7 files changed, 145 insertions, 20 deletions
diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/eval/api_functions_spec.lua
index 4fbd08f102..f527aff33f 100644
--- a/test/functional/eval/api_functions_spec.lua
+++ b/test/functional/eval/api_functions_spec.lua
@@ -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/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/let_spec.lua b/test/functional/eval/let_spec.lua
index 63e18f943f..f8fcdfd41f 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)
diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua
index 0a478fd05c..1e4d760dbc 100644
--- a/test/functional/eval/system_spec.lua
+++ b/test/functional/eval/system_spec.lua
@@ -84,7 +84,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 +121,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 +129,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 +165,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/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))