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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
-- Test argument list commands
local helpers = require('test.functional.helpers')(after_each)
local clear, command, eq = helpers.clear, helpers.command, helpers.eq
local eval, exc_exec, neq = helpers.eval, helpers.exc_exec, helpers.neq
describe('argument list commands', function()
before_each(clear)
local function init_abc()
command('args a b c')
command('next')
end
local function reset_arglist()
command('arga a | %argd')
end
local function assert_fails(cmd, err)
neq(exc_exec(cmd):find(err), nil)
end
it('test that argidx() works', function()
command('args a b c')
command('last')
eq(2, eval('argidx()'))
command('%argdelete')
eq(0, eval('argidx()'))
command('args a b c')
eq(0, eval('argidx()'))
command('next')
eq(1, eval('argidx()'))
command('next')
eq(2, eval('argidx()'))
command('1argdelete')
eq(1, eval('argidx()'))
command('1argdelete')
eq(0, eval('argidx()'))
command('1argdelete')
eq(0, eval('argidx()'))
end)
it('test that argadd() works', function()
-- Fails with “E474: Invalid argument”. Not sure whether it is how it is
-- supposed to behave.
-- command('%argdelete')
command('argadd a b c')
eq(0, eval('argidx()'))
command('%argdelete')
command('argadd a')
eq(0, eval('argidx()'))
command('argadd b c d')
eq(0, eval('argidx()'))
init_abc()
command('argadd x')
eq({'a', 'b', 'x', 'c'}, eval('argv()'))
eq(1, eval('argidx()'))
init_abc()
command('0argadd x')
eq({'x', 'a', 'b', 'c'}, eval('argv()'))
eq(2, eval('argidx()'))
init_abc()
command('1argadd x')
eq({'a', 'x', 'b', 'c'}, eval('argv()'))
eq(2, eval('argidx()'))
init_abc()
command('$argadd x')
eq({'a', 'b', 'c', 'x'}, eval('argv()'))
eq(1, eval('argidx()'))
init_abc()
command('$argadd x')
command('+2argadd y')
eq({'a', 'b', 'c', 'x', 'y'}, eval('argv()'))
eq(1, eval('argidx()'))
command('%argd')
command('edit d')
command('arga')
eq(1, eval('len(argv())'))
eq('d', eval('get(argv(), 0, "")'))
command('%argd')
command('new')
command('arga')
eq(0, eval('len(argv())'))
end)
it('test for 0argadd and 0argedit', function()
reset_arglist()
command('arga a b c d')
command('2argu')
command('0arga added')
eq({'added', 'a', 'b', 'c', 'd'}, eval('argv()'))
command('%argd')
command('arga a b c d')
command('2argu')
command('0arge edited')
eq({'edited', 'a', 'b', 'c', 'd'}, eval('argv()'))
command('2argu')
command('arga third')
eq({'edited', 'a', 'third', 'b', 'c', 'd'}, eval('argv()'))
end)
it('test for argc()', function()
reset_arglist()
eq(0, eval('argc()'))
command('argadd a b')
eq(2, eval('argc()'))
end)
it('test for arglistid()', function()
reset_arglist()
command('arga a b')
eq(0, eval('arglistid()'))
command('split')
command('arglocal')
eq(1, eval('arglistid()'))
command('tabnew | tabfirst')
eq(0, eval('arglistid(2)'))
eq(1, eval('arglistid(1, 1)'))
eq(0, eval('arglistid(2, 1)'))
eq(1, eval('arglistid(1, 2)'))
command('tabonly | only | enew!')
command('argglobal')
eq(0, eval('arglistid()'))
end)
it('test for argv()', function()
reset_arglist()
eq({}, eval('argv()'))
eq('', eval('argv(2)'))
command('argadd a b c d')
eq('c', eval('argv(2)'))
end)
it('test for :argedit command', function()
reset_arglist()
command('argedit a')
eq({'a'}, eval('argv()'))
eq('a', eval('expand("%:t")'))
command('argedit b')
eq({'a', 'b'}, eval('argv()'))
eq('b', eval('expand("%:t")'))
command('argedit a')
eq({'a', 'b', 'a'}, eval('argv()'))
eq('a', eval('expand("%:t")'))
command('argedit c')
eq({'a', 'b', 'a', 'c'}, eval('argv()'))
command('0argedit x')
eq({'x', 'a', 'b', 'a', 'c'}, eval('argv()'))
command('enew! | set modified')
assert_fails('argedit y', 'E37:')
command('argedit! y')
eq({'x', 'y', 'y', 'a', 'b', 'a', 'c'}, eval('argv()'))
command('%argd')
command('argedit a b')
eq({'a', 'b'}, eval('argv()'))
end)
it('test for :argdelete command', function()
reset_arglist()
command('args aa a aaa b bb')
command('argdelete a*')
eq({'b', 'bb'}, eval('argv()'))
eq('aa', eval('expand("%:t")'))
command('last')
command('argdelete %')
eq({'b'}, eval('argv()'))
assert_fails('argdelete', 'E471:')
assert_fails('1,100argdelete', 'E16:')
command('%argd')
end)
it('test for the :next, :prev, :first, :last, :rewind commands', function()
reset_arglist()
command('args a b c d')
command('last')
eq(3, eval('argidx()'))
assert_fails('next', 'E165:')
command('prev')
eq(2, eval('argidx()'))
command('Next')
eq(1, eval('argidx()'))
command('first')
eq(0, eval('argidx()'))
assert_fails('prev', 'E164:')
command('3next')
eq(3, eval('argidx()'))
command('rewind')
eq(0, eval('argidx()'))
command('%argd')
end)
it('test for autocommand that redefines the argument list, when doing ":all"', function()
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')
-- redefine arglist; go to Xxx1
command('next! Xxx1 Xxx2 Xxx3')
-- open window for all args
command('all')
eq('test file Xxx1', eval('getline(1)'))
command('wincmd w')
command('wincmd w')
eq('test file Xxx1', eval('getline(1)'))
-- should now be in Xxx2
command('rewind')
eq('test file Xxx2', eval('getline(1)'))
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')
end)
end)
|