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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
" Test argument list commands
func Test_argidx()
args a b c
last
call assert_equal(2, argidx())
%argdelete
call assert_equal(0, argidx())
args a b c
call assert_equal(0, argidx())
next
call assert_equal(1, argidx())
next
call assert_equal(2, argidx())
1argdelete
call assert_equal(1, argidx())
1argdelete
call assert_equal(0, argidx())
1argdelete
call assert_equal(0, argidx())
endfunc
func Test_argadd()
%argdelete
argadd a b c
call assert_equal(0, argidx())
%argdelete
argadd a
call assert_equal(0, argidx())
argadd b c d
call assert_equal(0, argidx())
call Init_abc()
argadd x
call Assert_argc(['a', 'b', 'x', 'c'])
call assert_equal(1, argidx())
call Init_abc()
0argadd x
call Assert_argc(['x', 'a', 'b', 'c'])
call assert_equal(2, argidx())
call Init_abc()
1argadd x
call Assert_argc(['a', 'x', 'b', 'c'])
call assert_equal(2, argidx())
call Init_abc()
$argadd x
call Assert_argc(['a', 'b', 'c', 'x'])
call assert_equal(1, argidx())
call Init_abc()
$argadd x
+2argadd y
call Assert_argc(['a', 'b', 'c', 'x', 'y'])
call assert_equal(1, argidx())
%argd
edit d
arga
call assert_equal(len(argv()), 1)
call assert_equal(get(argv(), 0, ''), 'd')
%argd
new
arga
call assert_equal(len(argv()), 0)
endfunc
func Init_abc()
args a b c
next
endfunc
func Assert_argc(l)
call assert_equal(len(a:l), argc())
let i = 0
while i < len(a:l) && i < argc()
call assert_equal(a:l[i], argv(i))
let i += 1
endwhile
endfunc
" Test for [count]argument and [count]argdelete commands
" Ported from the test_argument_count.in test script
function Test_argument()
" Clean the argument list
arga a | %argd
let save_hidden = &hidden
set hidden
let g:buffers = []
augroup TEST
au BufEnter * call add(buffers, expand('%:t'))
augroup END
argadd a b c d
$argu
$-argu
-argu
1argu
+2argu
augroup TEST
au!
augroup END
call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
redir => result
ar
redir END
call assert_true(result =~# 'a b \[c] d')
.argd
call assert_equal(['a', 'b', 'd'], argv())
-argd
call assert_equal(['a', 'd'], argv())
$argd
call assert_equal(['a'], argv())
1arga c
1arga b
$argu
$arga x
call assert_equal(['a', 'b', 'c', 'x'], argv())
0arga y
call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
%argd
call assert_equal([], argv())
arga a b c d e f
2,$-argd
call assert_equal(['a', 'f'], argv())
let &hidden = save_hidden
" Setting argument list should fail when the current buffer has unsaved
" changes
%argd
enew!
set modified
call assert_fails('args x y z', 'E37:')
args! x y z
call assert_equal(['x', 'y', 'z'], argv())
call assert_equal('x', expand('%:t'))
last | enew | argu
call assert_equal('z', expand('%:t'))
%argdelete
call assert_fails('argument', 'E163:')
endfunction
" Test for 0argadd and 0argedit
" Ported from the test_argument_0count.in test script
function Test_zero_argadd()
" Clean the argument list
arga a | %argd
arga a b c d
2argu
0arga added
call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
2argu
arga third
call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
%argd
arga a b c d
2argu
0arge edited
call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
2argu
arga third
call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
endfunction
function Reset_arglist()
args a | %argd
endfunction
" Test for argc()
function Test_argc()
call Reset_arglist()
call assert_equal(0, argc())
argadd a b
call assert_equal(2, argc())
endfunction
" Test for arglistid()
function Test_arglistid()
call Reset_arglist()
arga a b
call assert_equal(0, arglistid())
split
arglocal
call assert_equal(1, arglistid())
tabnew | tabfirst
call assert_equal(0, arglistid(2))
call assert_equal(1, arglistid(1, 1))
call assert_equal(0, arglistid(2, 1))
call assert_equal(1, arglistid(1, 2))
tabonly | only | enew!
argglobal
call assert_equal(0, arglistid())
endfunction
" Test for argv()
function Test_argv()
call Reset_arglist()
call assert_equal([], argv())
call assert_equal("", argv(2))
argadd a b c d
call assert_equal('c', argv(2))
endfunction
" Test for the :argedit command
function Test_argedit()
call Reset_arglist()
argedit a
call assert_equal(['a'], argv())
call assert_equal('a', expand('%:t'))
argedit b
call assert_equal(['a', 'b'], argv())
call assert_equal('b', expand('%:t'))
argedit a
call assert_equal(['a', 'b'], argv())
call assert_equal('a', expand('%:t'))
if has('unix')
" on MS-Windows this would edit file "a b"
call assert_fails('argedit a b', 'E172:')
endif
argedit c
call assert_equal(['a', 'c', 'b'], argv())
0argedit x
call assert_equal(['x', 'a', 'c', 'b'], argv())
enew! | set modified
call assert_fails('argedit y', 'E37:')
argedit! y
call assert_equal(['x', 'y', 'a', 'c', 'b'], argv())
%argd
endfunction
" Test for the :argdelete command
function Test_argdelete()
call Reset_arglist()
args aa a aaa b bb
argdelete a*
call assert_equal(['b', 'bb'], argv())
call assert_equal('aa', expand('%:t'))
last
argdelete %
call assert_equal(['b'], argv())
call assert_fails('argdelete', 'E471:')
call assert_fails('1,100argdelete', 'E16:')
%argd
endfunction
" Tests for the :next, :prev, :first, :last, :rewind commands
function Test_argpos()
call Reset_arglist()
args a b c d
last
call assert_equal(3, argidx())
call assert_fails('next', 'E165:')
prev
call assert_equal(2, argidx())
Next
call assert_equal(1, argidx())
first
call assert_equal(0, argidx())
call assert_fails('prev', 'E164:')
3next
call assert_equal(3, argidx())
rewind
call assert_equal(0, argidx())
%argd
endfunction
|