Mercurial > vim
diff src/testdir/test_terminal.vim @ 18170:4ac8161e92e0 v8.1.2080
patch 8.1.2080: the terminal API is limited and can't be disabled
Commit: https://github.com/vim/vim/commit/d2842ea60bd608b7f9ec93c77d3f36a8e3bf5fe9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 26 23:08:54 2019 +0200
patch 8.1.2080: the terminal API is limited and can't be disabled
Problem: The terminal API is limited and can't be disabled.
Solution: Add term_setapi() to set the function prefix. (Ozaki Kiichi,
closes #2907)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 Sep 2019 23:15:05 +0200 |
parents | 2416e1a887ca |
children | f6dcf7eabd26 |
line wrap: on
line diff
--- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -1353,30 +1353,90 @@ endfunc func Test_terminal_api_call() CheckRunVimInTerminal +call ch_logfile('logfile', 'w') + unlet! g:called_bufnum + unlet! g:called_arg + call WriteApiCall('Tapi_TryThis') + + " Default let buf = RunVimInTerminal('-S Xscript', {}) call WaitFor({-> exists('g:called_bufnum')}) call assert_equal(buf, g:called_bufnum) call assert_equal(['hello', 123], g:called_arg) + call StopVimInTerminal(buf) + unlet! g:called_bufnum + unlet! g:called_arg + + " Enable explicitly + let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'}) + call WaitFor({-> exists('g:called_bufnum')}) + call assert_equal(buf, g:called_bufnum) + call assert_equal(['hello', 123], g:called_arg) call StopVimInTerminal(buf) + + unlet! g:called_bufnum + unlet! g:called_arg + + func! ApiCall_TryThis(bufnum, arg) + let g:called_bufnum2 = a:bufnum + let g:called_arg2 = a:arg + endfunc + + call WriteApiCall('ApiCall_TryThis') + + " Use prefix match + let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'}) + call WaitFor({-> exists('g:called_bufnum2')}) + call assert_equal(buf, g:called_bufnum2) + call assert_equal(['hello', 123], g:called_arg2) + call StopVimInTerminal(buf) + + unlet! g:called_bufnum2 + unlet! g:called_arg2 + call delete('Xscript') - unlet g:called_bufnum - unlet g:called_arg + delfunction! ApiCall_TryThis + unlet! g:called_bufnum2 + unlet! g:called_arg2 endfunc func Test_terminal_api_call_fails() CheckRunVimInTerminal + func! TryThis(bufnum, arg) + let g:called_bufnum3 = a:bufnum + let g:called_arg3 = a:arg + endfunc + call WriteApiCall('TryThis') - call ch_logfile('Xlog', 'w') - let buf = RunVimInTerminal('-S Xscript', {}) - call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) + + unlet! g:called_bufnum3 + unlet! g:called_arg3 + " Not permitted + call ch_logfile('Xlog', 'w') + let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) + call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))}) + call assert_false(exists('g:called_bufnum3')) + call assert_false(exists('g:called_arg3')) call StopVimInTerminal(buf) + + " No match + call ch_logfile('Xlog', 'w') + let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'}) + call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'}) + call assert_false(exists('g:called_bufnum3')) + call assert_false(exists('g:called_arg3')) + call StopVimInTerminal(buf) + call delete('Xscript') - call ch_logfile('', '') + call ch_logfile('') call delete('Xlog') + delfunction! TryThis + unlet! g:called_bufnum3 + unlet! g:called_arg3 endfunc let s:caught_e937 = 0 @@ -2061,3 +2121,34 @@ func Test_terminal_altscreen() exe buf . "bwipe!" call delete('Xtext') endfunc + +func Test_terminal_setapi_and_call() + if !CanRunVimInTerminal() + return + endif + + call WriteApiCall('Tapi_TryThis') + call ch_logfile('Xlog', 'w') + + unlet! g:called_bufnum + unlet! g:called_arg + + let buf = RunVimInTerminal('-S Xscript', {'term_api': 0}) + call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) + call assert_false(exists('g:called_bufnum')) + call assert_false(exists('g:called_arg')) + + call term_setapi(buf, 'Tapi_TryThis') + call term_sendkeys(buf, ":set notitle\<CR>") + call term_sendkeys(buf, ":source Xscript\<CR>") + call WaitFor({-> exists('g:called_bufnum')}) + call assert_equal(buf, g:called_bufnum) + call assert_equal(['hello', 123], g:called_arg) + call StopVimInTerminal(buf) + + call delete('Xscript') + call ch_logfile('') + call delete('Xlog') + unlet! g:called_bufnum + unlet! g:called_arg +endfunc