Skip to content

Commit bc2b71d

Browse files
committed
patch 8.2.0270: some code not covered by tests
Problem: Some code not covered by tests. Solution: Add test cases. (Yegappan Lakshmanan, closes #5649)
1 parent b13af50 commit bc2b71d

20 files changed

Lines changed: 466 additions & 7 deletions

src/testdir/test_autocmd.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,3 +2357,5 @@ func Test_FileType_spell()
23572357
au! crash
23582358
setglobal spellfile=
23592359
endfunc
2360+
2361+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_buffer.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func Test_buflist_browse()
103103
call assert_equal(b2, bufnr())
104104
call assert_equal(1, line('.'))
105105

106-
brewind +/foo3
106+
brewind +
107107
call assert_equal(b1, bufnr())
108-
call assert_equal(3, line('.'))
108+
call assert_equal(4, line('.'))
109109

110110
blast +/baz2
111111
call assert_equal(b3, bufnr())

src/testdir/test_edit.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,22 @@ func Test_edit_startinsert()
15001500
bwipe!
15011501
endfunc
15021502

1503+
" Test for :startreplace and :startgreplace
1504+
func Test_edit_startreplace()
1505+
new
1506+
call setline(1, 'abc')
1507+
call feedkeys("l:startreplace\<CR>xyz\e", 'xt')
1508+
call assert_equal('axyz', getline(1))
1509+
call feedkeys("0:startreplace!\<CR>abc\e", 'xt')
1510+
call assert_equal('axyzabc', getline(1))
1511+
call setline(1, "a\tb")
1512+
call feedkeys("0l:startgreplace\<CR>xyz\e", 'xt')
1513+
call assert_equal("axyz\tb", getline(1))
1514+
call feedkeys("0i\<C-R>=execute('startreplace')\<CR>12\e", 'xt')
1515+
call assert_equal("12axyz\tb", getline(1))
1516+
close!
1517+
endfunc
1518+
15031519
func Test_edit_noesckeys()
15041520
CheckNotGui
15051521
new
@@ -1519,3 +1535,5 @@ func Test_edit_noesckeys()
15191535
bwipe!
15201536
set esckeys
15211537
endfunc
1538+
1539+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_ex_mode.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Test_ex_mode()
5555
let &encoding = encoding_save
5656
endfunc
5757

58-
" Test subsittute confirmation prompt :%s/pat/str/c in Ex mode
58+
" Test substitute confirmation prompt :%s/pat/str/c in Ex mode
5959
func Test_Ex_substitute()
6060
CheckRunVimInTerminal
6161
let buf = RunVimInTerminal('', {'rows': 6})
@@ -77,6 +77,11 @@ func Test_Ex_substitute()
7777
call term_sendkeys(buf, "q\<CR>")
7878
call WaitForAssert({-> assert_match(':', term_getline(buf, 6))}, 1000)
7979

80+
" Pressing enter in ex mode should print the current line
81+
call term_sendkeys(buf, "\<CR>")
82+
call WaitForAssert({-> assert_match(' 3 foo foo',
83+
\ term_getline(buf, 5))}, 1000)
84+
8085
call term_sendkeys(buf, ":vi\<CR>")
8186
call WaitForAssert({-> assert_match('foo bar', term_getline(buf, 1))}, 1000)
8287

src/testdir/test_excmd.vim

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ func Test_redir_cmd()
267267
call assert_fails('redir! > Xfile', 'E190:')
268268
call delete('Xfile')
269269
endif
270+
271+
" Test for redirecting to a register
272+
redir @q> | echon 'clean ' | redir END
273+
redir @q>> | echon 'water' | redir END
274+
call assert_equal('clean water', @q)
275+
276+
" Test for redirecting to a variable
277+
redir => color | echon 'blue ' | redir END
278+
redir =>> color | echon 'sky' | redir END
279+
call assert_equal('blue sky', color)
270280
endfunc
271281

272282
" Test for the :filetype command
@@ -279,4 +289,50 @@ func Test_mode_cmd()
279289
call assert_fails('mode abc', 'E359:')
280290
endfunc
281291

292+
" Test for the :sleep command
293+
func Test_sleep_cmd()
294+
call assert_fails('sleep x', 'E475:')
295+
endfunc
296+
297+
" Test for the :read command
298+
func Test_read_cmd()
299+
call writefile(['one'], 'Xfile')
300+
new
301+
call assert_fails('read', 'E32:')
302+
edit Xfile
303+
read
304+
call assert_equal(['one', 'one'], getline(1, '$'))
305+
close!
306+
new
307+
read Xfile
308+
call assert_equal(['', 'one'], getline(1, '$'))
309+
call deletebufline('', 1, '$')
310+
call feedkeys("Qr Xfile\<CR>visual\<CR>", 'xt')
311+
call assert_equal(['one'], getline(1, '$'))
312+
close!
313+
call delete('Xfile')
314+
endfunc
315+
316+
" Test for running Ex commands when text is locked.
317+
" <C-\>e in the command line is used to lock the text
318+
func Test_run_excmd_with_text_locked()
319+
" :quit
320+
let cmd = ":\<C-\>eexecute('quit')\<CR>\<C-C>"
321+
call assert_fails("call feedkeys(cmd, 'xt')", 'E523:')
322+
323+
" :qall
324+
let cmd = ":\<C-\>eexecute('qall')\<CR>\<C-C>"
325+
call assert_fails("call feedkeys(cmd, 'xt')", 'E523:')
326+
327+
" :exit
328+
let cmd = ":\<C-\>eexecute('exit')\<CR>\<C-C>"
329+
call assert_fails("call feedkeys(cmd, 'xt')", 'E523:')
330+
331+
" :close - should be ignored
332+
new
333+
let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>"
334+
call assert_equal(2, winnr('$'))
335+
close
336+
endfunc
337+
282338
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_expand.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Test for expanding file names
22

3+
source shared.vim
4+
35
func Test_with_directories()
46
call mkdir('Xdir1')
57
call mkdir('Xdir2')
@@ -81,3 +83,30 @@ func Test_expandcmd()
8183
call assert_fails('call expandcmd("make %")', 'E499:')
8284
close
8385
endfunc
86+
87+
" Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script
88+
func Test_source_sfile()
89+
let lines =<< trim [SCRIPT]
90+
:call assert_fails('echo expandcmd("<sfile>")', 'E498:')
91+
:call assert_fails('echo expandcmd("<slnum>")', 'E842:')
92+
:call assert_fails('echo expandcmd("<sflnum>")', 'E961:')
93+
:call assert_fails('call expandcmd("edit <cfile>")', 'E446:')
94+
:call assert_fails('call expandcmd("edit #")', 'E194:')
95+
:call assert_fails('call expandcmd("edit #<2")', 'E684:')
96+
:call assert_fails('call expandcmd("edit <cword>")', 'E348:')
97+
:call assert_fails('call expandcmd("edit <cexpr>")', 'E348:')
98+
:call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:')
99+
:call writefile(v:errors, 'Xresult')
100+
:qall!
101+
102+
[SCRIPT]
103+
call writefile(lines, 'Xscript')
104+
if RunVim([], [], '--clean -s Xscript')
105+
call assert_equal([], readfile('Xresult'))
106+
endif
107+
call delete('Xscript')
108+
call delete('Xresult')
109+
endfunc
110+
111+
112+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_filetype.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,25 @@ func Test_setfiletype_completion()
621621
call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
622622
call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)
623623
endfunc
624+
625+
" Test for ':filetype detect' command for a buffer without a file
626+
func Test_emptybuf_ftdetect()
627+
new
628+
call setline(1, '#!/bin/sh')
629+
call assert_equal('', &filetype)
630+
filetype detect
631+
call assert_equal('sh', &filetype)
632+
close!
633+
endfunc
634+
635+
" Test for ':filetype indent on' and ':filetype indent off' commands
636+
func Test_filetype_indent_off()
637+
new Xtest.vim
638+
filetype indent on
639+
call assert_equal(1, g:did_indent_on)
640+
filetype indent off
641+
call assert_equal(0, exists('g:did_indent_on'))
642+
close
643+
endfunc
644+
645+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_findfile.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,43 @@ func Test_finddir_error()
183183
call assert_fails('call finddir("x", "**x")', 'E343:')
184184
call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:')
185185
endfunc
186+
187+
" Test for the :find, :sfind and :tabfind commands
188+
func Test_find_cmd()
189+
new
190+
let save_path = &path
191+
let save_dir = getcwd()
192+
set path=.,./**/*
193+
call CreateFiles()
194+
cd Xdir1
195+
196+
" Test for :find
197+
find foo
198+
call assert_equal('foo', expand('%:.'))
199+
2find foo
200+
call assert_equal('Xdir2/foo', expand('%:.'))
201+
call assert_fails('3find foo', 'E347:')
202+
203+
" Test for :sfind
204+
enew
205+
sfind barfoo
206+
call assert_equal('Xdir2/Xdir3/barfoo', expand('%:.'))
207+
call assert_equal(3, winnr('$'))
208+
close
209+
call assert_fails('sfind baz', 'E345:')
210+
call assert_equal(2, winnr('$'))
211+
212+
" Test for :tabfind
213+
enew
214+
tabfind foobar
215+
call assert_equal('Xdir2/foobar', expand('%:.'))
216+
call assert_equal(2, tabpagenr('$'))
217+
tabclose
218+
call assert_fails('tabfind baz', 'E345:')
219+
call assert_equal(1, tabpagenr('$'))
220+
221+
call chdir(save_dir)
222+
call CleanFiles()
223+
let &path = save_path
224+
close
225+
endfunc

src/testdir/test_join.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,5 +436,11 @@ func Test_join_lines()
436436
call setline(1, ['a', 'b', '', 'c', 'd'])
437437
normal 5J
438438
call assert_equal('a b c d', getline(1))
439+
call setline(1, ['a', 'b', 'c'])
440+
2,2join
441+
call assert_equal(['a', 'b', 'c'], getline(1, '$'))
442+
call assert_equal(2, line('.'))
443+
2join
444+
call assert_equal(['a', 'b c'], getline(1, '$'))
439445
bwipe!
440446
endfunc

src/testdir/test_move.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func Test_move()
3838
call assert_fails("move -100", 'E16:')
3939
call assert_fails("move +100", 'E16:')
4040
call assert_fails('move', 'E16:')
41+
call assert_fails("move 'r", 'E20:')
4142

4243
%bwipeout!
4344
endfunc

0 commit comments

Comments
 (0)