quickfix_commands_spec.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local feed = n.feed
  5. local eq = t.eq
  6. local clear = n.clear
  7. local fn = n.fn
  8. local command = n.command
  9. local exc_exec = n.exc_exec
  10. local write_file = t.write_file
  11. local api = n.api
  12. local source = n.source
  13. local file_base = 'Xtest-functional-ex_cmds-quickfix_commands'
  14. before_each(clear)
  15. for _, c in ipairs({ 'l', 'c' }) do
  16. local file = ('%s.%s'):format(file_base, c)
  17. local filecmd = c .. 'file'
  18. local getfcmd = c .. 'getfile'
  19. local addfcmd = c .. 'addfile'
  20. local getlist = (c == 'c') and fn.getqflist or function()
  21. return fn.getloclist(0)
  22. end
  23. describe((':%s*file commands'):format(c), function()
  24. before_each(function()
  25. write_file(
  26. file,
  27. ([[
  28. %s-1.res:700:10:Line 700
  29. %s-2.res:800:15:Line 800
  30. ]]):format(file, file)
  31. )
  32. end)
  33. after_each(function()
  34. os.remove(file)
  35. end)
  36. it('work', function()
  37. command(('%s %s'):format(filecmd, file))
  38. -- Second line of each entry (i.e. `nr=-1, …`) was obtained from actual
  39. -- results. First line (i.e. `{lnum=…`) was obtained from legacy test.
  40. local list = {
  41. {
  42. lnum = 700,
  43. end_lnum = 0,
  44. col = 10,
  45. end_col = 0,
  46. text = 'Line 700',
  47. module = '',
  48. nr = -1,
  49. bufnr = 2,
  50. valid = 1,
  51. pattern = '',
  52. vcol = 0,
  53. ['type'] = '',
  54. },
  55. {
  56. lnum = 800,
  57. end_lnum = 0,
  58. col = 15,
  59. end_col = 0,
  60. text = 'Line 800',
  61. module = '',
  62. nr = -1,
  63. bufnr = 3,
  64. valid = 1,
  65. pattern = '',
  66. vcol = 0,
  67. ['type'] = '',
  68. },
  69. }
  70. eq(list, getlist())
  71. eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
  72. eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
  73. -- Run cfile/lfile from a modified buffer
  74. command('set nohidden')
  75. command('enew!')
  76. api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
  77. eq(
  78. ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd),
  79. exc_exec(('%s %s'):format(filecmd, file))
  80. )
  81. write_file(
  82. file,
  83. ([[
  84. %s-3.res:900:30:Line 900
  85. ]]):format(file)
  86. )
  87. command(('%s %s'):format(addfcmd, file))
  88. list[#list + 1] = {
  89. lnum = 900,
  90. end_lnum = 0,
  91. col = 30,
  92. end_col = 0,
  93. text = 'Line 900',
  94. module = '',
  95. nr = -1,
  96. bufnr = 5,
  97. valid = 1,
  98. pattern = '',
  99. vcol = 0,
  100. ['type'] = '',
  101. }
  102. eq(list, getlist())
  103. eq(('%s-3.res'):format(file), fn.bufname(list[3].bufnr))
  104. write_file(
  105. file,
  106. ([[
  107. %s-1.res:222:77:Line 222
  108. %s-2.res:333:88:Line 333
  109. ]]):format(file, file)
  110. )
  111. command('enew!')
  112. command(('%s %s'):format(getfcmd, file))
  113. list = {
  114. {
  115. lnum = 222,
  116. end_lnum = 0,
  117. col = 77,
  118. end_col = 0,
  119. text = 'Line 222',
  120. module = '',
  121. nr = -1,
  122. bufnr = 2,
  123. valid = 1,
  124. pattern = '',
  125. vcol = 0,
  126. ['type'] = '',
  127. },
  128. {
  129. lnum = 333,
  130. end_lnum = 0,
  131. col = 88,
  132. end_col = 0,
  133. text = 'Line 333',
  134. module = '',
  135. nr = -1,
  136. bufnr = 3,
  137. valid = 1,
  138. pattern = '',
  139. vcol = 0,
  140. ['type'] = '',
  141. },
  142. }
  143. eq(list, getlist())
  144. eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
  145. eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
  146. end)
  147. end)
  148. end
  149. describe('quickfix', function()
  150. it('location-list update on buffer modification', function()
  151. source([[
  152. new
  153. setl bt=nofile
  154. let lines = ['Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5']
  155. call append(0, lines)
  156. new
  157. setl bt=nofile
  158. call append(0, lines)
  159. let qf_item = {
  160. \ 'lnum': 4,
  161. \ 'text': "This is the error line.",
  162. \ }
  163. let qf_item['bufnr'] = bufnr('%')
  164. call setloclist(0, [qf_item])
  165. wincmd p
  166. let qf_item['bufnr'] = bufnr('%')
  167. call setloclist(0, [qf_item])
  168. 1del _
  169. call append(0, ['New line 1', 'New line 2', 'New line 3'])
  170. silent ll
  171. ]])
  172. eq({ 0, 6, 1, 0, 1 }, fn.getcurpos())
  173. end)
  174. it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function()
  175. local file = file_base .. '_reuse_qfbuf_BufAdd'
  176. write_file(file, ('\n'):rep(100) .. 'foo')
  177. finally(function()
  178. os.remove(file)
  179. end)
  180. source([[
  181. set grepprg=internal
  182. autocmd BufAdd * call and(0, 0)
  183. autocmd QuickFixCmdPost grep ++nested cclose | cwindow
  184. ]])
  185. command('grep foo ' .. file)
  186. command('grep foo ' .. file)
  187. end)
  188. it('jump message does not scroll with cmdheight=0 and shm+=O #29597', function()
  189. local screen = Screen.new(40, 6)
  190. command('set cmdheight=0')
  191. local file = file_base .. '_reuse_qfbuf_BufAdd'
  192. write_file(file, 'foobar')
  193. finally(function()
  194. os.remove(file)
  195. end)
  196. command('vimgrep /foo/gj ' .. file)
  197. feed(':cc<CR>')
  198. screen:expect([[
  199. ^foobar |
  200. {1:~ }|*4
  201. (1 of 1): foobar |
  202. ]])
  203. end)
  204. end)
  205. it(':vimgrep can specify Unicode pattern without delimiters', function()
  206. eq(
  207. 'Vim(vimgrep):E480: No match: →',
  208. exc_exec('vimgrep → test/functional/fixtures/tty-test.c')
  209. )
  210. local screen = Screen.new(40, 6)
  211. screen:set_default_attr_ids({
  212. [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
  213. [1] = { reverse = true }, -- IncSearch
  214. })
  215. feed('i→<Esc>:vimgrep →')
  216. screen:expect([[
  217. {1:→} |
  218. {0:~ }|*4
  219. :vimgrep →^ |
  220. ]])
  221. end)