defaults_spec.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. --
  2. -- Tests for default autocmds, mappings, commands, and menus.
  3. --
  4. -- See options/defaults_spec.lua for default options and environment decisions.
  5. --
  6. local t = require('test.testutil')
  7. local n = require('test.functional.testnvim')()
  8. local Screen = require('test.functional.ui.screen')
  9. describe('default', function()
  10. describe('autocommands', function()
  11. it('nvim_terminal.TermClose closes terminal with default shell on success', function()
  12. n.clear()
  13. n.api.nvim_set_option_value('shell', n.testprg('shell-test'), {})
  14. n.command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=')
  15. -- Should not block other events
  16. n.command('let g:n=0')
  17. n.command('au BufEnter * let g:n = g:n + 1')
  18. n.command('terminal')
  19. t.eq(1, n.eval('get(g:, "n", 0)'))
  20. t.retry(nil, 1000, function()
  21. t.neq('terminal', n.api.nvim_get_option_value('buftype', { buf = 0 }))
  22. t.eq(2, n.eval('get(g:, "n", 0)'))
  23. end)
  24. end)
  25. end)
  26. describe('popupmenu', function()
  27. it('can be disabled by user', function()
  28. n.clear {
  29. args = { '+autocmd! nvim.popupmenu', '+aunmenu PopUp' },
  30. }
  31. local screen = Screen.new(40, 8)
  32. n.insert([[
  33. 1 line 1
  34. 2 https://example.com
  35. 3 line 3
  36. 4 line 4]])
  37. n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
  38. screen:expect({
  39. grid = [[
  40. 1 line 1 |
  41. 2 ht^tps://example.com |
  42. 3 line 3 |
  43. 4 line 4 |
  44. {1:~ }|*3
  45. |
  46. ]],
  47. })
  48. end)
  49. it('right-click on URL shows "Open in web browser"', function()
  50. n.clear()
  51. local screen = Screen.new(40, 8)
  52. n.insert([[
  53. 1 line 1
  54. 2 https://example.com
  55. 3 line 3
  56. 4 line 4]])
  57. n.api.nvim_input_mouse('right', 'press', '', 0, 3, 4)
  58. screen:expect({
  59. grid = [[
  60. 1 line 1 |
  61. 2 https://example.com |
  62. 3 line 3 |
  63. 4 li^ne 4 |
  64. {1:~ }{4: Inspect }{1: }|
  65. {1:~ }{4: }{1: }|
  66. {1:~ }{4: Paste }{1: }|
  67. {4: Select All } |
  68. ]],
  69. })
  70. n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
  71. screen:expect({
  72. grid = [[
  73. 1 line 1 |
  74. 2 ht^tps://example.com |
  75. 3 l{4: Open in web browser } |
  76. 4 l{4: Inspect } |
  77. {1:~ }{4: }{1: }|
  78. {1:~ }{4: Paste }{1: }|
  79. {1:~ }{4: Select All }{1: }|
  80. {4: } |
  81. ]],
  82. })
  83. end)
  84. end)
  85. describe('key mappings', function()
  86. describe('Visual mode search mappings', function()
  87. it('handle various chars properly', function()
  88. n.clear({ args_rm = { '--cmd' } })
  89. local screen = Screen.new(60, 8)
  90. screen:set_default_attr_ids({
  91. [1] = { foreground = Screen.colors.NvimDarkGray4 },
  92. [2] = {
  93. foreground = Screen.colors.NvimDarkGray3,
  94. background = Screen.colors.NvimLightGray3,
  95. },
  96. [3] = {
  97. foreground = Screen.colors.NvimLightGrey1,
  98. background = Screen.colors.NvimDarkYellow,
  99. },
  100. [4] = {
  101. foreground = Screen.colors.NvimDarkGrey1,
  102. background = Screen.colors.NvimLightYellow,
  103. },
  104. })
  105. n.api.nvim_buf_set_lines(0, 0, -1, true, {
  106. [[testing <CR> /?\!1]],
  107. [[testing <CR> /?\!2]],
  108. [[testing <CR> /?\!3]],
  109. [[testing <CR> /?\!4]],
  110. })
  111. n.feed('gg0vf!')
  112. n.poke_eventloop()
  113. n.feed('*')
  114. screen:expect([[
  115. {3:testing <CR> /?\!}1 |
  116. {4:^testing <CR> /?\!}2 |
  117. {3:testing <CR> /?\!}3 |
  118. {3:testing <CR> /?\!}4 |
  119. {1:~ }|*2
  120. {2:[No Name] [+] 2,1 All}|
  121. /\Vtesting <CR> /?\\! [2/4] |
  122. ]])
  123. n.feed('n')
  124. screen:expect([[
  125. {3:testing <CR> /?\!}1 |
  126. {3:testing <CR> /?\!}2 |
  127. {4:^testing <CR> /?\!}3 |
  128. {3:testing <CR> /?\!}4 |
  129. {1:~ }|*2
  130. {2:[No Name] [+] 3,1 All}|
  131. /\Vtesting <CR> /?\\! [3/4] |
  132. ]])
  133. n.feed('G0vf!')
  134. n.poke_eventloop()
  135. n.feed('#')
  136. screen:expect([[
  137. {3:testing <CR> /?\!}1 |
  138. {3:testing <CR> /?\!}2 |
  139. {4:^testing <CR> /?\!}3 |
  140. {3:testing <CR> /?\!}4 |
  141. {1:~ }|*2
  142. {2:[No Name] [+] 3,1 All}|
  143. ?\Vtesting <CR> /?\\! [3/4] |
  144. ]])
  145. n.feed('n')
  146. screen:expect([[
  147. {3:testing <CR> /?\!}1 |
  148. {4:^testing <CR> /?\!}2 |
  149. {3:testing <CR> /?\!}3 |
  150. {3:testing <CR> /?\!}4 |
  151. {1:~ }|*2
  152. {2:[No Name] [+] 2,1 All}|
  153. ?\Vtesting <CR> /?\\! [2/4] |
  154. ]])
  155. end)
  156. end)
  157. describe('unimpaired-style mappings', function()
  158. it('show the command ouptut when successful', function()
  159. n.clear({ args_rm = { '--cmd' } })
  160. local screen = Screen.new(40, 8)
  161. n.fn.setqflist({
  162. { filename = 'file1', text = 'item1' },
  163. { filename = 'file2', text = 'item2' },
  164. })
  165. n.feed(']q')
  166. screen:set_default_attr_ids({
  167. [1] = { foreground = Screen.colors.NvimDarkGrey4 },
  168. [2] = {
  169. background = Screen.colors.NvimLightGray3,
  170. foreground = Screen.colors.NvimDarkGrey3,
  171. },
  172. })
  173. screen:expect({
  174. grid = [[
  175. ^ |
  176. {1:~ }|*5
  177. {2:file2 0,0-1 All}|
  178. (2 of 2): item2 |
  179. ]],
  180. })
  181. end)
  182. it('do not show a full stack trace when unsuccessful #30625', function()
  183. n.clear({ args_rm = { '--cmd' } })
  184. local screen = Screen.new(40, 8)
  185. screen:set_default_attr_ids({
  186. [1] = { foreground = Screen.colors.NvimDarkGray4 },
  187. [2] = {
  188. background = Screen.colors.NvimLightGrey3,
  189. foreground = Screen.colors.NvimDarkGray3,
  190. },
  191. [3] = { foreground = Screen.colors.NvimLightRed },
  192. [4] = { foreground = Screen.colors.NvimLightCyan },
  193. })
  194. n.feed('[a')
  195. screen:expect({
  196. grid = [[
  197. |
  198. {1:~ }|*4
  199. {2: }|
  200. {3:E163: There is only one file to edit} |
  201. {4:Press ENTER or type command to continue}^ |
  202. ]],
  203. })
  204. n.feed('[q')
  205. screen:expect({
  206. grid = [[
  207. ^ |
  208. {1:~ }|*5
  209. {2:[No Name] 0,0-1 All}|
  210. {3:E42: No Errors} |
  211. ]],
  212. })
  213. n.feed('[l')
  214. screen:expect({
  215. grid = [[
  216. ^ |
  217. {1:~ }|*5
  218. {2:[No Name] 0,0-1 All}|
  219. {3:E776: No location list} |
  220. ]],
  221. })
  222. n.feed('[t')
  223. screen:expect({
  224. grid = [[
  225. ^ |
  226. {1:~ }|*5
  227. {2:[No Name] 0,0-1 All}|
  228. {3:E73: Tag stack empty} |
  229. ]],
  230. })
  231. end)
  232. describe('[<Space>', function()
  233. it('adds an empty line above the current line', function()
  234. n.clear({ args_rm = { '--cmd' } })
  235. n.insert([[first line]])
  236. n.feed('[<Space>')
  237. n.expect([[
  238. first line]])
  239. end)
  240. it('works with a count', function()
  241. n.clear({ args_rm = { '--cmd' } })
  242. n.insert([[first line]])
  243. n.feed('5[<Space>')
  244. n.expect([[
  245. first line]])
  246. end)
  247. it('supports dot repetition', function()
  248. n.clear({ args_rm = { '--cmd' } })
  249. n.insert([[first line]])
  250. n.feed('[<Space>')
  251. n.feed('.')
  252. n.expect([[
  253. first line]])
  254. end)
  255. it('supports dot repetition and a count', function()
  256. n.clear({ args_rm = { '--cmd' } })
  257. n.insert([[first line]])
  258. n.feed('[<Space>')
  259. n.feed('3.')
  260. n.expect([[
  261. first line]])
  262. end)
  263. end)
  264. describe(']<Space>', function()
  265. it('adds an empty line below the current line', function()
  266. n.clear({ args_rm = { '--cmd' } })
  267. n.insert([[first line]])
  268. n.feed(']<Space>')
  269. n.expect([[
  270. first line
  271. ]])
  272. end)
  273. it('works with a count', function()
  274. n.clear({ args_rm = { '--cmd' } })
  275. n.insert([[first line]])
  276. n.feed('5]<Space>')
  277. n.expect([[
  278. first line
  279. ]])
  280. end)
  281. it('supports dot repetition', function()
  282. n.clear({ args_rm = { '--cmd' } })
  283. n.insert([[first line]])
  284. n.feed(']<Space>')
  285. n.feed('.')
  286. n.expect([[
  287. first line
  288. ]])
  289. end)
  290. it('supports dot repetition and a count', function()
  291. n.clear({ args_rm = { '--cmd' } })
  292. n.insert([[first line]])
  293. n.feed(']<Space>')
  294. n.feed('2.')
  295. n.expect([[
  296. first line
  297. ]])
  298. end)
  299. end)
  300. end)
  301. end)
  302. end)