test_excmd.vim (25545B)
1 " Tests for various Ex commands. 2 3 source check.vim 4 source shared.vim 5 source term_util.vim 6 source screendump.vim 7 8 func Test_ex_delete() 9 new 10 call setline(1, ['a', 'b', 'c']) 11 2 12 " :dl is :delete with the "l" flag, not :dlist 13 .dl 14 call assert_equal(['a', 'c'], getline(1, 2)) 15 endfunc 16 17 func Test_range_error() 18 call assert_fails(':.echo 1', 'E481:') 19 call assert_fails(':$echo 1', 'E481:') 20 call assert_fails(':1,2echo 1', 'E481:') 21 call assert_fails(':+1echo 1', 'E481:') 22 call assert_fails(':/1/echo 1', 'E481:') 23 call assert_fails(':\/echo 1', 'E481:') 24 normal vv 25 call assert_fails(":'<,'>echo 1", 'E481:') 26 call assert_fails(":\\xcenter", 'E10:') 27 endfunc 28 29 func Test_buffers_lastused() 30 edit bufc " oldest 31 32 sleep 1200m 33 edit bufa " middle 34 35 sleep 1200m 36 edit bufb " newest 37 38 enew 39 40 let ls = split(execute('buffers t', 'silent!'), '\n') 41 let bufs = [] 42 for line in ls 43 let bufs += [split(line, '"\s*')[1:2]] 44 endfor 45 46 let names = [] 47 for buf in bufs 48 if buf[0] !=# '[No Name]' 49 let names += [buf[0]] 50 endif 51 endfor 52 53 call assert_equal(['bufb', 'bufa', 'bufc'], names) 54 call assert_match('[0-2] seconds\= ago', bufs[1][1]) 55 56 bwipeout bufa 57 bwipeout bufb 58 bwipeout bufc 59 endfunc 60 61 " Test for the :copy command 62 func Test_copy() 63 new 64 65 call setline(1, ['L1', 'L2', 'L3', 'L4']) 66 " copy lines in a range to inside the range 67 1,3copy 2 68 call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7)) 69 70 " Specifying a count before using : to run an ex-command 71 exe "normal! gg4:yank\<CR>" 72 call assert_equal("L1\nL2\nL1\nL2\n", @") 73 74 close! 75 endfunc 76 77 " Test for the :file command 78 func Test_file_cmd() 79 call assert_fails('3file', 'E474:') 80 call assert_fails('0,0file', 'E474:') 81 call assert_fails('0file abc', 'E474:') 82 if !has('win32') 83 " Change the name of the buffer to the same name 84 new Xfile1 85 file Xfile1 86 call assert_equal('Xfile1', @%) 87 call assert_equal('Xfile1', @#) 88 bw! 89 endif 90 endfunc 91 92 " Test for the :drop command 93 func Test_drop_cmd() 94 call writefile(['L1', 'L2'], 'Xdropfile', 'D') 95 " Test for reusing the current buffer 96 enew | only 97 let expected_nr = bufnr() 98 drop Xdropfile 99 call assert_equal(expected_nr, bufnr()) 100 call assert_equal('L2', getline(2)) 101 " Test for switching to an existing window 102 below new 103 drop Xdropfile 104 call assert_equal(1, winnr()) 105 " Test for splitting the current window (set nohidden) 106 enew | only 107 set modified 108 drop Xdropfile 109 call assert_equal(2, winnr('$')) 110 " Not splitting the current window even if modified (set hidden) 111 set hidden 112 enew | only 113 set modified 114 drop Xdropfile 115 call assert_equal(1, winnr('$')) 116 " Check for setting the argument list 117 call assert_equal(['Xdropfile'], argv()) 118 enew | only! 119 endfunc 120 121 " Test for the :append command 122 func Test_append_cmd() 123 new 124 call setline(1, [' L1']) 125 call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 126 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 127 %delete _ 128 " append after a specific line 129 call setline(1, [' L1', ' L2', ' L3']) 130 call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 131 call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$')) 132 %delete _ 133 " append with toggling 'autoindent' 134 call setline(1, [' L1']) 135 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 136 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 137 call assert_false(&autoindent) 138 %delete _ 139 " append with 'autoindent' set and toggling 'autoindent' 140 set autoindent 141 call setline(1, [' L1']) 142 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 143 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$')) 144 call assert_true(&autoindent) 145 set autoindent& 146 close! 147 endfunc 148 149 func Test_append_cmd_empty_buf() 150 CheckRunVimInTerminal 151 let lines =<< trim END 152 func Timer(timer) 153 append 154 aaaaa 155 bbbbb 156 . 157 endfunc 158 call timer_start(10, 'Timer') 159 END 160 call writefile(lines, 'Xtest_append_cmd_empty_buf') 161 let buf = RunVimInTerminal('-S Xtest_append_cmd_empty_buf', {'rows': 6}) 162 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) 163 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) 164 165 " clean up 166 call StopVimInTerminal(buf) 167 call delete('Xtest_append_cmd_empty_buf') 168 endfunc 169 170 " Test for the :insert command 171 func Test_insert_cmd() 172 new 173 call setline(1, [' L1']) 174 call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 175 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 176 %delete _ 177 " insert before a specific line 178 call setline(1, [' L1', ' L2', ' L3']) 179 call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 180 call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$')) 181 %delete _ 182 " insert with toggling 'autoindent' 183 call setline(1, [' L1']) 184 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 185 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 186 call assert_false(&autoindent) 187 %delete _ 188 " insert with 'autoindent' set and toggling 'autoindent' 189 set autoindent 190 call setline(1, [' L1']) 191 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt') 192 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$')) 193 call assert_true(&autoindent) 194 set autoindent& 195 close! 196 endfunc 197 198 func Test_insert_cmd_empty_buf() 199 CheckRunVimInTerminal 200 let lines =<< trim END 201 func Timer(timer) 202 insert 203 aaaaa 204 bbbbb 205 . 206 endfunc 207 call timer_start(10, 'Timer') 208 END 209 call writefile(lines, 'Xtest_insert_cmd_empty_buf') 210 let buf = RunVimInTerminal('-S Xtest_insert_cmd_empty_buf', {'rows': 6}) 211 call WaitForAssert({-> assert_equal('bbbbb', term_getline(buf, 2))}) 212 call WaitForAssert({-> assert_equal('aaaaa', term_getline(buf, 1))}) 213 214 " clean up 215 call StopVimInTerminal(buf) 216 call delete('Xtest_insert_cmd_empty_buf') 217 endfunc 218 219 " Test for the :change command 220 func Test_change_cmd() 221 new 222 call setline(1, [' L1', 'L2', 'L3']) 223 call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 224 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 225 %delete _ 226 " change a specific line 227 call setline(1, [' L1', ' L2', ' L3']) 228 call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 229 call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$')) 230 %delete _ 231 " change with toggling 'autoindent' 232 call setline(1, [' L1', 'L2', 'L3']) 233 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 234 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 235 call assert_false(&autoindent) 236 %delete _ 237 " change with 'autoindent' set and toggling 'autoindent' 238 set autoindent 239 call setline(1, [' L1', 'L2', 'L3']) 240 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt') 241 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$')) 242 call assert_true(&autoindent) 243 set autoindent& 244 close! 245 endfunc 246 247 " Test for the :language command 248 func Test_language_cmd() 249 CheckFeature multi_lang 250 251 " OpenBSD allows nearly arbitrary locale names, since it largely ignores them 252 " (see setlocale(3)). One useful exception for this test is that in doesn't 253 " allow names containing dots unless they end in '.UTF-8'. 254 " 255 " Windows also allows nonsensical locale names, though it seems to reject 256 " names with multiple underscores (possibly expecting 'language_region', but 257 " not 'language_region_additional'). 258 call assert_fails('language ctype non_existing_lang.bad', 'E197:') 259 call assert_fails('language time non_existing_lang.bad', 'E197:') 260 endfunc 261 262 " Test for the :confirm command dialog 263 func Test_confirm_cmd() 264 CheckNotGui 265 CheckRunVimInTerminal 266 267 call writefile(['foo1'], 'Xfoo') 268 call writefile(['bar1'], 'Xbar') 269 270 " Test for saving all the modified buffers 271 let lines =<< trim END 272 set nomore 273 new Xfoo 274 call setline(1, 'foo2') 275 new Xbar 276 call setline(1, 'bar2') 277 wincmd b 278 END 279 call writefile(lines, 'Xscript') 280 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 281 call term_sendkeys(buf, ":confirm qall\n") 282 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 283 call term_sendkeys(buf, "A") 284 call StopVimInTerminal(buf) 285 286 call assert_equal(['foo2'], readfile('Xfoo')) 287 call assert_equal(['bar2'], readfile('Xbar')) 288 289 " Test for discarding all the changes to modified buffers 290 let lines =<< trim END 291 set nomore 292 new Xfoo 293 call setline(1, 'foo3') 294 new Xbar 295 call setline(1, 'bar3') 296 wincmd b 297 END 298 call writefile(lines, 'Xscript') 299 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 300 call term_sendkeys(buf, ":confirm qall\n") 301 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 302 call term_sendkeys(buf, "D") 303 call StopVimInTerminal(buf) 304 305 call assert_equal(['foo2'], readfile('Xfoo')) 306 call assert_equal(['bar2'], readfile('Xbar')) 307 308 " Test for saving and discarding changes to some buffers 309 let lines =<< trim END 310 set nomore 311 new Xfoo 312 call setline(1, 'foo4') 313 new Xbar 314 call setline(1, 'bar4') 315 wincmd b 316 END 317 call writefile(lines, 'Xscript') 318 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 319 call term_sendkeys(buf, ":confirm qall\n") 320 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000) 321 call term_sendkeys(buf, "N") 322 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, (C)ancel: ', term_getline(buf, 20))}, 1000) 323 call term_sendkeys(buf, "Y") 324 call StopVimInTerminal(buf) 325 326 call assert_equal(['foo4'], readfile('Xfoo')) 327 call assert_equal(['bar2'], readfile('Xbar')) 328 329 call delete('Xscript') 330 call delete('Xfoo') 331 call delete('Xbar') 332 endfunc 333 334 func Test_confirm_cmd_cancel() 335 CheckNotGui 336 CheckRunVimInTerminal 337 338 " Test for closing a window with a modified buffer 339 let lines =<< trim END 340 set nomore 341 new 342 call setline(1, 'abc') 343 END 344 call writefile(lines, 'Xscript') 345 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 346 call term_sendkeys(buf, ":confirm close\n") 347 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 348 \ term_getline(buf, 20))}, 1000) 349 call term_sendkeys(buf, "C") 350 call WaitForAssert({-> assert_equal('', term_getline(buf, 20))}, 1000) 351 call term_sendkeys(buf, ":confirm close\n") 352 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 353 \ term_getline(buf, 20))}, 1000) 354 call term_sendkeys(buf, "N") 355 call WaitForAssert({-> assert_match('^ *0,0-1 All$', 356 \ term_getline(buf, 20))}, 1000) 357 call StopVimInTerminal(buf) 358 call delete('Xscript') 359 endfunc 360 361 " The ":confirm" prompt was sometimes used with the terminal in cooked mode. 362 " This test verifies that a "\<CR>" character is NOT required to respond to a 363 " prompt from the ":conf q" and ":conf wq" commands. 364 func Test_confirm_q_wq() 365 CheckNotGui 366 CheckRunVimInTerminal 367 368 call writefile(['foo'], 'Xfoo') 369 370 let lines =<< trim END 371 set hidden nomore 372 call setline(1, 'abc') 373 edit Xfoo 374 END 375 call writefile(lines, 'Xscript') 376 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 377 call term_sendkeys(buf, ":confirm q\n") 378 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 379 \ term_getline(buf, 20))}, 1000) 380 call term_sendkeys(buf, 'C') 381 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', 382 \ term_getline(buf, 20))}, 1000) 383 384 call term_sendkeys(buf, ":edit Xfoo\n") 385 call term_sendkeys(buf, ":confirm wq\n") 386 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$', 387 \ term_getline(buf, 20))}, 1000) 388 call term_sendkeys(buf, 'C') 389 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$', 390 \ term_getline(buf, 20))}, 1000) 391 call StopVimInTerminal(buf) 392 393 call delete('Xscript') 394 call delete('Xfoo') 395 endfunc 396 397 func Test_confirm_write_ro() 398 CheckNotGui 399 CheckRunVimInTerminal 400 401 call writefile(['foo'], 'Xconfirm_write_ro') 402 let lines =<< trim END 403 set nobackup ff=unix cmdheight=2 404 edit Xconfirm_write_ro 405 norm Abar 406 END 407 call writefile(lines, 'Xscript') 408 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 409 410 " Try to write with 'ro' option. 411 call term_sendkeys(buf, ":set ro | confirm w\n") 412 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", 413 \ term_getline(buf, 18))}, 1000) 414 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', 415 \ term_getline(buf, 19))}, 1000) 416 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 417 call term_sendkeys(buf, 'N') 418 call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 19))}, 1000) 419 call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) 420 call assert_equal(['foo'], readfile('Xconfirm_write_ro')) 421 422 call term_sendkeys(buf, ":confirm w\n") 423 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$", 424 \ term_getline(buf, 18))}, 1000) 425 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$', 426 \ term_getline(buf, 19))}, 1000) 427 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 428 call term_sendkeys(buf, 'Y') 429 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 7B written$', 430 \ term_getline(buf, 19))}, 1000) 431 call assert_equal(['foobar'], readfile('Xconfirm_write_ro')) 432 433 " Try to write with read-only file permissions. 434 call setfperm('Xconfirm_write_ro', 'r--r--r--') 435 call term_sendkeys(buf, ":set noro | undo | confirm w\n") 436 call WaitForAssert({-> assert_match("^File permissions of \"Xconfirm_write_ro\" are read-only\. *$", 437 \ term_getline(buf, 17))}, 1000) 438 call WaitForAssert({-> assert_match('^It may still be possible to write it\. *$', 439 \ term_getline(buf, 18))}, 1000) 440 call WaitForAssert({-> assert_match('^Do you wish to try? *$', term_getline(buf, 19))}, 1000) 441 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000) 442 call term_sendkeys(buf, 'Y') 443 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$', 444 \ term_getline(buf, 19))}, 1000) 445 call assert_equal(['foo'], readfile('Xconfirm_write_ro')) 446 447 call StopVimInTerminal(buf) 448 call delete('Xscript') 449 call delete('Xconfirm_write_ro') 450 endfunc 451 452 func Test_confirm_write_partial_file() 453 CheckNotGui 454 CheckRunVimInTerminal 455 456 call writefile(['a', 'b', 'c', 'd'], 'Xwrite_partial') 457 call writefile(['set nobackup ff=unix cmdheight=2', 458 \ 'edit Xwrite_partial'], 'Xscript') 459 let buf = RunVimInTerminal('-S Xscript', {'rows': 20}) 460 461 call term_sendkeys(buf, ":confirm 2,3w\n") 462 call WaitForAssert({-> assert_match('^Write partial file? *$', 463 \ term_getline(buf, 19))}, 1000) 464 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', 465 \ term_getline(buf, 20))}, 1000) 466 call term_sendkeys(buf, 'N') 467 call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000) 468 call assert_equal(['a', 'b', 'c', 'd'], readfile('Xwrite_partial')) 469 call delete('Xwrite_partial') 470 471 call term_sendkeys(buf, ":confirm 2,3w\n") 472 call WaitForAssert({-> assert_match('^Write partial file? *$', 473 \ term_getline(buf, 19))}, 1000) 474 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', 475 \ term_getline(buf, 20))}, 1000) 476 call term_sendkeys(buf, 'Y') 477 call WaitForAssert({-> assert_match('^"Xwrite_partial" \[New\] 2L, 4B written *$', 478 \ term_getline(buf, 19))}, 1000) 479 call WaitForAssert({-> assert_match('^Press ENTER or type command to continue *$', 480 \ term_getline(buf, 20))}, 1000) 481 call assert_equal(['b', 'c'], readfile('Xwrite_partial')) 482 483 call StopVimInTerminal(buf) 484 call delete('Xwrite_partial') 485 call delete('Xscript') 486 endfunc 487 488 " Test for the :print command 489 func Test_print_cmd() 490 call assert_fails('print', 'E749:') 491 endfunc 492 493 " Test for the :winsize command 494 func Test_winsize_cmd() 495 call assert_fails('winsize 1', 'E465:') 496 call assert_fails('winsize 1 x', 'E465:') 497 call assert_fails('win_getid(1)', 'E475: Invalid argument: _getid(1)') 498 " Actually changing the window size would be flaky. 499 endfunc 500 501 " Test for the :redir command 502 " NOTE: if you run tests as root this will fail. Don't run tests as root! 503 func Test_redir_cmd() 504 call assert_fails('redir @@', 'E475:') 505 call assert_fails('redir abc', 'E475:') 506 call assert_fails('redir => 1abc', 'E474:') 507 call assert_fails('redir => a b', 'E488:') 508 call assert_fails('redir => abc[1]', 'E121:') 509 let b = 0zFF 510 call assert_fails('redir =>> b', 'E734:') 511 unlet b 512 513 if has('unix') 514 " Redirecting to a directory name 515 call mkdir('Xdir') 516 call assert_fails('redir > Xdir', 'E17:') 517 call delete('Xdir', 'd') 518 endif 519 520 " Test for redirecting to a register 521 redir @q> | echon 'clean ' | redir END 522 redir @q>> | echon 'water' | redir END 523 call assert_equal('clean water', @q) 524 525 " Test for redirecting to a variable 526 redir => color | echon 'blue ' | redir END 527 redir =>> color | echon 'sky' | redir END 528 call assert_equal('blue sky', color) 529 endfunc 530 531 func Test_redir_cmd_readonly() 532 CheckNotRoot 533 534 " Redirecting to a read-only file 535 call writefile([], 'Xfile') 536 call setfperm('Xfile', 'r--r--r--') 537 call assert_fails('redir! > Xfile', 'E190:') 538 call delete('Xfile') 539 endfunc 540 541 " Test for the :filetype command 542 func Test_filetype_cmd() 543 call assert_fails('filetype abc', 'E475:') 544 endfunc 545 546 " Test for the :mode command 547 func Test_mode_cmd() 548 call assert_fails('mode abc', 'E359:') 549 endfunc 550 551 " Test for the :sleep command 552 func Test_sleep_cmd() 553 call assert_fails('sleep x', 'E475:') 554 endfunc 555 556 " Test for the :read command 557 func Test_read_cmd() 558 call writefile(['one'], 'Xfile') 559 new 560 call assert_fails('read', 'E32:') 561 edit Xfile 562 read 563 call assert_equal(['one', 'one'], getline(1, '$')) 564 close! 565 new 566 read Xfile 567 call assert_equal(['', 'one'], getline(1, '$')) 568 call deletebufline('', 1, '$') 569 call feedkeys("Qr Xfile\<CR>visual\<CR>", 'xt') 570 call assert_equal(['one'], getline(1, '$')) 571 close! 572 call delete('Xfile') 573 endfunc 574 575 " Test for running Ex commands when text is locked. 576 " <C-\>e in the command line is used to lock the text 577 func Test_run_excmd_with_text_locked() 578 " :quit 579 let cmd = ":\<C-\>eexecute('quit')\<CR>\<C-C>" 580 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 581 582 " :qall 583 let cmd = ":\<C-\>eexecute('qall')\<CR>\<C-C>" 584 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 585 586 " :exit 587 let cmd = ":\<C-\>eexecute('exit')\<CR>\<C-C>" 588 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') 589 590 " :close - should be ignored 591 new 592 let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>" 593 call assert_equal(2, winnr('$')) 594 close 595 596 call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E565:') 597 598 " :tabfirst 599 tabnew 600 call assert_fails("call feedkeys(\":\<C-R>=execute('tabfirst')\<CR>\", 'xt')", 'E565:') 601 tabclose 602 endfunc 603 604 " Test for the :verbose command 605 func Test_verbose_cmd() 606 set verbose=3 607 call assert_match(' verbose=1\n\s*Last set from ', execute('verbose set vbs'), "\n") 608 call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n")) 609 set verbose=0 610 call assert_match(' verbose=4\n\s*Last set from .*\n verbose=0', 611 \ execute("4verbose set verbose | set verbose")) 612 endfunc 613 614 " Test for the :delete command and the related abbreviated commands 615 func Test_excmd_delete() 616 new 617 call setline(1, ['foo', "\tbar"]) 618 call assert_equal(['^Ibar$'], split(execute('dl'), "\n")) 619 call setline(1, ['foo', "\tbar"]) 620 call assert_equal(['^Ibar$'], split(execute('dell'), "\n")) 621 call setline(1, ['foo', "\tbar"]) 622 call assert_equal(['^Ibar$'], split(execute('delel'), "\n")) 623 call setline(1, ['foo', "\tbar"]) 624 call assert_equal(['^Ibar$'], split(execute('deletl'), "\n")) 625 call setline(1, ['foo', "\tbar"]) 626 call assert_equal(['^Ibar$'], split(execute('deletel'), "\n")) 627 call setline(1, ['foo', "\tbar"]) 628 call assert_equal([' bar'], split(execute('dp'), "\n")) 629 call setline(1, ['foo', "\tbar"]) 630 call assert_equal([' bar'], split(execute('dep'), "\n")) 631 call setline(1, ['foo', "\tbar"]) 632 call assert_equal([' bar'], split(execute('delp'), "\n")) 633 call setline(1, ['foo', "\tbar"]) 634 call assert_equal([' bar'], split(execute('delep'), "\n")) 635 call setline(1, ['foo', "\tbar"]) 636 call assert_equal([' bar'], split(execute('deletp'), "\n")) 637 call setline(1, ['foo', "\tbar"]) 638 call assert_equal([' bar'], split(execute('deletep'), "\n")) 639 close! 640 endfunc 641 642 " Test for commands that are blocked in a sandbox 643 func Sandbox_tests() 644 call assert_fails("call histadd(':', 'ls')", 'E48:') 645 call assert_fails("call mkdir('Xdir')", 'E48:') 646 call assert_fails("call rename('a', 'b')", 'E48:') 647 call assert_fails("call setbufvar(1, 'myvar', 1)", 'E48:') 648 call assert_fails("call settabvar(1, 'myvar', 1)", 'E48:') 649 call assert_fails("call settabwinvar(1, 1, 'myvar', 1)", 'E48:') 650 call assert_fails("call setwinvar(1, 'myvar', 1)", 'E48:') 651 call assert_fails("call timer_start(100, '')", 'E48:') 652 if has('channel') 653 call assert_fails("call prompt_setcallback(1, '')", 'E48:') 654 call assert_fails("call prompt_setinterrupt(1, '')", 'E48:') 655 call assert_fails("call prompt_setprompt(1, '')", 'E48:') 656 endif 657 call assert_fails("let $TESTVAR=1", 'E48:') 658 call assert_fails("call feedkeys('ivim')", 'E48:') 659 call assert_fails("source! Xfile", 'E48:') 660 call assert_fails("call delete('Xfile')", 'E48:') 661 call assert_fails("call writefile([], 'Xfile')", 'E48:') 662 call assert_fails('!ls', 'E48:') 663 " call assert_fails('shell', 'E48:') 664 call assert_fails('stop', 'E48:') 665 call assert_fails('exe "normal \<C-Z>"', 'E48:') 666 " set insertmode 667 " call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E48:') 668 " set insertmode& 669 call assert_fails('suspend', 'E48:') 670 call assert_fails('call system("ls")', 'E48:') 671 call assert_fails('call systemlist("ls")', 'E48:') 672 if has('clientserver') 673 call assert_fails('let s=remote_expr("gvim", "2+2")', 'E48:') 674 if !has('win32') 675 " remote_foreground() doesn't throw an error message on MS-Windows 676 call assert_fails('call remote_foreground("gvim")', 'E48:') 677 endif 678 call assert_fails('let s=remote_peek("gvim")', 'E48:') 679 call assert_fails('let s=remote_read("gvim")', 'E48:') 680 call assert_fails('let s=remote_send("gvim", "abc")', 'E48:') 681 call assert_fails('let s=server2client("gvim", "abc")', 'E48:') 682 endif 683 if has('terminal') 684 call assert_fails('terminal', 'E48:') 685 call assert_fails('call term_start("vim")', 'E48:') 686 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E48:') 687 endif 688 if has('channel') 689 call assert_fails("call ch_logfile('chlog')", 'E48:') 690 call assert_fails("call ch_open('localhost:8765')", 'E48:') 691 endif 692 if has('job') 693 call assert_fails("call job_start('vim')", 'E48:') 694 endif 695 if has('unix') && has('libcall') 696 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E48:') 697 endif 698 if has('unix') 699 call assert_fails('cd `pwd`', 'E48:') 700 endif 701 " some options cannot be changed in a sandbox 702 call assert_fails('set exrc', 'E48:') 703 call assert_fails('set cdpath', 'E48:') 704 if has('xim') && has('gui_gtk') 705 call assert_fails('set imstyle', 'E48:') 706 endif 707 endfunc 708 709 func Test_sandbox() 710 sandbox call Sandbox_tests() 711 endfunc 712 713 func Test_command_not_implemented_E319() 714 if !has('mzscheme') 715 call assert_fails('mzscheme', 'E319:') 716 endif 717 endfunc 718 719 func Test_not_break_expression_register() 720 call setreg('=', '1+1') 721 if 0 722 put =1 723 endif 724 call assert_equal('1+1', getreg('=', 1)) 725 endfunc 726 727 func Test_address_line_overflow() 728 if !has('nvim') && v:sizeoflong < 8 729 throw 'Skipped: only works with 64 bit long ints' 730 endif 731 new 732 call setline(1, range(100)) 733 call assert_fails('|.44444444444444444444444', 'E1247:') 734 call assert_fails('|.9223372036854775806', 'E1247:') 735 call assert_fails('.44444444444444444444444d', 'E1247:') 736 call assert_equal(range(100)->map('string(v:val)'), getline(1, '$')) 737 738 $ 739 yank 77777777777777777777 740 call assert_equal("99\n", @") 741 742 bwipe! 743 endfunc 744 745 " This was leaving the cursor in line zero 746 func Test_using_zero_in_range() 747 new 748 norm o00 749 silent! 0;s/\%') 750 bwipe! 751 endfunc 752 753 " Test :write after changing name with :file and loading it with :edit 754 func Test_write_after_rename() 755 call writefile(['text'], 'Xfile') 756 757 enew 758 file Xfile 759 call assert_fails('write', 'E13: File exists (add ! to override)') 760 761 " works OK after ":edit" 762 edit 763 write 764 765 call delete('Xfile') 766 bwipe! 767 endfunc 768 769 " catch address lines overflow 770 func Test_ex_address_range_overflow() 771 call assert_fails(':--+foobar', 'E492:') 772 endfunc 773 774 func Test_drop_modified_file() 775 CheckScreendump 776 let lines =<< trim END 777 call setline(1, 'The quick brown fox jumped over the lazy dogs') 778 END 779 call writefile([''], 'Xdrop_modified.txt', 'D') 780 call writefile(lines, 'Xtest_drop_modified', 'D') 781 let buf = RunVimInTerminal('-S Xtest_drop_modified Xdrop_modified.txt', {'rows': 10,'columns': 40}) 782 call term_sendkeys(buf, ":drop Xdrop_modified.txt\<CR>") 783 call VerifyScreenDump(buf, 'Test_drop_modified_1', {}) 784 785 " clean up 786 call StopVimInTerminal(buf) 787 endfunc 788 789 " vim: shiftwidth=2 sts=2 expandtab