defaults_spec.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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!o*')
  112. screen:expect([[
  113. {3:testing <CR> /?\!}1 |
  114. {4:^testing <CR> /?\!}2 |
  115. {3:testing <CR> /?\!}3 |
  116. {3:testing <CR> /?\!}4 |
  117. {1:~ }|*2
  118. {2:[No Name] [+] 2,1 All}|
  119. /\Vtesting <CR> \/?\\! [2/4] |
  120. ]])
  121. n.feed('n')
  122. screen:expect([[
  123. {3:testing <CR> /?\!}1 |
  124. {3:testing <CR> /?\!}2 |
  125. {4:^testing <CR> /?\!}3 |
  126. {3:testing <CR> /?\!}4 |
  127. {1:~ }|*2
  128. {2:[No Name] [+] 3,1 All}|
  129. /\Vtesting <CR> \/?\\! [3/4] |
  130. ]])
  131. n.feed('G0vf!o#')
  132. screen:expect([[
  133. {3:testing <CR> /?\!}1 |
  134. {3:testing <CR> /?\!}2 |
  135. {4:^testing <CR> /?\!}3 |
  136. {3:testing <CR> /?\!}4 |
  137. {1:~ }|*2
  138. {2:[No Name] [+] 3,1 All}|
  139. ?\Vtesting <CR> /?\\! [3/4] |
  140. ]])
  141. n.feed('n')
  142. screen:expect([[
  143. {3:testing <CR> /?\!}1 |
  144. {4:^testing <CR> /?\!}2 |
  145. {3:testing <CR> /?\!}3 |
  146. {3:testing <CR> /?\!}4 |
  147. {1:~ }|*2
  148. {2:[No Name] [+] 2,1 All}|
  149. ?\Vtesting <CR> /?\\! [2/4] |
  150. ]])
  151. end)
  152. end)
  153. describe('unimpaired-style mappings', function()
  154. it('show the command ouptut when successful', function()
  155. n.clear({ args_rm = { '--cmd' } })
  156. local screen = Screen.new(40, 8)
  157. n.fn.setqflist({
  158. { filename = 'file1', text = 'item1' },
  159. { filename = 'file2', text = 'item2' },
  160. })
  161. n.feed(']q')
  162. screen:set_default_attr_ids({
  163. [1] = { foreground = Screen.colors.NvimDarkGrey4 },
  164. [2] = {
  165. background = Screen.colors.NvimLightGray3,
  166. foreground = Screen.colors.NvimDarkGrey3,
  167. },
  168. })
  169. screen:expect({
  170. grid = [[
  171. ^ |
  172. {1:~ }|*5
  173. {2:file2 0,0-1 All}|
  174. (2 of 2): item2 |
  175. ]],
  176. })
  177. end)
  178. it('do not show a full stack trace when unsuccessful #30625', function()
  179. n.clear({ args_rm = { '--cmd' } })
  180. local screen = Screen.new(40, 8)
  181. screen:set_default_attr_ids({
  182. [1] = { foreground = Screen.colors.NvimDarkGray4 },
  183. [2] = {
  184. background = Screen.colors.NvimLightGrey3,
  185. foreground = Screen.colors.NvimDarkGray3,
  186. },
  187. [3] = { foreground = Screen.colors.NvimLightRed },
  188. [4] = { foreground = Screen.colors.NvimLightCyan },
  189. })
  190. n.feed('[a')
  191. screen:expect({
  192. grid = [[
  193. |
  194. {1:~ }|*4
  195. {2: }|
  196. {3:E163: There is only one file to edit} |
  197. {4:Press ENTER or type command to continue}^ |
  198. ]],
  199. })
  200. n.feed('[q')
  201. screen:expect({
  202. grid = [[
  203. ^ |
  204. {1:~ }|*5
  205. {2:[No Name] 0,0-1 All}|
  206. {3:E42: No Errors} |
  207. ]],
  208. })
  209. n.feed('[l')
  210. screen:expect({
  211. grid = [[
  212. ^ |
  213. {1:~ }|*5
  214. {2:[No Name] 0,0-1 All}|
  215. {3:E776: No location list} |
  216. ]],
  217. })
  218. n.feed('[t')
  219. screen:expect({
  220. grid = [[
  221. ^ |
  222. {1:~ }|*5
  223. {2:[No Name] 0,0-1 All}|
  224. {3:E73: Tag stack empty} |
  225. ]],
  226. })
  227. end)
  228. describe('[<Space>', function()
  229. it('adds an empty line above the current line', function()
  230. n.clear({ args_rm = { '--cmd' } })
  231. n.insert([[first line]])
  232. n.feed('[<Space>')
  233. n.expect([[
  234. first line]])
  235. end)
  236. it('works with a count', function()
  237. n.clear({ args_rm = { '--cmd' } })
  238. n.insert([[first line]])
  239. n.feed('5[<Space>')
  240. n.expect([[
  241. first line]])
  242. end)
  243. it('supports dot repetition', function()
  244. n.clear({ args_rm = { '--cmd' } })
  245. n.insert([[first line]])
  246. n.feed('[<Space>')
  247. n.feed('.')
  248. n.expect([[
  249. first line]])
  250. end)
  251. it('supports dot repetition and a count', function()
  252. n.clear({ args_rm = { '--cmd' } })
  253. n.insert([[first line]])
  254. n.feed('[<Space>')
  255. n.feed('3.')
  256. n.expect([[
  257. first line]])
  258. end)
  259. end)
  260. describe(']<Space>', function()
  261. it('adds an empty line below the current line', function()
  262. n.clear({ args_rm = { '--cmd' } })
  263. n.insert([[first line]])
  264. n.feed(']<Space>')
  265. n.expect([[
  266. first line
  267. ]])
  268. end)
  269. it('works with a count', function()
  270. n.clear({ args_rm = { '--cmd' } })
  271. n.insert([[first line]])
  272. n.feed('5]<Space>')
  273. n.expect([[
  274. first line
  275. ]])
  276. end)
  277. it('supports dot repetition', function()
  278. n.clear({ args_rm = { '--cmd' } })
  279. n.insert([[first line]])
  280. n.feed(']<Space>')
  281. n.feed('.')
  282. n.expect([[
  283. first line
  284. ]])
  285. end)
  286. it('supports dot repetition and a count', function()
  287. n.clear({ args_rm = { '--cmd' } })
  288. n.insert([[first line]])
  289. n.feed(']<Space>')
  290. n.feed('2.')
  291. n.expect([[
  292. first line
  293. ]])
  294. end)
  295. end)
  296. end)
  297. end)
  298. end)