summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-09-22 21:29:53 +0200
committerBram Moolenaar <Bram@vim.org>2019-09-22 21:29:53 +0200
commitc2585490321854ca3df115efcf0b40986901d96c (patch)
tree94da4422a3872bb6907961eeb75007c32317d901
parent910c378d9342e0de8c6736c83ebdbbb597267056 (diff)
downloadvim-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.
-rw-r--r--src/misc1.c2
-rw-r--r--src/testdir/test_functions.vim60
-rw-r--r--src/testdir/test_terminal.vim72
-rw-r--r--src/version.c2
4 files changed, 81 insertions, 55 deletions
diff --git a/src/misc1.c b/src/misc1.c
index 3c0bd4128..4566ca2a9 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -1297,7 +1297,7 @@ f_state(typval_T *argvars, typval_T *rettv)
may_add_state_char(&ga, include, 'o');
if (autocmd_busy)
may_add_state_char(&ga, include, 'x');
- if (!ctrl_x_mode_none())
+ if (ins_compl_active())
may_add_state_char(&ga, include, 'a');
# ifdef FEAT_JOB_CHANNEL
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
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index b354115e1..814a989c8 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -1033,9 +1033,7 @@ endfunc
" Run Vim in a terminal, then start a terminal in that Vim without a kill
" argument, check that :confirm qall works.
func Test_terminal_qall_prompt()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = RunVimInTerminal('', {})
" Open a terminal window and wait for the prompt to appear
@@ -1094,9 +1092,7 @@ func Check_dump01(off)
endfunc
func Test_terminal_dumpwrite_composing()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let save_enc = &encoding
set encoding=utf-8
call assert_equal(1, winnr('$'))
@@ -1219,9 +1215,7 @@ func Api_drop_common(options)
endfunc
func Test_terminal_api_drop_newwin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common('')
call assert_equal(0, &bin)
call assert_equal('', &fenc)
@@ -1232,9 +1226,7 @@ func Test_terminal_api_drop_newwin()
endfunc
func Test_terminal_api_drop_newwin_bin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"bin":1}')
call assert_equal(1, &bin)
@@ -1244,9 +1236,7 @@ func Test_terminal_api_drop_newwin_bin()
endfunc
func Test_terminal_api_drop_newwin_binary()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"binary":1}')
call assert_equal(1, &bin)
@@ -1256,9 +1246,7 @@ func Test_terminal_api_drop_newwin_binary()
endfunc
func Test_terminal_api_drop_newwin_nobin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set binary
let buf = Api_drop_common(',{"nobin":1}')
call assert_equal(0, &bin)
@@ -1270,9 +1258,7 @@ func Test_terminal_api_drop_newwin_nobin()
endfunc
func Test_terminal_api_drop_newwin_nobinary()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set binary
let buf = Api_drop_common(',{"nobinary":1}')
call assert_equal(0, &bin)
@@ -1284,9 +1270,7 @@ func Test_terminal_api_drop_newwin_nobinary()
endfunc
func Test_terminal_api_drop_newwin_ff()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"ff":"dos"}')
call assert_equal("dos", &ff)
@@ -1296,9 +1280,7 @@ func Test_terminal_api_drop_newwin_ff()
endfunc
func Test_terminal_api_drop_newwin_fileformat()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"fileformat":"dos"}')
call assert_equal("dos", &ff)
@@ -1308,9 +1290,7 @@ func Test_terminal_api_drop_newwin_fileformat()
endfunc
func Test_terminal_api_drop_newwin_enc()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"enc":"utf-16"}')
call assert_equal("utf-16", &fenc)
@@ -1320,9 +1300,7 @@ func Test_terminal_api_drop_newwin_enc()
endfunc
func Test_terminal_api_drop_newwin_encoding()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let buf = Api_drop_common(',{"encoding":"utf-16"}')
call assert_equal("utf-16", &fenc)
@@ -1332,9 +1310,7 @@ func Test_terminal_api_drop_newwin_encoding()
endfunc
func Test_terminal_api_drop_oldwin()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
let firstwinid = win_getid()
split Xtextfile
let textfile_winid = win_getid()
@@ -1375,9 +1351,7 @@ func WriteApiCall(funcname)
endfunc
func Test_terminal_api_call()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('Tapi_TryThis')
let buf = RunVimInTerminal('-S Xscript', {})
@@ -1392,9 +1366,7 @@ func Test_terminal_api_call()
endfunc
func Test_terminal_api_call_fails()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('TryThis')
call ch_logfile('Xlog', 'w')
@@ -1418,9 +1390,7 @@ func Tapi_Delete(bufnum, arg)
endfunc
func Test_terminal_api_call_fail_delete()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
call WriteApiCall('Tapi_Delete')
let buf = RunVimInTerminal('-S Xscript', {})
@@ -1513,9 +1483,7 @@ func Test_terminal_ansicolors_func()
endfunc
func Test_terminal_all_ansi_colors()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" Use all the ANSI colors.
call writefile([
@@ -1570,9 +1538,7 @@ func Test_terminal_all_ansi_colors()
endfunc
func Test_terminal_termwinsize_option_fixed()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
set termwinsize=6x40
let text = []
for n in range(10)
@@ -2034,9 +2000,7 @@ func Test_terminal_statusline()
endfunc
func Test_terminal_getwinpos()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" split, go to the bottom-right window
split
diff --git a/src/version.c b/src/version.c
index 576ac2342..2b2474f30 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2066,
+/**/
2065,
/**/
2064,