comparison src/testdir/test_functions.vim @ 15649:e649df212461 v8.1.0832

patch 8.1.0832: confirm() is not tested commit https://github.com/vim/vim/commit/2e0500921891e4fec57e97d3c0021aa2d2b4d7ae Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 27 15:00:36 2019 +0100 patch 8.1.0832: confirm() is not tested Problem: confirm() is not tested. Solution: Add a test. (Dominique Pelle, closes https://github.com/vim/vim/issues/3868)
author Bram Moolenaar <Bram@vim.org>
date Sun, 27 Jan 2019 15:15:05 +0100
parents 2dcaa860e3fc
children 772e72b046a3
comparison
equal deleted inserted replaced
15648:bd85af35d3e1 15649:e649df212461
1151 1151
1152 call delete('Xfuncexists2') 1152 call delete('Xfuncexists2')
1153 call delete('Xfuncexists') 1153 call delete('Xfuncexists')
1154 delfunc ExistingFunction 1154 delfunc ExistingFunction
1155 endfunc 1155 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