Skip to content

Commit e61e548

Browse files
committed
patch 8.1.1211: not all user command code is tested
Problem: Not all user command code is tested. Solution: Add more tests.
1 parent ac9fb18 commit e61e548

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

src/testdir/test_usercommands.vim

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,97 @@ function Test_cmdmods()
7373
unlet g:mods
7474
endfunction
7575

76+
func SaveCmdArgs(...)
77+
let g:args = a:000
78+
endfunc
79+
80+
func Test_f_args()
81+
command -nargs=* TestFArgs call SaveCmdArgs(<f-args>)
82+
83+
TestFArgs
84+
call assert_equal([], g:args)
85+
86+
TestFArgs one two three
87+
call assert_equal(['one', 'two', 'three'], g:args)
88+
89+
TestFArgs one\\two three
90+
call assert_equal(['one\two', 'three'], g:args)
91+
92+
TestFArgs one\ two three
93+
call assert_equal(['one two', 'three'], g:args)
94+
95+
TestFArgs one\"two three
96+
call assert_equal(['one\"two', 'three'], g:args)
97+
98+
delcommand TestFArgs
99+
endfunc
100+
101+
func Test_q_args()
102+
command -nargs=* TestQArgs call SaveCmdArgs(<q-args>)
103+
104+
TestQArgs
105+
call assert_equal([''], g:args)
106+
107+
TestQArgs one two three
108+
call assert_equal(['one two three'], g:args)
109+
110+
TestQArgs one\\two three
111+
call assert_equal(['one\\two three'], g:args)
112+
113+
TestQArgs one\ two three
114+
call assert_equal(['one\ two three'], g:args)
115+
116+
TestQArgs one\"two three
117+
call assert_equal(['one\"two three'], g:args)
118+
119+
delcommand TestQArgs
120+
endfunc
121+
122+
func Test_reg_arg()
123+
command -nargs=* -reg TestRegArg call SaveCmdArgs("<reg>", "<register>")
124+
125+
TestRegArg
126+
call assert_equal(['', ''], g:args)
127+
128+
TestRegArg x
129+
call assert_equal(['x', 'x'], g:args)
130+
131+
delcommand TestRegArg
132+
endfunc
133+
134+
func Test_no_arg()
135+
command -nargs=* TestNoArg call SaveCmdArgs("<args>", "<>", "<x>", "<lt>")
136+
137+
TestNoArg
138+
call assert_equal(['', '<>', '<x>', '<'], g:args)
139+
140+
TestNoArg one
141+
call assert_equal(['one', '<>', '<x>', '<'], g:args)
142+
143+
delcommand TestNoArg
144+
endfunc
145+
146+
func Test_range_arg()
147+
command -range TestRangeArg call SaveCmdArgs(<range>, <line1>, <line2>)
148+
new
149+
call setline(1, range(100))
150+
let lnum = line('.')
151+
152+
TestRangeArg
153+
call assert_equal([0, lnum, lnum], g:args)
154+
155+
99TestRangeArg
156+
call assert_equal([1, 99, 99], g:args)
157+
158+
88,99TestRangeArg
159+
call assert_equal([2, 88, 99], g:args)
160+
161+
call assert_fails('102TestRangeArg', 'E16:')
162+
163+
bwipe!
164+
delcommand TestRangeArg
165+
endfunc
166+
76167
func Test_Ambiguous()
77168
command Doit let g:didit = 'yes'
78169
command Dothat let g:didthat = 'also'
@@ -88,6 +179,8 @@ func Test_Ambiguous()
88179
Do
89180
call assert_equal('also', g:didthat)
90181
delcommand Dothat
182+
183+
call assert_fails("\x4ei\041", ' you demand a ')
91184
endfunc
92185

93186
func Test_redefine_on_reload()
@@ -139,6 +232,7 @@ func Test_CmdErrors()
139232
call assert_fails('com! - DoCmd :', 'E175:')
140233
call assert_fails('com! -xxx DoCmd :', 'E181:')
141234
call assert_fails('com! -addr DoCmd :', 'E179:')
235+
call assert_fails('com! -addr=asdf DoCmd :', 'E180:')
142236
call assert_fails('com! -complete DoCmd :', 'E179:')
143237
call assert_fails('com! -complete=xxx DoCmd :', 'E180:')
144238
call assert_fails('com! -complete=custom DoCmd :', 'E467:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1211,
770772
/**/
771773
1210,
772774
/**/

0 commit comments

Comments
 (0)