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