defaults_spec.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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('unimpaired-style mappings', function()
  87. it('do not show a full stack trace #30625', function()
  88. n.clear({ args_rm = { '--cmd' } })
  89. local screen = Screen.new(40, 8)
  90. screen:set_default_attr_ids({
  91. [1] = { foreground = Screen.colors.NvimDarkGray4 },
  92. [2] = {
  93. background = Screen.colors.NvimLightGrey3,
  94. foreground = Screen.colors.NvimDarkGray3,
  95. },
  96. [3] = { foreground = Screen.colors.NvimLightRed },
  97. [4] = { foreground = Screen.colors.NvimLightCyan },
  98. })
  99. n.feed('[a')
  100. screen:expect({
  101. grid = [[
  102. |
  103. {1:~ }|*4
  104. {2: }|
  105. {3:E163: There is only one file to edit} |
  106. {4:Press ENTER or type command to continue}^ |
  107. ]],
  108. })
  109. n.feed('[q')
  110. screen:expect({
  111. grid = [[
  112. ^ |
  113. {1:~ }|*5
  114. {2:[No Name] 0,0-1 All}|
  115. {3:E42: No Errors} |
  116. ]],
  117. })
  118. n.feed('[l')
  119. screen:expect({
  120. grid = [[
  121. ^ |
  122. {1:~ }|*5
  123. {2:[No Name] 0,0-1 All}|
  124. {3:E776: No location list} |
  125. ]],
  126. })
  127. n.feed('[t')
  128. screen:expect({
  129. grid = [[
  130. ^ |
  131. {1:~ }|*5
  132. {2:[No Name] 0,0-1 All}|
  133. {3:E73: Tag stack empty} |
  134. ]],
  135. })
  136. end)
  137. describe('[<Space>', function()
  138. it('adds an empty line above the current line', function()
  139. n.clear({ args_rm = { '--cmd' } })
  140. n.insert([[first line]])
  141. n.feed('[<Space>')
  142. n.expect([[
  143. first line]])
  144. end)
  145. it('works with a count', function()
  146. n.clear({ args_rm = { '--cmd' } })
  147. n.insert([[first line]])
  148. n.feed('5[<Space>')
  149. n.expect([[
  150. first line]])
  151. end)
  152. it('supports dot repetition', function()
  153. n.clear({ args_rm = { '--cmd' } })
  154. n.insert([[first line]])
  155. n.feed('[<Space>')
  156. n.feed('.')
  157. n.expect([[
  158. first line]])
  159. end)
  160. it('supports dot repetition and a count', function()
  161. n.clear({ args_rm = { '--cmd' } })
  162. n.insert([[first line]])
  163. n.feed('[<Space>')
  164. n.feed('3.')
  165. n.expect([[
  166. first line]])
  167. end)
  168. end)
  169. describe(']<Space>', function()
  170. it('adds an empty line below the current line', function()
  171. n.clear({ args_rm = { '--cmd' } })
  172. n.insert([[first line]])
  173. n.feed(']<Space>')
  174. n.expect([[
  175. first line
  176. ]])
  177. end)
  178. it('works with a count', function()
  179. n.clear({ args_rm = { '--cmd' } })
  180. n.insert([[first line]])
  181. n.feed('5]<Space>')
  182. n.expect([[
  183. first line
  184. ]])
  185. end)
  186. it('supports dot repetition', function()
  187. n.clear({ args_rm = { '--cmd' } })
  188. n.insert([[first line]])
  189. n.feed(']<Space>')
  190. n.feed('.')
  191. n.expect([[
  192. first line
  193. ]])
  194. end)
  195. it('supports dot repetition and a count', function()
  196. n.clear({ args_rm = { '--cmd' } })
  197. n.insert([[first line]])
  198. n.feed(']<Space>')
  199. n.feed('2.')
  200. n.expect([[
  201. first line
  202. ]])
  203. end)
  204. end)
  205. end)
  206. end)
  207. end)