robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Tests for diff mode 2 3source shared.vim 4source screendump.vim 5source check.vim 6source view_util.vim 7 8func Test_diff_fold_sync () 9enew ! 10let g: update_count = 0 11au DiffUpdated * let g: update_count += 1 12 13let l = range ( 50 ) 14call setline ( 1 , l ) 15diffthis 16let winone = win_getid () 17new 18let l [ 25 ] = 'diff' 19call setline ( 1 , l ) 20diffthis 21let wintwo = win_getid () 22" line 15 is inside the closed fold 23call assert_equal ( 19 , foldclosedend ( 10 )) 24call win_gotoid ( winone ) 25call assert_equal ( 19 , foldclosedend ( 10 )) 26" open the fold 27normal zv 28call assert_equal ( -1 , foldclosedend ( 10 )) 29" fold in other window must have opened too 30call win_gotoid ( wintwo ) 31call assert_equal ( -1 , foldclosedend ( 10 )) 32 33" cursor position is in sync 34normal 23G 35call win_gotoid ( winone ) 36call assert_equal ( 23 , getcurpos ()[ 1 ]) 37 38" depending on how redraw is done DiffUpdated may be triggered once or twice 39call assert_inrange ( 1 , 2 , g: update_count ) 40au ! DiffUpdated 41 42windo diffoff 43close ! 44set nomodified 45endfunc 46 47func Test_vert_split () 48set diffopt = filler 49call Common_vert_split () 50set diffopt & 51endfunc 52 53" Test for diff folding redraw after last diff is resolved 54func Test_diff_fold_redraw () 55" Set up two files with a minimal case. 56call writefile ([ 'Paragraph 1' , '' , 'Paragraph 2' , '' , 'Paragraph 3' ], 'Xfile1' ) 57call writefile ([ 'Paragraph 1' , '' , 'Paragraph 3' ], 'Xfile2' ) 58 59" Open in diff mode. 60edit Xfile1 61vert diffsplit Xfile2 62 63" Go to the diff and apply :diffput to copy Paragraph 2 to Xfile2. 64wincmd l 653 66diffput 67 68" Check that the folds in both windows are closed and extend from the first 69" line of the buffer to the last line of the buffer. 70call assert_equal ( 1 , foldclosed ( line ( "$" ))) 71wincmd h 72call assert_equal ( 1 , foldclosed ( line ( "$" ))) 73 74" Clean up. 75bwipe ! 76bwipe ! 77call delete ( 'Xfile1' ) 78call delete ( 'Xfile2' ) 79endfunc 80 81func Test_vert_split_internal () 82set diffopt = internal,filler 83call Common_vert_split () 84set diffopt & 85endfunc 86 87func Common_vert_split () 88" Disable the title to avoid xterm keeping the wrong one. 89set notitle noicon 90new 91let l = [ '1 aa' , '2 bb' , '3 cc' , '4 dd' , '5 ee' ] 92call setline ( 1 , l ) 93w ! Xtest 94normal dd 95$ 96put 97normal kkrXoxxx 98w ! Xtest2 99file Nop 100normal ggoyyyjjjozzzz 101set foldmethod = markerfoldcolumn = 4 102call assert_equal ( 0 , & diff ) 103call assert_equal ( 'marker' , & foldmethod ) 104call assert_equal ( '4' , & foldcolumn ) 105call assert_equal ( 0 , & scrollbind ) 106call assert_equal ( 0 , & cursorbind ) 107call assert_equal ( 1 , & wrap ) 108 109vert diffsplit Xtest 110vert diffsplit Xtest2 111call assert_equal ( 1 , & diff ) 112call assert_equal ( 'diff' , & foldmethod ) 113call assert_equal ( '2' , & foldcolumn ) 114call assert_equal ( 1 , & scrollbind ) 115call assert_equal ( 1 , & cursorbind ) 116call assert_equal ( 0 , & wrap ) 117 118let diff_fdm = & fdm 119let diff_fdc = & fdc 120" repeat entering diff mode here to see if this saves the wrong settings 121diffthis 122" jump to second window for a moment to have filler line appear at start of 123" first window 124wincmd w 125normal gg 126wincmd p 127normal gg 128call assert_equal ( 2 , winline ()) 129normal j 130call assert_equal ( 4 , winline ()) 131normal j 132call assert_equal ( 5 , winline ()) 133normal j 134call assert_equal ( 6 , winline ()) 135normal j 136call assert_equal ( 8 , winline ()) 137normal j 138call assert_equal ( 9 , winline ()) 139 140wincmd w 141normal gg 142call assert_equal ( 1 , winline ()) 143normal j 144call assert_equal ( 2 , winline ()) 145normal j 146call assert_equal ( 4 , winline ()) 147normal j 148call assert_equal ( 5 , winline ()) 149normal j 150call assert_equal ( 8 , winline ()) 151 152wincmd w 153normal gg 154call assert_equal ( 2 , winline ()) 155normal j 156call assert_equal ( 3 , winline ()) 157normal j 158call assert_equal ( 4 , winline ()) 159normal j 160call assert_equal ( 5 , winline ()) 161normal j 162call assert_equal ( 6 , winline ()) 163normal j 164call assert_equal ( 7 , winline ()) 165normal j 166call assert_equal ( 8 , winline ()) 167 168" Test diffoff 169diffoff ! 1701 wincmd w 171let & diff = 1 172let & fdm = diff_fdm 173let & fdc = diff_fdc 1744 wincmd w 175diffoff ! 1761 wincmd w 177call assert_equal ( 0 , & diff ) 178call assert_equal ( 'marker' , & foldmethod ) 179call assert_equal ( '4' , & foldcolumn ) 180call assert_equal ( 0 , & scrollbind ) 181call assert_equal ( 0 , & cursorbind ) 182call assert_equal ( 1 , & wrap ) 183 184wincmd w 185call assert_equal ( 0 , & diff ) 186call assert_equal ( 'marker' , & foldmethod ) 187call assert_equal ( '4' , & foldcolumn ) 188call assert_equal ( 0 , & scrollbind ) 189call assert_equal ( 0 , & cursorbind ) 190call assert_equal ( 1 , & wrap ) 191 192wincmd w 193call assert_equal ( 0 , & diff ) 194call assert_equal ( 'marker' , & foldmethod ) 195call assert_equal ( '4' , & foldcolumn ) 196call assert_equal ( 0 , & scrollbind ) 197call assert_equal ( 0 , & cursorbind ) 198call assert_equal ( 1 , & wrap ) 199 200call delete ( 'Xtest' ) 201call delete ( 'Xtest2' ) 202windo bw! 203endfunc 204 205func Test_filler_lines () 206" Test that diffing shows correct filler lines 207enew ! 208put =range(4,10) 2091 d _ 210vnew 211put =range(1,10) 2121 d _ 213windo diffthis 214wincmd h 215call assert_equal ( 1 , line ( 'w0' )) 216unlet ! diff_fdm diff_fdc 217windo diffoff 218bwipe ! 219enew ! 220endfunc 221 222func Test_diffget_diffput () 223enew ! 224let l = range ( 50 ) 225call setline ( 1 , l ) 226call assert_fails ( 'diffget' , 'E99:' ) 227diffthis 228call assert_fails ( 'diffget' , 'E100:' ) 229new 230let l [ 10 ] = 'one' 231let l [ 20 ] = 'two' 232let l [ 30 ] = 'three' 233let l [ 40 ] = 'four' 234call setline ( 1 , l ) 235diffthis 236call assert_equal ( 'one' , getline ( 11 )) 23711 diffget 238call assert_equal ( '10' , getline ( 11 )) 23921 diffput 240wincmd w 241call assert_equal ( 'two' , getline ( 21 )) 242normal 31Gdo 243call assert_equal ( 'three' , getline ( 31 )) 244call assert_equal ( '40' , getline ( 41 )) 245normal 41Gdp 246wincmd w 247call assert_equal ( '40' , getline ( 41 )) 248new 249diffthis 250call assert_fails ( 'diffget' , 'E101:' ) 251 252windo diffoff 253 %bwipe ! 254endfunc 255 256" Undo after getting lines into an empty buffer must leave it empty again 257func Test_diffget_undo_empty_buffer () 258enew ! 259diffthis 260new 261call setline ( 1 , [ '1' , '2' ]) 262diffthis 263 264wincmd p 265normal do 266call assert_equal ([ '1' , '2' ], getline ( 1 , '$' )) 267undo 268call assert_equal ([ '' ], getline ( 1 , '$' )) 269 270windo diffoff 271 %bwipe ! 272endfunc 273 274" Test putting two changes from one buffer to another 275func Test_diffput_two () 276new a 277let win_a = win_getid () 278call setline ( 1 , range ( 1 , 10 )) 279diffthis 280new b 281let win_b = win_getid () 282call setline ( 1 , range ( 1 , 10 )) 2838 del 2845 del 285diffthis 286call win_gotoid ( win_a ) 287 %diffput 288call win_gotoid ( win_b ) 289call assert_equal ( map ( range ( 1 , 10 ), 'string(v:val)' ), getline ( 1 , '$' )) 290bwipe ! a 291bwipe ! b 292endfunc 293 294" Test for :diffget/:diffput with a range that is inside a diff chunk 295func Test_diffget_diffput_range () 296call setline ( 1 , range ( 1 , 10 )) 297new 298call setline ( 1 , range ( 11 , 20 )) 299windo diffthis 3003 , 5 diffget 301call assert_equal ([ '13' , '14' , '15' ], getline ( 3 , 5 )) 302call setline ( 1 , range ( 1 , 10 )) 3034 , 8 diffput 304wincmd p 305call assert_equal ([ '13' , '4' , '5' , '6' , '7' , '8' , '19' ], getline ( 3 , 9 )) 306 %bw ! 307endfunc 308 309" Test :diffget/:diffput handling of added/deleted lines 310func Test_diffget_diffput_deleted_lines () 311call setline ( 1 , [ '2' , '4' , '6' ]) 312diffthis 313new 314call setline ( 1 , range ( 1 , 7 )) 315diffthis 316wincmd w 317 3183 , 3 diffget " get nothing 319call assert_equal ([ '2' , '4' , '6' ], getline ( 1 , '$' )) 3203 , 4 diffget " get the last insertion past the end of file 321call assert_equal ([ '2' , '4' , '6' , '7' ], getline ( 1 , '$' )) 3220 , 1 diffget " get the first insertion above first line 323call assert_equal ([ '1' , '2' , '4' , '6' , '7' ], getline ( 1 , '$' )) 324 325" When using non-range diffget on the last line, it should get the 326" change above or at the line as usual, but if the only change is below the 327" last line, diffget should get that instead. 3281 , $ delete 329call setline ( 1 , [ '2' , '4' , '6' ]) 330diffupdate 331norm Gdo 332call assert_equal ([ '2' , '4' , '5' , '6' ], getline ( 1 , '$' )) 333norm Gdo 334call assert_equal ([ '2' , '4' , '5' , '6' , '7' ], getline ( 1 , '$' )) 335 336" Test non-range diffput on last line with the same logic 3371 , $ delete 338call setline ( 1 , [ '2' , '4' , '6' ]) 339diffupdate 340norm Gdp 341wincmd w 342call assert_equal ([ '1' , '2' , '3' , '4' , '6' , '7' ], getline ( 1 , '$' )) 343wincmd w 344norm Gdp 345wincmd w 346call assert_equal ([ '1' , '2' , '3' , '4' , '6' ], getline ( 1 , '$' )) 347call setline ( 1 , range ( 1 , 7 )) 348diffupdate 349wincmd w 350 351" Test that 0,$+1 will get/put all changes from/to the other buffer 3521 , $ delete 353call setline ( 1 , [ '2' , '4' , '6' ]) 354diffupdate 3550 , $ +1 diffget 356call assert_equal ([ '1' , '2' , '3' , '4' , '5' , '6' , '7' ], getline ( 1 , '$' )) 3571 , $ delete 358call setline ( 1 , [ '2' , '4' , '6' ]) 359diffupdate 3600 , $ +1 diffput 361wincmd w 362call assert_equal ([ '2' , '4' , '6' ], getline ( 1 , '$' )) 363% bw ! 364endfunc 365 366" Test for :diffget/:diffput with an empty buffer and a non-empty buffer 367func Test_diffget_diffput_empty_buffer () 368% d _ 369new 370call setline ( 1 , 'one' ) 371windo diffthis 372diffget 373call assert_equal ([ 'one' ], getline ( 1 , '$' )) 374% d _ 375diffput 376wincmd p 377call assert_equal ([ '' ], getline ( 1 , '$' )) 378% bw ! 379endfunc 380 381" :diffput and :diffget completes names of buffers which 382" are in diff mode and which are different than current buffer. 383" No completion when the current window is not in diff mode. 384func Test_diffget_diffput_completion () 385e Xdiff1 | diffthis 386botright new Xdiff2 387botright new Xdiff3 | split | diffthis 388botright new Xdiff4 | diffthis 389 390wincmd t 391call assert_equal ( 'Xdiff1' , bufname ( '%' )) 392call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' ) 393call assert_equal ( '"diffput Xdiff3 Xdiff4' , @: ) 394call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' ) 395call assert_equal ( '"diffget Xdiff3 Xdiff4' , @: ) 396call assert_equal ([ 'Xdiff3' , 'Xdiff4' ], getcompletion ( '' , 'diff_buffer' )) 397 398" Xdiff2 is not in diff mode, so no completion for :diffput, :diffget 399wincmd j 400call assert_equal ( 'Xdiff2' , bufname ( '%' )) 401call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' ) 402call assert_equal ( '"diffput ' , @: ) 403call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' ) 404call assert_equal ( '"diffget ' , @: ) 405call assert_equal ([], getcompletion ( '' , 'diff_buffer' )) 406 407" Xdiff3 is split in 2 windows, only the top one is in diff mode. 408" So completion of :diffput :diffget only happens in the top window. 409wincmd j 410call assert_equal ( 'Xdiff3' , bufname ( '%' )) 411call assert_equal ( 1 , & diff ) 412call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' ) 413call assert_equal ( '"diffput Xdiff1 Xdiff4' , @: ) 414call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' ) 415call assert_equal ( '"diffget Xdiff1 Xdiff4' , @: ) 416call assert_equal ([ 'Xdiff1' , 'Xdiff4' ], getcompletion ( '' , 'diff_buffer' )) 417 418wincmd j 419call assert_equal ( 'Xdiff3' , bufname ( '%' )) 420call assert_equal ( 0 , & diff ) 421call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' ) 422call assert_equal ( '"diffput ' , @: ) 423call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' ) 424call assert_equal ( '"diffget ' , @: ) 425call assert_equal ([], getcompletion ( '' , 'diff_buffer' )) 426 427wincmd j 428call assert_equal ( 'Xdiff4' , bufname ( '%' )) 429call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' ) 430call assert_equal ( '"diffput Xdiff1 Xdiff3' , @: ) 431call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' ) 432call assert_equal ( '"diffget Xdiff1 Xdiff3' , @: ) 433call assert_equal ([ 'Xdiff1' , 'Xdiff3' ], getcompletion ( '' , 'diff_buffer' )) 434 435% bwipe 436endfunc 437 438func Test_dp_do_buffer () 439e ! one 440let bn1 = bufnr ( '%' ) 441let l = range ( 60 ) 442call setline ( 1 , l ) 443diffthis 444 445new two 446let l [ 10 ] = 'one' 447let l [ 20 ] = 'two' 448let l [ 30 ] = 'three' 449let l [ 40 ] = 'four' 450let l [ 50 ] = 'five' 451call setline ( 1 , l ) 452diffthis 453 454" dp and do with invalid buffer number. 45511 456call assert_fails ( 'norm 99999dp' , 'E102:' ) 457call assert_fails ( 'norm 99999do' , 'E102:' ) 458call assert_fails ( 'diffput non_existing_buffer' , 'E94:' ) 459call assert_fails ( 'diffget non_existing_buffer' , 'E94:' ) 460 461" dp and do with valid buffer number. 462call assert_equal ( 'one' , getline ( '.' )) 463exe 'norm ' . bn1 . 'do' 464call assert_equal ( '10' , getline ( '.' )) 46521 466call assert_equal ( 'two' , getline ( '.' )) 467diffget one 468call assert_equal ( '20' , getline ( '.' )) 469 47031 471exe 'norm ' . bn1 . 'dp' 47241 473diffput one 474wincmd w 47531 476call assert_equal ( 'three' , getline ( '.' )) 47741 478call assert_equal ( 'four' , getline ( '.' )) 479 480" dp and do with buffer number which is not in diff mode. 481new not_in_diff_mode 482let bn3 = bufnr ( '%' ) 483wincmd w 48451 485call assert_fails ( 'exe "norm" . bn3 . "dp"' , 'E103:' ) 486call assert_fails ( 'exe "norm" . bn3 . "do"' , 'E103:' ) 487call assert_fails ( 'diffput not_in_diff_mode' , 'E94:' ) 488call assert_fails ( 'diffget not_in_diff_mode' , 'E94:' ) 489 490windo diffoff 491% bwipe ! 492endfunc 493 494func Test_do_lastline () 495e ! one 496call setline ( 1 , [ '1' , '2' , '3' , '4' , '5' , '6' ]) 497diffthis 498 499new two 500call setline ( 1 , [ '2' , '4' , '5' ]) 501diffthis 502 5031 504norm dp]c 505norm dp]c 506wincmd w 507call assert_equal ( 4 , line ( '$' )) 508norm G 509norm do 510call assert_equal ( 3 , line ( '$' )) 511 512windo diffoff 513% bwipe ! 514endfunc 515 516func Test_diffoff () 517enew ! 518call setline ( 1 , [ 'Two' , 'Three' ]) 519redraw 520let normattr = screenattr ( 1 , 1 ) 521diffthis 522botright vert new 523call setline ( 1 , [ 'One' , '' , 'Two' , 'Three' ]) 524diffthis 525redraw 526call assert_notequal ( normattr , 1 -> screenattr ( 1 )) 527diffoff ! 528redraw 529call assert_equal ( normattr , screenattr ( 1 , 1 )) 530bwipe ! 531bwipe ! 532endfunc 533 534func Common_icase_test () 535edit one 536call setline ( 1 , [ 'One' , 'Two' , 'Three' , 'Four' , 'Fi#vϵ' , 'Si⃗x' , 'Se⃗ve⃗n' ]) 537redraw 538let normattr = screenattr ( 1 , 1 ) 539diffthis 540 541botright vert new two 542call setline ( 1 , [ 'one' , 'TWO' , 'Three ' , 'Four' , 'fI=VΕ' , 'SI⃗x' , 'SEvE⃗n' ]) 543diffthis 544 545redraw 546call assert_equal ( normattr , screenattr ( 1 , 1 )) 547call assert_equal ( normattr , screenattr ( 2 , 1 )) 548call assert_notequal ( normattr , screenattr ( 3 , 1 )) 549call assert_equal ( normattr , screenattr ( 4 , 1 )) 550call assert_equal ( normattr , screenattr ( 6 , 2 )) 551call assert_notequal ( normattr , screenattr ( 7 , 2 )) 552 553let dtextattr = screenattr ( 5 , 3 ) 554call assert_notequal ( dtextattr , screenattr ( 5 , 1 )) 555call assert_notequal ( dtextattr , screenattr ( 5 , 5 )) 556call assert_notequal ( dtextattr , screenattr ( 7 , 4 )) 557 558diffoff ! 559% bwipe ! 560endfunc 561 562func Test_diffopt_icase () 563set diffopt = icase,foldcolumn:0 564call Common_icase_test () 565set diffopt & 566endfunc 567 568func Test_diffopt_icase_internal () 569set diffopt = icase,foldcolumn:0,internal 570call Common_icase_test () 571set diffopt & 572endfunc 573 574func Common_iwhite_test () 575edit one 576" Difference in trailing spaces and amount of spaces should be ignored, 577" but not other space differences. 578call setline ( 1 , [ "One \t" , 'Two' , 'Three' , 'one two' , 'one two' , 'Four' ]) 579redraw 580let normattr = screenattr ( 1 , 1 ) 581diffthis 582 583botright vert new two 584call setline ( 1 , [ "One\t " , "Two\t " , 'Three' , 'one two' , 'onetwo' , ' Four' ]) 585diffthis 586 587redraw 588call assert_equal ( normattr , screenattr ( 1 , 1 )) 589call assert_equal ( normattr , screenattr ( 2 , 1 )) 590call assert_equal ( normattr , screenattr ( 3 , 1 )) 591call assert_equal ( normattr , screenattr ( 4 , 1 )) 592call assert_notequal ( normattr , screenattr ( 5 , 1 )) 593call assert_notequal ( normattr , screenattr ( 6 , 1 )) 594 595diffoff ! 596% bwipe ! 597endfunc 598 599func Test_diffopt_iwhite () 600set diffopt = iwhite,foldcolumn:0 601call Common_iwhite_test () 602set diffopt & 603endfunc 604 605func Test_diffopt_iwhite_internal () 606set diffopt = internal,iwhite,foldcolumn:0 607call Common_iwhite_test () 608set diffopt & 609endfunc 610 611func Test_diffopt_context () 612enew ! 613call setline ( 1 , [ '1' , '2' , '3' , '4' , '5' , '6' , '7' ]) 614diffthis 615new 616call setline ( 1 , [ '1' , '2' , '3' , '4' , '5x' , '6' , '7' ]) 617diffthis 618 619set diffopt = context:2 620call assert_equal ( '+-- 2 lines: 1' , foldtextresult ( 1 )) 621set diffopt = internal,context:2 622call assert_equal ( '+-- 2 lines: 1' , foldtextresult ( 1 )) 623 624set diffopt = context:1 625call assert_equal ( '+-- 3 lines: 1' , foldtextresult ( 1 )) 626set diffopt = internal,context:1 627call assert_equal ( '+-- 3 lines: 1' , foldtextresult ( 1 )) 628 629diffoff ! 630% bwipe ! 631set diffopt & 632endfunc 633 634func Test_diffopt_horizontal () 635set diffopt = internal,horizontal 636diffsplit 637 638call assert_equal ( & columns , winwidth ( 1 )) 639call assert_equal ( & columns , winwidth ( 2 )) 640call assert_equal ( & lines , winheight ( 1 ) + winheight ( 2 ) + 3 ) 641call assert_inrange ( 0 , 1 , winheight ( 1 ) - winheight ( 2 )) 642 643set diffopt & 644diffoff ! 645% bwipe 646endfunc 647 648func Test_diffopt_vertical () 649set diffopt = internal,vertical 650diffsplit 651 652call assert_equal ( & lines - 2 , winheight ( 1 )) 653call assert_equal ( & lines - 2 , winheight ( 2 )) 654call assert_equal ( & columns , winwidth ( 1 ) + winwidth ( 2 ) + 1 ) 655call assert_inrange ( 0 , 1 , winwidth ( 1 ) - winwidth ( 2 )) 656 657set diffopt & 658diffoff ! 659% bwipe 660endfunc 661 662func Test_diffopt_hiddenoff () 663set diffopt = internal,filler,foldcolumn:0,hiddenoff 664e ! one 665call setline ( 1 , [ 'Two' , 'Three' ]) 666redraw 667let normattr = screenattr ( 1 , 1 ) 668diffthis 669botright vert new two 670call setline ( 1 , [ 'One' , 'Four' ]) 671diffthis 672redraw 673call assert_notequal ( normattr , screenattr ( 1 , 1 )) 674set hidden 675close 676redraw 677" should not diffing with hidden buffer two while 'hiddenoff' is enabled 678call assert_equal ( normattr , screenattr ( 1 , 1 )) 679 680bwipe ! 681bwipe ! 682set hidden & diffopt & 683endfunc 684 685func Test_diffoff_hidden () 686set diffopt = internal,filler,foldcolumn:0 687e ! one 688call setline ( 1 , [ 'Two' , 'Three' ]) 689redraw 690let normattr = screenattr ( 1 , 1 ) 691diffthis 692botright vert new two 693call setline ( 1 , [ 'One' , 'Four' ]) 694diffthis 695redraw 696call assert_notequal ( normattr , screenattr ( 1 , 1 )) 697set hidden 698close 699redraw 700" diffing with hidden buffer two 701call assert_notequal ( normattr , screenattr ( 1 , 1 )) 702diffoff 703redraw 704call assert_equal ( normattr , screenattr ( 1 , 1 )) 705diffthis 706redraw 707" still diffing with hidden buffer two 708call assert_notequal ( normattr , screenattr ( 1 , 1 )) 709diffoff ! 710redraw 711call assert_equal ( normattr , screenattr ( 1 , 1 )) 712diffthis 713redraw 714" no longer diffing with hidden buffer two 715call assert_equal ( normattr , screenattr ( 1 , 1 )) 716 717bwipe ! 718bwipe ! 719set hidden & diffopt & 720endfunc 721 722func Test_setting_cursor () 723new Xtest1 724put =range(1,90) 725wq 726new Xtest2 727put =range(1,100) 728wq 729 730tabe Xtest2 731$ 732diffsp Xtest1 733tabclose 734 735call delete ( 'Xtest1' ) 736call delete ( 'Xtest2' ) 737endfunc 738 739func Test_diff_move_to () 740new 741call setline ( 1 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 742diffthis 743vnew 744call setline ( 1 , [ 1 , '2x' , 3 , 4 , 4 , 5 , '6x' , 7 , '8x' , 9 , '10x' ]) 745diffthis 746norm ]c 747call assert_equal ( 2 , line ( '.' )) 748norm 3]c 749call assert_equal ( 9 , line ( '.' )) 750norm 10]c 751call assert_equal ( 11 , line ( '.' )) 752norm [c 753call assert_equal ( 9 , line ( '.' )) 754norm 2[c 755call assert_equal ( 5 , line ( '.' )) 756norm 10[c 757call assert_equal ( 2 , line ( '.' )) 758% bwipe ! 759endfunc 760 761func Test_diffexpr () 762CheckExecutable diff 763 764func DiffExpr () 765" Prepend some text to check diff type detection 766call writefile ([ 'warning' , ' message' ], v: fname_out ) 767silent exe '!diff ' . v: fname_in . ' ' . v: fname_new . '>>' . v: fname_out 768endfunc 769set diffexpr = DiffExpr () 770set diffopt = foldcolumn:0 771 772enew ! 773call setline ( 1 , [ 'one' , 'two' , 'three' ]) 774redraw 775let normattr = screenattr ( 1 , 1 ) 776diffthis 777 778botright vert new 779call setline ( 1 , [ 'one' , 'two' , 'three.' ]) 780diffthis 781 782redraw 783call assert_equal ( normattr , screenattr ( 1 , 1 )) 784call assert_equal ( normattr , screenattr ( 2 , 1 )) 785call assert_notequal ( normattr , screenattr ( 3 , 1 )) 786diffoff ! 787 788" Try using a non-existing function for 'diffexpr'. 789set diffexpr = NewDiffFunc () 790call assert_fails ( 'windo diffthis' , [ 'E117:' , 'E97:' ]) 791diffoff ! 792 793" Using a script-local function 794func s: NewDiffExpr () 795endfunc 796set diffexpr = s :NewDiffExpr() 797call assert_equal ( expand ( '<SID>' ) .. 'NewDiffExpr()' , & diffexpr ) 798set diffexpr = < SID>NewDiffExpr() 799call assert_equal ( expand ( '<SID>' ) .. 'NewDiffExpr()' , & diffexpr ) 800 801% bwipe ! 802set diffexpr & diffopt & 803delfunc DiffExpr 804delfunc s:NewDiffExpr 805endfunc 806 807func Test_diffpatch () 808" The patch program on MS-Windows may fail or hang. 809CheckExecutable patch 810CheckUnix 811new 812insert 813* ************** 814* ** 1,3 **** 8151 816! 2 8173 818--- 1,4 ---- 8191 820! 2x 8213 822+ 4 823. 824saveas ! Xpatch 825bwipe ! 826new 827call assert_fails ( 'diffpatch Xpatch' , 'E816:' ) 828 829for name in [ 'Xpatch' , 'Xpatch$HOME' , 'Xpa''tch' ] 830call setline ( 1 , [ '1' , '2' , '3' ]) 831if name != 'Xpatch' 832call rename ( 'Xpatch' , name ) 833endif 834exe 'diffpatch ' . escape ( name , '$' ) 835call assert_equal ([ '1' , '2x' , '3' , '4' ], getline ( 1 , '$' )) 836if name != 'Xpatch' 837call rename ( name , 'Xpatch' ) 838endif 839bwipe ! 840endfor 841 842call delete ( 'Xpatch' ) 843bwipe ! 844endfunc 845 846func Test_diff_too_many_buffers () 847for i in range ( 1 , 8 ) 848exe "new Xtest" . i 849diffthis 850endfor 851new Xtest9 852call assert_fails ( 'diffthis' , 'E96:' ) 853% bwipe ! 854endfunc 855 856func Test_diff_nomodifiable () 857new 858call setline ( 1 , [ 1 , 2 , 3 , 4 ]) 859setl nomodifiable 860diffthis 861vnew 862call setline ( 1 , [ '1x' , 2 , 3 , 3 , 4 ]) 863diffthis 864call assert_fails ( 'norm dp' , 'E793:' ) 865setl nomodifiable 866call assert_fails ( 'norm do' , 'E21:' ) 867% bwipe ! 868endfunc 869 870func Test_diff_hlID () 871set diffopt = internal,filler 872new 873call setline ( 1 , [ 1 , 2 , 3 , 'Yz' , 'a dxxg' ,]) 874diffthis 875vnew 876call setline ( 1 , [ '1x' , 2 , 'x' , 3 , 'yx' , 'abc defg' ]) 877diffthis 878redraw 879 880call diff_hlID ( -1 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "" ) 881 882call diff_hlID ( 1 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 883call diff_hlID ( 1 , 2 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 884call diff_hlID ( 2 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "" ) 885call diff_hlID ( 3 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffAdd" ) 886eval 4 -> diff_hlID ( 1 ) -> synIDattr ( "name" ) -> assert_equal ( "" ) 887call diff_hlID ( 5 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 888call diff_hlID ( 5 , 2 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 889 890set diffopt += icase " test that caching is invalidated by diffopt change 891call diff_hlID ( 5 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 892set diffopt -= icase 893call diff_hlID ( 5 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 894 895call diff_hlID ( 6 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 896call diff_hlID ( 6 , 2 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 897call diff_hlID ( 6 , 4 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 898call diff_hlID ( 6 , 7 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 899call diff_hlID ( 6 , 8 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 900set diffopt += inline:char 901call diff_hlID ( 6 , 1 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 902call diff_hlID ( 6 , 2 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffTextAdd" ) 903call diff_hlID ( 6 , 4 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 904call diff_hlID ( 6 , 7 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffText" ) 905call diff_hlID ( 6 , 8 ) -> synIDattr ( "name" ) -> assert_equal ( "DiffChange" ) 906set diffopt -= inline:char 907 908wincmd w 909call assert_equal ( synIDattr ( diff_hlID ( 1 , 1 ), "name" ), "DiffChange" ) 910call assert_equal ( synIDattr ( diff_hlID ( 2 , 1 ), "name" ), "" ) 911call assert_equal ( synIDattr ( diff_hlID ( 3 , 1 ), "name" ), "" ) 912 913% bwipe ! 914set diffopt & 915endfunc 916 917func Test_diff_filler () 918new 919call setline ( 1 , [ 1 , 2 , 3 , 'x' , 4 ]) 920diffthis 921vnew 922call setline ( 1 , [ 1 , 2 , 'y' , 'y' , 3 , 4 ]) 923diffthis 924redraw 925 926call assert_equal ([ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ], map ( range ( -1 , 7 ), 'v:val->diff_filler()' )) 927wincmd w 928call assert_equal ([ 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 ], map ( range ( -1 , 6 ), 'diff_filler(v:val)' )) 929 930% bwipe ! 931endfunc 932 933func Test_diff_lastline () 934enew ! 935only ! 936call setline ( 1 , [ 'This is a ' , 'line with five ' , 'rows' ]) 937diffthis 938botright vert new 939call setline ( 1 , [ 'This is' , 'a line with ' , 'four rows' ]) 940diffthis 9411 942call feedkeys ( "Je a\<CR>" , 'tx' ) 943call feedkeys ( "Je a\<CR>" , 'tx' ) 944let w1lines = winline () 945wincmd w 946$ 947let w2lines = winline () 948call assert_equal ( w2lines , w1lines ) 949bwipe ! 950bwipe ! 951endfunc 952 953func WriteDiffFiles ( buf , list1 , list2 ) 954call writefile ( a: list1 , 'Xdifile1' ) 955call writefile ( a: list2 , 'Xdifile2' ) 956if a: buf 957call term_sendkeys ( a: buf , ":checktime\<CR>" ) 958endif 959endfunc 960 961func WriteDiffFiles3 ( buf , list1 , list2 , list3 ) 962call writefile ( a: list1 , 'Xdifile1' ) 963call writefile ( a: list2 , 'Xdifile2' ) 964call writefile ( a: list3 , 'Xdifile3' ) 965if a: buf 966call term_sendkeys ( a: buf , ":checktime\<CR>" ) 967endif 968endfunc 969 970" Verify a screendump with both the internal and external diff. 971func VerifyBoth ( buf , dumpfile , extra ) 972CheckScreendump 973 974" trailing : for leaving the cursor on the command line 975for cmd in [ ":set diffopt=filler" . a: extra . "\<CR>:" , ":set diffopt+=internal\<CR>:" ] 976call term_sendkeys ( a: buf , cmd ) 977if VerifyScreenDump ( a: buf , a: dumpfile , {}, cmd =~ 'internal' ? 'internal' : 'external' ) 978break " don't let the next iteration overwrite the "failed" file. 979" don't let the next iteration overwrite the "failed" file. 980return 981endif 982endfor 983 984" also test unified diff 985call term_sendkeys ( a: buf , ":call SetupUnified()\<CR>:" ) 986call term_sendkeys ( a: buf , ":redraw!\<CR>:" ) 987call VerifyScreenDump ( a: buf , a: dumpfile , {}, 'unified' ) 988call term_sendkeys ( a: buf , ":call StopUnified()\<CR>:" ) 989endfunc 990 991" Verify a screendump with the internal diff only. 992func VerifyInternal ( buf , dumpfile , extra ) 993CheckScreendump 994 995call term_sendkeys ( a: buf , ":diffupdate!\<CR>" ) 996" trailing : for leaving the cursor on the command line 997call term_sendkeys ( a: buf , ":set diffopt=internal,filler" . a: extra . "\<CR>:" ) 998call VerifyScreenDump ( a: buf , a: dumpfile , {}) 999endfunc 1000 1001func Test_diff_screen () 1002let g: test_is_flaky = 1 1003CheckScreendump 1004CheckFeature menu 1005 1006let lines =<< trim END 1007func UnifiedDiffExpr() 1008" Prepend some text to check diff type detection 1009call writefile(['warning', ' message'], v:fname_out) 1010silent exe '!diff -U0 ' .. v:fname_in .. ' ' .. v:fname_new .. '>>' .. v:fname_out 1011endfunc 1012func SetupUnified() 1013set diffexpr=UnifiedDiffExpr() 1014diffupdate 1015endfunc 1016func StopUnified() 1017set diffexpr= 1018endfunc 1019END 1020call writefile ( lines , 'XdiffSetup' , 'D' ) 1021 1022" clean up already existing swap files, just in case 1023call delete ( '.Xdifile1.swp' ) 1024call delete ( '.Xdifile2.swp' ) 1025 1026" Test 1: Add a line in beginning of file 2 1027call WriteDiffFiles ( 0 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 1028let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2' , {}) 1029" Set autoread mode, so that Vim won't complain once we re-write the test 1030" files 1031call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 1032 1033call VerifyBoth ( buf , 'Test_diff_01' , '' ) 1034 1035" Test 2: Add a line in beginning of file 1 1036call WriteDiffFiles ( buf , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 1037call VerifyBoth ( buf , 'Test_diff_02' , '' ) 1038 1039" Test 3: Add a line at the end of file 2 1040call WriteDiffFiles ( buf , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ]) 1041call VerifyBoth ( buf , 'Test_diff_03' , '' ) 1042 1043" Test 4: Add a line at the end of file 1 1044call WriteDiffFiles ( buf , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ], [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 1045call VerifyBoth ( buf , 'Test_diff_04' , '' ) 1046 1047" Test 5: Add a line in the middle of file 2, remove on at the end of file 1 1048call WriteDiffFiles ( buf , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ], [ 1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 1049call VerifyBoth ( buf , 'Test_diff_05' , '' ) 1050 1051" Test 6: Add a line in the middle of file 1, remove on at the end of file 2 1052call WriteDiffFiles ( buf , [ 1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ]) 1053call VerifyBoth ( buf , 'Test_diff_06' , '' ) 1054 1055" Variants on test 6 with different context settings 1056call term_sendkeys ( buf , ":set diffopt+=context:2\<cr>" ) 1057call VerifyScreenDump ( buf , 'Test_diff_06.2' , {}) 1058call term_sendkeys ( buf , ":set diffopt-=context:2\<cr>" ) 1059call term_sendkeys ( buf , ":set diffopt+=context:1\<cr>" ) 1060call VerifyScreenDump ( buf , 'Test_diff_06.1' , {}) 1061call term_sendkeys ( buf , ":set diffopt-=context:1\<cr>" ) 1062call term_sendkeys ( buf , ":set diffopt+=context:0\<cr>" ) 1063call VerifyScreenDump ( buf , 'Test_diff_06.0' , {}) 1064call term_sendkeys ( buf , ":set diffopt-=context:0\<cr>" ) 1065 1066" Test 7 - 9: Test normal/patience/histogram diff algorithm 1067call WriteDiffFiles ( buf , [ '#include <stdio.h>' , '' , '// Frobs foo heartily' , 'int frobnitz(int foo)' , '{' , 1068\ ' int i;' , ' for(i = 0; i < 10; i++)' , ' {' , ' printf("Your answer is: ");' , 1069\ ' printf("%d\n", foo);' , ' }' , '}' , '' , 'int fact(int n)' , '{' , ' if(n > 1)' , ' {' , 1070\ ' return fact(n-1) * n;' , ' }' , ' return 1;' , '}' , '' , 'int main(int argc, char **argv)' , 1071\ '{' , ' frobnitz(fact(10));' , '}' ], 1072\ [ '#include <stdio.h>' , '' , 'int fib(int n)' , '{' , ' if(n > 2)' , ' {' , 1073\ ' return fib(n-1) + fib(n-2);' , ' }' , ' return 1;' , '}' , '' , '// Frobs foo heartily' , 1074\ 'int frobnitz(int foo)' , '{' , ' int i;' , ' for(i = 0; i < 10; i++)' , ' {' , 1075\ ' printf("%d\n", foo);' , ' }' , '}' , '' , 1076\ 'int main(int argc, char **argv)' , '{' , ' frobnitz(fib(10));' , '}' ]) 1077call term_sendkeys ( buf , ":diffupdate!\<cr>" ) 1078call term_sendkeys ( buf , ":set diffopt+=internal\<cr>" ) 1079call VerifyScreenDump ( buf , 'Test_diff_07' , {}) 1080 1081call term_sendkeys ( buf , ":set diffopt+=algorithm:patience\<cr>" ) 1082call VerifyScreenDump ( buf , 'Test_diff_08' , {}) 1083 1084call term_sendkeys ( buf , ":set diffopt+=algorithm:histogram\<cr>" ) 1085call VerifyScreenDump ( buf , 'Test_diff_09' , {}) 1086 1087" Test 10-11: with/without indent-heuristic 1088call term_sendkeys ( buf , ":set diffopt&vim\<cr>" ) 1089call WriteDiffFiles ( buf , [ '' , ' def finalize(values)' , '' , ' values.each do |v|' , ' v.finalize' , ' end' ], 1090\ [ '' , ' def finalize(values)' , '' , ' values.each do |v|' , ' v.prepare' , ' end' , '' , 1091\ ' values.each do |v|' , ' v.finalize' , ' end' ]) 1092call term_sendkeys ( buf , ":diffupdate!\<cr>" ) 1093call term_sendkeys ( buf , ":set diffopt+=internal\<cr>:\<cr>" ) 1094call VerifyScreenDump ( buf , 'Test_diff_11' , {}) 1095 1096" Leave trailing : at commandline! 1097call term_sendkeys ( buf , ":set diffopt-=indent-heuristic\<cr>:\<cr>" ) 1098call VerifyScreenDump ( buf , 'Test_diff_10' , {}, 'one' ) 1099" shouldn't matter, if indent-algorithm comes before or after the algorithm 1100call term_sendkeys ( buf , ":set diffopt&\<cr>" ) 1101call term_sendkeys ( buf , ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>" ) 1102call VerifyScreenDump ( buf , 'Test_diff_11' , {}, 'two' ) 1103call term_sendkeys ( buf , ":set diffopt&\<cr>" ) 1104call term_sendkeys ( buf , ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>" ) 1105call VerifyScreenDump ( buf , 'Test_diff_11' , {}, 'three' ) 1106 1107" Test 12: diff the same file 1108call WriteDiffFiles ( buf , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]) 1109call VerifyBoth ( buf , 'Test_diff_12' , '' ) 1110 1111" Test 13: diff an empty file 1112call WriteDiffFiles ( buf , [], []) 1113call VerifyBoth ( buf , 'Test_diff_13' , '' ) 1114 1115" Test 14: test diffopt+=icase 1116call WriteDiffFiles ( buf , [ 'a' , 'b' , 'cd' ], [ 'A' , 'b' , 'cDe' ]) 1117call VerifyBoth ( buf , 'Test_diff_14' , " diffopt+=filler diffopt+=icase" ) 1118 1119" Test 15-16: test diffopt+=iwhite 1120call WriteDiffFiles ( buf , [ 'int main()' , '{' , ' printf("Hello, World!");' , ' return 0;' , '}' ], 1121\ [ 'int main()' , '{' , ' if (0)' , ' {' , ' printf("Hello, World!");' , ' return 0;' , ' }' , '}' ]) 1122call term_sendkeys ( buf , ":diffupdate!\<cr>" ) 1123call term_sendkeys ( buf , ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>" ) 1124call VerifyScreenDump ( buf , 'Test_diff_15' , {}) 1125call term_sendkeys ( buf , ":set diffopt+=internal\<cr>" ) 1126call VerifyScreenDump ( buf , 'Test_diff_16' , {}) 1127 1128" Test 17: test diffopt+=iblank 1129call WriteDiffFiles ( buf , [ 'a' , ' ' , 'cd' , 'ef' , 'xxx' ], [ 'a' , 'cd' , '' , 'ef' , 'yyy' ]) 1130call VerifyInternal ( buf , 'Test_diff_17' , " diffopt+=iblank" ) 1131 1132" Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol 1133call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhite" ) 1134call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhiteall" ) 1135call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhiteeol" ) 1136 1137" Test 19: test diffopt+=iwhiteeol 1138call WriteDiffFiles ( buf , [ 'a ' , 'x' , 'cd' , 'ef' , 'xx xx' , 'foo' , 'bar' ], [ 'a' , 'x' , 'c d' , ' ef' , 'xx xx' , 'foo' , '' , 'bar' ]) 1139call VerifyInternal ( buf , 'Test_diff_19' , " diffopt+=iwhiteeol" ) 1140 1141" Test 20: test diffopt+=iwhiteall 1142call VerifyInternal ( buf , 'Test_diff_20' , " diffopt+=iwhiteall" ) 1143 1144" Test 21: Delete all lines 1145call WriteDiffFiles ( buf , [ 0 ], []) 1146call VerifyBoth ( buf , "Test_diff_21" , "" ) 1147 1148" Test 22: Add line to empty file 1149call WriteDiffFiles ( buf , [], [ 0 ]) 1150call VerifyBoth ( buf , "Test_diff_22" , "" ) 1151 1152call WriteDiffFiles ( buf , [ '?a' , '?b' , '?c' ], [ '!b' ]) 1153call VerifyInternal ( buf , 'Test_diff_23' , " diffopt+=linematch:30" ) 1154 1155call WriteDiffFiles ( buf , [ '' , 1156\ 'common line' , 1157\ 'common line' , 1158\ '' , 1159\ 'DEFabc' , 1160\ 'xyz' , 1161\ 'xyz' , 1162\ 'xyz' , 1163\ 'DEFabc' , 1164\ 'DEFabc' , 1165\ 'DEFabc' , 1166\ 'common line' , 1167\ 'common line' , 1168\ 'DEF' , 1169\ 'common line' , 1170\ 'DEF' , 1171\ 'something' ], 1172\ [ '' , 1173\ 'common line' , 1174\ 'common line' , 1175\ '' , 1176\ 'ABCabc' , 1177\ 'ABCabc' , 1178\ 'ABCabc' , 1179\ 'ABCabc' , 1180\ 'common line' , 1181\ 'common line' , 1182\ 'common line' , 1183\ 'something' ]) 1184call VerifyInternal ( buf , 'Test_diff_24' , " diffopt+=linematch:30" ) 1185 1186 1187" clean up 1188call StopVimInTerminal ( buf ) 1189call delete ( 'Xdifile1' ) 1190call delete ( 'Xdifile2' ) 1191endfunc 1192 1193func Test_diff_with_scroll_and_change () 1194CheckScreendump 1195 1196let lines =<< trim END 1197call setline(1, range(1, 15)) 1198vnew 1199call setline(1, range(9, 15)) 1200windo diffthis 1201wincmd h 1202exe "normal Gl5\<C-E>" 1203END 1204call writefile ( lines , 'Xtest_scroll_change' , 'D' ) 1205let buf = RunVimInTerminal ( '-S Xtest_scroll_change' , {}) 1206 1207call VerifyScreenDump ( buf , 'Test_diff_scroll_change_01' , {}) 1208 1209call term_sendkeys ( buf , "ax\<Esc>" ) 1210call VerifyScreenDump ( buf , 'Test_diff_scroll_change_02' , {}) 1211 1212call term_sendkeys ( buf , "\<C-W>lay\<Esc>" ) 1213call VerifyScreenDump ( buf , 'Test_diff_scroll_change_03' , {}) 1214 1215" clean up 1216call StopVimInTerminal ( buf ) 1217endfunc 1218 1219func Test_diff_with_cursorline () 1220CheckScreendump 1221 1222call writefile ([ 1223\ 'hi CursorLine ctermbg=red ctermfg=white' , 1224\ 'set cursorline' , 1225\ 'call setline(1, ["foo","foo","foo","bar"])' , 1226\ 'vnew' , 1227\ 'call setline(1, ["bee","foo","foo","baz"])' , 1228\ 'windo diffthis' , 1229\ '2wincmd w' , 1230\ ], 'Xtest_diff_cursorline' , 'D' ) 1231let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline' , {}) 1232 1233call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_01' , {}) 1234call term_sendkeys ( buf , "j" ) 1235call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_02' , {}) 1236call term_sendkeys ( buf , "j" ) 1237call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_03' , {}) 1238 1239" clean up 1240call StopVimInTerminal ( buf ) 1241endfunc 1242 1243func Test_diff_with_cursorline_number () 1244CheckScreendump 1245 1246let lines =<< trim END 1247hi CursorLine ctermbg=red ctermfg=white 1248hi CursorLineNr ctermbg=white ctermfg=black cterm=underline 1249set cursorline number 1250call setline(1, ["baz", "foo", "foo", "bar"]) 12512 1252vnew 1253call setline(1, ["foo", "foo", "bar"]) 1254windo diffthis 12551wincmd w 1256END 1257call writefile ( lines , 'Xtest_diff_cursorline_number' , 'D' ) 1258let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline_number' , {}) 1259 1260call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_number_01' , {}) 1261call term_sendkeys ( buf , ":set cursorlineopt=number\r" ) 1262call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_number_02' , {}) 1263 1264" clean up 1265call StopVimInTerminal ( buf ) 1266endfunc 1267 1268func Test_diff_with_cursorline_breakindent () 1269CheckScreendump 1270 1271let lines =<< trim END 1272hi CursorLine ctermbg=red ctermfg=white 1273set noequalalways wrap diffopt=followwrap cursorline breakindent 127450vnew 1275call setline(1, [' ', ' ', ' ', ' ']) 1276exe "norm! 20Afoo\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abar\<Esc>" 1277vnew 1278call setline(1, [' ', ' ', ' ', ' ']) 1279exe "norm! 20Abee\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abaz\<Esc>" 1280windo diffthis 12812wincmd w 1282END 1283call writefile ( lines , 'Xtest_diff_cursorline_breakindent' , 'D' ) 1284let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline_breakindent' , {}) 1285 1286call term_sendkeys ( buf , "gg0" ) 1287call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_01' , {}) 1288call term_sendkeys ( buf , "j" ) 1289call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_02' , {}) 1290call term_sendkeys ( buf , "j" ) 1291call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_03' , {}) 1292call term_sendkeys ( buf , "j" ) 1293call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_04' , {}) 1294 1295" clean up 1296call StopVimInTerminal ( buf ) 1297endfunc 1298 1299func Test_diff_breakindent_after_filler () 1300CheckScreendump 1301 1302let lines =<< trim END 1303set laststatus=0 diffopt+=followwrap breakindent breakindentopt=min:0 1304call setline(1, ['a', ' ' .. repeat('c', 50)]) 1305vnew 1306call setline(1, ['a', 'b', ' ' .. repeat('c', 50)]) 1307windo diffthis 1308norm! G$ 1309END 1310call writefile ( lines , 'Xtest_diff_breakindent_after_filler' , 'D' ) 1311let buf = RunVimInTerminal ( '-S Xtest_diff_breakindent_after_filler' , #{ rows : 8 , cols : 45 }) 1312call VerifyScreenDump ( buf , 'Test_diff_breakindent_after_filler' , {}) 1313 1314" clean up 1315call StopVimInTerminal ( buf ) 1316endfunc 1317 1318func Test_diff_with_syntax () 1319CheckScreendump 1320 1321let lines =<< trim END 1322void doNothing() { 1323int x = 0; 1324char *s = "hello"; 1325return 5; 1326} 1327END 1328call writefile ( lines , 'Xprogram1.c' , 'D' ) 1329let lines =<< trim END 1330void doSomething() { 1331int x = 0; 1332char *s = "there"; 1333return 5; 1334} 1335END 1336call writefile ( lines , 'Xprogram2.c' , 'D' ) 1337 1338let lines =<< trim END 1339set diffopt=internal,filler 1340edit Xprogram1.c 1341diffsplit Xprogram2.c 1342END 1343call writefile ( lines , 'Xtest_diff_syntax' , 'D' ) 1344let buf = RunVimInTerminal ( '-S Xtest_diff_syntax' , {}) 1345 1346call VerifyScreenDump ( buf , 'Test_diff_syntax_1' , {}) 1347 1348" clean up 1349call StopVimInTerminal ( buf ) 1350endfunc 1351 1352func Test_diff_of_diff () 1353CheckScreendump 1354CheckFeature rightleft 1355 1356call writefile ([ 1357\ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])' , 1358\ 'vnew' , 1359\ 'call setline(1, ["aa","bb","cc"])' , 1360\ 'windo diffthis' , 1361\ '1wincmd w' , 1362\ 'setlocal number' , 1363\ ], 'Xtest_diff_diff' , 'D' ) 1364let buf = RunVimInTerminal ( '-S Xtest_diff_diff' , {}) 1365 1366call VerifyScreenDump ( buf , 'Test_diff_of_diff_01' , {}) 1367 1368call term_sendkeys ( buf , ":set rightleft\<cr>" ) 1369call VerifyScreenDump ( buf , 'Test_diff_of_diff_02' , {}) 1370 1371" clean up 1372call StopVimInTerminal ( buf ) 1373endfunc 1374 1375func CloseoffSetup () 1376enew 1377call setline ( 1 , [ 'one' , 'two' , 'three' ]) 1378diffthis 1379new 1380call setline ( 1 , [ 'one' , 'tow' , 'three' ]) 1381diffthis 1382call assert_equal ( 1 , & diff ) 1383bw ! 1384endfunc 1385 1386func Test_diff_closeoff () 1387" "closeoff" included by default: last diff win gets 'diff' reset' 1388call CloseoffSetup () 1389call assert_equal ( 0 , & diff ) 1390enew ! 1391 1392" "closeoff" excluded: last diff win keeps 'diff' set' 1393set diffopt -= closeoff 1394call CloseoffSetup () 1395call assert_equal ( 1 , & diff ) 1396diffoff ! 1397enew ! 1398endfunc 1399 1400func Test_diff_followwrap () 1401new 1402set diffopt += followwrap 1403set wrap 1404diffthis 1405call assert_equal ( 1 , & wrap ) 1406diffoff 1407set nowrap 1408diffthis 1409call assert_equal ( 0 , & wrap ) 1410diffoff 1411set diffopt & 1412bwipe ! 1413endfunc 1414 1415func Test_diff_maintains_change_mark () 1416func DiffMaintainsChangeMark () 1417enew ! 1418call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' ]) 1419diffthis 1420new 1421call setline ( 1 , [ 'a' , 'b' , 'c' , 'e' ]) 1422" Set '[ and '] marks 14232 , 3 yank 1424call assert_equal ([ 2 , 3 ], [ line ( "'[" ), line ( "']" )]) 1425" Verify they aren't affected by the implicit diff 1426diffthis 1427call assert_equal ([ 2 , 3 ], [ line ( "'[" ), line ( "']" )]) 1428" Verify they aren't affected by an explicit diff 1429diffupdate 1430call assert_equal ([ 2 , 3 ], [ line ( "'[" ), line ( "']" )]) 1431bwipe ! 1432bwipe ! 1433endfunc 1434 1435set diffopt -= internal 1436call DiffMaintainsChangeMark () 1437set diffopt += internal 1438call DiffMaintainsChangeMark () 1439 1440set diffopt & 1441delfunc DiffMaintainsChangeMark 1442endfunc 1443 1444" Test for 'patchexpr' 1445func Test_patchexpr () 1446let g: patch_args = [] 1447func TPatch () 1448call add ( g: patch_args , readfile ( v: fname_in )) 1449call add ( g: patch_args , readfile ( v: fname_diff )) 1450call writefile ([ 'output file' ], v: fname_out ) 1451endfunc 1452set patchexpr = TPatch () 1453 1454call writefile ([ 'input file' ], 'Xinput' , 'D' ) 1455call writefile ([ 'diff file' ], 'Xdiff' , 'D' ) 1456% bwipe ! 1457edit Xinput 1458diffpatch Xdiff 1459call assert_equal ( 'output file' , getline ( 1 )) 1460call assert_equal ( 'Xinput.new' , bufname ()) 1461call assert_equal ( 2 , winnr ( '$' )) 1462call assert_true ( & diff ) 1463 1464" Using a script-local function 1465func s: NewPatchExpr () 1466endfunc 1467set patchexpr = s :NewPatchExpr() 1468call assert_equal ( expand ( '<SID>' ) .. 'NewPatchExpr()' , & patchexpr ) 1469set patchexpr = < SID>NewPatchExpr() 1470call assert_equal ( expand ( '<SID>' ) .. 'NewPatchExpr()' , & patchexpr ) 1471 1472set patchexpr & 1473delfunc TPatch 1474delfunc s:NewPatchExpr 1475% bwipe ! 1476endfunc 1477 1478func Test_diff_rnu () 1479CheckScreendump 1480 1481let content =<< trim END 1482set diffopt=internal,filler 1483call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b']) 1484vnew 1485call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b']) 1486windo diffthis 1487setlocal number rnu foldcolumn=0 1488END 1489call writefile ( content , 'Xtest_diff_rnu' , 'D' ) 1490let buf = RunVimInTerminal ( '-S Xtest_diff_rnu' , {}) 1491 1492call VerifyScreenDump ( buf , 'Test_diff_rnu_01' , {}) 1493 1494call term_sendkeys ( buf , "j" ) 1495call VerifyScreenDump ( buf , 'Test_diff_rnu_02' , {}) 1496call term_sendkeys ( buf , "j" ) 1497call VerifyScreenDump ( buf , 'Test_diff_rnu_03' , {}) 1498 1499" clean up 1500call StopVimInTerminal ( buf ) 1501endfunc 1502 1503func Test_diff_multilineconceal () 1504new 1505diffthis 1506 1507new 1508call matchadd ( 'Conceal' , 'a\nb' , 9 , -1 , { 'conceal' : 'Y' }) 1509set cole = 2 cocu = n 1510call setline ( 1 , [ "a" , "b" ]) 1511diffthis 1512redraw 1513endfunc 1514 1515func Test_diff_and_scroll () 1516" this was causing an ml_get error 1517set ls = 2 1518for i in range ( winheight ( 0 ) * 2 ) 1519call setline ( i , i < winheight ( 0 ) - 10 ? i : i + 10 ) 1520endfor 1521vnew 1522for i in range ( winheight ( 0 ) * 2 + 10 ) 1523call setline ( i , i < winheight ( 0 ) - 10 ? 0 : i ) 1524endfor 1525diffthis 1526wincmd p 1527diffthis 1528execute 'normal ' . winheight ( 0 ) . "\<C-d>" 1529 1530bwipe ! 1531bwipe ! 1532set ls & 1533endfunc 1534 1535func Test_diff_filler_cursorcolumn () 1536CheckScreendump 1537 1538let content =<< trim END 1539call setline(1, ['aa', 'bb', 'cc']) 1540vnew 1541call setline(1, ['aa', 'cc']) 1542windo diffthis 1543wincmd p 1544setlocal cursorcolumn foldcolumn=0 1545norm! gg0 1546redraw! 1547END 1548call writefile ( content , 'Xtest_diff_cuc' , 'D' ) 1549let buf = RunVimInTerminal ( '-S Xtest_diff_cuc' , {}) 1550 1551call VerifyScreenDump ( buf , 'Test_diff_cuc_01' , {}) 1552 1553call term_sendkeys ( buf , "l" ) 1554call term_sendkeys ( buf , "\<C-l>" ) 1555call VerifyScreenDump ( buf , 'Test_diff_cuc_02' , {}) 1556call term_sendkeys ( buf , "0j" ) 1557call term_sendkeys ( buf , "\<C-l>" ) 1558call VerifyScreenDump ( buf , 'Test_diff_cuc_03' , {}) 1559call term_sendkeys ( buf , "l" ) 1560call term_sendkeys ( buf , "\<C-l>" ) 1561call VerifyScreenDump ( buf , 'Test_diff_cuc_04' , {}) 1562 1563" clean up 1564call StopVimInTerminal ( buf ) 1565endfunc 1566 1567" Test for adding/removing lines inside diff chunks, between diff chunks 1568" and before diff chunks 1569func Test_diff_modify_chunks () 1570set diffopt = internal,filler 1571enew ! 1572let w2_id = win_getid () 1573call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ]) 1574new 1575let w1_id = win_getid () 1576call setline ( 1 , [ 'a' , '2' , '3' , 'd' , 'e' , 'f' , '7' , '8' , 'i' ]) 1577windo diffthis 1578 1579" remove a line between two diff chunks and create a new diff chunk 1580call win_gotoid ( w2_id ) 15815 d 1582call win_gotoid ( w1_id ) 1583call diff_hlID ( 5 , 1 ) -> synIDattr ( 'name' ) -> assert_equal ( 'DiffAdd' ) 1584 1585" add a line between two diff chunks 1586call win_gotoid ( w2_id ) 1587normal ! 4Goe 1588call win_gotoid ( w1_id ) 1589call diff_hlID ( 4 , 1 ) -> synIDattr ( 'name' ) -> assert_equal ( '' ) 1590call diff_hlID ( 5 , 1 ) -> synIDattr ( 'name' ) -> assert_equal ( '' ) 1591 1592" remove all the lines in a diff chunk. 1593call win_gotoid ( w2_id ) 15947 , 8 d 1595call win_gotoid ( w1_id ) 1596let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1597call assert_equal ([ '' , 'DiffText' , 'DiffText' , '' , '' , '' , 'DiffAdd' , 1598\ 'DiffAdd' , '' ], hl ) 1599 1600" remove lines from one diff chunk to just before the next diff chunk 1601call win_gotoid ( w2_id ) 1602call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ]) 16032 , 6 d 1604call win_gotoid ( w1_id ) 1605let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1606call assert_equal ([ '' , 'DiffText' , 'DiffText' , 'DiffAdd' , 'DiffAdd' , 1607\ 'DiffAdd' , 'DiffAdd' , 'DiffAdd' , '' ], hl ) 1608 1609" remove lines just before the top of a diff chunk 1610call win_gotoid ( w2_id ) 1611call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ]) 16125 , 6 d 1613call win_gotoid ( w1_id ) 1614let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1615call assert_equal ([ '' , 'DiffText' , 'DiffText' , '' , 'DiffText' , 'DiffText' , 1616\ 'DiffAdd' , 'DiffAdd' , '' ], hl ) 1617 1618" remove line after the end of a diff chunk 1619call win_gotoid ( w2_id ) 1620call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ]) 16214 d 1622call win_gotoid ( w1_id ) 1623let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1624call assert_equal ([ '' , 'DiffText' , 'DiffText' , 'DiffAdd' , '' , '' , 'DiffText' , 1625\ 'DiffText' , '' ], hl ) 1626 1627" remove lines starting from the end of one diff chunk and ending inside 1628" another diff chunk 1629call win_gotoid ( w2_id ) 1630call setline ( 1 , [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ]) 16314 , 7 d 1632call win_gotoid ( w1_id ) 1633let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1634call assert_equal ([ '' , 'DiffText' , 'DiffText' , 'DiffText' , 'DiffAdd' , 1635\ 'DiffAdd' , 'DiffAdd' , 'DiffAdd' , '' ], hl ) 1636 1637" removing the only remaining diff chunk should make the files equal 1638call win_gotoid ( w2_id ) 1639call setline ( 1 , [ 'a' , '2' , '3' , 'x' , 'd' , 'e' , 'f' , 'x' , '7' , '8' , 'i' ]) 16408 d 1641let hl = range ( 1 , 10 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1642call assert_equal ([ '' , '' , '' , 'DiffAdd' , '' , '' , '' , '' , '' , '' ], hl ) 1643call win_gotoid ( w2_id ) 16444 d 1645call win_gotoid ( w1_id ) 1646let hl = range ( 1 , 9 ) -> map ({ _ , lnum -> diff_hlID ( lnum , 1 ) -> synIDattr ( 'name' )}) 1647call assert_equal ([ '' , '' , '' , '' , '' , '' , '' , '' , '' ], hl ) 1648 1649% bw ! 1650set diffopt & 1651endfunc 1652 1653func Test_diff_binary () 1654CheckScreendump 1655 1656let content =<< trim END 1657call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g']) 1658vnew 1659call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g']) 1660windo diffthis 1661wincmd p 1662norm! gg0 1663redraw! 1664END 1665call writefile ( content , 'Xtest_diff_bin' , 'D' ) 1666let buf = RunVimInTerminal ( '-S Xtest_diff_bin' , {}) 1667 1668" Test using internal diff 1669call VerifyScreenDump ( buf , 'Test_diff_bin_01' , {}) 1670 1671" Test using internal diff and case folding 1672call term_sendkeys ( buf , ":set diffopt+=icase\<cr>" ) 1673call term_sendkeys ( buf , "\<C-l>" ) 1674call VerifyScreenDump ( buf , 'Test_diff_bin_02' , {}) 1675" Test using external diff 1676call term_sendkeys ( buf , ":set diffopt=filler\<cr>" ) 1677call term_sendkeys ( buf , "\<C-l>" ) 1678call VerifyScreenDump ( buf , 'Test_diff_bin_03' , {}) 1679" Test using external diff and case folding 1680call term_sendkeys ( buf , ":set diffopt=filler,icase\<cr>" ) 1681call term_sendkeys ( buf , "\<C-l>" ) 1682call VerifyScreenDump ( buf , 'Test_diff_bin_04' , {}) 1683 1684" clean up 1685call StopVimInTerminal ( buf ) 1686set diffopt & vim 1687endfunc 1688 1689" Test for using the 'zi' command to invert 'foldenable' in diff windows (test 1690" for the issue fixed by patch 6.2.317) 1691func Test_diff_foldinvert () 1692% bw ! 1693edit Xdoffile1 1694new Xdoffile2 1695new Xdoffile3 1696windo diffthis 1697" open a non-diff window 1698botright new 16991 wincmd w 1700call assert_true ( getwinvar ( 1 , '&foldenable' )) 1701call assert_true ( getwinvar ( 2 , '&foldenable' )) 1702call assert_true ( getwinvar ( 3 , '&foldenable' )) 1703normal zi 1704call assert_false ( getwinvar ( 1 , '&foldenable' )) 1705call assert_false ( getwinvar ( 2 , '&foldenable' )) 1706call assert_false ( getwinvar ( 3 , '&foldenable' )) 1707normal zi 1708call assert_true ( getwinvar ( 1 , '&foldenable' )) 1709call assert_true ( getwinvar ( 2 , '&foldenable' )) 1710call assert_true ( getwinvar ( 3 , '&foldenable' )) 1711 1712" If the current window has 'noscrollbind', then 'zi' should not change 1713" 'foldenable' in other windows. 17141 wincmd w 1715set noscrollbind 1716normal zi 1717call assert_false ( getwinvar ( 1 , '&foldenable' )) 1718call assert_true ( getwinvar ( 2 , '&foldenable' )) 1719call assert_true ( getwinvar ( 3 , '&foldenable' )) 1720 1721" 'zi' should not change the 'foldenable' for windows with 'noscrollbind' 17221 wincmd w 1723set scrollbind 1724normal zi 1725call setwinvar ( 2 , '&scrollbind' , v: false ) 1726normal zi 1727call assert_false ( getwinvar ( 1 , '&foldenable' )) 1728call assert_true ( getwinvar ( 2 , '&foldenable' )) 1729call assert_false ( getwinvar ( 3 , '&foldenable' )) 1730 1731% bw ! 1732set scrollbind & 1733endfunc 1734 1735" This was scrolling for 'cursorbind' but 'scrollbind' is more important 1736func Test_diff_scroll () 1737CheckScreendump 1738 1739let left =<< trim END 1740line 1 1741line 2 1742line 3 1743line 4 1744 1745// Common block 1746// one 1747// containing 1748// four lines 1749 1750// Common block 1751// two 1752// containing 1753// four lines 1754END 1755call writefile ( left , 'Xleft' , 'D' ) 1756let right =<< trim END 1757line 1 1758line 2 1759line 3 1760line 4 1761 1762Lorem 1763ipsum 1764dolor 1765sit 1766amet, 1767consectetur 1768adipiscing 1769elit. 1770Etiam 1771luctus 1772lectus 1773sodales, 1774dictum 1775 1776// Common block 1777// one 1778// containing 1779// four lines 1780 1781Vestibulum 1782tincidunt 1783aliquet 1784nulla. 1785 1786// Common block 1787// two 1788// containing 1789// four lines 1790END 1791call writefile ( right , 'Xright' , 'D' ) 1792let buf = RunVimInTerminal ( '-d Xleft Xright' , { 'rows' : 12 }) 1793call term_sendkeys ( buf , "\<C-W>\<C-W>jjjj" ) 1794call VerifyScreenDump ( buf , 'Test_diff_scroll_1' , {}) 1795call term_sendkeys ( buf , "j" ) 1796call VerifyScreenDump ( buf , 'Test_diff_scroll_2' , {}) 1797 1798call StopVimInTerminal ( buf ) 1799endfunc 1800 1801" This was scrolling too many lines. 1802func Test_diff_scroll_wrap_on () 180320 new 180440 vsplit 1805call setline ( 1 , map ( range ( 1 , 9 ), 'repeat(v:val, 200)' )) 1806setlocal number diff so = 0 1807redraw 1808normal ! jj 1809call assert_equal ( 1 , winsaveview (). topline ) 1810normal ! j 1811call assert_equal ( 2 , winsaveview (). topline ) 1812 1813bwipe ! 1814bwipe ! 1815endfunc 1816 1817func Test_diff_scroll_many_filler () 181820 new 1819vnew 1820call setline ( 1 , range ( 1 , 40 )) 1821diffthis 1822setlocal scrolloff = 0 1823wincmd p 1824call setline ( 1 , range ( 1 , 20 ) -> reverse () + [ '###' ] -> repeat ( 41 ) + range ( 21 , 40 ) -> reverse ()) 1825diffthis 1826setlocal scrolloff = 0 1827wincmd p 1828redraw 1829 1830" Note: need a redraw after each scroll, otherwise the test always passes. 1831for _ in range ( 2 ) 1832normal ! G 1833redraw 1834call assert_equal ( 40 , winsaveview (). topline ) 1835call assert_equal ( 19 , winsaveview (). topfill ) 1836exe "normal! \<C-B>" 1837redraw 1838call assert_equal ( 22 , winsaveview (). topline ) 1839call assert_equal ( 0 , winsaveview (). topfill ) 1840exe "normal! \<C-B>" 1841redraw 1842call assert_equal ( 4 , winsaveview (). topline ) 1843call assert_equal ( 0 , winsaveview (). topfill ) 1844exe "normal! \<C-B>" 1845redraw 1846call assert_equal ( 1 , winsaveview (). topline ) 1847call assert_equal ( 0 , winsaveview (). topfill ) 1848set smoothscroll 1849endfor 1850 1851set smoothscroll & 1852% bwipe ! 1853endfunc 1854 1855" This was trying to update diffs for a buffer being closed 1856func Test_diff_only () 1857silent ! lfile 1858set diff 1859lopen 1860norm o 1861silent ! norm o 1862 1863set nodiff 1864% bwipe ! 1865endfunc 1866 1867" This was causing invalid diff block values 1868" FIXME: somehow this causes a valgrind error when run directly but not when 1869" run as a test. 1870func Test_diff_manipulations () 1871set diff 1872split 0 1873sil ! norm R doobdeuR doobdeuR doobdeu 1874 1875set nodiff 1876% bwipe ! 1877endfunc 1878 1879" This was causing the line number in the diff block to go below one. 1880" FIXME: somehow this causes a valgrind error when run directly but not when 1881" run as a test. 1882func Test_diff_put_and_undo () 1883set diff 1884next 0 1885split 00 1886sil ! norm o0gguudpo0ggJuudp 1887 1888bwipe ! 1889bwipe ! 1890set nodiff 1891endfunc 1892 1893 1894func Test_diff_toggle_wrap_skipcol_leftcol () 189561 vnew 1896call setline ( 1 , 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.' ) 189730 vnew 1898call setline ( 1 , 'ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.' ) 1899let win1 = win_getid () 1900setlocal smoothscroll 1901exe "normal! $\<C-E>" 1902wincmd l 1903let win2 = win_getid () 1904setlocal smoothscroll 1905exe "normal! $\<C-E>" 1906call assert_equal ([ 1907\ '<<<sadipscing elitr, sed diam |<<<tetur sadipscing elitr, sed|' , 1908\ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|' , 1909\ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|' , 1910\ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|' , 1911\ '~ |ptua. |' , 1912\ ], ScreenLines ([ 1 , 5 ], 62 )) 1913call assert_equal ({ 'col' : 29 , 'row' : 4 , 'endcol' : 29 , 'curscol' : 29 }, 1914\ screenpos ( win1 , line ( '.' , win1 ), col ( '.' , win1 ))) 1915call assert_equal ({ 'col' : 36 , 'row' : 5 , 'endcol' : 36 , 'curscol' : 36 }, 1916\ screenpos ( win2 , line ( '.' , win2 ), col ( '.' , win2 ))) 1917 1918wincmd h 1919diffthis 1920wincmd l 1921diffthis 1922normal ! 0 1923call assert_equal ([ 1924\ ' ipsum dolor sit amet, conset| Lorem ipsum dolor sit amet, |' , 1925\ '~ |~ |' , 1926\ ], ScreenLines ([ 1 , 2 ], 62 )) 1927call assert_equal ({ 'col' : 3 , 'row' : 1 , 'endcol' : 3 , 'curscol' : 3 }, 1928\ screenpos ( win1 , line ( '.' , win1 ), col ( '.' , win1 ))) 1929call assert_equal ({ 'col' : 34 , 'row' : 1 , 'endcol' : 34 , 'curscol' : 34 }, 1930\ screenpos ( win2 , line ( '.' , win2 ), col ( '.' , win2 ))) 1931 1932normal ! $ 1933call assert_equal ([ 1934\ ' voluptua. | diam voluptua. |' , 1935\ '~ |~ |' , 1936\ ], ScreenLines ([ 1 , 2 ], 62 )) 1937call assert_equal ({ 'col' : 11 , 'row' : 1 , 'endcol' : 11 , 'curscol' : 11 }, 1938\ screenpos ( win1 , line ( '.' , win1 ), col ( '.' , win1 ))) 1939call assert_equal ({ 'col' : 48 , 'row' : 1 , 'endcol' : 48 , 'curscol' : 48 }, 1940\ screenpos ( win2 , line ( '.' , win2 ), col ( '.' , win2 ))) 1941 1942diffoff ! 1943call assert_equal ([ 1944\ 'ipsum dolor sit amet, consetet|Lorem ipsum dolor sit amet, co|' , 1945\ 'ur sadipscing elitr, sed diam |nsetetur sadipscing elitr, sed|' , 1946\ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|' , 1947\ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|' , 1948\ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|' , 1949\ '~ |ptua. |' , 1950\ ], ScreenLines ([ 1 , 6 ], 62 )) 1951call assert_equal ({ 'col' : 29 , 'row' : 5 , 'endcol' : 29 , 'curscol' : 29 }, 1952\ screenpos ( win1 , line ( '.' , win1 ), col ( '.' , win1 ))) 1953call assert_equal ({ 'col' : 36 , 'row' : 6 , 'endcol' : 36 , 'curscol' : 36 }, 1954\ screenpos ( win2 , line ( '.' , win2 ), col ( '.' , win2 ))) 1955 1956bwipe ! 1957bwipe ! 1958endfunc 1959 1960" Ctrl-D reveals filler lines below the last line in the buffer. 1961func Test_diff_eob_halfpage () 1962new 1963call setline ( 1 , [ '' ] -> repeat ( 10 ) + [ 'a' ]) 1964diffthis 1965new 1966call setline ( 1 , [ '' ] -> repeat ( 3 ) + [ 'a' , 'b' ]) 1967diffthis 1968resize 5 1969wincmd j 1970resize 5 1971norm G 1972call assert_equal ( 7 , line ( 'w0' )) 1973exe "norm! \<C-D>" 1974call assert_equal ( 8 , line ( 'w0' )) 1975 1976% bwipe ! 1977endfunc 1978 1979func Test_diff_overlapped_diff_blocks_will_be_merged () 1980CheckScreendump 1981 1982let lines =<< trim END 1983func DiffExprStub() 1984let txt_in = readfile(v:fname_in) 1985let txt_new = readfile(v:fname_new) 1986if txt_in == ["line1"] && txt_new == ["line2"] 1987call writefile(["1c1"], v:fname_out) 1988elseif txt_in == readfile("Xdiin1") && txt_new == readfile("Xdinew1") 1989call writefile(readfile("Xdiout1"), v:fname_out) 1990elseif txt_in == readfile("Xdiin2") && txt_new == readfile("Xdinew2") 1991call writefile(readfile("Xdiout2"), v:fname_out) 1992endif 1993endfunc 1994END 1995call writefile ( lines , 'XdiffSetup' , 'D' ) 1996 1997call WriteDiffFiles ( 0 , [], []) 1998let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2' , {}) 1999call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2000 2001call WriteDiffFiles ( buf , [ "a" , "b" ], [ "x" , "x" ]) 2002call writefile ([ "a" , "b" ], "Xdiin1" ) 2003call writefile ([ "x" , "x" ], "Xdinew1" ) 2004call writefile ([ "1c1" , "2c2" ], "Xdiout1" ) 2005call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2006call VerifyBoth ( buf , "Test_diff_overlapped_2.01" , "" ) 2007call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2008 2009call WriteDiffFiles ( buf , [ "a" , "b" , "c" ], [ "x" , "c" ]) 2010call writefile ([ "a" , "b" , "c" ], "Xdiin1" ) 2011call writefile ([ "x" , "c" ], "Xdinew1" ) 2012call writefile ([ "1c1" , "2d1" ], "Xdiout1" ) 2013call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2014call VerifyBoth ( buf , "Test_diff_overlapped_2.02" , "" ) 2015call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2016 2017call WriteDiffFiles ( buf , [ "a" , "c" ], [ "x" , "x" , "c" ]) 2018call writefile ([ "a" , "c" ], "Xdiin1" ) 2019call writefile ([ "x" , "x" , "c" ], "Xdinew1" ) 2020call writefile ([ "1c1" , "1a2" ], "Xdiout1" ) 2021call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2022call VerifyBoth ( buf , "Test_diff_overlapped_2.03" , "" ) 2023call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2024 2025call StopVimInTerminal ( buf ) 2026wincmd c 2027 2028call WriteDiffFiles3 ( 0 , [], [], []) 2029let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2 Xdifile3' , {}) 2030call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2031 2032call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "y" , "b" , "c" ]) 2033call VerifyBoth ( buf , "Test_diff_overlapped_3.01" , "" ) 2034 2035call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "y" , "c" ]) 2036call VerifyBoth ( buf , "Test_diff_overlapped_3.02" , "" ) 2037 2038call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "b" , "y" ]) 2039call VerifyBoth ( buf , "Test_diff_overlapped_3.03" , "" ) 2040 2041call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "y" , "y" , "c" ]) 2042call VerifyBoth ( buf , "Test_diff_overlapped_3.04" , "" ) 2043 2044call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "y" , "y" ]) 2045call VerifyBoth ( buf , "Test_diff_overlapped_3.05" , "" ) 2046 2047call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "y" , "y" , "y" ]) 2048call VerifyBoth ( buf , "Test_diff_overlapped_3.06" , "" ) 2049 2050call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "x" ], [ "y" , "y" , "c" ]) 2051call VerifyBoth ( buf , "Test_diff_overlapped_3.07" , "" ) 2052 2053call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "x" , "x" , "c" ], [ "a" , "y" , "y" ]) 2054call VerifyBoth ( buf , "Test_diff_overlapped_3.08" , "" ) 2055 2056call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "y" , "y" , "y" , "d" , "e" ]) 2057call VerifyBoth ( buf , "Test_diff_overlapped_3.09" , "" ) 2058 2059call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "y" , "y" , "y" , "y" , "e" ]) 2060call VerifyBoth ( buf , "Test_diff_overlapped_3.10" , "" ) 2061 2062call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "y" , "y" , "y" , "y" , "y" ]) 2063call VerifyBoth ( buf , "Test_diff_overlapped_3.11" , "" ) 2064 2065call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "y" , "y" , "d" , "e" ]) 2066call VerifyBoth ( buf , "Test_diff_overlapped_3.12" , "" ) 2067 2068call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "y" , "y" , "y" , "e" ]) 2069call VerifyBoth ( buf , "Test_diff_overlapped_3.13" , "" ) 2070 2071call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "y" , "y" , "y" , "y" ]) 2072call VerifyBoth ( buf , "Test_diff_overlapped_3.14" , "" ) 2073 2074call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" , "y" , "d" , "e" ]) 2075call VerifyBoth ( buf , "Test_diff_overlapped_3.15" , "" ) 2076 2077call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" , "y" , "y" , "e" ]) 2078call VerifyBoth ( buf , "Test_diff_overlapped_3.16" , "" ) 2079 2080call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" , "y" , "y" , "y" ]) 2081call VerifyBoth ( buf , "Test_diff_overlapped_3.17" , "" ) 2082 2083call WriteDiffFiles3 ( buf , [ "a" , "b" ], [ "x" , "b" ], [ "y" , "y" ]) 2084call writefile ([ "a" , "b" ], "Xdiin1" ) 2085call writefile ([ "x" , "b" ], "Xdinew1" ) 2086call writefile ([ "1c1" ], "Xdiout1" ) 2087call writefile ([ "a" , "b" ], "Xdiin2" ) 2088call writefile ([ "y" , "y" ], "Xdinew2" ) 2089call writefile ([ "1c1" , "2c2" ], "Xdiout2" ) 2090call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2091call VerifyInternal ( buf , "Test_diff_overlapped_3.18" , "" ) 2092call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2093 2094call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" ], [ "x" , "b" , "x" , "d" ], [ "y" , "y" , "c" , "d" ]) 2095call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin1" ) 2096call writefile ([ "x" , "b" , "x" , "d" ], "Xdinew1" ) 2097call writefile ([ "1c1" , "3c3" ], "Xdiout1" ) 2098call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin2" ) 2099call writefile ([ "y" , "y" , "c" , "d" ], "Xdinew2" ) 2100call writefile ([ "1c1" , "2c2" ], "Xdiout2" ) 2101call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2102call VerifyInternal ( buf , "Test_diff_overlapped_3.19" , "" ) 2103call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2104 2105call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" ], [ "x" , "b" , "x" , "d" ], [ "y" , "y" , "y" , "d" ]) 2106call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin1" ) 2107call writefile ([ "x" , "b" , "x" , "d" ], "Xdinew1" ) 2108call writefile ([ "1c1" , "3c3" ], "Xdiout1" ) 2109call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin2" ) 2110call writefile ([ "y" , "y" , "y" , "d" ], "Xdinew2" ) 2111call writefile ([ "1c1" , "2,3c2,3" ], "Xdiout2" ) 2112call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2113call VerifyInternal ( buf , "Test_diff_overlapped_3.20" , "" ) 2114call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2115 2116call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" ], [ "x" , "b" , "x" , "d" ], [ "y" , "y" , "y" , "y" ]) 2117call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin1" ) 2118call writefile ([ "x" , "b" , "x" , "d" ], "Xdinew1" ) 2119call writefile ([ "1c1" , "3c3" ], "Xdiout1" ) 2120call writefile ([ "a" , "b" , "c" , "d" ], "Xdiin2" ) 2121call writefile ([ "y" , "y" , "y" , "y" ], "Xdinew2" ) 2122call writefile ([ "1c1" , "2,4c2,4" ], "Xdiout2" ) 2123call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" ) 2124call VerifyInternal ( buf , "Test_diff_overlapped_3.21" , "" ) 2125call term_sendkeys ( buf , ":set diffexpr&\<CR>:" ) 2126 2127call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "b" , "c" ]) 2128call VerifyBoth ( buf , "Test_diff_overlapped_3.22" , "" ) 2129 2130call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "c" ]) 2131call VerifyBoth ( buf , "Test_diff_overlapped_3.23" , "" ) 2132 2133call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], []) 2134call VerifyBoth ( buf , "Test_diff_overlapped_3.24" , "" ) 2135 2136call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "c" ]) 2137call VerifyBoth ( buf , "Test_diff_overlapped_3.25" , "" ) 2138 2139call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" ]) 2140call VerifyBoth ( buf , "Test_diff_overlapped_3.26" , "" ) 2141 2142call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "b" ]) 2143call VerifyBoth ( buf , "Test_diff_overlapped_3.27" , "" ) 2144 2145call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "d" , "e" ]) 2146call VerifyBoth ( buf , "Test_diff_overlapped_3.28" , "" ) 2147 2148call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "e" ]) 2149call VerifyBoth ( buf , "Test_diff_overlapped_3.29" , "" ) 2150 2151call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "d" , "e" ]) 2152call VerifyBoth ( buf , "Test_diff_overlapped_3.30" , "" ) 2153 2154call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "e" ]) 2155call VerifyBoth ( buf , "Test_diff_overlapped_3.31" , "" ) 2156 2157call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" ]) 2158call VerifyBoth ( buf , "Test_diff_overlapped_3.32" , "" ) 2159 2160call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" , "d" , "e" ]) 2161call VerifyBoth ( buf , "Test_diff_overlapped_3.33" , "" ) 2162 2163call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" , "e" ]) 2164call VerifyBoth ( buf , "Test_diff_overlapped_3.34" , "" ) 2165 2166call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" , "d" , "e" ], [ "a" , "x" , "c" , "x" , "e" ], [ "a" , "b" ]) 2167call VerifyBoth ( buf , "Test_diff_overlapped_3.35" , "" ) 2168 2169call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "y" , "b" , "c" ]) 2170call VerifyBoth ( buf , "Test_diff_overlapped_3.36" , "" ) 2171 2172call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "a" , "x" , "c" ], [ "a" , "b" , "y" , "c" ]) 2173call VerifyBoth ( buf , "Test_diff_overlapped_3.37" , "" ) 2174 2175call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "d" , "e" ], [ "b" , "f" ]) 2176call VerifyBoth ( buf , "Test_diff_overlapped_3.38" , "" ) 2177 2178call WriteDiffFiles3 ( buf , [ "a" , "b" , "c" ], [ "d" , "e" ], [ "b" ]) 2179call VerifyBoth ( buf , "Test_diff_overlapped_3.39" , "" ) 2180 2181" File 3 overlaps twice, 2nd overlap completely within the existing block. 2182call WriteDiffFiles3 ( buf , [ "foo" , "a" , "b" , "c" , "bar" ], [ "foo" , "w" , "x" , "y" , "z" , "bar" ], [ "foo" , "1" , "a" , "b" , "2" , "bar" ]) 2183call VerifyBoth ( buf , "Test_diff_overlapped_3.40" , "" ) 2184 2185" File 3 overlaps twice, 2nd overlap extends beyond existing block on new 2186" side. Make sure we don't over-extend the range and hit 'bar'. 2187call WriteDiffFiles3 ( buf , [ "foo" , "a" , "b" , "c" , "d" , "bar" ], [ "foo" , "w" , "x" , "y" , "z" , "u" , "bar" ], [ "foo" , "1" , "a" , "b" , "2" , "d" , "bar" ]) 2188call VerifyBoth ( buf , "Test_diff_overlapped_3.41" , "" ) 2189 2190" Chained overlaps. File 3's 2nd overlap spans two diff blocks and is longer 2191" than the 2nd one. 2192call WriteDiffFiles3 ( buf , [ "foo" , "a" , "b" , "c" , "d" , "e" , "f" , "bar" ], [ "foo" , "w" , "x" , "y" , "z" , "e" , "u" , "bar" ], [ "foo" , "1" , "b" , "2" , "3" , "d" , "4" , "f" , "bar" ]) 2193call VerifyBoth ( buf , "Test_diff_overlapped_3.42" , "" ) 2194 2195" File 3 has 2 overlaps. An add and a delete. First overlap's expansion hits 2196" the 2nd one. Make sure we adjust the diff block to have fewer lines. 2197call WriteDiffFiles3 ( buf , [ "foo" , "a" , "b" , "bar" ], [ "foo" , "x" , "y" , "bar" ], [ "foo" , "1" , "a" , "bar" ]) 2198call VerifyBoth ( buf , "Test_diff_overlapped_3.43" , "" ) 2199 2200" File 3 has 2 overlaps. An add and another add. First overlap's expansion hits 2201" the 2nd one. Make sure we adjust the diff block to have more lines. 2202call WriteDiffFiles3 ( buf , [ "foo" , "a" , "b" , "c" , "d" , "bar" ], [ "foo" , "w" , "x" , "y" , "z" , "u" , "bar" ], [ "foo" , "1" , "a" , "b" , "3" , "4" , "d" , "bar" ]) 2203call VerifyBoth ( buf , "Test_diff_overlapped_3.44" , "" ) 2204 2205call StopVimInTerminal ( buf ) 2206endfunc 2207 2208" switching windows in diff mode caused an unnecessary scroll 2209func Test_diff_topline_noscroll () 2210CheckScreendump 2211 2212let content =<< trim END 2213call setline(1, range(1,60)) 2214vnew 2215call setline(1, range(1,10) + range(50,60)) 2216windo diffthis 2217norm! G 2218exe "norm! 30\<C-y>" 2219END 2220call writefile ( content , 'Xcontent' , 'D' ) 2221let buf = RunVimInTerminal ( '-S Xcontent' , { 'rows' : 20 }) 2222call VerifyScreenDump ( buf , 'Test_diff_topline_1' , {}) 2223call term_sendkeys ( buf , ":echo line('w0', 1001)\<cr>" ) 2224call term_wait ( buf ) 2225call VerifyScreenDump ( buf , 'Test_diff_topline_2' , {}) 2226call term_sendkeys ( buf , "\<C-W>p" ) 2227call term_wait ( buf ) 2228call VerifyScreenDump ( buf , 'Test_diff_topline_3' , {}) 2229call term_sendkeys ( buf , "\<C-W>p" ) 2230call term_wait ( buf ) 2231call VerifyScreenDump ( buf , 'Test_diff_topline_4' , {}) 2232call StopVimInTerminal ( buf ) 2233endfunc 2234 2235" Test inline highlighting which shows what's different within each diff block 2236func Test_diff_inline () 2237CheckScreendump 2238 2239call WriteDiffFiles ( 0 , [], []) 2240let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2241call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2242 2243call WriteDiffFiles ( buf , [ "abcdef ghi jk n" , "x" , "y" ], [ "aBcef gHi lm n" , "y" , "z" ]) 2244call VerifyInternal ( buf , "Test_diff_inline_01" , "" ) 2245call VerifyInternal ( buf , "Test_diff_inline_02" , " diffopt+=inline:none" ) 2246 2247" inline:simple is the same as default 2248call VerifyInternal ( buf , "Test_diff_inline_01" , " diffopt+=inline:simple" ) 2249 2250call VerifyInternal ( buf , "Test_diff_inline_03" , " diffopt+=inline:char" ) 2251call VerifyInternal ( buf , "Test_diff_inline_04" , " diffopt+=inline:word" ) 2252 2253" multiple inline values will the last one 2254call VerifyInternal ( buf , "Test_diff_inline_01" , " diffopt+=inline:none,inline:char,inline:simple" ) 2255call VerifyInternal ( buf , "Test_diff_inline_02" , " diffopt+=inline:simple,inline:word,inline:none" ) 2256call VerifyInternal ( buf , "Test_diff_inline_03" , " diffopt+=inline:simple,inline:word,inline:char" ) 2257 2258" DiffTextAdd highlight 2259call term_sendkeys ( buf , ":hi DiffTextAdd ctermbg=blue\<CR>" ) 2260call VerifyInternal ( buf , "Test_diff_inline_05" , " diffopt+=inline:char" ) 2261 2262" Live update in insert mode 2263call term_sendkeys ( buf , "\<Esc>isometext" ) 2264call VerifyScreenDump ( buf , "Test_diff_inline_06" , {}) 2265call term_sendkeys ( buf , "\<Esc>u" ) 2266 2267" icase simple scenarios 2268call VerifyInternal ( buf , "Test_diff_inline_07" , " diffopt+=inline:simple,icase" ) 2269call VerifyInternal ( buf , "Test_diff_inline_08" , " diffopt+=inline:char,icase" ) 2270call VerifyInternal ( buf , "Test_diff_inline_09" , " diffopt+=inline:word,icase" ) 2271 2272" diff algorithms should affect highlight 2273call WriteDiffFiles ( buf , [ "apples and oranges" ], [ "oranges and apples" ]) 2274call VerifyInternal ( buf , "Test_diff_inline_10" , " diffopt+=inline:char" ) 2275call VerifyInternal ( buf , "Test_diff_inline_11" , " diffopt+=inline:char,algorithm:patience" ) 2276 2277" icase: composing chars and Unicode fold case edge cases 2278call WriteDiffFiles ( buf , 2279\ [ "1 - sigma in 6σ and Ὀδυσσεύς" , "1 - angstrom in åå" , "1 - composing: ii⃗I⃗" ], 2280\ [ "2 - Sigma in 6Σ and ὈΔΥΣΣΕΎΣ" , "2 - Angstrom in ÅÅ" , "2 - Composing: i⃗I⃗I⃗" ]) 2281call VerifyInternal ( buf , "Test_diff_inline_12" , " diffopt+=inline:char" ) 2282call VerifyInternal ( buf , "Test_diff_inline_13" , " diffopt+=inline:char,icase" ) 2283 2284" wide chars 2285call WriteDiffFiles ( buf , [ "abc😅xde一" , "f🚀g" ], [ "abcy😢de" , "二f🚀g" ]) 2286call VerifyInternal ( buf , "Test_diff_inline_14" , " diffopt+=inline:char,icase" ) 2287 2288" NUL char (\n below is internally substituted as NUL) 2289call WriteDiffFiles ( buf , [ "1\n34\n5\n6" ], [ "1234\n5" , "6" ]) 2290call VerifyInternal ( buf , "Test_diff_inline_15" , " diffopt+=inline:char" ) 2291 2292" word diff: always use first buffer's iskeyword and ignore others' for consistency 2293call WriteDiffFiles ( buf , [ "foo+bar test" ], [ "foo+baz test" ]) 2294call VerifyInternal ( buf , "Test_diff_inline_word_01" , " diffopt+=inline:word" ) 2295 2296call term_sendkeys ( buf , ":set iskeyword+=+\<CR>:diffupdate\<CR>" ) 2297call VerifyInternal ( buf , "Test_diff_inline_word_02" , " diffopt+=inline:word" ) 2298 2299call term_sendkeys ( buf , ":set iskeyword&\<CR>:wincmd w\<CR>" ) 2300call term_sendkeys ( buf , ":set iskeyword+=+\<CR>:wincmd w\<CR>:diffupdate\<CR>" ) 2301" Use the previous screen dump as 2nd buffer's iskeyword does not matter 2302call VerifyInternal ( buf , "Test_diff_inline_word_01" , " diffopt+=inline:word" ) 2303 2304call term_sendkeys ( buf , ":windo set iskeyword&\<CR>:1wincmd w\<CR>" ) 2305 2306" word diff: test handling of multi-byte characters. Only alphanumeric chars 2307" (e.g. Greek alphabet, but not CJK/emoji) count as words. 2308call WriteDiffFiles ( buf , [ "🚀⛵️一二三ひらがなΔέλτα Δelta foobar" ], [ "🚀🛸一二四ひらなδέλτα δelta foobar" ]) 2309call VerifyInternal ( buf , "Test_diff_inline_word_03" , " diffopt+=inline:word" ) 2310 2311" char diff: should slide highlight to whitespace boundary if possible for 2312" better readability (by using forced indent-heuristics). A wrong result 2313" would be if the highlight is "Bar, prefix". It should be "prefixBar, " 2314" instead. 2315call WriteDiffFiles ( buf , [ "prefixFoo, prefixEnd" ], [ "prefixFoo, prefixBar, prefixEnd" ]) 2316call VerifyInternal ( buf , "Test_diff_inline_char_01" , " diffopt+=inline:char" ) 2317 2318" char diff: small gaps between inline diff blocks will be merged during refine step 2319" - first segment: test that we iteratively merge small gaps after we merged 2320" adjacent blocks, but only with limited number (set to 4) of iterations. 2321" - second and third segments: show that we need a large enough adjacent block to 2322" trigger a merge. 2323" - fourth segment: small gaps are not merged when adjacent large block is 2324" on a different line. 2325call WriteDiffFiles ( buf , 2326\ [ "abcdefghijklmno" , "anchor1" , 2327\ "abcdefghijklmno" , "anchor2" , 2328\ "abcdefghijklmno" , "anchor3" , 2329\ "test" , "multiline" ], 2330\ [ "a?c?e?g?i?k???o" , "anchor1" , 2331\ "a??de?????klmno" , "anchor2" , 2332\ "a??de??????lmno" , "anchor3" , 2333\ "t?s?" , "??????i?e" ]) 2334call VerifyInternal ( buf , "Test_diff_inline_char_02" , " diffopt+=inline:char" ) 2335 2336" Test multi-line blocks and whitespace 2337call WriteDiffFiles ( buf , 2338\ [ "this is " , "sometest text foo" , "baz abc def " , "one" , "word another word" , "additional line" ], 2339\ [ "this is some test" , "texts" , "foo bar abX Yef " , "oneword another word" ]) 2340call VerifyInternal ( buf , "Test_diff_inline_multiline_01" , " diffopt+=inline:char,iwhite" ) 2341call VerifyInternal ( buf , "Test_diff_inline_multiline_02" , " diffopt+=inline:word,iwhite" ) 2342call VerifyInternal ( buf , "Test_diff_inline_multiline_03" , " diffopt+=inline:char,iwhiteeol" ) 2343call VerifyInternal ( buf , "Test_diff_inline_multiline_04" , " diffopt+=inline:word,iwhiteeol" ) 2344call VerifyInternal ( buf , "Test_diff_inline_multiline_05" , " diffopt+=inline:char,iwhiteall" ) 2345call VerifyInternal ( buf , "Test_diff_inline_multiline_06" , " diffopt+=inline:word,iwhiteall" ) 2346 2347" newline should be highlighted too when 'list' is set 2348call term_sendkeys ( buf , ":windo set list\<CR>" ) 2349call VerifyInternal ( buf , "Test_diff_inline_multiline_07" , " diffopt+=inline:char" ) 2350call VerifyInternal ( buf , "Test_diff_inline_multiline_08" , " diffopt+=inline:char,iwhite" ) 2351call VerifyInternal ( buf , "Test_diff_inline_multiline_09" , " diffopt+=inline:char,iwhiteeol" ) 2352call VerifyInternal ( buf , "Test_diff_inline_multiline_10" , " diffopt+=inline:char,iwhiteall" ) 2353call term_sendkeys ( buf , ":windo set nolist\<CR>" ) 2354 2355call StopVimInTerminal ( buf ) 2356endfunc 2357 2358func Test_diff_inline_multibuffer () 2359CheckScreendump 2360 2361call WriteDiffFiles3 ( 0 , [], [], []) 2362let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3' , {}) 2363call term_sendkeys ( buf , ":windo set autoread\<CR>:1wincmd w\<CR>" ) 2364call term_sendkeys ( buf , ":hi DiffTextAdd ctermbg=blue\<CR>" ) 2365 2366call WriteDiffFiles3 ( buf , 2367\ [ "That is buffer1." , "anchor" , "Some random text" , "anchor" ], 2368\ [ "This is buffer2." , "anchor" , "Some text" , "anchor" , "buffer2/3" ], 2369\ [ "This is buffer3. Last." , "anchor" , "Some more" , "text here." , "anchor" , "only in buffer2/3" , "not in buffer1" ]) 2370call VerifyInternal ( buf , "Test_diff_inline_multibuffer_01" , " diffopt+=inline:char" ) 2371 2372" Close one of the buffers and make sure it updates correctly 2373call term_sendkeys ( buf , ":diffoff\<CR>" ) 2374call VerifyInternal ( buf , "Test_diff_inline_multibuffer_02" , " diffopt+=inline:char" ) 2375 2376" Update text in the non-diff buffer and nothing should be changed 2377call term_sendkeys ( buf , "\<Esc>isometext" ) 2378call VerifyScreenDump ( buf , "Test_diff_inline_multibuffer_03" , {}) 2379call term_sendkeys ( buf , "\<Esc>u" ) 2380 2381call term_sendkeys ( buf , ":diffthis\<CR>" ) 2382call VerifyInternal ( buf , "Test_diff_inline_multibuffer_01" , " diffopt+=inline:char" ) 2383 2384" Test that removing first buffer from diff will in turn use the next 2385" earliest buffer's iskeyword during word diff. 2386call WriteDiffFiles3 ( buf , 2387\ [ "This+is=a-setence" ], 2388\ [ "This+is=another-setence" ], 2389\ [ "That+is=a-setence" ]) 2390call term_sendkeys ( buf , ":set iskeyword+=+\<CR>:2wincmd w\<CR>:set iskeyword+=-\<CR>:1wincmd w\<CR>" ) 2391call VerifyInternal ( buf , "Test_diff_inline_multibuffer_04" , " diffopt+=inline:word" ) 2392call term_sendkeys ( buf , ":diffoff\<CR>" ) 2393call VerifyInternal ( buf , "Test_diff_inline_multibuffer_05" , " diffopt+=inline:word" ) 2394call term_sendkeys ( buf , ":diffthis\<CR>" ) 2395call VerifyInternal ( buf , "Test_diff_inline_multibuffer_04" , " diffopt+=inline:word" ) 2396 2397" Test multi-buffer char diff refinement, and that removing a buffer from 2398" diff will update the others properly. 2399call WriteDiffFiles3 ( buf , 2400\ [ "abcdefghijkYmYYY" ], 2401\ [ "aXXdXXghijklmnop" ], 2402\ [ "abcdefghijkYmYop" ]) 2403call VerifyInternal ( buf , "Test_diff_inline_multibuffer_06" , " diffopt+=inline:char" ) 2404call term_sendkeys ( buf , ":diffoff\<CR>" ) 2405call VerifyInternal ( buf , "Test_diff_inline_multibuffer_07" , " diffopt+=inline:char" ) 2406call term_sendkeys ( buf , ":diffthis\<CR>" ) 2407call VerifyInternal ( buf , "Test_diff_inline_multibuffer_06" , " diffopt+=inline:char" ) 2408 2409call StopVimInTerminal ( buf ) 2410endfunc 2411 2412" Test that when using multi-buffer diff, an empty block would be correctly 2413" skipped in the result, without resulting in invalid states or crashes. 2414func Test_diff_inline_multibuffer_empty_block () 2415CheckScreendump 2416 2417call writefile ([ 'anchor1' , '1234567890abcde' , 'anchor2' ], 'Xdifile1' ) 2418call writefile ([ 'anchor1' , '1234567--0abc-e' , 'anchor2' ], 'Xdifile2' ) 2419call writefile ([ 'anchor1' , 'anchor2' ], 'Xdifile3' ) 2420call writefile ([ 'anchor1' , '1???????90abcd?' , 'anchor2' ], 'Xdifile4' ) 2421 2422let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3 Xdifile4' , {}) 2423call VerifyInternal ( buf , "Test_diff_inline_multibuffer_empty_block_01" , " diffopt+=inline:char" ) 2424 2425call StopVimInTerminal ( buf ) 2426endfunc 2427 2428" An inline:word diff block that starts with inserted words has df_count zero 2429" for the first buffer, then the index of its last line is negative. This 2430" caused a heap-buffer underflow 2431func Test_diff_inline_word_empty_block () 2432set diffopt = internal,filler,inline:word 2433enew ! 2434call setline ( 1 , [ 'b c' , 'y z' ]) 2435diffthis 2436vnew 2437call setline ( 1 , [ 'a b c d e' , 'x y z w v' ]) 2438diffthis 2439redraw 2440 2441" Part of the line is highlighted, not all of it. 2442let attrs = map ( range ( 1 , 9 ), 'screenattr(1, v:val)' ) 2443call assert_true ( len ( uniq ( sort ( attrs ))) > 1 ) 2444 2445diffoff ! 2446set diffopt & 2447bwipe ! 2448bwipe ! 2449endfunc 2450 2451func Test_diffget_diffput_linematch () 2452CheckScreendump 2453call delete ( '.Xdifile1.swp' ) 2454call delete ( '.Xdifile2.swp' ) 2455call WriteDiffFiles ( 0 , [], []) 2456let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2457call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2458 2459" enable linematch 2460call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" ) 2461call WriteDiffFiles ( buf , [ '' , 2462\ 'common line' , 2463\ 'common line' , 2464\ '' , 2465\ 'ABCabc' , 2466\ 'ABCabc' , 2467\ 'ABCabc' , 2468\ 'ABCabc' , 2469\ 'common line' , 2470\ 'common line' , 2471\ 'common line' , 2472\ 'something' ], 2473\ [ '' , 2474\ 'common line' , 2475\ 'common line' , 2476\ '' , 2477\ 'DEFabc' , 2478\ 'xyz' , 2479\ 'xyz' , 2480\ 'xyz' , 2481\ 'DEFabc' , 2482\ 'DEFabc' , 2483\ 'DEFabc' , 2484\ 'common line' , 2485\ 'common line' , 2486\ 'DEF' , 2487\ 'common line' , 2488\ 'DEF' , 2489\ 'something' ]) 2490call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_1' , {}) 2491 2492" get from window 1 from line 5 to 9 2493call term_sendkeys ( buf , "1\<c-w>w" ) 2494call term_sendkeys ( buf , ":5,9diffget\<CR>" ) 2495call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_2' , {}) 2496 2497" undo the last diffget 2498call term_sendkeys ( buf , "u" ) 2499 2500" get from window 2 from line 5 to 10 2501call term_sendkeys ( buf , "2\<c-w>w" ) 2502call term_sendkeys ( buf , ":5,10diffget\<CR>" ) 2503call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_3' , {}) 2504 2505" undo the last diffget 2506call term_sendkeys ( buf , "u" ) 2507 2508" get all from window 2 2509call term_sendkeys ( buf , "2\<c-w>w" ) 2510call term_sendkeys ( buf , ":4,17diffget\<CR>" ) 2511call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_4' , {}) 2512 2513" undo the last diffget 2514call term_sendkeys ( buf , "u" ) 2515 2516" get all from window 1 2517call term_sendkeys ( buf , "1\<c-w>w" ) 2518call term_sendkeys ( buf , ":4,12diffget\<CR>" ) 2519call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_5' , {}) 2520 2521" undo the last diffget 2522call term_sendkeys ( buf , "u" ) 2523 2524" get from window 1 using do 1 line 5 2525call term_sendkeys ( buf , "1\<c-w>w" ) 2526call term_sendkeys ( buf , "5gg" ) 2527call term_sendkeys ( buf , ":diffget\<CR>" ) 2528call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_6' , {}) 2529 2530" undo the last diffget 2531call term_sendkeys ( buf , "u" ) 2532 2533" get from window 1 using do 2 line 6 2534call term_sendkeys ( buf , "1\<c-w>w" ) 2535call term_sendkeys ( buf , "6gg" ) 2536call term_sendkeys ( buf , ":diffget\<CR>" ) 2537call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_7' , {}) 2538 2539" undo the last diffget 2540call term_sendkeys ( buf , "u" ) 2541 2542" get from window 1 using do 2 line 7 2543call term_sendkeys ( buf , "1\<c-w>w" ) 2544call term_sendkeys ( buf , "7gg" ) 2545call term_sendkeys ( buf , ":diffget\<CR>" ) 2546call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_8' , {}) 2547 2548" undo the last diffget 2549call term_sendkeys ( buf , "u" ) 2550 2551" get from window 1 using do 2 line 11 2552call term_sendkeys ( buf , "1\<c-w>w" ) 2553call term_sendkeys ( buf , "11gg" ) 2554call term_sendkeys ( buf , ":diffget\<CR>" ) 2555call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_9' , {}) 2556 2557" undo the last diffget 2558call term_sendkeys ( buf , "u" ) 2559 2560" get from window 1 using do 2 line 12 2561call term_sendkeys ( buf , "1\<c-w>w" ) 2562call term_sendkeys ( buf , "12gg" ) 2563call term_sendkeys ( buf , ":diffget\<CR>" ) 2564call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_10' , {}) 2565 2566" undo the last diffget 2567call term_sendkeys ( buf , "u" ) 2568 2569" put from window 1 using dp 1 line 5 2570call term_sendkeys ( buf , "1\<c-w>w" ) 2571call term_sendkeys ( buf , "5gg" ) 2572call term_sendkeys ( buf , ":diffput\<CR>" ) 2573call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_11' , {}) 2574 2575" undo the last diffput 2576call term_sendkeys ( buf , "2\<c-w>w" ) 2577call term_sendkeys ( buf , "u" ) 2578 2579" put from window 1 using dp 2 line 6 2580call term_sendkeys ( buf , "1\<c-w>w" ) 2581call term_sendkeys ( buf , "6gg" ) 2582call term_sendkeys ( buf , ":diffput\<CR>" ) 2583call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_12' , {}) 2584 2585" undo the last diffput 2586call term_sendkeys ( buf , "2\<c-w>w" ) 2587call term_sendkeys ( buf , "u" ) 2588 2589" put from window 1 using dp 2 line 7 2590call term_sendkeys ( buf , "1\<c-w>w" ) 2591call term_sendkeys ( buf , "7gg" ) 2592call term_sendkeys ( buf , ":diffput\<CR>" ) 2593call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_13' , {}) 2594 2595" undo the last diffput 2596call term_sendkeys ( buf , "2\<c-w>w" ) 2597call term_sendkeys ( buf , "u" ) 2598 2599" put from window 1 using dp 2 line 11 2600call term_sendkeys ( buf , "1\<c-w>w" ) 2601call term_sendkeys ( buf , "11gg" ) 2602call term_sendkeys ( buf , ":diffput\<CR>" ) 2603call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_14' , {}) 2604 2605" undo the last diffput 2606call term_sendkeys ( buf , "2\<c-w>w" ) 2607call term_sendkeys ( buf , "u" ) 2608 2609" put from window 1 using dp 2 line 12 2610call term_sendkeys ( buf , "1\<c-w>w" ) 2611call term_sendkeys ( buf , "12gg" ) 2612call term_sendkeys ( buf , ":diffput\<CR>" ) 2613call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_15' , {}) 2614 2615" undo the last diffput 2616call term_sendkeys ( buf , "2\<c-w>w" ) 2617call term_sendkeys ( buf , "u" ) 2618 2619" put from window 2 using dp line 6 2620call term_sendkeys ( buf , "2\<c-w>w" ) 2621call term_sendkeys ( buf , "6gg" ) 2622call term_sendkeys ( buf , ":diffput\<CR>" ) 2623call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_16' , {}) 2624 2625" undo the last diffput 2626call term_sendkeys ( buf , "1\<c-w>w" ) 2627call term_sendkeys ( buf , "u" ) 2628 2629" put from window 2 using dp line 8 2630call term_sendkeys ( buf , "2\<c-w>w" ) 2631call term_sendkeys ( buf , "8gg" ) 2632call term_sendkeys ( buf , ":diffput\<CR>" ) 2633call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_17' , {}) 2634 2635" undo the last diffput 2636call term_sendkeys ( buf , "1\<c-w>w" ) 2637call term_sendkeys ( buf , "u" ) 2638 2639" put from window 2 using dp line 9 2640call term_sendkeys ( buf , "2\<c-w>w" ) 2641call term_sendkeys ( buf , "9gg" ) 2642call term_sendkeys ( buf , ":diffput\<CR>" ) 2643call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_18' , {}) 2644 2645" undo the last diffput 2646call term_sendkeys ( buf , "1\<c-w>w" ) 2647call term_sendkeys ( buf , "u" ) 2648 2649" put from window 2 using dp line 17 2650call term_sendkeys ( buf , "2\<c-w>w" ) 2651call term_sendkeys ( buf , "17gg" ) 2652call term_sendkeys ( buf , ":diffput\<CR>" ) 2653call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_19' , {}) 2654" clean up 2655call StopVimInTerminal ( buf ) 2656endfunc 2657 2658func Test_linematch_diff () 2659CheckScreendump 2660call delete ( '.Xdifile1.swp' ) 2661call delete ( '.Xdifile2.swp' ) 2662call WriteDiffFiles ( 0 , [], []) 2663let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2664call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2665 2666" enable linematch 2667call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:30\<CR>" ) 2668call WriteDiffFiles ( buf , [ '// abc d?' , 2669\ '// d?' , 2670\ '// d?' ], 2671\ [ '!' , 2672\ 'abc d!' , 2673\ 'd!' ]) 2674call term_sendkeys ( buf , ":\<CR>" ) " clear cmdline 2675call VerifyScreenDump ( buf , 'Test_linematch_diff1' , {}) 2676 2677" test that filler is always implicitly set by linematch 2678call term_sendkeys ( buf , ":set diffopt-=filler\<CR>" ) 2679call term_sendkeys ( buf , ":\<CR>" ) " clear cmdline 2680call VerifyScreenDump ( buf , 'Test_linematch_diff1' , {}) 2681 2682" clean up 2683call StopVimInTerminal ( buf ) 2684endfunc 2685 2686func Test_linematch_diff_iwhite () 2687CheckScreendump 2688call delete ( '.Xdifile1.swp' ) 2689call delete ( '.Xdifile2.swp' ) 2690call WriteDiffFiles ( 0 , [], []) 2691let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2692call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2693 2694" setup a diff with 2 files and set linematch:30, with ignore white 2695call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:30\<CR>" ) 2696call WriteDiffFiles ( buf , [ 'void testFunction () {' , 2697\ ' for (int i = 0; i < 10; i++) {' , 2698\ ' for (int j = 0; j < 10; j++) {' , 2699\ ' }' , 2700\ ' }' , 2701\ '}' ], 2702\ [ 'void testFunction () {' , 2703\ ' // for (int j = 0; j < 10; i++) {' , 2704\ ' // }' , 2705\ '}' ]) 2706call VerifyScreenDump ( buf , 'Test_linematch_diff_iwhite1' , {}) 2707call term_sendkeys ( buf , ":set diffopt+=iwhiteall\<CR>" ) 2708call VerifyScreenDump ( buf , 'Test_linematch_diff_iwhite2' , {}) 2709" clean up 2710call StopVimInTerminal ( buf ) 2711endfunc 2712 2713func Test_linematch_diff_grouping () 2714CheckScreendump 2715call delete ( '.Xdifile1.swp' ) 2716call delete ( '.Xdifile2.swp' ) 2717call WriteDiffFiles ( 0 , [], []) 2718let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2719call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2720 2721" a diff that would result in multiple groups before grouping optimization 2722call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:30\<CR>" ) 2723call WriteDiffFiles ( buf , [ '!A' , 2724\ '!B' , 2725\ '!C' ], 2726\ [ '?Z' , 2727\ '?A' , 2728\ '?B' , 2729\ '?C' , 2730\ '?A' , 2731\ '?B' , 2732\ '?B' , 2733\ '?C' ]) 2734call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping1' , {}) 2735call WriteDiffFiles ( buf , [ '!A' , 2736\ '!B' , 2737\ '!C' ], 2738\ [ '?A' , 2739\ '?Z' , 2740\ '?B' , 2741\ '?C' , 2742\ '?A' , 2743\ '?B' , 2744\ '?C' , 2745\ '?C' ]) 2746call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping2' , {}) 2747" clean up 2748call StopVimInTerminal ( buf ) 2749endfunc 2750 2751func Test_linematch_diff_scroll () 2752CheckScreendump 2753call delete ( '.Xdifile1.swp' ) 2754call delete ( '.Xdifile2.swp' ) 2755call WriteDiffFiles ( 0 , [], []) 2756let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2757call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2758 2759" a diff that would result in multiple groups before grouping optimization 2760call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:30\<CR>" ) 2761call WriteDiffFiles ( buf , [ '!A' , 2762\ '!B' , 2763\ '!C' ], 2764\ [ '?A' , 2765\ '?Z' , 2766\ '?B' , 2767\ '?C' , 2768\ '?A' , 2769\ '?B' , 2770\ '?C' , 2771\ '?C' ]) 2772" scroll down to show calculation of top fill and scroll to correct line in 2773" both windows 2774call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll0' , {}) 2775call term_sendkeys ( buf , "3\<c-e>" ) 2776call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll1' , {}) 2777call term_sendkeys ( buf , "3\<c-e>" ) 2778call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll2' , {}) 2779" clean up 2780call StopVimInTerminal ( buf ) 2781endfunc 2782 2783func Test_linematch_line_limit_exceeded () 2784CheckScreendump 2785call delete ( '.Xdifile1.swp' ) 2786call delete ( '.Xdifile2.swp' ) 2787call WriteDiffFiles ( 0 , [], []) 2788let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2789call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" ) 2790 2791call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:10\<CR>" ) 2792" a diff block will not be aligned with linematch because it's contents 2793" exceed 10 lines 2794call WriteDiffFiles ( buf , 2795\ [ 'common line' , 2796\ 'HIL' , 2797\ '' , 2798\ 'aABCabc' , 2799\ 'aABCabc' , 2800\ 'aABCabc' , 2801\ 'aABCabc' , 2802\ 'common line' , 2803\ 'HIL' , 2804\ 'common line' , 2805\ 'something' ], 2806\ [ 'common line' , 2807\ 'DEF' , 2808\ 'GHI' , 2809\ 'something' , 2810\ '' , 2811\ 'aDEFabc' , 2812\ 'xyz' , 2813\ 'xyz' , 2814\ 'xyz' , 2815\ 'aDEFabc' , 2816\ 'aDEFabc' , 2817\ 'aDEFabc' , 2818\ 'common line' , 2819\ 'DEF' , 2820\ 'GHI' , 2821\ 'something else' , 2822\ 'common line' , 2823\ 'something' ]) 2824call VerifyScreenDump ( buf , 'Test_linematch_line_limit_exceeded1' , {}) 2825" after increasing the count to 30, the limit is not exceeded, and the 2826" alignment algorithm will run on the largest diff block here 2827call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" ) 2828call VerifyScreenDump ( buf , 'Test_linematch_line_limit_exceeded2' , {}) 2829" clean up 2830call StopVimInTerminal ( buf ) 2831endfunc 2832 2833func Test_linematch_3diffs () 2834CheckScreendump 2835call delete ( '.Xdifile1.swp' ) 2836call delete ( '.Xdifile2.swp' ) 2837call delete ( '.Xdifile3.swp' ) 2838call WriteDiffFiles3 ( 0 , [], [], []) 2839let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3' , {}) 2840call term_sendkeys ( buf , "1\<c-w>w:set autoread\<CR>" ) 2841call term_sendkeys ( buf , "2\<c-w>w:set autoread\<CR>" ) 2842call term_sendkeys ( buf , "3\<c-w>w:set autoread\<CR>" ) 2843call term_sendkeys ( buf , ":set diffopt=internal,filler,linematch:30\<CR>" ) 2844call WriteDiffFiles3 ( buf , 2845\ [ "" , 2846\ " common line" , 2847\ " AAA" , 2848\ " AAA" , 2849\ " AAA" ], 2850\ [ "" , 2851\ " common line" , 2852\ " <<<<<<< HEAD" , 2853\ " AAA" , 2854\ " AAA" , 2855\ " AAA" , 2856\ " =======" , 2857\ " BBB" , 2858\ " BBB" , 2859\ " BBB" , 2860\ " >>>>>>> branch1" ], 2861\ [ "" , 2862\ " common line" , 2863\ " BBB" , 2864\ " BBB" , 2865\ " BBB" ]) 2866call VerifyScreenDump ( buf , 'Test_linematch_3diffs1' , {}) 2867" clean up 2868call StopVimInTerminal ( buf ) 2869endfunc 2870 2871" this used to access invalid memory 2872func Test_linematch_3diffs_sanity_check () 2873CheckScreendump 2874call delete ( '.Xfile_linematch1.swp' ) 2875call delete ( '.Xfile_linematch2.swp' ) 2876call delete ( '.Xfile_linematch3.swp' ) 2877let lines =<< trim END 2878set diffopt=internal,filler,linematch:60 2879call feedkeys("Aq\<esc>") 2880call feedkeys("GAklm\<esc>") 2881call feedkeys("o") 2882END 2883call writefile ( lines , 'Xlinematch_3diffs.vim' , 'D' ) 2884call writefile ([ 'abcd' , 'def' , 'hij' ], 'Xfile_linematch1' , 'D' ) 2885call writefile ([ 'defq' , 'hijk' , 'nopq' ], 'Xfile_linematch2' , 'D' ) 2886call writefile ([ 'hijklm' , 'nopqr' , 'stuv' ], 'Xfile_linematch3' , 'D' ) 2887call WriteDiffFiles3 ( 0 , [], [], []) 2888let buf = RunVimInTerminal ( '-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3' , {}) 2889call VerifyScreenDump ( buf , 'Test_linematch_3diffs2' , {}) 2890 2891" clean up 2892call StopVimInTerminal ( buf ) 2893endfunc 2894 2895func Test_diffanchors () 2896CheckScreendump 2897call WriteDiffFiles3 ( 0 , 2898\ [ "anchorA1" , "1" , "2" , "3" , 2899\ "100" , "101" , "102" , "anchorB" , "103" , "104" , "105" ], 2900\ [ "100" , "101" , "102" , "anchorB" , "103" , "104" , "105" , 2901\ "anchorA2" , "1" , "2" , "3" ], 2902\ [ "100" , "anchorB" , "103" , 2903\ "anchorA3" , "1" , "2" , "3" ]) 2904let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3' , {}) 2905 2906" Simple diff without any anchors 2907call VerifyInternal ( buf , "Test_diff_anchors_00" , "" ) 2908 2909" Setting diffopt+=anchor or diffanchors without the other won't do anything 2910call VerifyInternal ( buf , "Test_diff_anchors_00" , " diffopt+=anchor" ) 2911call VerifyInternal ( buf , "Test_diff_anchors_00" , " dia=1/anchorA/" ) 2912 2913" Use a single anchor by specifying a pattern. Test both internal and 2914" external diff to make sure both paths work. 2915call VerifyBoth ( buf , "Test_diff_anchors_01" , " dia=1/anchorA/ diffopt+=anchor" ) 2916 2917" Use 2 anchors. They should be sorted by line number, so in file 2/3 2918" anchorB is used before anchorA. 2919call VerifyBoth ( buf , "Test_diff_anchors_02" , " dia=1/anchorA/,1/anchorB/ diffopt+=anchor" ) 2920 2921" Set marks and specify addresses using marks and repeat the test 2922call term_sendkeys ( buf , ":2wincmd w\<CR>:1/anchorA/mark a\<CR>" ) 2923call term_sendkeys ( buf , ":1/anchorB/mark b\<CR>" ) 2924call term_sendkeys ( buf , ":3wincmd w\<CR>:1/anchorA/mark a\<CR>" ) 2925call term_sendkeys ( buf , ":1/anchorB/mark b\<CR>" ) 2926call term_sendkeys ( buf , ":1wincmd w\<CR>:1/anchorA/mark a\<CR>" ) 2927call term_sendkeys ( buf , ":1/anchorB/mark b\<CR>" ) 2928 2929call VerifyInternal ( buf , "Test_diff_anchors_01" , " dia='a diffopt+=anchor" ) 2930call VerifyInternal ( buf , "Test_diff_anchors_02" , " dia='a,'b diffopt+=anchor" ) 2931 2932" Update marks to point somewhere else. When we first set the mark the diff 2933" won't be updated until we manually invoke :diffupdate. 2934call VerifyInternal ( buf , "Test_diff_anchors_01" , " dia='a diffopt+=anchor" ) 2935call term_sendkeys ( buf , ":1wincmd w\<CR>:1/anchorB/mark a\<CR>:" ) 2936call term_wait ( buf ) 2937call VerifyScreenDump ( buf , "Test_diff_anchors_01" , {}) 2938call term_sendkeys ( buf , ":diffupdate\<CR>:" ) 2939call term_wait ( buf ) 2940call VerifyScreenDump ( buf , "Test_diff_anchors_03" , {}) 2941 2942" Use local diff anchors with line numbers, and repeat the same test 2943call term_sendkeys ( buf , ":2wincmd w\<CR>:setlocal dia=8\<CR>" ) 2944call term_sendkeys ( buf , ":3wincmd w\<CR>:setlocal dia=4\<CR>" ) 2945call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1\<CR>" ) 2946call VerifyInternal ( buf , "Test_diff_anchors_01" , " diffopt+=anchor" ) 2947call term_sendkeys ( buf , ":2wincmd w\<CR>:setlocal dia=8,4\<CR>" ) 2948call term_sendkeys ( buf , ":3wincmd w\<CR>:setlocal dia=4,2\<CR>" ) 2949call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1,8\<CR>" ) 2950call VerifyInternal ( buf , "Test_diff_anchors_02" , " diffopt+=anchor" ) 2951 2952" Test multiple diff anchors on the same line in file 1. 2953call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1,1\<CR>" ) 2954call VerifyInternal ( buf , "Test_diff_anchors_04" , " diffopt+=anchor" ) 2955 2956" Test that if one file has fewer diff anchors than others. Vim should only 2957" use the minimum in this case. 2958call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=8\<CR>" ) 2959call VerifyInternal ( buf , "Test_diff_anchors_05" , " diffopt+=anchor" ) 2960 2961" $+1 should anchor everything past the last line 2962call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=$+1\<CR>" ) 2963call VerifyInternal ( buf , "Test_diff_anchors_06" , " diffopt+=anchor" ) 2964 2965" Sorting of diff anchors should work with multiple anchors 2966call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1,10,8,2\<CR>" ) 2967call term_sendkeys ( buf , ":2wincmd w\<CR>:setlocal dia=1,2,3,4\<CR>" ) 2968call term_sendkeys ( buf , ":3wincmd w\<CR>:setlocal dia=4,3,2,1\<CR>" ) 2969call VerifyInternal ( buf , "Test_diff_anchors_07" , " diffopt+=anchor" ) 2970 2971" Intentionally set an invalid anchor with wrong line number. Should fall 2972" back to treat it as if no anchors are used at all. 2973call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1,10,8,2,1000 | silent! diffupdate\<CR>:" ) 2974call VerifyScreenDump ( buf , "Test_diff_anchors_00" , {}) 2975 2976call StopVimInTerminal ( buf ) 2977endfunc 2978 2979" Test that scrollbind and topline calculations work correctly, even when diff 2980" anchors create adjacent diff blocks which complicates the calculations. 2981func Test_diffanchors_scrollbind_topline () 2982CheckScreendump 2983 2984" Simple overlapped line anchored to be adjacent to each other 2985call WriteDiffFiles ( 0 , 2986\ [ "anchor1" , "diff1a" , "anchor2" ], 2987\ [ "anchor1" , "diff2a" , "anchor2" ]) 2988let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {}) 2989 2990call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=2\<CR>" ) 2991call term_sendkeys ( buf , ":2wincmd w\<CR>:setlocal dia=3\<CR>" ) 2992 2993call VerifyInternal ( buf , "Test_diff_anchors_scrollbind_topline_01" , " diffopt+=anchor" ) 2994call term_sendkeys ( buf , "\<Esc>\<C-E>" ) 2995call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_02" , {}) 2996call term_sendkeys ( buf , "\<C-E>" ) 2997call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_03" , {}) 2998call term_sendkeys ( buf , "\<C-E>" ) 2999call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_04" , {}) 3000 3001" Also test no-filler 3002call term_sendkeys ( buf , "gg" ) 3003call VerifyInternal ( buf , "Test_diff_anchors_scrollbind_topline_05" , " diffopt+=anchor diffopt-=filler" ) 3004call term_sendkeys ( buf , "\<Esc>\<C-E>" ) 3005call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_06" , {}) 3006call term_sendkeys ( buf , "\<C-E>" ) 3007call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_07" , {}) 3008 3009call StopVimInTerminal ( buf ) 3010endfunc 3011 3012func Test_diffanchors_scrollbind_topline2 () 3013CheckScreendump 3014 3015" More-complicated case with 3 files and multiple overlapping diff blocks 3016call WriteDiffFiles3 ( 0 , 3017\ [ "anchor1" ], 3018\ [ "diff2a" , "diff2b" , "diff2c" , "diff2d" , "anchor2" ], 3019\ [ "diff3a" , "diff3c" , "diff3d" , "anchor3" , "diff3e" ]) 3020let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3' , {}) 3021 3022call term_sendkeys ( buf , ":1wincmd w\<CR>:setlocal dia=1,1,2\<CR>" ) 3023call term_sendkeys ( buf , ":2wincmd w\<CR>:setlocal dia=3,5,6\<CR>" ) 3024call term_sendkeys ( buf , ":3wincmd w\<CR>:setlocal dia=2,4,5\<CR>" ) 3025 3026call VerifyInternal ( buf , "Test_diff_anchors_scrollbind_topline_08" , " diffopt+=anchor" ) 3027call term_sendkeys ( buf , ":1wincmd w\<CR>" ) 3028call term_sendkeys ( buf , "\<C-E>" ) 3029call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_09" , {}) 3030call term_sendkeys ( buf , "\<C-E>" ) 3031call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_10" , {}) 3032call term_sendkeys ( buf , "\<C-E>" ) 3033call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_11" , {}) 3034call term_sendkeys ( buf , "\<C-E>" ) 3035call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_12" , {}) 3036 3037" Also test no-filler 3038call term_sendkeys ( buf , ":3wincmd w\<CR>gg" ) 3039call VerifyInternal ( buf , "Test_diff_anchors_scrollbind_topline_13" , " diffopt+=anchor diffopt-=filler" ) 3040call term_sendkeys ( buf , "\<Esc>\<C-E>" ) 3041call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_14" , {}) 3042call term_sendkeys ( buf , "\<C-E>" ) 3043call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_15" , {}) 3044call term_sendkeys ( buf , "\<C-E>" ) 3045call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_16" , {}) 3046call term_sendkeys ( buf , "\<C-E>" ) 3047call VerifyScreenDump ( buf , "Test_diff_anchors_scrollbind_topline_17" , {}) 3048 3049call StopVimInTerminal ( buf ) 3050endfunc 3051 3052" Test that setting 'diffanchors' will update the diff. 3053func Test_diffanchors_option_set_update () 3054set diffanchors = 'a diffopt = internal,filler,anchor 3055 3056" Set up 3 tabs that share some buffers, and set up marks on each of them. 3057" We want to make sure only relevant tabs are updated if buffer-local diff 3058" anchors are updated, but all tabs should refresh if global diff anchors 3059" are updated (see diffanchors_changed() in code). 3060 3061" Tab 1. A buffer here will be reused. 3062call setline ( 1 , range ( 1 , 10 )) 30633 mark a 30644 mark b 3065diffthis 3066new 3067call setline ( 1 , range ( 21 , 25 )) 3068let buf = bufnr () 30691 mark a 30702 mark b 3071diffthis 3072call assert_equal ( 2 , diff_filler ( 1 )) 3073call assert_equal ( 0 , diff_filler ( 2 )) 3074 3075" Tab 2. "buf" is here but intentionally not participating in diff. 3076tabnew 3077exec 'buf ' .. buf 3078diffoff 3079new 3080call setline ( 1 , range ( 31 , 40 )) 30818 mark a 30829 mark b 3083diffthis 3084new 3085call setline ( 1 , range ( 41 , 50 )) 30865 mark a 30876 mark b 3088diffthis 3089 3090call assert_equal ( 3 , diff_filler ( 5 )) 3091call assert_equal ( 0 , diff_filler ( 6 )) 3092call assert_equal ( 0 , diff_filler ( 7 )) 3093 3094" Update mark a location, and check that the diff has *not* updated. When 3095" updating marks diff's won't automatically update. 30967 mark a 3097call assert_equal ( 3 , diff_filler ( 5 )) 3098call assert_equal ( 0 , diff_filler ( 6 )) 3099call assert_equal ( 0 , diff_filler ( 7 )) 3100 3101" Tab 3. "buf" is used here and also in a diff. 3102tabnew 3103call setline ( 1 , range ( 51 , 65 )) 310410 mark a 310511 mark b 3106diffthis 3107exec 'sbuffer ' .. buf 3108diffthis 3109 3110" Change local diff anchor of "buf" to mark b 3111setlocal diffanchors = 'b 3112 3113" Tab 1 should immediately update the diff to use mark b because the buf 3114" local diff anchor has been changed in "buf". 31151 tabnext 3116call assert_equal ( 0 , diff_filler ( 1 )) 3117call assert_equal ( 1 , diff_filler ( 2 )) 3118 3119" Tab 2 should not immediately update because "buf" is not a diff buffer 3120" here. 31212 tabnext 3122call assert_equal ( 3 , diff_filler ( 5 )) 3123call assert_equal ( 0 , diff_filler ( 6 )) 3124call assert_equal ( 0 , diff_filler ( 7 )) 3125 3126" Manual diff update would refresh the diff since we previously changed mark 3127" a's location above. 3128diffupdate 3129call assert_equal ( 0 , diff_filler ( 5 )) 3130call assert_equal ( 0 , diff_filler ( 6 )) 3131call assert_equal ( 1 , diff_filler ( 7 )) 3132 3133" Go back to tab 1. Reset diff anchor to global value and make sure it uses 3134" mark a again. 31351 tabnext 3136set diffanchors < 3137call assert_equal ( 2 , diff_filler ( 1 )) 3138call assert_equal ( 0 , diff_filler ( 2 )) 3139 3140" Now, change the global diff anchor to mark b. This should affect all tabs 3141" including tab 2 which should update automatically. 3142set diffanchors = 'b 3143call assert_equal ( 0 , diff_filler ( 1 )) 3144call assert_equal ( 2 , diff_filler ( 2 )) 3145 31462 tabnext 3147call assert_equal ( 0 , diff_filler ( 5 )) 3148call assert_equal ( 3 , diff_filler ( 6 )) 3149call assert_equal ( 0 , diff_filler ( 7 )) 3150 3151% bw ! 3152set diffopt & 3153set diffanchors & 3154endfunc 3155 3156" Test that using diff anchors with window/buffer-local addresses will work as 3157" expected and use the relevant window/buffer instead of curbuf/curwin. 3158func Test_diffanchors_buf_win_local_addresses () 3159" Win 1-3 point to buffer 1. Set up different window-specific jump history 3160" Win 2 is the one we activate diff mode on. 3161call setline ( 1 , range ( 1 , 15 )) 3162norm 2gg 3163norm 3gg 3164 3165split 3166norm 4gg 3167norm 5gg 3168 3169split 3170norm 11gg 3171norm 12gg 3172call setline ( 10 , 'new text 1' ) " update the '. mark to line 10 3173 3174" Win 4 points to buffer 2 3175botright vert new 3176call setline ( 1 , range ( 101 , 110 )) 3177norm 8gg 3178norm 9gg 3179call setline ( 3 , 'new text 2' ) " update the '. mark to line 3 3180 31812 wincmd w 3182diffthis 31834 wincmd w 3184diffthis 3185 3186" Test buffer-local marks using '. Should be anchored to lines 10 / 3. 3187set diffopt = internal,filler,anchor 3188set diffanchors = '. 31894 wincmd w 3190call assert_equal ( 7 , diff_filler ( 3 )) 3191 3192" Test window-local marks using '' Should be anchored to lines 4 / 8. 3193" Note that windows 1 & 3 point to the buffer being diff'ed but are not used 3194" for diffing themselves and therefore should not be used. Windows 2 & 4 3195" should be used. 3196set diffanchors = '' 31972 wincmd w 3198call assert_equal ( 4 , diff_filler ( 4 )) 3199 3200" Also test "." for the current cursor position, which is also 3201" window-specific. Make sure the cursor position at the longer file doesn't 3202" result in the other file using out of bounds line number. 32034 wincmd w 3204norm G 32052 wincmd w 3206norm G 3207set diffanchors = . 3208diffupdate 32094 wincmd w 3210call assert_equal ( 5 , diff_filler ( 10 )) 3211 3212% bw ! 3213set diffopt & 3214set diffanchors & 3215endfunc 3216 3217" Test diff anchors error handling for anchors that fail to resolve to a line. 3218" These are not handled during option parsing because they depend on the 3219" specifics of the buffer at diff time. 3220func Test_diffanchors_invalid () 3221call setline ( 1 , range ( 1 , 5 )) 3222new 3223call setline ( 1 , range ( 11 , 20 )) 3224set diffopt = internal,filler,anchor 3225windo diffthis 32261 wincmd w 3227 3228" Line numbers that are out of bounds should be an error 3229set diffanchors = 0 3230call assert_fails ( 'diffupdate' , 'E16:' ) 3231set diffanchors = 1 3232diffupdate 3233set diffanchors = $ 3234diffupdate 3235set diffanchors = $+1 3236diffupdate 3237set diffanchors = $+2 3238call assert_fails ( 'diffupdate' , 'E16:' ) 3239 3240" Test that non-existent marks in any one buffer will be detected 3241set diffanchors = 'a 3242call assert_fails ( 'diffupdate' , 'E20:' ) 32432 mark a 3244call assert_fails ( 'diffupdate' , 'E20:' ) 3245 3246set diffanchors = 1 3247setlocal diffanchors = 'a 3248diffupdate 3249 3250set diffanchors < 3251windo 2mark a 3252set diffanchors = 'b 3253call assert_fails ( 'diffupdate' , 'E20:' ) 3254set diffanchors = 'a 3255diffupdate 3256 3257" File marks are ok to use for anchors only if it is in the same file 32581 wincmd w 32593 mark C 3260setlocal diffanchors = 'C 3261diffupdate 3262set diffanchors = 'C 3263call assert_fails ( 'diffupdate' , 'E20:' ) 3264 3265" Buffer-local marks also can only be used in buffers that have them. 3266set diffanchors = 1 3267exec "norm 1ggVj\<Esc>" 3268setlocal diffanchors = '< 3269diffupdate 3270set diffanchors = '< 3271call assert_fails ( 'diffupdate' , 'E20:' ) 3272 3273" Pattern search that failed will be an error too 3274let @/ = 'orig_search_pat' 3275set diffanchors = 1/5/ 3276diffupdate 3277call assert_equal ( 'orig_search_pat' , @/ ) " also check we don't pollute the search register 3278set diffanchors = 1/does_not_exist/ 3279call assert_fails ( 'diffupdate' , 'E1550:' ) 3280call assert_equal ( 'orig_search_pat' , @/ ) 3281 3282" Hidden buffers are not supported right now 3283hide 3284call assert_fails ( 'diffupdate' , 'E1562:' ) 3285 3286% bw ! 3287set diffopt & 3288set diffanchors & 3289endfunc 3290 3291" Test diffget/diffput behaviors when using diff anchors which could create 3292" adjacent diff blocks. 3293func Test_diffget_diffput_diffanchors () 3294set diffanchors = 1/anchor/ 3295set diffopt = internal,filler,anchor 3296 3297call setline ( 1 , [ '1' , 'anchor1' , '4' ]) 3298diffthis 3299new 3300call setline ( 1 , [ '2' , '3' , 'anchor2' , '4' , '5' ]) 3301diffthis 3302wincmd w 3303 3304" Test using no-range diffget. It should grab the closest diff block only, 3305" even if there are multiple adjacent blocks. 33062 3307diffget 3308call assert_equal ([ '1' , 'anchor2' , '4' ], getline ( 1 , '$' )) 3309diffget 3310call assert_equal ([ '2' , '3' , 'anchor2' , '4' ], getline ( 1 , '$' )) 3311 3312" Test using a range to get/put all the adjacent diff blocks. 33131 , $ delete 3314call setline ( 1 , [ 'anchor1' , '4' ]) 33150 , 1 diffget 3316call assert_equal ([ '2' , '3' , 'anchor2' , '4' ], getline ( 1 , '$' )) 3317 33181 , $ delete 3319call setline ( 1 , [ 'anchor1' , '4' ]) 33200 , $ +1 diffget 3321call assert_equal ([ '2' , '3' , 'anchor2' , '4' , '5' ], getline ( 1 , '$' )) 3322 33231 , $ delete 3324call setline ( 1 , [ 'anchor1' , '4' ]) 33250 , 1 diffput 3326wincmd w 3327call assert_equal ([ 'anchor1' , '4' , '5' ], getline ( 1 , '$' )) 3328 3329% bw ! 3330set diffopt & 3331set diffanchors & 3332endfunc 3333 3334func Test_diff_add_prop_in_autocmd () 3335CheckScreendump 3336 3337let lines =<< trim END 3338func MyDiff() abort 3339let f1 = readfile(v:fname_in) 3340let f2 = readfile(v:fname_new) 3341let f0 = diff(f1, f2) 3342call writefile(split(f0, "\n"), v:fname_out) 3343endfunc 3344 3345call prop_type_add('myprop', #{highlight: 'Search', override: 1}) 3346autocmd OptionSet diff call prop_add(1, 1, #{type: 'myprop', length: 100}) 3347set diffexpr=MyDiff() 3348END 3349call writefile ( lines , 'Xtest_diff_add_prop_in_autocmd' , 'D' ) 3350call writefile ([ 'foo' , 'bar' , 'baz' ], 'Xdiffsplit_file' , 'D' ) 3351 3352let buf = RunVimInTerminal ( '-S Xtest_diff_add_prop_in_autocmd' , {}) 3353call term_sendkeys ( buf , ":diffsplit Xdiffsplit_file\<CR>" ) 3354call VerifyScreenDump ( buf , 'Test_diff_add_prop_in_autocmd_01' , {}) 3355 3356call StopVimInTerminal ( buf ) 3357endfunc 3358 3359" this was causing a use-after-free by calling winframe_remove() recursively 3360func Test_diffexpr_wipe_buffers () 3361CheckRunVimInTerminal 3362 3363let lines =<< trim END 3364def DiffFuncExpr() 3365var in: list<string> = readfile(v:fname_in) 3366var new = readfile(v:fname_new) 3367var out: string = diff(in, new) 3368writefile(split(out, "n"), v:fname_out) 3369enddef 3370 3371new 3372vnew 3373set diffexpr=DiffFuncExpr() 3374wincmd l 3375new 3376cal setline(1,range(20)) 3377wind difft 3378wincm w 3379hid 3380%bw! 3381END 3382call writefile ( lines , 'Xtest_diffexpr_wipe' , 'D' ) 3383 3384let buf = RunVimInTerminal ( 'Xtest_diffexpr_wipe' , {}) 3385call term_sendkeys ( buf , ":so\<CR>" ) 3386call WaitForAssert ({ -> assert_match ( '4 buffers wiped out' , term_getline ( buf , 20 ))}) 3387 3388call StopVimInTerminal ( buf ) 3389endfunc 3390 3391func Test_diffput_to_empty_buf () 3392CheckScreendump 3393 3394let lines =<< trim END 3395call setline(1, ['foo', 'bar', 'baz']) 3396rightbelow vnew 3397windo diffthis 3398windo set cursorline nofoldenable 3399wincmd t 3400END 3401call writefile ( lines , 'Xtest_diffput_to_empty_buf' , 'D' ) 3402 3403let buf = RunVimInTerminal ( '-S Xtest_diffput_to_empty_buf' , {}) 3404call VerifyScreenDump ( buf , 'Test_diffput_to_empty_buf_01' , {}) 3405call term_sendkeys ( buf , '0' ) " Trigger an initial 'cursorbind' check. 3406call VerifyScreenDump ( buf , 'Test_diffput_to_empty_buf_01' , {}) 3407call term_sendkeys ( buf , ":diffput | echo\<CR>" ) 3408call VerifyScreenDump ( buf , 'Test_diffput_to_empty_buf_02' , {}) 3409call term_sendkeys ( buf , ":redraw!\<CR>" ) 3410call VerifyScreenDump ( buf , 'Test_diffput_to_empty_buf_02' , {}) 3411call term_sendkeys ( buf , 'j' ) 3412call VerifyScreenDump ( buf , 'Test_diffput_to_empty_buf_03' , {}) 3413 3414call StopVimInTerminal ( buf ) 3415endfunc 3416 3417" Undo can change which lines correspond in a diff. 'cursorbind' must update 3418" the other window even when the cursor here did not move. 3419func Test_diff_cursorbind_after_undo () 3420call setline ( 1 , [ 'x' , 'y' , 'c' , 'd' ]) 3421let w1 = win_getid () 3422new 3423call setline ( 1 , [ 'p' , 'q' , 'c' , 'd' ]) 3424let w2 = win_getid () 3425windo diffthis 3426call win_gotoid ( w1 ) 3427 3428normal ! 2dd 3429call assert_equal ( 1 , line ( '.' , w1 )) 3430call assert_equal ( 1 , line ( '.' , w2 )) 3431normal ! jk 3432call assert_equal ( 1 , line ( '.' , w1 )) 3433call assert_equal ( 3 , line ( '.' , w2 )) 3434 3435normal ! u 3436call assert_equal ( 1 , line ( '.' , w1 )) 3437call assert_equal ( 1 , line ( '.' , w2 )) 3438 3439% bw ! 3440endfunc 3441 3442" Redrawing folds scans the diff block list. The scan is resumed from a 3443" remembered position (the "finger") when the line number does not move 3444" backwards, so make sure it yields exactly the same folds as a full scan 3445" with many changes, when walking up and down, in both windows, and after an 3446" edit invalidates the finger. 3447func Test_diff_fold_scan_finger () 3448enew ! 3449let lines = [] 3450for i in range ( 1 , 600 ) 3451call add ( lines , string ( i )) 3452endfor 3453call setline ( 1 , lines ) 3454diffthis 3455let winone = win_getid () 3456new 3457let other = copy ( lines ) 3458" Change one line in every 30-line block, far enough apart to stay separate. 3459let changes = range ( 30 , 570 , 30 ) 3460for c in changes 3461let other [ c - 1 ] = 'x' . other [ c - 1 ] 3462endfor 3463call setline ( 1 , other ) 3464diffthis 3465let wintwo = win_getid () 3466 3467set diffopt = internal,filler,context:4 3468diffupdate 3469" Park the cursor on a changed (never folded) line so the fold under the 3470" cursor is not opened, which would perturb the checks below. 3471call cursor ( 300 , 1 ) 3472normal ! zx 3473 3474" Fold boundaries derived independently from the change positions: each 3475" change at line c keeps [c - 4, c + 4] visible, the gaps are closed folds. 3476let expected = [] 3477let prev_end = 0 3478for c in changes 3479if c - 4 - 1 >= prev_end + 1 3480call add ( expected , [ prev_end + 1 , c - 4 - 1 ]) 3481endif 3482let prev_end = c + 4 3483endfor 3484if prev_end + 1 <= 600 3485call add ( expected , [ prev_end + 1 , 600 ]) 3486endif 3487 3488" Walk the folds forward (lnum increasing: exercises the resume path). 3489for [ s , e ] in expected 3490call assert_equal ( s , foldclosed ( s ), 'foldclosed at ' . s ) 3491call assert_equal ( e , foldclosedend ( s ), 'foldclosedend at ' . s ) 3492endfor 3493 3494" Walk the folds backward (lnum decreasing: forces the finger to restart). 3495for [ s , e ] in reverse ( copy ( expected )) 3496call assert_equal ( s , foldclosed ( e ), 'reverse foldclosed at ' . e ) 3497call assert_equal ( e , foldclosedend ( e ), 'reverse foldclosedend at ' . e ) 3498endfor 3499 3500" The context lines around every change must not be in a closed fold. 3501for c in changes 3502call assert_equal ( -1 , foldclosed ( c ), 'change line ' . c . ' visible' ) 3503endfor 3504 3505" The other window (different buffer index) must produce the same folds. 3506call win_gotoid ( winone ) 3507call cursor ( 300 , 1 ) 3508normal ! zx 3509for [ s , e ] in expected 3510call assert_equal ( s , foldclosed ( s ), 'winone foldclosed at ' . s ) 3511call assert_equal ( e , foldclosedend ( s ), 'winone foldclosedend at ' . s ) 3512endfor 3513 3514" Editing invalidates the finger; a new change deep inside a fold must split 3515" it and become visible. 3516call win_gotoid ( wintwo ) 3517call cursor ( 300 , 1 ) 3518call setline ( 315 , 'x' . getline ( 315 )) 3519diffupdate 3520normal ! zx 3521call assert_equal ( 305 , foldclosed ( 305 )) 3522call assert_equal ( 310 , foldclosedend ( 305 )) 3523call assert_equal ( -1 , foldclosed ( 315 )) 3524call assert_equal ( 320 , foldclosed ( 320 )) 3525call assert_equal ( 325 , foldclosedend ( 320 )) 3526 3527diffoff ! 3528% bwipe ! 3529set diffopt & 3530endfunc 3531 3532" vim: shiftwidth=2 sts=2 expandtab