robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfeat(input)!: CmdAtom event #4129764a301184e

master
24.2 KiB960 linesraw
1" Tests for using Ctrl-A/Ctrl-X
2
3func SetUp()
4  new dummy
5  set nrformats&vim
6  set nrformats+=octal
7endfunc
8
9func TearDown()
10  bwipe!
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
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('.'))
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()
356  call 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.
359  exec "norm! G\<C-V>k\<C-A>Gw."
360  call assert_equal(["2 2", "2 2"], getline(1, '$'))
361  call 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()
373  call setline(1, ["101"])
374  exec "norm! lv\<C-A>"
375  call assert_equal(["111"], getline(1, '$'))
376  call assert_equal([0, 1, 2, 0], getpos('.'))
377
378  call setline(1, ["019"])
379  exec "norm! 0vl\<C-A>"
380  call assert_equal("029", getline(1))
381
382  call setline(1, ["01239"])
383  exec "norm! 0vlll\<C-A>"
384  call assert_equal("01249", getline(1))
385
386  call setline(1, ["01299"])
387  exec "norm! 0vlll\<C-A>"
388  call 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()
402  call setline(1, ["   1", "  19", " 119"])
403  exec "norm! VG\<C-A>"
404  call assert_equal(["   2", "  20", " 120"], getline(1, '$'))
405  call 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()
424  call setline(1, [" 100", " 1", "", " 100", " 1"])
425  exec "norm! \<C-V>j$\<C-A>2j."
426  call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$'))
427  call 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()
444  call setline(1, repeat(["0"], 4))
445  exec "norm! GV3kg\<C-A>"
446  " Nvim: "." re-executes "V3kg<C-A>": replay from the last line, like the
447  " original.
448  exec "norm! G.G."
449  call assert_equal(["3", "6", "9", "12"], getline(1, '$'))
450  call 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()
463  set nrformats+=alpha
464  call setline(1, ["1", "1a"])
465  exec "norm! \<C-V>G$\<C-A>"
466  call assert_equal(["2", "2a"], getline(1, '$'))
467  call 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()
478  set nrformats+=alpha
479  call setline(1, ["a"])
480  exec "norm! \<C-A>"
481  call assert_equal(["b"], getline(1, '$'))
482  call assert_equal([0, 1, 1, 0], getpos('.'))
483  " decrement a and A and increment z and Z
484  call setline(1, ['a', 'A', 'z', 'Z'])
485  exe "normal 1G\<C-X>2G\<C-X>3G\<C-A>4G\<C-A>"
486  call 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()
497  call setline(1, ["0x123456"])
498  exec "norm! \<C-V>f3\<C-A>"
499  call assert_equal(["0x124456"], getline(1, '$'))
500  call 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()
515  call setline(1, repeat(["0b1"], 2))
516  exec "norm! \<C-V>j$\<C-A>"
517  call assert_equal(repeat(["0b10"], 2), getline(1, '$'))
518  call assert_equal([0, 1, 1, 0], getpos('.'))
519
520  call setline(1, repeat(["0b1"], 2))
521  exec "norm! $\<C-V>+\<C-A>"
522  call assert_equal(repeat(["0b10"], 2), getline(1, '$'))
523  call 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()
534  call setline(1, ["0b1001"])
535  exec "norm! \<C-V>4l\<C-A>"
536  call assert_equal(["0b1011"], getline(1, '$'))
537  call 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()
548  call setline(1, ["0x0b1001"])
549  exec "norm! \<C-V>$\<C-A>"
550  call assert_equal(["0x0b1002"], getline(1, '$'))
551  call 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()
562  set nrformats+=alpha
563  call setline(1, ["0b1001a"])
564  exec "norm! \<C-V>$\<C-A>"
565  call assert_equal(["0b1010a"], getline(1, '$'))
566  call 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()
577  set nrformats+=bin
578  call setline(1, ["0b11111111111111111111111111111110"])
579  exec "norm! \<C-V>$\<C-A>"
580  call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$'))
581  call assert_equal([0, 1, 1, 0], getpos('.'))
582  exec "norm! \<C-V>$\<C-X>"
583  call assert_equal(["0b11111111111111111111111111111110"], getline(1, '$'))
584  set nrformats-=bin
585endfunc
586
587" 27) increment with 'rightreft', if supported
588func Test_visual_increment_27()
589  if exists('+rightleft')
590    set rightleft
591    call setline(1, ["1234 56"])
592
593    exec "norm! $\<C-A>"
594    call assert_equal(["1234 57"], getline(1, '$'))
595    call assert_equal([0, 1, 7, 0], getpos('.'))
596
597    exec "norm! \<C-A>"
598    call assert_equal(["1234 58"], getline(1, '$'))
599    call assert_equal([0, 1, 7, 0], getpos('.'))
600    set norightleft
601  endif
602endfunc
603
604" Tab code and linewise-visual inc/dec
605func Test_visual_increment_28()
606  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
607  exec "norm! Vj\<C-A>"
608  call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
609  call assert_equal([0, 1, 1, 0], getpos('.'))
610
611  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
612  exec "norm! ggVj\<C-X>"
613  call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
614  call 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()
619  set nrformats+=alpha
620  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
621  exec "norm! Vj\<C-A>"
622  call assert_equal(["y\<TAB>10", "\<TAB>0"], getline(1, '$'))
623  call assert_equal([0, 1, 1, 0], getpos('.'))
624
625  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
626  exec "norm! ggVj\<C-X>"
627  call assert_equal(["w\<TAB>10", "\<TAB>-2"], getline(1, '$'))
628  call assert_equal([0, 1, 1, 0], getpos('.'))
629endfunc
630
631" Tab code and character-visual inc/dec
632func Test_visual_increment_30()
633  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
634  exec "norm! f1vjf1\<C-A>"
635  call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
636  call assert_equal([0, 1, 3, 0], getpos('.'))
637
638  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
639  exec "norm! ggf1vjf1\<C-X>"
640  call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
641  call assert_equal([0, 1, 3, 0], getpos('.'))
642endfunc
643
644" Tab code and blockwise-visual inc/dec
645func Test_visual_increment_31()
646  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
647  exec "norm! f1\<C-V>jl\<C-A>"
648  call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
649  call assert_equal([0, 1, 3, 0], getpos('.'))
650
651  call setline(1, ["x\<TAB>10", "\<TAB>-1"])
652  exec "norm! ggf1\<C-V>jl\<C-X>"
653  call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
654  call 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()
659  28vnew dummy_31
660  set linebreak showbreak=+
661  call setline(1, ["x\<TAB>\<TAB>\<TAB>10", "\<TAB>\<TAB>\<TAB>\<TAB>-1"])
662  exec "norm! ggf0\<C-V>jg_\<C-X>"
663  call assert_equal(["x\<TAB>\<TAB>\<TAB>1-1", "\<TAB>\<TAB>\<TAB>\<TAB>-2"], getline(1, '$'))
664  call assert_equal([0, 1, 6, 0], getpos('.'))
665  bwipe!
666endfunc
667
668" Tab code and blockwise-visual increment with $
669func Test_visual_increment_33()
670  call setline(1, ["\<TAB>123", "456"])
671  exec "norm! gg0\<C-V>j$\<C-A>"
672  call assert_equal(["\<TAB>124", "457"], getline(1, '$'))
673  call assert_equal([0, 1, 1, 0], getpos('.'))
674endfunc
675
676" Tab code and blockwise-visual increment and redo
677func Test_visual_increment_34()
678  call setline(1, ["\<TAB>123", "     456789"])
679  exec "norm! gg0\<C-V>j\<C-A>"
680  call assert_equal(["\<TAB>123", "     457789"], getline(1, '$'))
681  call assert_equal([0, 1, 1, 0], getpos('.'))
682
683  exec "norm! .."
684  call assert_equal(["\<TAB>123", "     459789"], getline(1, '$'))
685  call assert_equal([0, 1, 1, 0], getpos('.'))
686endfunc
687
688" Tab code, spaces and character-visual increment and redo
689func Test_visual_increment_35()
690  call 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.
693  exec "norm! ggvjf3\<C-A>..."
694  exe "norm! \<Esc>"
695  call assert_equal(["\<TAB>124", "        124", "\<TAB>123", "\<TAB>123"], getline(1, '$'))
696  call assert_equal([0, 2, 9, 0], getpos('.'))
697endfunc
698
699" Tab code, spaces and blockwise-visual increment and redo
700func Test_visual_increment_36()
701  call setline(1, ["           123", "\<TAB>456789"])
702  exec "norm! G0\<C-V>kl\<C-A>"
703  call assert_equal(["           123", "\<TAB>556789"], getline(1, '$'))
704  call 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.
708  exec "norm! G0.G0.G0."
709  call assert_equal(["           123", "\<TAB>856789"], getline(1, '$'))
710  call 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()
725  call setline(1, ["  1 23", "  4 56"])
726  exec "norm! ggf2\<C-V>jl\<C-A>.."
727  call assert_equal(["  1 26", "  4 59"], getline(1, 2))
728
729  call setline(1, ["1 23", "4 56"])
730  exec "norm! ggf2\<C-V>jl\<C-A>.."
731  call assert_equal(["1 26", "4 59"], getline(1, 2))
732endfunc
733
734" Check redo after the normal mode increment
735func Test_visual_increment_38()
736  exec "norm! i10\<ESC>5\<C-A>."
737  call assert_equal(["20"], getline(1, '$'))
738  call 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()
743  call setline(1, "000")
744  exec "norm! gg0\<C-A>"
745  call assert_equal("001", getline(1))
746
747  call setline(1, "000")
748  exec "norm! gg$\<C-A>"
749  call assert_equal("001", getline(1))
750
751  call setline(1, "001")
752  exec "norm! gg0\<C-A>"
753  call assert_equal("002", getline(1))
754
755  call setline(1, "001")
756  exec "norm! gg$\<C-A>"
757  call assert_equal("002", getline(1))
758endfunc
759
760" Test a regression of patch 7.4.1087 fixed.
761func Test_normal_increment_02()
762  call setline(1, ["hello 10", "world"])
763  exec "norm! ggl\<C-A>jx"
764  call assert_equal(["hello 11", "worl"], getline(1, '$'))
765  call assert_equal([0, 2, 4, 0], getpos('.'))
766endfunc
767
768" The test35 unified to this file.
769func Test_normal_increment_03()
770  call setline(1, ["100     0x100     077     0",
771        \          "100     0x100     077     ",
772        \          "100     0x100     077     0xfF     0xFf",
773        \          "100     0x100     077     "])
774  set nrformats=octal,hex
775  exec "norm! gg\<C-A>102\<C-X>\<C-A>l\<C-X>l\<C-A>64\<C-A>128\<C-X>$\<C-X>"
776  set nrformats=octal
777  exec "norm! j0\<C-A>102\<C-X>\<C-A>l\<C-X>2\<C-A>w65\<C-A>129\<C-X>blx6lD"
778  set nrformats=hex
779  exec "norm! j0101\<C-X>l257\<C-X>\<C-A>Txldt \<C-A> \<C-X> \<C-X>"
780  set nrformats=
781  exec "norm! j0200\<C-X>l100\<C-X>w78\<C-X>\<C-A>k"
782  call assert_equal(["0     0x0ff     0000     -1",
783        \            "0     1x100     0777777",
784        \            "-1     0x0     078     0xFE     0xfe",
785        \            "-100     -100x100     000     "], getline(1, '$'))
786  call assert_equal([0, 3, 25, 0], getpos('.'))
787endfunc
788
789func Test_increment_empty_line()
790  call setline(1, ['0', '0', '0', '0', '0', '0', ''])
791  exe "normal Gvgg\<C-A>"
792  call 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
796  call setline(1, 'one two')
797  exe "normal! c\<C-A>l"
798  exe "normal! c\<C-X>l"
799  call assert_equal('one two', getline(1))
800endfunc
801
802" Try incrementing/decrementing a non-digit/alpha character
803func Test_increment_special_char()
804  call setline(1, '!')
805  call assert_beeps("normal \<C-A>")
806  call assert_beeps("normal \<C-X>")
807endfunc
808
809" Try incrementing/decrementing a number when nrformats contains unsigned
810func Test_increment_unsigned()
811  set nrformats+=unsigned
812
813  call setline(1, '0')
814  exec "norm! gg0\<C-X>"
815  call assert_equal('0', getline(1))
816
817  call setline(1, '3')
818  exec "norm! gg010\<C-X>"
819  call assert_equal('0', getline(1))
820
821  call setline(1, '-0')
822  exec "norm! gg0\<C-X>"
823  call assert_equal("-0", getline(1))
824
825  call setline(1, '-11')
826  exec "norm! gg08\<C-X>"
827  call assert_equal('-3', getline(1))
828
829  " NOTE: 18446744073709551615 == 2^64 - 1
830  call setline(1, '18446744073709551615')
831  exec "norm! gg0\<C-A>"
832  call assert_equal('18446744073709551615', getline(1))
833
834  call setline(1, '-18446744073709551615')
835  exec "norm! gg0\<C-A>"
836  call assert_equal('-18446744073709551615', getline(1))
837
838  call setline(1, '-18446744073709551614')
839  exec "norm! gg08\<C-A>"
840  call assert_equal('-18446744073709551615', getline(1))
841
842  call setline(1, '-1')
843  exec "norm! gg0\<C-A>"
844  call assert_equal('-2', getline(1))
845
846  call setline(1, '-3')
847  exec "norm! gg08\<C-A>"
848  call assert_equal('-11', getline(1))
849
850  set nrformats-=unsigned
851endfunc
852
853" Try incrementing/decrementing a number when nrformats contains blank
854func Test_increment_blank()
855  set nrformats+=blank
856
857  " Signed
858  call setline(1, '0')
859  exec "norm! gg0\<C-X>"
860  call assert_equal('-1', getline(1))
861
862  call setline(1, '3')
863  exec "norm! gg010\<C-X>"
864  call assert_equal('-7', getline(1))
865
866  call setline(1, '-0')
867  exec "norm! gg0\<C-X>"
868  call assert_equal("-1", getline(1))
869
870  " Unsigned
871  " NOTE: 18446744073709551615 == 2^64 - 1
872  call setline(1, 'a-18446744073709551615')
873  exec "norm! gg0\<C-A>"
874  call assert_equal('a-18446744073709551615', getline(1))
875
876  call setline(1, 'a-18446744073709551615')
877  exec "norm! gg0\<C-A>"
878  call assert_equal('a-18446744073709551615', getline(1))
879
880  call setline(1, 'a-18446744073709551614')
881  exec "norm! gg08\<C-A>"
882  call assert_equal('a-18446744073709551615', getline(1))
883
884  call setline(1, 'a-1')
885  exec "norm! gg0\<C-A>"
886  call assert_equal('a-2', getline(1))
887
888  set nrformats-=blank
889endfunc
890
891func Test_in_decrement_large_number()
892  " NOTE: 18446744073709551616 == 2^64
893  call setline(1, '18446744073709551616')
894  exec "norm! gg0\<C-X>"
895  call assert_equal('18446744073709551615', getline(1))
896
897  exec "norm! gg0\<C-X>"
898  call assert_equal('18446744073709551614', getline(1))
899
900  exec "norm! gg0\<C-A>"
901  call assert_equal('18446744073709551615', getline(1))
902
903  exec "norm! gg0\<C-A>"
904  call assert_equal('-18446744073709551615', getline(1))
905endfunc
906
907func Test_normal_increment_with_virtualedit()
908  set virtualedit=all
909
910  call setline(1, ["\<TAB>1"])
911  exec "norm! 0\<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! 0l\<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! 07l\<C-A>"
922  call assert_equal("\<TAB>2", getline(1))
923  call assert_equal([0, 1, 2, 0], getpos('.'))
924
925  call setline(1, ["\<TAB>1"])
926  exec "norm! 0w\<C-A>"
927  call assert_equal("\<TAB>2", getline(1))
928  call assert_equal([0, 1, 2, 0], getpos('.'))
929
930  call setline(1, ["\<TAB>1"])
931  exec "norm! 0wl\<C-A>"
932  call assert_equal("\<TAB>1", getline(1))
933  call assert_equal([0, 1, 3, 0], getpos('.'))
934
935  call setline(1, ["\<TAB>1"])
936  exec "norm! 0w30l\<C-A>"
937  call assert_equal("\<TAB>1", getline(1))
938  call assert_equal([0, 1, 3, 29], getpos('.'))
939
940  set virtualedit&
941endfunc
942
943" Test for incrementing a signed hexadecimal and octal number
944func Test_normal_increment_signed_hexoct_nr()
945  new
946  " negative sign before a hex number should be ignored
947  call setline(1, ["-0x9"])
948  exe "norm \<C-A>"
949  call assert_equal(["-0xa"], getline(1, '$'))
950  exe "norm \<C-X>"
951  call assert_equal(["-0x9"], getline(1, '$'))
952  call setline(1, ["-007"])
953  exe "norm \<C-A>"
954  call assert_equal(["-010"], getline(1, '$'))
955  exe "norm \<C-X>"
956  call assert_equal(["-007"], getline(1, '$'))
957  bw!
958endfunc
959
960" vim: shiftwidth=2 sts=2 expandtab