forked from aniani/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 #6300)
This commit is contained in:
@@ -254,6 +254,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(test_null_blob(), 1, 2)", 'E979:')
|
||||
endfunc
|
||||
|
||||
|
@@ -246,6 +246,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()
|
||||
@@ -294,9 +295,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()
|
||||
@@ -334,7 +338,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()
|
||||
@@ -498,7 +504,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()
|
||||
@@ -543,8 +551,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)
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
source check.vim
|
||||
CheckFeature digraphs
|
||||
source term_util.vim
|
||||
|
||||
func Put_Dig(chars)
|
||||
exe "norm! o\<c-k>".a:chars
|
||||
@@ -502,4 +503,20 @@ func Test_loadkeymap_error()
|
||||
call delete('Xkeymap')
|
||||
endfunc
|
||||
|
||||
" Test for the characters displayed one the screen when entering a digraph
|
||||
func Test_entering_digraph()
|
||||
CheckRunVimInTerminal
|
||||
let buf = RunVimInTerminal('', {'rows': 6})
|
||||
call term_sendkeys(buf, "i\<C-K>")
|
||||
call term_wait(buf)
|
||||
call assert_equal('?', term_getline(buf, 1))
|
||||
call term_sendkeys(buf, "1")
|
||||
call term_wait(buf)
|
||||
call assert_equal('1', term_getline(buf, 1))
|
||||
call term_sendkeys(buf, "2")
|
||||
call term_wait(buf)
|
||||
call assert_equal('½', term_getline(buf, 1))
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -401,6 +401,14 @@ func Test_edit_13()
|
||||
call assert_equal("", getline(2))
|
||||
call assert_equal(" baz", getline(3))
|
||||
set autoindent&
|
||||
|
||||
" pressing <C-U> to erase line should keep the indent with 'autoindent'
|
||||
set backspace=2 autoindent
|
||||
%d
|
||||
exe "normal i\tone\<CR>three\<C-U>two"
|
||||
call assert_equal(["\tone", "\ttwo"], getline(1, '$'))
|
||||
set backspace& autoindent&
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
@@ -1301,9 +1309,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)
|
||||
@@ -1348,6 +1354,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
|
||||
@@ -1683,4 +1696,103 @@ func Test_edit_file_no_read_perm()
|
||||
call delete('Xfile')
|
||||
endfunc
|
||||
|
||||
" Pressing escape in 'insertmode' should beep
|
||||
func Test_edit_insertmode_esc_beeps()
|
||||
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()
|
||||
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
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -7,7 +7,7 @@ let s:imstatus_active = 0
|
||||
|
||||
func IM_activatefunc(active)
|
||||
let s:imactivatefunc_called = 1
|
||||
let s:imstatus_active = a:active
|
||||
let s:imstatus_active = a:active
|
||||
endfunc
|
||||
|
||||
func IM_statusfunc()
|
||||
@@ -83,4 +83,30 @@ func Test_lmap_in_insert_mode()
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" Test for using CTRL-^ to toggle iminsert in insert mode
|
||||
func Test_iminsert_toggle()
|
||||
CheckGui
|
||||
if has('win32')
|
||||
CheckFeature multi_byte_ime
|
||||
elseif !has('gui_mac')
|
||||
CheckFeature xim
|
||||
endif
|
||||
if has('gui_running') && !has('win32')
|
||||
" this works only in Win32 GUI version (for some reason)
|
||||
return
|
||||
endif
|
||||
new
|
||||
let save_imdisable = &imdisable
|
||||
let save_iminsert = &iminsert
|
||||
set noimdisable
|
||||
set iminsert=0
|
||||
exe "normal i\<C-^>"
|
||||
call assert_equal(2, &iminsert)
|
||||
exe "normal i\<C-^>"
|
||||
call assert_equal(0, &iminsert)
|
||||
let &iminsert = save_iminsert
|
||||
let &imdisable = save_imdisable
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -79,11 +79,27 @@ func Test_paste_clipboard()
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
" bracketed paste in command line
|
||||
func Test_paste_cmdline()
|
||||
call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt')
|
||||
call assert_equal("\"afoo\<CR>barb", getreg(':'))
|
||||
endfunc
|
||||
|
||||
" bracketed paste in Ex-mode
|
||||
func Test_paste_ex_mode()
|
||||
unlet! foo
|
||||
call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt')
|
||||
call assert_equal("foo\rbar", foo)
|
||||
endfunc
|
||||
|
||||
func Test_paste_onechar()
|
||||
new
|
||||
let @f='abc'
|
||||
call feedkeys("i\<C-R>\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
|
||||
call assert_equal("abc", getline(1))
|
||||
close!
|
||||
endfunc
|
||||
|
||||
func Test_paste_visual_mode()
|
||||
new
|
||||
call setline(1, 'here are some words')
|
||||
@@ -134,3 +150,5 @@ func Test_xrestore()
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -147,6 +147,11 @@ func Test_prompt_buffer_edit()
|
||||
call assert_beeps('normal! S')
|
||||
call assert_beeps("normal! \<C-A>")
|
||||
call assert_beeps("normal! \<C-X>")
|
||||
" pressing CTRL-W in the prompt buffer should trigger the window commands
|
||||
call assert_equal(1, winnr())
|
||||
exe "normal A\<C-W>\<C-W>"
|
||||
call assert_equal(2, winnr())
|
||||
wincmd w
|
||||
close!
|
||||
call assert_equal(0, prompt_setprompt([], ''))
|
||||
endfunc
|
||||
|
@@ -38,6 +38,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
|
||||
|
@@ -623,4 +623,15 @@ 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
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -240,6 +240,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
|
||||
@@ -1055,7 +1056,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
|
||||
|
||||
@@ -1337,4 +1338,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
|
||||
|
@@ -1116,6 +1116,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
|
||||
|
@@ -87,6 +87,28 @@ func Test_global_vars()
|
||||
call assert_equal(test_null, g:MY_GLOBAL_NULL)
|
||||
call assert_equal(test_none, g:MY_GLOBAL_NONE)
|
||||
|
||||
" Test for invalid values for a blob, list, dict in a viminfo file
|
||||
call writefile([
|
||||
\ "!GLOB_BLOB_1\tBLO\t123",
|
||||
\ "!GLOB_BLOB_2\tBLO\t012",
|
||||
\ "!GLOB_BLOB_3\tBLO\t0z1x",
|
||||
\ "!GLOB_BLOB_4\tBLO\t0z12 ab",
|
||||
\ "!GLOB_LIST_1\tLIS\t1 2",
|
||||
\ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo')
|
||||
call assert_fails('rv! Xviminfo', 'E15:')
|
||||
call assert_equal('123', g:GLOB_BLOB_1)
|
||||
call assert_equal(1, type(g:GLOB_BLOB_1))
|
||||
call assert_equal('012', g:GLOB_BLOB_2)
|
||||
call assert_equal(1, type(g:GLOB_BLOB_2))
|
||||
call assert_equal('0z1x', g:GLOB_BLOB_3)
|
||||
call assert_equal(1, type(g:GLOB_BLOB_3))
|
||||
call assert_equal('0z12 ab', g:GLOB_BLOB_4)
|
||||
call assert_equal(1, type(g:GLOB_BLOB_4))
|
||||
call assert_equal('1 2', g:GLOB_LIST_1)
|
||||
call assert_equal(1, type(g:GLOB_LIST_1))
|
||||
call assert_equal('1 2', g:GLOB_DICT_1)
|
||||
call assert_equal(1, type(g:GLOB_DICT_1))
|
||||
|
||||
call delete('Xviminfo')
|
||||
set viminfo-=!
|
||||
endfunc
|
||||
|
@@ -357,4 +357,22 @@ 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
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -208,6 +208,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')
|
||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1022,
|
||||
/**/
|
||||
1021,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user