" Tests for various functions.
source shared.vim
source check.vim
+source term_util.vim
" Must be done first, since the alternate buffer must be unset.
func Test_00_bufexists()
call assert_equal(0, bufexists('someName'))
call delete('XotherName')
endfunc
+
+func Test_state()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ call setline(1, ['one', 'two', 'three'])
+ map ;; gg
+ func RunTimer()
+ call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')})
+ endfunc
+ au Filetype foobar let g:state = state()|let g:mode = mode()
+ END
+ call writefile(lines, 'XState')
+ let buf = RunVimInTerminal('-S XState', #{rows: 6})
+
+ " Using a ":" command Vim is busy, thus "S" is returned
+ call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>")
+ call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000)
+ call term_sendkeys(buf, ":\<CR>")
+
+ " Using a timer callback
+ call term_sendkeys(buf, ":call RunTimer()\<CR>")
+ call term_wait(buf, 50)
+ let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>"
+ call term_sendkeys(buf, getstate)
+ call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000)
+
+ " Halfway a mapping
+ call term_sendkeys(buf, ":call RunTimer()\<CR>;")
+ call term_wait(buf, 50)
+ call term_sendkeys(buf, ";")
+ call term_sendkeys(buf, getstate)
+ call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000)
+
+ " Insert mode completion
+ call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>")
+ call term_wait(buf, 50)
+ call term_sendkeys(buf, "\<Esc>")
+ call term_sendkeys(buf, getstate)
+ call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000)
+
+ " Autocommand executing
+ call term_sendkeys(buf, ":set filetype=foobar\<CR>")
+ call term_wait(buf, 50)
+ call term_sendkeys(buf, getstate)
+ call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000)
+
+ " Todo: "w" - waiting for ch_evalexpr()
+
+ " messages scrolled
+ call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>")
+ call term_wait(buf, 50)
+ call term_sendkeys(buf, "\<CR>")
+ call term_sendkeys(buf, getstate)
+ call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000)
+
+ call StopVimInTerminal(buf)
+ call delete('XState')
+endfunc
" Run Vim in a terminal, then start a terminal in that Vim without a kill
" argument, check that :confirm qall works.
func Test_terminal_qall_prompt()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = RunVimInTerminal('', {})
" Open a terminal window and wait for the prompt to appear
endfunc
func Test_terminal_dumpwrite_composing()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let save_enc = &encoding
set encoding=utf-8
call assert_equal(1, winnr('$'))
endfunc
func Test_terminal_api_drop_newwin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common('')
call assert_equal(0, &bin)
call assert_equal('', &fenc)
endfunc
func Test_terminal_api_drop_newwin_bin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"bin":1}')
call assert_equal(1, &bin)
endfunc
func Test_terminal_api_drop_newwin_binary()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"binary":1}')
call assert_equal(1, &bin)
endfunc
func Test_terminal_api_drop_newwin_nobin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set binary
let buf = Api_drop_common(',{"nobin":1}')
call assert_equal(0, &bin)
endfunc
func Test_terminal_api_drop_newwin_nobinary()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set binary
let buf = Api_drop_common(',{"nobinary":1}')
call assert_equal(0, &bin)
endfunc
func Test_terminal_api_drop_newwin_ff()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"ff":"dos"}')
call assert_equal("dos", &ff)
endfunc
func Test_terminal_api_drop_newwin_fileformat()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"fileformat":"dos"}')
call assert_equal("dos", &ff)
endfunc
func Test_terminal_api_drop_newwin_enc()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"enc":"utf-16"}')
call assert_equal("utf-16", &fenc)
endfunc
func Test_terminal_api_drop_newwin_encoding()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"encoding":"utf-16"}')
call assert_equal("utf-16", &fenc)
endfunc
func Test_terminal_api_drop_oldwin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let firstwinid = win_getid()
split Xtextfile
let textfile_winid = win_getid()
endfunc
func Test_terminal_api_call()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('Tapi_TryThis')
let buf = RunVimInTerminal('-S Xscript', {})
endfunc
func Test_terminal_api_call_fails()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('TryThis')
call ch_logfile('Xlog', 'w')
endfunc
func Test_terminal_api_call_fail_delete()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('Tapi_Delete')
let buf = RunVimInTerminal('-S Xscript', {})
endfunc
func Test_terminal_all_ansi_colors()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" Use all the ANSI colors.
call writefile([
endfunc
func Test_terminal_termwinsize_option_fixed()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set termwinsize=6x40
let text = []
for n in range(10)
endfunc
func Test_terminal_getwinpos()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" split, go to the bottom-right window
split