From f7c6676199f222162dc4ec448857ac64faa26f87 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Jul 2022 20:35:07 +0800 Subject: vim-patch:8.2.0052: more-prompt not properly tested Problem: More-prompt not properly tested. Solution: Add a test case. (Dominique Pelle, closes vim/vim#5404) https://github.com/vim/vim/commit/c6d539b67181ad573452e919e58ecbfa362f4c49 --- src/nvim/testdir/test_messages.vim | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 8be0c79499..6954b4bc91 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -112,6 +112,101 @@ func Test_echospace() set ruler& showcmd& endfunc +" Test more-prompt (see :help more-prompt). +func Test_message_more() + if !CanRunVimInTerminal() + throw 'Skipped: cannot run vim in terminal' + endif + let buf = RunVimInTerminal('', {'rows': 6}) + call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") + + call term_sendkeys(buf, ":%p#\n") + call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + + call term_sendkeys(buf, '?') + call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))}) + + " Down a line with j, , or . + call term_sendkeys(buf, "j") + call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))}) + + " Down a screen with , f, or . + call term_sendkeys(buf, 'f') + call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + call term_sendkeys(buf, ' ') + call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))}) + + " Down a page (half a screen) with d. + call term_sendkeys(buf, 'd') + call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))}) + + " Down all the way with 'G'. + call term_sendkeys(buf, 'G') + call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) + + " Up a line k, or . + call term_sendkeys(buf, 'k') + call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))}) + + " Up a screen with b or . + call term_sendkeys(buf, 'b') + call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))}) + + " Up a page (half a screen) with u. + call term_sendkeys(buf, 'u') + call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))}) + + " Up all the way with 'g'. + call term_sendkeys(buf, 'g') + call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + + " All the way down. Pressing f should do nothing but pressing + " space should end the more prompt. + call term_sendkeys(buf, 'G') + call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) + call term_sendkeys(buf, 'f') + call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) + call term_sendkeys(buf, ' ') + call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) + + " Pressing g< shows the previous command output. + call term_sendkeys(buf, 'g<') + call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) + + call term_sendkeys(buf, ":%p#\n") + call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + + " Stop command output with q, or CTRL-C. + call term_sendkeys(buf, 'q') + call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) + + call term_sendkeys(buf, ':q!') + call StopVimInTerminal(buf) +endfunc + func Test_mapping_at_hit_return_prompt() nnoremap :echo "hit ctrl-b" call feedkeys(":ls\", "xt") -- cgit From bc73795a5858129a84d510f682c9dcb17aa1813a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Jul 2022 21:14:54 +0800 Subject: vim-patch:8.2.0198: no tests for y/n prompt Problem: No tests for y/n prompt. Solution: Add tests. (Dominique Pelle, closes vim/vim#5564) https://github.com/vim/vim/commit/43c60eda2aa22ba3d7aaf418cfbdb75f1a008e67 --- src/nvim/testdir/test_messages.vim | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 6954b4bc91..fb6c9c1554 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -203,7 +203,37 @@ func Test_message_more() call term_sendkeys(buf, 'q') call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) - call term_sendkeys(buf, ':q!') + call term_sendkeys(buf, ":q!\n") + call StopVimInTerminal(buf) +endfunc + +func Test_ask_yesno() + if !CanRunVimInTerminal() + throw 'Skipped: cannot run vim in terminal' + endif + let buf = RunVimInTerminal('', {'rows': 6}) + call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") + + call term_sendkeys(buf, ":2,1s/^/n/\n") + call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) + call term_sendkeys(buf, "n") + call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) + call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) + + call term_sendkeys(buf, ":2,1s/^/Esc/\n") + call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) + call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) + + call term_sendkeys(buf, ":2,1s/^/y/\n") + call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) + call term_sendkeys(buf, "y") + call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))}) + call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) + call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) + + call term_sendkeys(buf, ":q!\n") call StopVimInTerminal(buf) endfunc -- cgit From 780edfc0eb1293f5813d904ad61fc65bbbb41784 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Jul 2022 21:39:05 +0800 Subject: vim-patch:8.2.2608: character input not fully tested Problem: Character input not fully tested. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#7963) https://github.com/vim/vim/commit/f4fcedc59d4cc5ae6b5270a933e8377030283c1c Cherry-pick related changes from patches 8.2.{0433,0866}. --- src/nvim/testdir/test_messages.vim | 21 +++++++++++++-------- src/nvim/testdir/test_registers.vim | 10 ++++++++++ src/nvim/testdir/test_undo.vim | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index fb6c9c1554..5670368936 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -114,9 +114,7 @@ endfunc " Test more-prompt (see :help more-prompt). func Test_message_more() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let buf = RunVimInTerminal('', {'rows': 6}) call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") @@ -203,14 +201,22 @@ func Test_message_more() call term_sendkeys(buf, 'q') call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) - call term_sendkeys(buf, ":q!\n") + " Execute a : command from the more prompt + call term_sendkeys(buf, ":%p#\n") + call term_wait(buf) + call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) + call term_sendkeys(buf, ":") + call term_wait(buf) + call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))}) + call term_sendkeys(buf, "echo 'Hello'\n") + call term_wait(buf) + call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))}) + call StopVimInTerminal(buf) endfunc func Test_ask_yesno() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let buf = RunVimInTerminal('', {'rows': 6}) call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") @@ -233,7 +239,6 @@ func Test_ask_yesno() call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) - call term_sendkeys(buf, ":q!\n") call StopVimInTerminal(buf) endfunc diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index abe28b77cd..52e745438d 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -684,6 +684,16 @@ func Test_insert_small_delete() bwipe! endfunc +" Record in insert mode using CTRL-O +func Test_record_in_insert_mode() + new + let @r = '' + call setline(1, ['foo']) + call feedkeys("i\qrbaz\q", 'xt') + call assert_equal('baz', @r) + bwipe! +endfunc + func Test_record_in_select_mode() new call setline(1, 'text') diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index da8bf12318..efc39fb3f5 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -735,6 +735,20 @@ func Test_undofile_cryptmethod_blowfish2() set undofile& undolevels& cryptmethod& endfunc +" Test for redoing with incrementing numbered registers +func Test_redo_repeat_numbered_register() + new + for [i, v] in [[1, 'one'], [2, 'two'], [3, 'three'], + \ [4, 'four'], [5, 'five'], [6, 'six'], + \ [7, 'seven'], [8, 'eight'], [9, 'nine']] + exe 'let @' .. i .. '="' .. v .. '\n"' + endfor + call feedkeys('"1p.........', 'xt') + call assert_equal(['', 'one', 'two', 'three', 'four', 'five', 'six', + \ 'seven', 'eight', 'nine', 'nine'], getline(1, '$')) + bwipe! +endfunc + func Test_undo_mark() new " The undo is applied to the only line. -- cgit From 0cfd4fa8f3dc2241de5f69d5c52510542dfc927c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Jul 2022 21:56:47 +0800 Subject: vim-patch:8.2.2643: various code not covered by tests Problem: Various code not covered by tests. Solution: Add a few more test. (Yegappan Lakshmanan, closes vim/vim#7995) https://github.com/vim/vim/commit/1f448d906b3c516e5864dc5bae3ddbf3664ee649 Cherry-pick some test_edit.vim changes from patches 8.2.{1022,1432}. Reorder test_undo.vim to match upstream. --- src/nvim/testdir/test_edit.vim | 39 ++++++++++- src/nvim/testdir/test_mapping.vim | 10 +++ src/nvim/testdir/test_termcodes.vim | 34 ++++++++++ src/nvim/testdir/test_undo.vim | 127 +++++++++++++++++++----------------- 4 files changed, 147 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 65194f49dd..69a34a1c51 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -420,16 +420,49 @@ func Test_edit_13() call assert_equal("", getline(2)) call assert_equal(" baz", getline(3)) set autoindent& + + " pressing to erase line should keep the indent with 'autoindent' + set backspace=2 autoindent + %d + exe "normal i\tone\three\two" + call assert_equal(["\tone", "\ttwo"], getline(1, '$')) + set backspace& autoindent& + bwipe! endfunc +" Test for autoindent removing indent when insert mode is stopped. Some parts +" of the code is exercised only when interactive mode is used. So use Vim in a +" terminal. +func Test_autoindent_remove_indent() + CheckRunVimInTerminal + let buf = RunVimInTerminal('-N Xfile', {'rows': 6, 'cols' : 20}) + call TermWait(buf) + call term_sendkeys(buf, ":set autoindent\n") + " leaving insert mode in a new line with indent added by autoindent, should + " remove the indent. + call term_sendkeys(buf, "i\foo\\") + " Need to delay for sometime, otherwise the code in getchar.c will not be + " exercised. + call TermWait(buf, 50) + " when a line is wrapped and the cursor is at the start of the second line, + " leaving insert mode, should move the cursor back to the first line. + call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\") + " Need to delay for sometime, otherwise the code in getchar.c will not be + " exercised. + call TermWait(buf, 50) + call term_sendkeys(buf, ":w\n") + call TermWait(buf) + call StopVimInTerminal(buf) + call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xfile')) + call delete('Xfile') +endfunc + func Test_edit_CR() " Test for in insert mode " basically only in quickfix mode ist tested, the rest " has been taken care of by other tests - if !has("quickfix") - return - endif + CheckFeature quickfix botright new call writefile(range(1, 10), 'Xqflist.txt') call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index a34a950526..e1d0b9a9ba 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -956,6 +956,16 @@ func Test_map_cmdkey_redo() ounmap i- endfunc +" Test for using