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