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)
1f448d906b

Cherry-pick some test_edit.vim changes from patches 8.2.{1022,1432}.
Reorder test_undo.vim to match upstream.
This commit is contained in:
zeertzjq
2022-07-16 21:56:47 +08:00
parent 780edfc0eb
commit 0cfd4fa8f3
5 changed files with 186 additions and 76 deletions

View File

@@ -420,16 +420,49 @@ 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
" 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\<Tab>foo\<CR>\<Esc>")
" 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) .. "\<Esc>")
" 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 <CR> 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}])

View File

@@ -956,6 +956,16 @@ func Test_map_cmdkey_redo()
ounmap i-
endfunc
" Test for using <script> with a map to remap characters in rhs
func Test_script_local_remap()
new
inoremap <buffer> <SID>xyz mno
inoremap <buffer> <script> abc st<SID>xyzre
normal iabc
call assert_equal('stmnore', getline(1))
bwipe!
endfunc
func Test_abbreviate_multi_byte()
new
iabbrev foo bar

View File

@@ -1,4 +1,38 @@
" Test for terminal keycodes that doesn't have termcap entries
func Test_special_term_keycodes()
new
" Test for <xHome>, <S-xHome> and <C-xHome>
" send <K_SPECIAL> <KS_EXTRA> keycode
call feedkeys("i\<C-K>\x80\xfd\x3f\n", 'xt')
" send <K_SPECIAL> <KS_MODIFIER> bitmap <K_SPECIAL> <KS_EXTRA> keycode
call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3f\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3f\n", 'xt')
" Test for <xEnd>, <S-xEnd> and <C-xEnd>
call feedkeys("i\<C-K>\x80\xfd\x3d\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3d\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3d\n", 'xt')
" Test for <zHome>, <S-zHome> and <C-zHome>
call feedkeys("i\<C-K>\x80\xfd\x40\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x40\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x40\n", 'xt')
" Test for <zEnd>, <S-zEnd> and <C-zEnd>
call feedkeys("i\<C-K>\x80\xfd\x3e\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3e\n", 'xt')
call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3e\n", 'xt')
" Test for <xUp>, <xDown>, <xLeft> and <xRight>
call feedkeys("i\<C-K>\x80\xfd\x41\n", 'xt')
call feedkeys("i\<C-K>\x80\xfd\x42\n", 'xt')
call feedkeys("i\<C-K>\x80\xfd\x43\n", 'xt')
call feedkeys("i\<C-K>\x80\xfd\x44\n", 'xt')
call assert_equal(['<Home>', '<S-Home>', '<C-Home>',
\ '<End>', '<S-End>', '<C-End>',
\ '<Home>', '<S-Home>', '<C-Home>',
\ '<End>', '<S-End>', '<C-End>',
\ '<Up>', '<Down>', '<Left>', '<Right>', ''], getline(1, '$'))
bw!
endfunc
func Test_simplify_ctrl_at()
" feeding unsimplified CTRL-@ should still trigger i_CTRL-@
call feedkeys("ifoo\<Esc>A\<*C-@>x", 'xt')

View File

