Skip to content

Commit f0cee19

Browse files
committed
patch 8.2.0261: some code not covered by tests
Problem: Some code not covered by tests. Solution: Add test cases. (Yegappan Lakshmanan, closes #5645)
1 parent f414048 commit f0cee19

11 files changed

Lines changed: 223 additions & 0 deletions

src/testdir/test_buffer.vim

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,97 @@ func Test_bunload_with_offset()
6161
call delete('b2')
6262
call delete('b3')
6363
call delete('b4')
64+
65+
call assert_fails('1,4bunload', 'E16:')
66+
call assert_fails(',100bunload', 'E16:')
67+
68+
" Use a try-catch for this test. When assert_fails() is used for this
69+
" test, the command fails with E515: instead of E90:
70+
let caught_E90 = 0
71+
try
72+
$bunload
73+
catch /E90:/
74+
let caught_E90 = 1
75+
endtry
76+
call assert_equal(1, caught_E90)
77+
call assert_fails('$bunload', 'E515:')
78+
endfunc
79+
80+
" Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified
81+
" commands
82+
func Test_buflist_browse()
83+
%bwipe!
84+
call assert_fails('buffer 1000', 'E86:')
85+
86+
call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xfile1')
87+
call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xfile2')
88+
call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xfile3')
89+
edit Xfile1
90+
let b1 = bufnr()
91+
edit Xfile2
92+
let b2 = bufnr()
93+
edit +/baz4 Xfile3
94+
let b3 = bufnr()
95+
96+
call assert_fails('buffer ' .. b1 .. ' abc', 'E488:')
97+
call assert_equal(b3, bufnr())
98+
call assert_equal(4, line('.'))
99+
exe 'buffer +/bar2 ' .. b2
100+
call assert_equal(b2, bufnr())
101+
call assert_equal(2, line('.'))
102+
exe 'buffer +/bar1'
103+
call assert_equal(b2, bufnr())
104+
call assert_equal(1, line('.'))
105+
106+
brewind +/foo3
107+
call assert_equal(b1, bufnr())
108+
call assert_equal(3, line('.'))
109+
110+
blast +/baz2
111+
call assert_equal(b3, bufnr())
112+
call assert_equal(2, line('.'))
113+
114+
bprevious +/bar4
115+
call assert_equal(b2, bufnr())
116+
call assert_equal(4, line('.'))
117+
118+
bnext +/baz3
119+
call assert_equal(b3, bufnr())
120+
call assert_equal(3, line('.'))
121+
122+
call assert_fails('bmodified', 'E84:')
123+
call setbufvar(b2, '&modified', 1)
124+
exe 'bmodified +/bar3'
125+
call assert_equal(b2, bufnr())
126+
call assert_equal(3, line('.'))
127+
128+
" With no listed buffers in the list, :bnext and :bprev should fail
129+
%bwipe!
130+
set nobuflisted
131+
call assert_fails('bnext', 'E85:')
132+
call assert_fails('bprev', 'E85:')
133+
set buflisted
134+
135+
call assert_fails('sandbox bnext', 'E48:')
136+
137+
call delete('Xfile1')
138+
call delete('Xfile2')
139+
call delete('Xfile3')
140+
%bwipe!
141+
endfunc
142+
143+
" Test for :bdelete
144+
func Test_bdelete_cmd()
145+
%bwipe!
146+
call assert_fails('bdelete 5', 'E516:')
147+
148+
" Deleting a unlisted and unloaded buffer
149+
edit Xfile1
150+
let bnr = bufnr()
151+
set nobuflisted
152+
enew
153+
call assert_fails('bdelete ' .. bnr, 'E516:')
154+
%bwipe!
64155
endfunc
65156

66157
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_cmdline.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,32 @@ func Test_cmdline_search_range()
632632
1,\&s/b/B/
633633
call assert_equal('B', getline(2))
634634

635+
let @/ = 'apple'
636+
call assert_fails('\/print', 'E486:')
637+
635638
bwipe!
636639
endfunc
637640

641+
" Test for the tick mark (') in an excmd range
642+
func Test_tick_mark_in_range()
643+
" If only the tick is passed as a range and no command is specified, there
644+
" should not be an error
645+
call feedkeys(":'\<CR>", 'xt')
646+
call assert_equal("'", getreg(':'))
647+
call assert_fails("',print", 'E78:')
648+
endfunc
649+
650+
" Test for using a line number followed by a search pattern as range
651+
func Test_lnum_and_pattern_as_range()
652+
new
653+
call setline(1, ['foo 1', 'foo 2', 'foo 3'])
654+
let @" = ''
655+
2/foo/yank
656+
call assert_equal("foo 3\n", @")
657+
call assert_equal(1, line('.'))
658+
close!
659+
endfunc
660+
638661
" Tests for getcmdline(), getcmdpos() and getcmdtype()
639662
func Check_cmdline(cmdtype)
640663
call assert_equal('MyCmd a', getcmdline())
@@ -934,4 +957,24 @@ func Test_cmdline_expand_special()
934957
call assert_fails('e <amatch>', 'E497:')
935958
endfunc
936959

960+
func Test_cmdwin_jump_to_win()
961+
call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
962+
new
963+
set modified
964+
call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
965+
close!
966+
call feedkeys("q/:close\<CR>", "xt")
967+
call assert_equal(1, winnr('$'))
968+
call feedkeys("q/:exit\<CR>", "xt")
969+
call assert_equal(1, winnr('$'))
970+
endfunc
971+
972+
" Test for backtick expression in the command line
973+
func Test_cmd_backtick()
974+
%argd
975+
argadd `=['a', 'b', 'c']`
976+
call assert_equal(['a', 'b', 'c'], argv())
977+
%argd
978+
endfunc
979+
937980
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_exists.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ func Test_exists()
9494
call assert_equal(0, exists(':edit/a'))
9595
" Valid internal command (partial match)
9696
call assert_equal(1, exists(':q'))
97+
" Valid internal command with a digit
98+
call assert_equal(2, exists(':2match'))
9799
" Non-existing internal command
98100
call assert_equal(0, exists(':invalidcmd'))
101+
" Internal command with a count
102+
call assert_equal(0, exists(':3buffer'))
99103

100104
" User defined command (full match)
101105
command! MyCmd :echo 'My command'

src/testdir/test_filechanged.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,18 @@ func Test_file_changed_dialog()
146146
bwipe!
147147
call delete('Xchanged_d')
148148
endfunc
149+
150+
" Test for editing a new buffer from a FileChangedShell autocmd
151+
func Test_FileChangedShell_newbuf()
152+
call writefile(['one', 'two'], 'Xfile')
153+
new Xfile
154+
augroup testnewbuf
155+
autocmd FileChangedShell * enew
156+
augroup END
157+
call writefile(['red'], 'Xfile')
158+
call assert_fails('checktime', 'E811:')
159+
au! testnewbuf
160+
call delete('Xfile')
161+
endfunc
162+
163+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_fileformat.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,23 @@ func Test_fileformats()
276276
call delete('XXUxDsMc')
277277
call delete('Xtest')
278278
endfunc
279+
280+
" Test for changing the fileformat using ++read
281+
func Test_fileformat_plusplus_read()
282+
new
283+
call setline(1, ['one', 'two', 'three'])
284+
w ++ff=dos Xfile1
285+
enew!
286+
r ++fileformat=unix Xfile1
287+
call assert_equal('unix', &fileformat)
288+
3r ++edit Xfile1
289+
call assert_equal('dos', &fileformat)
290+
close!
291+
call delete('Xfile1')
292+
set fileformat&
293+
call assert_fails('e ++fileformat Xfile1', 'E474:')
294+
call assert_fails('e ++ff=abc Xfile1', 'E474:')
295+
call assert_fails('e ++abc1 Xfile1', 'E474:')
296+
endfunc
297+
298+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_mapping.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func Test_abclear()
3838

3939
abclear
4040
call assert_equal("\n\nNo abbreviation found", execute('abbrev'))
41+
call assert_fails('%abclear', 'E481:')
4142
endfunc
4243

4344
func Test_abclear_buffer()

src/testdir/test_marks.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,13 @@ func Test_lockmarks_with_put()
212212
bwipe!
213213
endfunc
214214

215+
" Test for :k command to set a mark
216+
func Test_marks_k_cmd()
217+
new
218+
call setline(1, ['foo', 'bar', 'baz', 'qux'])
219+
1,3kr
220+
call assert_equal([0, 3, 1, 0], getpos("'r"))
221+
close!
222+
endfunc
223+
215224
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_normal.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,3 +2705,19 @@ func Test_normal_gk()
27052705
bw!
27062706
set cpoptions& number& numberwidth&
27072707
endfunc
2708+
2709+
" Test for cursor movement with '-' in 'cpoptions'
2710+
func Test_normal_cpo_minus()
2711+
new
2712+
call setline(1, ['foo', 'bar', 'baz'])
2713+
let save_cpo = &cpo
2714+
set cpo+=-
2715+
call assert_beeps('normal 10j')
2716+
call assert_equal(1, line('.'))
2717+
normal G
2718+
call assert_beeps('normal 10k')
2719+
call assert_equal(3, line('.'))
2720+
call assert_fails(10, 'E16:')
2721+
let &cpo = save_cpo
2722+
close!
2723+
endfunc

src/testdir/test_plus_arg_edit.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ func Test_edit_bad()
3232
bw!
3333
call delete('Xfile')
3434
endfunc
35+
36+
" Test for ++bin and ++nobin arguments
37+
func Test_binary_arg()
38+
new
39+
edit ++bin Xfile1
40+
call assert_equal(1, &binary)
41+
edit ++nobin Xfile2
42+
call assert_equal(0, &binary)
43+
call assert_fails('edit ++binabc Xfile3', 'E474:')
44+
close!
45+
endfunc
46+
47+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_quickfix.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,15 @@ func Xtest_browse(cchar)
538538
10Xcc
539539
call assert_equal(11, line('.'))
540540
call assert_equal('Xqftestfile2', bufname('%'))
541+
Xopen
542+
call cursor(2, 1)
543+
if a:cchar == 'c'
544+
.cc
545+
else
546+
.ll
547+
endif
548+
call assert_equal(6, line('.'))
549+
call assert_equal('Xqftestfile1', bufname('%'))
541550

542551
" Jumping to an error from the error window (when only the error window is
543552
" present)

0 commit comments

Comments
 (0)