Skip to content

Commit 8d588cc

Browse files
committed
patch 8.2.0316: ex_getln.c code has insufficient test coverage
Problem: ex_getln.c code has insufficient test coverage. Solution: Add more tests. Fix a problem. (Yegappan Lakshmanan, closes #5693)
1 parent c593bec commit 8d588cc

6 files changed

Lines changed: 163 additions & 1 deletion

File tree

src/cmdhist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ calc_hist_idx(int histype, int num)
389389
i += hislen;
390390
wrapped = TRUE;
391391
}
392-
if (hist[i].hisnum == num && hist[i].hisstr != NULL)
392+
if (i >= 0 && hist[i].hisnum == num && hist[i].hisstr != NULL)
393393
return i;
394394
}
395395
else if (-num <= hislen)

src/testdir/test_cmdline.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func Test_complete_wildmenu()
5151
call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
5252
call assert_equal('testfile1', getline(1))
5353

54+
" Completion using a relative path
55+
cd Xdir1/Xdir2
56+
call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
57+
call assert_equal('"e Xtestfile3 Xtestfile4', @:)
58+
cd -
59+
5460
" cleanup
5561
%bwipe
5662
call delete('Xdir1/Xdir2/Xtestfile4')
@@ -456,6 +462,10 @@ func Test_cmdline_paste()
456462
" ignore error E32
457463
endtry
458464
call assert_equal("Xtestfile", bufname("%"))
465+
466+
" Use an invalid expression for <C-\>e
467+
call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
468+
459469
bwipe!
460470
endfunc
461471

@@ -690,6 +700,8 @@ func Test_getcmdtype()
690700
cnoremap <expr> <F6> Check_cmdline('=')
691701
call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
692702
cunmap <F6>
703+
704+
call assert_equal('', getcmdline())
693705
endfunc
694706

695707
func Test_getcmdwintype()
@@ -930,6 +942,22 @@ func Test_cmdwin_cedit()
930942
delfunc CmdWinType
931943
endfunc
932944

945+
" Test for CmdwinEnter autocmd
946+
func Test_cmdwin_autocmd()
947+
augroup CmdWin
948+
au!
949+
autocmd CmdwinEnter * startinsert
950+
augroup END
951+
952+
call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
953+
call assert_equal('xyz', @:)
954+
955+
augroup CmdWin
956+
au!
957+
augroup END
958+
augroup! CmdWin
959+
endfunc
960+
933961
func Test_cmdlineclear_tabenter()
934962
CheckScreendump
935963

@@ -967,6 +995,10 @@ func Test_cmdwin_jump_to_win()
967995
call assert_equal(1, winnr('$'))
968996
call feedkeys("q/:exit\<CR>", "xt")
969997
call assert_equal(1, winnr('$'))
998+
999+
" opening command window twice should fail
1000+
call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1001+
call assert_equal(1, winnr('$'))
9701002
endfunc
9711003

9721004
" Test for backtick expression in the command line
@@ -1006,4 +1038,19 @@ func Test_cmd_bang()
10061038
call delete('Xresult')
10071039
endfunc
10081040

1041+
" Test for using ~ for home directory in cmdline completion matches
1042+
func Test_cmdline_expand_home()
1043+
call mkdir('Xdir')
1044+
call writefile([], 'Xdir/Xfile1')
1045+
call writefile([], 'Xdir/Xfile2')
1046+
cd Xdir
1047+
let save_HOME = $HOME
1048+
let $HOME = getcwd()
1049+
call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
1050+
call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
1051+
let $HOME = save_HOME
1052+
cd ..
1053+
call delete('Xdir', 'rf')
1054+
endfunc
1055+
10091056
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_functions.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,30 @@ func Test_col()
11411141
bw!
11421142
endfunc
11431143

1144+
" Test for input()
1145+
func Test_input_func()
1146+
" Test for prompt with multiple lines
1147+
redir => v
1148+
call feedkeys(":let c = input(\"A\\nB\\nC\\n? \")\<CR>B\<CR>", 'xt')
1149+
redir END
1150+
call assert_equal("B", c)
1151+
call assert_equal(['A', 'B', 'C'], split(v, "\n"))
1152+
1153+
" Test for default value
1154+
call feedkeys(":let c = input('color? ', 'red')\<CR>\<CR>", 'xt')
1155+
call assert_equal('red', c)
1156+
1157+
" Test for completion at the input prompt
1158+
func! Tcomplete(arglead, cmdline, pos)
1159+
return "item1\nitem2\nitem3"
1160+
endfunc
1161+
call feedkeys(":let c = input('Q? ', '' , 'custom,Tcomplete')\<CR>"
1162+
\ .. "\<C-A>\<CR>", 'xt')
1163+
delfunc Tcomplete
1164+
call assert_equal('item1 item2 item3', c)
1165+
endfunc
1166+
1167+
" Test for inputlist()
11441168
func Test_inputlist()
11451169
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx')
11461170
call assert_equal(1, c)
@@ -2034,3 +2058,5 @@ func Test_echoraw()
20342058
call StopVimInTerminal(buf)
20352059
call delete('XTest_echoraw')
20362060
endfunc
2061+
2062+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_history.vim

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function Test_History()
8585
call assert_fails('call histget([])', 'E730:')
8686
call assert_equal(-1, histnr('abc'))
8787
call assert_fails('call histnr([])', 'E730:')
88+
call assert_fails('history xyz', 'E488:')
89+
call assert_fails('history ,abc', 'E488:')
8890
endfunction
8991

