Mercurial > vim
diff src/testdir/test_functions.vim @ 18143:2416e1a887ca
patch 8.1.2066: no tests for state()
Commit: https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 22 21:29:53 2019 +0200
patch 8.1.2066: no tests for state()
Problem: No tests for state().
Solution: Add tests. Clean up some feature checks. Make "a" flag work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Sep 2019 21:30:04 +0200 |
parents | 609b351cb58f |
children | 9a7bbad64376 |
line wrap: on
line diff
--- 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