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