9092
function Test_Search_history_window()
@@ -108,3 +110,52 @@ function Test_history_completion()
108110
call feedkeys(":history \<C-A>\<C-B>\"\<CR>", 'tx')
109111
call assert_equal('"history / : = > ? @ all cmd debug expr input search', @:)
110112
endfunc
113+
114+
" Test for increasing the 'history' option value
115+
func Test_history_size()
116+
let save_histsz = &history
117+
call histdel(':')
118+
set history=5
119+
for i in range(1, 5)
120+
call histadd(':', 'cmd' .. i)
121+
endfor
122+
call assert_equal(5, histnr(':'))
123+
call assert_equal('cmd5', histget(':', -1))
124+
125+
set history=10
126+
for i in range(6, 10)
127+
call histadd(':', 'cmd' .. i)
128+
endfor
129+
call assert_equal(10, histnr(':'))
130+
call assert_equal('cmd1', histget(':', 1))
131+
call assert_equal('cmd10', histget(':', -1))
132+
133+
set history=5
134+
call histadd(':', 'abc')
135+
call assert_equal('', histget(':', 6))
136+
call assert_equal('', histget(':', 12))
137+
call assert_equal('cmd7', histget(':', 7))
138+
call assert_equal('abc', histget(':', -1))
139+
140+
let &history=save_histsz
141+
endfunc
142+
143+
" Test for recalling old search patterns in /
144+
func Test_history_search()
145+
call histdel('/')
146+
let g:pat = []
147+
func SavePat()
148+
call add(g:pat, getcmdline())
149+
return ''
150+
endfunc
151+
cnoremap <F2> <C-\>eSavePat()<CR>
152+
call histadd('/', 'pat1')
153+
call histadd('/', 'pat2')
154+
let @/ = ''
155+
call feedkeys("/\<Up>\<F2>\<Up>\<F2>\<Down>\<Down>\<F2>\<Esc>", 'xt')
156+
call assert_equal(['pat2', 'pat1', ''], g:pat)
157+
cunmap <F2>
158+
delfunc SavePat
159+
endfunc
160+
161+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_menu.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,39 @@ func Test_menu_commands()
8888

8989
unlet g:did_menu
9090
endfun
91+
92+
" Test for menu item completion in command line
93+
func Test_menu_expand()
94+
" Create the menu itmes for test
95+
for i in range(1, 4)
96+
let m = 'menu Xmenu.A' .. i .. '.A' .. i
97+
for j in range(1, 4)
98+
exe m .. 'B' .. j .. ' :echo "A' .. i .. 'B' .. j .. '"' .. "<CR>"
99+
endfor
100+
endfor
101+
set wildmenu
102+
103+
" Test for <CR> selecting a submenu
104+
call feedkeys(":emenu Xmenu.A\<Tab>\<CR>\<Right>x\<BS>\<C-B>\"\<CR>", 'xt')
105+
call assert_equal('"emenu Xmenu.A1.A1B2', @:)
106+
107+
" Test for <Down> selecting a submenu
108+
call feedkeys(":emenu Xmenu.A\<Tab>\<Right>\<Right>\<Down>" ..
109+
\ "\<C-A>\<C-B>\"\<CR>", 'xt')
110+
call assert_equal('"emenu Xmenu.A3.A3B1 A3B2 A3B3 A3B4', @:)
111+
112+
" Test for <Up> to go up a submenu
113+
call feedkeys(":emenu Xmenu.A\<Tab>\<Down>\<Up>\<Right>\<Right>" ..
114+
\ "\<Left>\<Down>\<C-A>\<C-B>\"\<CR>", 'xt')
115+
call assert_equal('"emenu Xmenu.A2.A2B1 A2B2 A2B3 A2B4', @:)
116+
117+
" Test for <Up> to go up a menu
118+
call feedkeys(":emenu Xmenu.A\<Tab>\<Down>\<Up>\<Up>\<Up>" ..
119+
\ "\<C-A>\<C-B>\"\<CR>", 'xt')
120+
call assert_equal('"emenu Buffers. Xmenu.', @:)
121+
122+
set wildmenu&
123+
unmenu Xmenu
124+
endfunc
125+
126+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
316,
741743
/**/
742744
315,
743745
/**/

0 commit comments

Comments
 (0)