diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-03-08 05:13:15 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-03-08 05:13:15 +0100 |
commit | f5f1e10d0d39890298cdf27f664d466c8872b87e (patch) | |
tree | 5485b5ec47d1236a14e2db3dc0fecc87d6e7ce5d /src/testdir | |
parent | d0d440f702d1c6fef36386f8b91d074d0f3e4718 (diff) |
patch 8.2.0363: some Normal mode commands not testedv8.2.0363
Problem: Some Normal mode commands not tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes #5746)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_cindent.vim | 11 | ||||
-rw-r--r-- | src/testdir/test_cmdline.vim | 10 | ||||
-rw-r--r-- | src/testdir/test_edit.vim | 14 | ||||
-rw-r--r-- | src/testdir/test_indent.vim | 42 | ||||
-rw-r--r-- | src/testdir/test_normal.vim | 164 | ||||
-rw-r--r-- | src/testdir/test_prompt_buffer.vim | 12 | ||||
-rw-r--r-- | src/testdir/test_virtualedit.vim | 3 | ||||
-rw-r--r-- | src/testdir/test_visual.vim | 63 |
8 files changed, 294 insertions, 25 deletions
diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim index dfafd01786..9258192897 100644 --- a/src/testdir/test_cindent.vim +++ b/src/testdir/test_cindent.vim @@ -5258,9 +5258,18 @@ func Test_cindent_case() set cindent norm! f:a: call assert_equal('case x:: // x', getline(1)) - set cindent& bwipe! endfunc +" Test for changing multiple lines (using c) with cindent +func Test_cindent_change_multline() + new + setlocal cindent + call setline(1, ['if (a)', '{', ' i = 1;', '}']) + normal! jc3jm = 2; + call assert_equal("\tm = 2;", getline(2)) + close! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index dfd7fa8eda..610f91e8b3 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -1316,4 +1316,14 @@ func Test_cmdline_composing_chars() call assert_equal('"ゔ', @:) endfunc +" Test for normal mode commands not supported in the cmd window +func Test_cmdwin_blocked_commands() + call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') + call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') + call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') + call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') + call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') + call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim index eef22d49c2..9d2d0f34ac 100644 --- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -265,6 +265,10 @@ func Test_edit_10() call cursor(1, 4) call feedkeys("A\<s-home>start\<esc>", 'txin') call assert_equal(['startdef', 'ghi'], getline(1, '$')) + " start select mode again with gv + set selectmode=cmd + call feedkeys('gvabc', 'xt') + call assert_equal('abctdef', getline(1)) set selectmode= keymodel= bw! endfunc @@ -1263,6 +1267,16 @@ func Test_edit_forbidden() catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function endtry au! InsertCharPre + " Not allowed to enter ex mode when text is locked + au InsertCharPre <buffer> :normal! gQ<CR> + let caught_e523 = 0 + try + call feedkeys("ix\<esc>", 'xt') + catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 + let caught_e523 = 1 + endtry + call assert_equal(1, caught_e523) + au! InsertCharPre " 3) edit when completion is shown fun! Complete(findstart, base) if a:findstart diff --git a/src/testdir/test_indent.vim b/src/testdir/test_indent.vim index 91e801a64a..42743a6556 100644 --- a/src/testdir/test_indent.vim +++ b/src/testdir/test_indent.vim @@ -98,4 +98,46 @@ func Test_copyindent() close! endfunc +" Test for changing multiple lines with lisp indent +func Test_lisp_indent_change_multiline() + new + setlocal lisp autoindent + call setline(1, ['(if a', ' (if b', ' (return 5)))']) + normal! jc2j(return 4)) + call assert_equal(' (return 4))', getline(2)) + close! +endfunc + +func Test_lisp_indent() + new + setlocal lisp autoindent + call setline(1, ['(if a', ' ;; comment', ' \ abc', '', ' " str1\', ' " st\b', ' (return 5)']) + normal! jo;; comment + normal! jo\ abc + normal! jo;; ret + normal! jostr1" + normal! jostr2" + call assert_equal([' ;; comment', ' ;; comment', ' \ abc', ' \ abc', '', ' ;; ret', ' " str1\', ' str1"', ' " st\b', ' str2"'], getline(2, 11)) + close! +endfunc + +" Test for setting the 'indentexpr' from a modeline +func Test_modeline_indent_expr() + let modeline = &modeline + set modeline + func GetIndent() + return line('.') * 2 + endfunc + call writefile(['# vim: indentexpr=GetIndent()'], 'Xfile.txt') + set modelineexpr + new Xfile.txt + call assert_equal('GetIndent()', &indentexpr) + exe "normal Oa\nb\n" + call assert_equal([' a', ' b'], getline(1, 2)) + set modelineexpr& + delfunc GetIndent + let &modeline = modeline + close! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim index 35d5d5fa72..6c2c6296c6 100644 --- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -115,8 +115,8 @@ func Test_normal01_keymodel() bw! endfunc +" Test for select mode func Test_normal02_selectmode() - " some basic select mode tests call Setup_NewWindow() 50 norm! gHy @@ -439,8 +439,12 @@ func Test_normal12_nv_error() 10new call setline(1, range(1,5)) " should not do anything, just beep - exe "norm! <c-k>" + call assert_beeps('exe "norm! <c-k>"') call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) + call assert_beeps('normal! G2dd') + call assert_beeps("normal! g\<C-A>") + call assert_beeps("normal! g\<C-X>") + call assert_beeps("normal! g\<C-B>") bw! endfunc @@ -1628,6 +1632,14 @@ fun! Test_normal30_changecase() throw 'Skipped: Turkish locale not available' endtry + call setline(1, ['aaaaaa', 'aaaaaa']) + normal! gg10~ + call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2)) + set whichwrap+=~ + normal! gg10~ + call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2)) + set whichwrap& + " clean up bw! endfunc @@ -1657,8 +1669,8 @@ fun! Test_normal31_r_cmd() bw! endfunc +" Test for g*, g# func Test_normal32_g_cmd1() - " Test for g*, g# new call append(0, ['abc.x_foo', 'x_foobar.abc']) 1 @@ -1673,11 +1685,12 @@ func Test_normal32_g_cmd1() bw! endfunc +" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, +" gi and gI commands fun! Test_normal33_g_cmd2() if !has("jumplist") return endif - " Tests for g cmds call Setup_NewWindow() " Test for g` clearjumps @@ -1689,6 +1702,10 @@ fun! Test_normal33_g_cmd2() call assert_equal('>', a[-1:]) call assert_equal(1, line('.')) call assert_equal('1', getline('.')) + call cursor(10, 1) + norm! g'a + call assert_equal('>', a[-1:]) + call assert_equal(1, line('.')) " Test for g; and g, norm! g; @@ -1730,6 +1747,12 @@ fun! Test_normal33_g_cmd2() exe "norm! G0\<c-v>4k4ly" exe "norm! gvood" call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) + " gv cannot be used in operator pending mode + call assert_beeps('normal! cgv') + " gv should beep without a previously selected visual area + new + call assert_beeps('normal! gv') + close " Test for gk/gj %d @@ -1770,8 +1793,17 @@ fun! Test_normal33_g_cmd2() norm! g^yl call assert_equal(15, col('.')) call assert_equal('l', getreg(0)) + call assert_beeps('normal 5g$') + + " Test for g_ + call assert_beeps('normal! 100g_') + call setline(2, [' foo ', ' foobar ']) + normal! 2ggg_ + call assert_equal(5, col('.')) + normal! 2g_ + call assert_equal(8, col('.')) - norm! 2ggdd + norm! 2ggdG $put =lineC " Test for gM @@ -1805,11 +1837,23 @@ fun! Test_normal33_g_cmd2() $put ='third line' norm! gi another word call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) + call setline(1, 'foobar') + normal! Ggifirst line + call assert_equal('foobarfirst line', getline(1)) + " Test gi in 'virtualedit' mode with cursor after the end of the line + set virtualedit=all + call setline(1, 'foo') + exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" + call setline(1, 'foo') + normal! Ggifirst line + call assert_equal('foo first line', getline(1)) + set virtualedit& " clean up bw! endfunc +" Test for g CTRL-G func Test_g_ctrl_g() new @@ -1883,8 +1927,8 @@ func Test_g_ctrl_g() bwipe! endfunc +" Test for g8 fun! Test_normal34_g_cmd3() - " Test for g8 new let a=execute(':norm! 1G0g8') call assert_equal("\nNUL", a) @@ -1901,11 +1945,10 @@ fun! Test_normal34_g_cmd3() bw! endfunc +" Test 8g8 which finds invalid utf8 at or after the cursor. func Test_normal_8g8() new - " Test 8g8 which finds invalid utf8 at or after the cursor. - " With invalid byte. call setline(1, "___\xff___") norm! 1G08g8g @@ -1934,8 +1977,8 @@ func Test_normal_8g8() bw! endfunc +" Test for g< fun! Test_normal35_g_cmd4() - " Test for g< " Cannot capture its output, " probably a bug, therefore, test disabled: throw "Skipped: output of g< can't be tested currently" @@ -1944,6 +1987,7 @@ fun! Test_normal35_g_cmd4() call assert_true(!empty(b), 'failed `execute(g<)`') endfunc +" Test for gp gP go fun! Test_normal36_g_cmd5() new call append(0, 'abcdefghijklmnopqrstuvwxyz') @@ -1982,8 +2026,8 @@ fun! Test_normal36_g_cmd5() bw! endfunc +" Test for gt and gT fun! Test_normal37_g_cmd6() - " basic test for gt and gT tabnew 1.txt tabnew 2.txt tabnew 3.txt @@ -2009,8 +2053,8 @@ fun! Test_normal37_g_cmd6() call assert_fails(':tabclose', 'E784:') endfunc +" Test for <Home> and <C-Home> key fun! Test_normal38_nvhome() - " Test for <Home> and <C-Home> key new call setline(1, range(10)) $ @@ -2025,11 +2069,14 @@ fun! Test_normal38_nvhome() call assert_equal([0, 5, 1, 0, 1], getcurpos()) exe "norm! \<c-home>" call assert_equal([0, 1, 1, 0, 1], getcurpos()) + exe "norm! G\<c-kHome>" + call assert_equal([0, 1, 1, 0, 1], getcurpos()) " clean up bw! endfunc +" Test for cw cW ce fun! Test_normal39_cw() " Test for cw and cW on whitespace " and cpo+=w setting @@ -2050,12 +2097,27 @@ fun! Test_normal39_cw() norm! 2gg0cwfoo call assert_equal('foo', getline('.')) + call setline(1, 'one; two') + call cursor(1, 1) + call feedkeys('cwvim', 'xt') + call assert_equal('vim; two', getline(1)) + call feedkeys('0cWone', 'xt') + call assert_equal('one two', getline(1)) + "When cursor is at the end of a word 'ce' will change until the end of the + "next word, but 'cw' will change only one character + call setline(1, 'one two') + call feedkeys('0ecwce', 'xt') + call assert_equal('once two', getline(1)) + call setline(1, 'one two') + call feedkeys('0ecely', 'xt') + call assert_equal('only', getline(1)) + " clean up bw! endfunc +" Test for CTRL-\ commands fun! Test_normal40_ctrl_bsl() - " Basic test for CTRL-\ commands new call append(0, 'here are some words') exe "norm! 1gg0a\<C-\>\<C-N>" @@ -2079,9 +2141,8 @@ fun! Test_normal40_ctrl_bsl() bw! endfunc +" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode fun! Test_normal41_insert_reg() - " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= - " in insert mode new set sts=2 sw=2 ts=8 tw=0 call append(0, ["aaa\tbbb\tccc", '', '', '']) @@ -2099,8 +2160,8 @@ fun! Test_normal41_insert_reg() bw! endfunc +" Test for Ctrl-D and Ctrl-U func Test_normal42_halfpage() - " basic test for Ctrl-D and Ctrl-U call Setup_NewWindow() call assert_equal(5, &scroll) exe "norm! \<c-d>" @@ -2136,8 +2197,8 @@ func Test_normal42_halfpage() bw! endfunc +" Tests for text object aw fun! Test_normal43_textobject1() - " basic tests for text object aw new call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) " diw @@ -2167,8 +2228,8 @@ fun! Test_normal43_textobject1() bw! endfunc +" Test for is and as text objects func Test_normal44_textobjects2() - " basic testing for is and as text objects new call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) " Test for dis - does not remove trailing whitespace @@ -2462,6 +2523,18 @@ func Test_gr_command() normal 4gro call assert_equal('ooooecond line', getline(2)) let &cpo = save_cpo + normal! ggvegrx + call assert_equal('xxxxx line', getline(1)) + exe "normal! gggr\<C-V>122" + call assert_equal('zxxxx line', getline(1)) + set virtualedit=all + normal! 15|grl + call assert_equal('zxxxx line l', getline(1)) + set virtualedit& + set nomodifiable + call assert_fails('normal! grx', 'E21:') + call assert_fails('normal! gRx', 'E21:') + set modifiable& enew! endfunc @@ -2659,10 +2732,11 @@ fun! Test_normal_gdollar_cmd() bw! endfunc -func Test_normal_gk() +func Test_normal_gk_gj() " needs 80 column new window new vert 80new + call assert_beeps('normal gk') put =[repeat('x',90)..' {{{1', 'x {{{1'] norm! gk " In a 80 column wide terminal the window will be only 78 char @@ -2677,12 +2751,12 @@ func Test_normal_gk() norm! gk call assert_equal(95, col('.')) call assert_equal(95, virtcol('.')) - bw! - bw! + %bw! " needs 80 column new window new vert 80new + call assert_beeps('normal gj') set number set numberwidth=10 set cpoptions+=n @@ -2701,9 +2775,14 @@ func Test_normal_gk() call assert_equal(1, col('.')) norm! gj call assert_equal(76, col('.')) - bw! - bw! - set cpoptions& number& numberwidth& + " When 'nowrap' is set, gk and gj behave like k and j + set nowrap + normal! gk + call assert_equal([2, 76], [line('.'), col('.')]) + normal! gj + call assert_equal([3, 76], [line('.'), col('.')]) + %bw! + set cpoptions& number& numberwidth& wrap& endfunc " Test for cursor movement with '-' in 'cpoptions' @@ -2731,3 +2810,42 @@ func Test_normal_yank_with_excmd() call assert_equal('f', @a) close! endfunc + +" Test for supplying a count to a normal-mode command across a cursorhold call +func Test_normal_cursorhold_with_count() + func s:cHold() + let g:cHold_Called += 1 + endfunc + new + augroup normalcHoldTest + au! + au CursorHold <buffer> call s:cHold() + augroup END + let g:cHold_Called = 0 + call feedkeys("3\<CursorHold>2ix", 'xt') + call assert_equal(1, g:cHold_Called) + call assert_equal(repeat('x', 32), getline(1)) + augroup normalcHoldTest + au! + augroup END + au! normalcHoldTest + close! + delfunc s:cHold +endfunc + +" Test for using a count and a command with CTRL-W +func Test_wincmd_with_count() + call feedkeys("\<C-W>12n", 'xt') + call assert_equal(12, winheight(0)) +endfunc + +" Test for 'b', 'B' 'ge' and 'gE' commands +func Test_backward_motion() + normal! gg + call assert_beeps('normal! b') + call assert_beeps('normal! B') + call assert_beeps('normal! gE') + call assert_beeps('normal! ge') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_prompt_buffer.vim b/src/testdir/test_prompt_buffer.vim index 199c1c2984..e13f9a6b2d 100644 --- a/src/testdir/test_prompt_buffer.vim +++ b/src/testdir/test_prompt_buffer.vim @@ -124,3 +124,15 @@ func Test_prompt_garbage_collect() delfunc MyPromptCallback bwipe! endfunc + +" Test for editing the prompt buffer +func Test_prompt_buffer_edit() + new + set buftype=prompt + normal! i + call assert_beeps('normal! dd') + call assert_beeps('normal! ~') + close! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_virtualedit.vim b/src/testdir/test_virtualedit.vim index 25ca33f8eb..bfb4985ff1 100644 --- a/src/testdir/test_virtualedit.vim +++ b/src/testdir/test_virtualedit.vim @@ -301,6 +301,9 @@ func Test_replace_on_tab() call append(0, "'r'\t") normal gg^5lrxAy call assert_equal("'r' x y", getline(1)) + call setline(1, 'aaaaaaaaaaaa') + exe "normal! gg2lgR\<Tab>" + call assert_equal("aa\taaaa", getline(1)) bwipe! set virtualedit= endfunc diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim index 601ad0fbe2..c15c6144dd 100644 --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -659,7 +659,6 @@ func Test_linewise_select_mode() exe "normal GkkgH\<Del>" call assert_equal(['', 'b', 'c'], getline(1, '$')) - " linewise select mode: delete middle two lines call deletebufline('', 1, '$') call append('$', ['a', 'b', 'c']) @@ -681,6 +680,15 @@ func Test_linewise_select_mode() bwipe! endfunc +" Test for blockwise select mode (g CTRL-H) +func Test_blockwise_select_mode() + new + call setline(1, ['foo', 'bar']) + call feedkeys("g\<BS>\<Right>\<Down>mm", 'xt') + call assert_equal(['mmo', 'mmr'], getline(1, '$')) + close! +endfunc + func Test_visual_mode_put() new @@ -908,4 +916,57 @@ func Test_star_register() close! endfunc +" Test for using visual mode maps in select mode +func Test_select_mode_map() + new + vmap <buffer> <F2> 3l + call setline(1, 'Test line') + call feedkeys("gh\<F2>map", 'xt') + call assert_equal('map line', getline(1)) + + vmap <buffer> <F2> ygV + call feedkeys("0gh\<Right>\<Right>\<F2>cwabc", 'xt') + call assert_equal('abc line', getline(1)) + + vmap <buffer> <F2> :<C-U>let v=100<CR> + call feedkeys("gggh\<Right>\<Right>\<F2>foo", 'xt') + call assert_equal('foo line', getline(1)) + + " reselect the select mode using gv from a visual mode map + vmap <buffer> <F2> gv + set selectmode=cmd + call feedkeys("0gh\<F2>map", 'xt') + call assert_equal('map line', getline(1)) + set selectmode& + + close! +endfunc + +" Test for changing text in visual mode with 'exclusive' selection +func Test_exclusive_selection() + new + call setline(1, ['one', 'two']) + set selection=exclusive + call feedkeys("vwcabc", 'xt') + call assert_equal('abctwo', getline(1)) + call setline(1, ["\tone"]) + set virtualedit=all + call feedkeys('0v2lcl', 'xt') + call assert_equal('l one', getline(1)) + set virtualedit& + set selection& + close! +endfunc + +" Test for starting visual mode with a count +" This test should be run withou any previous visual modes. So this should be +" run as a first test. +func Test_AAA_start_visual_mode_with_count() + new + call setline(1, ['aaaaaaa', 'aaaaaaa', 'aaaaaaa', 'aaaaaaa']) + normal! gg2Vy + call assert_equal("aaaaaaa\naaaaaaa\n", @") + close! +endfunc + " vim: shiftwidth=2 sts=2 expandtab |