number_spec.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. local n = require('test.functional.testnvim')()
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = n.clear
  4. local command = n.command
  5. local exec = n.exec
  6. local feed = n.feed
  7. describe("'number' and 'relativenumber'", function()
  8. before_each(clear)
  9. -- oldtest: Test_relativenumber_colors()
  10. it('LineNr, LineNrAbove and LineNrBelow', function()
  11. local screen = Screen.new(50, 10)
  12. screen:set_default_attr_ids({
  13. [1] = { foreground = Screen.colors.Red },
  14. [2] = { foreground = Screen.colors.Blue },
  15. [3] = { foreground = Screen.colors.Green },
  16. })
  17. exec([[
  18. call setline(1, range(200))
  19. 111
  20. set number relativenumber
  21. hi LineNr guifg=red
  22. ]])
  23. screen:expect([[
  24. {1: 4 }106 |
  25. {1: 3 }107 |
  26. {1: 2 }108 |
  27. {1: 1 }109 |
  28. {1:111 }^110 |
  29. {1: 1 }111 |
  30. {1: 2 }112 |
  31. {1: 3 }113 |
  32. {1: 4 }114 |
  33. |
  34. ]])
  35. command('hi LineNrAbove guifg=blue')
  36. screen:expect([[
  37. {2: 4 }106 |
  38. {2: 3 }107 |
  39. {2: 2 }108 |
  40. {2: 1 }109 |
  41. {1:111 }^110 |
  42. {1: 1 }111 |
  43. {1: 2 }112 |
  44. {1: 3 }113 |
  45. {1: 4 }114 |
  46. |
  47. ]])
  48. command('hi LineNrBelow guifg=green')
  49. screen:expect([[
  50. {2: 4 }106 |
  51. {2: 3 }107 |
  52. {2: 2 }108 |
  53. {2: 1 }109 |
  54. {1:111 }^110 |
  55. {3: 1 }111 |
  56. {3: 2 }112 |
  57. {3: 3 }113 |
  58. {3: 4 }114 |
  59. |
  60. ]])
  61. command('hi clear LineNrAbove')
  62. screen:expect([[
  63. {1: 4 }106 |
  64. {1: 3 }107 |
  65. {1: 2 }108 |
  66. {1: 1 }109 |
  67. {1:111 }^110 |
  68. {3: 1 }111 |
  69. {3: 2 }112 |
  70. {3: 3 }113 |
  71. {3: 4 }114 |
  72. |
  73. ]])
  74. end)
  75. -- oldtest: Test_relativenumber_colors_wrapped()
  76. it('LineNr, LineNrAbove and LineNrBelow with wrapped lines', function()
  77. local screen = Screen.new(50, 20)
  78. screen:set_default_attr_ids({
  79. [1] = { background = Screen.colors.Red, foreground = Screen.colors.Black },
  80. [2] = { background = Screen.colors.Blue, foreground = Screen.colors.Black },
  81. [3] = { background = Screen.colors.Green, foreground = Screen.colors.Black },
  82. [4] = { bold = true, foreground = Screen.colors.Blue },
  83. })
  84. exec([[
  85. set display=lastline scrolloff=0
  86. call setline(1, range(200)->map('v:val->string()->repeat(40)'))
  87. 111
  88. set number relativenumber
  89. hi LineNr guibg=red guifg=black
  90. hi LineNrAbove guibg=blue guifg=black
  91. hi LineNrBelow guibg=green guifg=black
  92. ]])
  93. screen:expect([[
  94. {2: 2 }1081081081081081081081081081081081081081081081|
  95. {2: }0810810810810810810810810810810810810810810810|
  96. {2: }8108108108108108108108108108 |
  97. {2: 1 }1091091091091091091091091091091091091091091091|
  98. {2: }0910910910910910910910910910910910910910910910|
  99. {2: }9109109109109109109109109109 |
  100. {1:111 }^1101101101101101101101101101101101101101101101|
  101. {1: }1011011011011011011011011011011011011011011011|
  102. {1: }0110110110110110110110110110 |
  103. {3: 1 }1111111111111111111111111111111111111111111111|
  104. {3: }1111111111111111111111111111111111111111111111|
  105. {3: }1111111111111111111111111111 |
  106. {3: 2 }1121121121121121121121121121121121121121121121|
  107. {3: }1211211211211211211211211211211211211211211211|
  108. {3: }2112112112112112112112112112 |
  109. {3: 3 }1131131131131131131131131131131131131131131131|
  110. {3: }1311311311311311311311311311311311311311311311|
  111. {3: }3113113113113113113113113113 |
  112. {3: 4 }1141141141141141141141141141141141141141141{4:@@@}|
  113. |
  114. ]])
  115. feed('k')
  116. screen:expect([[
  117. {2: 1 }1081081081081081081081081081081081081081081081|
  118. {2: }0810810810810810810810810810810810810810810810|
  119. {2: }8108108108108108108108108108 |
  120. {1:110 }^1091091091091091091091091091091091091091091091|
  121. {1: }0910910910910910910910910910910910910910910910|
  122. {1: }9109109109109109109109109109 |
  123. {3: 1 }1101101101101101101101101101101101101101101101|
  124. {3: }1011011011011011011011011011011011011011011011|
  125. {3: }0110110110110110110110110110 |
  126. {3: 2 }1111111111111111111111111111111111111111111111|
  127. {3: }1111111111111111111111111111111111111111111111|
  128. {3: }1111111111111111111111111111 |
  129. {3: 3 }1121121121121121121121121121121121121121121121|
  130. {3: }1211211211211211211211211211211211211211211211|
  131. {3: }2112112112112112112112112112 |
  132. {3: 4 }1131131131131131131131131131131131131131131131|
  133. {3: }1311311311311311311311311311311311311311311311|
  134. {3: }3113113113113113113113113113 |
  135. {3: 5 }1141141141141141141141141141141141141141141{4:@@@}|
  136. |
  137. ]])
  138. feed('2j')
  139. screen:expect([[
  140. {2: 3 }1081081081081081081081081081081081081081081081|
  141. {2: }0810810810810810810810810810810810810810810810|
  142. {2: }8108108108108108108108108108 |
  143. {2: 2 }1091091091091091091091091091091091091091091091|
  144. {2: }0910910910910910910910910910910910910910910910|
  145. {2: }9109109109109109109109109109 |
  146. {2: 1 }1101101101101101101101101101101101101101101101|
  147. {2: }1011011011011011011011011011011011011011011011|
  148. {2: }0110110110110110110110110110 |
  149. {1:112 }^1111111111111111111111111111111111111111111111|
  150. {1: }1111111111111111111111111111111111111111111111|
  151. {1: }1111111111111111111111111111 |
  152. {3: 1 }1121121121121121121121121121121121121121121121|
  153. {3: }1211211211211211211211211211211211211211211211|
  154. {3: }2112112112112112112112112112 |
  155. {3: 2 }1131131131131131131131131131131131131131131131|
  156. {3: }1311311311311311311311311311311311311311311311|
  157. {3: }3113113113113113113113113113 |
  158. {3: 3 }1141141141141141141141141141141141141141141{4:@@@}|
  159. |
  160. ]])
  161. feed('2j')
  162. screen:expect([[
  163. {2: 5 }1081081081081081081081081081081081081081081081|
  164. {2: }0810810810810810810810810810810810810810810810|
  165. {2: }8108108108108108108108108108 |
  166. {2: 4 }1091091091091091091091091091091091091091091091|
  167. {2: }0910910910910910910910910910910910910910910910|
  168. {2: }9109109109109109109109109109 |
  169. {2: 3 }1101101101101101101101101101101101101101101101|
  170. {2: }1011011011011011011011011011011011011011011011|
  171. {2: }0110110110110110110110110110 |
  172. {2: 2 }1111111111111111111111111111111111111111111111|
  173. {2: }1111111111111111111111111111111111111111111111|
  174. {2: }1111111111111111111111111111 |
  175. {2: 1 }1121121121121121121121121121121121121121121121|
  176. {2: }1211211211211211211211211211211211211211211211|
  177. {2: }2112112112112112112112112112 |
  178. {1:114 }^1131131131131131131131131131131131131131131131|
  179. {1: }1311311311311311311311311311311311311311311311|
  180. {1: }3113113113113113113113113113 |
  181. {3: 1 }1141141141141141141141141141141141141141141{4:@@@}|
  182. |
  183. ]])
  184. feed('k')
  185. screen:expect([[
  186. {2: 4 }1081081081081081081081081081081081081081081081|
  187. {2: }0810810810810810810810810810810810810810810810|
  188. {2: }8108108108108108108108108108 |
  189. {2: 3 }1091091091091091091091091091091091091091091091|
  190. {2: }0910910910910910910910910910910910910910910910|
  191. {2: }9109109109109109109109109109 |
  192. {2: 2 }1101101101101101101101101101101101101101101101|
  193. {2: }1011011011011011011011011011011011011011011011|
  194. {2: }0110110110110110110110110110 |
  195. {2: 1 }1111111111111111111111111111111111111111111111|
  196. {2: }1111111111111111111111111111111111111111111111|
  197. {2: }1111111111111111111111111111 |
  198. {1:113 }^1121121121121121121121121121121121121121121121|
  199. {1: }1211211211211211211211211211211211211211211211|
  200. {1: }2112112112112112112112112112 |
  201. {3: 1 }1131131131131131131131131131131131131131131131|
  202. {3: }1311311311311311311311311311311311311311311311|
  203. {3: }3113113113113113113113113113 |
  204. {3: 2 }1141141141141141141141141141141141141141141{4:@@@}|
  205. |
  206. ]])
  207. end)
  208. -- oldtest: Test_relativenumber_callback()
  209. it('relative line numbers are updated if cursor is moved from timer', function()
  210. local screen = Screen.new(50, 8)
  211. exec([[
  212. call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
  213. set relativenumber
  214. call cursor(4, 1)
  215. func Func(timer)
  216. call cursor(1, 1)
  217. endfunc
  218. call timer_start(300, 'Func')
  219. ]])
  220. screen:expect({
  221. grid = [[
  222. {8: 3 }aaaaa |
  223. {8: 2 }bbbbb |
  224. {8: 1 }ccccc |
  225. {8: 0 }^ddddd |
  226. {1:~ }|*3
  227. |
  228. ]],
  229. timeout = 100,
  230. })
  231. screen:expect({
  232. grid = [[
  233. {8: 0 }^aaaaa |
  234. {8: 1 }bbbbb |
  235. {8: 2 }ccccc |
  236. {8: 3 }ddddd |
  237. {1:~ }|*3
  238. |
  239. ]],
  240. })
  241. end)
  242. -- oldtest: Test_number_insert_delete_lines()
  243. it('line numbers are updated when deleting/inserting lines', function()
  244. local screen = Screen.new(50, 8)
  245. exec([[
  246. call setline(1, range(1, 7))
  247. set number
  248. call cursor(2, 1)
  249. ]])
  250. local snapshot1 = [[
  251. {8: 1 }1 |
  252. {8: 2 }^2 |
  253. {8: 3 }3 |
  254. {8: 4 }4 |
  255. {8: 5 }5 |
  256. {8: 6 }6 |
  257. {8: 7 }7 |
  258. |
  259. ]]
  260. screen:expect(snapshot1)
  261. feed('dd')
  262. screen:expect([[
  263. {8: 1 }1 |
  264. {8: 2 }^3 |
  265. {8: 3 }4 |
  266. {8: 4 }5 |
  267. {8: 5 }6 |
  268. {8: 6 }7 |
  269. {1:~ }|
  270. |
  271. ]])
  272. feed('P')
  273. screen:expect(snapshot1)
  274. feed('2dd')
  275. screen:expect([[
  276. {8: 1 }1 |
  277. {8: 2 }^4 |
  278. {8: 3 }5 |
  279. {8: 4 }6 |
  280. {8: 5 }7 |
  281. {1:~ }|*2
  282. |
  283. ]])
  284. feed('P')
  285. screen:expect(snapshot1)
  286. end)
  287. end)