neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_increment.vim (24249B)


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