Skip to content

Commit 2e05009

Browse files
committed
patch 8.1.0832: confirm() is not tested
Problem: confirm() is not tested. Solution: Add a test. (Dominique Pelle, closes #3868)
1 parent 0eb220c commit 2e05009

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/testdir/test_functions.vim

+55
Original file line numberDiff line numberDiff line change
@@ -1153,3 +1153,58 @@ func Test_func_exists_on_reload()
11531153
call delete('Xfuncexists')
11541154
delfunc ExistingFunction
11551155
endfunc
1156+
1157+
" Test confirm({msg} [, {choices} [, {default} [, {type}]]])
1158+
func Test_confirm()
1159+
if !has('unix') || has('gui_running')
1160+
return
1161+
endif
1162+
1163+
call feedkeys('o', 'L')
1164+
let a = confirm('Press O to proceed')
1165+
call assert_equal(1, a)
1166+
1167+
call feedkeys('y', 'L')
1168+
let a = confirm('Are you sure?', "&Yes\n&No")
1169+
call assert_equal(1, a)
1170+
1171+
call feedkeys('n', 'L')
1172+
let a = confirm('Are you sure?', "&Yes\n&No")
1173+
call assert_equal(2, a)
1174+
1175+
" confirm() should return 0 when pressing CTRL-C.
1176+
call feedkeys("\<C-c>", 'L')
1177+
let a = confirm('Are you sure?', "&Yes\n&No")
1178+
call assert_equal(0, a)
1179+
1180+
" <Esc> requires another character to avoid it being seen as the start of an
1181+
" escape sequence. Zero should be harmless.
1182+
call feedkeys("\<Esc>0", 'L')
1183+
let a = confirm('Are you sure?', "&Yes\n&No")
1184+
call assert_equal(0, a)
1185+
1186+
" Default choice is returned when pressing <CR>.
1187+
call feedkeys("\<CR>", 'L')
1188+
let a = confirm('Are you sure?', "&Yes\n&No")
1189+
call assert_equal(1, a)
1190+
1191+
call feedkeys("\<CR>", 'L')
1192+
let a = confirm('Are you sure?', "&Yes\n&No", 2)
1193+
call assert_equal(2, a)
1194+
1195+
call feedkeys("\<CR>", 'L')
1196+
let a = confirm('Are you sure?', "&Yes\n&No", 0)
1197+
call assert_equal(0, a)
1198+
1199+
" Test with the {type} 4th argument
1200+
for type in ['Error', 'Question', 'Info', 'Warning', 'Generic']
1201+
call feedkeys('y', 'L')
1202+
let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type)
1203+
call assert_equal(1, a)
1204+
endfor
1205+
1206+
call assert_fails('call confirm([])', 'E730:')
1207+
call assert_fails('call confirm("Are you sure?", [])', 'E730:')
1208+
call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:')
1209+
call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:')
1210+
endfunc

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ static char *(features[]) =
783783

784784
static int included_patches[] =
785785
{ /* Add new patch number below this line */
786+
/**/
787+
832,
786788
/**/
787789
831,
788790
/**/

0 commit comments

Comments
 (0)