diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-04 19:49:23 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-04 20:54:50 +0800 |
commit | 2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2 (patch) | |
tree | 94140dbc845f6145eae7876cd0bd933a9dcfcdbe | |
parent | 2b86ca81b400b1311379f3258cc6c38be94fcf36 (diff) | |
download | rneovim-2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2.tar.gz rneovim-2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2.tar.bz2 rneovim-2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2.zip |
vim-patch:8.2.1022: various parts of code not covered by tests
Problem: Various parts of code not covered by tests.
Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#6300)
https://github.com/vim/vim/commit/845e0ee59430eac07e74b6cb92020e420d17953d
Omit test_iminsert.vim: the commit that created this file was N/A.
Omit test_viminfo.vim: the added tests are N/A.
-rw-r--r-- | src/nvim/testdir/test_blob.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_cpoptions.vim | 20 | ||||
-rw-r--r-- | src/nvim/testdir/test_edit.vim | 112 | ||||
-rw-r--r-- | src/nvim/testdir/test_selectmode.vim | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_tabpage.vim | 11 | ||||
-rw-r--r-- | src/nvim/testdir/test_tagjump.vim | 55 | ||||
-rw-r--r-- | src/nvim/testdir/test_textformat.vim | 14 | ||||
-rw-r--r-- | src/nvim/testdir/test_virtualedit.vim | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_visual.vim | 9 | ||||
-rw-r--r-- | test/functional/legacy/digraph_spec.lua | 46 | ||||
-rw-r--r-- | test/functional/legacy/edit_spec.lua | 64 |
11 files changed, 327 insertions, 26 deletions
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 151de71312..1c0261933f 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -252,6 +252,7 @@ func Test_blob_func_remove() call assert_fails("call remove(b, 3, 2)", 'E979:') call assert_fails("call remove(1, 0)", 'E896:') call assert_fails("call remove(b, b)", 'E974:') + call assert_fails("call remove(b, 1, [])", 'E745:') call assert_fails("call remove(v:_null_blob, 1, 2)", 'E979:') " Translated from v8.2.3284 diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index f0732934d4..cc281ef521 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -248,6 +248,7 @@ func Test_cpo_H() endfunc " TODO: Add a test for the 'i' flag in 'cpo' +" Interrupting the reading of a file will leave it modified. " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) func Test_cpo_I() @@ -296,9 +297,12 @@ func Test_cpo_J() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'k' flag in 'cpo' +" TODO: Add a test for the 'k' flag in 'cpo'. +" Disable the recognition of raw key codes in mappings, abbreviations, and the +" "to" part of menu commands. -" TODO: Add a test for the 'K' flag in 'cpo' +" TODO: Add a test for the 'K' flag in 'cpo'. +" Don't wait for a key code to complete when it is halfway a mapping. " Test for the 'l' flag in 'cpo' (backslash in a [] range) func Test_cpo_l() @@ -336,7 +340,9 @@ func Test_cpo_L() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'm' flag in 'cpo' +" TODO: Add a test for the 'm' flag in 'cpo'. +" When included, a showmatch will always wait half a second. When not +" included, a showmatch will wait half a second or until a character is typed. " Test for the 'M' flag in 'cpo' (% with escape parenthesis) func Test_cpo_M() @@ -500,7 +506,9 @@ func Test_cpo_R() let &cpo = save_cpo endfunc -" TODO: Add a test for the 's' flag in 'cpo' +" TODO: Add a test for the 's' flag in 'cpo'. +" Set buffer options when entering the buffer for the first time. If not +" present the options are set when the buffer is created. " Test for the 'S' flag in 'cpo' (copying buffer options) func Test_cpo_S() @@ -545,8 +553,8 @@ func Test_cpo_u() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove -" characters from the screen) +" TODO: Add a test for the 'v' flag in 'cpo'. +" Backspaced characters remain visible on the screen in Insert mode. " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one " character) diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index d19826f5b9..89fd73351d 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1433,9 +1433,7 @@ endfunc func Test_edit_rightleft() " Cursor in rightleft mode moves differently - if !exists("+rightleft") - return - endif + CheckFeature rightleft call NewWindow(10, 20) call setline(1, ['abc', 'def', 'ghi']) call cursor(1, 2) @@ -1480,6 +1478,13 @@ func Test_edit_rightleft() \" ihg", \" ~"] call assert_equal(join(expect, "\n"), join(lines, "\n")) + %d _ + " call test_override('redraw_flag', 1) + " call test_override('char_avail', 1) + call feedkeys("a\<C-V>x41", "xt") + redraw! + call assert_equal(repeat(' ', 19) .. 'A', Screenline(1)) + " call test_override('ALL', 0) set norightleft bw! endfunc @@ -1868,6 +1873,107 @@ func Test_edit_insertmode_ex_edit() call delete('Xtest_edit_insertmode_ex_edit') endfunc +" Pressing escape in 'insertmode' should beep +func Test_edit_insertmode_esc_beeps() + throw "Skipped: Nvim does not support 'insertmode'" + new + set insertmode + call assert_beeps("call feedkeys(\"one\<Esc>\", 'xt')") + set insertmode& + " unsupported CTRL-G command should beep in insert mode. + call assert_beeps("normal i\<C-G>l") + close! +endfunc + +" Test for 'hkmap' and 'hkmapp' +func Test_edit_hkmap() + CheckFeature rightleft + if has('win32') && !has('gui') + " Test fails on the MS-Windows terminal version + return + endif + new + + set revins hkmap + let str = 'abcdefghijklmnopqrstuvwxyz' + let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + let str ..= '`/'',.;' + call feedkeys('i' .. str, 'xt') + let expected = "óõú,.;" + let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA" + let expected ..= "æèñ'äåàãø/ôíîöêìçïéòë÷âáðù" + call assert_equal(expected, getline(1)) + + %d + set revins hkmap hkmapp + let str = 'abcdefghijklmnopqrstuvwxyz' + let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + call feedkeys('i' .. str, 'xt') + let expected = "õYXWVUTSRQóOïíLKJIHGFEDêBA" + let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà" + call assert_equal(expected, getline(1)) + + set revins& hkmap& hkmapp& + close! +endfunc + +" Test for 'allowrevins' and using CTRL-_ in insert mode +func Test_edit_allowrevins() + CheckFeature rightleft + new + set allowrevins + call feedkeys("iABC\<C-_>DEF\<C-_>GHI", 'xt') + call assert_equal('ABCFEDGHI', getline(1)) + set allowrevins& + close! +endfunc + +" Test for inserting a register in insert mode using CTRL-R +func Test_edit_insert_reg() + throw 'Skipped: use test/functional/legacy/edit_spec.lua' + new + let g:Line = '' + func SaveFirstLine() + let g:Line = Screenline(1) + return 'r' + endfunc + inoremap <expr> <buffer> <F2> SaveFirstLine() + call test_override('redraw_flag', 1) + call test_override('char_avail', 1) + let @r = 'sample' + call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt") + call assert_equal('"', g:Line) + call test_override('ALL', 0) + close! +endfunc + +" When a character is inserted at the last position of the last line in a +" window, the window contents should be scrolled one line up. If the top line +" is part of a fold, then the entire fold should be scrolled up. +func Test_edit_lastline_scroll() + new + let h = winheight(0) + let lines = ['one', 'two', 'three'] + let lines += repeat(['vim'], h - 4) + call setline(1, lines) + call setline(h, repeat('x', winwidth(0) - 1)) + call feedkeys("GAx", 'xt') + redraw! + call assert_equal(h - 1, winline()) + call assert_equal(2, line('w0')) + + " scroll with a fold + 1,2fold + normal gg + call setline(h + 1, repeat('x', winwidth(0) - 1)) + call feedkeys("GAx", 'xt') + redraw! + call assert_equal(h - 1, winline()) + call assert_equal(3, line('w0')) + + close! +endfunc + func Test_edit_browse() " in the GUI this opens a file picker, we only test the terminal behavior CheckNotGui diff --git a/src/nvim/testdir/test_selectmode.vim b/src/nvim/testdir/test_selectmode.vim index f2cab45450..041f0592f1 100644 --- a/src/nvim/testdir/test_selectmode.vim +++ b/src/nvim/testdir/test_selectmode.vim @@ -34,6 +34,9 @@ func Test_selectmode_start() set selectmode=cmd call feedkeys('gvabc', 'xt') call assert_equal('abctdef', getline(1)) + " arrow keys without shift should not start selection + call feedkeys("A\<Home>\<Right>\<Left>ro", 'xt') + call assert_equal('roabctdef', getline(1)) set selectmode= keymodel= bw! endfunc diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index 6d468ec9de..4ada48d56c 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -623,6 +623,17 @@ func Test_tabpage_close_cmdwin() tabonly endfunc +" Pressing <C-PageUp> in insert mode should go to the previous tab page +" and <C-PageDown> should go to the next tab page +func Test_tabpage_Ctrl_Pageup() + tabnew + call feedkeys("i\<C-PageUp>", 'xt') + call assert_equal(1, tabpagenr()) + call feedkeys("i\<C-PageDown>", 'xt') + call assert_equal(2, tabpagenr()) + %bw! +endfunc + " Return the terminal key code for selecting a tab page from the tabline. This " sequence contains the following codes: a CSI (0x9b), KS_TABLINE (0xf0), " KS_FILLER (0x58) and then the tab page number. diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 04c0218f74..592e13e340 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -282,6 +282,7 @@ func Test_tag_file_encoding() call delete('Xtags1') endfunc +" Test for emacs-style tags file (TAGS) func Test_tagjump_etags() if !has('emacs_tags') return @@ -1099,7 +1100,7 @@ func Test_tselect_listing() call writefile([ \ "!_TAG_FILE_ENCODING\tutf-8\t//", \ "first\tXfoo\t1" .. ';"' .. "\tv\ttyperef:typename:int\tfile:", - \ "first\tXfoo\t2" .. ';"' .. "\tv\ttyperef:typename:char\tfile:"], + \ "first\tXfoo\t2" .. ';"' .. "\tkind:v\ttyperef:typename:char\tfile:"], \ 'Xtags') set tags=Xtags @@ -1422,4 +1423,56 @@ func Test_tag_length() set tags& taglength& endfunc +" Tests for errors in a tags file +func Test_tagfile_errors() + set tags=Xtags + + " missing search pattern or line number for a tag + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile\t"], 'Xtags', 'b') + call writefile(['foo'], 'Xfile') + + enew + tag foo + call assert_equal('', @%) + let caught_431 = v:false + try + eval taglist('.*') + catch /:E431:/ + let caught_431 = v:true + endtry + call assert_equal(v:true, caught_431) + + call delete('Xtags') + call delete('Xfile') + set tags& +endfunc + +" When :stag fails to open the file, should close the new window +func Test_stag_close_window_on_error() + new | only + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile\t1"], 'Xtags') + call writefile(['foo'], 'Xfile') + call writefile([], '.Xfile.swp') + " Remove the catch-all that runtest.vim adds + au! SwapExists + augroup StagTest + au! + autocmd SwapExists Xfile let v:swapchoice='q' + augroup END + + stag foo + call assert_equal(1, winnr('$')) + call assert_equal('', @%) + + augroup StagTest + au! + augroup END + call delete('Xfile') + call delete('.Xfile.swp') + set tags& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 4eb6e69adf..3bce2eb24d 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -1096,6 +1096,20 @@ func Test_fo_a_w() call feedkeys("iabc abc a abc\<Esc>k0weade", 'xt') call assert_equal(['abc abcde ', 'a abc'], getline(1, '$')) + " when a line ends with space, it is not broken up. + %d + call feedkeys("ione two to ", 'xt') + call assert_equal('one two to ', getline(1)) + + " when a line ends with spaces and backspace is used in the next line, the + " last space in the previous line should be removed. + %d + set backspace=indent,eol,start + call setline(1, ['one ', 'two']) + exe "normal 2Gi\<BS>" + call assert_equal(['one two'], getline(1, '$')) + set backspace& + " Test for 'a', 'w' and '1' options. setlocal textwidth=0 setlocal fo=1aw diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index ddc7c20637..edf68e6482 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -357,6 +357,24 @@ func Test_delete_break_tab() close! endfunc +" Test for using <BS>, <C-W> and <C-U> in virtual edit mode +" to erase character, word and line. +func Test_ve_backspace() + new + call setline(1, 'sample') + set virtualedit=all + set backspace=indent,eol,start + exe "normal 15|i\<BS>\<BS>" + call assert_equal([0, 1, 7, 5], getpos('.')) + exe "normal 15|i\<C-W>" + call assert_equal([0, 1, 6, 0], getpos('.')) + exe "normal 15|i\<C-U>" + call assert_equal([0, 1, 1, 0], getpos('.')) + set backspace& + set virtualedit& + close! +endfunc + " After calling s:TryVirtualeditReplace(), line 1 will contain one of these " two strings, depending on whether virtual editing is on or off. let s:result_ve_on = 'a x' diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index a9c057088d..712ea343ed 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -225,6 +225,15 @@ func Test_virtual_replace() exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" call assert_equal(['AB......CDEFGHI.Jkl', \ 'AB IJKLMNO QRst'], getline(12, 13)) + + " Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4 + %d + call setline(1, 'aaaaaaaaaaaaa') + set softtabstop=4 + exe "normal gggR\<Tab>\<Tab>x" + call assert_equal("\txaaaa", getline(1)) + set softtabstop& + enew! set noai bs&vim if exists('save_t_kD') diff --git a/test/functional/legacy/digraph_spec.lua b/test/functional/legacy/digraph_spec.lua new file mode 100644 index 0000000000..0cb0bb84be --- /dev/null +++ b/test/functional/legacy/digraph_spec.lua @@ -0,0 +1,46 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local feed = helpers.feed + +before_each(clear) + +describe('digraph', function() + -- oldtest: Test_entering_digraph() + it('characters displayed on the screen', function() + local screen = Screen.new(10, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {foreground = Screen.colors.Blue}, -- SpecialKey + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + feed('i<C-K>') + screen:expect([[ + {1:^?} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('1') + screen:expect([[ + {1:^1} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('2') + screen:expect([[ + ½^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + end) +end) diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua index 7fc5f11a79..362d33a0fd 100644 --- a/test/functional/legacy/edit_spec.lua +++ b/test/functional/legacy/edit_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local expect = helpers.expect @@ -7,20 +8,51 @@ local sleep = helpers.sleep before_each(clear) --- oldtest: Test_autoindent_remove_indent() -it('autoindent removes indent when Insert mode is stopped', function() - command('set autoindent') - -- leaving insert mode in a new line with indent added by autoindent, should - -- remove the indent. - feed('i<Tab>foo<CR><Esc>') - -- Need to delay for sometime, otherwise the code in getchar.c will not be - -- exercised. - sleep(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. - feed('o' .. ('x'):rep(20) .. '<Esc>') - -- Need to delay for sometime, otherwise the code in getchar.c will not be - -- exercised. - sleep(50) - expect('\tfoo\n\n' .. ('x'):rep(20)) +describe('edit', function() + -- oldtest: Test_autoindent_remove_indent() + it('autoindent removes indent when Insert mode is stopped', function() + command('set autoindent') + -- leaving insert mode in a new line with indent added by autoindent, should + -- remove the indent. + feed('i<Tab>foo<CR><Esc>') + -- Need to delay for sometime, otherwise the code in getchar.c will not be + -- exercised. + sleep(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. + feed('o' .. ('x'):rep(20) .. '<Esc>') + -- Need to delay for sometime, otherwise the code in getchar.c will not be + -- exercised. + sleep(50) + expect('\tfoo\n\n' .. ('x'):rep(20)) + end) + + -- oldtest: Test_edit_insert_reg() + it('inserting a register using CTRL-R', function() + local screen = Screen.new(10, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {foreground = Screen.colors.Blue}, -- SpecialKey + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + feed('a<C-R>') + screen:expect([[ + {1:^"} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('=') + screen:expect([[ + {1:"} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + =^ | + ]]) + end) end) |