mirror of
https://github.com/vim/vim.git
synced 2025-10-03 05:14:07 -04:00
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.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user