robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
00289fa20a
master
1" Tests for 'virtualedit'. 2 3func Test_yank_move_change () 4new 5call setline ( 1 , [ 6 \"func foo() error {" , 7 \"\tif n, err := bar();" , 8 \"\terr != nil {" , 9 \"\t\treturn err" , 10 \"\t}" , 11 \"\tn = n * n" , 12 \]) 13set virtualedit = all 14set ts = 4 15function ! MoveSelectionDown ( count ) abort 16normal ! m` 17silent ! exe "'<,'>move'>+" . a: count 18norm ! `` 19endfunction 20 21xmap ]e :< C-U > call MoveSelectionDown(v:count1)< CR > 222 23normal 2gg 24normal J 25normal jVj 26normal ]e 27normal ce 28bwipe ! 29set virtualedit = 30set ts = 8 31endfunc 32 33func Test_paste_end_of_line () 34new 35set virtualedit = all 36call setline ( 1 , [ '456' , '123' ]) 37normal ! gg0"ay$ 38exe "normal! 2G$lllA\<C-O>:normal! \"agP\r" 39call assert_equal ( '123456' , getline ( 2 )) 40 41bwipe ! 42set virtualedit = 43endfunc 44 45func Test_replace_end_of_line () 46new 47set virtualedit = all 48call setline ( 1 , range ( 20 )) 49exe "normal! gg2jv10lr-" 50call assert_equal ([ "1" , "-----------" , "3" ], getline ( 2 , 4 )) 51call setline ( 1 , range ( 20 )) 52exe "normal! gg2jv10lr\<c-k>hh" 53call assert_equal ([ "1" , "───────────" , "3" ], getline ( 2 , 4 )) 54 55bwipe ! 56set virtualedit = 57endfunc 58 59func Test_edit_CTRL_G () 60new 61set virtualedit = insert 62call setline ( 1 , [ '123' , '1' , '12' ]) 63exe "normal! ggA\<c-g>jx\<c-g>jx" 64call assert_equal ([ '123' , '1 x' , '12 x' ], getline ( 1 , '$' )) 65 66set virtualedit = all 67 %d _ 68call setline ( 1 , [ '1' , '12' ]) 69exe "normal! ggllix\<c-g>jx" 70call assert_equal ([ '1 x' , '12x' ], getline ( 1 , '$' )) 71 72 73bwipe ! 74set virtualedit = 75endfunc 76 77func Test_edit_change () 78new 79set virtualedit = all 80 81call setline ( 1 , "\t⒌" ) 82normal Cx 83call assert_equal ( 'x' , getline ( 1 )) 84 85call setline ( 1 , "\ta̳" ) 86normal Cx 87call assert_equal ( 'x' , getline ( 1 )) 88 89call setline ( 1 , "\tβ̳" ) 90normal Cx 91call assert_equal ( 'x' , getline ( 1 )) 92 93if has ( 'arabic' ) 94call setline ( 1 , "\tلا" ) 95normal Cx 96call assert_equal ( 'x' , getline ( 1 )) 97endif 98 99" Do a visual block change 100call setline ( 1 , [ 'a' , 'b' , 'c' ]) 101exe "normal gg3l\<C-V>2jcx" 102call assert_equal ([ 'a x' , 'b x' , 'c x' ], getline ( 1 , '$' )) 103 104bwipe ! 105set virtualedit = 106endfunc 107 108func Test_edit_special_char () 109new 110se ve = all 111norm a0 112sil ! exe "norm o00000\<Nul>k<a0s" 113 114bwipe ! 115set virtualedit = 116endfunc 117 118" Tests for pasting at the beginning, end and middle of a tab character 119" in virtual edit mode. 120func Test_paste_in_tab () 121new 122call append ( 0 , '' ) 123set virtualedit = all 124 125" Tests for pasting a register with characterwise mode type 126call setreg ( '"' , 'xyz' , 'c' ) 127 128" paste (p) unnamed register at the beginning of a tab 129call setline ( 1 , "a\tb" ) 130call cursor ( 1 , 2 , 0 ) 131normal p 132call assert_equal ( 'a xyz b' , getline ( 1 )) 133 134" paste (P) unnamed register at the beginning of a tab 135call setline ( 1 , "a\tb" ) 136call cursor ( 1 , 2 , 0 ) 137normal P 138call assert_equal ( "axyz\tb" , getline ( 1 )) 139 140" paste (p) unnamed register at the end of a tab 141call setline ( 1 , "a\tb" ) 142call cursor ( 1 , 2 , 6 ) 143normal p 144call assert_equal ( "a\txyzb" , getline ( 1 )) 145 146" paste (P) unnamed register at the end of a tab 147call setline ( 1 , "a\tb" ) 148call cursor ( 1 , 2 , 6 ) 149normal P 150call assert_equal ( 'a xyz b' , getline ( 1 )) 151 152" Tests for pasting a register with blockwise mode type 153call setreg ( '"' , 'xyz' , 'b' ) 154 155" paste (p) unnamed register at the beginning of a tab 156call setline ( 1 , "a\tb" ) 157call cursor ( 1 , 2 , 0 ) 158normal p 159call assert_equal ( 'a xyz b' , getline ( 1 )) 160 161" paste (P) unnamed register at the beginning of a tab 162call setline ( 1 , "a\tb" ) 163call cursor ( 1 , 2 , 0 ) 164normal P 165call assert_equal ( "axyz\tb" , getline ( 1 )) 166 167" paste (p) unnamed register at the end of a tab 168call setline ( 1 , "a\tb" ) 169call cursor ( 1 , 2 , 6 ) 170normal p 171call assert_equal ( "a\txyzb" , getline ( 1 )) 172 173" paste (P) unnamed register at the end of a tab 174call setline ( 1 , "a\tb" ) 175call cursor ( 1 , 2 , 6 ) 176normal P 177call assert_equal ( 'a xyz b' , getline ( 1 )) 178 179" Tests for pasting with gp and gP in virtual edit mode 180 181" paste (gp) unnamed register at the beginning of a tab 182call setline ( 1 , "a\tb" ) 183call cursor ( 1 , 2 , 0 ) 184normal gp 185call assert_equal ( 'a xyz b' , getline ( 1 )) 186call assert_equal ([ 0 , 1 , 12 , 0 , 12 ], getcurpos ()) 187 188" paste (gP) unnamed register at the beginning of a tab 189call setline ( 1 , "a\tb" ) 190call cursor ( 1 , 2 , 0 ) 191normal gP 192call assert_equal ( "axyz\tb" , getline ( 1 )) 193call assert_equal ([ 0 , 1 , 5 , 0 , 5 ], getcurpos ()) 194 195" paste (gp) unnamed register at the end of a tab 196call setline ( 1 , "a\tb" ) 197call cursor ( 1 , 2 , 6 ) 198normal gp 199call assert_equal ( "a\txyzb" , getline ( 1 )) 200call assert_equal ([ 0 , 1 , 6 , 0 , 12 ], getcurpos ()) 201 202" paste (gP) unnamed register at the end of a tab 203call setline ( 1 , "a\tb" ) 204call cursor ( 1 , 2 , 6 ) 205normal gP 206call assert_equal ( 'a xyz b' , getline ( 1 )) 207call assert_equal ([ 0 , 1 , 12 , 0 , 12 ], getcurpos ()) 208 209" Tests for pasting a named register 210let @r= 'xyz' 211 212" paste (gp) named register in the middle of a tab 213call setline ( 1 , "a\tb" ) 214call cursor ( 1 , 2 , 2 ) 215normal "rgp 216call assert_equal ( 'a xyz b' , getline ( 1 )) 217call assert_equal ([ 0 , 1 , 8 , 0 , 8 ], getcurpos ()) 218 219" paste (gP) named register in the middle of a tab 220call setline ( 1 , "a\tb" ) 221call cursor ( 1 , 2 , 2 ) 222normal "rgP 223call assert_equal ( 'a xyz b' , getline ( 1 )) 224call assert_equal ([ 0 , 1 , 7 , 0 , 7 ], getcurpos ()) 225 226bwipe ! 227set virtualedit = 228endfunc 229 230" Test for yanking a few spaces within a tab to a register 231func Test_yank_in_tab () 232new 233let @r= '' 234call setline ( 1 , "a\tb" ) 235set virtualedit = all 236call cursor ( 1 , 2 , 2 ) 237normal "ry5l 238call assert_equal ( ' ' , @r) 239 240bwipe ! 241set virtualedit = 242endfunc 243 244" Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword". 245" Repeating CTRL-N fixes it. (Mary Ellen Foster) 246func Test_ve_completion () 247new 248set completeopt & vim 249set virtualedit = all 250exe "normal ikeyword keyw\<Esc>C\<C-N>" 251call assert_equal ( 'keyword keyword' , getline ( 1 )) 252bwipe ! 253set virtualedit = 254endfunc 255 256" Using "C" then <CR> moves the last remaining character to the next 257" line. (Mary Ellen Foster) 258func Test_ve_del_to_eol () 259new 260set virtualedit = all 261call append ( 0 , 'all your base are belong to us' ) 262call search ( 'are' , 'w' ) 263exe "normal C\<CR>are belong to vim" 264call assert_equal ([ 'all your base ' , 'are belong to vim' ], getline ( 1 , 2 )) 265bwipe ! 266set virtualedit = 267endfunc 268 269" When past the end of a line that ends in a single character "b" skips 270" that word. 271func Test_ve_b_past_eol () 272new 273set virtualedit = all 274call append ( 0 , '1 2 3 4 5 6' ) 275normal gg^$15lbC7 276call assert_equal ( '1 2 3 4 5 7' , getline ( 1 )) 277bwipe ! 278set virtualedit = 279endfunc 280 281" Make sure 'i', 'C', 'a', 'A' and 'D' works 282func Test_ve_ins_del () 283new 284set virtualedit = all 285call append ( 0 , [ "'i'" , "'C'" , "'a'" , "'A'" , "'D'" ]) 286call cursor ( 1 , 1 ) 287normal $4lix 288call assert_equal ( "'i' x" , getline ( 1 )) 289call cursor ( 2 , 1 ) 290normal $4lCx 291call assert_equal ( "'C' x" , getline ( 2 )) 292call cursor ( 3 , 1 ) 293normal $4lax 294call assert_equal ( "'a' x" , getline ( 3 )) 295call cursor ( 4 , 1 ) 296normal $4lAx 297call assert_equal ( "'A'x" , getline ( 4 )) 298call cursor ( 5 , 1 ) 299normal $4lDix 300call assert_equal ( "'D' x" , getline ( 5 )) 301bwipe ! 302set virtualedit = 303endfunc 304 305" Test for yank bug reported by Mark Waggoner. 306func Test_yank_block () 307new 308set virtualedit = block 309call append ( 0 , repeat ([ 'this is a test' ], 3 )) 310exe "normal gg^2w\<C-V>3jy" 311call assert_equal ( "a\na\na\n " , @") 312bwipe ! 313set virtualedit = 314endfunc 315 316" Test "r" beyond the end of the line 317func Test_replace_after_eol () 318new 319set virtualedit = all 320call append ( 0 , '"r"' ) 321normal gg$5lrxa 322call assert_equal ( '"r" x' , getline ( 1 )) 323" visual block replace 324 %d _ 325call setline ( 1 , [ 'a' , '' , 'b' ]) 326exe "normal 2l\<C-V>2jrx" 327call assert_equal ([ 'a x' , ' x' , 'b x' ], getline ( 1 , '$' )) 328" visual characterwise selection replace after eol 329 %d _ 330call setline ( 1 , 'a' ) 331normal 4lv2lrx 332call assert_equal ( 'a xxx' , getline ( 1 )) 333bwipe ! 334set virtualedit = 335endfunc 336 337" Test "r" on a tab 338" Note that for this test, 'ts' must be 8 (the default). 339func Test_replace_on_tab () 340new 341set virtualedit = all 342call append ( 0 , "'r'\t" ) 343normal gg^5lrxAy 344call assert_equal ( "'r' x y" , getline ( 1 )) 345call setline ( 1 , 'aaaaaaaaaaaa' ) 346exe "normal! gg2lgR\<Tab>" 347call assert_equal ( "aa\taaaa" , getline ( 1 )) 348bwipe ! 349set virtualedit = 350endfunc 351 352" Test to make sure 'x' can delete control characters 353func Test_ve_del_ctrl_chars () 354new 355set virtualedit = all 356call append ( 0 , "a\<C-V>b\<CR>sd" ) 357set display = uhex 358normal gg^xxxxxxi[text] 359set display = 360call assert_equal ( '[text]' , getline ( 1 )) 361bwipe ! 362set virtualedit = 363endfunc 364 365" Test for ^Y/^E due to bad w_virtcol value, reported by 366" Roy <royl@netropolis.net>. 367func Test_ins_copy_char () 368new 369set virtualedit = all 370call append ( 0 , 'abcv8efi.him2kl' ) 371exe "normal gg^O\<Esc>3li\<C-E>\<Esc>4li\<C-E>\<Esc>4li\<C-E> <--" 372exe "normal j^o\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>\<Esc>4li\<C-Y> <--" 373call assert_equal ( ' v i m <--' , getline ( 1 )) 374call assert_equal ( ' 8 . 2 <--' , getline ( 3 )) 375bwipe ! 376set virtualedit = 377endfunc 378 379" Test for yanking and pasting using the small delete register 380func Test_yank_paste_small_del_reg () 381new 382set virtualedit = all 383call append ( 0 , "foo, bar" ) 384normal ggdewve"-p 385call assert_equal ( ', foo' , getline ( 1 )) 386bwipe ! 387set virtualedit = 388endfunc 389 390" Test for delete that breaks a tab into spaces 391func Test_delete_break_tab () 392new 393call setline ( 1 , "one\ttwo" ) 394set virtualedit = all 395normal v3ld 396call assert_equal ( ' two' , getline ( 1 )) 397set virtualedit & 398bw ! 399endfunc 400 401" Test for using <BS>, <C-W> and <C-U> in virtual edit mode 402" to erase character, word and line. 403func Test_ve_backspace () 404new 405call setline ( 1 , 'sample' ) 406set virtualedit = all 407set backspace = indent,eol,start 408exe "normal 15|i\<BS>\<BS>" 409call assert_equal ([ 0 , 1 , 7 , 5 ], getpos ( '.' )) 410exe "normal 15|i\<C-W>" 411call assert_equal ([ 0 , 1 , 6 , 0 ], getpos ( '.' )) 412exe "normal 15|i\<C-U>" 413call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 414set backspace & 415set virtualedit & 416bw ! 417endfunc 418 419" Test for delete (x) on EOL character and after EOL 420func Test_delete_past_eol () 421new 422call setline ( 1 , "ab" ) 423set virtualedit = all 424exe "normal 2lx" 425call assert_equal ( 'ab' , getline ( 1 )) 426exe "normal 10lx" 427call assert_equal ( 'ab' , getline ( 1 )) 428set virtualedit & 429bw ! 430endfunc 431 432" After calling s:TryVirtualeditReplace(), line 1 will contain one of these 433" two strings, depending on whether virtual editing is on or off. 434let s: result_ve_on = 'a x' 435let s: result_ve_off = 'x' 436 437" Utility function for Test_global_local_virtualedit() 438func s: TryVirtualeditReplace () 439call setline ( 1 , 'a' ) 440normal gg7l 441normal rx 442endfunc 443 444" Test for :set and :setlocal 445func Test_global_local_virtualedit () 446new 447 448" Verify that 'virtualedit' is initialized to empty, can be set globally to 449" all and to empty, and can be set locally to all and to empty. 450call s: TryVirtualeditReplace () 451call assert_equal ( s: result_ve_off , getline ( 1 )) 452set ve = all 453call s: TryVirtualeditReplace () 454call assert_equal ( s: result_ve_on , getline ( 1 )) 455set ve = 456call s: TryVirtualeditReplace () 457call assert_equal ( s: result_ve_off , getline ( 1 )) 458setlocal ve = all 459call s: TryVirtualeditReplace () 460call assert_equal ( s: result_ve_on , getline ( 1 )) 461setlocal ve = 462call s: TryVirtualeditReplace () 463call assert_equal ( s: result_ve_off , getline ( 1 )) 464 465" Verify that :set affects multiple windows. 466split 467set ve = all 468call s: TryVirtualeditReplace () 469call assert_equal ( s: result_ve_on , getline ( 1 )) 470wincmd p 471call s: TryVirtualeditReplace () 472call assert_equal ( s: result_ve_on , getline ( 1 )) 473set ve = 474wincmd p 475call s: TryVirtualeditReplace () 476call assert_equal ( s: result_ve_off , getline ( 1 )) 477bwipe ! 478 479" Verify that :setlocal affects only the current window. 480new 481split 482setlocal ve = all 483call s: TryVirtualeditReplace () 484call assert_equal ( s: result_ve_on , getline ( 1 )) 485wincmd p 486call s: TryVirtualeditReplace () 487call assert_equal ( s: result_ve_off , getline ( 1 )) 488bwipe ! 489call s: TryVirtualeditReplace () 490call assert_equal ( s: result_ve_off , getline ( 1 )) 491 492" Verify that the buffer 'virtualedit' state follows the global value only 493" when empty and that "none" works as expected. 494" 495" 'virtualedit' State 496" +--------+--------------------------+ 497" | Local | Global | 498" | | | 499" +--------+--------+--------+--------+ 500" | | "" | "all" | "none" | 501" +--------+--------+--------+--------+ 502" | "" | off | on | off | 503" | "all" | on | on | on | 504" | "none" | off | off | off | 505" +--------+--------+--------+--------+ 506new 507 508setglobal ve= 509setlocal ve = 510call s: TryVirtualeditReplace () 511call assert_equal ( s: result_ve_off , getline ( 1 )) 512setlocal ve = all 513call s: TryVirtualeditReplace () 514call assert_equal ( s: result_ve_on , getline ( 1 )) 515setlocal ve = none 516call s: TryVirtualeditReplace () 517call assert_equal ( s: result_ve_off , getline ( 1 )) 518 519setglobal ve=all 520setlocal ve = 521call s: TryVirtualeditReplace () 522call assert_equal ( s: result_ve_on , getline ( 1 )) 523setlocal ve = all 524call s: TryVirtualeditReplace () 525call assert_equal ( s: result_ve_on , getline ( 1 )) 526setlocal ve = none 527call s: TryVirtualeditReplace () 528call assert_equal ( s: result_ve_off , getline ( 1 )) 529setlocal ve = NONE 530call s: TryVirtualeditReplace () 531call assert_equal ( s: result_ve_off , getline ( 1 )) 532 533setglobal ve=none 534setlocal ve = 535call s: TryVirtualeditReplace () 536call assert_equal ( s: result_ve_off , getline ( 1 )) 537setlocal ve = all 538call s: TryVirtualeditReplace () 539call assert_equal ( s: result_ve_on , getline ( 1 )) 540setlocal ve = none 541call s: TryVirtualeditReplace () 542call assert_equal ( s: result_ve_off , getline ( 1 )) 543 544bwipe ! 545 546" Verify that the 'virtualedit' state is copied to new windows. 547new 548call s: TryVirtualeditReplace () 549call assert_equal ( s: result_ve_off , getline ( 1 )) 550split 551setlocal ve = all 552call s: TryVirtualeditReplace () 553call assert_equal ( s: result_ve_on , getline ( 1 )) 554split 555call s: TryVirtualeditReplace () 556call assert_equal ( s: result_ve_on , getline ( 1 )) 557setlocal ve = 558split 559call s: TryVirtualeditReplace () 560call assert_equal ( s: result_ve_off , getline ( 1 )) 561bwipe ! 562 563setlocal virtualedit & 564set virtualedit & 565endfunc 566 567func Test_virtualedit_setlocal () 568enew 569setglobal virtualedit=all 570setlocal virtualedit = all 571normal ! l 572redraw 573setlocal virtualedit = none 574call assert_equal ( 1 , wincol ()) 575 576setlocal virtualedit & 577set virtualedit & 578endfunc 579 580func Test_virtualedit_mouse () 581let save_mouse = & mouse 582set mouse = a 583set virtualedit = all 584botright new 585let row = win_screenpos ( 0 )[ 0 ] 58620 vsplit 587wincmd p 588 589call setline ( 1 , [ "text\tword" ]) 590redraw 591call Ntest_setmouse ( row , 21 + 4 ) 592call feedkeys ( "\<LeftMouse>" , "xt" ) 593call assert_equal ([ 0 , 1 , 4 , 0 , 4 ], getcurpos ()) 594call Ntest_setmouse ( row , 21 + 5 ) 595call feedkeys ( "\<LeftMouse>" , "xt" ) 596call assert_equal ([ 0 , 1 , 5 , 0 , 5 ], getcurpos ()) 597call Ntest_setmouse ( row , 21 + 6 ) 598call feedkeys ( "\<LeftMouse>" , "xt" ) 599call assert_equal ([ 0 , 1 , 5 , 1 , 6 ], getcurpos ()) 600call Ntest_setmouse ( row , 21 + 7 ) 601call feedkeys ( "\<LeftMouse>" , "xt" ) 602call assert_equal ([ 0 , 1 , 5 , 2 , 7 ], getcurpos ()) 603call Ntest_setmouse ( row , 21 + 8 ) 604call feedkeys ( "\<LeftMouse>" , "xt" ) 605call assert_equal ([ 0 , 1 , 5 , 3 , 8 ], getcurpos ()) 606call Ntest_setmouse ( row , 21 + 9 ) 607call feedkeys ( "\<LeftMouse>" , "xt" ) 608call assert_equal ([ 0 , 1 , 6 , 0 , 9 ], getcurpos ()) 609call Ntest_setmouse ( row , 21 + 12 ) 610call feedkeys ( "\<LeftMouse>" , "xt" ) 611call assert_equal ([ 0 , 1 , 9 , 0 , 12 ], getcurpos ()) 612call Ntest_setmouse ( row , 21 + 13 ) 613call feedkeys ( "\<LeftMouse>" , "xt" ) 614call assert_equal ([ 0 , 1 , 10 , 0 , 13 ], getcurpos ()) 615call Ntest_setmouse ( row , 21 + 15 ) 616call feedkeys ( "\<LeftMouse>" , "xt" ) 617call assert_equal ([ 0 , 1 , 10 , 2 , 15 ], getcurpos ()) 618call Ntest_setmouse ( row , 21 + 20 ) 619call feedkeys ( "\<LeftMouse>" , "xt" ) 620call assert_equal ([ 0 , 1 , 10 , 7 , 20 ], getcurpos ()) 621 622setlocal nowrap 623call setline ( 2 , repeat ( 'a' , 19 )) 624normal ! j14zl 625redraw 626call Ntest_setmouse ( row , 21 + 1 ) 627call feedkeys ( "\<LeftMouse>" , "xt" ) 628call assert_equal ([ 0 , 1 , 10 , 2 , 15 ], getcurpos ()) 629call Ntest_setmouse ( row , 21 + 11 ) 630call feedkeys ( "\<LeftMouse>" , "xt" ) 631call assert_equal ([ 0 , 1 , 10 , 12 , 25 ], getcurpos ()) 632call Ntest_setmouse ( row + 1 , 21 + 1 ) 633call feedkeys ( "\<LeftMouse>" , "xt" ) 634call assert_equal ([ 0 , 2 , 15 , 0 , 15 ], getcurpos ()) 635call Ntest_setmouse ( row + 1 , 21 + 11 ) 636call feedkeys ( "\<LeftMouse>" , "xt" ) 637call assert_equal ([ 0 , 2 , 20 , 5 , 25 ], getcurpos ()) 638 639setlocal number numberwidth = 2 640redraw 641call Ntest_setmouse ( row , 21 + 3 ) 642call feedkeys ( "\<LeftMouse>" , "xt" ) 643call assert_equal ([ 0 , 1 , 10 , 2 , 15 ], getcurpos ()) 644call Ntest_setmouse ( row , 21 + 13 ) 645call feedkeys ( "\<LeftMouse>" , "xt" ) 646call assert_equal ([ 0 , 1 , 10 , 12 , 25 ], getcurpos ()) 647call Ntest_setmouse ( row + 1 , 21 + 3 ) 648call feedkeys ( "\<LeftMouse>" , "xt" ) 649call assert_equal ([ 0 , 2 , 15 , 0 , 15 ], getcurpos ()) 650call Ntest_setmouse ( row + 1 , 21 + 13 ) 651call feedkeys ( "\<LeftMouse>" , "xt" ) 652call assert_equal ([ 0 , 2 , 20 , 5 , 25 ], getcurpos ()) 653setlocal nonumber 654 655if has ( 'signs' ) 656sign defineSign1 text= 口 657sign place1 name= Sign1 line= 1 658sign place2 name= Sign1 line= 2 659redraw 660call Ntest_setmouse ( row , 21 + 3 ) 661call feedkeys ( "\<LeftMouse>" , "xt" ) 662call assert_equal ([ 0 , 1 , 10 , 2 , 15 ], getcurpos ()) 663call Ntest_setmouse ( row , 21 + 13 ) 664call feedkeys ( "\<LeftMouse>" , "xt" ) 665call assert_equal ([ 0 , 1 , 10 , 12 , 25 ], getcurpos ()) 666call Ntest_setmouse ( row + 1 , 21 + 3 ) 667call feedkeys ( "\<LeftMouse>" , "xt" ) 668call assert_equal ([ 0 , 2 , 15 , 0 , 15 ], getcurpos ()) 669call Ntest_setmouse ( row + 1 , 21 + 13 ) 670call feedkeys ( "\<LeftMouse>" , "xt" ) 671call assert_equal ([ 0 , 2 , 20 , 5 , 25 ], getcurpos ()) 672sign unplace1 673sign unplace2 674sign undefineSign1 675endif 676 677wincmd h 6784 wincmd > 679normal ! gg24I. 680redraw 681call Ntest_setmouse ( row + 1 , 12 ) 682call feedkeys ( "\<LeftMouse>" , "xt" ) 683call assert_equal ([ 0 , 1 , 24 + 9 , 0 , 24 + 12 ], getcurpos ()) 684call Ntest_setmouse ( row + 1 , 13 ) 685call feedkeys ( "\<LeftMouse>" , "xt" ) 686call assert_equal ([ 0 , 1 , 24 + 10 , 0 , 24 + 13 ], getcurpos ()) 687call Ntest_setmouse ( row + 1 , 15 ) 688call feedkeys ( "\<LeftMouse>" , "xt" ) 689call assert_equal ([ 0 , 1 , 24 + 10 , 2 , 24 + 15 ], getcurpos ()) 690call Ntest_setmouse ( row + 1 , 20 ) 691call feedkeys ( "\<LeftMouse>" , "xt" ) 692call assert_equal ([ 0 , 1 , 24 + 10 , 7 , 24 + 20 ], getcurpos ()) 693 694bwipe ! 695let & mouse = save_mouse 696set virtualedit & 697endfunc 698 699" this was replacing the NUL at the end of the line 700func Test_virtualedit_replace_after_tab () 701new 702s /\v/ 0 703set ve = all 704let @"= '' 705sil ! norm vPvr0 706 707call assert_equal ( "\t0" , getline ( 1 )) 708set ve & 709bwipe ! 710endfunc 711 712" Test that setpos('.') and cursor() behave the same for v:maxcol 713func Test_virtualedit_set_cursor_pos_maxcol () 714new 715set virtualedit = all 716 717call setline ( 1 , 'foobar' ) 718exe "normal! V\<Esc>" 719call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( "'<" )) 720call assert_equal ([ 0 , 1 , v: maxcol , 0 ], getpos ( "'>" )) 721let pos = getpos ( "'>" ) 722 723call cursor ( 1 , 1 ) 724call setpos ( '.' , pos ) 725call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 726 727call cursor ( 1 , 1 ) 728call cursor ( pos [ 1 :]) 729call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 730 731set virtualedit & 732bwipe ! 733endfunc 734 735" Verify that getpos() remains consistent when the cursor is past EOL after 736" toggling Visual mode with virtualedit=all. 737func Test_virtualedit_getpos_stable_past_eol_after_visual () 738new 739set virtualedit = all 740call setline ( 1 , 'abc' ) 741 742normal ! gg$3l 743let p1 = getpos ( '.' ) 744 745normal ! v 746redraw 747exe "normal! \<Esc>" 748 749let p2 = getpos ( '.' ) 750call assert_equal ( p1 , p2 , 'Position should not be re-encoded after leaving Visual mode' ) 751 752set virtualedit & 753bwipe ! 754endfunc 755 756func Test_virtualedit_insert () 757new 758set virtualedit = insert 759 760call feedkeys ( "ifoobar\<Right>\<Right>\<Right>\<Right>baz\<Esc>" , 'tnix' ) 761call assert_equal ( 'foobar baz' , getline ( 1 )) 762 763call feedkeys ( "ccFOOBAR\<Right>\<Right>\<Right>\<Right>BAZ\<Esc>" , 'tnix' ) 764call assert_equal ( 'FOOBAR BAZ' , getline ( 1 )) 765 766set virtualedit & 767bwipe ! 768endfunc 769 770func Test_set_virtualedit_on_mode_change () 771new 772set virtualedit = all 773augroup testing 774au ModeChanged n: * set virtualedit = onemore 775au ModeChanged *:n set virtualedit = all 776au ModeChanged i: * call cursor ( getpos ( "'^" )[ 1 :]) 777augroup END 778 779call feedkeys ( "ilkj\<Esc>" , 'tnix' ) 780call assert_equal ([ 0 , 1 , 4 , 0 ], getpos ( '.' )) 781 782call feedkeys ( "cclkj\<Esc>" , 'tnix' ) 783call assert_equal ([ 0 , 1 , 4 , 0 ], getpos ( '.' )) 784 785au ! testing ModeChanged 786augroup ! testing 787set virtualedit & 788bwipe ! 789endfunc 790 791func Test_strip_autoindent_with_virtualedit_onemore () 792new 793setlocal autoindent virtualedit = onemore 794call feedkeys ( "i x\<CR>\<Esc>" , 'tnix' ) 795call assert_equal ([ ' x' , '' ], getline ( 1 , '$' )) 796 797% delete _ 798setlocal virtualedit & 799call feedkeys ( "i x\<CR>\<Esc>" , 'tnix' ) 800call assert_equal ([ ' x' , '' ], getline ( 1 , '$' )) 801 802bwipe ! 803endfunc 804 805" vim: shiftwidth=2 sts=2 expandtab