command_count_spec.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. -- Test for user command counts
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local clear, source, expect = helpers.clear, helpers.source, helpers.expect
  4. local feed_command = helpers.feed_command
  5. -- luacheck: ignore 613 (Trailing whitespace in a string)
  6. describe('command_count', function()
  7. it('is working', function()
  8. -- It is relevant for the test to load a file initially. If this is
  9. -- emulated with :arg the buffer count is wrong as nvim creates an empty
  10. -- buffer if it was started without a filename.
  11. clear('test_command_count.in')
  12. source([[
  13. let g:tmpname = tempname()
  14. call mkdir(g:tmpname)
  15. execute "cd ".g:tmpname
  16. lang C
  17. let g:lines = []
  18. com -range=% RangeLines
  19. \ :call add(g:lines, 'RangeLines '.<line1>.' '.<line2>)
  20. com -range -addr=arguments RangeArguments
  21. \ :call add(g:lines, 'RangeArguments '.<line1>.' '.<line2>)
  22. com -range=% -addr=arguments RangeArgumentsAll
  23. \ :call add(g:lines, 'RangeArgumentsAll '.<line1>.' '.<line2>)
  24. com -range -addr=loaded_buffers RangeLoadedBuffers
  25. \ :call add(g:lines, 'RangeLoadedBuffers '.<line1>.' '.<line2>)
  26. com -range=% -addr=loaded_buffers RangeLoadedBuffersAll
  27. \ :call add(g:lines, 'RangeLoadedBuffersAll '.<line1>.' '.<line2>)
  28. com -range -addr=buffers RangeBuffers
  29. \ :call add(g:lines, 'RangeBuffers '.<line1>.' '.<line2>)
  30. com -range=% -addr=buffers RangeBuffersAll
  31. \ :call add(g:lines, 'RangeBuffersAll '.<line1>.' '.<line2>)
  32. com -range -addr=windows RangeWindows
  33. \ :call add(g:lines, 'RangeWindows '.<line1>.' '.<line2>)
  34. com -range=% -addr=windows RangeWindowsAll
  35. \ :call add(g:lines, 'RangeWindowsAll '.<line1>.' '.<line2>)
  36. com -range -addr=tabs RangeTabs
  37. \ :call add(g:lines, 'RangeTabs '.<line1>.' '.<line2>)
  38. com -range=% -addr=tabs RangeTabsAll
  39. \ :call add(g:lines, 'RangeTabsAll '.<line1>.' '.<line2>)
  40. set hidden
  41. arga a b c d
  42. argdo echo "loading buffers"
  43. argu 3
  44. .-,$-RangeArguments
  45. %RangeArguments
  46. RangeArgumentsAll
  47. N
  48. .RangeArguments
  49. split
  50. split
  51. split
  52. split
  53. 3wincmd w
  54. .,$RangeWindows
  55. %RangeWindows
  56. RangeWindowsAll
  57. only
  58. blast
  59. bd
  60. .,$RangeLoadedBuffers
  61. %RangeLoadedBuffers
  62. RangeLoadedBuffersAll
  63. .,$RangeBuffers
  64. %RangeBuffers
  65. RangeBuffersAll
  66. tabe
  67. tabe
  68. tabe
  69. tabe
  70. normal 2gt
  71. .,$RangeTabs
  72. %RangeTabs
  73. RangeTabsAll
  74. 1tabonly
  75. s/\n/\r\r\r\r\r/
  76. 2ma<
  77. $-ma>
  78. '<,'>RangeLines
  79. com -range=% -buffer LocalRangeLines
  80. \ :call add(g:lines, 'LocalRangeLines '.<line1>.' '.<line2>)
  81. '<,'>LocalRangeLines
  82. b1
  83. call add(g:lines, '')
  84. %argd
  85. arga a b c d
  86. ]])
  87. -- This can not be in the source() call as it will produce errors.
  88. feed_command([[let v:errmsg = '']])
  89. feed_command('5argu')
  90. feed_command([[call add(g:lines, '5argu ' . v:errmsg)]])
  91. feed_command('$argu')
  92. feed_command([[call add(g:lines, '4argu ' . expand('%:t'))]])
  93. feed_command([[let v:errmsg = '']])
  94. feed_command('1argu')
  95. feed_command([[call add(g:lines, '1argu ' . expand('%:t'))]])
  96. feed_command([[let v:errmsg = '']])
  97. feed_command('100b')
  98. feed_command([[call add(g:lines, '100b ' . v:errmsg)]])
  99. feed_command('split')
  100. feed_command('split')
  101. feed_command('split')
  102. feed_command('split')
  103. feed_command([[let v:errmsg = '']])
  104. feed_command('0close')
  105. feed_command([[call add(g:lines, '0close ' . v:errmsg)]])
  106. feed_command('$wincmd w')
  107. feed_command('$close')
  108. feed_command([[call add(g:lines, '$close ' . winnr())]])
  109. feed_command([[let v:errmsg = '']])
  110. feed_command('$+close')
  111. feed_command([[call add(g:lines, '$+close ' . v:errmsg)]])
  112. feed_command('$tabe')
  113. feed_command([[call add(g:lines, '$tabe ' . tabpagenr())]])
  114. feed_command([[let v:errmsg = '']])
  115. feed_command('$+tabe')
  116. feed_command([[call add(g:lines, '$+tabe ' . v:errmsg)]])
  117. source([[
  118. only!
  119. e x
  120. 0tabm
  121. normal 1gt
  122. call add(g:lines, '0tabm ' . expand('%:t'))
  123. tabonly!
  124. only!
  125. e! test.out
  126. call append(0, g:lines)
  127. unlet g:lines
  128. w
  129. bd
  130. b1
  131. let g:lines = []
  132. func BufStatus()
  133. call add(g:lines,
  134. \ 'aaa: ' . buflisted(g:buf_aaa) .
  135. \ ' bbb: ' . buflisted(g:buf_bbb) .
  136. \ ' ccc: ' . buflisted(g:buf_ccc))
  137. endfunc
  138. se nohidden
  139. e aaa
  140. let buf_aaa = bufnr('%')
  141. e bbb
  142. let buf_bbb = bufnr('%')
  143. e ccc
  144. let buf_ccc = bufnr('%')
  145. b1
  146. call BufStatus()
  147. exe buf_bbb . "," . buf_ccc . "bdelete"
  148. call BufStatus()
  149. exe buf_aaa . "bdelete"
  150. call BufStatus()
  151. e! test.out
  152. call append('$', g:lines)
  153. unlet g:lines
  154. delfunc BufStatus
  155. w
  156. bd
  157. b1
  158. se hidden
  159. only!
  160. let g:lines = []
  161. %argd
  162. arga a b c d e f
  163. 3argu
  164. let args = ''
  165. .,$-argdo let args .= ' '.expand('%')
  166. call add(g:lines, 'argdo:' . args)
  167. split
  168. split
  169. split
  170. split
  171. 2wincmd w
  172. let windows = ''
  173. .,$-windo let windows .= ' '.winnr()
  174. call add(g:lines, 'windo:'. windows)
  175. b2
  176. let buffers = ''
  177. .,$-bufdo let buffers .= ' '.bufnr('%')
  178. call add(g:lines, 'bufdo:' . buffers)
  179. 3bd
  180. let buffers = ''
  181. 3,7bufdo let buffers .= ' '.bufnr('%')
  182. call add(g:lines, 'bufdo:' . buffers)
  183. tabe
  184. tabe
  185. tabe
  186. tabe
  187. normal! 2gt
  188. let tabpages = ''
  189. .,$-tabdo let tabpages .= ' '.tabpagenr()
  190. call add(g:lines, 'tabdo:' . tabpages)
  191. e! test.out
  192. call append('$', g:lines)
  193. ]])
  194. -- Assert buffer contents.
  195. expect([[
  196. RangeArguments 2 4
  197. RangeArguments 1 5
  198. RangeArgumentsAll 1 5
  199. RangeArguments 2 2
  200. RangeWindows 3 5
  201. RangeWindows 1 5
  202. RangeWindowsAll 1 5
  203. RangeLoadedBuffers 2 4
  204. RangeLoadedBuffers 1 4
  205. RangeLoadedBuffersAll 1 4
  206. RangeBuffers 2 5
  207. RangeBuffers 1 5
  208. RangeBuffersAll 1 5
  209. RangeTabs 2 5
  210. RangeTabs 1 5
  211. RangeTabsAll 1 5
  212. RangeLines 2 5
  213. LocalRangeLines 2 5
  214. 5argu E16: Invalid range
  215. 4argu d
  216. 1argu a
  217. 100b E16: Invalid range
  218. 0close
  219. $close 3
  220. $+close E16: Invalid range
  221. $tabe 2
  222. $+tabe E16: Invalid range
  223. 0tabm x
  224. aaa: 1 bbb: 1 ccc: 1
  225. aaa: 1 bbb: 0 ccc: 0
  226. aaa: 0 bbb: 0 ccc: 0
  227. argdo: c d e
  228. windo: 2 3 4
  229. bufdo: 2 3 4 5 6 7 8 9 10 15
  230. bufdo: 4 5 6 7
  231. tabdo: 2 3 4]])
  232. source([[
  233. cd ..
  234. call delete(g:tmpname, 'rf')
  235. ]])
  236. end)
  237. end)