robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
4adf961148
master
1" Test for textobjects 2 3source check.vim 4 5func CpoM ( line , useM , expected ) 6new 7 8if a: useM 9set cpoptions += M 10else 11set cpoptions -= M 12endif 13 14call setline ( 1 , a: line ) 15 16call setreg ( '"' , '' ) 17normal ! ggfrmavi)y 18call assert_equal ( getreg ( '"' ), a: expected [ 0 ]) 19 20call setreg ( '"' , '' ) 21normal ! `afbmavi)y 22call assert_equal ( getreg ( '"' ), a: expected [ 1 ]) 23 24call setreg ( '"' , '' ) 25normal ! `afgmavi)y 26call assert_equal ( getreg ( '"' ), a: expected [ 2 ]) 27 28q ! 29endfunc 30 31func Test_inner_block_without_cpo_M () 32call CpoM ( '(red \(blue) green)' , 0 , [ 'red \(blue' , 'red \(blue' , '' ]) 33endfunc 34 35func Test_inner_block_with_cpo_M_left_backslash () 36call CpoM ( '(red \(blue) green)' , 1 , [ 'red \(blue) green' , 'blue' , 'red \(blue) green' ]) 37endfunc 38 39func Test_inner_block_with_cpo_M_right_backslash () 40call CpoM ( '(red (blue\) green)' , 1 , [ 'red (blue\) green' , 'blue\' , 'red (blue\) green' ]) 41endfunc 42 43func Test_inner_block_single_char () 44new 45call setline ( 1 , "(a)" ) 46 47set selection = inclusive 48let @"= '' 49call assert_nobeep ( 'norm! 0faviby' ) 50call assert_equal ( 'a' , @") 51 52set selection = exclusive 53let @"= '' 54call assert_nobeep ( 'norm! 0faviby' ) 55call assert_equal ( 'a' , @") 56 57set selection & 58bwipe ! 59endfunc 60 61func Test_quote_selection_selection_exclusive () 62new 63call setline ( 1 , "a 'bcde' f" ) 64set selection = exclusive 65 66exe "norm! fdvhi'y" 67call assert_equal ( 'bcde' , @") 68 69let @"= 'dummy' 70exe "norm! $gevi'y" 71call assert_equal ( 'bcde' , @") 72 73let @"= 'dummy' 74exe "norm! 0fbhvi'y" 75call assert_equal ( 'bcde' , @") 76 77set selection & vim 78bw ! 79endfunc 80 81func Test_quote_selection_selection_exclusive_abort () 82new 83set selection = exclusive 84call setline ( 1 , "'abzzc'" ) 85let exp_curs = [ 0 , 1 , 6 , 0 ] 86call cursor ( 1 , 1 ) 87exe 'norm! fcdvi"' 88" make sure to end visual mode to have a clear state 89exe "norm! \<esc>" 90call assert_equal ( exp_curs , getpos ( '.' )) 91call cursor ( 1 , 1 ) 92exe 'norm! fcvi"' 93exe "norm! \<esc>" 94call assert_equal ( exp_curs , getpos ( '.' )) 95call cursor ( 1 , 2 ) 96exe 'norm! vfcoi"' 97exe "norm! \<esc>" 98let exp_curs = [ 0 , 1 , 2 , 0 ] 99let exp_visu = [ 0 , 1 , 7 , 0 ] 100call assert_equal ( exp_curs , getpos ( '.' )) 101call assert_equal ( exp_visu , getpos ( "'>" )) 102set selection & vim 103bw ! 104endfunc 105 106" Tests for string and html text objects 107func Test_string_html_objects () 108 109" Nvim only supports set encoding=utf-8 110" for e in ['utf-8', 'latin1', 'cp932'] 111for e in [ 'utf-8' ] 112enew ! 113exe 'set enc=' .. e 114 115let t = '"wo\"rd\\" foo' 116put =t 117normal ! da" 118call assert_equal ( 'foo' , getline ( '.' ), e ) 119 120let t = "'foo' 'bar' 'piep'" 121put =t 122normal ! 0va'a'rx 123call assert_equal ( "xxxxxxxxxxxx'piep'" , getline ( '.' ), e ) 124 125let t = "bla bla `quote` blah" 126put =t 127normal ! 02f`da` 128call assert_equal ( "bla bla blah" , getline ( '.' ), e ) 129 130let t = 'out " in "noXno"' 131put =t 132normal ! 0fXdi" 133call assert_equal ( 'out " in ""' , getline ( '.' ), e ) 134 135let t = "\"'\" 'blah' rep 'buh'" 136put =t 137normal ! 03f'vi'ry 138call assert_equal ( "\"'\" 'blah'yyyyy'buh'" , getline ( '.' ), e ) 139 140set quoteescape = +*- 141let t = "bla `s*`d-`+++`l**` b`la" 142put =t 143normal ! di` 144call assert_equal ( "bla `` b`la" , getline ( '.' ), e ) 145 146let t = 'voo "nah" sdf " asdf" sdf " sdf" sd' 147put =t 148normal ! $F"va"oha"i"rz 149call assert_equal ( 'voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd' , getline ( '.' ), e ) 150 151let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" 152put =t 153normal ! fXdit 154call assert_equal ( '-<b>asdf<i></i>asdf</b>-' , getline ( '.' ), e ) 155 156let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-" 157put =t 158normal ! 0fXdit 159call assert_equal ( '-<b></b>-' , getline ( '.' ), e ) 160 161let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" 162put =t 163normal ! fXdat 164call assert_equal ( '-<b>asdfasdf</b>-' , getline ( '.' ), e ) 165 166let t = "-<b>asdX<i>as<b />df</i>asdf</b>-" 167put =t 168normal ! 0fXdat 169call assert_equal ( '--' , getline ( '.' ), e ) 170 171let t = "-<b>\ninnertext object\n</b>" 172put =t 173normal ! dit 174call assert_equal ( '-<b></b>' , getline ( '.' ), e ) 175 176" copy the tag block from leading indentation before the start tag 177let t = " <b>\ntext\n</b>" 178$ put =t 179normal ! 2kvaty 180call assert_equal ( "<b>\ntext\n</b>" , @", e ) 181 182" copy the tag block from the end tag 183let t = "<title>\nwelcome\n</title>" 184$ put =t 185normal ! $vaty 186call assert_equal ( "<title>\nwelcome\n</title>" , @", e ) 187 188" copy the outer tag block from a tag without an end tag 189let t = "<html>\n<title>welcome\n</html>" 190$ put =t 191normal ! k$vaty 192call assert_equal ( "<html>\n<title>welcome\n</html>" , @", e ) 193 194" nested tag that has < in a different line from > 195let t = "<div><div\n></div></div>" 196$ put =t 197normal ! k0vaty 198call assert_equal ( "<div><div\n></div></div>" , @", e ) 199 200" nested tag with attribute that has < in a different line from > 201let t = "<div><div\nattr=\"attr\"\n></div></div>" 202$ put =t 203normal ! 2k0vaty 204call assert_equal ( "<div><div\nattr=\"attr\"\n></div></div>" , @", e ) 205 206" tag, that includes a > in some attribute 207let t = "<div attr=\"attr >> foo >> bar \">Hello</div>" 208$ put =t 209normal ! fHyit 210call assert_equal ( "Hello" , @", e ) 211 212" tag, that includes a > in some attribute 213let t = "<div attr='attr >> foo >> bar '>Hello 123</div>" 214$ put =t 215normal ! fHyit 216call assert_equal ( "Hello 123" , @", e ) 217 218set quoteescape & 219 220" this was going beyond the end of the line 221 %del 222sil ! norm i"\ 223sil ! norm i"\ 224sil ! norm i"\ 225call assert_equal ( '"\' , getline ( 1 )) 226 227bwipe ! 228endfor 229 230set enc = utf-8 231endfunc 232 233func Test_empty_html_tag () 234new 235call setline ( 1 , '<div></div>' ) 236normal 0citxxx 237call assert_equal ( '<div>xxx</div>' , getline ( 1 )) 238 239call setline ( 1 , '<div></div>' ) 240normal 0f<cityyy 241call assert_equal ( '<div>yyy</div>' , getline ( 1 )) 242 243call setline ( 1 , '<div></div>' ) 244normal 0f<vitsaaa 245call assert_equal ( 'aaa' , getline ( 1 )) 246 247" selecting a tag block in a non-empty blank line should fail 248call setline ( 1 , ' ' ) 249call assert_beeps ( 'normal $vaty' ) 250 251bwipe ! 252endfunc 253 254" Tests for match() and matchstr() 255func Test_match () 256call assert_equal ( "b" , matchstr ( "abcd" , "." , 0 , 2 )) 257call assert_equal ( "bc" , matchstr ( "abcd" , ".." , 0 , 2 )) 258call assert_equal ( "c" , matchstr ( "abcd" , "." , 2 , 0 )) 259call assert_equal ( "a" , matchstr ( "abcd" , "." , 0 , -1 )) 260call assert_equal ( -1 , match ( "abcd" , "." , 0 , 5 )) 261call assert_equal ( 0 , match ( "abcd" , "." , 0 , -1 )) 262call assert_equal ( 0 , match ( 'abc' , '.' , 0 , 1 )) 263call assert_equal ( 1 , match ( 'abc' , '.' , 0 , 2 )) 264call assert_equal ( 2 , match ( 'abc' , '.' , 0 , 3 )) 265call assert_equal ( -1 , match ( 'abc' , '.' , 0 , 4 )) 266call assert_equal ( 1 , match ( 'abc' , '.' , 1 , 1 )) 267call assert_equal ( 2 , match ( 'abc' , '.' , 2 , 1 )) 268call assert_equal ( -1 , match ( 'abc' , '.' , 3 , 1 )) 269call assert_equal ( 3 , match ( 'abc' , '$' , 0 , 1 )) 270call assert_equal ( -1 , match ( 'abc' , '$' , 0 , 2 )) 271call assert_equal ( 3 , match ( 'abc' , '$' , 1 , 1 )) 272call assert_equal ( 3 , match ( 'abc' , '$' , 2 , 1 )) 273call assert_equal ( 3 , match ( 'abc' , '$' , 3 , 1 )) 274call assert_equal ( -1 , match ( 'abc' , '$' , 4 , 1 )) 275call assert_equal ( 0 , match ( 'abc' , '\zs' , 0 , 1 )) 276call assert_equal ( 1 , match ( 'abc' , '\zs' , 0 , 2 )) 277call assert_equal ( 2 , match ( 'abc' , '\zs' , 0 , 3 )) 278call assert_equal ( 3 , match ( 'abc' , '\zs' , 0 , 4 )) 279call assert_equal ( -1 , match ( 'abc' , '\zs' , 0 , 5 )) 280call assert_equal ( 1 , match ( 'abc' , '\zs' , 1 , 1 )) 281call assert_equal ( 2 , match ( 'abc' , '\zs' , 2 , 1 )) 282call assert_equal ( 3 , match ( 'abc' , '\zs' , 3 , 1 )) 283call assert_equal ( -1 , match ( 'abc' , '\zs' , 4 , 1 )) 284endfunc 285 286" This was causing an illegal memory access 287func Test_inner_tag () 288new 289norm ixxx 290call feedkeys ( "v" , 'xt' ) 291insert 292x 293x 294. 295norm it 296q ! 297endfunc 298 299func Test_sentence () 300enew ! 301call setline ( 1 , 'A sentence. A sentence? A sentence!' ) 302 303normal yis 304call assert_equal ( 'A sentence.' , @") 305normal yas 306call assert_equal ( 'A sentence. ' , @") 307 308normal ) 309 310normal yis 311call assert_equal ( 'A sentence?' , @") 312normal yas 313call assert_equal ( 'A sentence? ' , @") 314 315normal ) 316 317normal yis 318call assert_equal ( 'A sentence!' , @") 319normal yas 320call assert_equal ( ' A sentence!' , @") 321 322normal 0 323normal 2yis 324call assert_equal ( 'A sentence. ' , @") 325normal 3yis 326call assert_equal ( 'A sentence. A sentence?' , @") 327normal 2yas 328call assert_equal ( 'A sentence. A sentence? ' , @") 329 330 %delete _ 331endfunc 332 333func Test_sentence_with_quotes () 334enew ! 335call setline ( 1 , 'A "sentence." A sentence.' ) 336 337normal yis 338call assert_equal ( 'A "sentence."' , @") 339normal yas 340call assert_equal ( 'A "sentence." ' , @") 341 342normal ) 343 344normal yis 345call assert_equal ( 'A sentence.' , @") 346normal yas 347call assert_equal ( ' A sentence.' , @") 348 349 %delete _ 350endfunc 351 352func Test_sentence_with_cursor_on_delimiter () 353enew ! 354call setline ( 1 , "A '([sentence.])' A sentence." ) 355 356normal ! 15|yis 357call assert_equal ( "A '([sentence.])'" , @") 358normal ! 15|yas 359call assert_equal ( "A '([sentence.])' " , @") 360 361normal ! 16|yis 362call assert_equal ( "A '([sentence.])'" , @") 363normal ! 16|yas 364call assert_equal ( "A '([sentence.])' " , @") 365 366normal ! 17|yis 367call assert_equal ( "A '([sentence.])'" , @") 368normal ! 17|yas 369call assert_equal ( "A '([sentence.])' " , @") 370 371" don't get stuck on a quote at the start of a sentence 372 %delete _ 373call setline ( 1 , [ 'A sentence.' , '"A sentence"?' , 'A sentence!' ]) 374normal gg)) 375call assert_equal ( 3 , getcurpos ()[ 1 ]) 376 377 %delete _ 378call setline ( 1 , [ 'A sentence.' , "'A sentence'?" , 'A sentence!' ]) 379normal gg)) 380call assert_equal ( 3 , getcurpos ()[ 1 ]) 381 382 %delete _ 383endfunc 384 385" Test for the paragraph (ap) text object 386func Test_paragraph () 387new 388call setline ( 1 , [ 'First line.' , 'Second line.' , 'Third line.' ]) 389call cursor ( 2 , 1 ) 390normal vapy 391call assert_equal ( "First line.\nSecond line.\nThird line.\n" , @") 392 393call cursor ( 2 , 1 ) 394call assert_beeps ( 'normal vapapy' ) 395 396call setline ( 1 , [ 'First line.' , 'Second line.' , ' ' , '' ]) 397call cursor ( 1 , 1 ) 398normal vapy 399call assert_equal ( "First line.\nSecond line.\n \n\n" , @") 400 401call setline ( 1 , [ '' , '' , '' , 'First line.' , 'Second line.' ]) 402call cursor ( 2 , 1 ) 403normal yap 404call assert_equal ( "\n\n\nFirst line.\nSecond line.\n" , @") 405call assert_beeps ( 'normal 3yap' ) 406exe "normal \<C-C>" 407 408 %d 409call setline ( 1 , [ ' ' , ' ' , ' ' ]) 410call cursor ( 2 , 1 ) 411normal Vipy 412call assert_equal ( " \n \n \n" , @") 413call cursor ( 2 , 1 ) 414call assert_beeps ( "normal Vipip" ) 415exe "normal \<C-C>" 416 417bw ! 418endfunc 419 420" Tests for text object aw 421func Test_textobj_a_word () 422new 423call append ( 0 , [ 'foobar,eins,foobar' , 'foo,zwei,foo ' ]) 424" diw 425norm ! 1gg0diw 426call assert_equal ([ ',eins,foobar' , 'foo,zwei,foo ' , '' ], getline ( 1 , '$' )) 427" daw 428norm ! 2ggEdaw 429call assert_equal ([ ',eins,foobar' , 'foo,zwei,' , '' ], getline ( 1 , '$' )) 430" daw the last word in a line 431call setline ( 1 , [ 'foo bar' , 'foo bar' , '' ]) 432call cursor ( 1 , 5 ) 433normal daw 434call assert_equal ( 'foo' , getline ( 1 )) 435" aw in visual mode 436call cursor ( 2 , 5 ) 437normal ! vawx 438call assert_equal ( 'foo' , getline ( 2 )) 439 %d 440call append ( 0 , [ "foo\teins\tfoobar" , "foo\tzwei\tfoo " ]) 441" diW 442norm ! 2ggwd2iW 443call assert_equal ([ 'foo eins foobar' , 'foo foo ' , '' ], getline ( 1 , '$' )) 444" daW 445norm ! 1ggd2aW 446call assert_equal ([ 'foobar' , 'foo foo ' , '' ], getline ( 1 , '$' )) 447 448 %d 449call append ( 0 , [ "foo\teins\tfoobar" , "foo\tzwei\tfoo " ]) 450" aw in visual line mode switches to characterwise mode 451norm ! 2gg$Vawd 452call assert_equal ([ 'foo eins foobar' , 'foo zwei foo' ], getline ( 1 , '$' )) 453norm ! 1gg$Viwd 454call assert_equal ([ 'foo eins ' , 'foo zwei foo' ], getline ( 1 , '$' )) 455 456" visually selecting a tab before a word with 'selection' set to 'exclusive' 457set selection = exclusive 458normal gg3lvlawy 459call assert_equal ( "\teins" , @") 460" visually selecting a tab before a word with 'selection' set to 'inclusive' 461set selection = inclusive 462normal gg3lvlawy 463call assert_equal ( "\teins\t" , @") 464set selection & 465 466" selecting a word with no non-space characters in a buffer fails 467 %d 468call setline ( 1 , ' ' ) 469call assert_beeps ( 'normal 3lyaw' ) 470 471" visually selecting words backwards with no more words to select 472call setline ( 1 , 'one two' ) 473call assert_beeps ( 'normal 2lvh2aw' ) 474exe "normal \<C-C>" 475call assert_beeps ( 'normal $vh3aw' ) 476exe "normal \<C-C>" 477call setline ( 1 , [ '' , 'one two' ]) 478call assert_beeps ( 'normal 2G2lvh3aw' ) 479exe "normal \<C-C>" 480 481" selecting words forward with no more words to select 482 %d 483call setline ( 1 , 'one a' ) 484call assert_beeps ( 'normal 0y3aw' ) 485call setline ( 1 , 'one two ' ) 486call assert_beeps ( 'normal 0y3aw' ) 487call assert_beeps ( 'normal 03ly2aw' ) 488 489" clean up 490bw ! 491endfunc 492 493" Test for is and as text objects 494func Test_textobj_sentence () 495new 496call append ( 0 , [ 'This is a test. With some sentences!' , '' , 497 \'Even with a question? And one more. And no sentence here' ]) 498" Test for dis - does not remove trailing whitespace 499norm ! 1gg0dis 500call assert_equal ([ ' With some sentences!' , '' , 501 \'Even with a question? And one more. And no sentence here' , '' ], 502 \getline ( 1 , '$' )) 503" Test for das - removes leading whitespace 504norm ! 3ggf?ldas 505call assert_equal ([ ' With some sentences!' , '' , 506 \'Even with a question? And no sentence here' , '' ], getline ( 1 , '$' )) 507" when used in visual mode, is made characterwise 508norm ! 3gg$Visy 509call assert_equal ( 'v' , visualmode ()) 510" reset visualmode() 511norm ! 3ggVy 512norm ! 3gg$Vasy 513call assert_equal ( 'v' , visualmode ()) 514" basic testing for textobjects a< and at 515 %d 516call setline ( 1 , [ '<div> ' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ]) 517" a< 518norm ! 1gg0da< 519call assert_equal ([ ' ' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ], getline ( 1 , '$' )) 520norm ! 1pj 521call assert_equal ([ ' <div>' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ], getline ( 1 , '$' )) 522" at 523norm ! d2at 524call assert_equal ([ ' ' ], getline ( 1 , '$' )) 525 %d 526call setline ( 1 , [ '<div> ' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ]) 527" i< 528norm ! 1gg0di< 529call assert_equal ([ '<> ' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ], getline ( 1 , '$' )) 530norm ! 1Pj 531call assert_equal ([ '<div> ' , '<a href="foobar" class="foo">xyz</a>' , ' </div>' , ' ' ], getline ( 1 , '$' )) 532norm ! d2it 533call assert_equal ([ '<div></div>' , ' ' ], getline ( 1 , '$' )) 534" basic testing for a[ and i[ text object 535 %d 536call setline ( 1 , [ ' ' , '[' , 'one [two]' , 'thre' , ']' ]) 537norm ! 3gg0di[ 538call assert_equal ([ ' ' , '[' , ']' ], getline ( 1 , '$' )) 539call setline ( 1 , [ ' ' , '[' , 'one [two]' , 'thre' , ']' ]) 540norm ! 3gg0ftd2a[ 541call assert_equal ([ ' ' ], getline ( 1 , '$' )) 542 543" clean up 544bw ! 545endfunc 546 547" Test for quote (', " and `) textobjects 548func Test_textobj_quote () 549new 550 551" Test for i" when cursor is in front of a quoted object 552call append ( 0 , 'foo "bar"' ) 553norm ! 1gg0di" 554call assert_equal ([ 'foo ""' , '' ], getline ( 1 , '$' )) 555 556" Test for visually selecting an inner quote 557 %d 558" extend visual selection from one quote to the next 559call setline ( 1 , 'color "red" color "blue"' ) 560call cursor ( 1 , 7 ) 561normal v4li"y 562call assert_equal ( '"red" color "blue' , @") 563 564" try to extend visual selection from one quote to a non-existing quote 565call setline ( 1 , 'color "red" color blue' ) 566call cursor ( 1 , 7 ) 567call feedkeys ( 'v4li"y' , 'xt' ) 568call assert_equal ( '"red"' , @") 569 570" try to extend visual selection from one quote to a next partial quote 571call setline ( 1 , 'color "red" color "blue' ) 572call cursor ( 1 , 7 ) 573normal v4li"y 574call assert_equal ( '"red" color ' , @") 575 576" select a quote backwards in visual mode 577call cursor ( 1 , 12 ) 578normal vhi"y 579call assert_equal ( 'red" ' , @") 580call assert_equal ( 8 , col ( '.' )) 581 582" select a quote backwards in visual mode from outside the quote 583call cursor ( 1 , 17 ) 584normal v2hi"y 585call assert_equal ( 'red' , @") 586call assert_equal ( 8 , col ( '.' )) 587 588" visually selecting a quote with 'selection' set to 'exclusive' 589call setline ( 1 , 'He said "How are you?"' ) 590set selection = exclusive 591normal 012lv2li"y 592call assert_equal ( 'How are you?' , @") 593set selection & 594 595" try copy a quote object with a single quote in the line 596call setline ( 1 , "Smith's car" ) 597call cursor ( 1 , 6 ) 598call assert_beeps ( "normal yi'" ) 599call assert_beeps ( "normal 2lyi'" ) 600 601" selecting space before and after a quoted string 602call setline ( 1 , "some 'special' string" ) 603normal 0ya' 604call assert_equal ( "'special' " , @") 605call setline ( 1 , "some 'special'string" ) 606normal 0ya' 607call assert_equal ( " 'special'" , @") 608 609" quoted string with odd or even number of backslashes. 610call setline ( 1 , 'char *s = "foo\"bar"' ) 611normal $hhyi" 612call assert_equal ( 'foo\"bar' , @") 613call setline ( 1 , 'char *s = "foo\\"bar"' ) 614normal $hhyi" 615call assert_equal ( 'bar' , @") 616call setline ( 1 , 'char *s = "foo\\\"bar"' ) 617normal $hhyi" 618call assert_equal ( 'foo\\\"bar' , @") 619call setline ( 1 , 'char *s = "foo\\\\"bar"' ) 620normal $hhyi" 621call assert_equal ( 'bar' , @") 622 623bw ! 624endfunc 625 626" Test for i(, i<, etc. when cursor is in front of a block 627func Test_textobj_find_paren_forward () 628new 629 630" i< and a> when cursor is in front of a block 631call setline ( 1 , '#include <foo.h>' ) 632normal 0yi< 633call assert_equal ( 'foo.h' , @") 634normal 0ya> 635call assert_equal ( '<foo.h>' , @") 636 637" 2i(, 3i( in front of a block enters second/third nested '(' 638call setline ( 1 , 'foo (bar (baz (quux)))' ) 639normal 0yi) 640call assert_equal ( 'bar (baz (quux))' , @") 641normal 02yi) 642call assert_equal ( 'baz (quux)' , @") 643normal 03yi) 644call assert_equal ( 'quux' , @") 645 646" 3i( in front of a block doesn't enter third but un-nested '(' 647call setline ( 1 , 'foo (bar (baz) (quux))' ) 648normal 03di) 649call assert_equal ( 'foo (bar (baz) (quux))' , getline ( 1 )) 650normal 02di) 651call assert_equal ( 'foo (bar () (quux))' , getline ( 1 )) 652normal 0di) 653call assert_equal ( 'foo ()' , getline ( 1 )) 654 655call setline ( 1 , [ 'x" (a "b" )\' , '")' ]) 656call cursor ( 1 , 6 ) 657normal va)y 658call assert_equal ( '(a "b" )' , @") 659 660call setline ( 1 , [ 'x" [a "b" ]\' , '"]' ]) 661call cursor ( 1 , 6 ) 662normal va]y 663call assert_equal ( '[a "b" ]' , @") 664 665bw ! 666endfunc 667 668func Test_inner_block_empty_paren () 669new 670call setline ( 1 , [ "(text)()" , "" , "(text)(" , ")" , "" , "()()" , "" , "text()" ]) 671 672" Example 1 673call cursor ( 1 , 1 ) 674let @"= '' 675call assert_beeps ( ':call feedkeys("0f(viby","xt")' ) 676call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 677call assert_equal ( '(' , @") 678 679" Example 2 680call cursor ( 3 , 1 ) 681let @"= '' 682call assert_beeps ( 'call feedkeys("0f(viby", "xt")' ) 683call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 684call assert_equal ( '(' , @") 685 686" Example 3 687call cursor ( 6 , 1 ) 688let @"= '' 689call assert_beeps ( 'call feedkeys("0f(viby", "xt")' ) 690call assert_equal ( 3 , getpos ( '.' )[ 2 ]) 691call assert_equal ( '(' , @") 692 693" Change empty inner block 694call cursor ( 8 , 1 ) 695call feedkeys ( "0cibtext" , "xt" ) 696call assert_equal ( "text(text)" , getline ( '.' )) 697 698bwipe ! 699endfunc 700 701func Test_inner_block_empty_bracket () 702new 703call setline ( 1 , [ "[text][]" , "" , "[text][" , "]" , "" , "[][]" , "" , "text[]" ]) 704 705" Example 1 706call cursor ( 1 , 1 ) 707let @"= '' 708call assert_beeps ( ':call feedkeys("0f[viby","xt")' ) 709call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 710call assert_equal ( '[' , @") 711 712" Example 2 713call cursor ( 3 , 1 ) 714let @"= '' 715call assert_beeps ( 'call feedkeys("0f[viby", "xt")' ) 716call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 717call assert_equal ( '[' , @") 718 719" Example 3 720call cursor ( 6 , 1 ) 721let @"= '' 722call assert_beeps ( 'call feedkeys("0f[viby", "xt")' ) 723call assert_equal ( 3 , getpos ( '.' )[ 2 ]) 724call assert_equal ( '[' , @") 725 726" Change empty inner block 727call cursor ( 8 , 1 ) 728call feedkeys ( "0ci[text" , "xt" ) 729call assert_equal ( "text[text]" , getline ( '.' )) 730 731bwipe ! 732endfunc 733 734func Test_inner_block_empty_brace () 735new 736call setline ( 1 , [ "{text}{}" , "" , "{text}{" , "}" , "" , "{}{}" , "" , "text{}" ]) 737 738" Example 1 739call cursor ( 1 , 1 ) 740let @"= '' 741call assert_beeps ( ':call feedkeys("0f{viby","xt")' ) 742call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 743call assert_equal ( '{' , @") 744 745" Example 2 746call cursor ( 3 , 1 ) 747let @"= '' 748call assert_beeps ( 'call feedkeys("0f{viby", "xt")' ) 749call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 750call assert_equal ( '{' , @") 751 752" Example 3 753call cursor ( 6 , 1 ) 754let @"= '' 755call assert_beeps ( 'call feedkeys("0f{viby", "xt")' ) 756call assert_equal ( 3 , getpos ( '.' )[ 2 ]) 757call assert_equal ( '{' , @") 758 759" Change empty inner block 760call cursor ( 8 , 1 ) 761call feedkeys ( "0ciBtext" , "xt" ) 762call assert_equal ( "text{text}" , getline ( '.' )) 763 764bwipe ! 765endfunc 766 767func Test_inner_block_empty_lessthan () 768new 769call setline ( 1 , [ "<text><>" , "" , "<text><" , ">" , "" , "<><>" ]) 770 771" Example 1 772call cursor ( 1 , 1 ) 773let @"= '' 774call assert_beeps ( ':call feedkeys("0f<viby","xt")' ) 775call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 776call assert_equal ( '<' , @") 777 778" Example 2 779call cursor ( 3 , 1 ) 780let @"= '' 781call assert_beeps ( 'call feedkeys("0f<viby", "xt")' ) 782call assert_equal ( 7 , getpos ( '.' )[ 2 ]) 783call assert_equal ( '<' , @") 784 785" Example 3 786call cursor ( 6 , 1 ) 787let @"= '' 788call assert_beeps ( 'call feedkeys("0f<viby", "xt")' ) 789call assert_equal ( 3 , getpos ( '.' )[ 2 ]) 790call assert_equal ( '<' , @") 791bwipe ! 792endfunc 793 794" vim: shiftwidth=2 sts=2 expandtab