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