diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-27 15:00:36 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-27 15:00:36 +0100 |
commit | 2e0500921891e4fec57e97d3c0021aa2d2b4d7ae (patch) | |
tree | ce0c7e1272e908894f796205fd363537dd2e26c0 | |
parent | 0eb220c03057096a26dda9c5544b362dce6df4d7 (diff) |
patch 8.1.0832: confirm() is not testedv8.1.0832
Problem: confirm() is not tested.
Solution: Add a test. (Dominique Pelle, closes #3868)
-rw-r--r-- | src/testdir/test_functions.vim | 55 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index 3d8104817d..ceb8486927 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -1153,3 +1153,58 @@ func Test_func_exists_on_reload() call delete('Xfuncexists') delfunc ExistingFunction endfunc + +" Test confirm({msg} [, {choices} [, {default} [, {type}]]]) +func Test_confirm() + if !has('unix') || has('gui_running') + return + endif + + call feedkeys('o', 'L') + let a = confirm('Press O to proceed') + call assert_equal(1, a) + + call feedkeys('y', 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(1, a) + + call feedkeys('n', 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(2, a) + + " confirm() should return 0 when pressing CTRL-C. + call feedkeys("\<C-c>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(0, a) + + " <Esc> requires another character to avoid it being seen as the start of an + " escape sequence. Zero should be harmless. + call feedkeys("\<Esc>0", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(0, a) + + " Default choice is returned when pressing <CR>. + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(1, a) + + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No", 2) + call assert_equal(2, a) + + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No", 0) + call assert_equal(0, a) + + " Test with the {type} 4th argument + for type in ['Error', 'Question', 'Info', 'Warning', 'Generic'] + call feedkeys('y', 'L') + let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type) + call assert_equal(1, a) + endfor + + call assert_fails('call confirm([])', 'E730:') + call assert_fails('call confirm("Are you sure?", [])', 'E730:') + call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:') + call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:') +endfunc diff --git a/src/version.c b/src/version.c index 1e5f7e3b6e..fc8fe1b29d 100644 --- a/src/version.c +++ b/src/version.c @@ -784,6 +784,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 832, +/**/ 831, /**/ 830, |