2016-05-14 03:26:03 -07:00
|
|
|
-- Test argument list commands
|
|
|
|
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2017-04-08 14:12:26 -07:00
|
|
|
local clear, command, eq = helpers.clear, helpers.command, helpers.eq
|
2016-05-14 07:05:41 -07:00
|
|
|
local eval, exc_exec, neq = helpers.eval, helpers.exc_exec, helpers.neq
|
2016-05-14 03:26:03 -07:00
|
|
|
|
|
|
|
describe('argument list commands', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
2016-05-14 07:05:41 -07:00
|
|
|
local function init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('args a b c')
|
|
|
|
command('next')
|
2016-05-14 03:40:05 -07:00
|
|
|
end
|
|
|
|
|
2016-05-14 07:05:41 -07:00
|
|
|
local function reset_arglist()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('arga a | %argd')
|
2016-05-14 04:26:27 -07:00
|
|
|
end
|
|
|
|
|
2016-05-14 07:05:41 -07:00
|
|
|
local function assert_fails(cmd, err)
|
2016-05-14 04:26:27 -07:00
|
|
|
neq(exc_exec(cmd):find(err), nil)
|
|
|
|
end
|
|
|
|
|
2016-05-14 03:40:05 -07:00
|
|
|
it('test that argidx() works', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('args a b c')
|
|
|
|
command('last')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(2, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argdelete')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(0, eval('argidx()'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('args a b c')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(0, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('next')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(1, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('next')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(2, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('1argdelete')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(1, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('1argdelete')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(0, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('1argdelete')
|
2016-05-14 03:26:03 -07:00
|
|
|
eq(0, eval('argidx()'))
|
|
|
|
end)
|
2016-05-14 03:40:05 -07:00
|
|
|
|
|
|
|
it('test that argadd() works', function()
|
2017-04-08 16:15:26 -07:00
|
|
|
-- Fails with “E474: Invalid argument”. Not sure whether it is how it is
|
|
|
|
-- supposed to behave.
|
|
|
|
-- command('%argdelete')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argadd a b c')
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(0, eval('argidx()'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argdelete')
|
|
|
|
command('argadd a')
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(0, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argadd b c d')
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(0, eval('argidx()'))
|
|
|
|
|
|
|
|
init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argadd x')
|
2016-05-14 07:05:41 -07:00
|
|
|
eq({'a', 'b', 'x', 'c'}, eval('argv()'))
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(1, eval('argidx()'))
|
|
|
|
|
|
|
|
init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('0argadd x')
|
2016-05-14 07:05:41 -07:00
|
|
|
eq({'x', 'a', 'b', 'c'}, eval('argv()'))
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(2, eval('argidx()'))
|
|
|
|
|
|
|
|
init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('1argadd x')
|
2016-05-14 07:05:41 -07:00
|
|
|
eq({'a', 'x', 'b', 'c'}, eval('argv()'))
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(2, eval('argidx()'))
|
|
|
|
|
|
|
|
init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$argadd x')
|
2016-05-14 07:05:41 -07:00
|
|
|
eq({'a', 'b', 'c', 'x'}, eval('argv()'))
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(1, eval('argidx()'))
|
|
|
|
|
|
|
|
init_abc()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$argadd x')
|
|
|
|
command('+2argadd y')
|
2016-05-14 07:05:41 -07:00
|
|
|
eq({'a', 'b', 'c', 'x', 'y'}, eval('argv()'))
|
2016-05-14 03:40:05 -07:00
|
|
|
eq(1, eval('argidx()'))
|
2016-05-14 06:51:44 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
|
|
|
command('edit d')
|
|
|
|
command('arga')
|
2016-05-14 06:51:44 -07:00
|
|
|
eq(1, eval('len(argv())'))
|
|
|
|
eq('d', eval('get(argv(), 0, "")'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
|
|
|
command('new')
|
|
|
|
command('arga')
|
2016-05-14 06:51:44 -07:00
|
|
|
eq(0, eval('len(argv())'))
|
2016-05-14 03:40:05 -07:00
|
|
|
end)
|
2016-05-14 04:26:27 -07:00
|
|
|
|
|
|
|
it('test for 0argadd and 0argedit', function()
|
|
|
|
reset_arglist()
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('arga a b c d')
|
|
|
|
command('2argu')
|
|
|
|
command('0arga added')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'added', 'a', 'b', 'c', 'd'}, eval('argv()'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
|
|
|
command('arga a b c d')
|
|
|
|
command('2argu')
|
|
|
|
command('0arge edited')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'edited', 'a', 'b', 'c', 'd'}, eval('argv()'))
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command('2argu')
|
|
|
|
command('arga third')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'edited', 'a', 'third', 'b', 'c', 'd'}, eval('argv()'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for argc()', function()
|
|
|
|
reset_arglist()
|
|
|
|
eq(0, eval('argc()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argadd a b')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(2, eval('argc()'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for arglistid()', function()
|
|
|
|
reset_arglist()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('arga a b')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(0, eval('arglistid()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('split')
|
|
|
|
command('arglocal')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(1, eval('arglistid()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('tabnew | tabfirst')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(0, eval('arglistid(2)'))
|
|
|
|
eq(1, eval('arglistid(1, 1)'))
|
|
|
|
eq(0, eval('arglistid(2, 1)'))
|
|
|
|
eq(1, eval('arglistid(1, 2)'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('tabonly | only | enew!')
|
|
|
|
command('argglobal')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(0, eval('arglistid()'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for argv()', function()
|
|
|
|
reset_arglist()
|
|
|
|
eq({}, eval('argv()'))
|
|
|
|
eq('', eval('argv(2)'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argadd a b c d')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq('c', eval('argv(2)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for :argedit command', function()
|
|
|
|
reset_arglist()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argedit a')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'a'}, eval('argv()'))
|
|
|
|
eq('a', eval('expand("%:t")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argedit b')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'a', 'b'}, eval('argv()'))
|
|
|
|
eq('b', eval('expand("%:t")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argedit a')
|
2018-02-11 08:06:34 -07:00
|
|
|
eq({'a', 'b', 'a'}, eval('argv()'))
|
2016-05-14 04:26:27 -07:00
|
|
|
eq('a', eval('expand("%:t")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argedit c')
|
2018-02-11 08:06:34 -07:00
|
|
|
eq({'a', 'b', 'a', 'c'}, eval('argv()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('0argedit x')
|
2018-02-11 08:06:34 -07:00
|
|
|
eq({'x', 'a', 'b', 'a', 'c'}, eval('argv()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('enew! | set modified')
|
2016-05-14 04:26:27 -07:00
|
|
|
assert_fails('argedit y', 'E37:')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('argedit! y')
|
2018-02-11 08:06:34 -07:00
|
|
|
eq({'x', 'y', 'y', 'a', 'b', 'a', 'c'}, eval('argv()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
|
|
|
command('argedit a b')
|
2018-02-11 08:06:34 -07:00
|
|
|
eq({'a', 'b'}, eval('argv()'))
|
2016-05-14 04:26:27 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for :argdelete command', function()
|
|
|
|
reset_arglist()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('args aa a aaa b bb')
|
|
|
|
command('argdelete a*')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'b', 'bb'}, eval('argv()'))
|
|
|
|
eq('aa', eval('expand("%:t")'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('last')
|
|
|
|
command('argdelete %')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq({'b'}, eval('argv()'))
|
|
|
|
assert_fails('argdelete', 'E471:')
|
|
|
|
assert_fails('1,100argdelete', 'E16:')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
2016-05-14 04:26:27 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('test for the :next, :prev, :first, :last, :rewind commands', function()
|
|
|
|
reset_arglist()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('args a b c d')
|
|
|
|
command('last')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(3, eval('argidx()'))
|
|
|
|
assert_fails('next', 'E165:')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('prev')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(2, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('Next')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(1, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('first')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(0, eval('argidx()'))
|
|
|
|
assert_fails('prev', 'E164:')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('3next')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(3, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('rewind')
|
2016-05-14 04:26:27 -07:00
|
|
|
eq(0, eval('argidx()'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%argd')
|
2016-05-14 04:26:27 -07:00
|
|
|
end)
|
2017-03-28 16:30:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
it('test for autocommand that redefines the argument list, when doing ":all"', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('autocmd BufReadPost Xxx2 next Xxx2 Xxx1')
|
|
|
|
command("call writefile(['test file Xxx1'], 'Xxx1')")
|
|
|
|
command("call writefile(['test file Xxx2'], 'Xxx2')")
|
|
|
|
command("call writefile(['test file Xxx3'], 'Xxx3')")
|
|
|
|
|
|
|
|
command('new')
|
2017-03-28 16:30:54 -07:00
|
|
|
-- redefine arglist; go to Xxx1
|
2017-04-08 14:12:26 -07:00
|
|
|
command('next! Xxx1 Xxx2 Xxx3')
|
2017-03-28 16:30:54 -07:00
|
|
|
-- open window for all args
|
2017-04-08 14:12:26 -07:00
|
|
|
command('all')
|
2017-03-28 16:30:54 -07:00
|
|
|
eq('test file Xxx1', eval('getline(1)'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wincmd w')
|
|
|
|
command('wincmd w')
|
2017-03-28 16:30:54 -07:00
|
|
|
eq('test file Xxx1', eval('getline(1)'))
|
|
|
|
-- should now be in Xxx2
|
2017-04-08 14:12:26 -07:00
|
|
|
command('rewind')
|
2017-03-28 16:30:54 -07:00
|
|
|
eq('test file Xxx2', eval('getline(1)'))
|
2017-04-08 14:12:26 -07:00
|
|
|
|
|
|
|
command('autocmd! BufReadPost Xxx2')
|
|
|
|
command('enew! | only')
|
|
|
|
command("call delete('Xxx1')")
|
|
|
|
command("call delete('Xxx2')")
|
|
|
|
command("call delete('Xxx3')")
|
|
|
|
command('argdelete Xxx*')
|
|
|
|
command('bwipe! Xxx1 Xxx2 Xxx3')
|
2017-03-28 16:30:54 -07:00
|
|
|
end)
|
2016-05-14 03:26:03 -07:00
|
|
|
end)
|