refactor(test): simplify v:argf tests #38055

This commit is contained in:
Justin M. Keyes
2026-02-25 13:06:53 -05:00
committed by GitHub
parent 1983c70d10
commit c0f8b3fb66
3 changed files with 49 additions and 101 deletions

View File

@@ -1806,88 +1806,3 @@ describe('inccommand on ex mode', function()
]])
end)
end)
describe('v:argf', function()
local files = {}
before_each(function()
clear()
files = {}
for _, f in ipairs({
'Xargf_file1',
'Xargf_file2',
'Xargf_sep1',
'Xargf_sep2',
'Xargf_sep3',
}) do
os.remove(f)
end
end)
after_each(function()
for _, f in ipairs(files) do
os.remove(f)
end
end)
it('stores full path of file args', function()
local file1, file2 = 'Xargf_file1', 'Xargf_file2'
write_file(file1, '')
write_file(file2, '')
files = { file1, file2 }
local abs1 = fn.fnamemodify(file1, ':p')
local abs2 = fn.fnamemodify(file2, ':p')
local p = n.spawn_wait('--cmd', 'echo v:argf', '-c', 'qall', file1, file2)
eq(0, p.status)
matches(pesc(abs1), p.stderr)
matches(pesc(abs2), p.stderr)
end)
it('argadd does not affect v:argf', function()
local file1, file2 = 'Xargf_file1', 'Xargf_file2'
write_file(file1, '')
write_file(file2, '')
files = { file1, file2 }
local p = n.spawn_wait(
'--cmd',
'argadd extrafile.txt',
'--cmd',
'echo v:argf',
'-c',
'qall',
file1,
file2
)
eq(0, p.status)
eq(nil, string.find(p.stderr, 'extrafile.txt'))
end)
it('handles -- separator correctly', function()
local file1, file2, file3 = 'Xargf_sep1', 'Xargf_sep2', 'Xargf_sep3'
write_file(file1, '')
write_file(file2, '')
write_file(file3, '')
files = { file1, file2, file3 }
local abs1 = fn.fnamemodify(file1, ':p')
local abs2 = fn.fnamemodify(file2, ':p')
local abs3 = fn.fnamemodify(file3, ':p')
local p = n.spawn_wait(file1, '--cmd', 'echo v:argf', '-c', 'qall', '--', file2, file3)
eq(0, p.status)
matches(pesc(abs1), p.stderr)
matches(pesc(abs2), p.stderr)
matches(pesc(abs3), p.stderr)
end)
it('is read-only', function()
matches('E46', t.pcall_err(command, "let v:argf = ['foo']"))
end)
end)

View File

@@ -1,16 +0,0 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local clear, eval, eq = n.clear, n.eval, t.eq
local command = n.command
describe('v:event', function()
before_each(clear)
it('is empty before any autocommand', function()
eq({}, eval('v:event'))
end)
it('is immutable', function()
eq(false, pcall(command, 'let v:event = {}'))
eq(false, pcall(command, 'let v:event.mykey = {}'))
end)
end)

View File

@@ -0,0 +1,49 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local clear, eval, eq = n.clear, n.eval, t.eq
local command = n.command
describe('v:event', function()
before_each(clear)
it('is empty before any autocommand', function()
eq({}, eval('v:event'))
end)
it('is immutable', function()
eq(false, pcall(command, 'let v:event = {}'))
eq(false, pcall(command, 'let v:event.mykey = {}'))
end)
end)
describe('v:argf', function()
it('is read-only', function()
n.clear()
t.matches('E46', t.pcall_err(command, "let v:argf = ['foo']"))
end)
it('gets file args, ignores :argadd, handles "--"', function()
local file1, file2, file3 = 'Xargf_sep1', 'Xargf_sep2', 'Xargf_sep3'
n.clear {
args_rm = { '--cmd', '-c' },
args = {
'--clean',
'--cmd',
'argadd extrafile.txt', -- :argadd should not affect v:argf.
file1,
file2,
'-c',
'let a = 1 + 3',
'--',
file3,
},
}
local abs1 = n.fn.fnamemodify(file1, ':p')
local abs2 = n.fn.fnamemodify(file2, ':p')
local abs3 = n.fn.fnamemodify(file3, ':p')
eq({ abs1, abs2, abs3 }, n.eval('v:argf'))
end)
end)