diff options
Diffstat (limited to 'test/old/testdir/test_functions.vim')
-rw-r--r-- | test/old/testdir/test_functions.vim | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 4ad01c8531..759cde7d5a 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -2565,6 +2565,65 @@ func Test_bufadd_bufload() 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 + func Test_range() " destructuring let [x, y] = range(2) |