1" Test for the various 'cpoptions' (cpo) flags 2 3source check.vim 4source shared.vim 5source view_util.vim 6 7" Test for the 'a' flag in 'cpo'. Reading a file should set the alternate 8" file name. 9func Test_cpo_a() 10 let save_cpo = &cpo 11 call writefile(['one'], 'Xfile') 12 " Wipe out all the buffers, so that the alternate file is empty 13 edit Xfoo | %bw 14 set cpo-=a 15 new 16 read Xfile 17 call assert_equal('', @#) 18 %d 19 set cpo+=a 20 read Xfile 21 call assert_equal('Xfile', @#) 22 close! 23 call delete('Xfile') 24 let &cpo = save_cpo 25endfunc 26 27" Test for the 'A' flag in 'cpo'. Writing a file should set the alternate 28" file name. 29func Test_cpo_A() 30 let save_cpo = &cpo 31 " Wipe out all the buffers, so that the alternate file is empty 32 edit Xfoo | %bw 33 set cpo-=A 34 new Xfile1 35 write Xfile2 36 call assert_equal('', @#) 37 %bw 38 call delete('Xfile2') 39 new Xfile1 40 set cpo+=A 41 write Xfile2 42 call assert_equal('Xfile2', @#) 43 close! 44 call delete('Xfile2') 45 let &cpo = save_cpo 46endfunc 47 48" Test for the 'b' flag in 'cpo'. "\|" at the end of a map command is 49" recognized as the end of the map. 50func Test_cpo_b() 51 let save_cpo = &cpo 52 set cpo+=b 53 nnoremap <F5> :pwd\<CR>\|let i = 1 54 call assert_equal(':pwd\<CR>\', maparg('<F5>')) 55 nunmap <F5> 56 exe "nnoremap <F5> :pwd\<C-V>|let i = 1" 57 call assert_equal(':pwd|let i = 1', maparg('<F5>')) 58 nunmap <F5> 59 set cpo-=b 60 nnoremap <F5> :pwd\<CR>\|let i = 1 61 call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>')) 62 let &cpo = save_cpo 63 nunmap <F5> 64endfunc 65 66" Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user 67" commands and menu commands has no special meaning. 68func Test_cpo_B() 69 let save_cpo = &cpo 70 new 71 set cpo-=B 72 iabbr <buffer> abc ab\<BS>d 73 exe "normal iabc " 74 call assert_equal('ab<BS>d ', getline(1)) 75 %d 76 set cpo+=B 77 iabbr <buffer> abc ab\<BS>d 78 exe "normal iabc " 79 call assert_equal('abd ', getline(1)) 80 close! 81 let &cpo = save_cpo 82endfunc 83 84" Test for the 'c' flag in 'cpo'. 85func Test_cpo_c() 86 let save_cpo = &cpo 87 set cpo+=c 88 new 89 call setline(1, ' abababababab') 90 exe "normal gg/abab\<CR>" 91 call assert_equal(3, searchcount().total) 92 set cpo-=c 93 exe "normal gg/abab\<CR>" 94 call assert_equal(5, searchcount().total) 95 close! 96 let &cpo = save_cpo 97endfunc 98 99" Test for the 'C' flag in 'cpo' (line continuation) 100func Test_cpo_C() 101 let save_cpo = &cpo 102 call writefile(['let l = [', '\ 1,', '\ 2]'], 'Xfile') 103 set cpo-=C 104 source Xfile 105 call assert_equal([1, 2], g:l) 106 set cpo+=C 107 call assert_fails('source Xfile', 'E10:') 108 call delete('Xfile') 109 let &cpo = save_cpo 110endfunc 111 112" Test for the 'd' flag in 'cpo' (tags relative to the current file) 113func Test_cpo_d() 114 let save_cpo = &cpo 115 call mkdir('Xdir') 116 call writefile(["one\tXfile1\t/^one$/"], 'tags') 117 call writefile(["two\tXfile2\t/^two$/"], 'Xdir/tags') 118 set tags=./tags 119 set cpo-=d 120 edit Xdir/Xfile 121 call assert_equal('two', taglist('.*')[0].name) 122 set cpo+=d 123 call assert_equal('one', taglist('.*')[0].name) 124 %bw! 125 call delete('tags') 126 call delete('Xdir', 'rf') 127 set tags& 128 let &cpo = save_cpo 129endfunc 130 131" Test for the 'D' flag in 'cpo' (digraph after a r, f or t) 132func Test_cpo_D() 133 CheckFeature digraphs 134 let save_cpo = &cpo 135 new 136 set cpo-=D 137 call setline(1, 'abcdefgh|') 138 exe "norm! 1gg0f\<c-k>!!" 139 call assert_equal(9, col('.')) 140 set cpo+=D 141 exe "norm! 1gg0f\<c-k>!!" 142 call assert_equal(1, col('.')) 143 set cpo-=D 144 close! 145 let &cpo = save_cpo 146endfunc 147 148" Test for the 'e' flag in 'cpo' 149func Test_cpo_e() 150 let save_cpo = &cpo 151 let @a='let i = 45' 152 set cpo+=e 153 call feedkeys(":@a\<CR>", 'xt') 154 call assert_equal(45, i) 155 set cpo-=e 156 call feedkeys(":@a\<CR>6\<CR>", 'xt') 157 call assert_equal(456, i) 158 let &cpo = save_cpo 159endfunc 160 161" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators 162func Test_cpo_E() 163 new 164 call setline(1, '') 165 set cpo+=E 166 " yank an empty line 167 call assert_beeps('normal "ayl') 168 " change an empty line 169 call assert_beeps('normal lcTa') 170 " delete an empty line 171 call assert_beeps('normal D') 172 call assert_beeps('normal dl') 173 call assert_equal('', getline(1)) 174 " change case of an empty line 175 call assert_beeps('normal gul') 176 call assert_beeps('normal gUl') 177 " replace a character 178 call assert_beeps('normal vrx') 179 " increment and decrement 180 call assert_beeps('exe "normal v\<C-A>"') 181 call assert_beeps('exe "normal v\<C-X>"') 182 set cpo-=E 183 close! 184endfunc 185 186" Test for the 'f' flag in 'cpo' (read in an empty buffer sets the file name) 187func Test_cpo_f() 188 let save_cpo = &cpo 189 new 190 set cpo-=f 191 read test_cpoptions.vim 192 call assert_equal('', @%) 193 %d 194 set cpo+=f 195 read test_cpoptions.vim 196 call assert_equal('test_cpoptions.vim', @%) 197 close! 198 let &cpo = save_cpo 199endfunc 200 201" Test for the 'F' flag in 'cpo' (write in an empty buffer sets the file name) 202func Test_cpo_F() 203 let save_cpo = &cpo 204 new 205 set cpo-=F 206 write Xfile 207 call assert_equal('', @%) 208 call delete('Xfile') 209 set cpo+=F 210 write Xfile 211 call assert_equal('Xfile', @%) 212 close! 213 call delete('Xfile') 214 let &cpo = save_cpo 215endfunc 216 217" Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file) 218func Test_cpo_g() 219 let save_cpo = &cpo 220 new test_cpoptions.vim 221 set cpo-=g 222 normal 20G 223 edit 224 call assert_equal(20, line('.')) 225 set cpo+=g 226 edit 227 call assert_equal(1, line('.')) 228 close! 229 let &cpo = save_cpo 230endfunc 231 232" Test for inserting text in a line with only spaces ('H' flag in 'cpoptions') 233func Test_cpo_H() 234 let save_cpo = &cpo 235 new 236 set cpo-=H 237 call setline(1, ' ') 238 normal! Ia 239 call assert_equal(' a', getline(1)) 240 set cpo+=H 241 call setline(1, ' ') 242 normal! Ia 243 call assert_equal(' a ', getline(1)) 244 close! 245 let &cpo = save_cpo 246endfunc 247 248" TODO: Add a test for the 'i' flag in 'cpo' 249 250" Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) 251func Test_cpo_I() 252 let save_cpo = &cpo 253 new 254 setlocal autoindent 255 set cpo+=I 256 exe "normal i one\<CR>\<Up>" 257 call assert_equal(' ', getline(2)) 258 set cpo-=I 259 %d 260 exe "normal i one\<CR>\<Up>" 261 call assert_equal('', getline(2)) 262 close! 263 let &cpo = save_cpo 264endfunc 265 266" Test for the 'j' flag in 'cpo' is in the test_join.vim file. 267 268" Test for the 'J' flag in 'cpo' (two spaces after a sentence) 269func Test_cpo_J() 270 let save_cpo = &cpo 271 new 272 set cpo-=J 273 call setline(1, 'one. two! three? four."'' five.)]') 274 normal 0 275 for colnr in [6, 12, 19, 28, 34] 276 normal ) 277 call assert_equal(colnr, col('.')) 278 endfor 279 for colnr in [28, 19, 12, 6, 1] 280 normal ( 281 call assert_equal(colnr, col('.')) 282 endfor 283 set cpo+=J 284 normal 0 285 for colnr in [12, 28, 34] 286 normal ) 287 call assert_equal(colnr, col('.')) 288 endfor 289 for colnr in [28, 12, 1] 290 normal ( 291 call assert_equal(colnr, col('.')) 292 endfor 293 close! 294 let &cpo = save_cpo 295endfunc 296 297" TODO: Add a test for the 'k' flag in 'cpo' 298 299" TODO: Add a test for the 'K' flag in 'cpo' 300 301" Test for the 'l' flag in 'cpo' (backslash in a [] range) 302func Test_cpo_l() 303 let save_cpo = &cpo 304 new 305 call setline(1, ['', "a\tc" .. '\t']) 306 set cpo-=l 307 exe 'normal gg/[\t]' .. "\<CR>" 308 call assert_equal([2, 8], [col('.'), virtcol('.')]) 309 set cpo+=l 310 exe 'normal gg/[\t]' .. "\<CR>" 311 call assert_equal([4, 10], [col('.'), virtcol('.')]) 312 close! 313 let &cpo = save_cpo 314endfunc 315 316" Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions') 317func Test_cpo_L() 318 let save_cpo = &cpo 319 new 320 set cpo-=L 321 call setline(1, 'abcdefghijklmnopqr') 322 exe "normal 0gR\<Tab>" 323 call assert_equal("\<Tab>ijklmnopqr", getline(1)) 324 set cpo+=L 325 set list 326 call setline(1, 'abcdefghijklmnopqr') 327 exe "normal 0gR\<Tab>" 328 call assert_equal("\<Tab>cdefghijklmnopqr", getline(1)) 329 set nolist 330 call setline(1, 'abcdefghijklmnopqr') 331 exe "normal 0gR\<Tab>" 332 call assert_equal("\<Tab>ijklmnopqr", getline(1)) 333 close! 334 let &cpo = save_cpo 335endfunc 336 337" TODO: Add a test for the 'm' flag in 'cpo' 338 339" Test for the 'M' flag in 'cpo' (% with escape parenthesis) 340func Test_cpo_M() 341 let save_cpo = &cpo 342 new 343 call setline(1, ['( \( )', '\( ( \)']) 344 345 set cpo-=M 346 call cursor(1, 1) 347 normal % 348 call assert_equal(6, col('.')) 349 call cursor(1, 4) 350 call assert_beeps('normal %') 351 call cursor(2, 2) 352 normal % 353 call assert_equal(7, col('.')) 354 call cursor(2, 4) 355 call assert_beeps('normal %') 356 357 set cpo+=M 358 call cursor(1, 4) 359 normal % 360 call assert_equal(6, col('.')) 361 call cursor(1, 1) 362 call assert_beeps('normal %') 363 call cursor(2, 4) 364 normal % 365 call assert_equal(7, col('.')) 366 call cursor(2, 1) 367 call assert_beeps('normal %') 368 369 close! 370 let &cpo = save_cpo 371endfunc 372 373" Test for the 'n' flag in 'cpo' (using number column for wrapped lines) 374func Test_cpo_n() 375 let save_cpo = &cpo 376 new 377 call setline(1, repeat('a', &columns)) 378 setlocal number 379 set cpo-=n 380 redraw! 381 call assert_equal(' aaaa', Screenline(2)) 382 set cpo+=n 383 redraw! 384 call assert_equal('aaaa', Screenline(2)) 385 close! 386 let &cpo = save_cpo 387endfunc 388 389" Test for the 'o' flag in 'cpo' (line offset to search command) 390func Test_cpo_o() 391 let save_cpo = &cpo 392 new 393 call setline(1, ['', 'one', 'two', 'three', 'one', 'two', 'three']) 394 set cpo-=o 395 exe "normal /one/+2\<CR>" 396 normal n 397 call assert_equal(7, line('.')) 398 set cpo+=o 399 exe "normal /one/+2\<CR>" 400 normal n 401 call assert_equal(5, line('.')) 402 close! 403 let &cpo = save_cpo 404endfunc 405 406" Test for the 'O' flag in 'cpo' (overwriting an existing file) 407func Test_cpo_O() 408 let save_cpo = &cpo 409 new Xfile 410 call setline(1, 'one') 411 call writefile(['two'], 'Xfile') 412 set cpo-=O 413 call assert_fails('write', 'E13:') 414 set cpo+=O 415 write 416 call assert_equal(['one'], readfile('Xfile')) 417 close! 418 call delete('Xfile') 419 let &cpo = save_cpo 420endfunc 421 422" Test for the 'p' flag in 'cpo' is in the test_lispwords.vim file. 423 424" Test for the 'P' flag in 'cpo' (appending to a file sets the current file 425" name) 426func Test_cpo_P() 427 let save_cpo = &cpo 428 call writefile([], 'Xfile') 429 new 430 call setline(1, 'one') 431 set cpo+=F 432 set cpo-=P 433 write >> Xfile 434 call assert_equal('', @%) 435 set cpo+=P 436 write >> Xfile 437 call assert_equal('Xfile', @%) 438 close! 439 call delete('Xfile') 440 let &cpo = save_cpo 441endfunc 442 443" Test for the 'q' flag in 'cpo' (joining multiple lines) 444func Test_cpo_q() 445 let save_cpo = &cpo 446 new 447 call setline(1, ['one', 'two', 'three', 'four', 'five']) 448 set cpo-=q 449 normal gg4J 450 call assert_equal(14, col('.')) 451 %d 452 call setline(1, ['one', 'two', 'three', 'four', 'five']) 453 set cpo+=q 454 normal gg4J 455 call assert_equal(4, col('.')) 456 close! 457 let &cpo = save_cpo 458endfunc 459 460" Test for the 'r' flag in 'cpo' (redo command with a search motion) 461func Test_cpo_r() 462 let save_cpo = &cpo 463 new 464 call setline(1, repeat(['one two three four'], 2)) 465 set cpo-=r 466 exe "normal ggc/two\<CR>abc " 467 let @/ = 'three' 468 normal 2G. 469 call assert_equal('abc two three four', getline(2)) 470 %d 471 call setline(1, repeat(['one two three four'], 2)) 472 set cpo+=r 473 exe "normal ggc/two\<CR>abc " 474 let @/ = 'three' 475 normal 2G. 476 call assert_equal('abc three four', getline(2)) 477 close! 478 let &cpo = save_cpo 479endfunc 480 481" Test for the 'R' flag in 'cpo' (clear marks after a filter command) 482func Test_cpo_R() 483 CheckUnix 484 let save_cpo = &cpo 485 new 486 call setline(1, ['three', 'one', 'two']) 487 set cpo-=R 488 3mark r 489 %!sort 490 call assert_equal(3, line("'r")) 491 %d 492 call setline(1, ['three', 'one', 'two']) 493 set cpo+=R 494 3mark r 495 %!sort 496 call assert_equal(0, line("'r")) 497 close! 498 let &cpo = save_cpo 499endfunc 500 501" TODO: Add a test for the 's' flag in 'cpo' 502 503" Test for the 'S' flag in 'cpo' (copying buffer options) 504func Test_cpo_S() 505 let save_cpo = &cpo 506 new Xfile1 507 set noautoindent 508 new Xfile2 509 set cpo-=S 510 set autoindent 511 wincmd p 512 call assert_equal(0, &autoindent) 513 wincmd p 514 call assert_equal(1, &autoindent) 515 set cpo+=S 516 wincmd p 517 call assert_equal(1, &autoindent) 518 set noautoindent 519 wincmd p 520 call assert_equal(0, &autoindent) 521 wincmd t 522 close! 523 close! 524 let &cpo = save_cpo 525endfunc 526 527" Test for the 't' flag in 'cpo' is in the test_tagjump.vim file. 528 529" Test for the 'u' flag in 'cpo' (Vi-compatible undo) 530func Test_cpo_u() 531 let save_cpo = &cpo 532 new 533 set cpo-=u 534 exe "normal iabc\<C-G>udef\<C-G>ughi" 535 normal uu 536 call assert_equal('abc', getline(1)) 537 %d 538 set cpo+=u 539 exe "normal iabc\<C-G>udef\<C-G>ughi" 540 normal uu 541 call assert_equal('abcdefghi', getline(1)) 542 close! 543 let &cpo = save_cpo 544endfunc 545 546" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove 547" characters from the screen) 548 549" Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one 550" character) 551func Test_cpo_w() 552 let save_cpo = &cpo 553 new 554 set cpo+=w 555 call setline(1, 'here are some words') 556 norm! 1gg0elcwZZZ 557 call assert_equal('hereZZZ are some words', getline('.')) 558 norm! 1gg2elcWYYY 559 call assert_equal('hereZZZ areYYY some words', getline('.')) 560 set cpo-=w 561 call setline(1, 'here are some words') 562 norm! 1gg0elcwZZZ 563 call assert_equal('hereZZZare some words', getline('.')) 564 norm! 1gg2elcWYYY 565 call assert_equal('hereZZZare someYYYwords', getline('.')) 566 close! 567 let &cpo = save_cpo 568endfunc 569 570" Test for the 'W' flag in 'cpo' is in the test_writefile.vim file 571 572" Test for the 'x' flag in 'cpo' (Esc on command-line executes command) 573func Test_cpo_x() 574 let save_cpo = &cpo 575 set cpo-=x 576 let i = 1 577 call feedkeys(":let i=10\<Esc>", 'xt') 578 call assert_equal(1, i) 579 set cpo+=x 580 call feedkeys(":let i=10\<Esc>", 'xt') 581 call assert_equal(10, i) 582 let &cpo = save_cpo 583endfunc 584 585" Test for the 'X' flag in 'cpo' ('R' with a count) 586func Test_cpo_X() 587 let save_cpo = &cpo 588 new 589 call setline(1, 'aaaaaa') 590 set cpo-=X 591 normal gg4Rx 592 call assert_equal('xxxxaa', getline(1)) 593 normal ggRy 594 normal 4. 595 call assert_equal('yyyyaa', getline(1)) 596 call setline(1, 'aaaaaa') 597 set cpo+=X 598 normal gg4Rx 599 call assert_equal('xxxxaaaaa', getline(1)) 600 normal ggRy 601 normal 4. 602 call assert_equal('yyyyxxxaaaaa', getline(1)) 603 close! 604 let &cpo = save_cpo 605endfunc 606 607" Test for the 'y' flag in 'cpo' (repeating a yank command) 608func Test_cpo_y() 609 let save_cpo = &cpo 610 new 611 call setline(1, ['one', 'two']) 612 set cpo-=y 613 normal ggyy 614 normal 2G. 615 call assert_equal("one\n", @") 616 %d 617 call setline(1, ['one', 'two']) 618 set cpo+=y 619 normal ggyy 620 normal 2G. 621 call assert_equal("two\n", @") 622 close! 623 let &cpo = save_cpo 624endfunc 625 626" Test for the 'Z' flag in 'cpo' (write! resets 'readonly') 627func Test_cpo_Z() 628 let save_cpo = &cpo 629 call writefile([], 'Xfile') 630 new Xfile 631 setlocal readonly 632 set cpo-=Z 633 write! 634 call assert_equal(0, &readonly) 635 set cpo+=Z 636 setlocal readonly 637 write! 638 call assert_equal(1, &readonly) 639 close! 640 call delete('Xfile') 641 let &cpo = save_cpo 642endfunc 643 644" Test for the '!' flag in 'cpo' is in the test_normal.vim file 645 646" Test for displaying dollar when changing text ('$' flag in 'cpoptions') 647func Test_cpo_dollar() 648 new 649 let g:Line = '' 650 func SaveFirstLine() 651 let g:Line = Screenline(1) 652 return '' 653 endfunc 654 inoremap <expr> <buffer> <F2> SaveFirstLine() 655 call test_override('redraw_flag', 1) 656 set cpo+=$ 657 call setline(1, 'one two three') 658 redraw! 659 exe "normal c2w\<F2>vim" 660 call assert_equal('one tw$ three', g:Line) 661 call assert_equal('vim three', getline(1)) 662 set cpo-=$ 663 call test_override('ALL', 0) 664 delfunc SaveFirstLine 665 %bw! 666endfunc 667 668" Test for the '%' flag in 'cpo' (parenthesis matching inside strings) 669func Test_cpo_percent() 670 let save_cpo = &cpo 671 new 672 call setline(1, ' if (strcmp("ab)cd(", s))') 673 set cpo-=% 674 normal 8|% 675 call assert_equal(28, col('.')) 676 normal 15|% 677 call assert_equal(27, col('.')) 678 normal 27|% 679 call assert_equal(15, col('.')) 680 call assert_beeps("normal 19|%") 681 call assert_beeps("normal 22|%") 682 set cpo+=% 683 normal 8|% 684 call assert_equal(28, col('.')) 685 normal 15|% 686 call assert_equal(19, col('.')) 687 normal 27|% 688 call assert_equal(22, col('.')) 689 normal 19|% 690 call assert_equal(15, col('.')) 691 normal 22|% 692 call assert_equal(27, col('.')) 693 close! 694 let &cpo = save_cpo 695endfunc 696 697" Test for cursor movement with '-' in 'cpoptions' 698func Test_cpo_minus() 699 new 700 call setline(1, ['foo', 'bar', 'baz']) 701 let save_cpo = &cpo 702 set cpo+=- 703 call assert_beeps('normal 10j') 704 call assert_equal(1, line('.')) 705 normal G 706 call assert_beeps('normal 10k') 707 call assert_equal(3, line('.')) 708 call assert_fails(10, 'E16:') 709 close! 710 let &cpo = save_cpo 711endfunc 712 713" Test for the '+' flag in 'cpo' ('write file' command resets the 'modified' 714" flag) 715func Test_cpo_plus() 716 let save_cpo = &cpo 717 call writefile([], 'Xfile') 718 new Xfile 719 call setline(1, 'foo') 720 write X1 721 call assert_equal(1, &modified) 722 set cpo+=+ 723 write X2 724 call assert_equal(0, &modified) 725 close! 726 call delete('Xfile') 727 call delete('X1') 728 call delete('X2') 729 let &cpo = save_cpo 730endfunc 731 732" Test for the '*' flag in 'cpo' (':*' is same as ':@') 733func Test_cpo_star() 734 let save_cpo = &cpo 735 let x = 0 736 new 737 set cpo-=* 738 let @a = 'let x += 1' 739 call assert_fails('*a', 'E20:') 740 set cpo+=* 741 *a 742 call assert_equal(1, x) 743 close! 744 let &cpo = save_cpo 745endfunc 746 747" Test for the '<' flag in 'cpo' is in the test_mapping.vim file 748 749" Test for the '>' flag in 'cpo' (use a new line when appending to a register) 750func Test_cpo_gt() 751 let save_cpo = &cpo 752 new 753 call setline(1, 'one two') 754 set cpo-=> 755 let @r = '' 756 normal gg"Rye 757 normal "Rye 758 call assert_equal("oneone", @r) 759 set cpo+=> 760 let @r = '' 761 normal gg"Rye 762 normal "Rye 763 call assert_equal("\none\none", @r) 764 close! 765 let &cpo = save_cpo 766endfunc 767 768" Test for the ';' flag in 'cpo' 769" Test for t,f,F,T movement commands and 'cpo-;' setting 770func Test_cpo_semicolon() 771 let save_cpo = &cpo 772 new 773 call append(0, ["aaa two three four", " zzz", "yyy ", 774 \ "bbb yee yoo four", "ccc two three four", 775 \ "ddd yee yoo four"]) 776 set cpo-=; 777 1 778 normal! 0tt;D 779 2 780 normal! 0fz;D 781 3 782 normal! $Fy;D 783 4 784 normal! $Ty;D 785 set cpo+=; 786 5 787 normal! 0tt;;D 788 6 789 normal! $Ty;;D 790 791 call assert_equal('aaa two', getline(1)) 792 call assert_equal(' z', getline(2)) 793 call assert_equal('y', getline(3)) 794 call assert_equal('bbb y', getline(4)) 795 call assert_equal('ccc', getline(5)) 796 call assert_equal('ddd yee y', getline(6)) 797 close! 798 let &cpo = save_cpo 799endfunc 800 801" Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators) 802func Test_cpo_hash() 803 let save_cpo = &cpo 804 new 805 set cpo-=# 806 call setline(1, ['one', 'two', 'three']) 807 normal gg2D 808 call assert_equal(['three'], getline(1, '$')) 809 normal gg2ofour 810 call assert_equal(['three', 'four', 'four'], getline(1, '$')) 811 normal gg2Otwo 812 call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$')) 813 %d 814 set cpo+=# 815 call setline(1, ['one', 'two', 'three']) 816 normal gg2D 817 call assert_equal(['', 'two', 'three'], getline(1, '$')) 818 normal gg2oone 819 call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) 820 normal gg2Ozero 821 call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$')) 822 close! 823 let &cpo = save_cpo 824endfunc 825 826" Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still 827" loaded and ':preserve' is used. 828func Test_cpo_ampersand() 829 call writefile(['one'], 'Xfile') 830 let after =<< trim [CODE] 831 set cpo+=& 832 preserve 833 qall 834 [CODE] 835 if RunVim([], after, 'Xfile') 836 call assert_equal(1, filereadable('.Xfile.swp')) 837 call delete('.Xfile.swp') 838 endif 839 call delete('Xfile') 840endfunc 841 842" Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) 843func Test_cpo_backslash() 844 let save_cpo = &cpo 845 new 846 call setline(1, ['', " \\-string"]) 847 set cpo-=\ 848 exe 'normal gg/[ \-]' .. "\<CR>n" 849 call assert_equal(3, col('.')) 850 set cpo+=\ 851 exe 'normal gg/[ \-]' .. "\<CR>n" 852 call assert_equal(2, col('.')) 853 close! 854 let &cpo = save_cpo 855endfunc 856 857" Test for the '/' flag in 'cpo' is in the test_substitute.vim file 858 859" Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a { 860" character at the start of a line) 861func Test_cpo_brace() 862 let save_cpo = &cpo 863 new 864 call setline(1, ['', '{', ' int i;', '}', '']) 865 set cpo-={ 866 normal gg} 867 call assert_equal(5, line('.')) 868 normal G{ 869 call assert_equal(1, line('.')) 870 set cpo+={ 871 normal gg} 872 call assert_equal(2, line('.')) 873 normal G{ 874 call assert_equal(2, line('.')) 875 close! 876 let &cpo = save_cpo 877endfunc 878 879" Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is 880" modified) 881func Test_cpo_dot() 882 let save_cpo = &cpo 883 new Xfoo 884 call setline(1, 'foo') 885 let save_dir = getcwd() 886 set cpo+=. 887 888 " :cd should fail when buffer is modified and 'cpo' contains dot. 889 call assert_fails('cd ..', 'E747:') 890 call assert_equal(save_dir, getcwd()) 891 892 " :cd with exclamation mark should succeed. 893 cd! .. 894 call assert_notequal(save_dir, getcwd()) 895 896 " :cd should succeed when buffer has been written. 897 w! 898 exe 'cd ' .. fnameescape(save_dir) 899 call assert_equal(save_dir, getcwd()) 900 901 call delete('Xfoo') 902 set cpo& 903 close! 904 let &cpo = save_cpo 905endfunc 906 907" vim: shiftwidth=2 sts=2 expandtab 908