mirror of
https://github.com/neovim/neovim.git
synced 2026-05-03 20:45:02 +00:00
refactor(test): simplify v:argf tests #38055
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
49
test/functional/vimscript/vvars_spec.lua
Normal file
49
test/functional/vimscript/vvars_spec.lua
Normal 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)
|
||||
Reference in New Issue
Block a user