robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Tests for various Visual modes. 2 3source shared.vim 4source check.vim 5source screendump.vim 6source vim9.vim 7 8func Test_block_shift_multibyte () 9" Uses double-wide character. 10split 11call setline ( 1 , [ 'xヹxxx' , 'ヹxxx' ]) 12exe "normal 1G0l\<C-V>jl>" 13call assert_equal ( 'x ヹxxx' , getline ( 1 )) 14call assert_equal ( ' ヹxxx' , getline ( 2 )) 15q ! 16endfunc 17 18func Test_block_shift_overflow () 19" This used to cause a multiplication overflow followed by a crash. 20new 21normal ii 22exe "normal \<C-V>876543210>" 23q ! 24endfunc 25 26func Test_dotregister_paste () 27new 28exe "norm! ihello world\<esc>" 29norm ! 0ve".p 30call assert_equal ( 'hello world world' , getline ( 1 )) 31q ! 32endfunc 33 34func Test_Visual_ctrl_o () 35new 36call setline ( 1 , [ 'one' , 'two' , 'three' ]) 37call cursor ( 1 , 2 ) 38set noshowmode 39set tw = 0 40call feedkeys ( "\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>" , 'tx' ) 41call assert_equal ([ 'oane' , 'tawo' , 'tahree' ], getline ( 1 , 3 )) 42call assert_equal ( 88 , & tw ) 43set tw & 44bw ! 45endfu 46 47func Test_Visual_vapo () 48new 49normal oxx 50normal vapo 51bwipe ! 52endfunc 53 54func Test_Visual_inner_quote () 55new 56normal oxX 57normal vki' 58bwipe ! 59endfunc 60 61" Test for Visual mode not being reset causing E315 error. 62func TriggerTheProblem () 63" At this point there is no visual selection because :call reset it. 64" Let's restore the selection: 65normal gv 66 '<, '>del _ 67try 68exe "normal \<Esc>" 69catch /^Vim\%((\a\+)\)\=:E315/ 70echom 'Snap! E315 error!' 71let g: msg = 'Snap! E315 error!' 72endtry 73endfunc 74 75func Test_visual_mode_reset () 76enew 77let g: msg = "Everything's fine." 78enew 79setl buftype = nofile 80call append ( line ( '$' ), 'Delete this line.' ) 81 82" NOTE: this has to be done by a call to a function because executing :del 83" the ex-way will require the colon operator which resets the visual mode 84" thus preventing the problem: 85exe "normal! GV:call TriggerTheProblem()\<CR>" 86call assert_equal ( "Everything's fine." , g: msg ) 87endfunc 88 89" Test for visual block shift and tab characters. 90func Test_block_shift_tab () 91new 92call append ( 0 , repeat ([ 'one two three' ], 5 )) 93call cursor ( 1 , 1 ) 94exe "normal i\<C-G>u" 95exe "normal fe\<C-V>4jR\<Esc>ugvr1" 96call assert_equal ( 'on1 two three' , getline ( 1 )) 97call assert_equal ( 'on1 two three' , getline ( 2 )) 98call assert_equal ( 'on1 two three' , getline ( 5 )) 99 100 %d _ 101call append ( 0 , repeat ([ 'abcdefghijklmnopqrstuvwxyz' ], 5 )) 102call cursor ( 1 , 1 ) 103exe "normal \<C-V>4jI \<Esc>j<<11|D" 104exe "normal j7|a\<Tab>\<Tab>" 105exe "normal j7|a\<Tab>\<Tab> " 106exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<" 107call assert_equal ( ' abcdefghijklmnopqrstuvwxyz' , getline ( 1 )) 108call assert_equal ( 'abcdefghij' , getline ( 2 )) 109call assert_equal ( " abc\<Tab> defghijklmnopqrstuvwxyz" , getline ( 3 )) 110call assert_equal ( " abc\<Tab> defghijklmnopqrstuvwxyz" , getline ( 4 )) 111call assert_equal ( " abc\<Tab> defghijklmnopqrstuvwxyz" , getline ( 5 )) 112 113 %s /\s\+//g 114call cursor ( 1 , 1 ) 115exe "normal \<C-V>4jI \<Esc>j<<" 116exe "normal j7|a\<Tab>\<Tab>" 117exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>" 118exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<" 119call assert_equal ( ' abcdefghijklmnopqrstuvwxyz' , getline ( 1 )) 120call assert_equal ( 'abcdefghij' , getline ( 2 )) 121call assert_equal ( " abc\<Tab> defghijklmnopqrstuvwxyz" , getline ( 3 )) 122call assert_equal ( " abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz" , getline ( 4 )) 123call assert_equal ( " abc\<Tab> defghijklmnopqrstuvwxyz" , getline ( 5 )) 124 125" Test for block shift with space characters at the beginning and with 126" 'noexpandtab' and 'expandtab' 127 %d _ 128call setline ( 1 , [ " 1" , " 2" , " 3" ]) 129setlocal shiftwidth = 2 noexpandtab 130exe "normal gg\<C-V>3j>" 131call assert_equal ([ "\t1" , "\t2" , "\t3" ], getline ( 1 , '$' )) 132 %d _ 133call setline ( 1 , [ " 1" , " 2" , " 3" ]) 134setlocal shiftwidth = 2 expandtab 135exe "normal gg\<C-V>3j>" 136call assert_equal ([ " 1" , " 2" , " 3" ], getline ( 1 , '$' )) 137setlocal shiftwidth & 138 139bw ! 140endfunc 141 142" Tests Blockwise Visual when there are TABs before the text. 143func Test_blockwise_visual () 144new 145call append ( 0 , [ '123456' , 146 \'234567' , 147 \'345678' , 148 \'' , 149 \'test text test tex start here' , 150 \"\t\tsome text" , 151 \"\t\ttest text" , 152 \'test text' ]) 153call cursor ( 1 , 1 ) 154exe "normal /start here$\<CR>" 155exe 'normal "by$' . "\<C-V>jjlld" 156exe "normal /456$\<CR>" 157exe "normal \<C-V>jj" . '"bP' 158call assert_equal ([ '123start here56' , 159 \'234start here67' , 160 \'345start here78' , 161 \'' , 162 \'test text test tex rt here' , 163 \"\t\tsomext" , 164 \"\t\ttesext" ], getline ( 1 , 7 )) 165 166bw ! 167endfunc 168 169" Test swapping corners in blockwise visual mode with o and O 170func Test_blockwise_visual_o_O () 171new 172 173exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr " 174exe "norm! gvO\<Esc>ra" 175exe "norm! gvO\<Esc>rb" 176exe "norm! gvo\<C-c>rc" 177exe "norm! gvO\<C-c>rd" 178set selection = exclusive 179exe "norm! gvOo\<C-c>re" 180call assert_equal ( '...a be.' , getline ( 4 )) 181exe "norm! gvOO\<C-c>rf" 182set selection & 183 184call assert_equal ([ '..........' , 185 \'...c d..' , 186 \'... ..' , 187 \'...a bf.' , 188 \'..........' ], getline ( 1 , '$' )) 189 190bw ! 191endfun 192 193" Test Virtual replace mode. 194func Test_virtual_replace () 195if exists ( '&t_kD' ) 196let save_t_kD = & t_kD 197endif 198if exists ( '&t_kb' ) 199let save_t_kb = & t_kb 200endif 201exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" 202enew ! 203exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 204call cursor ( 1 , 1 ) 205set ai bs = 2 206exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 207call assert_equal ([ ' 1' , 208 \' A' , 209 \' BCDEFGHIJ' , 210 \' KL' , 211 \' MNO' , 212 \' PQR' , 213 \], getline ( 1 , 6 )) 214normal G 215mark a 216exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" 217exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat ( "\<BS>" , 29 ) 218call assert_equal ([ ' 1' , 219 \'abcdefghi' , 220 \'jk lmn' , 221 \' opq rst' , 222 \'uvwxyz' ], getline ( 7 , 11 )) 223normal G 224exe "normal iab\tcdefghi\tjkl" 225exe "normal 0gRAB......CDEFGHI.J\<Esc>o" 226exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" 227call assert_equal ([ 'AB......CDEFGHI.Jkl' , 228 \'AB IJKLMNO QRst' ], getline ( 12 , 13 )) 229 230" Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4 231 %d 232call setline ( 1 , 'aaaaaaaaaaaaa' ) 233set softtabstop = 4 234exe "normal gggR\<Tab>\<Tab>x" 235call assert_equal ( "\txaaaa" , getline ( 1 )) 236set softtabstop & 237 238enew ! 239set noai bs & vim 240if exists ( 'save_t_kD' ) 241let & t_kD = save_t_kD 242endif 243if exists ( 'save_t_kb' ) 244let & t_kb = save_t_kb 245endif 246endfunc 247 248" Test Virtual replace mode. 249func Test_virtual_replace2 () 250enew ! 251set bs = 2 252exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 253call cursor ( 1 , 1 ) 254" Test 1: Test that del deletes the newline 255exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 256call assert_equal ([ '0 1' , 257 \'A' , 258 \'BCDEFGHIJ' , 259 \' KL' , 260 \'MNO' , 261 \'PQR' , 262 \], getline ( 1 , 6 )) 263" Test 2: 264" a newline is not deleted, if no newline has been added in virtual replace mode 265 %d _ 266call setline ( 1 , [ 'abcd' , 'efgh' , 'ijkl' ]) 267call cursor ( 2 , 1 ) 268exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" 269call assert_equal ([ 'abcd' , 270 \'123h' , 271 \'ijkl' ], getline ( 1 , '$' )) 272" Test 3: 273" a newline is deleted, if a newline has been inserted before in virtual replace mode 274 %d _ 275call setline ( 1 , [ 'abcd' , 'efgh' , 'ijkl' ]) 276call cursor ( 2 , 1 ) 277exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" 278call assert_equal ([ 'abcd' , 279 \'1234' , 280 \'ijkl' ], getline ( 1 , '$' )) 281" Test 4: 282" delete add a newline, delete it, add it again and check undo 283 %d _ 284call setline ( 1 , [ 'abcd' , 'efgh' , 'ijkl' ]) 285call cursor ( 2 , 1 ) 286" break undo sequence explicitly 287let & ul = & ul 288exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" 289let & ul = & ul 290call assert_equal ([ 'abcd' , 291 \'123456' , 292 \'' ], getline ( 1 , '$' )) 293norm ! u 294call assert_equal ([ 'abcd' , 295 \'efgh' , 296 \'ijkl' ], getline ( 1 , '$' )) 297 298" Test for truncating spaces in a newly added line using 'autoindent' if 299" characters are not added to that line. 300 %d _ 301call setline ( 1 , [ ' app' , ' bee' , ' cat' ]) 302setlocal autoindent 303exe "normal gg$gRt\n\nr" 304call assert_equal ([ ' apt' , '' , ' rat' ], getline ( 1 , '$' )) 305 306" clean up 307 %d _ 308set bs & vim 309endfunc 310 311func Test_Visual_word_textobject () 312new 313call setline ( 1 , [ 'First sentence. Second sentence.' ]) 314 315" When start and end of visual area are identical, 'aw' or 'iw' select 316" the whole word. 317norm ! 1go2fcvawy 318call assert_equal ( 'Second ' , @") 319norm ! 1go2fcviwy 320call assert_equal ( 'Second' , @") 321 322" When start and end of visual area are not identical, 'aw' or 'iw' 323" extend the word in direction of the end of the visual area. 324norm ! 1go2fcvlawy 325call assert_equal ( 'cond ' , @") 326norm ! gv2awy 327call assert_equal ( 'cond sentence.' , @") 328 329norm ! 1go2fcvliwy 330call assert_equal ( 'cond' , @") 331norm ! gv2iwy 332call assert_equal ( 'cond sentence' , @") 333 334" Extend visual area in opposite direction. 335norm ! 1go2fcvhawy 336call assert_equal ( ' Sec' , @") 337norm ! gv2awy 338call assert_equal ( ' sentence. Sec' , @") 339 340norm ! 1go2fcvhiwy 341call assert_equal ( 'Sec' , @") 342norm ! gv2iwy 343call assert_equal ( '. Sec' , @") 344 345bwipe ! 346endfunc 347 348func Test_Visual_sentence_textobject () 349new 350call setline ( 1 , [ 'First sentence. Second sentence. Third' , 'sentence. Fourth sentence' ]) 351 352" When start and end of visual area are identical, 'as' or 'is' select 353" the whole sentence. 354norm ! 1gofdvasy 355call assert_equal ( 'Second sentence. ' , @") 356norm ! 1gofdvisy 357call assert_equal ( 'Second sentence.' , @") 358 359" When start and end of visual area are not identical, 'as' or 'is' 360" extend the sentence in direction of the end of the visual area. 361norm ! 1gofdvlasy 362call assert_equal ( 'd sentence. ' , @") 363norm ! gvasy 364call assert_equal ( "d sentence. Third\nsentence. " , @") 365 366norm ! 1gofdvlisy 367call assert_equal ( 'd sentence.' , @") 368norm ! gvisy 369call assert_equal ( 'd sentence. ' , @") 370norm ! gvisy 371call assert_equal ( "d sentence. Third\nsentence." , @") 372 373" Extend visual area in opposite direction. 374norm ! 1gofdvhasy 375call assert_equal ( ' Second' , @") 376norm ! gvasy 377call assert_equal ( "First sentence. Second" , @") 378 379norm ! 1gofdvhisy 380call assert_equal ( 'Second' , @") 381norm ! gvisy 382call assert_equal ( ' Second' , @") 383norm ! gvisy 384call assert_equal ( 'First sentence. Second' , @") 385 386bwipe ! 387endfunc 388 389func Test_Visual_paragraph_textobject () 390new 391let lines =<< trim [END] 392First line. 393 394Second line. 395Third line. 396Fourth line. 397Fifth line. 398 399Sixth line. 400[END] 401call setline ( 1 , lines ) 402 403" When start and end of visual area are identical, 'ap' or 'ip' select 404" the whole paragraph. 405norm ! 4ggvapy 406call assert_equal ( "Second line.\nThird line.\nFourth line.\nFifth line.\n\n" , @") 407norm ! 4ggvipy 408call assert_equal ( "Second line.\nThird line.\nFourth line.\nFifth line.\n" , @") 409 410" When start and end of visual area are not identical, 'ap' or 'ip' 411" extend the sentence in direction of the end of the visual area. 412" FIXME: actually, it is not sufficient to have different start and 413" end of visual selection, the start line and end line have to differ, 414" which is not consistent with the documentation. 415norm ! 4ggVjapy 416call assert_equal ( "Third line.\nFourth line.\nFifth line.\n\n" , @") 417norm ! gvapy 418call assert_equal ( "Third line.\nFourth line.\nFifth line.\n\nSixth line.\n" , @") 419norm ! 4ggVjipy 420call assert_equal ( "Third line.\nFourth line.\nFifth line.\n" , @") 421norm ! gvipy 422call assert_equal ( "Third line.\nFourth line.\nFifth line.\n\n" , @") 423norm ! gvipy 424call assert_equal ( "Third line.\nFourth line.\nFifth line.\n\nSixth line.\n" , @") 425 426" Extend visual area in opposite direction. 427norm ! 5ggVkapy 428call assert_equal ( "\nSecond line.\nThird line.\nFourth line.\n" , @") 429norm ! gvapy 430call assert_equal ( "First line.\n\nSecond line.\nThird line.\nFourth line.\n" , @") 431norm ! 5ggVkipy 432call assert_equal ( "Second line.\nThird line.\nFourth line.\n" , @") 433norma gvipy 434call assert_equal ( "\nSecond line.\nThird line.\nFourth line.\n" , @") 435norm ! gvipy 436call assert_equal ( "First line.\n\nSecond line.\nThird line.\nFourth line.\n" , @") 437 438bwipe ! 439endfunc 440 441func Test_curswant_not_changed () 442new 443call setline ( 1 , [ 'one' , 'two' ]) 444au InsertLeave * call getcurpos () 445call feedkeys ( "gg0\<C-V>jI123 \<Esc>j" , 'xt' ) 446call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos ()) 447 448bwipe ! 449au ! InsertLeave 450endfunc 451 452" Tests for "vaBiB", end could be wrong. 453func Test_Visual_Block () 454new 455a 456-Bug in "vPPPP" on this text: 457 { 458cmd ; 459 { 460cmd ;\t/* <-- Start cursor here */ 461 { 462} 463} 464} 465. 466normal gg 467call search ( 'Start cursor here' ) 468normal vaBiBD 469call assert_equal ([ '- Bug in "vPPPP" on this text:' , 470 \"\t{" , 471 \"\t}" ], getline ( 1 , '$' )) 472 473bw ! 474endfunc 475 476" Test for 'p'ut in visual block mode 477func Test_visual_block_put () 478new 479call append ( 0 , [ 'One' , 'Two' , 'Three' ]) 480normal gg 481yank 482call feedkeys ( "jl\<C-V>ljp" , 'xt' ) 483call assert_equal ([ 'One' , 'T' , 'Tee' , 'One' , '' ], getline ( 1 , '$' )) 484bw ! 485endfunc 486 487func Test_visual_block_put_invalid () 488enew ! 489" behave mswin 490set selection = exclusive 491norm yy 492norm v)Ps/^/ 493" this was causing the column to become negative 494silent norm ggv)P 495 496bwipe ! 497" behave xterm 498set selection & 499endfunc 500 501" Visual modes (v V CTRL-V) followed by an operator; count; repeating 502func Test_visual_mode_op () 503new 504call append ( 0 , '' ) 505 506call setline ( 1 , 'apple banana cherry' ) 507call cursor ( 1 , 1 ) 508" Nvim: "." re-executes the captured keysequence (|visual-repeat|): the final 509" "." replays "3vd", multiplying the previous (grown) selection again. 510normal lvld.l3vd. 511call assert_equal ( 'a ' , getline ( 1 )) 512 513call setline ( 1 , [ 'line 1 line 1' , 'line 2 line 2' , 'line 3 line 3' , 514 \'line 4 line 4' , 'line 5 line 5' , 'line 6 line 6' ]) 515call cursor ( 1 , 1 ) 516exe "normal Vcnewline\<Esc>j.j2Vd." 517call assert_equal ([ 'newline' , 'newline' ], getline ( 1 , '$' )) 518 519call deletebufline ( '' , 1 , '$' ) 520call setline ( 1 , [ 'xxxxxxxxxxxxx' , 'xxxxxxxxxxxxx' , 'xxxxxxxxxxxxx' , 521 \'xxxxxxxxxxxxx' ]) 522exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l." 523call assert_equal ([ ' --------' , 524 \' --------' , 525 \'xxxx--------' , 526 \'xxxx--------' ], getline ( 1 , '$' )) 527 528bwipe ! 529endfunc 530 531" Visual mode maps (movement and text object) 532" Visual mode maps; count; repeating 533" - Simple 534" - With an Ex command (custom text object) 535func Test_visual_mode_maps () 536new 537call append ( 0 , '' ) 538 539func SelectInCaps () 540let [ line1 , col1 ] = searchpos ( '\u' , 'bcnW' ) 541let [ line2 , col2 ] = searchpos ( '.\u' , 'nW' ) 542call setpos ( "'<" , [ 0 , line1 , col1 , 0 ]) 543call setpos ( "'>" , [ 0 , line2 , col2 , 0 ]) 544normal ! gv 545endfunction 546 547vnoremap W /\u/s-1< CR > 548vnoremap iW :< C-U > call SelectInCaps()< CR > 549 550" Nvim: a selection extended by a search or Ex motion is not replayable: 551" "." falls back to an equal-size reselect ("1v"), like Vim. But "." after 552" "2vd" re-executes "2vd", multiplying the previous (grown) area again. 553call setline ( 1 , 'KiwiRaspberryDateWatermelonPeach' ) 554call cursor ( 1 , 1 ) 555exe "normal vWcNo\<Esc>l.fD2vd." 556call assert_equal ( 'NoNo' , getline ( 1 )) 557 558call setline ( 1 , 'JambuRambutanBananaTangerineMango' ) 559call cursor ( 1 , 1 ) 560exe "normal llviWc-\<Esc>l.l2vdl." 561call assert_equal ( '--a' , getline ( 1 )) 562 563vunmap W 564vunmap iW 565bwipe ! 566delfunc SelectInCaps 567endfunc 568 569" Operator-pending mode maps (movement and text object) 570" - Simple 571" - With Ex command moving the cursor 572" - With Ex command and Visual selection (custom text object) 573func Test_visual_oper_pending_mode_maps () 574new 575call append ( 0 , '' ) 576 577func MoveToCap () 578call search ( '\u' , 'W' ) 579endfunction 580 581func SelectInCaps () 582let [ line1 , col1 ] = searchpos ( '\u' , 'bcnW' ) 583let [ line2 , col2 ] = searchpos ( '.\u' , 'nW' ) 584call setpos ( "'<" , [ 0 , line1 , col1 , 0 ]) 585call setpos ( "'>" , [ 0 , line2 , col2 , 0 ]) 586normal ! gv 587endfunction 588 589onoremap W /\u/< CR > 590onoremap < Leader > W :< C-U > call MoveToCap()< CR > 591onoremap iW :< C-U > call SelectInCaps()< CR > 592 593call setline ( 1 , 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ' ) 594call cursor ( 1 , 1 ) 595exe "normal cW-\<Esc>l.l2.l." 596call assert_equal ( '----Z' , getline ( 1 )) 597 598call setline ( 1 , 'JuniperDurianZ' ) 599call cursor ( 1 , 1 ) 600exe "normal g?\WfD." 601call assert_equal ( 'WhavcreQhevnaZ' , getline ( 1 )) 602 603call setline ( 1 , 'LemonNectarineZ' ) 604call cursor ( 1 , 1 ) 605exe "normal yiWPlciWNew\<Esc>fr." 606call assert_equal ( 'LemonNewNewZ' , getline ( 1 )) 607 608ounmap W 609ounmap <Leader>W 610ounmap iW 611bwipe ! 612delfunc MoveToCap 613delfunc SelectInCaps 614endfunc 615 616" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. 617func Test_op_pend_mode_abort () 618new 619call append ( 0 , '' ) 620 621call setline ( 1 , [ 'zzzz' , 'zzzz' ]) 622call cursor ( 1 , 1 ) 623 624exe "normal dV:\<CR>dv:\<CR>" 625call assert_equal ([ 'zzz' ], getline ( 1 , 2 )) 626set nomodifiable 627call assert_fails ( 'exe "normal d:\<CR>"' , 'E21:' ) 628set modifiable 629call feedkeys ( "dv:\<Esc>dV:\<Esc>" , 'xt' ) 630call assert_equal ([ 'zzz' ], getline ( 1 , 2 )) 631set nomodifiable 632let v: errmsg = '' 633call feedkeys ( "d:\<Esc>" , 'xt' ) 634call assert_true ( v: errmsg !~# '^E21:' ) 635set modifiable 636 637bwipe ! 638endfunc 639 640func Test_characterwise_visual_mode () 641new 642 643" characterwise visual mode: replace last line 644$ put ='a' 645let @"= 'x' 646normal v$p 647call assert_equal ( 'x' , getline ( '$' )) 648 649" characterwise visual mode: delete middle line 650call deletebufline ( '' , 1 , '$' ) 651call append ( '$' , [ 'a' , 'b' , 'c' ]) 652normal G 653normal kkv$d 654call assert_equal ([ '' , 'b' , 'c' ], getline ( 1 , '$' )) 655 656" characterwise visual mode: delete middle two lines 657call deletebufline ( '' , 1 , '$' ) 658call append ( '$' , [ 'a' , 'b' , 'c' ]) 659normal Gkkvj$d 660call assert_equal ([ '' , 'c' ], getline ( 1 , '$' )) 661 662" characterwise visual mode: delete last line 663call deletebufline ( '' , 1 , '$' ) 664call append ( '$' , [ 'a' , 'b' , 'c' ]) 665normal Gv$d 666call assert_equal ([ '' , 'a' , 'b' , '' ], getline ( 1 , '$' )) 667 668" characterwise visual mode: delete last two lines 669call deletebufline ( '' , 1 , '$' ) 670call append ( '$' , [ 'a' , 'b' , 'c' ]) 671normal Gkvj$d 672call assert_equal ([ '' , 'a' , '' ], getline ( 1 , '$' )) 673 674" characterwise visual mode: use a count with the visual mode from the last 675" line in the buffer 676 %d _ 677call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' ]) 678norm ! vj$y 679norm ! G1vy 680call assert_equal ( 'four' , @") 681 682" characterwise visual mode: replace a single character line and the eol 683 %d _ 684call setline ( 1 , "a" ) 685normal v$rx 686call assert_equal ([ 'x' ], getline ( 1 , '$' )) 687 688" replace a character with composing characters 689call setline ( 1 , "xã̳x" ) 690normal gg0lvrb 691call assert_equal ( "xbx" , getline ( 1 )) 692 693bwipe ! 694endfunc 695 696func Test_visual_mode_put () 697new 698 699" v_p: replace last character with line register at middle line 700call append ( '$' , [ 'aaa' , 'bbb' , 'ccc' ]) 701normal G 702-2 yank 703normal k$vp 704call assert_equal ([ '' , 'aaa' , 'bb' , 'aaa' , '' , 'ccc' ], getline ( 1 , '$' )) 705 706" v_p: replace last character with line register at middle line selecting 707" newline 708call deletebufline ( '' , 1 , '$' ) 709call append ( '$' , [ 'aaa' , 'bbb' , 'ccc' ]) 710normal G 711-2 yank 712normal k$v$p 713call assert_equal ([ '' , 'aaa' , 'bb' , 'aaa' , 'ccc' ], getline ( 1 , '$' )) 714 715" v_p: replace last character with line register at last line 716call deletebufline ( '' , 1 , '$' ) 717call append ( '$' , [ 'aaa' , 'bbb' , 'ccc' ]) 718normal G 719-2 yank 720normal $vp 721call assert_equal ([ '' , 'aaa' , 'bbb' , 'cc' , 'aaa' , '' ], getline ( 1 , '$' )) 722 723" v_p: replace last character with line register at last line selecting 724" newline 725call deletebufline ( '' , 1 , '$' ) 726call append ( '$' , [ 'aaa' , 'bbb' , 'ccc' ]) 727normal G 728-2 yank 729normal $v$p 730call assert_equal ([ '' , 'aaa' , 'bbb' , 'cc' , 'aaa' , '' ], getline ( 1 , '$' )) 731 732bwipe ! 733endfunc 734 735func Test_gv_with_exclusive_selection () 736new 737 738" gv with exclusive selection after an operation 739call append ( '$' , [ 'zzz ' , 'äà ' ]) 740set selection = exclusive 741normal Gkv3lyjv3lpgvcxxx 742call assert_equal ([ '' , 'zzz ' , 'xxx ' ], getline ( 1 , '$' )) 743 744" gv with exclusive selection without an operation 745call deletebufline ( '' , 1 , '$' ) 746call append ( '$' , 'zzz ' ) 747set selection = exclusive 748exe "normal G0v3l\<Esc>gvcxxx" 749call assert_equal ([ '' , 'xxx ' ], getline ( 1 , '$' )) 750 751set selection & vim 752bwipe ! 753endfunc 754 755" Tests for the visual block mode commands 756func Test_visual_block_mode () 757new 758call append ( 0 , '' ) 759call setline ( 1 , repeat ([ 'abcdefghijklm' ], 5 )) 760call cursor ( 1 , 1 ) 761 762" Test shift-right of a block 763exe "normal jllll\<C-V>jj>wll\<C-V>jlll>" 764" Test shift-left of a block 765exe "normal G$hhhh\<C-V>kk<" 766" Test block-insert 767exe "normal Gkl\<C-V>kkkIxyz" 768" Test block-replace 769exe "normal Gllll\<C-V>kkklllrq" 770" Test block-change 771exe "normal G$khhh\<C-V>hhkkcmno" 772call assert_equal ([ 'axyzbcdefghijklm' , 773 \'axyzqqqq mno ghijklm' , 774 \'axyzqqqqef mno ghijklm' , 775 \'axyzqqqqefgmnoklm' , 776 \'abcdqqqqijklm' ], getline ( 1 , 5 )) 777 778" Test 'C' to change till the end of the line 779call cursor ( 3 , 4 ) 780exe "normal! \<C-V>j3lCooo" 781call assert_equal ([ 'axyooo' , 'axyooo' ], getline ( 3 , 4 )) 782 783" Test 'D' to delete till the end of the line 784call cursor ( 3 , 3 ) 785exe "normal! \<C-V>j2lD" 786call assert_equal ([ 'ax' , 'ax' ], getline ( 3 , 4 )) 787 788" Test block insert with a short line that ends before the block 789 %d _ 790call setline ( 1 , [ " one" , "a" , " two" ]) 791exe "normal gg\<C-V>2jIx" 792call assert_equal ([ " xone" , "a" , " xtwo" ], getline ( 1 , '$' )) 793 794" Test block append at EOL with '$' and without '$' 795 %d _ 796call setline ( 1 , [ "one" , "a" , "two" ]) 797exe "normal gg$\<C-V>2jAx" 798call assert_equal ([ "onex" , "ax" , "twox" ], getline ( 1 , '$' )) 799 %d _ 800call setline ( 1 , [ "one" , "a" , "two" ]) 801exe "normal gg3l\<C-V>2jAx" 802call assert_equal ([ "onex" , "a x" , "twox" ], getline ( 1 , '$' )) 803 804" Test block replace with an empty line in the middle and use $ to jump to 805" the end of the line. 806 %d _ 807call setline ( 1 , [ 'one' , '' , 'two' ]) 808exe "normal gg$\<C-V>2jrx" 809call assert_equal ([ "onx" , "" , "twx" ], getline ( 1 , '$' )) 810 811" Test block replace with an empty line in the middle and move cursor to the 812" end of the line 813 %d _ 814call setline ( 1 , [ 'one' , '' , 'two' ]) 815exe "normal gg2l\<C-V>2jrx" 816call assert_equal ([ "onx" , "" , "twx" ], getline ( 1 , '$' )) 817 818" Replace odd number of characters with a multibyte character 819 %d _ 820call setline ( 1 , [ 'abcd' , 'efgh' ]) 821exe "normal ggl\<C-V>2ljr\u1100" 822call assert_equal ([ "a\u1100 " , "e\u1100 " ], getline ( 1 , '$' )) 823 824" During visual block append, if the cursor moved outside of the selected 825" range, then the edit should not be applied to the block. 826 %d _ 827call setline ( 1 , [ 'aaa' , 'bbb' , 'ccc' ]) 828exe "normal 2G\<C-V>jAx\<Up>" 829call assert_equal ([ 'aaa' , 'bxbb' , 'ccc' ], getline ( 1 , '$' )) 830 831" During visual block append, if the cursor is moved before the start of the 832" block, then the new text should be appended there. 833 %d _ 834call setline ( 1 , [ 'aaa' , 'bbb' , 'ccc' ]) 835exe "normal $\<C-V>2jA\<Left>x" 836call assert_equal ([ 'aaxa' , 'bbxb' , 'ccxc' ], getline ( 1 , '$' )) 837" Repeat the previous test but use 'l' to move the cursor instead of '$' 838call setline ( 1 , [ 'aaa' , 'bbb' , 'ccc' ]) 839exe "normal! gg2l\<C-V>2jA\<Left>x" 840call assert_equal ([ 'aaxa' , 'bbxb' , 'ccxc' ], getline ( 1 , '$' )) 841 842" Change a characterwise motion to a blockwise motion using CTRL-V 843 %d _ 844call setline ( 1 , [ '123' , '456' , '789' ]) 845exe "normal ld\<C-V>j" 846call assert_equal ([ '13' , '46' , '789' ], getline ( 1 , '$' )) 847 848" Test from ':help v_b_I_example' 849 %d _ 850setlocal tabstop = 8 shiftwidth = 4 851let lines =<< trim END 852abcdefghijklmnopqrstuvwxyz 853abc defghijklmnopqrstuvwxyz 854abcdef ghi jklmnopqrstuvwxyz 855abcdefghijklmnopqrstuvwxyz 856END 857call setline ( 1 , lines ) 858exe "normal ggfo\<C-V>3jISTRING" 859let expected =<< trim END 860abcdefghijklmnSTRINGopqrstuvwxyz 861abc STRING defghijklmnopqrstuvwxyz 862abcdef ghi STRING jklmnopqrstuvwxyz 863abcdefghijklmnSTRINGopqrstuvwxyz 864END 865call assert_equal ( expected , getline ( 1 , '$' )) 866 867" Test from ':help v_b_A_example' 868 %d _ 869let lines =<< trim END 870abcdefghijklmnopqrstuvwxyz 871abc defghijklmnopqrstuvwxyz 872abcdef ghi jklmnopqrstuvwxyz 873abcdefghijklmnopqrstuvwxyz 874END 875call setline ( 1 , lines ) 876exe "normal ggfo\<C-V>3j$ASTRING" 877let expected =<< trim END 878abcdefghijklmnopqrstuvwxyzSTRING 879abc defghijklmnopqrstuvwxyzSTRING 880abcdef ghi jklmnopqrstuvwxyzSTRING 881abcdefghijklmnopqrstuvwxyzSTRING 882END 883call assert_equal ( expected , getline ( 1 , '$' )) 884 885" Test from ':help v_b_<_example' 886 %d _ 887let lines =<< trim END 888abcdefghijklmnopqrstuvwxyz 889abc defghijklmnopqrstuvwxyz 890abcdef ghi jklmnopqrstuvwxyz 891abcdefghijklmnopqrstuvwxyz 892END 893call setline ( 1 , lines ) 894exe "normal ggfo\<C-V>3j3l<.." 895let expected =<< trim END 896abcdefghijklmnopqrstuvwxyz 897abc defghijklmnopqrstuvwxyz 898abcdef ghi jklmnopqrstuvwxyz 899abcdefghijklmnopqrstuvwxyz 900END 901call assert_equal ( expected , getline ( 1 , '$' )) 902 903" Test from ':help v_b_>_example' 904 %d _ 905let lines =<< trim END 906abcdefghijklmnopqrstuvwxyz 907abc defghijklmnopqrstuvwxyz 908abcdef ghi jklmnopqrstuvwxyz 909abcdefghijklmnopqrstuvwxyz 910END 911call setline ( 1 , lines ) 912exe "normal ggfo\<C-V>3j>.." 913let expected =<< trim END 914abcdefghijklmn opqrstuvwxyz 915abc defghijklmnopqrstuvwxyz 916abcdef ghi jklmnopqrstuvwxyz 917abcdefghijklmn opqrstuvwxyz 918END 919call assert_equal ( expected , getline ( 1 , '$' )) 920 921" Test from ':help v_b_r_example' 922 %d _ 923let lines =<< trim END 924abcdefghijklmnopqrstuvwxyz 925abc defghijklmnopqrstuvwxyz 926abcdef ghi jklmnopqrstuvwxyz 927abcdefghijklmnopqrstuvwxyz 928END 929call setline ( 1 , lines ) 930exe "normal ggfo\<C-V>5l3jrX" 931let expected =<< trim END 932abcdefghijklmnXXXXXXuvwxyz 933abc XXXXXXhijklmnopqrstuvwxyz 934abcdef ghi XXXXXX jklmnopqrstuvwxyz 935abcdefghijklmnXXXXXXuvwxyz 936END 937call assert_equal ( expected , getline ( 1 , '$' )) 938 939bwipe ! 940set tabstop & shiftwidth & 941endfunc 942 943func Test_visual_force_motion_feedkeys () 944onoremap <expr> i- execute ( 'let g:mode = mode(1)' ) ->slice ( 0 , 0 ) 945call feedkeys ( 'dvi-' , 'x' ) 946call assert_equal ( 'nov' , g: mode ) 947call feedkeys ( 'di-' , 'x' ) 948call assert_equal ( 'no' , g: mode ) 949ounmap i- 950endfunc 951 952" Test block-insert using cursor keys for movement 953func Test_visual_block_insert_cursor_keys () 954new 955call append ( 0 , [ 'aaaaaa' , 'bbbbbb' , 'cccccc' , 'dddddd' ]) 956call cursor ( 1 , 1 ) 957 958exe "norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" 959call assert_equal ([ 'aaa aaa' , 'bbb bbb' , 'ccc ccc' , 'ddd ddd' ], 960 \getline ( 1 , 4 )) 961 962call deletebufline ( '' , 1 , '$' ) 963call setline ( 1 , [ 'xaaa' , 'bbbb' , 'cccc' , 'dddd' ]) 964call cursor ( 1 , 1 ) 965exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>" 966call assert_equal ([ '<p>xaaa' , '<p>bbbb' , '<p>cccc' , '<p>dddd' ], 967 \getline ( 1 , 4 )) 968bwipe ! 969endfunc 970 971func Test_visual_block_create () 972new 973call append ( 0 , '' ) 974" Test for Visual block was created with the last <C-v>$ 975call setline ( 1 , [ 'A23' , '4567' ]) 976call cursor ( 1 , 1 ) 977exe "norm! l\<C-V>j$Aab\<Esc>" 978call assert_equal ([ 'A23ab' , '4567ab' ], getline ( 1 , 2 )) 979 980" Test for Visual block was created with the middle <C-v>$ (1) 981call deletebufline ( '' , 1 , '$' ) 982call setline ( 1 , [ 'B23' , '4567' ]) 983call cursor ( 1 , 1 ) 984exe "norm! l\<C-V>j$hAab\<Esc>" 985call assert_equal ([ 'B23 ab' , '4567ab' ], getline ( 1 , 2 )) 986 987" Test for Visual block was created with the middle <C-v>$ (2) 988call deletebufline ( '' , 1 , '$' ) 989call setline ( 1 , [ 'C23' , '4567' ]) 990call cursor ( 1 , 1 ) 991exe "norm! l\<C-V>j$hhAab\<Esc>" 992call assert_equal ([ 'C23ab' , '456ab7' ], getline ( 1 , 2 )) 993bwipe ! 994endfunc 995 996" Test for Visual block insert when virtualedit=all 997func Test_virtualedit_visual_block () 998set ve = all 999new 1000call append ( 0 , [ "\t\tline1" , "\t\tline2" , "\t\tline3" ]) 1001call cursor ( 1 , 1 ) 1002exe "norm! 07l\<C-V>jjIx\<Esc>" 1003call assert_equal ([ " x \tline1" , 1004 \" x \tline2" , 1005 \" x \tline3" ], getline ( 1 , 3 )) 1006 1007" Test for Visual block append when virtualedit=all 1008exe "norm! 012l\<C-v>jjAx\<Esc>" 1009call assert_equal ([ ' x x line1' , 1010 \' x x line2' , 1011 \' x x line3' ], getline ( 1 , 3 )) 1012set ve = 1013bwipe ! 1014endfunc 1015 1016func Test_virtualedit_visual_block_reselect () 1017set ve = all 1018new 1019call append ( 0 , [ '###' , '###' , '###' , '#####' ]) 1020call cursor ( 1 , 1 ) 1021exe "norm! \<C-V>lljj" 1022call assert_equal ([ 0 , 3 , 3 , 0 ], getpos ( '.' )) 1023call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( 'v' )) 1024norm ! y 1025call assert_equal ([ '###' , '###' , '###' ], getreg ( '"' , v: true , v: true )) 1026call cursor ( 2 , 6 ) 1027call assert_equal ([ 0 , 2 , 4 , 2 ], getpos ( '.' )) 1028norm ! 1v 1029call assert_equal ([ 0 , 4 , 6 , 2 ], getpos ( '.' )) 1030call assert_equal ([ 0 , 2 , 4 , 2 ], getpos ( 'v' )) 1031norm ! r! 1032call assert_equal ([ '### !!!' , '### !!!' , '#####!!!' ], getline ( 2 , 4 )) 1033 1034bwipe ! 1035set ve & 1036endfunc 1037 1038" Test for changing case 1039func Test_visual_change_case () 1040new 1041" gUe must uppercase a whole word, also when ß changes to ẞ 1042exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r" 1043" gUfx must uppercase until x, inclusive. 1044exe "normal O- youßtußexu -\<Esc>0fogUfx\r" 1045" VU must uppercase a whole line 1046exe "normal YpkVU\r" 1047" same, when it's the last line in the buffer 1048exe "normal YPGi111\<Esc>VUddP\r" 1049" Uppercase two lines 1050exe "normal Oblah di\rdoh dut\<Esc>VkUj\r" 1051" Uppercase part of two lines 1052exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk" 1053call assert_equal ([ 'the YOUTUẞEUU end' , '- yOUẞTUẞEXu -' , 1054 \'THE YOUTUẞEUU END' , '111THE YOUTUẞEUU END' , 'BLAH DI' , 'DOH DUT' , 1055 \'222the yoUTUẞEUU END' , '333THE YOUTUßeuu end' ], getline ( 2 , '$' )) 1056bwipe ! 1057endfunc 1058 1059" Test for Visual replace using Enter or NL 1060func Test_visual_replace_crnl () 1061new 1062exe "normal G3o123456789\e2k05l\<C-V>2jr\r" 1063exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n" 1064exe "normal G3o123456789\e2k05l\<C-V>2jr\n" 1065exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n" 1066call assert_equal ([ '12345' , '789' , '12345' , '789' , '12345' , '789' , "98\r65" , 1067 \"98\r65" , "98\r65" , '12345' , '789' , '12345' , '789' , '12345' , '789' , 1068 \"98\n65" , "98\n65" , "98\n65" ], getline ( 2 , '$' )) 1069bwipe ! 1070endfunc 1071 1072func Test_ve_block_curpos () 1073new 1074" Test cursor position. When ve=block and Visual block mode and $gj 1075call append ( 0 , [ '12345' , '789' ]) 1076call cursor ( 1 , 3 ) 1077set virtualedit = block 1078exe "norm! \<C-V>$gj\<Esc>" 1079call assert_equal ([ 0 , 2 , 4 , 0 ], getpos ( "'>" )) 1080set virtualedit = 1081bwipe ! 1082endfunc 1083 1084" Test for block_insert when replacing spaces in front of the a with tabs 1085func Test_block_insert_replace_tabs () 1086new 1087set ts = 8 sts = 4 sw = 4 1088call append ( 0 , [ "#define BO_ALL\t 0x0001" , 1089 \"#define BO_BS\t 0x0002" , 1090 \"#define BO_CRSR\t 0x0004" ]) 1091call cursor ( 1 , 1 ) 1092exe "norm! f0\<C-V>2jI\<tab>\<esc>" 1093call assert_equal ([ 1094 \"#define BO_ALL\t\t0x0001" , 1095 \"#define BO_BS\t \t0x0002" , 1096 \"#define BO_CRSR\t \t0x0004" , '' ], getline ( 1 , '$' )) 1097set ts & sts & sw & 1098bwipe ! 1099endfunc 1100 1101" Test for * register in : 1102func Test_star_register () 1103call assert_fails ( '*bfirst' , 'E16:' ) 1104new 1105call setline ( 1 , [ 'foo' , 'bar' , 'baz' , 'qux' ]) 1106exe "normal jVj\<ESC>" 1107* yank r 1108call assert_equal ( "bar\nbaz\n" , @r) 1109 1110delmarks < > 1111call assert_fails ( '*yank' , 'E20:' ) 1112bw ! 1113endfunc 1114 1115" Test for changing text in visual mode with 'exclusive' selection 1116func Test_exclusive_selection () 1117new 1118call setline ( 1 , [ 'one' , 'two' ]) 1119set selection = exclusive 1120call feedkeys ( "vwcabc" , 'xt' ) 1121call assert_equal ( 'abctwo' , getline ( 1 )) 1122call setline ( 1 , [ "\tone" ]) 1123set virtualedit = all 1124call feedkeys ( '0v2lcl' , 'xt' ) 1125call assert_equal ( 'l one' , getline ( 1 )) 1126set virtualedit & 1127set selection & 1128bw ! 1129endfunc 1130 1131" Test for inclusive motion in visual mode with 'exclusive' selection 1132func Test_inclusive_motion_selection_exclusive () 1133func s: compare_exclu_inclu ( line , keys , expected_exclu ) 1134let msg = "data: '" . a: line . "' operation: '" . a: keys . "'" 1135call setline ( 1 , a: line ) 1136set selection = exclusive 1137call feedkeys ( a: keys , 'xt' ) 1138call assert_equal ( a: expected_exclu , getpos ( '.' ), msg ) 1139let pos_ex = col ( '.' ) 1140set selection = inclusive 1141call feedkeys ( a: keys , 'xt' ) 1142let pos_in = col ( '.' ) 1143call assert_equal ( 1 , pos_ex - pos_in , msg ) 1144endfunc 1145 1146new 1147" Test 'e' motion 1148set selection = exclusive 1149call setline ( 1 , 'eins zwei drei' ) 1150norm ! ggvey 1151call assert_equal ( 'eins' , @") 1152call setline ( 1 , 'abc(abc)abc' ) 1153norm ! ggveeed 1154call assert_equal ( ')abc' , getline ( 1 )) 1155call setline ( 1 , 'abc(abc)abc' ) 1156norm ! gg3lvey 1157call assert_equal ( '(abc' , @") 1158call s: compare_exclu_inclu ( 'abc(abc)abc' , 'ggveee' , [ 0 , 1 , 8 , 0 ]) 1159" Test 'f' motion 1160call s: compare_exclu_inclu ( 'geschwindigkeit' , 'ggvfefe' , [ 0 , 1 , 14 , 0 ]) 1161call s: compare_exclu_inclu ( 'loooooooooooong' , 'ggv2fo2fo2fo' , [ 0 , 1 , 8 , 0 ]) 1162" Test 't' motion 1163call s: compare_exclu_inclu ( 'geschwindigkeit' , 'ggv2te' , [ 0 , 1 , 13 , 0 ]) 1164call s: compare_exclu_inclu ( 'loooooooooooong' , 'gglv2to2to2to' , [ 0 , 1 , 6 , 0 ]) 1165" Test ';' motion 1166call s: compare_exclu_inclu ( 'geschwindigkeit' , 'ggvfi;;' , [ 0 , 1 , 15 , 0 ]) 1167call s: compare_exclu_inclu ( 'geschwindigkeit' , 'ggvti;;' , [ 0 , 1 , 14 , 0 ]) 1168call s: compare_exclu_inclu ( 'loooooooooooong' , 'ggv2fo;;' , [ 0 , 1 , 6 , 0 ]) 1169call s: compare_exclu_inclu ( 'loooooooooooong' , 'ggvl2to;;' , [ 0 , 1 , 6 , 0 ]) 1170" Clean up 1171set selection & 1172bw ! 1173endfunc 1174 1175" Test for starting linewise visual with a count. 1176" This test needs to be run without any previous visual mode. Otherwise the 1177" count will use the count from the previous visual mode. 1178func Test_linewise_visual_with_count () 1179let after =<< trim [CODE] 1180call setline(1, ['one', 'two', 'three', 'four']) 1181norm! 3Vy 1182call assert_equal("one\ntwo\nthree\n", @") 1183call writefile(v:errors, 'Xtestout') 1184qall! 1185[CODE] 1186if RunVim ([], after , '' ) 1187call assert_equal ([], readfile ( 'Xtestout' )) 1188call delete ( 'Xtestout' ) 1189endif 1190endfunc 1191 1192" Test for starting characterwise visual with a count. 1193" This test needs to be run without any previous visual mode. Otherwise the 1194" count will use the count from the previous visual mode. 1195func Test_characterwise_visual_with_count () 1196let after =<< trim [CODE] 1197call setline(1, ['one two', 'three']) 1198norm! l5vy 1199call assert_equal("ne tw", @") 1200call writefile(v:errors, 'Xtestout') 1201qall! 1202[CODE] 1203if RunVim ([], after , '' ) 1204call assert_equal ([], readfile ( 'Xtestout' )) 1205call delete ( 'Xtestout' ) 1206endif 1207endfunc 1208 1209" Test for visually selecting an inner block (iB) 1210func Test_visual_inner_block () 1211new 1212call setline ( 1 , [ 'one' , '{' , 'two' , '{' , 'three' , '}' , 'four' , '}' , 'five' ]) 1213call cursor ( 5 , 1 ) 1214" visually select all the lines in the block and then execute iB 1215call feedkeys ( "ViB\<C-C>" , 'xt' ) 1216call assert_equal ([ 0 , 5 , 1 , 0 ], getpos ( "'<" )) 1217call assert_equal ([ 0 , 5 , 6 , 0 ], getpos ( "'>" )) 1218" visually select two inner blocks 1219call feedkeys ( "ViBiB\<C-C>" , 'xt' ) 1220call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( "'<" )) 1221call assert_equal ([ 0 , 7 , 5 , 0 ], getpos ( "'>" )) 1222" try to select non-existing inner block 1223call cursor ( 5 , 1 ) 1224call assert_beeps ( 'normal ViBiBiB' ) 1225" try to select an unclosed inner block 12268 , 9 d 1227call cursor ( 5 , 1 ) 1228call assert_beeps ( 'normal ViBiB' ) 1229bw ! 1230endfunc 1231 1232func Test_visual_put_in_block () 1233new 1234call setline ( 1 , [ 'xxxx' , 'y∞yy' , 'zzzz' ]) 1235normal 1G2yl 1236exe "normal 1G2l\<C-V>jjlp" 1237call assert_equal ([ 'xxxx' , 'y∞xx' , 'zzxx' ], getline ( 1 , 3 )) 1238bwipe ! 1239endfunc 1240 1241func Test_visual_put_in_block_using_zp () 1242new 1243" paste using zP 1244call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1245 \'/subdir' , 1246 \'/longsubdir' , 1247 \'/longlongsubdir' ]) 1248exe "normal! 5G\<c-v>2j$y" 1249norm ! 1Gf;zP 1250call assert_equal ([ '/path/subdir;text' , '/path/longsubdir;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1251 %d 1252" paste using zP 1253call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1254 \'/subdir' , 1255 \'/longsubdir' , 1256 \'/longlongsubdir' ]) 1257exe "normal! 5G\<c-v>2j$y" 1258norm ! 1Gf;hzp 1259call assert_equal ([ '/path/subdir;text' , '/path/longsubdir;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1260bwipe ! 1261endfunc 1262 1263func Test_visual_put_in_block_using_zy_and_zp () 1264new 1265 1266" Test 1) Paste using zp - after the cursor without trailing spaces 1267call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1268 \'texttext /subdir columntext' , 1269 \'texttext /longsubdir columntext' , 1270 \'texttext /longlongsubdir columntext' ]) 1271exe "normal! 5G0f/\<c-v>2jezy" 1272norm ! 1G0f;hzp 1273call assert_equal ([ '/path/subdir;text' , '/path/longsubdir;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1274 1275" Test 2) Paste using zP - in front of the cursor without trailing spaces 1276 %d 1277call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1278 \'texttext /subdir columntext' , 1279 \'texttext /longsubdir columntext' , 1280 \'texttext /longlongsubdir columntext' ]) 1281exe "normal! 5G0f/\<c-v>2jezy" 1282norm ! 1G0f;zP 1283call assert_equal ([ '/path/subdir;text' , '/path/longsubdir;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1284 1285" Test 3) Paste using p - with trailing spaces 1286 %d 1287call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1288 \'texttext /subdir columntext' , 1289 \'texttext /longsubdir columntext' , 1290 \'texttext /longlongsubdir columntext' ]) 1291exe "normal! 5G0f/\<c-v>2jezy" 1292norm ! 1G0f;hp 1293call assert_equal ([ '/path/subdir ;text' , '/path/longsubdir ;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1294 1295" Test 4) Paste using P - with trailing spaces 1296 %d 1297call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1298 \'texttext /subdir columntext' , 1299 \'texttext /longsubdir columntext' , 1300 \'texttext /longlongsubdir columntext' ]) 1301exe "normal! 5G0f/\<c-v>2jezy" 1302norm ! 1G0f;P 1303call assert_equal ([ '/path/subdir ;text' , '/path/longsubdir ;text' , '/path/longlongsubdir;text' ], getline ( 1 , 3 )) 1304 1305" Test 5) Yank with spaces inside the block 1306 %d 1307call setline ( 1 , [ '/path;text' , '/path;text' , '/path;text' , '' , 1308 \'texttext /sub dir/ columntext' , 1309 \'texttext /lon gsubdir/ columntext' , 1310 \'texttext /lon glongsubdir/ columntext' ]) 1311exe "normal! 5G0f/\<c-v>2jf/zy" 1312norm ! 1G0f;zP 1313call assert_equal ([ '/path/sub dir/;text' , '/path/lon gsubdir/;text' , '/path/lon glongsubdir/;text' ], getline ( 1 , 3 )) 1314bwipe ! 1315endfunc 1316 1317func Test_visual_put_blockedit_zy_and_zp () 1318new 1319 1320call setline ( 1 , [ 'aa' , 'bbbbb' , 'ccc' , '' , 'XX' , 'GGHHJ' , 'RTZU' ]) 1321exe "normal! gg0\<c-v>2j$zy" 1322norm ! 5gg0zP 1323call assert_equal ([ 'aa' , 'bbbbb' , 'ccc' , '' , 'aaXX' , 'bbbbbGGHHJ' , 'cccRTZU' ], getline ( 1 , 7 )) 1324" 1325" now with blockmode editing 1326sil %d 1327: set ve = block 1328call setline ( 1 , [ 'aa' , 'bbbbb' , 'ccc' , '' , 'XX' , 'GGHHJ' , 'RTZU' ]) 1329exe "normal! gg0\<c-v>2j$zy" 1330norm ! 5gg0zP 1331call assert_equal ([ 'aa' , 'bbbbb' , 'ccc' , '' , 'aaXX' , 'bbbbbGGHHJ' , 'cccRTZU' ], getline ( 1 , 7 )) 1332set ve & vim 1333bw ! 1334endfunc 1335 1336func Test_visual_block_yank_zy () 1337new 1338" this was reading before the start of the line 1339exe "norm o\<C-T>\<Esc>\<C-V>zy" 1340bwipe ! 1341endfunc 1342 1343func Test_visual_block_with_virtualedit () 1344CheckScreendump 1345 1346let lines =<< trim END 1347call setline(1, ['aaaaaa', 'bbbb', 'cc']) 1348set virtualedit=block 1349normal G 1350END 1351call writefile ( lines , 'XTest_block' , 'D' ) 1352 1353let buf = RunVimInTerminal ( '-S XTest_block' , { 'rows' : 8 , 'cols' : 50 }) 1354call term_sendkeys ( buf , "\<C-V>gg$" ) 1355call WaitForAssert ({ ->assert_match ( 'VISUAL.*\dx\d' , term_getline ( buf , 8 ))}, 1000 ) 1356call VerifyScreenDump ( buf , 'Test_visual_block_with_virtualedit' , {}) 1357 1358call term_sendkeys ( buf , "\<Esc>gg\<C-V>G$" ) 1359call VerifyScreenDump ( buf , 'Test_visual_block_with_virtualedit2' , {}) 1360 1361" clean up 1362call term_sendkeys ( buf , "\<Esc>" ) 1363call StopVimInTerminal ( buf ) 1364endfunc 1365 1366func Test_visual_block_ctrl_w_f () 1367" Empty block selected in new buffer should not result in an error. 1368au ! BufNew foo sil norm f 1369edit foo 1370 1371au ! BufNew 1372endfunc 1373 1374func Test_visual_block_append_invalid_char () 1375" this was going over the end of the line 1376set isprint = @,161-255 1377new 1378call setline ( 1 , [ ' let xxx' , 'xxxxx' , 'xxxxxxxxxxx' ]) 1379exe "normal 0\<C-V>jjA-\<Esc>" 1380call assert_equal ([ ' - let xxx' , 'xxxxx -' , 'xxxxxxxx-xxx' ], getline ( 1 , 3 )) 1381bwipe ! 1382set isprint & 1383endfunc 1384 1385func Test_visual_block_with_substitute () 1386" this was reading beyond the end of the line 1387new 1388norm a0) 1389sil ! norm O 1390s /) 1391sil ! norm 1392 bwipe ! 1393endfunc 1394 1395func Test_visual_reselect_with_count () 1396enew 1397call setline ( 1 , [ 'aaaaaa' , '✗ bbbb' , '✗ bbbb' ]) 1398exe "normal! 2Gw\<C-V>jed" 1399exe "normal! gg0lP" 1400call assert_equal ([ 'abbbbaaaaa' , '✗bbbb ' , '✗ ' ], getline ( 1 , '$' )) 1401 1402exe "normal! 1vr." 1403call assert_equal ([ 'a....aaaaa' , '✗.... ' , '✗ ' ], getline ( 1 , '$' )) 1404 1405bwipe ! 1406 1407" this was causing an illegal memory access 1408let lines =<< trim END 1409 1410 1411 1412: 1413r<sfile> 1414exe "%norm e3\<c-v>kr\t" 1415: 1416 1417: 1418END 1419call writefile ( lines , 'XvisualReselect' ) 1420source XvisualReselect 1421 1422bwipe ! 1423call delete ( 'XvisualReselect' ) 1424endfunc 1425 1426func Test_visual_reselect_exclusive () 1427new 1428call setline ( 1 , [ 'abcde' , 'abcde' ]) 1429set selection = exclusive 1430normal 1G0viwd 1431normal 2G01vd 1432call assert_equal ([ '' , '' ], getline ( 1 , 2 )) 1433 1434set selection & 1435bwipe ! 1436endfunc 1437 1438func Test_visual_block_insert_round_off () 1439new 1440" The number of characters are tuned to fill a 4096 byte allocated block, 1441" so that valgrind reports going over the end. 1442call setline ( 1 , [ 'xxxxx' , repeat ( '0' , 1350 ), "\t" , repeat ( 'x' , 60 )]) 1443exe "normal gg0\<C-V>GI" .. repeat ( '0' , 1320 ) .. "\<Esc>" 1444bwipe ! 1445endfunc 1446 1447" this was causing an ml_get error 1448func Test_visual_exchange_windows () 1449enew ! 1450new 1451call setline ( 1 , [ 'foo' , 'bar' ]) 1452exe "normal G\<C-V>gg\<C-W>\<C-X>OO\<Esc>" 1453bwipe ! 1454bwipe ! 1455endfunc 1456 1457" this was leaving the end of the Visual area beyond the end of a line 1458func Test_visual_ex_copy_line () 1459new 1460call setline ( 1 , [ "aaa" , "bbbbbbbbbxbb" ]) 1461/ x 1462exe "normal ggvjfxO" 1463t 0 1464normal gNU 1465bwipe ! 1466endfunc 1467 1468" This was leaving the end of the Visual area beyond the end of a line. 1469" Set 'undolevels' to start a new undo block. 1470func Test_visual_undo_deletes_last_line () 1471new 1472call setline ( 1 , [ "aaa" , "ccc" , "dyd" ]) 1473set undolevels = 100 1474exe "normal obbbbbbbbbxbb\<Esc>" 1475set undolevels = 100 1476/ y 1477exe "normal ggvjfxO" 1478undo 1479normal gNU 1480 1481bwipe ! 1482endfunc 1483 1484func Test_visual_paste () 1485new 1486 1487" v_p overwrites unnamed register. 1488call setline ( 1 , [ 'xxxx' ]) 1489call setreg ( '"' , 'foo' ) 1490call setreg ( '-' , 'bar' ) 1491normal gg0vp 1492call assert_equal ( 'x' , @") 1493call assert_equal ( 'x' , @-) 1494call assert_equal ( 'fooxxx' , getline ( 1 )) 1495normal $vp 1496call assert_equal ( 'x' , @") 1497call assert_equal ( 'x' , @-) 1498call assert_equal ( 'fooxxx' , getline ( 1 )) 1499" Test with a different register as unnamed register. 1500call setline ( 2 , [ 'baz' ]) 1501normal 2gg0"rD 1502call assert_equal ( 'baz' , @") 1503normal gg0vp 1504call assert_equal ( 'f' , @") 1505call assert_equal ( 'f' , @-) 1506call assert_equal ( 'bazooxxx' , getline ( 1 )) 1507normal $vp 1508call assert_equal ( 'x' , @") 1509call assert_equal ( 'x' , @-) 1510call assert_equal ( 'bazooxxf' , getline ( 1 )) 1511 1512bwipe ! 1513endfunc 1514 1515func Test_visual_paste_clipboard () 1516CheckFeature clipboard_working 1517 1518if has ( 'gui' ) 1519" auto select feature breaks tests 1520set guioptions -= a 1521endif 1522 1523" v_P does not overwrite unnamed register. 1524call setline ( 1 , [ 'xxxx' ]) 1525call setreg ( '"' , 'foo' ) 1526call setreg ( '-' , 'bar' ) 1527normal gg0vP 1528call assert_equal ( 'foo' , @") 1529call assert_equal ( 'bar' , @-) 1530call assert_equal ( 'fooxxx' , getline ( 1 )) 1531normal $vP 1532call assert_equal ( 'foo' , @") 1533call assert_equal ( 'bar' , @-) 1534call assert_equal ( 'fooxxfoo' , getline ( 1 )) 1535" Test with a different register as unnamed register. 1536call setline ( 2 , [ 'baz' ]) 1537normal 2gg0"rD 1538call assert_equal ( 'baz' , @") 1539normal gg0vP 1540call assert_equal ( 'baz' , @") 1541call assert_equal ( 'bar' , @-) 1542call assert_equal ( 'bazooxxfoo' , getline ( 1 )) 1543normal $vP 1544call assert_equal ( 'baz' , @") 1545call assert_equal ( 'bar' , @-) 1546call assert_equal ( 'bazooxxfobaz' , getline ( 1 )) 1547 1548" Test for unnamed clipboard 1549set clipboard = unnamed 1550call setline ( 1 , [ 'xxxx' ]) 1551call setreg ( '"' , 'foo' ) 1552call setreg ( '-' , 'bar' ) 1553call setreg ( '*' , 'baz' ) 1554normal gg0vP 1555call assert_equal ( 'foo' , @") 1556call assert_equal ( 'bar' , @-) 1557call assert_equal ( 'baz' , @*) 1558call assert_equal ( 'bazxxx' , getline ( 1 )) 1559 1560" Test for unnamedplus clipboard 1561if has ( 'unnamedplus' ) 1562set clipboard = unnamedplus 1563call setline ( 1 , [ 'xxxx' ]) 1564call setreg ( '"' , 'foo' ) 1565call setreg ( '-' , 'bar' ) 1566call setreg ( '+' , 'baz' ) 1567normal gg0vP 1568call assert_equal ( 'foo' , @") 1569call assert_equal ( 'bar' , @-) 1570call assert_equal ( 'baz' , @+) 1571call assert_equal ( 'bazxxx' , getline ( 1 )) 1572endif 1573 1574set clipboard & 1575if has ( 'gui' ) 1576set guioptions & 1577endif 1578bwipe ! 1579endfunc 1580 1581func Test_visual_area_adjusted_when_hiding () 1582" The Visual area ended after the end of the line after :hide 1583call setline ( 1 , 'xxx' ) 1584vsplit Xfile 1585call setline ( 1 , 'xxxxxxxx' ) 1586norm ! $o 1587hid 1588norm ! zW 1589bwipe ! 1590bwipe ! 1591endfunc 1592 1593func Test_switch_buffer_ends_visual_mode () 1594enew 1595call setline ( 1 , 'foo' ) 1596set hidden 1597set virtualedit = all 1598let buf1 = bufnr () 1599enew 1600let buf2 = bufnr () 1601call setline ( 1 , [ '' , '' , '' , '' ]) 1602call cursor ( 4 , 5 ) 1603call feedkeys ( "\<C-V>3k4h" , 'xt' ) 1604exe 'buffer' buf1 1605call assert_equal ( 'n' , mode ()) 1606 1607set nohidden 1608set virtualedit = 1609bwipe ! 1610exe 'bwipe!' buf2 1611endfunc 1612 1613" Check fix for the heap-based buffer overflow bug found in the function 1614" utfc_ptr2len and reported at 1615" https://huntr.dev/bounties/ae933869-a1ec-402a-bbea-d51764c6618e 1616func Test_heap_buffer_overflow () 1617enew 1618set updatecount = 0 1619 1620norm R0 1621split other 1622norm R000 1623exe "norm \<C-V>l" 1624ball 1625call assert_equal ( getpos ( "." ), getpos ( "v" )) 1626call assert_equal ( 'n' , mode ()) 1627norm zW 1628 1629 %bwipe ! 1630set updatecount & 1631endfunc 1632 1633func s: ScreenAttr ( row , col ) 1634redraw 1635return screenattr ( a: row , a: col ) 1636endfunc 1637 1638func Test_charwise_visual_hl_inclusive_and_exclusive_selection () 1639new 1640call setline ( 1 , '12345' ) 1641 1642normal ! V$ 1643const visual_attr = s: ScreenAttr ( 1 , 1 ) 1644let VisualCols = { ->range ( 1 , strlen ( getline ( 1 ))) ->filter ({ _ , c -> 1645 \s: ScreenAttr ( 1 , c ) == visual_attr })} 1646 1647exe "normal! \<Esc>" 1648call assert_true ( visual_attr != s: ScreenAttr ( 1 , 1 ), 1649 \"sanity check: Visual displayed differently to Normal" ) 1650 1651set selection = inclusive 1652normal ! ggf2vf4 1653call assert_equal ([ 2 , 3 , 4 ], VisualCols ()) 1654 1655set selection = exclusive 1656exe "normal! \<Esc>ggf2vll" 1657call assert_equal ([ 2 , 3 ], VisualCols ()) " (Character under cursor excluded.) 1658normal ! o 1659call assert_equal ( 2 , col ( '.' ), "sanity check: cursor column after 'o'" ) 1660call assert_equal ([ 2 , 3 ], VisualCols ()) 1661normal ! y 1662call assert_equal ( '23' , @", 1663 \"sanity check: yanked text matches visual selection" ) 1664 1665set selection & 1666bwipe ! 1667endfunc 1668 1669" Test Visual highlight with cursor at end of screen line and 'showbreak' 1670func Test_visual_hl_with_showbreak () 1671CheckScreendump 1672 1673let lines =<< trim END 1674setlocal showbreak=+ 1675call setline(1, repeat('a', &columns + 10)) 1676normal g$v4lo 1677END 1678call writefile ( lines , 'XTest_visual_sbr' , 'D' ) 1679 1680let buf = RunVimInTerminal ( '-S XTest_visual_sbr' , { 'rows' : 6 , 'cols' : 50 }) 1681call VerifyScreenDump ( buf , 'Test_visual_hl_with_showbreak' , {}) 1682 1683" clean up 1684call term_sendkeys ( buf , "\<Esc>" ) 1685call StopVimInTerminal ( buf ) 1686endfunc 1687 1688func Test_Visual_r_CTRL_C () 1689new 1690" visual r_cmd 1691call setline ( 1 , [ ' ' ]) 1692call feedkeys ( "\<c-v>$r\<c-c>" , 'tx' ) 1693call assert_equal ([ '' ], getline ( 1 , 1 )) 1694 1695" visual gr_cmd 1696call setline ( 1 , [ ' ' ]) 1697call feedkeys ( "\<c-v>$gr\<c-c>" , 'tx' ) 1698call assert_equal ([ '' ], getline ( 1 , 1 )) 1699bw ! 1700endfunc 1701 1702func Test_visual_drag_out_of_window () 1703rightbelow vnew 1704call setline ( 1 , '123456789' ) 1705set mouse = a 1706func ClickExpr ( off ) 1707call Ntest_setmouse ( 1 , getwininfo ( win_getid ())[ 0 ]. wincol + a: off ) 1708return "\<LeftMouse>" 1709endfunc 1710func DragExpr ( off ) 1711call Ntest_setmouse ( 1 , getwininfo ( win_getid ())[ 0 ]. wincol + a: off ) 1712return "\<LeftDrag>" 1713endfunc 1714 1715nnoremap <expr> < F2 > ClickExpr ( 5 ) 1716nnoremap <expr> < F3 > DragExpr ( -1 ) 1717redraw 1718call feedkeys ( "\<F2>\<F3>\<LeftRelease>" , 'tx' ) 1719call assert_equal ([ 1 , 6 ], [ col ( '.' ), col ( 'v' )]) 1720call feedkeys ( "\<Esc>" , 'tx' ) 1721 1722nnoremap <expr> < F2 > ClickExpr ( 6 ) 1723nnoremap <expr> < F3 > DragExpr ( -2 ) 1724redraw 1725call feedkeys ( "\<F2>\<F3>\<LeftRelease>" , 'tx' ) 1726call assert_equal ([ 1 , 7 ], [ col ( '.' ), col ( 'v' )]) 1727call feedkeys ( "\<Esc>" , 'tx' ) 1728 1729nunmap <F2> 1730nunmap <F3> 1731delfunc ClickExpr 1732delfunc DragExpr 1733set mouse & 1734bwipe ! 1735endfunc 1736 1737func Test_visual_substitute_visual () 1738new 1739call setline ( 1 , [ 'one' , 'two' , 'three' ]) 1740call feedkeys ( "Gk\<C-V>j$:s/\\%V\\_.*\\%V/foobar\<CR>" , 'tx' ) 1741call assert_equal ([ 'one' , 'foobar' ], getline ( 1 , '$' )) 1742bwipe ! 1743endfunc 1744 1745func Test_virtualedit_exclusive_selection () 1746new 1747set virtualedit = allselection = exclusive 1748 1749call setline ( 1 , "a\tb" ) 1750normal ! 0v8ly 1751call assert_equal ( "a\t" , getreg ( '"' )) 1752normal ! 0v6ly 1753call assert_equal ( 'a ' , getreg ( '"' )) 1754normal ! 06lv2ly 1755call assert_equal ( ' ' , getreg ( '"' )) 1756 1757set virtualedit & selection & 1758bwipe ! 1759endfunc 1760 1761func Test_visual_getregion () 1762let lines =<< trim END 1763new 1764 1765call setline(1, ['one', 'two', 'three']) 1766 1767#" Visual mode 1768call cursor(1, 1) 1769call feedkeys("\<ESC>vjl", 'tx') 1770 1771call assert_equal(['one', 'tw'], 1772\ 'v'->getpos()->getregion(getpos('.'))) 1773call assert_equal([ 1774\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1775\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]] 1776\ ], 1777\ 'v'->getpos()->getregionpos(getpos('.'))) 1778 1779call assert_equal(['one', 'tw'], 1780\ '.'->getpos()->getregion(getpos('v'))) 1781call assert_equal([ 1782\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1783\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]] 1784\ ], 1785\ '.'->getpos()->getregionpos(getpos('v'))) 1786 1787call assert_equal(['o'], 1788\ 'v'->getpos()->getregion(getpos('v'))) 1789call assert_equal([ 1790\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], 1791\ ], 1792\ 'v'->getpos()->getregionpos(getpos('v'))) 1793 1794call assert_equal(['w'], 1795\ '.'->getpos()->getregion(getpos('.'), {'type': 'v' })) 1796call assert_equal([ 1797\ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 0]], 1798\ ], 1799\ '.'->getpos()->getregionpos(getpos('.'), {'type': 'v' })) 1800 1801call assert_equal(['one', 'two'], 1802\ getpos('.')->getregion(getpos('v'), {'type': 'V' })) 1803call assert_equal([ 1804\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1805\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1806\ ], 1807\ getpos('.')->getregionpos(getpos('v'), {'type': 'V' })) 1808 1809call assert_equal(['on', 'tw'], 1810\ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" })) 1811call assert_equal([ 1812\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], 1813\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]], 1814\ ], 1815\ getpos('.')->getregionpos(getpos('v'), {'type': "\<C-v>" })) 1816 1817#" Line visual mode 1818call cursor(1, 1) 1819call feedkeys("\<ESC>Vl", 'tx') 1820call assert_equal(['one'], 1821\ getregion(getpos('v'), getpos('.'), {'type': 'V' })) 1822call assert_equal(['one'], 1823\ getregion(getpos('.'), getpos('v'), {'type': 'V' })) 1824call assert_equal(['one'], 1825\ getregion(getpos('v'), getpos('v'), {'type': 'V' })) 1826call assert_equal(['one'], 1827\ getregion(getpos('.'), getpos('.'), {'type': 'V' })) 1828call assert_equal(['on'], 1829\ getpos('.')->getregion(getpos('v'), {'type': 'v' })) 1830call assert_equal(['on'], 1831\ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" })) 1832 1833#" Block visual mode 1834call cursor(1, 1) 1835call feedkeys("\<ESC>\<C-v>ll", 'tx') 1836call assert_equal(['one'], 1837\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1838call assert_equal(['one'], 1839\ getregion(getpos('.'), getpos('v'), {'type': "\<C-v>" })) 1840call assert_equal(['o'], 1841\ getregion(getpos('v'), getpos('v'), {'type': "\<C-v>" })) 1842call assert_equal(['e'], 1843\ getregion(getpos('.'), getpos('.'), {'type': "\<C-v>" })) 1844call assert_equal(['one'], 1845\ '.'->getpos()->getregion(getpos('v'), {'type': 'V' })) 1846call assert_equal(['one'], 1847\ '.'->getpos()->getregion(getpos('v'), {'type': 'v' })) 1848 1849#" Using Marks 1850call setpos("'a", [0, 2, 3, 0]) 1851call cursor(1, 1) 1852call assert_equal(['one', 'two'], 1853\ "'a"->getpos()->getregion(getpos('.'), {'type': 'v' })) 1854call assert_equal(['one', 'two'], 1855\ "."->getpos()->getregion(getpos("'a"), {'type': 'v' })) 1856call assert_equal(['one', 'two'], 1857\ "."->getpos()->getregion(getpos("'a"), {'type': 'V' })) 1858call assert_equal(['two'], 1859\ "'a"->getpos()->getregion(getpos("'a"), {'type': 'V' })) 1860call assert_equal(['one', 'two'], 1861\ "."->getpos()->getregion(getpos("'a"), {'type': "\<c-v>" })) 1862call feedkeys("\<ESC>jVj\<ESC>", 'tx') 1863call assert_equal(['two', 'three'], getregion(getpos("'<"), getpos("'>"))) 1864call assert_equal(['two', 'three'], getregion(getpos("'>"), getpos("'<"))) 1865 1866#" Using List 1867call cursor(1, 1) 1868call assert_equal(['one', 'two'], 1869\ [0, 2, 3, 0]->getregion(getpos('.'), {'type': 'v' })) 1870call assert_equal(['one', 'two'], 1871\ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'v' })) 1872call assert_equal(['one', 'two'], 1873\ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'V' })) 1874call assert_equal(['two'], 1875\ [0, 2, 3, 0]->getregion([0, 2, 3, 0], {'type': 'V' })) 1876call assert_equal(['one', 'two'], 1877\ '.'->getpos()->getregion([0, 2, 3, 0], {'type': "\<c-v>" })) 1878 1879#" Multiline with line visual mode 1880call cursor(1, 1) 1881call feedkeys("\<ESC>Vjj", 'tx') 1882call assert_equal(['one', 'two', 'three'], 1883\ getregion(getpos('v'), getpos('.'), {'type': 'V' })) 1884call assert_equal([ 1885\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1886\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1887\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 1888\ ], 1889\ getregionpos(getpos('v'), getpos('.'), {'type': 'V' })) 1890call assert_equal([ 1891\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], 1892\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], 1893\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 0]], 1894\ ], 1895\ getregionpos(getpos('v'), getpos('.'), 1896\ {'type': 'V', 'eol': v:true })) 1897 1898#" Multiline with block visual mode 1899call cursor(1, 1) 1900call feedkeys("\<ESC>\<C-v>jj", 'tx') 1901call assert_equal(['o', 't', 't'], 1902\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1903call assert_equal([ 1904\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], 1905\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], 1906\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 1, 0]], 1907\ ], 1908\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1909 1910call cursor(1, 1) 1911call feedkeys("\<ESC>\<C-v>jj$", 'tx') 1912call assert_equal(['one', 'two', 'three'], 1913\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1914call assert_equal([ 1915\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1916\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1917\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 1918\ ], 1919\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1920call assert_equal([ 1921\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1922\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1923\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 1924\ ], 1925\ getregionpos(getpos('v'), getpos('.'), 1926\ {'type': "\<C-v>", 'eol': v:true })) 1927 1928#" 'virtualedit' 1929set virtualedit=all 1930 1931call cursor(1, 1) 1932call feedkeys("\<ESC>\<C-v>10ljj$", 'tx') 1933call assert_equal(['one ', 'two ', 'three '], 1934\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1935call assert_equal([ 1936\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 1937\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1938\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 1939\ ], 1940\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1941call assert_equal([ 1942\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 3]], 1943\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 3]], 1944\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 1]], 1945\ ], 1946\ getregionpos(getpos('v'), getpos('.'), 1947\ {'type': "\<C-v>", 'eol': v:true })) 1948 1949call cursor(3, 5) 1950call feedkeys("\<ESC>\<C-v>hkk", 'tx') 1951call assert_equal([' ', ' ', 'ee'], 1952\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1953call assert_equal([ 1954\ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], 1955\ [[bufnr('%'), 2, 0, 0], [bufnr('%'), 2, 0, 0]], 1956\ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], 1957\ ], 1958\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1959call assert_equal([ 1960\ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 4, 2]], 1961\ [[bufnr('%'), 2, 4, 0], [bufnr('%'), 2, 4, 2]], 1962\ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], 1963\ ], 1964\ getregionpos(getpos('v'), getpos('.'), 1965\ {'type': "\<C-v>", 'eol': v:true })) 1966 1967call cursor(3, 5) 1968call feedkeys("\<ESC>\<C-v>kk", 'tx') 1969call assert_equal([' ', ' ', 'e'], 1970\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1971call assert_equal([ 1972\ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], 1973\ [[bufnr('%'), 2, 0, 0], [bufnr('%'), 2, 0, 0]], 1974\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], 1975\ ], 1976\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 1977call assert_equal([ 1978\ [[bufnr('%'), 1, 4, 1], [bufnr('%'), 1, 4, 2]], 1979\ [[bufnr('%'), 2, 4, 1], [bufnr('%'), 2, 4, 2]], 1980\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], 1981\ ], 1982\ getregionpos(getpos('v'), getpos('.'), 1983\ {'type': "\<C-v>", 'eol': v:true })) 1984 1985call cursor(1, 3) 1986call feedkeys("\<ESC>vjj4l", 'tx') 1987call assert_equal(['e', 'two', 'three '], 1988\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 1989call assert_equal([ 1990\ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 3, 0]], 1991\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 1992\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 1993\ ], 1994\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 1995call assert_equal([ 1996\ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 4, 0]], 1997\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], 1998\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 2]], 1999\ ], 2000\ getregionpos(getpos('v'), getpos('.'), 2001\ {'type': 'v', 'eol': v:true })) 2002 2003call cursor(1, 3) 2004call feedkeys("\<ESC>lvjj3l", 'tx') 2005call assert_equal(['', 'two', 'three '], 2006\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2007call assert_equal([ 2008\ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], 2009\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 2010\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 2011\ ], 2012\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2013call assert_equal([ 2014\ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 4, 0]], 2015\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], 2016\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 2]], 2017\ ], 2018\ getregionpos(getpos('v'), getpos('.'), 2019\ {'type': 'v', 'eol': v:true })) 2020 2021call cursor(3, 5) 2022call feedkeys("\<ESC>v3l", 'tx') 2023call assert_equal(['e '], 2024\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2025call assert_equal([ 2026\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], 2027\ ], 2028\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2029call assert_equal([ 2030\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 6, 3]], 2031\ ], 2032\ getregionpos(getpos('v'), getpos('.'), 2033\ {'type': 'v', 'eol': v:true })) 2034 2035call cursor(3, 5) 2036call feedkeys("\<ESC>lv3l", 'tx') 2037call assert_equal([' '], 2038\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2039call assert_equal([ 2040\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2041\ ], 2042\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2043call assert_equal([ 2044\ [[bufnr('%'), 3, 6, 0], [bufnr('%'), 3, 6, 4]], 2045\ ], 2046\ getregionpos(getpos('v'), getpos('.'), 2047\ {'type': 'v', 'eol': v:true })) 2048 2049call cursor(3, 5) 2050call feedkeys("\<ESC>3lv3l", 'tx') 2051call assert_equal([' '], 2052\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2053call assert_equal([ 2054\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2055\ ], 2056\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2057call assert_equal([ 2058\ [[bufnr('%'), 3, 6, 2], [bufnr('%'), 3, 6, 6]], 2059\ ], 2060\ getregionpos(getpos('v'), getpos('.'), 2061\ {'type': 'v', 'eol': v:true })) 2062 2063set virtualedit& 2064 2065#" using wrong types for positions 2066call cursor(1, 1) 2067call feedkeys("\<ESC>vjj$", 'tx') 2068call assert_fails("call getregion(1, 2)", 'E1211:') 2069call assert_fails("call getregion(getpos('.'), {})", 'E1211:') 2070call assert_fails(':echo "."->getpos()->getregion("$", [])', 'E1211:') 2071call assert_fails("call getregionpos(1, 2)", 'E1211:') 2072call assert_fails("call getregionpos(getpos('.'), {})", 'E1211:') 2073call assert_fails(':echo "."->getpos()->getregionpos("$", [])', 'E1211:') 2074 2075#" using invalid value for "type" 2076call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '' })", 'E475:') 2077call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '' })", 'E475:') 2078call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': 'v0' })", 'E475:') 2079call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': 'v0' })", 'E475:') 2080call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': 'V0' })", 'E475:') 2081call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': 'V0' })", 'E475:') 2082call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '\<C-v>0' })", 'E475:') 2083call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '\<C-v>0' })", 'E475:') 2084call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '\<C-v>1:' })", 'E475:') 2085call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '\<C-v>1:' })", 'E475:') 2086 2087#" using a mark from another buffer to current buffer 2088new 2089LET g:buf = bufnr() 2090call setline(1, range(10)) 2091normal! GmA 2092wincmd p 2093call assert_equal([g:buf, 10, 1, 0], getpos("'A")) 2094call assert_equal([], getregion(getpos('.'), getpos("'A"), {'type': 'v' })) 2095call assert_equal([], getregion(getpos("'A"), getpos('.'), {'type': 'v' })) 2096call assert_equal([], getregionpos(getpos('.'), getpos("'A"), {'type': 'v' })) 2097call assert_equal([], getregionpos(getpos("'A"), getpos('.'), {'type': 'v' })) 2098 2099#" using two marks from another buffer 2100wincmd p 2101normal! GmB 2102wincmd p 2103call assert_equal([g:buf, 10, 1, 0], getpos("'B")) 2104call assert_equal(['9'], 2105\ getregion(getpos("'B"), getpos("'A"), {'type': 'v' })) 2106call assert_equal([ 2107\ [[g:buf, 10, 1, 0], [g:buf, 10, 1, 0]], 2108\ ], 2109\ getregionpos(getpos("'B"), getpos("'A"), {'type': 'v' })) 2110 2111#" using two positions from another buffer 2112for type in ['v', 'V', "\<C-V>"] 2113for exclusive in [v:false, v:true] 2114call assert_equal(range(10)->mapnew('string(v:val)'), 2115\ getregion([g:buf, 1, 1, 0], [g:buf, 10, 2, 0], 2116\ {'type': type, 'exclusive': exclusive })) 2117call assert_equal(range(10)->mapnew('string(v:val)'), 2118\ getregion([g:buf, 10, 2, 0], [g:buf, 1, 1, 0], 2119\ {'type': type, 'exclusive': exclusive })) 2120call assert_equal(range(1, 10)->mapnew('repeat([[g:buf, v:val, 1, 0]], 2)'), 2121\ getregionpos([g:buf, 1, 1, 0], [g:buf, 10, 2, 0], 2122\ {'type': type, 'exclusive': exclusive })) 2123call assert_equal(range(1, 10)->mapnew('repeat([[g:buf, v:val, 1, 0]], 2)'), 2124\ getregionpos([g:buf, 10, 2, 0], [g:buf, 1, 1, 0], 2125\ {'type': type, 'exclusive': exclusive })) 2126endfor 2127endfor 2128 2129#" using invalid positions in buffer 2130call assert_fails('call getregion([g:buf, 0, 1, 0], [g:buf, 10, 2, 0])', 'E966:') 2131call assert_fails('call getregion([g:buf, 10, 2, 0], [g:buf, 0, 1, 0])', 'E966:') 2132call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 11, 2, 0])', 'E966:') 2133call assert_fails('call getregion([g:buf, 11, 2, 0], [g:buf, 1, 1, 0])', 'E966:') 2134call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 0, 0])', 'E964:') 2135call assert_fails('call getregion([g:buf, 10, 0, 0], [g:buf, 1, 1, 0])', 'E964:') 2136call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 3, 0])', 'E964:') 2137call assert_fails('call getregion([g:buf, 10, 3, 0], [g:buf, 1, 1, 0])', 'E964:') 2138call assert_fails('call getregion([g:buf, 1, 0, 0], [g:buf, 1, 1, 0])', 'E964:') 2139call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 1, 0, 0])', 'E964:') 2140 2141#" using invalid buffer 2142call assert_fails('call getregion([10000, 10, 1, 0], [10000, 10, 1, 0])', 'E681:') 2143 2144exe $':{g:buf}bwipe!' 2145unlet g:buf 2146bwipe! 2147END 2148call CheckLegacyAndVim9Success ( lines ) 2149 2150let lines =<< trim END 2151#" Selection in starts or ends in the middle of a multibyte character 2152new 2153call setline(1, [ 2154\ "abcdefghijk\u00ab", 2155\ "\U0001f1e6\u00ab\U0001f1e7\u00ab\U0001f1e8\u00ab\U0001f1e9", 2156\ "1234567890" 2157\ ]) 2158 2159call cursor(1, 3) 2160call feedkeys("\<Esc>\<C-v>ljj", 'xt') 2161call assert_equal(['cd', "\u00ab ", '34'], 2162\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2163call assert_equal([ 2164\ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 4, 0]], 2165\ [[bufnr('%'), 2, 5, 0], [bufnr('%'), 2, 7, 1]], 2166\ [[bufnr('%'), 3, 3, 0], [bufnr('%'), 3, 4, 0]], 2167\ ], 2168\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2169 2170call cursor(1, 4) 2171call feedkeys("\<Esc>\<C-v>ljj", 'xt') 2172call assert_equal(['de', "\U0001f1e7", '45'], 2173\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2174call assert_equal([ 2175\ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 5, 0]], 2176\ [[bufnr('%'), 2, 7, 0], [bufnr('%'), 2, 10, 0]], 2177\ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], 2178\ ], 2179\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2180 2181call cursor(1, 5) 2182call feedkeys("\<Esc>\<C-v>jj", 'xt') 2183call assert_equal(['e', ' ', '5'], 2184\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2185call assert_equal([ 2186\ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 5, 0]], 2187\ [[bufnr('%'), 2, 7, 1], [bufnr('%'), 2, 7, 2]], 2188\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], 2189\ ], 2190\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2191call assert_equal(['efghijk«', '🇦«🇧«🇨«🇩', '12345'], 2192\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2193call assert_equal([ 2194\ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 13, 0]], 2195\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 22, 0]], 2196\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], 2197\ ], 2198\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2199 2200call cursor(1, 5) 2201call feedkeys("\<Esc>\<C-v>5l2j", 'xt') 2202call assert_equal(['efghij', ' «🇨« ', '567890'], 2203\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2204call assert_equal([ 2205\ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 10, 0]], 2206\ [[bufnr('%'), 2, 7, 1], [bufnr('%'), 2, 19, 1]], 2207\ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 10, 0]], 2208\ ], 2209\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2210 2211call cursor(1, 4) 2212call feedkeys("\<Esc>\<C-v>02j", 'xt') 2213call assert_equal(['abcd', '🇦« ', '1234'], 2214\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2215call assert_equal([ 2216\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], 2217\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 7, 1]], 2218\ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 4, 0]], 2219\ ], 2220\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2221 2222#" characterwise selection with multibyte chars 2223call cursor(1, 1) 2224call feedkeys("\<Esc>vj", 'xt') 2225call assert_equal(['abcdefghijk«', "\U0001f1e6"], 2226\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2227call assert_equal([ 2228\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 13, 0]], 2229\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], 2230\ ], 2231\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2232 2233set selection=exclusive 2234call feedkeys('l', 'xt') 2235call assert_equal(['abcdefghijk«', "\U0001f1e6"], 2236\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2237call assert_equal([ 2238\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 13, 0]], 2239\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], 2240\ ], 2241\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2242 2243#" marks on multibyte chars 2244call setpos("'a", [0, 1, 11, 0]) 2245call setpos("'b", [0, 2, 16, 0]) 2246call setpos("'c", [0, 2, 0, 0]) 2247call cursor(1, 1) 2248 2249call assert_equal(['ghijk', '🇨«🇩'], 2250\ getregion(getpos("'a"), getpos("'b"), {'type': "\<C-v>" })) 2251call assert_equal([ 2252\ [[bufnr('%'), 1, 7, 0], [bufnr('%'), 1, 11, 0]], 2253\ [[bufnr('%'), 2, 13, 0], [bufnr('%'), 2, 22, 0]], 2254\ ], 2255\ getregionpos(getpos("'a"), getpos("'b"), {'type': "\<C-v>" })) 2256 2257call assert_equal(['k«', '🇦«🇧«🇨'], 2258\ getregion(getpos("'a"), getpos("'b"), {'type': 'v' })) 2259call assert_equal([ 2260\ [[bufnr('%'), 1, 11, 0], [bufnr('%'), 1, 13, 0]], 2261\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 16, 0]], 2262\ ], 2263\ getregionpos(getpos("'a"), getpos("'b"), {'type': 'v' })) 2264 2265call assert_equal(['k«'], 2266\ getregion(getpos("'a"), getpos("'c"), {'type': 'v' })) 2267call assert_equal([ 2268\ [[bufnr('%'), 1, 11, 0], [bufnr('%'), 1, 13, 0]], 2269\ ], 2270\ getregionpos(getpos("'a"), getpos("'c"), {'type': 'v' })) 2271 2272#" use inclusive selection, although 'selection' is exclusive 2273call setpos("'a", [0, 1, 11, 0]) 2274call setpos("'b", [0, 1, 1, 0]) 2275call assert_equal(['abcdefghijk'], 2276\ getregion(getpos("'a"), getpos("'b"), 2277\ {'type': "\<c-v>", 'exclusive': v:false })) 2278call assert_equal(['abcdefghij'], 2279\ getregion(getpos("'a"), getpos("'b"), 2280\ {'type': "\<c-v>", 'exclusive': v:true })) 2281call assert_equal(['abcdefghijk'], 2282\ getregion(getpos("'a"), getpos("'b"), 2283\ {'type': 'v', 'exclusive': 0 })) 2284call assert_equal(['abcdefghij'], 2285\ getregion(getpos("'a"), getpos("'b"), 2286\ {'type': 'v', 'exclusive': 1 })) 2287call assert_equal(['abcdefghijk«'], 2288\ getregion(getpos("'a"), getpos("'b"), 2289\ {'type': 'V', 'exclusive': 0 })) 2290call assert_equal(['abcdefghijk«'], 2291\ getregion(getpos("'a"), getpos("'b"), 2292\ {'type': 'V', 'exclusive': 1 })) 2293 2294set selection& 2295bwipe! 2296END 2297call CheckLegacyAndVim9Success ( lines ) 2298 2299let lines =<< trim END 2300#" Exclusive selection 2301new 2302set selection=exclusive 2303call setline(1, ["a\tc", "x\tz", '', '']) 2304call cursor(1, 1) 2305call feedkeys("\<Esc>v2l", 'xt') 2306call assert_equal(["a\t"], 2307\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2308call cursor(1, 1) 2309call feedkeys("\<Esc>v$G", 'xt') 2310call assert_equal(["a\tc", "x\tz", ''], 2311\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2312call cursor(1, 1) 2313call feedkeys("\<Esc>v$j", 'xt') 2314call assert_equal(["a\tc", "x\tz"], 2315\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2316call cursor(1, 1) 2317call feedkeys("\<Esc>\<C-v>$j", 'xt') 2318call assert_equal(["a\tc", "x\tz"], 2319\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2320call cursor(1, 1) 2321call feedkeys("\<Esc>\<C-v>$G", 'xt') 2322call assert_equal(["a", "x", '', ''], 2323\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2324call cursor(1, 1) 2325call feedkeys("\<Esc>wv2j", 'xt') 2326call assert_equal(["c", "x\tz"], 2327\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2328set selection& 2329bwipe! 2330 2331#" Exclusive selection 2 2332new 2333call setline(1, ["a\tc", "x\tz", '', '']) 2334 2335call cursor(1, 1) 2336call feedkeys("\<Esc>v2l", 'xt') 2337call assert_equal(["a\t"], 2338\ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) 2339call assert_equal([ 2340\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], 2341\ ], 2342\ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) 2343 2344call cursor(1, 1) 2345call feedkeys("\<Esc>v$G", 'xt') 2346call assert_equal(["a\tc", "x\tz", ''], 2347\ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) 2348call assert_equal([ 2349\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2350\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 2351\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2352\ ], 2353\ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) 2354 2355call cursor(1, 1) 2356call feedkeys("\<Esc>v$j", 'xt') 2357call assert_equal(["a\tc", "x\tz"], 2358\ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) 2359call assert_equal([ 2360\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2361\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 2362\ ], 2363\ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) 2364 2365call cursor(1, 1) 2366call feedkeys("\<Esc>\<C-v>$j", 'xt') 2367call assert_equal(["a\tc", "x\tz"], 2368\ getregion(getpos('v'), getpos('.'), 2369\ {'exclusive': v:true, 'type': "\<C-v>" })) 2370call assert_equal([ 2371\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2372\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 2373\ ], 2374\ getregionpos(getpos('v'), getpos('.'), 2375\ {'exclusive': v:true, 'type': "\<C-v>" })) 2376 2377call cursor(1, 1) 2378call feedkeys("\<Esc>\<C-v>$G", 'xt') 2379call assert_equal(["a", "x", '', ''], 2380\ getregion(getpos('v'), getpos('.'), 2381\ {'exclusive': v:true, 'type': "\<C-v>" })) 2382call assert_equal([ 2383\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], 2384\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], 2385\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2386\ [[bufnr('%'), 4, 0, 0], [bufnr('%'), 4, 0, 0]], 2387\ ], 2388\ getregionpos(getpos('v'), getpos('.'), 2389\ {'exclusive': v:true, 'type': "\<C-v>" })) 2390 2391call cursor(1, 1) 2392call feedkeys("\<Esc>wv2j", 'xt') 2393call assert_equal(["c", "x\tz"], 2394\ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) 2395call assert_equal([ 2396\ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 3, 0]], 2397\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], 2398\ ], 2399\ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) 2400 2401#" 'virtualedit' with exclusive selection 2402set selection=exclusive 2403set virtualedit=all 2404 2405call cursor(1, 1) 2406call feedkeys("\<Esc>vj", 'xt') 2407call assert_equal(["a\tc"], 2408\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2409call assert_equal([ 2410\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2411\ ], 2412\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2413 2414call cursor(1, 1) 2415call feedkeys("\<Esc>v8l", 'xt') 2416call assert_equal(["a\t"], 2417\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2418call assert_equal([ 2419\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], 2420\ ], 2421\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2422 2423call cursor(1, 1) 2424call feedkeys("\<Esc>v6l", 'xt') 2425call assert_equal(['a '], 2426\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2427call assert_equal([ 2428\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 5]], 2429\ ], 2430\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2431 2432call cursor(1, 1) 2433call feedkeys("\<Esc>6lv2l", 'xt') 2434call assert_equal([' '], 2435\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2436call assert_equal([ 2437\ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 2, 0]], 2438\ ], 2439\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2440 2441call cursor(1, 1) 2442call feedkeys("\<Esc>lv2l", 'xt') 2443call assert_equal([' '], 2444\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2445call assert_equal([ 2446\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], 2447\ ], 2448\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2449 2450call cursor(1, 1) 2451call feedkeys("\<Esc>2lv2l", 'xt') 2452call assert_equal([' '], 2453\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2454call assert_equal([ 2455\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], 2456\ ], 2457\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2458 2459call feedkeys('j', 'xt') 2460call assert_equal([' c', 'x '], 2461\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2462call assert_equal([ 2463\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 3, 0]], 2464\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 3]], 2465\ ], 2466\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2467 2468call cursor(1, 1) 2469call feedkeys("\<Esc>6l\<C-v>2lj", 'xt') 2470call assert_equal([' ', ' '], 2471\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2472call assert_equal([ 2473\ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 2, 7]], 2474\ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 2, 7]], 2475\ ], 2476\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2477 2478call cursor(1, 1) 2479call feedkeys("\<Esc>l\<C-v>2l2j", 'xt') 2480call assert_equal([' ', ' ', ' '], 2481\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2482call assert_equal([ 2483\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], 2484\ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 2]], 2485\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2486\ ], 2487\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2488call assert_equal([ 2489\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], 2490\ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 2]], 2491\ [[bufnr('%'), 3, 1, 1], [bufnr('%'), 3, 1, 3]], 2492\ ], 2493\ getregionpos(getpos('v'), getpos('.'), 2494\ {'type': "\<C-v>", "eol": v:true })) 2495 2496call cursor(1, 1) 2497call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt') 2498call assert_equal([' ', ' ', ' '], 2499\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2500call assert_equal([ 2501\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], 2502\ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 3]], 2503\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2504\ ], 2505\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2506call assert_equal([ 2507\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], 2508\ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 3]], 2509\ [[bufnr('%'), 3, 1, 2], [bufnr('%'), 3, 1, 4]], 2510\ ], 2511\ getregionpos(getpos('v'), getpos('.'), 2512\ {'type': "\<C-v>", "eol": v:true })) 2513 2514#" 'virtualedit' with inclusive selection 2515set selection& 2516 2517call cursor(1, 1) 2518call feedkeys("\<Esc>vj", 'xt') 2519call assert_equal(["a\tc", 'x'], 2520\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2521call assert_equal([ 2522\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2523\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], 2524\ ], 2525\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2526 2527call cursor(1, 1) 2528call feedkeys("\<Esc>v8l", 'xt') 2529call assert_equal(["a\tc"], 2530\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2531call assert_equal([ 2532\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], 2533\ ], 2534\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2535 2536call cursor(1, 1) 2537call feedkeys("\<Esc>v6l", 'xt') 2538call assert_equal(['a '], 2539\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2540call assert_equal([ 2541\ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 6]], 2542\ ], 2543\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2544 2545call cursor(1, 1) 2546call feedkeys("\<Esc>6lv2l", 'xt') 2547call assert_equal([' c'], 2548\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2549call assert_equal([ 2550\ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 3, 0]], 2551\ ], 2552\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2553 2554call cursor(1, 1) 2555call feedkeys("\<Esc>lv2l", 'xt') 2556call assert_equal([' '], 2557\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2558call assert_equal([ 2559\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], 2560\ ], 2561\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2562 2563call cursor(1, 1) 2564call feedkeys("\<Esc>2lv2l", 'xt') 2565call assert_equal([' '], 2566\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2567call assert_equal([ 2568\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], 2569\ ], 2570\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2571 2572call feedkeys('j', 'xt') 2573call assert_equal([' c', 'x '], 2574\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2575call assert_equal([ 2576\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 3, 0]], 2577\ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 4]], 2578\ ], 2579\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2580 2581call cursor(1, 1) 2582call feedkeys("\<Esc>6l\<C-v>2lj", 'xt') 2583call assert_equal([' c', ' z'], 2584\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2585call assert_equal([ 2586\ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 3, 0]], 2587\ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 3, 0]], 2588\ ], 2589\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2590 2591call cursor(1, 1) 2592call feedkeys("\<Esc>l\<C-v>2l2j", 'xt') 2593call assert_equal([' ', ' ', ' '], 2594\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2595call assert_equal([ 2596\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], 2597\ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 3]], 2598\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2599\ ], 2600\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2601call assert_equal([ 2602\ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], 2603\ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 3]], 2604\ [[bufnr('%'), 3, 1, 1], [bufnr('%'), 3, 1, 4]], 2605\ ], 2606\ getregionpos(getpos('v'), getpos('.'), 2607\ {'type': "\<C-v>", "eol": v:true })) 2608 2609call cursor(1, 1) 2610call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt') 2611call assert_equal([' ', ' ', ' '], 2612\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2613call assert_equal([ 2614\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], 2615\ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 4]], 2616\ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], 2617\ ], 2618\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2619call assert_equal([ 2620\ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], 2621\ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 4]], 2622\ [[bufnr('%'), 3, 1, 2], [bufnr('%'), 3, 1, 5]], 2623\ ], 2624\ getregionpos(getpos('v'), getpos('.'), 2625\ {'type': "\<C-v>", "eol": v:true })) 2626 2627set virtualedit& 2628bwipe! 2629END 2630call CheckLegacyAndVim9Success ( lines ) 2631 2632let lines =<< trim END 2633#" 'virtualedit' with TABs at end of line 2634new 2635set virtualedit=all 2636call setline(1, ["\t", "a\t", "aa\t"]) 2637 2638call feedkeys("gg06l\<C-v>3l2j", 'xt') 2639call assert_equal([' ', ' ', ' '], 2640\ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2641call assert_equal([ 2642\ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 1, 0]], 2643\ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 2, 0]], 2644\ [[bufnr('%'), 3, 3, 4], [bufnr('%'), 3, 3, 0]], 2645\ ], 2646\ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) 2647call assert_equal([ 2648\ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 2, 2]], 2649\ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 3, 2]], 2650\ [[bufnr('%'), 3, 3, 4], [bufnr('%'), 3, 4, 2]], 2651\ ], 2652\ getregionpos(getpos('v'), getpos('.'), 2653\ {'type': "\<C-v>", "eol": v:true })) 2654 2655call feedkeys("gg06lv3l", 'xt') 2656call assert_equal([' '], 2657\ getregion(getpos('v'), getpos('.'), {'type': 'v' })) 2658call assert_equal([ 2659\ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 1, 0]], 2660\ ], 2661\ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) 2662call assert_equal([ 2663\ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 2, 2]], 2664\ ], 2665\ getregionpos(getpos('v'), getpos('.'), 2666\ {'type': 'v', "eol": v:true })) 2667 2668set virtualedit& 2669bwipe! 2670END 2671call CheckLegacyAndVim9Success ( lines ) 2672endfunc 2673 2674" Test the "bounds" option of getregionpos(), which returns only the outer 2675" endpoints of the region as a single pair. 2676func Test_visual_getregionpos_bounds () 2677new 2678call setline ( 1 , [ 2679 \'one two' , 2680 \'' , 2681 \"a\tb\tc" , 2682 \'ábĉdé' , 2683 \"e\u0301x\u0301" , 2684 \"\U0001f1e6\u00ab\U0001f1e7\u00ab\U0001f1e8" , 2685 \'last line' , 2686 \]) 2687let b = bufnr ( '%' ) 2688 2689" The pair is the start on the first line and the end on the last line. 2690call assert_equal ([[[ b , 1 , 5 , 0 ], [ b , 3 , 3 , 0 ]]], 2691 \getregionpos ([ 0 , 1 , 5 , 0 ], [ 0 , 3 , 3 , 0 ], #{ bounds : v: true })) 2692call assert_equal ([[[ b , 1 , 1 , 0 ], [ b , 3 , 5 , 0 ]]], 2693 \getregionpos ([ 0 , 1 , 5 , 0 ], [ 0 , 3 , 3 , 0 ], 2694 \#{ type : 'V' , bounds : v: true })) 2695 2696" For a blockwise region that is a diagonal of the block, not its corners. 2697call assert_equal ([[[ b , 1 , 3 , 0 ], [ b , 3 , 5 , 0 ]]], 2698 \getregionpos ([ 0 , 1 , 3 , 0 ], [ 0 , 3 , 5 , 0 ], 2699 \#{ type : "\<C-v>" , bounds : v: true })) 2700call assert_equal ([[[ b , 1 , 3 , 0 ], [ b , 3 , 2 , 5 ]]], 2701 \getregionpos ([ 0 , 1 , 3 , 0 ], [ 0 , 3 , 5 , 0 ], 2702 \#{ type : "\<C-v>4" , bounds : v: true })) 2703 2704" When the first line is empty and "eol" is false its "col" is 0, while the 2705" "col" of the end position is not. 2706call assert_equal ([[[ b , 2 , 0 , 0 ], [ b , 4 , 5 , 0 ]]], 2707 \getregionpos ([ 0 , 2 , 1 , 0 ], [ 0 , 4 , 5 , 0 ], #{ bounds : v: true })) 2708call assert_equal ([[[ b , 2 , 1 , 0 ], [ b , 4 , 5 , 0 ]]], 2709 \getregionpos ([ 0 , 2 , 1 , 0 ], [ 0 , 4 , 5 , 0 ], 2710 \#{ eol : v: true , bounds : v: true })) 2711 2712" Region within one line, also with the positions reversed. 2713call assert_equal ([[[ b , 4 , 3 , 0 ], [ b , 4 , 8 , 0 ]]], 2714 \getregionpos ([ 0 , 4 , 3 , 0 ], [ 0 , 4 , 7 , 0 ], #{ bounds : v: true })) 2715call assert_equal ([[[ b , 4 , 3 , 0 ], [ b , 4 , 8 , 0 ]]], 2716 \getregionpos ([ 0 , 4 , 7 , 0 ], [ 0 , 4 , 3 , 0 ], #{ bounds : v: true })) 2717 2718" Combining characters and v:maxcol. 2719call assert_equal ([[[ b , 5 , 1 , 0 ], [ b , 6 , 16 , 0 ]]], 2720 \getregionpos ([ 0 , 5 , 1 , 0 ], [ 0 , 6 , v: maxcol , 0 ], #{ bounds : v: true })) 2721 2722" The pair is always what indexing the full result gives. 2723for ve in [ '' , 'all' , 'block' , 'onemore' ] 2724let & virtualedit = ve 2725for sel in [ 'inclusive' , 'exclusive' ] 2726let & selection = sel 2727for type in [ 'v' , 'V' , "\<C-v>" , "\<C-v>3" ] 2728for excl in [#{}, #{ exclusive : v: false }, #{ exclusive : v: true }] 2729for eol in [ v: false , v: true ] 2730let opts = extend (#{ type : type , eol : eol }, excl ) 2731for p1 in [[ 0 , 1 , 3 , 0 ], [ 0 , 2 , 1 , 0 ], [ 0 , 3 , 4 , 0 ], [ 0 , 5 , 1 , 0 ]] 2732for p2 in [[ 0 , 3 , 2 , 0 ], [ 0 , 4 , 6 , 0 ], 2733 \[ 0 , 6 , v: maxcol , 0 ], [ 0 , 7 , 10 , 0 ]] 2734for args in [[ p1 , p2 ], [ p2 , p1 ]] 2735let full = getregionpos ( args [ 0 ], args [ 1 ], opts ) 2736call assert_equal ([[ full [ 0 ][ 0 ], full [ -1 ][ 1 ]]], 2737 \getregionpos ( args [ 0 ], args [ 1 ], 2738 \extend ( copy ( opts ), #{ bounds : v: true })), 2739 \printf ( '%s ve=%s sel=%s %s' , 2740 \string ( args ), ve , sel , string ( opts ))) 2741endfor 2742endfor 2743endfor 2744endfor 2745endfor 2746endfor 2747endfor 2748endfor 2749set virtualedit & selection & 2750 2751" "bounds" does not change the errors for invalid arguments. 2752call assert_fails ( 'call getregionpos(1, 2, #{bounds: v:true})' , 'E1211:' ) 2753call assert_fails ( 'call getregionpos([0, 1, 1, 0], [0, 1, 1, 0], 2754\ #{type: "", bounds: v:true})' , 'E475:' ) 2755call assert_fails ( 'call getregionpos([0, 0, 1, 0], [0, 1, 1, 0], 2756\ #{bounds: v:true})' , 'E966:' ) 2757call assert_fails ( 'call getregionpos([0, 1, 0, 0], [0, 1, 1, 0], 2758\ #{bounds: v:true})' , 'E964:' ) 2759 2760" Positions in two different buffers still give an empty list, not a pair. 2761new 2762call setline ( 1 , [ 'other buffer' ]) 2763let other = bufnr ( '%' ) 2764normal ! mA 2765wincmd p 2766call assert_equal ([], 2767 \getregionpos ( getpos ( '.' ), getpos ( "'A" ), #{ bounds : v: true })) 2768call assert_equal ([], 2769 \getregionpos ( getpos ( "'A" ), getpos ( '.' ), #{ bounds : v: true })) 2770 2771exe other .. 'bwipe!' 2772bwipe ! 2773endfunc 2774 2775func Test_getregion_invalid_buf () 2776new 2777help index 2778call cursor ( 7 , 6 ) 2779norm ! mA 2780call cursor ( 7 , 18 ) 2781norm ! mB 2782call assert_equal ([ 'file contains' ], getregion ( getpos ( "'A" ), getpos ( "'B" ))) 2783" close the help window 2784q 2785call assert_fails ( "call getregion(getpos(\"'A\"), getpos(\"'B\"))" , 'E681:' ) 2786bwipe ! 2787endfunc 2788 2789func Test_getregion_after_yank () 2790func ! Check_Results ( type ) 2791call assert_equal ( g: expected_region , 2792 \getregion ( getpos ( "'[" ), getpos ( "']" ), #{ type : a: type })) 2793call assert_equal ( g: expected_regionpos , 2794 \getregionpos ( getpos ( "'[" ), getpos ( "']" ), #{ type : a: type })) 2795call assert_equal ( g: expected_region , 2796 \getregion ( getpos ( "']" ), getpos ( "'[" ), #{ type : a: type })) 2797call assert_equal ( g: expected_regionpos , 2798 \getregionpos ( getpos ( "']" ), getpos ( "'[" ), #{ type : a: type })) 2799let g: checked = 1 2800endfunc 2801 2802autocmd TextYankPost * 2803 \: if v: event . operator ==? 'y' 2804 \ |call Check_Results ( v: event . regtype ) 2805 \ |endif 2806 2807new 2808call setline ( 1 , [ 'abcd' , 'efghijk' , 'lmn' ]) 2809 2810let g: expected_region = [ 'abcd' ] 2811let g: expected_regionpos = [ 2812 \[[ bufnr ( '%' ), 1 , 1 , 0 ], [ bufnr ( '%' ), 1 , 4 , 0 ]], 2813 \] 2814let g: checked = 0 2815normal yy 2816call assert_equal ( 1 , g: checked ) 2817call Check_Results ( getregtype ( '"' )) 2818 2819let g: expected_region = [ 'cd' , 'ghijk' , 'n' ] 2820let g: expected_regionpos = [ 2821 \[[ bufnr ( '%' ), 1 , 3 , 0 ], [ bufnr ( '%' ), 1 , 4 , 0 ]], 2822 \[[ bufnr ( '%' ), 2 , 3 , 0 ], [ bufnr ( '%' ), 2 , 7 , 0 ]], 2823 \[[ bufnr ( '%' ), 3 , 3 , 0 ], [ bufnr ( '%' ), 3 , 3 , 0 ]], 2824 \] 2825let g: checked = 0 2826call feedkeys ( "gg0ll\<C-V>jj$y" , 'tx' ) 2827call assert_equal ( 1 , g: checked ) 2828call Check_Results ( getregtype ( '"' )) 2829call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2830 2831let g: expected_region = [ 'bc' , 'fg' , 'mn' ] 2832let g: expected_regionpos = [ 2833 \[[ bufnr ( '%' ), 1 , 2 , 0 ], [ bufnr ( '%' ), 1 , 3 , 0 ]], 2834 \[[ bufnr ( '%' ), 2 , 2 , 0 ], [ bufnr ( '%' ), 2 , 3 , 0 ]], 2835 \[[ bufnr ( '%' ), 3 , 2 , 0 ], [ bufnr ( '%' ), 3 , 3 , 0 ]], 2836 \] 2837let g: checked = 0 2838call feedkeys ( "gg0l\<C-V>jjly" , 'tx' ) 2839call assert_equal ( 1 , g: checked ) 2840call Check_Results ( getregtype ( '"' )) 2841call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2842 2843bwipe ! 2844 2845new 2846let lines = [ 'asdfghjkl' , '«口=口»' , 'qwertyuiop' , '口口=口口' , 'zxcvbnm' ] 2847call setline ( 1 , lines ) 2848 2849let g: expected_region = lines 2850let g: expected_regionpos = [ 2851 \[[ bufnr ( '%' ), 1 , 1 , 0 ], [ bufnr ( '%' ), 1 , 9 , 0 ]], 2852 \[[ bufnr ( '%' ), 2 , 1 , 0 ], [ bufnr ( '%' ), 2 , 11 , 0 ]], 2853 \[[ bufnr ( '%' ), 3 , 1 , 0 ], [ bufnr ( '%' ), 3 , 10 , 0 ]], 2854 \[[ bufnr ( '%' ), 4 , 1 , 0 ], [ bufnr ( '%' ), 4 , 13 , 0 ]], 2855 \[[ bufnr ( '%' ), 5 , 1 , 0 ], [ bufnr ( '%' ), 5 , 7 , 0 ]], 2856 \] 2857let g: checked = 0 2858call feedkeys ( 'ggyG' , 'tx' ) 2859call assert_equal ( 1 , g: checked ) 2860call Check_Results ( getregtype ( '"' )) 2861call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2862 2863let g: expected_region = [ '=口»' , 'qwertyuiop' , '口口=口' ] 2864let g: expected_regionpos = [ 2865 \[[ bufnr ( '%' ), 2 , 6 , 0 ], [ bufnr ( '%' ), 2 , 11 , 0 ]], 2866 \[[ bufnr ( '%' ), 3 , 1 , 0 ], [ bufnr ( '%' ), 3 , 10 , 0 ]], 2867 \[[ bufnr ( '%' ), 4 , 1 , 0 ], [ bufnr ( '%' ), 4 , 10 , 0 ]], 2868 \] 2869let g: checked = 0 2870call feedkeys ( '2gg02lv2j2ly' , 'tx' ) 2871call assert_equal ( 1 , g: checked ) 2872call Check_Results ( getregtype ( '"' )) 2873call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2874 2875let g: expected_region = [ 'asdf' , '«口=' , 'qwer' , '口口' , 'zxcv' ] 2876let g: expected_regionpos = [ 2877 \[[ bufnr ( '%' ), 1 , 1 , 0 ], [ bufnr ( '%' ), 1 , 4 , 0 ]], 2878 \[[ bufnr ( '%' ), 2 , 1 , 0 ], [ bufnr ( '%' ), 2 , 6 , 0 ]], 2879 \[[ bufnr ( '%' ), 3 , 1 , 0 ], [ bufnr ( '%' ), 3 , 4 , 0 ]], 2880 \[[ bufnr ( '%' ), 4 , 1 , 0 ], [ bufnr ( '%' ), 4 , 6 , 0 ]], 2881 \[[ bufnr ( '%' ), 5 , 1 , 0 ], [ bufnr ( '%' ), 5 , 4 , 0 ]], 2882 \] 2883let g: checked = 0 2884call feedkeys ( "G0\<C-V>3l4ky" , 'tx' ) 2885call assert_equal ( 1 , g: checked ) 2886call Check_Results ( getregtype ( '"' )) 2887call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2888 2889let g: expected_region = [ 'ghjkl' , '口»' , 'tyuiop' , '=口口' , 'bnm' ] 2890let g: expected_regionpos = [ 2891 \[[ bufnr ( '%' ), 1 , 5 , 0 ], [ bufnr ( '%' ), 1 , 9 , 0 ]], 2892 \[[ bufnr ( '%' ), 2 , 7 , 0 ], [ bufnr ( '%' ), 2 , 11 , 0 ]], 2893 \[[ bufnr ( '%' ), 3 , 5 , 0 ], [ bufnr ( '%' ), 3 , 10 , 0 ]], 2894 \[[ bufnr ( '%' ), 4 , 7 , 0 ], [ bufnr ( '%' ), 4 , 13 , 0 ]], 2895 \[[ bufnr ( '%' ), 5 , 5 , 0 ], [ bufnr ( '%' ), 5 , 7 , 0 ]], 2896 \] 2897let g: checked = 0 2898call feedkeys ( "G04l\<C-V>$4ky" , 'tx' ) 2899call assert_equal ( 1 , g: checked ) 2900call Check_Results ( getregtype ( '"' )) 2901call assert_equal ( g: expected_region , getreg ( '"' , v: true , v: true )) 2902 2903bwipe ! 2904 2905unlet g: expected_region 2906unlet g: expected_regionpos 2907unlet g: checked 2908autocmd ! TextYankPost 2909delfunc Check_Results 2910endfunc 2911 2912func Test_visual_block_cursor_delete () 2913new 2914call setline ( 1 , 'ab' ) 2915exe ":norm! $\<c-v>hI\<Del>\<ESC>" 2916call assert_equal ([ 'b' ], getline ( 1 , 1 )) 2917bwipe ! 2918endfunc 2919 2920func Test_visual_block_cursor_insert_enter () 2921new 2922call setline ( 1 , [ 'asdf asdf' , 'asdf asdf' , 'asdf asdf' , 'asdf asdf' ]) 2923call cursor ( 1 , 5 ) 2924exe ":norm! \<c-v>3jcw\<cr>" 2925call assert_equal ([ 'asdfw' , 'asdf' , 'asdfasdf' , 'asdfasdf' , 'asdfasdf' ], getline ( 1 , '$' )) 2926bwipe ! 2927endfunc 2928 2929func Test_visual_block_exclusive_selection () 2930new 2931set selection = exclusive 2932call setline ( 1 , [ 'asöd asdf' , 'asdf asdf' , 'as€d asdf' , 'asdf asdf' ]) 2933call cursor ( 1 , 1 ) 2934exe ":norm! \<c-v>eh3j~" 2935call assert_equal ([ 'ASÖd asdf' , 'ASDf asdf' , 'AS€d asdf' , 'ASDf asdf' ], getline ( 1 , '$' )) 2936exe ":norm! 1v~" 2937call assert_equal ([ 'asöd asdf' , 'asdf asdf' , 'as€d asdf' , 'asdf asdf' ], getline ( 1 , '$' )) 2938bwipe ! 2939set selection & vim 2940endfunc 2941 2942func Test_visual_block_exclusive_selection_adjusted () 2943new 2944" Test that the end-position of the visual selection is adjusted for exclusive selection 2945set selection = exclusive 2946call setline ( 1 , [ 'asöd asdf ' , 'asdf asdf ' , 'as€d asdf ' , 'asdf asdf ' ]) 2947call cursor ( 1 , 1 ) 2948" inclusive motion 2949exe ":norm! \<c-v>e3jy" 2950call assert_equal ([ 0 , 4 , 5 , 0 ], getpos ( "'>" )) 2951" exclusive motion 2952exe ":norm! \<c-v>ta3jy" 2953call assert_equal ([ 0 , 4 , 6 , 0 ], getpos ( "'>" )) 2954" another inclusive motion 2955exe ":norm! \<c-v>g_3jy" 2956call assert_equal ([ 0 , 4 , 10 , 0 ], getpos ( "'>" )) 2957 2958" Reset selection option to Vim default 2959set selection & vim 2960call cursor ( 1 , 1 ) 2961 2962" inclusive motion 2963exe ":norm! \<c-v>e3jy" 2964call assert_equal ([ 0 , 4 , 4 , 0 ], getpos ( "'>" )) 2965" exclusive motion 2966exe ":norm! \<c-v>ta3jy" 2967call assert_equal ([ 0 , 4 , 5 , 0 ], getpos ( "'>" )) 2968" another inclusive motion 2969exe ":norm! \<c-v>g_3jy" 2970call assert_equal ([ 0 , 4 , 9 , 0 ], getpos ( "'>" )) 2971bwipe ! 2972set selection & vim 2973endfunc 2974 2975" the following caused a Heap-Overflow, because Vim was accessing outside of a 2976" line end 2977func Test_visual_pos_buffer_heap_overflow () 2978set virtualedit = all 2979args Xa Xb 2980all 2981call setline ( 1 , [ '' , '' , '' ]) 2982call cursor ( 3 , 1 ) 2983wincmd w 2984call setline ( 1 , 'foobar' ) 2985normal ! $lv0 2986all 2987call setreg ( '"' , 'baz' ) 2988normal ! [P 2989set virtualedit = 2990bw ! Xa Xb 2991endfunc 2992 2993" Test visual block pos update after block insert and gv 2994func Test_visual_block_pos_update () 2995new 2996set virtualedit = block 2997call setline ( 1 , [ 'aacccc' , 'bb' ]) 2998exe "norm! e\<C-v>jAa\<Esc>gv" 2999call assert_equal ([[ 0 , 1 , 6 , 0 ], [ 0 , 2 , 6 , 0 ]], [ getpos ( "v" ), getpos ( "." )]) 3000normal ! kj 3001call assert_equal ([[ 0 , 1 , 6 , 0 ], [ 0 , 2 , 6 , 0 ]], [ getpos ( "v" ), getpos ( "." )]) 3002set virtualedit = 3003bw ! 3004endfunc 3005 3006" Test that blockwise end position matches getpos('.') 3007" when 'wrap' and 'linebreak' are set 3008func Test_getregionpos_block_linebreak_matches_getpos () 3009CheckFeature linebreak 3010 3011new 3012setlocal buftype = 3013setlocal bufhidden = wipe 3014setlocal noswapfile 3015 3016setlocal wrap 3017setlocal linebreak 3018setlocal breakat = \ \t 3019setlocal nonumber norelativenumber 3020setlocal signcolumn = no 3021setlocal foldcolumn = 0 3022 3023call setline ( 1 , '1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888' ) 3024 3025" Force wrapping deterministically by shrinking the screen width. 3026let save_columns = & columns 3027let moved = 0 3028for c in [ 30 , 20 , 15 , 10 ] 3029execute 'set columns=' .. c 3030redraw ! 3031normal ! gg0 3032let row0 = winline () 3033normal ! gj 3034let row1 = winline () 3035if row1 > row0 3036let moved = 1 3037break 3038endif 3039endfor 3040call assert_true ( moved ) 3041 3042" Move a bit right so we are not at column 1, then go back up one screen line. 3043normal ! 5l 3044normal ! gk 3045let row2 = winline () 3046call assert_equal ( row0 , row2 ) 3047 3048" Start Visual block and move down one screen line to the previous position. 3049execute "normal! \<C-V>" 3050normal ! gj 3051let row3 = winline () 3052call assert_equal ( row1 , row3 ) 3053 3054let p1 = getpos ( 'v' ) 3055let p2 = getpos ( '.' ) 3056 3057" Sanity: block selection is within the same wrapped buffer line. 3058call assert_equal ( 1 , p1 [ 1 ]) 3059call assert_equal ( 1 , p2 [ 1 ]) 3060 3061" For blockwise region, getregionpos() should not report an end position 3062" different from the {pos2} we passed in. 3063let segs = getregionpos ( p1 , p2 , #{ type : "\<C-V>" , exclusive : v: false }) 3064 3065call assert_equal ( 1 , len ( segs )) 3066let endp = segs [ 0 ][ 1 ] 3067 3068call assert_equal ( p2 [ 1 ], endp [ 1 ]) " lnum 3069call assert_equal ( p2 [ 2 ], endp [ 2 ]) " col 3070call assert_equal ( p2 [ 3 ], endp [ 3 ]) " off 3071 3072let & columns = save_columns 3073bw ! 3074endfunc 3075 3076func Test_visual_ended_in_wiped_buffer () 3077edit Xfoo 3078edit Xbar 3079setlocal bufhidden = wipe 3080augroup testing 3081autocmd BufWipeout * ++oncenormal ! v 3082augroup END 3083" Must be the last window. 3084call assert_equal ( 1 , winnr ( '$' )) 3085call assert_equal ( 1 , tabpagenr ( '$' )) 3086" Was a member access on a NULL curbuf from Vim ending Visual mode. 3087buffer # 3088call assert_equal ( 0 , bufexists ( 'Xbar' )) 3089call assert_equal ( 'n' , mode ()) 3090 3091autocmd ! testing 3092 %bw ! 3093endfunc 3094 3095func Test_visual_ended_in_unloaded_buffer () 3096throw 'Skipped: needs clipboard=autoselect' 3097CheckFeature clipboard 3098CheckNotGui 3099set clipboard += autoselect 3100edit Xfoo 3101edit Xbar 3102call setline ( 1 , 'hi' ) 3103setlocal nomodified 3104let s: fired = 0 3105augroup testing 3106autocmd BufUnload Xbar call assert_equal ( 'Xbar' , bufname ()) 3107 \|execute 'normal! V' 3108 \|call assert_equal ( 'V' , mode ()) 3109 3110" From Vim ending Visual mode. Used to occur too late, after the buffer was 3111" unloaded, so @* didn't contain the selection. Window also had a NULL 3112" w_buffer here! 3113autocmd TextYankPost * ++oncelet s: fired = 1 3114 \|if has ( 'clipboard_working' ) |call assert_equal ( "hi\n" , @*) |endif 3115 \|call tabpagebuflist () " was a NULL member access on w_buffer 3116augroup END 3117 3118buffer Xfoo 3119call assert_equal ( 0 , bufloaded ( 'Xbar' )) 3120call assert_equal ( 'n' , mode ()) 3121call assert_equal ( 1 , s: fired ) 3122 3123augroup testing 3124autocmd ! 3125autocmd BufHidden Xfoo ++oncecall assert_equal ( 'Xfoo' , bufname ()) 3126 \|execute 'normal! v' 3127 \|call assert_equal ( 'v' , mode ()) 3128 3129" Check b_nwindows is not decremented too early when Visual mode ends in a 3130" loaded buffer. Buffer should not be considered hidden in TextYankPost, as 3131" by that point it's still loaded and displayed in the current window. 3132autocmd TextYankPost * ++oncelet s: fired = 2 3133 \|call assert_equal ( 1 , bufloaded ( bufnr ())) 3134 \|call assert_equal ( 0 , getbufinfo ( bufnr ())[ 0 ]. hidden ) 3135augroup END 3136edit Xbar 3137edit Xfoo 3138only 3139hide buffer # 3140call assert_equal ( 'n' , mode ()) 3141call assert_equal ( 2 , s: fired ) 3142 3143autocmd ! testing 3144unlet ! s: fired 3145set clipboard & 3146 %bw ! 3147endfunc 3148 3149" vim: shiftwidth=2 sts=2 expandtab