Skip to content

Commit c258549

Browse files
committed
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.
1 parent 910c378 commit c258549

4 files changed

Lines changed: 81 additions & 55 deletions

File tree

src/misc1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ f_state(typval_T *argvars, typval_T *rettv)
12971297
may_add_state_char(&ga, include, 'o');
12981298
if (autocmd_busy)
12991299
may_add_state_char(&ga, include, 'x');
1300-
if (!ctrl_x_mode_none())
1300+
if (ins_compl_active())
13011301
may_add_state_char(&ga, include, 'a');
13021302

13031303
# ifdef FEAT_JOB_CHANNEL

src/testdir/test_functions.vim

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
" Tests for various functions.
22
source shared.vim
33
source check.vim
4+
source term_util.vim
45

56
" Must be done first, since the alternate buffer must be unset.
67
func Test_00_bufexists()
@@ -1659,3 +1660,62 @@ func Test_bufadd_bufload()
16591660
call assert_equal(0, bufexists('someName'))
16601661
call delete('XotherName')
16611662
endfunc
1663+
1664+
func Test_state()
1665+
CheckRunVimInTerminal
1666+
1667+
let lines =<< trim END
1668+
call setline(1, ['one', 'two', 'three'])
1669+
map ;; gg
1670+
func RunTimer()
1671+
call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')})
1672+
endfunc
1673+
au Filetype foobar let g:state = state()|let g:mode = mode()
1674+
END
1675+
call writefile(lines, 'XState')
1676+
let buf = RunVimInTerminal('-S XState', #{rows: 6})
1677+
1678+
" Using a ":" command Vim is busy, thus "S" is returned
1679+
call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>")
1680+
call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000)
1681+
call term_sendkeys(buf, ":\<CR>")
1682+
1683+
" Using a timer callback
1684+
call term_sendkeys(buf, ":call RunTimer()\<CR>")
1685+
call term_wait(buf, 50)
1686+
let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>"
1687+
call term_sendkeys(buf, getstate)
1688+
call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000)
1689+
1690+
" Halfway a mapping
1691+
call term_sendkeys(buf, ":call RunTimer()\<CR>;")
1692+
call term_wait(buf, 50)
1693+
call term_sendkeys(buf, ";")
1694+
call term_sendkeys(buf, getstate)
1695+
call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000)
1696+
1697+
" Insert mode completion
1698+
call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>")
1699+
call term_wait(buf, 50)
1700+
call term_sendkeys(buf, "\<Esc>")
1701+
call term_sendkeys(buf, getstate)
1702+
call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000)
1703+
1704+
" Autocommand executing
1705+
call term_sendkeys(buf, ":set filetype=foobar\<CR>")
1706+
call term_wait(buf, 50)
1707+
call term_sendkeys(buf, getstate)
1708+
call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000)
1709+
1710+
" Todo: "w" - waiting for ch_evalexpr()
1711+
1712+
" messages scrolled
1713+
call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>")
1714+
call term_wait(buf, 50)
1715+
call term_sendkeys(buf, "\<CR>")
1716+
call term_sendkeys(buf, getstate)
1717+
call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000)
1718+
1719+
call StopVimInTerminal(buf)
1720+
call delete('XState')
1721+
endfunc

src/testdir/test_terminal.vim

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,7 @@ endfunc
10331033
" Run Vim in a terminal, then start a terminal in that Vim without a kill
10341034
" argument, check that :confirm qall works.
10351035
func Test_terminal_qall_prompt()
1036-
if !CanRunVimInTerminal()
1037-
throw 'Skipped: cannot run Vim in a terminal window'
1038-
endif
1036+
CheckRunVimInTerminal
10391037
let buf = RunVimInTerminal('', {})
10401038

10411039
" Open a terminal window and wait for the prompt to appear
@@ -1094,9 +1092,7 @@ func Check_dump01(off)
10941092
endfunc
10951093

