robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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