aboutsummaryrefslogtreecommitdiff
path: root/test/old
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-21 14:40:43 +0800
committerGitHub <noreply@github.com>2023-08-21 14:40:43 +0800
commit3b0515e674f279d6504a0fc055808cdf01eead99 (patch)
tree39f1120f66af1d5fb573241d06ce5d2d70d9a028 /test/old
parent91d8f2ac534a51859c0e3c6562d07c94b27f4478 (diff)
parent6aa29d0f01e715fe51de4f66dee377e4c1726229 (diff)
downloadrneovim-3b0515e674f279d6504a0fc055808cdf01eead99.tar.gz
rneovim-3b0515e674f279d6504a0fc055808cdf01eead99.tar.bz2
rneovim-3b0515e674f279d6504a0fc055808cdf01eead99.zip
Merge pull request #24816 from zeertzjq/vim-8.1.2044
vim-patch:8.1.{2044,2046,2047,2048,2053,2066,2067,2068,2069,2099},8.2.4299: SafeState, state()
Diffstat (limited to 'test/old')
-rw-r--r--test/old/testdir/test_autocmd.vim33
-rw-r--r--test/old/testdir/test_functions.vim60
2 files changed, 93 insertions, 0 deletions
diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim
index c44988321f..959efc0b49 100644
--- a/test/old/testdir/test_autocmd.vim
+++ b/test/old/testdir/test_autocmd.vim
@@ -2959,6 +2959,39 @@ func Test_autocmd_in_try_block()
au! BufEnter
endfunc
+func Test_autocmd_SafeState()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ let g:safe = 0
+ let g:again = ''
+ au SafeState * let g:safe += 1
+ au SafeStateAgain * let g:again ..= 'x'
+ func CallTimer()
+ call timer_start(10, {id -> execute('let g:again ..= "t"')})
+ endfunc
+ END
+ call writefile(lines, 'XSafeState')
+ let buf = RunVimInTerminal('-S XSafeState', #{rows: 6})
+
+ " Sometimes we loop to handle an K_IGNORE
+ call term_sendkeys(buf, ":echo g:safe\<CR>")
+ call WaitForAssert({-> assert_match('^[12] ', term_getline(buf, 6))}, 1000)
+
+ call term_sendkeys(buf, ":echo g:again\<CR>")
+ call WaitForAssert({-> assert_match('^xxxx', term_getline(buf, 6))}, 1000)
+
+ call term_sendkeys(buf, ":let g:again = ''\<CR>:call CallTimer()\<CR>")
+ call term_wait(buf)
+ call term_sendkeys(buf, ":\<CR>")
+ call term_wait(buf)
+ call term_sendkeys(buf, ":echo g:again\<CR>")
+ call WaitForAssert({-> assert_match('xtx', term_getline(buf, 6))}, 1000)
+
+ call StopVimInTerminal(buf)
+ call delete('XSafeState')
+endfunc
+
func Test_autocmd_CmdWinEnter()
CheckRunVimInTerminal
" There is not cmdwin switch, so
diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim
index 4ad01c8531..5981b5214b 100644
--- a/test/old/testdir/test_functions.vim
+++ b/test/old/testdir/test_functions.vim
@@ -2565,6 +2565,66 @@ func Test_bufadd_bufload()
call delete('XotherName')
endfunc
+func Test_state()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ call setline(1, ['one', 'two', 'three'])
+ map ;; gg
+ set complete=.
+ 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 (bit slower on Mac)
+ call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>")
+ call term_wait(buf, 200)
+ 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)