test_increment.vim 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. " Tests for using Ctrl-A/Ctrl-X
  2. func SetUp()
  3. new dummy
  4. set nrformats&vim
  5. set nrformats+=octal
  6. endfunc
  7. func TearDown()
  8. bwipe!
  9. endfunc
  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. " Expected:
  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. "
  341. " Also: 019 with "01" selected increments to "029".
  342. func Test_visual_increment_15()
  343. call setline(1, ["101"])
  344. exec "norm! lv\<C-A>"
  345. call assert_equal(["111"], getline(1, '$'))
  346. call assert_equal([0, 1, 2, 0], getpos('.'))
  347. call setline(1, ["019"])
  348. exec "norm! 0vl\<C-A>"
  349. call assert_equal("029", getline(1))
  350. call setline(1, ["01239"])
  351. exec "norm! 0vlll\<C-A>"
  352. call assert_equal("01249", getline(1))
  353. call setline(1, ["01299"])
  354. exec "norm! 0vlll\<C-A>"
  355. call assert_equal("1309", getline(1))
  356. endfunc
  357. " 16) increment right aligned numbers
  358. " Text:
  359. " 1
  360. " 19
  361. " 119
  362. " Expected:
  363. " 1) Ctrl-a on line selected region
  364. " 2
  365. " 20
  366. " 120
  367. func Test_visual_increment_16()
  368. call setline(1, [" 1", " 19", " 119"])
  369. exec "norm! VG\<C-A>"
  370. call assert_equal([" 2", " 20", " 120"], getline(1, '$'))
  371. call assert_equal([0, 1, 1, 0], getpos('.'))
  372. endfunc
  373. " 17) block-wise increment and redo
  374. " Text:
  375. " 100
  376. " 1
  377. "
  378. " 100
  379. " 1
  380. "
  381. " Expected:
  382. " 1) Ctrl-V j $ on first block, afterwards '.' on second
  383. " 101
  384. " 2
  385. "
  386. " 101
  387. " 2
  388. func Test_visual_increment_17()
  389. call setline(1, [" 100", " 1", "", " 100", " 1"])
  390. exec "norm! \<C-V>j$\<C-A>2j."
  391. call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$'))
  392. call assert_equal([0, 3, 1, 0], getpos('.'))
  393. endfunc
  394. " 18) repeat of g<Ctrl-a>
  395. " Text:
  396. " 0
  397. " 0
  398. " 0
  399. " 0
  400. "
  401. " Expected:
  402. " 1) V 4j g<ctrl-a>, repeat twice afterwards with .
  403. " 3
  404. " 6
  405. " 9
  406. " 12
  407. func Test_visual_increment_18()
  408. call setline(1, repeat(["0"], 4))
  409. exec "norm! GV3kg\<C-A>"
  410. exec "norm! .."
  411. call assert_equal(["3", "6", "9", "12"], getline(1, '$'))
  412. call assert_equal([0, 1, 1, 0], getpos('.'))
  413. endfunc
  414. " 19) increment on number with nrformat including alpha
  415. " Text:
  416. " 1
  417. " 1a
  418. "
  419. " Expected:
  420. " 1) <Ctrl-V>j$ <ctrl-a>
  421. " 2
  422. " 2a
  423. func Test_visual_increment_19()
  424. set nrformats+=alpha
  425. call setline(1, ["1", "1a"])
  426. exec "norm! \<C-V>G$\<C-A>"
  427. call assert_equal(["2", "2a"], getline(1, '$'))
  428. call assert_equal([0, 1, 1, 0], getpos('.'))
  429. endfunc
  430. " 20) increment a single letter
  431. " Text:
  432. " a
  433. "
  434. " Expected:
  435. " 1) <Ctrl-a> and cursor is on a
  436. " b
  437. func Test_visual_increment_20()
  438. set nrformats+=alpha
  439. call setline(1, ["a"])
  440. exec "norm! \<C-A>"
  441. call assert_equal(["b"], getline(1, '$'))
  442. call assert_equal([0, 1, 1, 0], getpos('.'))
  443. " decrement a and A and increment z and Z
  444. call setline(1, ['a', 'A', 'z', 'Z'])
  445. exe "normal 1G\<C-X>2G\<C-X>3G\<C-A>4G\<C-A>"
  446. call assert_equal(['a', 'A', 'z', 'Z'], getline(1, '$'))
  447. endfunc
  448. " 21) block-wise increment on part of hexadecimal
  449. " Text:
  450. " 0x123456
  451. "
  452. " Expected:
  453. " 1) Ctrl-V f3 <ctrl-a>
  454. " 0x124456
  455. func Test_visual_increment_21()
  456. call setline(1, ["0x123456"])
  457. exec "norm! \<C-V>f3\<C-A>"
  458. call assert_equal(["0x124456"], getline(1, '$'))
  459. call assert_equal([0, 1, 1, 0], getpos('.'))
  460. endfunc
  461. " 22) Block increment on 0b0
  462. " Text:
  463. " 0b1
  464. " 0b1
  465. " Expected:
  466. " 1) Ctrl-A on visually block selected region (cursor at beginning):
  467. " 0b10
  468. " 0b10
  469. " 2) Ctrl-A on visually block selected region (cursor at end)
  470. " 0b10
  471. " 0b10
  472. func Test_visual_increment_22()
  473. call setline(1, repeat(["0b1"], 2))
  474. exec "norm! \<C-V>j$\<C-A>"
  475. call assert_equal(repeat(["0b10"], 2), getline(1, '$'))
  476. call assert_equal([0, 1, 1, 0], getpos('.'))
  477. call setline(1, repeat(["0b1"], 2))
  478. exec "norm! $\<C-V>+\<C-A>"
  479. call assert_equal(repeat(["0b10"], 2), getline(1, '$'))
  480. call assert_equal([0, 1, 1, 0], getpos('.'))
  481. endfunc
  482. " 23) block-wise increment on part of binary
  483. " Text:
  484. " 0b1001
  485. "
  486. " Expected:
  487. " 1) Ctrl-V 5l <ctrl-a>
  488. " 0b1011
  489. func Test_visual_increment_23()
  490. call setline(1, ["0b1001"])
  491. exec "norm! \<C-V>4l\<C-A>"
  492. call assert_equal(["0b1011"], getline(1, '$'))
  493. call assert_equal([0, 1, 1, 0], getpos('.'))
  494. endfunc
  495. " 24) increment hexadecimal
  496. " Text:
  497. " 0x0b1001
  498. "
  499. " Expected:
  500. " 1) <ctrl-a>
  501. " 0x0b1002
  502. func Test_visual_increment_24()
  503. call setline(1, ["0x0b1001"])
  504. exec "norm! \<C-V>$\<C-A>"
  505. call assert_equal(["0x0b1002"], getline(1, '$'))
  506. call assert_equal([0, 1, 1, 0], getpos('.'))
  507. endfunc
  508. " 25) increment binary with nrformats including alpha
  509. " Text:
  510. " 0b1001a
  511. "
  512. " Expected:
  513. " 1) <ctrl-a>
  514. " 0b1010a
  515. func Test_visual_increment_25()
  516. set nrformats+=alpha
  517. call setline(1, ["0b1001a"])
  518. exec "norm! \<C-V>$\<C-A>"
  519. call assert_equal(["0b1010a"], getline(1, '$'))
  520. call assert_equal([0, 1, 1, 0], getpos('.'))
  521. endfunc
  522. " 26) increment binary with 32 bits
  523. " Text:
  524. " 0b11111111111111111111111111111110
  525. "
  526. " Expected:
  527. " 1) <ctrl-a>
  528. " 0b11111111111111111111111111111111
  529. func Test_visual_increment_26()
  530. set nrformats+=bin
  531. call setline(1, ["0b11111111111111111111111111111110"])
  532. exec "norm! \<C-V>$\<C-A>"
  533. call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$'))
  534. call assert_equal([0, 1, 1, 0], getpos('.'))
  535. exec "norm! \<C-V>$\<C-X>"
  536. call assert_equal(["0b11111111111111111111111111111110"], getline(1, '$'))
  537. set nrformats-=bin
  538. endfunc
  539. " 27) increment with 'rightreft', if supported
  540. func Test_visual_increment_27()
  541. if exists('+rightleft')
  542. set rightleft
  543. call setline(1, ["1234 56"])
  544. exec "norm! $\<C-A>"
  545. call assert_equal(["1234 57"], getline(1, '$'))
  546. call assert_equal([0, 1, 7, 0], getpos('.'))
  547. exec "norm! \<C-A>"
  548. call assert_equal(["1234 58"], getline(1, '$'))
  549. call assert_equal([0, 1, 7, 0], getpos('.'))
  550. set norightleft
  551. endif
  552. endfunc
  553. " Tab code and linewise-visual inc/dec
  554. func Test_visual_increment_28()
  555. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  556. exec "norm! Vj\<C-A>"
  557. call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
  558. call assert_equal([0, 1, 1, 0], getpos('.'))
  559. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  560. exec "norm! ggVj\<C-X>"
  561. call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
  562. call assert_equal([0, 1, 1, 0], getpos('.'))
  563. endfunc
  564. " Tab code and linewise-visual inc/dec with 'nrformats'+=alpha
  565. func Test_visual_increment_29()
  566. set nrformats+=alpha
  567. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  568. exec "norm! Vj\<C-A>"
  569. call assert_equal(["y\<TAB>10", "\<TAB>0"], getline(1, '$'))
  570. call assert_equal([0, 1, 1, 0], getpos('.'))
  571. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  572. exec "norm! ggVj\<C-X>"
  573. call assert_equal(["w\<TAB>10", "\<TAB>-2"], getline(1, '$'))
  574. call assert_equal([0, 1, 1, 0], getpos('.'))
  575. endfunc
  576. " Tab code and character-visual inc/dec
  577. func Test_visual_increment_30()
  578. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  579. exec "norm! f1vjf1\<C-A>"
  580. call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
  581. call assert_equal([0, 1, 3, 0], getpos('.'))
  582. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  583. exec "norm! ggf1vjf1\<C-X>"
  584. call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
  585. call assert_equal([0, 1, 3, 0], getpos('.'))
  586. endfunc
  587. " Tab code and blockwise-visual inc/dec
  588. func Test_visual_increment_31()
  589. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  590. exec "norm! f1\<C-V>jl\<C-A>"
  591. call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
  592. call assert_equal([0, 1, 3, 0], getpos('.'))
  593. call setline(1, ["x\<TAB>10", "\<TAB>-1"])
  594. exec "norm! ggf1\<C-V>jl\<C-X>"
  595. call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
  596. call assert_equal([0, 1, 3, 0], getpos('.'))
  597. endfunc
  598. " Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak'
  599. func Test_visual_increment_32()
  600. 28vnew dummy_31
  601. set linebreak showbreak=+
  602. call setline(1, ["x\<TAB>\<TAB>\<TAB>10", "\<TAB>\<TAB>\<TAB>\<TAB>-1"])
  603. exec "norm! ggf0\<C-V>jg_\<C-X>"
  604. call assert_equal(["x\<TAB>\<TAB>\<TAB>1-1", "\<TAB>\<TAB>\<TAB>\<TAB>-2"], getline(1, '$'))
  605. call assert_equal([0, 1, 6, 0], getpos('.'))
  606. bwipe!
  607. endfunc
  608. " Tab code and blockwise-visual increment with $
  609. func Test_visual_increment_33()
  610. call setline(1, ["\<TAB>123", "456"])
  611. exec "norm! gg0\<C-V>j$\<C-A>"
  612. call assert_equal(["\<TAB>124", "457"], getline(1, '$'))
  613. call assert_equal([0, 1, 1, 0], getpos('.'))
  614. endfunc
  615. " Tab code and blockwise-visual increment and redo
  616. func Test_visual_increment_34()
  617. call setline(1, ["\<TAB>123", " 456789"])
  618. exec "norm! gg0\<C-V>j\<C-A>"
  619. call assert_equal(["\<TAB>123", " 457789"], getline(1, '$'))
  620. call assert_equal([0, 1, 1, 0], getpos('.'))
  621. exec "norm! .."
  622. call assert_equal(["\<TAB>123", " 459789"], getline(1, '$'))
  623. call assert_equal([0, 1, 1, 0], getpos('.'))
  624. endfunc
  625. " Tab code, spaces and character-visual increment and redo
  626. func Test_visual_increment_35()
  627. call setline(1, ["\<TAB>123", " 123", "\<TAB>123", "\<TAB>123"])
  628. exec "norm! ggvjf3\<C-A>..."
  629. call assert_equal(["\<TAB>127", " 127", "\<TAB>123", "\<TAB>123"], getline(1, '$'))
  630. call assert_equal([0, 1, 2, 0], getpos('.'))
  631. endfunc
  632. " Tab code, spaces and blockwise-visual increment and redo
  633. func Test_visual_increment_36()
  634. call setline(1, [" 123", "\<TAB>456789"])
  635. exec "norm! G0\<C-V>kl\<C-A>"
  636. call assert_equal([" 123", "\<TAB>556789"], getline(1, '$'))
  637. call assert_equal([0, 1, 1, 0], getpos('.'))
  638. exec "norm! ..."
  639. call assert_equal([" 123", "\<TAB>856789"], getline(1, '$'))
  640. call assert_equal([0, 1, 1, 0], getpos('.'))
  641. endfunc
  642. " block-wise increment and dot-repeat
  643. " Text:
  644. " 1 23
  645. " 4 56
  646. "
  647. " Expected:
  648. " 1) f2 Ctrl-V jl <ctrl-a>, repeat twice afterwards with .
  649. " 1 26
  650. " 4 59
  651. "
  652. " Try with and without indent.
  653. func Test_visual_increment_37()
  654. call setline(1, [" 1 23", " 4 56"])
  655. exec "norm! ggf2\<C-V>jl\<C-A>.."
  656. call assert_equal([" 1 26", " 4 59"], getline(1, 2))
  657. call setline(1, ["1 23", "4 56"])
  658. exec "norm! ggf2\<C-V>jl\<C-A>.."
  659. call assert_equal(["1 26", "4 59"], getline(1, 2))
  660. endfunc
  661. " Check redo after the normal mode increment
  662. func Test_visual_increment_38()
  663. exec "norm! i10\<ESC>5\<C-A>."
  664. call assert_equal(["20"], getline(1, '$'))
  665. call assert_equal([0, 1, 2, 0], getpos('.'))
  666. endfunc
  667. " Test what patch 7.3.414 fixed. Ctrl-A on "000" drops the leading zeros.
  668. func Test_normal_increment_01()
  669. call setline(1, "000")
  670. exec "norm! gg0\<C-A>"
  671. call assert_equal("001", getline(1))
  672. call setline(1, "000")
  673. exec "norm! gg$\<C-A>"
  674. call assert_equal("001", getline(1))
  675. call setline(1, "001")
  676. exec "norm! gg0\<C-A>"
  677. call assert_equal("002", getline(1))
  678. call setline(1, "001")
  679. exec "norm! gg$\<C-A>"
  680. call assert_equal("002", getline(1))
  681. endfunc
  682. " Test a regression of patch 7.4.1087 fixed.
  683. func Test_normal_increment_02()
  684. call setline(1, ["hello 10", "world"])
  685. exec "norm! ggl\<C-A>jx"
  686. call assert_equal(["hello 11", "worl"], getline(1, '$'))
  687. call assert_equal([0, 2, 4, 0], getpos('.'))
  688. endfunc
  689. " The test35 unified to this file.
  690. func Test_normal_increment_03()
  691. call setline(1, ["100 0x100 077 0",
  692. \ "100 0x100 077 ",
  693. \ "100 0x100 077 0xfF 0xFf",
  694. \ "100 0x100 077 "])
  695. set nrformats=octal,hex
  696. exec "norm! gg\<C-A>102\<C-X>\<C-A>l\<C-X>l\<C-A>64\<C-A>128\<C-X>$\<C-X>"
  697. set nrformats=octal
  698. exec "norm! j0\<C-A>102\<C-X>\<C-A>l\<C-X>2\<C-A>w65\<C-A>129\<C-X>blx6lD"
  699. set nrformats=hex
  700. exec "norm! j0101\<C-X>l257\<C-X>\<C-A>Txldt \<C-A> \<C-X> \<C-X>"
  701. set nrformats=
  702. exec "norm! j0200\<C-X>l100\<C-X>w78\<C-X>\<C-A>k"
  703. call assert_equal(["0 0x0ff 0000 -1",
  704. \ "0 1x100 0777777",
  705. \ "-1 0x0 078 0xFE 0xfe",
  706. \ "-100 -100x100 000 "], getline(1, '$'))
  707. call assert_equal([0, 3, 25, 0], getpos('.'))
  708. endfunc
  709. func Test_increment_empty_line()
  710. call setline(1, ['0', '0', '0', '0', '0', '0', ''])
  711. exe "normal Gvgg\<C-A>"
  712. call assert_equal(['1', '1', '1', '1', '1', '1', ''], getline(1, 7))
  713. " Ctrl-A/Ctrl-X should do nothing in operator pending mode
  714. %d
  715. call setline(1, 'one two')
  716. exe "normal! c\<C-A>l"
  717. exe "normal! c\<C-X>l"
  718. call assert_equal('one two', getline(1))
  719. endfunc
  720. " Try incrementing/decrementing a non-digit/alpha character
  721. func Test_increment_special_char()
  722. call setline(1, '!')
  723. call assert_beeps("normal \<C-A>")
  724. call assert_beeps("normal \<C-X>")
  725. endfunc
  726. " Try incrementing/decrementing a number when nrformats contains unsigned
  727. func Test_increment_unsigned()
  728. set nrformats+=unsigned
  729. call setline(1, '0')
  730. exec "norm! gg0\<C-X>"
  731. call assert_equal('0', getline(1))
  732. call setline(1, '3')
  733. exec "norm! gg010\<C-X>"
  734. call assert_equal('0', getline(1))
  735. call setline(1, '-0')
  736. exec "norm! gg0\<C-X>"
  737. call assert_equal("-0", getline(1))
  738. call setline(1, '-11')
  739. exec "norm! gg08\<C-X>"
  740. call assert_equal('-3', getline(1))
  741. " NOTE: 18446744073709551615 == 2^64 - 1
  742. call setline(1, '18446744073709551615')
  743. exec "norm! gg0\<C-A>"
  744. call assert_equal('18446744073709551615', getline(1))
  745. call setline(1, '-18446744073709551615')
  746. exec "norm! gg0\<C-A>"
  747. call assert_equal('-18446744073709551615', getline(1))
  748. call setline(1, '-18446744073709551614')
  749. exec "norm! gg08\<C-A>"
  750. call assert_equal('-18446744073709551615', getline(1))
  751. call setline(1, '-1')
  752. exec "norm! gg0\<C-A>"
  753. call assert_equal('-2', getline(1))
  754. call setline(1, '-3')
  755. exec "norm! gg08\<C-A>"
  756. call assert_equal('-11', getline(1))
  757. set nrformats-=unsigned
  758. endfunc
  759. " Try incrementing/decrementing a number when nrformats contains blank
  760. func Test_increment_blank()
  761. set nrformats+=blank
  762. " Signed
  763. call setline(1, '0')
  764. exec "norm! gg0\<C-X>"
  765. call assert_equal('-1', getline(1))
  766. call setline(1, '3')
  767. exec "norm! gg010\<C-X>"
  768. call assert_equal('-7', getline(1))
  769. call setline(1, '-0')
  770. exec "norm! gg0\<C-X>"
  771. call assert_equal("-1", getline(1))
  772. " Unsigned
  773. " NOTE: 18446744073709551615 == 2^64 - 1
  774. call setline(1, 'a-18446744073709551615')
  775. exec "norm! gg0\<C-A>"
  776. call assert_equal('a-18446744073709551615', getline(1))
  777. call setline(1, 'a-18446744073709551615')
  778. exec "norm! gg0\<C-A>"
  779. call assert_equal('a-18446744073709551615', getline(1))
  780. call setline(1, 'a-18446744073709551614')
  781. exec "norm! gg08\<C-A>"
  782. call assert_equal('a-18446744073709551615', getline(1))
  783. call setline(1, 'a-1')
  784. exec "norm! gg0\<C-A>"
  785. call assert_equal('a-2', getline(1))
  786. set nrformats-=blank
  787. endfunc
  788. func Test_in_decrement_large_number()
  789. " NOTE: 18446744073709551616 == 2^64
  790. call setline(1, '18446744073709551616')
  791. exec "norm! gg0\<C-X>"
  792. call assert_equal('18446744073709551615', getline(1))
  793. exec "norm! gg0\<C-X>"
  794. call assert_equal('18446744073709551614', getline(1))
  795. exec "norm! gg0\<C-A>"
  796. call assert_equal('18446744073709551615', getline(1))
  797. exec "norm! gg0\<C-A>"
  798. call assert_equal('-18446744073709551615', getline(1))
  799. endfunc
  800. func Test_normal_increment_with_virtualedit()
  801. set virtualedit=all
  802. call setline(1, ["\<TAB>1"])
  803. exec "norm! 0\<C-A>"
  804. call assert_equal("\<TAB>2", getline(1))
  805. call assert_equal([0, 1, 2, 0], getpos('.'))
  806. call setline(1, ["\<TAB>1"])
  807. exec "norm! 0l\<C-A>"
  808. call assert_equal("\<TAB>2", getline(1))
  809. call assert_equal([0, 1, 2, 0], getpos('.'))
  810. call setline(1, ["\<TAB>1"])
  811. exec "norm! 07l\<C-A>"
  812. call assert_equal("\<TAB>2", getline(1))
  813. call assert_equal([0, 1, 2, 0], getpos('.'))
  814. call setline(1, ["\<TAB>1"])
  815. exec "norm! 0w\<C-A>"
  816. call assert_equal("\<TAB>2", getline(1))
  817. call assert_equal([0, 1, 2, 0], getpos('.'))
  818. call setline(1, ["\<TAB>1"])
  819. exec "norm! 0wl\<C-A>"
  820. call assert_equal("\<TAB>1", getline(1))
  821. call assert_equal([0, 1, 3, 0], getpos('.'))
  822. call setline(1, ["\<TAB>1"])
  823. exec "norm! 0w30l\<C-A>"
  824. call assert_equal("\<TAB>1", getline(1))
  825. call assert_equal([0, 1, 3, 29], getpos('.'))
  826. set virtualedit&
  827. endfunc
  828. " Test for incrementing a signed hexadecimal and octal number
  829. func Test_normal_increment_signed_hexoct_nr()
  830. new
  831. " negative sign before a hex number should be ignored
  832. call setline(1, ["-0x9"])
  833. exe "norm \<C-A>"
  834. call assert_equal(["-0xa"], getline(1, '$'))
  835. exe "norm \<C-X>"
  836. call assert_equal(["-0x9"], getline(1, '$'))
  837. call setline(1, ["-007"])
  838. exe "norm \<C-A>"
  839. call assert_equal(["-010"], getline(1, '$'))
  840. exe "norm \<C-X>"
  841. call assert_equal(["-007"], getline(1, '$'))
  842. bw!
  843. endfunc
  844. " vim: shiftwidth=2 sts=2 expandtab