increment_spec.lua 22 KB

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