robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
64a301184e
master
1" Tests for using Ctrl-A/Ctrl-X 2 3func SetUp () 4new dummy 5set nrformats & vim 6set nrformats += octal 7endfunc 8 9func TearDown () 10bwipe ! 11endfunc 12 13" 1) Ctrl-A on visually selected number 14" Text: 15" foobar-10 16" Expected: 17" 1) Ctrl-A on start of line: 18" foobar-9 19" 2) Ctrl-A on visually selected "-10": 20" foobar-9 21" 3) Ctrl-A on visually selected "10": 22" foobar-11 23" 4) Ctrl-X on visually selected "-10" 24" foobar-11 25" 5) Ctrl-X on visually selected "10" 26" foobar-9 27func Test_visual_increment_01 () 28call setline ( 1 , repeat ([ "foobaar-10" ], 5 )) 29 30call cursor ( 1 , 1 ) 31exec "norm! \<C-A>" 32call assert_equal ( "foobaar-9" , getline ( '.' )) 33call assert_equal ([ 0 , 1 , 9 , 0 ], getpos ( '.' )) 34 35call cursor ( 2 , 1 ) 36exec "norm! f-v$\<C-A>" 37call assert_equal ( "foobaar-9" , getline ( '.' )) 38call assert_equal ([ 0 , 2 , 8 , 0 ], getpos ( '.' )) 39 40call cursor ( 3 , 1 ) 41exec "norm! f1v$\<C-A>" 42call assert_equal ( "foobaar-11" , getline ( '.' )) 43call assert_equal ([ 0 , 3 , 9 , 0 ], getpos ( '.' )) 44 45call cursor ( 4 , 1 ) 46exec "norm! f-v$\<C-X>" 47call assert_equal ( "foobaar-11" , getline ( '.' )) 48call assert_equal ([ 0 , 4 , 8 , 0 ], getpos ( '.' )) 49 50call cursor ( 5 , 1 ) 51exec "norm! f1v$\<C-X>" 52call assert_equal ( "foobaar-9" , getline ( '.' )) 53call assert_equal ([ 0 , 5 , 9 , 0 ], getpos ( '.' )) 54endfunc 55 56" 2) Ctrl-A on visually selected lines 57" Text: 58" 10 59" 20 60" 30 61" 40 62" 63" Expected: 64" 1) Ctrl-A on visually selected lines: 65" 11 66" 21 67" 31 68" 41 69" 70" 2) Ctrl-X on visually selected lines: 71" 9 72" 19 73" 29 74" 39 75func Test_visual_increment_02 () 76call setline ( 1 , [ "10" , "20" , "30" , "40" ]) 77exec "norm! GV3k$\<C-A>" 78call assert_equal ([ "11" , "21" , "31" , "41" ], getline ( 1 , '$' )) 79call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 80 81call setline ( 1 , [ "10" , "20" , "30" , "40" ]) 82exec "norm! GV3k$\<C-X>" 83call assert_equal ([ "9" , "19" , "29" , "39" ], getline ( 1 , '$' )) 84call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 85endfunc 86 87" 3) g Ctrl-A on visually selected lines, with non-numbers in between 88" Text: 89" 10 90" 91" 20 92" 93" 30 94" 95" 40 96" 97" Expected: 98" 1) 2 g Ctrl-A on visually selected lines: 99" 12 100" 101" 24 102" 103" 36 104" 105" 48 106" 2) 2 g Ctrl-X on visually selected lines 107" 8 108" 109" 16 110" 111" 24 112" 113" 32 114func Test_visual_increment_03 () 115call setline ( 1 , [ "10" , "" , "20" , "" , "30" , "" , "40" ]) 116exec "norm! GV6k2g\<C-A>" 117call assert_equal ([ "12" , "" , "24" , "" , "36" , "" , "48" ], getline ( 1 , '$' )) 118call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 119 120call setline ( 1 , [ "10" , "" , "20" , "" , "30" , "" , "40" ]) 121exec "norm! GV6k2g\<C-X>" 122call assert_equal ([ "8" , "" , "16" , "" , "24" , "" , "32" ], getline ( 1 , '$' )) 123call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 124endfunc 125 126" 4) Ctrl-A on non-number 127" Text: 128" foobar-10 129" Expected: 130" 1) visually select foobar: 131" foobar-10 132func Test_visual_increment_04 () 133call setline ( 1 , [ "foobar-10" ]) 134exec "norm! vf-\<C-A>" 135call assert_equal ([ "foobar-10" ], getline ( 1 , '$' )) 136" NOTE: I think this is correct behavior... 137call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 138endfunc 139 140" 5) g<Ctrl-A> on letter 141" Test: 142" a 143" a 144" a 145" a 146" Expected: 147" 1) g Ctrl-A on visually selected lines 148" b 149" c 150" d 151" e 152func Test_visual_increment_05 () 153set nrformats += alpha 154call setline ( 1 , repeat ([ "a" ], 4 )) 155exec "norm! GV3kg\<C-A>" 156call assert_equal ([ "b" , "c" , "d" , "e" ], getline ( 1 , '$' )) 157call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 158endfunc 159 160" 6) g<Ctrl-A> on letter 161" Test: 162" z 163" z 164" z 165" z 166" Expected: 167" 1) g Ctrl-X on visually selected lines 168" y 169" x 170" w 171" v 172func Test_visual_increment_06 () 173set nrformats += alpha 174call setline ( 1 , repeat ([ "z" ], 4 )) 175exec "norm! GV3kg\<C-X>" 176call assert_equal ([ "y" , "x" , "w" , "v" ], getline ( 1 , '$' )) 177call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 178endfunc 179 180" 7) <Ctrl-A> on letter 181" Test: 182" 2 183" 1 184" 0 185" -1 186" -2 187" 188" Expected: 189" 1) Ctrl-A on visually selected lines 190" 3 191" 2 192" 1 193" 0 194" -1 195" 196" 2) Ctrl-X on visually selected lines 197" 1 198" 0 199" -1 200" -2 201" -3 202func Test_visual_increment_07 () 203call setline ( 1 , [ "2" , "1" , "0" , "-1" , "-2" ]) 204exec "norm! GV4k\<C-A>" 205call assert_equal ([ "3" , "2" , "1" , "0" , "-1" ], getline ( 1 , '$' )) 206call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 207 208call setline ( 1 , [ "2" , "1" , "0" , "-1" , "-2" ]) 209exec "norm! GV4k\<C-X>" 210call assert_equal ([ "1" , "0" , "-1" , "-2" , "-3" ], getline ( 1 , '$' )) 211call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 212endfunc 213 214" 8) Block increment on 0x9 215" Text: 216" 0x9 217" 0x9 218" Expected: 219" 1) Ctrl-A on visually block selected region (cursor at beginning): 220" 0xa 221" 0xa 222" 2) Ctrl-A on visually block selected region (cursor at end) 223" 0xa 224" 0xa 225func Test_visual_increment_08 () 226call setline ( 1 , repeat ([ "0x9" ], 2 )) 227exec "norm! \<C-V>j$\<C-A>" 228call assert_equal ([ "0xa" , "0xa" ], getline ( 1 , '$' )) 229call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 230 231call setline ( 1 , repeat ([ "0x9" ], 2 )) 232exec "norm! gg$\<C-V>+\<C-A>" 233call assert_equal ([ "0xa" , "0xa" ], getline ( 1 , '$' )) 234call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 235endfunc 236 237" 9) Increment and redo 238" Text: 239" 2 240" 2 241" 242" 3 243" 3 244" 245" Expected: 246" 1) 2 Ctrl-A on first 2 visually selected lines 247" 4 248" 4 249" 2) redo (.) on 3 250" 5 251" 5 252func Test_visual_increment_09 () 253call setline ( 1 , [ "2" , "2" , "" , "3" , "3" , "" ]) 254exec "norm! ggVj2\<C-A>" 255call assert_equal ([ "4" , "4" , "" , "3" , "3" , "" ], getline ( 1 , '$' )) 256call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 257 258exec "norm! 3j." 259call assert_equal ([ "4" , "4" , "" , "5" , "5" , "" ], getline ( 1 , '$' )) 260call assert_equal ([ 0 , 4 , 1 , 0 ], getpos ( '.' )) 261endfunc 262 263" 10) sequentially decrement 1 264" Text: 265" 1 266" 1 267" 1 268" 1 269" Expected: 270" 1) g Ctrl-X on visually selected lines 271" 0 272" -1 273" -2 274" -3 275func Test_visual_increment_10 () 276call setline ( 1 , repeat ([ "1" ], 4 )) 277exec "norm! GV3kg\<C-X>" 278call assert_equal ([ "0" , "-1" , "-2" , "-3" ], getline ( 1 , '$' )) 279call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 280endfunc 281 282" 11) visually block selected indented lines 283" Text: 284" 1 285" 1 286" 1 287" 1 288" Expected: 289" 1) g Ctrl-A on block selected indented lines 290" 2 291" 1 292" 3 293" 4 294func Test_visual_increment_11 () 295call setline ( 1 , [ " 1" , "1" , " 1" , " 1" ]) 296exec "norm! f1\<C-V>3jg\<C-A>" 297call assert_equal ([ " 2" , "1" , " 3" , " 4" ], getline ( 1 , '$' )) 298call assert_equal ([ 0 , 1 , 5 , 0 ], getpos ( '.' )) 299endfunc 300 301" 12) visually selected several columns 302" Text: 303" 0 0 304" 0 0 305" 0 0 306" Expected: 307" 1) 'v' select last zero and first zeroes 308" 0 1 309" 1 0 310" 1 0 311func Test_visual_increment_12 () 312call setline ( 1 , repeat ([ "0 0" ], 3 )) 313exec "norm! $v++\<C-A>" 314call assert_equal ([ "0 1" , "1 0" , "1 0" ], getline ( 1 , '$' )) 315call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 316endfunc 317 318" 13) visually selected part of columns 319" Text: 320" max: 100px 321" max: 200px 322" max: 300px 323" max: 400px 324" Expected: 325" 1) 'v' on first two numbers Ctrl-A 326" max: 110px 327" max: 220px 328" max: 330px 329" max: 400px 330" 2) 'v' on first two numbers Ctrl-X 331" max: 90px 332" max: 190px 333" max: 290px 334" max: 400px 335func Test_visual_increment_13 () 336call setline ( 1 , [ "max: 100px" , "max: 200px" , "max: 300px" , "max: 400px" ]) 337exec "norm! f1\<C-V>l2j\<C-A>" 338call assert_equal ([ "max: 110px" , "max: 210px" , "max: 310px" , "max: 400px" ], getline ( 1 , '$' )) 339call assert_equal ([ 0 , 1 , 6 , 0 ], getpos ( '.' )) 340 341call setline ( 1 , [ "max: 100px" , "max: 200px" , "max: 300px" , "max: 400px" ]) 342exec "norm! ggf1\<C-V>l2j\<C-X>" 343call assert_equal ([ "max: 90px" , "max: 190px" , "max: 290px" , "max: 400px" ], getline ( 1 , '$' )) 344call assert_equal ([ 0 , 1 , 6 , 0 ], getpos ( '.' )) 345endfunc 346 347" 14) redo in block mode 348" Text: 349" 1 1 350" 1 1 351" Expected: 352" 1) Ctrl-a on first column, redo on second column 353" 2 2 354" 2 2 355func Test_visual_increment_14 () 356call setline ( 1 , repeat ([ "1 1" ], 2 )) 357" Nvim: "." re-executes the keysequence, so the replayed "k" needs a line 358" above: repeat from the last line, like the original. 359exec "norm! G\<C-V>k\<C-A>Gw." 360call assert_equal ([ "2 2" , "2 2" ], getline ( 1 , '$' )) 361call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 362endfunc 363 364" 15) block select single numbers 365" Text: 366" 101 367" Expected: 368" 1) Ctrl-a on visually selected zero 369" 111 370" 371" Also: 019 with "01" selected increments to "029". 372func Test_visual_increment_15 () 373call setline ( 1 , [ "101" ]) 374exec "norm! lv\<C-A>" 375call assert_equal ([ "111" ], getline ( 1 , '$' )) 376call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 377 378call setline ( 1 , [ "019" ]) 379exec "norm! 0vl\<C-A>" 380call assert_equal ( "029" , getline ( 1 )) 381 382call setline ( 1 , [ "01239" ]) 383exec "norm! 0vlll\<C-A>" 384call assert_equal ( "01249" , getline ( 1 )) 385 386call setline ( 1 , [ "01299" ]) 387exec "norm! 0vlll\<C-A>" 388call assert_equal ( "1309" , getline ( 1 )) 389endfunc 390 391" 16) increment right aligned numbers 392" Text: 393" 1 394" 19 395" 119 396" Expected: 397" 1) Ctrl-a on line selected region 398" 2 399" 20 400" 120 401func Test_visual_increment_16 () 402call setline ( 1 , [ " 1" , " 19" , " 119" ]) 403exec "norm! VG\<C-A>" 404call assert_equal ([ " 2" , " 20" , " 120" ], getline ( 1 , '$' )) 405call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 406endfunc 407 408" 17) block-wise increment and redo 409" Text: 410" 100 411" 1 412" 413" 100 414" 1 415" 416" Expected: 417" 1) Ctrl-V j $ on first block, afterwards '.' on second 418" 101 419" 2 420" 421" 101 422" 2 423func Test_visual_increment_17 () 424call setline ( 1 , [ " 100" , " 1" , "" , " 100" , " 1" ]) 425exec "norm! \<C-V>j$\<C-A>2j." 426call assert_equal ([ " 101" , " 2" , "" , " 101" , " 1" ], getline ( 1 , '$' )) 427call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( '.' )) 428endfunc 429 430" 18) repeat of g<Ctrl-a> 431" Text: 432" 0 433" 0 434" 0 435" 0 436" 437" Expected: 438" 1) V 4j g<ctrl-a>, repeat twice afterwards with . 439" 3 440" 6 441" 9 442" 12 443func Test_visual_increment_18 () 444call setline ( 1 , repeat ([ "0" ], 4 )) 445exec "norm! GV3kg\<C-A>" 446" Nvim: "." re-executes "V3kg<C-A>": replay from the last line, like the 447" original. 448exec "norm! G.G." 449call assert_equal ([ "3" , "6" , "9" , "12" ], getline ( 1 , '$' )) 450call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 451endfunc 452 453" 19) increment on number with nrformat including alpha 454" Text: 455" 1 456" 1a 457" 458" Expected: 459" 1) <Ctrl-V>j$ <ctrl-a> 460" 2 461" 2a 462func Test_visual_increment_19 () 463set nrformats += alpha 464call setline ( 1 , [ "1" , "1a" ]) 465exec "norm! \<C-V>G$\<C-A>" 466call assert_equal ([ "2" , "2a" ], getline ( 1 , '$' )) 467call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 468endfunc 469 470" 20) increment a single letter 471" Text: 472" a 473" 474" Expected: 475" 1) <Ctrl-a> and cursor is on a 476" b 477func Test_visual_increment_20 () 478set nrformats += alpha 479call setline ( 1 , [ "a" ]) 480exec "norm! \<C-A>" 481call assert_equal ([ "b" ], getline ( 1 , '$' )) 482call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 483" decrement a and A and increment z and Z 484call setline ( 1 , [ 'a' , 'A' , 'z' , 'Z' ]) 485exe "normal 1G\<C-X>2G\<C-X>3G\<C-A>4G\<C-A>" 486call assert_equal ([ 'a' , 'A' , 'z' , 'Z' ], getline ( 1 , '$' )) 487endfunc 488 489" 21) block-wise increment on part of hexadecimal 490" Text: 491" 0x123456 492" 493" Expected: 494" 1) Ctrl-V f3 <ctrl-a> 495" 0x124456 496func Test_visual_increment_21 () 497call setline ( 1 , [ "0x123456" ]) 498exec "norm! \<C-V>f3\<C-A>" 499call assert_equal ([ "0x124456" ], getline ( 1 , '$' )) 500call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 501endfunc 502 503" 22) Block increment on 0b0 504" Text: 505" 0b1 506" 0b1 507" Expected: 508" 1) Ctrl-A on visually block selected region (cursor at beginning): 509" 0b10 510" 0b10 511" 2) Ctrl-A on visually block selected region (cursor at end) 512" 0b10 513" 0b10 514func Test_visual_increment_22 () 515call setline ( 1 , repeat ([ "0b1" ], 2 )) 516exec "norm! \<C-V>j$\<C-A>" 517call assert_equal ( repeat ([ "0b10" ], 2 ), getline ( 1 , '$' )) 518call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 519 520call setline ( 1 , repeat ([ "0b1" ], 2 )) 521exec "norm! $\<C-V>+\<C-A>" 522call assert_equal ( repeat ([ "0b10" ], 2 ), getline ( 1 , '$' )) 523call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 524endfunc 525 526" 23) block-wise increment on part of binary 527" Text: 528" 0b1001 529" 530" Expected: 531" 1) Ctrl-V 5l <ctrl-a> 532" 0b1011 533func Test_visual_increment_23 () 534call setline ( 1 , [ "0b1001" ]) 535exec "norm! \<C-V>4l\<C-A>" 536call assert_equal ([ "0b1011" ], getline ( 1 , '$' )) 537call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 538endfunc 539 540" 24) increment hexadecimal 541" Text: 542" 0x0b1001 543" 544" Expected: 545" 1) <ctrl-a> 546" 0x0b1002 547func Test_visual_increment_24 () 548call setline ( 1 , [ "0x0b1001" ]) 549exec "norm! \<C-V>$\<C-A>" 550call assert_equal ([ "0x0b1002" ], getline ( 1 , '$' )) 551call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 552endfunc 553 554" 25) increment binary with nrformats including alpha 555" Text: 556" 0b1001a 557" 558" Expected: 559" 1) <ctrl-a> 560" 0b1010a 561func Test_visual_increment_25 () 562set nrformats += alpha 563call setline ( 1 , [ "0b1001a" ]) 564exec "norm! \<C-V>$\<C-A>" 565call assert_equal ([ "0b1010a" ], getline ( 1 , '$' )) 566call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 567endfunc 568 569" 26) increment binary with 32 bits 570" Text: 571" 0b11111111111111111111111111111110 572" 573" Expected: 574" 1) <ctrl-a> 575" 0b11111111111111111111111111111111 576func Test_visual_increment_26 () 577set nrformats += bin 578call setline ( 1 , [ "0b11111111111111111111111111111110" ]) 579exec "norm! \<C-V>$\<C-A>" 580call assert_equal ([ "0b11111111111111111111111111111111" ], getline ( 1 , '$' )) 581call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 582exec "norm! \<C-V>$\<C-X>" 583call assert_equal ([ "0b11111111111111111111111111111110" ], getline ( 1 , '$' )) 584set nrformats -= bin 585endfunc 586 587" 27) increment with 'rightreft', if supported 588func Test_visual_increment_27 () 589if exists ( '+rightleft' ) 590set rightleft 591call setline ( 1 , [ "1234 56" ]) 592 593exec "norm! $\<C-A>" 594call assert_equal ([ "1234 57" ], getline ( 1 , '$' )) 595call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 596 597exec "norm! \<C-A>" 598call assert_equal ([ "1234 58" ], getline ( 1 , '$' )) 599call assert_equal ([ 0 , 1 , 7 , 0 ], getpos ( '.' )) 600set norightleft 601endif 602endfunc 603 604" Tab code and linewise-visual inc/dec 605func Test_visual_increment_28 () 606call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 607exec "norm! Vj\<C-A>" 608call assert_equal ([ "x\<TAB>11" , "\<TAB>0" ], getline ( 1 , '$' )) 609call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 610 611call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 612exec "norm! ggVj\<C-X>" 613call assert_equal ([ "x\<TAB>9" , "\<TAB>-2" ], getline ( 1 , '$' )) 614call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 615endfunc 616 617" Tab code and linewise-visual inc/dec with 'nrformats'+=alpha 618func Test_visual_increment_29 () 619set nrformats += alpha 620call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 621exec "norm! Vj\<C-A>" 622call assert_equal ([ "y\<TAB>10" , "\<TAB>0" ], getline ( 1 , '$' )) 623call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 624 625call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 626exec "norm! ggVj\<C-X>" 627call assert_equal ([ "w\<TAB>10" , "\<TAB>-2" ], getline ( 1 , '$' )) 628call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 629endfunc 630 631" Tab code and character-visual inc/dec 632func Test_visual_increment_30 () 633call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 634exec "norm! f1vjf1\<C-A>" 635call assert_equal ([ "x\<TAB>11" , "\<TAB>0" ], getline ( 1 , '$' )) 636call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 637 638call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 639exec "norm! ggf1vjf1\<C-X>" 640call assert_equal ([ "x\<TAB>9" , "\<TAB>-2" ], getline ( 1 , '$' )) 641call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 642endfunc 643 644" Tab code and blockwise-visual inc/dec 645func Test_visual_increment_31 () 646call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 647exec "norm! f1\<C-V>jl\<C-A>" 648call assert_equal ([ "x\<TAB>11" , "\<TAB>0" ], getline ( 1 , '$' )) 649call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 650 651call setline ( 1 , [ "x\<TAB>10" , "\<TAB>-1" ]) 652exec "norm! ggf1\<C-V>jl\<C-X>" 653call assert_equal ([ "x\<TAB>9" , "\<TAB>-2" ], getline ( 1 , '$' )) 654call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 655endfunc 656 657" Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' 658func Test_visual_increment_32 () 65928 vnew dummy_31 660set linebreak showbreak = + 661call setline ( 1 , [ "x\<TAB>\<TAB>\<TAB>10" , "\<TAB>\<TAB>\<TAB>\<TAB>-1" ]) 662exec "norm! ggf0\<C-V>jg_\<C-X>" 663call assert_equal ([ "x\<TAB>\<TAB>\<TAB>1-1" , "\<TAB>\<TAB>\<TAB>\<TAB>-2" ], getline ( 1 , '$' )) 664call assert_equal ([ 0 , 1 , 6 , 0 ], getpos ( '.' )) 665bwipe ! 666endfunc 667 668" Tab code and blockwise-visual increment with $ 669func Test_visual_increment_33 () 670call setline ( 1 , [ "\<TAB>123" , "456" ]) 671exec "norm! gg0\<C-V>j$\<C-A>" 672call assert_equal ([ "\<TAB>124" , "457" ], getline ( 1 , '$' )) 673call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 674endfunc 675 676" Tab code and blockwise-visual increment and redo 677func Test_visual_increment_34 () 678call setline ( 1 , [ "\<TAB>123" , " 456789" ]) 679exec "norm! gg0\<C-V>j\<C-A>" 680call assert_equal ([ "\<TAB>123" , " 457789" ], getline ( 1 , '$' )) 681call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 682 683exec "norm! .." 684call assert_equal ([ "\<TAB>123" , " 459789" ], getline ( 1 , '$' )) 685call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 686endfunc 687 688" Tab code, spaces and character-visual increment and redo 689func Test_visual_increment_35 () 690call setline ( 1 , [ "\<TAB>123" , " 123" , "\<TAB>123" , "\<TAB>123" ]) 691" Nvim: "." re-executes "vjf3<C-A>"; the replayed "f3" fails (the numbers 692" are now "124"), aborting the replay and (in :norm) flushing the rest. 693exec "norm! ggvjf3\<C-A>..." 694exe "norm! \<Esc>" 695call assert_equal ([ "\<TAB>124" , " 124" , "\<TAB>123" , "\<TAB>123" ], getline ( 1 , '$' )) 696call assert_equal ([ 0 , 2 , 9 , 0 ], getpos ( '.' )) 697endfunc 698 699" Tab code, spaces and blockwise-visual increment and redo 700func Test_visual_increment_36 () 701call setline ( 1 , [ " 123" , "\<TAB>456789" ]) 702exec "norm! G0\<C-V>kl\<C-A>" 703call assert_equal ([ " 123" , "\<TAB>556789" ], getline ( 1 , '$' )) 704call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 705 706" Nvim: "." re-executes "<C-V>kl<C-A>": replay from the last line, like the 707" original. 708exec "norm! G0.G0.G0." 709call assert_equal ([ " 123" , "\<TAB>856789" ], getline ( 1 , '$' )) 710call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 711endfunc 712 713" block-wise increment and dot-repeat 714" Text: 715" 1 23 716" 4 56 717" 718" Expected: 719" 1) f2 Ctrl-V jl <ctrl-a>, repeat twice afterwards with . 720" 1 26 721" 4 59 722" 723" Try with and without indent. 724func Test_visual_increment_37 () 725call setline ( 1 , [ " 1 23" , " 4 56" ]) 726exec "norm! ggf2\<C-V>jl\<C-A>.." 727call assert_equal ([ " 1 26" , " 4 59" ], getline ( 1 , 2 )) 728 729call setline ( 1 , [ "1 23" , "4 56" ]) 730exec "norm! ggf2\<C-V>jl\<C-A>.." 731call assert_equal ([ "1 26" , "4 59" ], getline ( 1 , 2 )) 732endfunc 733 734" Check redo after the normal mode increment 735func Test_visual_increment_38 () 736exec "norm! i10\<ESC>5\<C-A>." 737call assert_equal ([ "20" ], getline ( 1 , '$' )) 738call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 739endfunc 740 741" Test what patch 7.3.414 fixed. Ctrl-A on "000" drops the leading zeros. 742func Test_normal_increment_01 () 743call setline ( 1 , "000" ) 744exec "norm! gg0\<C-A>" 745call assert_equal ( "001" , getline ( 1 )) 746 747call setline ( 1 , "000" ) 748exec "norm! gg$\<C-A>" 749call assert_equal ( "001" , getline ( 1 )) 750 751call setline ( 1 , "001" ) 752exec "norm! gg0\<C-A>" 753call assert_equal ( "002" , getline ( 1 )) 754 755call setline ( 1 , "001" ) 756exec "norm! gg$\<C-A>" 757call assert_equal ( "002" , getline ( 1 )) 758endfunc 759 760" Test a regression of patch 7.4.1087 fixed. 761func Test_normal_increment_02 () 762call setline ( 1 , [ "hello 10" , "world" ]) 763exec "norm! ggl\<C-A>jx" 764call assert_equal ([ "hello 11" , "worl" ], getline ( 1 , '$' )) 765call assert_equal ([ 0 , 2 , 4 , 0 ], getpos ( '.' )) 766endfunc 767 768" The test35 unified to this file. 769func Test_normal_increment_03 () 770call setline ( 1 , [ "100 0x100 077 0" , 771 \"100 0x100 077 " , 772 \"100 0x100 077 0xfF 0xFf" , 773 \"100 0x100 077 " ]) 774set nrformats = octal,hex 775exec "norm! gg\<C-A>102\<C-X>\<C-A>l\<C-X>l\<C-A>64\<C-A>128\<C-X>$\<C-X>" 776set nrformats = octal 777exec "norm! j0\<C-A>102\<C-X>\<C-A>l\<C-X>2\<C-A>w65\<C-A>129\<C-X>blx6lD" 778set nrformats = hex 779exec "norm! j0101\<C-X>l257\<C-X>\<C-A>Txldt \<C-A> \<C-X> \<C-X>" 780set nrformats = 781exec "norm! j0200\<C-X>l100\<C-X>w78\<C-X>\<C-A>k" 782call assert_equal ([ "0 0x0ff 0000 -1" , 783 \"0 1x100 0777777" , 784 \"-1 0x0 078 0xFE 0xfe" , 785 \"-100 -100x100 000 " ], getline ( 1 , '$' )) 786call assert_equal ([ 0 , 3 , 25 , 0 ], getpos ( '.' )) 787endfunc 788 789func Test_increment_empty_line () 790call setline ( 1 , [ '0' , '0' , '0' , '0' , '0' , '0' , '' ]) 791exe "normal Gvgg\<C-A>" 792call assert_equal ([ '1' , '1' , '1' , '1' , '1' , '1' , '' ], getline ( 1 , 7 )) 793 794" Ctrl-A/Ctrl-X should do nothing in operator pending mode 795 %d 796call setline ( 1 , 'one two' ) 797exe "normal! c\<C-A>l" 798exe "normal! c\<C-X>l" 799call assert_equal ( 'one two' , getline ( 1 )) 800endfunc 801 802" Try incrementing/decrementing a non-digit/alpha character 803func Test_increment_special_char () 804call setline ( 1 , '!' ) 805call assert_beeps ( "normal \<C-A>" ) 806call assert_beeps ( "normal \<C-X>" ) 807endfunc 808 809" Try incrementing/decrementing a number when nrformats contains unsigned 810func Test_increment_unsigned () 811set nrformats += unsigned 812 813call setline ( 1 , '0' ) 814exec "norm! gg0\<C-X>" 815call assert_equal ( '0' , getline ( 1 )) 816 817call setline ( 1 , '3' ) 818exec "norm! gg010\<C-X>" 819call assert_equal ( '0' , getline ( 1 )) 820 821call setline ( 1 , '-0' ) 822exec "norm! gg0\<C-X>" 823call assert_equal ( "-0" , getline ( 1 )) 824 825call setline ( 1 , '-11' ) 826exec "norm! gg08\<C-X>" 827call assert_equal ( '-3' , getline ( 1 )) 828 829" NOTE: 18446744073709551615 == 2^64 - 1 830call setline ( 1 , '18446744073709551615' ) 831exec "norm! gg0\<C-A>" 832call assert_equal ( '18446744073709551615' , getline ( 1 )) 833 834call setline ( 1 , '-18446744073709551615' ) 835exec "norm! gg0\<C-A>" 836call assert_equal ( '-18446744073709551615' , getline ( 1 )) 837 838call setline ( 1 , '-18446744073709551614' ) 839exec "norm! gg08\<C-A>" 840call assert_equal ( '-18446744073709551615' , getline ( 1 )) 841 842call setline ( 1 , '-1' ) 843exec "norm! gg0\<C-A>" 844call assert_equal ( '-2' , getline ( 1 )) 845 846call setline ( 1 , '-3' ) 847exec "norm! gg08\<C-A>" 848call assert_equal ( '-11' , getline ( 1 )) 849 850set nrformats -= unsigned 851endfunc 852 853" Try incrementing/decrementing a number when nrformats contains blank 854func Test_increment_blank () 855set nrformats += blank 856 857" Signed 858call setline ( 1 , '0' ) 859exec "norm! gg0\<C-X>" 860call assert_equal ( '-1' , getline ( 1 )) 861 862call setline ( 1 , '3' ) 863exec "norm! gg010\<C-X>" 864call assert_equal ( '-7' , getline ( 1 )) 865 866call setline ( 1 , '-0' ) 867exec "norm! gg0\<C-X>" 868call assert_equal ( "-1" , getline ( 1 )) 869 870" Unsigned 871" NOTE: 18446744073709551615 == 2^64 - 1 872call setline ( 1 , 'a-18446744073709551615' ) 873exec "norm! gg0\<C-A>" 874call assert_equal ( 'a-18446744073709551615' , getline ( 1 )) 875 876call setline ( 1 , 'a-18446744073709551615' ) 877exec "norm! gg0\<C-A>" 878call assert_equal ( 'a-18446744073709551615' , getline ( 1 )) 879 880call setline ( 1 , 'a-18446744073709551614' ) 881exec "norm! gg08\<C-A>" 882call assert_equal ( 'a-18446744073709551615' , getline ( 1 )) 883 884call setline ( 1 , 'a-1' ) 885exec "norm! gg0\<C-A>" 886call assert_equal ( 'a-2' , getline ( 1 )) 887 888set nrformats -= blank 889endfunc 890 891func Test_in_decrement_large_number () 892" NOTE: 18446744073709551616 == 2^64 893call setline ( 1 , '18446744073709551616' ) 894exec "norm! gg0\<C-X>" 895call assert_equal ( '18446744073709551615' , getline ( 1 )) 896 897exec "norm! gg0\<C-X>" 898call assert_equal ( '18446744073709551614' , getline ( 1 )) 899 900exec "norm! gg0\<C-A>" 901call assert_equal ( '18446744073709551615' , getline ( 1 )) 902 903exec "norm! gg0\<C-A>" 904call assert_equal ( '-18446744073709551615' , getline ( 1 )) 905endfunc 906 907func Test_normal_increment_with_virtualedit () 908set virtualedit = all 909 910call setline ( 1 , [ "\<TAB>1" ]) 911exec "norm! 0\<C-A>" 912call assert_equal ( "\<TAB>2" , getline ( 1 )) 913call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 914 915call setline ( 1 , [ "\<TAB>1" ]) 916exec "norm! 0l\<C-A>" 917call assert_equal ( "\<TAB>2" , getline ( 1 )) 918call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 919 920call setline ( 1 , [ "\<TAB>1" ]) 921exec "norm! 07l\<C-A>" 922call assert_equal ( "\<TAB>2" , getline ( 1 )) 923call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 924 925call setline ( 1 , [ "\<TAB>1" ]) 926exec "norm! 0w\<C-A>" 927call assert_equal ( "\<TAB>2" , getline ( 1 )) 928call assert_equal ([ 0 , 1 , 2 , 0 ], getpos ( '.' )) 929 930call setline ( 1 , [ "\<TAB>1" ]) 931exec "norm! 0wl\<C-A>" 932call assert_equal ( "\<TAB>1" , getline ( 1 )) 933call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 934 935call setline ( 1 , [ "\<TAB>1" ]) 936exec "norm! 0w30l\<C-A>" 937call assert_equal ( "\<TAB>1" , getline ( 1 )) 938call assert_equal ([ 0 , 1 , 3 , 29 ], getpos ( '.' )) 939 940set virtualedit & 941endfunc 942 943" Test for incrementing a signed hexadecimal and octal number 944func Test_normal_increment_signed_hexoct_nr () 945new 946" negative sign before a hex number should be ignored 947call setline ( 1 , [ "-0x9" ]) 948exe "norm \<C-A>" 949call assert_equal ([ "-0xa" ], getline ( 1 , '$' )) 950exe "norm \<C-X>" 951call assert_equal ([ "-0x9" ], getline ( 1 , '$' )) 952call setline ( 1 , [ "-007" ]) 953exe "norm \<C-A>" 954call assert_equal ([ "-010" ], getline ( 1 , '$' )) 955exe "norm \<C-X>" 956call assert_equal ([ "-007" ], getline ( 1 , '$' )) 957bw ! 958endfunc 959 960" vim: shiftwidth=2 sts=2 expandtab