comparison src/testdir/test_usercommands.vim @ 16413:4734d601ebdd v8.1.1211

patch 8.1.1211: not all user command code is tested commit https://github.com/vim/vim/commit/e61e548dd6a20471fd81160b1c2a16089505ec8c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 27 15:05:12 2019 +0200 patch 8.1.1211: not all user command code is tested Problem: Not all user command code is tested. Solution: Add more tests.
author Bram Moolenaar <Bram@vim.org>
date Sat, 27 Apr 2019 15:15:07 +0200
parents 250420b35b10
children 854fb0ad4be6
comparison
equal deleted inserted replaced
16412:e7c242103171 16413:4734d601ebdd
71 delcommand MyCmd 71 delcommand MyCmd
72 delcommand MyQCmd 72 delcommand MyQCmd
73 unlet g:mods 73 unlet g:mods
74 endfunction 74 endfunction
75 75
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
76 func Test_Ambiguous() 167 func Test_Ambiguous()
77 command Doit let g:didit = 'yes' 168 command Doit let g:didit = 'yes'
78 command Dothat let g:didthat = 'also' 169 command Dothat let g:didthat = 'also'
79 call assert_fails('Do', 'E464:') 170 call assert_fails('Do', 'E464:')
80 Doit 171 Doit
86 177
87 delcommand Doit 178 delcommand Doit
88 Do 179 Do
89 call assert_equal('also', g:didthat) 180 call assert_equal('also', g:didthat)
90 delcommand Dothat 181 delcommand Dothat
182
183 call assert_fails("\x4ei\041", ' you demand a ')
91 endfunc 184 endfunc
92 185
93 func Test_redefine_on_reload() 186 func Test_redefine_on_reload()
94 call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists') 187 call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists')
95 call assert_equal(0, exists(':ExistingCommand')) 188 call assert_equal(0, exists(':ExistingCommand'))
137 call assert_fails('com! _ :', 'E182:') 230 call assert_fails('com! _ :', 'E182:')
138 call assert_fails('com! X :', 'E841:') 231 call assert_fails('com! X :', 'E841:')
139 call assert_fails('com! - DoCmd :', 'E175:') 232 call assert_fails('com! - DoCmd :', 'E175:')
140 call assert_fails('com! -xxx DoCmd :', 'E181:') 233 call assert_fails('com! -xxx DoCmd :', 'E181:')
141 call assert_fails('com! -addr DoCmd :', 'E179:') 234 call assert_fails('com! -addr DoCmd :', 'E179:')
235 call assert_fails('com! -addr=asdf DoCmd :', 'E180:')
142 call assert_fails('com! -complete DoCmd :', 'E179:') 236 call assert_fails('com! -complete DoCmd :', 'E179:')
143 call assert_fails('com! -complete=xxx DoCmd :', 'E180:') 237 call assert_fails('com! -complete=xxx DoCmd :', 'E180:')
144 call assert_fails('com! -complete=custom DoCmd :', 'E467:') 238 call assert_fails('com! -complete=custom DoCmd :', 'E467:')
145 call assert_fails('com! -complete=customlist DoCmd :', 'E467:') 239 call assert_fails('com! -complete=customlist DoCmd :', 'E467:')
146 call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:') 240 call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:')