1" Test argument list commands 2 3func Test_argidx() 4 args a b c 5 last 6 call assert_equal(2, argidx()) 7 %argdelete 8 call assert_equal(0, argidx()) 9 " doing it again doesn't result in an error 10 %argdelete 11 call assert_equal(0, argidx()) 12 call assert_fails('2argdelete', 'E16:') 13 14 args a b c 15 call assert_equal(0, argidx()) 16 next 17 call assert_equal(1, argidx()) 18 next 19 call assert_equal(2, argidx()) 20 1argdelete 21 call assert_equal(1, argidx()) 22 1argdelete 23 call assert_equal(0, argidx()) 24 1argdelete 25 call assert_equal(0, argidx()) 26endfunc 27 28func Test_argadd() 29 %argdelete 30 argadd a b c 31 call assert_equal(0, argidx()) 32 33 %argdelete 34 argadd a 35 call assert_equal(0, argidx()) 36 argadd b c d 37 call assert_equal(0, argidx()) 38 39 call Init_abc() 40 argadd x 41 call Assert_argc(['a', 'b', 'x', 'c']) 42 call assert_equal(1, argidx()) 43 44 call Init_abc() 45 0argadd x 46 call Assert_argc(['x', 'a', 'b', 'c']) 47 call assert_equal(2, argidx()) 48 49 call Init_abc() 50 1argadd x 51 call Assert_argc(['a', 'x', 'b', 'c']) 52 call assert_equal(2, argidx()) 53 54 call Init_abc() 55 $argadd x 56 call Assert_argc(['a', 'b', 'c', 'x']) 57 call assert_equal(1, argidx()) 58 59 call Init_abc() 60 $argadd x 61 +2argadd y 62 call Assert_argc(['a', 'b', 'c', 'x', 'y']) 63 call assert_equal(1, argidx()) 64 65 %argd 66 edit d 67 arga 68 call assert_equal(1, len(argv())) 69 call assert_equal('d', get(argv(), 0, '')) 70 71 %argd 72 edit some\ file 73 arga 74 call assert_equal(1, len(argv())) 75 call assert_equal('some file', get(argv(), 0, '')) 76 77 %argd 78 new 79 arga 80 call assert_equal(0, len(argv())) 81endfunc 82 83func Init_abc() 84 args a b c 85 next 86endfunc 87 88func Assert_argc(l) 89 call assert_equal(len(a:l), argc()) 90 let i = 0 91 while i < len(a:l) && i < argc() 92 call assert_equal(a:l[i], argv(i)) 93 let i += 1 94 endwhile 95endfunc 96 97" Test for [count]argument and [count]argdelete commands 98" Ported from the test_argument_count.in test script 99func Test_argument() 100 " Clean the argument list 101 arga a | %argd 102 103 let save_hidden = &hidden 104 set hidden 105 106 let g:buffers = [] 107 augroup TEST 108 au BufEnter * call add(buffers, expand('%:t')) 109 augroup END 110 111 argadd a b c d 112 $argu 113 $-argu 114 -argu 115 1argu 116 +2argu 117 118 augroup TEST 119 au! 120 augroup END 121 122 call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers) 123 124 redir => result 125 ar 126 redir END 127 call assert_true(result =~# 'a b \[c] d') 128 129 .argd 130 call assert_equal(['a', 'b', 'd'], argv()) 131 132 -argd 133 call assert_equal(['a', 'd'], argv()) 134 135 $argd 136 call assert_equal(['a'], argv()) 137 138 1arga c 139 1arga b 140 $argu 141 $arga x 142 call assert_equal(['a', 'b', 'c', 'x'], argv()) 143 144 0arga y 145 call assert_equal(['y', 'a', 'b', 'c', 'x'], argv()) 146 147 %argd 148 call assert_equal([], argv()) 149 150 arga a b c d e f 151 2,$-argd 152 call assert_equal(['a', 'f'], argv()) 153 154 let &hidden = save_hidden 155 156 " Setting argument list should fail when the current buffer has unsaved 157 " changes 158 %argd 159 enew! 160 set modified 161 call assert_fails('args x y z', 'E37:') 162 args! x y z 163 call assert_equal(['x', 'y', 'z'], argv()) 164 call assert_equal('x', expand('%:t')) 165 166 last | enew | argu 167 call assert_equal('z', expand('%:t')) 168 169 %argdelete 170 call assert_fails('argument', 'E163:') 171endfunc 172 173" Test for 0argadd and 0argedit 174" Ported from the test_argument_0count.in test script 175func Test_zero_argadd() 176 " Clean the argument list 177 arga a | %argd 178 179 arga a b c d 180 2argu 181 0arga added 182 call assert_equal(['added', 'a', 'b', 'c', 'd'], argv()) 183 184 2argu 185 arga third 186 call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv()) 187 188 %argd 189 arga a b c d 190 2argu 191 0arge edited 192 call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv()) 193 194 2argu 195 arga third 196 call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv()) 197 198 2argu 199 argedit file\ with\ spaces another file 200 call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv()) 201 call assert_equal('file with spaces', expand('%')) 202endfunc 203 204func Reset_arglist() 205 args a | %argd 206endfunc 207 208" Test for argc() 209func Test_argc() 210 call Reset_arglist() 211 call assert_equal(0, argc()) 212 argadd a b 213 call assert_equal(2, argc()) 214endfunc 215 216" Test for arglistid() 217func Test_arglistid() 218 call Reset_arglist() 219 arga a b 220 call assert_equal(0, arglistid()) 221 split 222 arglocal 223 call assert_equal(1, arglistid()) 224 tabnew | tabfirst 225 call assert_equal(0, arglistid(2)) 226 call assert_equal(1, arglistid(1, 1)) 227 call assert_equal(0, arglistid(2, 1)) 228 call assert_equal(1, arglistid(1, 2)) 229 tabonly | only | enew! 230 argglobal 231 call assert_equal(0, arglistid()) 232endfunc 233 234" Test for argv() 235func Test_argv() 236 call Reset_arglist() 237 call assert_equal([], argv()) 238 call assert_equal("", argv(2)) 239 argadd a b c d 240 call assert_equal('c', argv(2)) 241endfunc 242 243" Test for the :argedit command 244func Test_argedit() 245 call Reset_arglist() 246 argedit a 247 call assert_equal(['a'], argv()) 248 call assert_equal('a', expand('%:t')) 249 argedit b 250 call assert_equal(['a', 'b'], argv()) 251 call assert_equal('b', expand('%:t')) 252 argedit a 253 call assert_equal(['a', 'b', 'a'], argv()) 254 call assert_equal('a', expand('%:t')) 255 " When file name case is ignored, an existing buffer with only case 256 " difference is re-used. Make sure they don't exist so the case is 257 " preserved. 258 bwipe! c 259 bwipe! d 260 argedit C D 261 call assert_equal('C', expand('%:t')) 262 call assert_equal(['a', 'b', 'a', 'C', 'D'], argv()) 263 argedit c 264 if has('fname_case') 265 call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv()) 266 else 267 call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv()) 268 endif 269 0argedit x 270 if has('fname_case') 271 call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) 272 else 273 call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) 274 endif 275 enew! | set modified 276 call assert_fails('argedit y', 'E37:') 277 argedit! y 278 if has('fname_case') 279 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) 280 else 281 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) 282 endif 283 %argd 284 bwipe! C 285 bwipe! D 286endfunc 287 288" Test for the :argdelete command 289func Test_argdelete() 290 call Reset_arglist() 291 args aa a aaa b bb 292 argdelete a* 293 call assert_equal(['b', 'bb'], argv()) 294 call assert_equal('aa', expand('%:t')) 295 last 296 argdelete % 297 call assert_equal(['b'], argv()) 298 call assert_fails('argdelete', 'E471:') 299 call assert_fails('1,100argdelete', 'E16:') 300 %argd 301endfunc 302 303" Tests for the :next, :prev, :first, :last, :rewind commands 304func Test_argpos() 305 call Reset_arglist() 306 args a b c d 307 last 308 call assert_equal(3, argidx()) 309 call assert_fails('next', 'E165:') 310 prev 311 call assert_equal(2, argidx()) 312 Next 313 call assert_equal(1, argidx()) 314 first 315 call assert_equal(0, argidx()) 316 call assert_fails('prev', 'E164:') 317 3next 318 call assert_equal(3, argidx()) 319 rewind 320 call assert_equal(0, argidx()) 321 %argd 322endfunc 323 324" Test for autocommand that redefines the argument list, when doing ":all". 325func Test_arglist_autocmd() 326 autocmd BufReadPost Xxx2 next Xxx2 Xxx1 327 call writefile(['test file Xxx1'], 'Xxx1') 328 call writefile(['test file Xxx2'], 'Xxx2') 329 call writefile(['test file Xxx3'], 'Xxx3') 330 331 new 332 " redefine arglist; go to Xxx1 333 next! Xxx1 Xxx2 Xxx3 334 " open window for all args 335 all 336 call assert_equal('test file Xxx1', getline(1)) 337 wincmd w 338 wincmd w 339 call assert_equal('test file Xxx1', getline(1)) 340 " should now be in Xxx2 341 rewind 342 call assert_equal('test file Xxx2', getline(1)) 343 344 autocmd! BufReadPost Xxx2 345 enew! | only 346 call delete('Xxx1') 347 call delete('Xxx2') 348 call delete('Xxx3') 349 argdelete Xxx* 350 bwipe! Xxx1 Xxx2 Xxx3 351endfunc 352 353func Test_arg_all_expand() 354 call writefile(['test file Xxx1'], 'Xx x') 355 next notexist Xx\ x runtest.vim 356 call assert_equal('notexist Xx\ x runtest.vim', expand('##')) 357 call delete('Xx x') 358endfunc 359