Mercurial > vim
diff src/testdir/test_terminal.vim @ 19245:5ed8297121fa v8.2.0181
patch 8.2.0181: problems parsing :term arguments
Commit: https://github.com/vim/vim/commit/21109272f5b0d32c408dc292561c0b1f2f8ebc53
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 30 16:27:20 2020 +0100
patch 8.2.0181: problems parsing :term arguments
Problem: Problems parsing :term arguments.
Solution: Improve parsing, fix memory leak, add tests. (Ozaki Kiichi,
closes #5536)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 30 Jan 2020 16:30:04 +0100 |
parents | c7b16393c248 |
children | ce8c47ed54e5 |
line wrap: on
line diff
--- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -689,53 +689,70 @@ func Test_terminal_noblock() endfunc func Test_terminal_write_stdin() - if !executable('wc') - throw 'skipped: wc command not available' - endif - if has('win32') - " TODO: enable once writing to stdin works on MS-Windows - return - endif - new + " TODO: enable once writing to stdin works on MS-Windows + CheckNotMSWindows + CheckExecutable wc + call setline(1, ['one', 'two', 'three']) %term wc call WaitForAssert({-> assert_match('3', getline("$"))}) let nrs = split(getline('$')) call assert_equal(['3', '3', '14'], nrs) - bwipe + %bwipe! - new call setline(1, ['one', 'two', 'three', 'four']) 2,3term wc call WaitForAssert({-> assert_match('2', getline("$"))}) let nrs = split(getline('$')) call assert_equal(['2', '2', '10'], nrs) - bwipe + %bwipe! +endfunc + +func Test_terminal_eof_arg() + CheckExecutable python + + call setline(1, ['print("hello")']) + 1term ++eof=exit(123) python + " MS-Windows echoes the input, Unix doesn't. + if has('win32') + call WaitFor({-> getline('$') =~ 'exit(123)'}) + call assert_equal('hello', getline(line('$') - 1)) + else + call WaitFor({-> getline('$') =~ 'hello'}) + call assert_equal('hello', getline('$')) + endif + call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) + %bwipe! +endfunc + +func Test_terminal_eof_arg_win32_ctrl_z() + CheckMSWindows + CheckExecutable python - if executable('python') - new - call setline(1, ['print("hello")']) - 1term ++eof=exit() python - " MS-Windows echoes the input, Unix doesn't. - call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"') - if getline(1) =~ 'hello' - call assert_equal('hello', getline(1)) - else - call assert_equal('hello', getline(line('$') - 1)) - endif - bwipe + call setline(1, ['print("hello")']) + 1term ++eof=<C-Z> python + call WaitForAssert({-> assert_match('\^Z', getline(line('$') - 1))}) + call assert_match('\^Z', getline(line('$') - 1)) + %bwipe! +endfunc + +func Test_terminal_duplicate_eof_arg() + CheckExecutable python - if has('win32') - new - call setline(1, ['print("hello")']) - 1term ++eof=<C-Z> python - call WaitForAssert({-> assert_match('Z', getline("$"))}) - call assert_equal('hello', getline(line('$') - 1)) - bwipe - endif + " Check the last specified ++eof arg is used and should not memory leak. + new + call setline(1, ['print("hello")']) + 1term ++eof=<C-Z> ++eof=exit(123) python + " MS-Windows echoes the input, Unix doesn't. + if has('win32') + call WaitFor({-> getline('$') =~ 'exit(123)'}) + call assert_equal('hello', getline(line('$') - 1)) + else + call WaitFor({-> getline('$') =~ 'hello'}) + call assert_equal('hello', getline('$')) endif - - bwipe! + call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) + %bwipe! endfunc func Test_terminal_no_cmd() @@ -2242,9 +2259,7 @@ func Test_terminal_shell_option() endfunc func Test_terminal_setapi_and_call() - if !CanRunVimInTerminal() - return - endif + CheckRunVimInTerminal call WriteApiCall('Tapi_TryThis') call ch_logfile('Xlog', 'w') @@ -2252,17 +2267,18 @@ func Test_terminal_setapi_and_call() unlet! g:called_bufnum unlet! g:called_arg - let buf = RunVimInTerminal('-S Xscript', {'term_api': 0}) + let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) 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') + eval buf->term_setapi('Tapi_') 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') @@ -2271,3 +2287,37 @@ func Test_terminal_setapi_and_call() unlet! g:called_bufnum unlet! g:called_arg endfunc + +func Test_terminal_api_arg() + CheckRunVimInTerminal + + call WriteApiCall('Tapi_TryThis') + call ch_logfile('Xlog', 'w') + + unlet! g:called_bufnum + unlet! g:called_arg + + execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript' + let buf = bufnr('%') + 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 StopVimInTerminal(buf) + + call ch_logfile('Xlog', 'w') + + execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript' + let buf = bufnr('%') + 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