@@ -3,8 +3,6 @@
" undo-able pieces. Do that by setting 'undolevels'.
" Also tests :earlier and :later.
source check.vim
func Test_undotree()
new
@@ -137,8 +135,7 @@ func BackOne(expected)
endfunc
func Test_undo_del_chars()
CheckFunction test_settime
throw 'Skipped: Nvim does not support test_settime()'
" Setup a buffer without creating undo entries
new
set ul=-1
@@ -334,8 +331,9 @@ func Test_insert_expr()
endfunc
func Test_undofile_earlier()
CheckFunction test_settime
throw 'Skipped: Nvim does not support test_settime()'
" Issue #1254
" create undofile with timestamps older than Vim startup time.
let t0 = localtime() - 43200
call test_settime(t0)
new Xfile
@@ -368,7 +366,7 @@ func Test_wundo_errors()
bwipe!
endfunc
" Check that reading a truncted undo file doesn't hang.
" Check that reading a truncated undo file doesn't hang.
func Test_undofile_truncated()
new
call setline(1, 'hello')
@@ -431,31 +429,6 @@ func Test_cmd_in_reg_undo()
let @a = ''
endfunc
" undo or redo are noop if there is nothing to undo or redo
func Test_undo_redo_noop()
new
call assert_fails('undo 2', 'E830:')
message clear
undo
let messages = split(execute('message'), "\n")
call assert_equal('Already at oldest change', messages[-1])
message clear
redo
let messages = split(execute('message'), "\n")
call assert_equal('Already at newest change', messages[-1])
bwipe!
endfunc
func Test_redo_empty_line()
new
exe "norm\x16r\x160"
exe "norm."
bwipe!
endfunc
" This used to cause an illegal memory access
func Test_undo_append()
new
@@ -465,47 +438,6 @@ func Test_undo_append()
quit
endfunc
funct Test_undofile()
" Test undofile() without setting 'undodir'.
if has('persistent_undo')
call assert_equal(fnamemodify('.Xundofoo.un~', ':p'), undofile('Xundofoo'))
else
call assert_equal('', undofile('Xundofoo'))
endif
call assert_equal('', undofile(''))
" Test undofile() with 'undodir' set to to an existing directory.
call mkdir('Xundodir')
set undodir=Xundodir
let cwd = getcwd()
if has('win32')
" Replace windows drive such as C:... into C%...
let cwd = substitute(cwd, '^\([a-zA-Z]\):', '\1%', 'g')
endif
let cwd = substitute(cwd . '/Xundofoo', '/', '%', 'g')
if has('persistent_undo')
call assert_equal('Xundodir/' . cwd, undofile('Xundofoo'))
else
call assert_equal('', undofile('Xundofoo'))
endif
call assert_equal('', undofile(''))
call delete('Xundodir', 'd')
" Test undofile() with 'undodir' set to a non-existing directory.
" call assert_equal('', 'Xundofoo'->undofile())
if isdirectory('/tmp')
set undodir=/tmp
if has('osx')
call assert_equal('/tmp/%private%tmp%file', undofile('///tmp/file'))
else
call assert_equal('/tmp/%tmp%file', undofile('///tmp/file'))
endif
endif
set undodir&
endfunc
func Test_undo_0()
new
set ul=100
@@ -550,6 +482,72 @@ func Test_undo_0()
bwipe!
endfunc
" undo or redo are noop if there is nothing to undo or redo
func Test_undo_redo_noop()
new
call assert_fails('undo 2', 'E830:')
message clear
undo
let messages = split(execute('message'), "\n")
call assert_equal('Already at oldest change', messages[-1])
message clear
redo
let messages = split(execute('message'), "\n")
call assert_equal('Already at newest change', messages[-1])
bwipe!
endfunc
func Test_redo_empty_line()
new
exe "norm\x16r\x160"
exe "norm."
bwipe!
endfunc
funct Test_undofile()
" Test undofile() without setting 'undodir'.
if has('persistent_undo')
call assert_equal(fnamemodify('.Xundofoo.un~', ':p'), undofile('Xundofoo'))
else
call assert_equal('', undofile('Xundofoo'))
endif
call assert_equal('', undofile(''))
" Test undofile() with 'undodir' set to to an existing directory.
call mkdir('Xundodir')
set undodir=Xundodir
let cwd = getcwd()
if has('win32')
" Replace windows drive such as C:... into C%...
let cwd = substitute(cwd, '^\([a-zA-Z]\):', '\1%', 'g')
endif
let cwd = substitute(cwd . '/Xundofoo', '/', '%', 'g')
if has('persistent_undo')
call assert_equal('Xundodir/' . cwd, undofile('Xundofoo'))
else
call assert_equal('', undofile('Xundofoo'))
endif
call assert_equal('', undofile(''))
call delete('Xundodir', 'd')
" Test undofile() with 'undodir' set to a non-existing directory.
" call assert_equal('', 'Xundofoo'->undofile())
if isdirectory('/tmp')
set undodir=/tmp
if has('osx')
call assert_equal('/tmp/%private%tmp%file', undofile('///tmp/file'))
else
call assert_equal('/tmp/%tmp%file', undofile('///tmp/file'))
endif
endif
set undodir&
endfunc
" Tests for the undo file
" Explicitly break changes up in undo-able pieces by setting 'undolevels'.
func Test_undofile_2()
@@ -749,6 +747,15 @@ func Test_redo_repeat_numbered_register()
bwipe!
endfunc
" Test for redo in insert mode using CTRL-O with multibyte characters
func Test_redo_multibyte_in_insert_mode()
new
call feedkeys("a\<C-K>ft", 'xt')
call feedkeys("uiHe\<C-O>.llo", 'xt')
call assert_equal("He\ufb05llo", getline(1))
bwipe!
endfunc
func Test_undo_mark()
new
" The undo is applied to the only line.

View File

@@ -0,0 +1,26 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local expect = helpers.expect
local feed = helpers.feed
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))
end)