aboutsummaryrefslogtreecommitdiff
path: root/test/functional/eval/ctx_functions_spec.lua
diff options
context:
space:
mode:
authorAbdelhakeem <abdelhakeem.osama@hotmail.com>2019-07-21 21:41:04 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-07-27 22:14:58 +0200
commitb6278bbf12dd4946095b76f47b7c2ace3f929245 (patch)
tree37d30921c145e9266535441b7e51959ddbc7b8b2 /test/functional/eval/ctx_functions_spec.lua
parent691deca2e8449ec0c3b5081ed4fe6076fd820913 (diff)
downloadrneovim-b6278bbf12dd4946095b76f47b7c2ace3f929245.tar.gz
rneovim-b6278bbf12dd4946095b76f47b7c2ace3f929245.tar.bz2
rneovim-b6278bbf12dd4946095b76f47b7c2ace3f929245.zip
API: Context: save/restore
Diffstat (limited to 'test/functional/eval/ctx_functions_spec.lua')
-rw-r--r--test/functional/eval/ctx_functions_spec.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/test/functional/eval/ctx_functions_spec.lua b/test/functional/eval/ctx_functions_spec.lua
index 3699af0793..35133e2341 100644
--- a/test/functional/eval/ctx_functions_spec.lua
+++ b/test/functional/eval/ctx_functions_spec.lua
@@ -10,6 +10,8 @@ local feed = helpers.feed
local map = helpers.map
local nvim = helpers.nvim
local parse_context = helpers.parse_context
+local redir_exec = helpers.redir_exec
+local source = helpers.source
local trim = helpers.trim
local write_file = helpers.write_file
@@ -126,6 +128,109 @@ describe('context functions', function()
eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]'))
end)
+ it('saves and restores script functions properly', function()
+ source([[
+ function s:greet(name)
+ echom 'Hello, '.a:name.'!'
+ endfunction
+
+ function s:greet_all(name, ...)
+ echom 'Hello, '.a:name.'!'
+ for more in a:000
+ echom 'Hello, '.more.'!'
+ endfor
+ endfunction
+
+ function Greet(name)
+ call call('s:greet', [a:name])
+ endfunction
+
+ function GreetAll(name, ...)
+ call call('s:greet_all', extend([a:name], a:000))
+ endfunction
+
+ function SaveSFuncs()
+ call ctxpush(['sfuncs'])
+ endfunction
+
+ function DeleteSFuncs()
+ delfunction s:greet
+ delfunction s:greet_all
+ endfunction
+
+ function RestoreFuncs()
+ call ctxpop()
+ endfunction
+ ]])
+
+ eq('\nHello, World!', redir_exec([[call Greet('World')]]))
+ eq('\nHello, World!'..
+ '\nHello, One!'..
+ '\nHello, Two!'..
+ '\nHello, Three!',
+ redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+
+ call('SaveSFuncs')
+ call('DeleteSFuncs')
+
+ eq('\nError detected while processing function Greet:'..
+ '\nline 1:'..
+ '\nE117: Unknown function: s:greet',
+ redir_exec([[call Greet('World')]]))
+ eq('\nError detected while processing function GreetAll:'..
+ '\nline 1:'..
+ '\nE117: Unknown function: s:greet_all',
+ redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+
+ call('RestoreFuncs')
+
+ eq('\nHello, World!', redir_exec([[call Greet('World')]]))
+ eq('\nHello, World!'..
+ '\nHello, One!'..
+ '\nHello, Two!'..
+ '\nHello, Three!',
+ redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ end)
+
+ it('saves and restores functions properly', function()
+ source([[
+ function Greet(name)
+ echom 'Hello, '.a:name.'!'
+ endfunction
+
+ function GreetAll(name, ...)
+ echom 'Hello, '.a:name.'!'
+ for more in a:000
+ echom 'Hello, '.more.'!'
+ endfor
+ endfunction
+ ]])
+
+ eq('\nHello, World!', redir_exec([[call Greet('World')]]))
+ eq('\nHello, World!'..
+ '\nHello, One!'..
+ '\nHello, Two!'..
+ '\nHello, Three!',
+ redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+
+ call('ctxpush', {'funcs'})
+ command('delfunction Greet')
+ command('delfunction GreetAll')
+
+ expect_err('Vim:E117: Unknown function: Greet', call, 'Greet', 'World')
+ expect_err('Vim:E117: Unknown function: Greet', call, 'GreetAll',
+ 'World', 'One', 'Two', 'Three')
+
+ call('ctxpop')
+
+ eq('\nHello, World!', redir_exec([[call Greet('World')]]))
+ eq('\nHello, World!'..
+ '\nHello, One!'..
+ '\nHello, Two!'..
+ '\nHello, Three!',
+ redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]]))
+ end)
+
it('errors out when context stack is empty', function()
local err = 'Vim:Context stack is empty'
expect_err(err, call, 'ctxpop')