summaryrefslogtreecommitdiff
path: root/src/testdir/test_functions.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_functions.vim')
-rw-r--r--src/testdir/test_functions.vim60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 37aba38f9..878d3436a 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -1,6 +1,7 @@
" 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()
@@ -1659,3 +1660,62 @@ func Test_bufadd_bufload()
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