10961094
func Test_terminal_dumpwrite_composing()
1097-
if !CanRunVimInTerminal()
1098-
throw 'Skipped: cannot run Vim in a terminal window'
1099-
endif
1095+
CheckRunVimInTerminal
11001096
let save_enc = &encoding
11011097
set encoding=utf-8
11021098
call assert_equal(1, winnr('$'))
@@ -1219,9 +1215,7 @@ func Api_drop_common(options)
12191215
endfunc
12201216

12211217
func Test_terminal_api_drop_newwin()
1222-
if !CanRunVimInTerminal()
1223-
throw 'Skipped: cannot run Vim in a terminal window'
1224-
endif
1218+
CheckRunVimInTerminal
12251219
let buf = Api_drop_common('')
12261220
call assert_equal(0, &bin)
12271221
call assert_equal('', &fenc)
@@ -1232,9 +1226,7 @@ func Test_terminal_api_drop_newwin()
12321226
endfunc
12331227

12341228
func Test_terminal_api_drop_newwin_bin()
1235-
if !CanRunVimInTerminal()
1236-
throw 'Skipped: cannot run Vim in a terminal window'
1237-
endif
1229+
CheckRunVimInTerminal
12381230
let buf = Api_drop_common(',{"bin":1}')
12391231
call assert_equal(1, &bin)
12401232

@@ -1244,9 +1236,7 @@ func Test_terminal_api_drop_newwin_bin()
12441236
endfunc
12451237

12461238
func Test_terminal_api_drop_newwin_binary()
1247-
if !CanRunVimInTerminal()
1248-
throw 'Skipped: cannot run Vim in a terminal window'
1249-
endif
1239+
CheckRunVimInTerminal
12501240
let buf = Api_drop_common(',{"binary":1}')
12511241
call assert_equal(1, &bin)
12521242

@@ -1256,9 +1246,7 @@ func Test_terminal_api_drop_newwin_binary()
12561246
endfunc
12571247

12581248
func Test_terminal_api_drop_newwin_nobin()
1259-
if !CanRunVimInTerminal()
1260-
throw 'Skipped: cannot run Vim in a terminal window'
1261-
endif
1249+
CheckRunVimInTerminal
12621250
set binary
12631251
let buf = Api_drop_common(',{"nobin":1}')
12641252
call assert_equal(0, &bin)
@@ -1270,9 +1258,7 @@ func Test_terminal_api_drop_newwin_nobin()
12701258
endfunc
12711259

12721260
func Test_terminal_api_drop_newwin_nobinary()
1273-
if !CanRunVimInTerminal()
1274-
throw 'Skipped: cannot run Vim in a terminal window'
1275-
endif
1261+
CheckRunVimInTerminal
12761262
set binary
12771263
let buf = Api_drop_common(',{"nobinary":1}')
12781264
call assert_equal(0, &bin)
@@ -1284,9 +1270,7 @@ func Test_terminal_api_drop_newwin_nobinary()
12841270
endfunc
12851271

12861272
func Test_terminal_api_drop_newwin_ff()
1287-
if !CanRunVimInTerminal()
1288-
throw 'Skipped: cannot run Vim in a terminal window'
1289-
endif
1273+
CheckRunVimInTerminal
12901274
let buf = Api_drop_common(',{"ff":"dos"}')
12911275
call assert_equal("dos", &ff)
12921276

@@ -1296,9 +1280,7 @@ func Test_terminal_api_drop_newwin_ff()
12961280
endfunc
12971281

12981282
func Test_terminal_api_drop_newwin_fileformat()
1299-
if !CanRunVimInTerminal()
1300-
throw 'Skipped: cannot run Vim in a terminal window'
1301-
endif
1283+
CheckRunVimInTerminal
13021284
let buf = Api_drop_common(',{"fileformat":"dos"}')
13031285
call assert_equal("dos", &ff)
13041286

@@ -1308,9 +1290,7 @@ func Test_terminal_api_drop_newwin_fileformat()
13081290
endfunc
13091291

13101292
func Test_terminal_api_drop_newwin_enc()
1311-
if !CanRunVimInTerminal()
1312-
throw 'Skipped: cannot run Vim in a terminal window'
1313-
endif
1293+
CheckRunVimInTerminal
13141294
let buf = Api_drop_common(',{"enc":"utf-16"}')
13151295
call assert_equal("utf-16", &fenc)
13161296

