increment_spec.lua 22 KB

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