diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-09-22 21:29:53 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-09-22 21:29:53 +0200 |
commit | c2585490321854ca3df115efcf0b40986901d96c (patch) | |
tree | 94da4422a3872bb6907961eeb75007c32317d901 /src/testdir/test_functions.vim | |
parent | 910c378d9342e0de8c6736c83ebdbbb597267056 (diff) | |
download | vim-git-c2585490321854ca3df115efcf0b40986901d96c.tar.gz |
patch 8.1.2066: no tests for state()v8.1.2066
Problem: No tests for state().
Solution: Add tests. Clean up some feature checks. Make "a" flag work.
Diffstat (limited to 'src/testdir/test_functions.vim')
-rw-r--r-- | src/testdir/test_functions.vim | 60 |
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 |