Bram Moolenaar | aaad995 | 2020-05-31 15:08:59 +0200 | [diff] [blame] | 1 | " Tests for using Ctrl-A/Ctrl-X |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 2 | |
| 3 | func SetUp() |
| 4 | new dummy |
| 5 | set nrformats&vim |
| 6 | endfunc |
| 7 | |
| 8 | func TearDown() |
| 9 | bwipe! |
| 10 | endfunc |
| 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 |
| 26 | func 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('.')) |
| 53 | endfunc |
| 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 |
| 74 | func 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('.')) |
| 84 | endfunc |
| 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 |
| 113 | func 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('.')) |
| 123 | endfunc |
| 124 | |
| 125 | " 4) Ctrl-A on non-number |
| 126 | " Text: |
| 127 | " foobar-10 |
| 128 | " Expected: |
| 129 | " 1) visually select foobar: |
| 130 | " foobar-10 |
| 131 | func 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... |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 136 | call assert_equal([0, 1, 1, 0], getpos('.')) |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 137 | endfunc |
| 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 |
| 151 | func 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('.')) |
| 157 | endfunc |
| 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 |
| 171 | func 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('.')) |
| 177 | endfunc |
| 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 |
| 201 | func 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('.')) |
| 211 | endfunc |
| 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 |
| 224 | func 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('.')) |
| 234 | endfunc |
| 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 |
| 251 | func 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('.')) |
| 260 | endfunc |
| 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 |
| 274 | func 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('.')) |
| 279 | endfunc |
| 280 | |
| 281 | " 11) visually block selected indented lines |
| 282 | " Text: |
| 283 | " 1 |
| 284 | " 1 |
| 285 | " 1 |
| 286 | " 1 |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 287 | " Expected: |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 288 | " 1) g Ctrl-A on block selected indented lines |
| 289 | " 2 |
| 290 | " 1 |
| 291 | " 3 |
| 292 | " 4 |
| 293 | func 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('.')) |
| 298 | endfunc |
| 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 |
| 310 | func 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('.')) |
| 315 | endfunc |
| 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 |
| 334 | func 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('.')) |
| 344 | endfunc |
| 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 |
| 354 | func 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('.')) |
| 359 | endfunc |
| 360 | |
| 361 | " 15) block select single numbers |
| 362 | " Text: |
| 363 | " 101 |
| 364 | " Expected: |
| 365 | " 1) Ctrl-a on visually selected zero |
| 366 | " 111 |
Bram Moolenaar | 5fe6bdf | 2017-12-05 17:22:12 +0100 | [diff] [blame] | 367 | " |
| 368 | " Also: 019 with "01" selected increments to "029". |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 369 | func 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('.')) |
Bram Moolenaar | 5fe6bdf | 2017-12-05 17:22:12 +0100 | [diff] [blame] | 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)) |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 386 | endfunc |
| 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 |
| 398 | func 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('.')) |
| 403 | endfunc |
| 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 |
| 420 | func 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('.')) |
| 425 | endfunc |
| 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 |
| 440 | func 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('.')) |
| 446 | endfunc |
| 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 |
| 457 | func 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('.')) |
| 463 | endfunc |
| 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 |
| 472 | func 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('.')) |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 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, '$')) |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 482 | endfunc |
| 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 |
| 491 | func 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('.')) |
| 496 | endfunc |
| 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 |
| 509 | func 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('.')) |
| 519 | endfunc |
| 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 |
| 528 | func 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('.')) |
| 533 | endfunc |
| 534 | |
| 535 | " 24) increment hexadecimal |
| 536 | " Text: |
| 537 | " 0x0b1001 |
| 538 | " |
| 539 | " Expected: |
| 540 | " 1) <ctrl-a> |
| 541 | " 0x0b1002 |
| 542 | func 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('.')) |
| 547 | endfunc |
| 548 | |
| 549 | " 25) increment binary with nrformats including alpha |
| 550 | " Text: |
| 551 | " 0b1001a |
| 552 | " |
| 553 | " Expected: |
| 554 | " 1) <ctrl-a> |
| 555 | " 0b1010a |
| 556 | func 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('.')) |
| 562 | endfunc |
| 563 | |
| 564 | " 26) increment binary with 32 bits |
| 565 | " Text: |
| 566 | " 0b11111111111111111111111111111110 |
| 567 | " |
| 568 | " Expected: |
| 569 | " 1) <ctrl-a> |
| 570 | " 0b11111111111111111111111111111111 |
| 571 | func Test_visual_increment_26() |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 572 | set nrformats+=bin |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 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('.')) |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 577 | exec "norm! \<C-V>$\<C-X>" |
| 578 | call assert_equal(["0b11111111111111111111111111111110"], getline(1, '$')) |
| 579 | set nrformats-=bin |
Bram Moolenaar | 44132a1 | 2016-01-09 21:09:10 +0100 | [diff] [blame] | 580 | endfunc |
| 581 | |
Bram Moolenaar | 6a3c8af | 2016-01-10 14:13:40 +0100 | [diff] [blame] | 582 | " 27) increment with 'rightreft', if supported |
| 583 | func 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 |
| 597 | endfunc |
| 598 | |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 599 | " Tab code and linewise-visual inc/dec |
| 600 | func 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('.')) |
| 610 | endfunc |
| 611 | |
| 612 | " Tab code and linewise-visual inc/dec with 'nrformats'+=alpha |
| 613 | func 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('.')) |
| 624 | endfunc |
| 625 | |
| 626 | " Tab code and character-visual inc/dec |
| 627 | func 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('.')) |
| 637 | endfunc |
| 638 | |
| 639 | " Tab code and blockwise-visual inc/dec |
| 640 | func 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('.')) |
| 650 | endfunc |
| 651 | |
| 652 | " Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' |
| 653 | func 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! |
| 661 | endfunc |
| 662 | |
| 663 | " Tab code and blockwise-visual increment with $ |
| 664 | func 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('.')) |
| 669 | endfunc |
| 670 | |
| 671 | " Tab code and blockwise-visual increment and redo |
| 672 | func 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('.')) |
| 681 | endfunc |
| 682 | |
| 683 | " Tab code, spaces and character-visual increment and redo |
| 684 | func 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('.')) |
| 689 | endfunc |
| 690 | |
| 691 | " Tab code, spaces and blockwise-visual increment and redo |
| 692 | func 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('.')) |
| 701 | endfunc |
| 702 | |
| 703 | " block-wise increment and dot-repeat |
Bram Moolenaar | e1edc1c | 2016-01-10 20:08:03 +0100 | [diff] [blame] | 704 | " Text: |
| 705 | " 1 23 |
| 706 | " 4 56 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 707 | " |
Bram Moolenaar | e1edc1c | 2016-01-10 20:08:03 +0100 | [diff] [blame] | 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. |
Bram Moolenaar | d79e550 | 2016-01-10 22:13:02 +0100 | [diff] [blame] | 714 | func Test_visual_increment_37() |
Bram Moolenaar | e1edc1c | 2016-01-10 20:08:03 +0100 | [diff] [blame] | 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)) |
| 722 | endfunc |
| 723 | |
Bram Moolenaar | ef2b503 | 2016-01-12 22:20:58 +0100 | [diff] [blame] | 724 | " Check redo after the normal mode increment |
| 725 | func 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('.')) |
| 729 | endfunc |
| 730 | |
Bram Moolenaar | 3fc3e14 | 2016-02-04 21:53:33 +0100 | [diff] [blame] | 731 | " Test what patch 7.3.414 fixed. Ctrl-A on "000" drops the leading zeros. |
| 732 | func 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)) |
| 748 | endfunc |
| 749 | |
Bram Moolenaar | 8e08125 | 2016-03-21 23:13:32 +0100 | [diff] [blame] | 750 | " Test a regression of patch 7.4.1087 fixed. |
| 751 | func 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('.')) |
| 756 | endfunc |
| 757 | |
Bram Moolenaar | 52df117 | 2016-06-26 19:38:19 +0200 | [diff] [blame] | 758 | " The test35 unified to this file. |
| 759 | func 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('.')) |
| 777 | endfunc |
| 778 | |
Bram Moolenaar | 5fe6bdf | 2017-12-05 17:22:12 +0100 | [diff] [blame] | 779 | func Test_increment_empty_line() |
Bram Moolenaar | 5fe6bdf | 2017-12-05 17:22:12 +0100 | [diff] [blame] | 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)) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 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)) |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 790 | endfunc |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 791 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 792 | " Try incrementing/decrementing a non-digit/alpha character |
| 793 | func Test_increment_special_char() |
| 794 | call setline(1, '!') |
| 795 | call assert_beeps("normal \<C-A>") |
| 796 | call assert_beeps("normal \<C-X>") |
Bram Moolenaar | 5fe6bdf | 2017-12-05 17:22:12 +0100 | [diff] [blame] | 797 | endfunc |
Bram Moolenaar | 8e08125 | 2016-03-21 23:13:32 +0100 | [diff] [blame] | 798 | |
Bram Moolenaar | aaad995 | 2020-05-31 15:08:59 +0200 | [diff] [blame] | 799 | " Try incrementing/decrementing a number when nrformats contains unsigned |
| 800 | func 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 |
| 841 | endfunc |
| 842 | |
distobs | 25ac6d6 | 2024-07-06 17:50:09 +0200 | [diff] [blame] | 843 | " Try incrementing/decrementing a number when nrformats contains blank |
| 844 | func Test_increment_blank() |
| 845 | set nrformats+=blank |
| 846 | |
| 847 | " Signed |
| 848 | call setline(1, '0') |
| 849 | exec "norm! gg0\<C-X>" |
| 850 | call assert_equal('-1', getline(1)) |
| 851 | |
| 852 | call setline(1, '3') |
| 853 | exec "norm! gg010\<C-X>" |
| 854 | call assert_equal('-7', getline(1)) |
| 855 | |
| 856 | call setline(1, '-0') |
| 857 | exec "norm! gg0\<C-X>" |
| 858 | call assert_equal("-1", getline(1)) |
| 859 | |
| 860 | " Unsigned |
| 861 | " NOTE: 18446744073709551615 == 2^64 - 1 |
| 862 | call setline(1, 'a-18446744073709551615') |
| 863 | exec "norm! gg0\<C-A>" |
| 864 | call assert_equal('a-18446744073709551615', getline(1)) |
| 865 | |
| 866 | call setline(1, 'a-18446744073709551615') |
| 867 | exec "norm! gg0\<C-A>" |
| 868 | call assert_equal('a-18446744073709551615', getline(1)) |
| 869 | |
| 870 | call setline(1, 'a-18446744073709551614') |
| 871 | exec "norm! gg08\<C-A>" |
| 872 | call assert_equal('a-18446744073709551615', getline(1)) |
| 873 | |
| 874 | call setline(1, 'a-1') |
| 875 | exec "norm! gg0\<C-A>" |
| 876 | call assert_equal('a-2', getline(1)) |
| 877 | |
| 878 | set nrformats-=blank |
| 879 | endfunc |
| 880 | |
Bram Moolenaar | 5fb78c3 | 2023-03-04 20:47:39 +0000 | [diff] [blame] | 881 | func Test_in_decrement_large_number() |
| 882 | " NOTE: 18446744073709551616 == 2^64 |
| 883 | call setline(1, '18446744073709551616') |
| 884 | exec "norm! gg0\<C-X>" |
| 885 | call assert_equal('18446744073709551615', getline(1)) |
| 886 | |
| 887 | exec "norm! gg0\<C-X>" |
| 888 | call assert_equal('18446744073709551614', getline(1)) |
| 889 | |
| 890 | exec "norm! gg0\<C-A>" |
| 891 | call assert_equal('18446744073709551615', getline(1)) |
| 892 | |
| 893 | exec "norm! gg0\<C-A>" |
| 894 | call assert_equal('-18446744073709551615', getline(1)) |
| 895 | endfunc |
| 896 | |
Bram Moolenaar | 6c6be9e | 2020-06-12 20:19:44 +0200 | [diff] [blame] | 897 | func Test_normal_increment_with_virtualedit() |
| 898 | set virtualedit=all |
| 899 | |
| 900 | call setline(1, ["\<TAB>1"]) |
| 901 | exec "norm! 0\<C-A>" |
| 902 | call assert_equal("\<TAB>2", getline(1)) |
| 903 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 904 | |
| 905 | call setline(1, ["\<TAB>1"]) |
| 906 | exec "norm! 0l\<C-A>" |
| 907 | call assert_equal("\<TAB>2", getline(1)) |
| 908 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 909 | |
| 910 | call setline(1, ["\<TAB>1"]) |
| 911 | exec "norm! 07l\<C-A>" |
| 912 | call assert_equal("\<TAB>2", getline(1)) |
| 913 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 914 | |
| 915 | call setline(1, ["\<TAB>1"]) |
| 916 | exec "norm! 0w\<C-A>" |
| 917 | call assert_equal("\<TAB>2", getline(1)) |
| 918 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 919 | |
| 920 | call setline(1, ["\<TAB>1"]) |
| 921 | exec "norm! 0wl\<C-A>" |
| 922 | call assert_equal("\<TAB>1", getline(1)) |
| 923 | call assert_equal([0, 1, 3, 0], getpos('.')) |
| 924 | |
| 925 | call setline(1, ["\<TAB>1"]) |
| 926 | exec "norm! 0w30l\<C-A>" |
| 927 | call assert_equal("\<TAB>1", getline(1)) |
| 928 | call assert_equal([0, 1, 3, 29], getpos('.')) |
| 929 | |
| 930 | set virtualedit& |
| 931 | endfunc |
| 932 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 933 | " Test for incrementing a signed hexadecimal and octal number |
| 934 | func Test_normal_increment_signed_hexoct_nr() |
| 935 | new |
| 936 | " negative sign before a hex number should be ignored |
| 937 | call setline(1, ["-0x9"]) |
| 938 | exe "norm \<C-A>" |
| 939 | call assert_equal(["-0xa"], getline(1, '$')) |
| 940 | exe "norm \<C-X>" |
| 941 | call assert_equal(["-0x9"], getline(1, '$')) |
| 942 | call setline(1, ["-007"]) |
| 943 | exe "norm \<C-A>" |
| 944 | call assert_equal(["-010"], getline(1, '$')) |
| 945 | exe "norm \<C-X>" |
| 946 | call assert_equal(["-007"], getline(1, '$')) |
| 947 | bw! |
| 948 | endfunc |
| 949 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 950 | " vim: shiftwidth=2 sts=2 expandtab |