show_spec.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = n.clear
  5. local command = n.command
  6. local dedent = t.dedent
  7. local eq = t.eq
  8. local fn = n.fn
  9. local eval = n.eval
  10. local exec = n.exec
  11. local feed = n.feed
  12. describe(':autocmd', function()
  13. before_each(function()
  14. clear({ '-u', 'NONE' })
  15. end)
  16. it('should not segfault when you just do autocmd', function()
  17. command ':autocmd'
  18. end)
  19. it('should filter based on ++once', function()
  20. command 'autocmd! BufEnter'
  21. command "autocmd BufEnter * :echo 'Hello'"
  22. command [[augroup TestingOne]]
  23. command [[ autocmd BufEnter * :echo "Line 1"]]
  24. command [[ autocmd BufEnter * :echo "Line 2"]]
  25. command [[augroup END]]
  26. eq(
  27. dedent([[
  28. --- Autocommands ---
  29. BufEnter
  30. * :echo 'Hello'
  31. TestingOne BufEnter
  32. * :echo "Line 1"
  33. :echo "Line 2"]]),
  34. fn.execute('autocmd BufEnter')
  35. )
  36. end)
  37. it('should not show group information if interrupted', function()
  38. local screen = Screen.new(50, 6)
  39. screen:add_extra_attr_ids {
  40. [100] = { foreground = Screen.colors.Magenta, bold = true },
  41. }
  42. exec([[
  43. set more
  44. autocmd! BufEnter
  45. augroup test_1
  46. autocmd BufEnter A echo 'A'
  47. autocmd BufEnter B echo 'B'
  48. autocmd BufEnter C echo 'C'
  49. autocmd BufEnter D echo 'D'
  50. autocmd BufEnter E echo 'E'
  51. autocmd BufEnter F echo 'F'
  52. augroup END
  53. autocmd! BufLeave
  54. augroup test_1
  55. autocmd BufLeave A echo 'A'
  56. autocmd BufLeave B echo 'B'
  57. autocmd BufLeave C echo 'C'
  58. autocmd BufLeave D echo 'D'
  59. autocmd BufLeave E echo 'E'
  60. autocmd BufLeave F echo 'F'
  61. augroup END
  62. ]])
  63. feed(':autocmd<CR>')
  64. screen:expect([[
  65. :autocmd |
  66. {100:--- Autocommands ---} |
  67. {100:test_1} {100:BufEnter} |
  68. A echo 'A' |
  69. B echo 'B' |
  70. {6:-- More --}^ |
  71. ]])
  72. feed('q')
  73. screen:expect([[
  74. ^ |
  75. {1:~ }|*4
  76. |
  77. ]])
  78. end)
  79. it('should not show group information for deleted pattern', function()
  80. exec([[
  81. autocmd! BufEnter
  82. augroup test_1
  83. autocmd BufEnter A echo 'A'
  84. autocmd BufEnter B echo 'B'
  85. autocmd BufEnter C echo 'C'
  86. augroup END
  87. augroup test_2
  88. autocmd BufEnter foo echo 'foo'
  89. augroup END
  90. augroup test_3
  91. autocmd BufEnter D echo 'D'
  92. autocmd BufEnter E echo 'E'
  93. autocmd BufEnter F echo 'F'
  94. augroup END
  95. func Func()
  96. autocmd! test_2 BufEnter
  97. let g:output = execute('autocmd BufEnter')
  98. endfunc
  99. autocmd User foo call Func()
  100. doautocmd User foo
  101. ]])
  102. eq(
  103. dedent([[
  104. --- Autocommands ---
  105. test_1 BufEnter
  106. A echo 'A'
  107. B echo 'B'
  108. C echo 'C'
  109. test_3 BufEnter
  110. D echo 'D'
  111. E echo 'E'
  112. F echo 'F']]),
  113. eval('g:output')
  114. )
  115. end)
  116. it('can filter by pattern #17973', function()
  117. exec([[
  118. autocmd! BufEnter
  119. autocmd! User
  120. augroup test_1
  121. autocmd BufEnter A echo "A1"
  122. autocmd BufEnter B echo "B1"
  123. autocmd User A echo "A1"
  124. autocmd User B echo "B1"
  125. augroup END
  126. augroup test_2
  127. autocmd BufEnter A echo "A2"
  128. autocmd BufEnter B echo "B2"
  129. autocmd User A echo "A2"
  130. autocmd User B echo "B2"
  131. augroup END
  132. augroup test_3
  133. autocmd BufEnter A echo "A3"
  134. autocmd BufEnter B echo "B3"
  135. autocmd User A echo "A3"
  136. autocmd User B echo "B3"
  137. augroup END
  138. ]])
  139. eq(
  140. dedent([[
  141. --- Autocommands ---
  142. test_1 User
  143. A echo "A1"
  144. test_2 User
  145. A echo "A2"
  146. test_3 User
  147. A echo "A3"]]),
  148. fn.execute('autocmd User A')
  149. )
  150. eq(
  151. dedent([[
  152. --- Autocommands ---
  153. test_1 BufEnter
  154. B echo "B1"
  155. test_2 BufEnter
  156. B echo "B2"
  157. test_3 BufEnter
  158. B echo "B3"
  159. test_1 User
  160. B echo "B1"
  161. test_2 User
  162. B echo "B2"
  163. test_3 User
  164. B echo "B3"]]),
  165. fn.execute('autocmd * B')
  166. )
  167. eq(
  168. dedent([[
  169. --- Autocommands ---
  170. test_3 BufEnter
  171. B echo "B3"
  172. test_3 User
  173. B echo "B3"]]),
  174. fn.execute('autocmd test_3 * B')
  175. )
  176. end)
  177. it('should skip consecutive patterns', function()
  178. exec([[
  179. autocmd! BufEnter
  180. augroup test_1
  181. autocmd BufEnter A echo 'A'
  182. autocmd BufEnter A echo 'B'
  183. autocmd BufEnter A echo 'C'
  184. autocmd BufEnter B echo 'D'
  185. autocmd BufEnter B echo 'E'
  186. autocmd BufEnter B echo 'F'
  187. augroup END
  188. augroup test_2
  189. autocmd BufEnter C echo 'A'
  190. autocmd BufEnter C echo 'B'
  191. autocmd BufEnter C echo 'C'
  192. autocmd BufEnter D echo 'D'
  193. autocmd BufEnter D echo 'E'
  194. autocmd BufEnter D echo 'F'
  195. augroup END
  196. let g:output = execute('autocmd BufEnter')
  197. ]])
  198. eq(
  199. dedent([[
  200. --- Autocommands ---
  201. test_1 BufEnter
  202. A echo 'A'
  203. echo 'B'
  204. echo 'C'
  205. B echo 'D'
  206. echo 'E'
  207. echo 'F'
  208. test_2 BufEnter
  209. C echo 'A'
  210. echo 'B'
  211. echo 'C'
  212. D echo 'D'
  213. echo 'E'
  214. echo 'F']]),
  215. eval('g:output')
  216. )
  217. end)
  218. end)