@@ -1320,9 +1300,7 @@ func Test_terminal_api_drop_newwin_enc()
13201300
endfunc
13211301

13221302
func Test_terminal_api_drop_newwin_encoding()
1323-
if !CanRunVimInTerminal()
1324-
throw 'Skipped: cannot run Vim in a terminal window'
1325-
endif
1303+
CheckRunVimInTerminal
13261304
let buf = Api_drop_common(',{"encoding":"utf-16"}')
13271305
call assert_equal("utf-16", &fenc)
13281306

@@ -1332,9 +1310,7 @@ func Test_terminal_api_drop_newwin_encoding()
13321310
endfunc
13331311

13341312
func Test_terminal_api_drop_oldwin()
1335-
if !CanRunVimInTerminal()
1336-
throw 'Skipped: cannot run Vim in a terminal window'
1337-
endif
1313+
CheckRunVimInTerminal
13381314
let firstwinid = win_getid()
13391315
split Xtextfile
13401316
let textfile_winid = win_getid()
@@ -1375,9 +1351,7 @@ func WriteApiCall(funcname)
13751351
endfunc
13761352

13771353
func Test_terminal_api_call()
1378-
if !CanRunVimInTerminal()
1379-
throw 'Skipped: cannot run Vim in a terminal window'
1380-
endif
1354+
CheckRunVimInTerminal
13811355

13821356
call WriteApiCall('Tapi_TryThis')
13831357
let buf = RunVimInTerminal('-S Xscript', {})
@@ -1392,9 +1366,7 @@ func Test_terminal_api_call()
13921366
endfunc
13931367

13941368
func Test_terminal_api_call_fails()
1395-
if !CanRunVimInTerminal()
1396-
throw 'Skipped: cannot run Vim in a terminal window'
1397-
endif
1369+
CheckRunVimInTerminal
13981370

13991371
call WriteApiCall('TryThis')
14001372
call ch_logfile('Xlog', 'w')
@@ -1418,9 +1390,7 @@ func Tapi_Delete(bufnum, arg)
14181390
endfunc
14191391

14201392
func Test_terminal_api_call_fail_delete()
1421-
if !CanRunVimInTerminal()
1422-
throw 'Skipped: cannot run Vim in a terminal window'
1423-
endif
1393+
CheckRunVimInTerminal
14241394

14251395
call WriteApiCall('Tapi_Delete')
14261396
let buf = RunVimInTerminal('-S Xscript', {})
@@ -1513,9 +1483,7 @@ func Test_terminal_ansicolors_func()
15131483
endfunc
15141484

15151485
func Test_terminal_all_ansi_colors()
1516-
if !CanRunVimInTerminal()
1517-
throw 'Skipped: cannot run Vim in a terminal window'
1518-
endif
1486+
CheckRunVimInTerminal
15191487

15201488
" Use all the ANSI colors.
15211489
call writefile([
@@ -1570,9 +1538,7 @@ func Test_terminal_all_ansi_colors()
15701538
endfunc
15711539

15721540
func Test_terminal_termwinsize_option_fixed()
1573-
if !CanRunVimInTerminal()
1574-
throw 'Skipped: cannot run Vim in a terminal window'
1575-
endif
1541+
CheckRunVimInTerminal
15761542
set termwinsize=6x40
15771543
let text = []
15781544
for n in range(10)
@@ -2034,9 +2000,7 @@ func Test_terminal_statusline()
20342000
endfunc
20352001

20362002
func Test_terminal_getwinpos()
2037-
if !CanRunVimInTerminal()
2038-
throw 'Skipped: cannot run Vim in a terminal window'
2039-
endif
2003+
CheckRunVimInTerminal
20402004

20412005
" split, go to the bottom-right window
20422006
split

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ static char *(features[]) =
757757

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
2066,
760762
/**/
761763
2065,
762764
/**/

0 commit comments

Comments
 (0)