blob: af92f1565640242ec6eb925a85c4f5300bd12c2f [file] [log] [blame]
Bram Moolenaar72defda2016-01-17 18:04:33 +01001" Test argument list commands
2
3func Test_argidx()
4 args a b c
5 last
6 call assert_equal(2, argidx())
7 %argdelete
8 call assert_equal(0, argidx())
9
10 args a b c
11 call assert_equal(0, argidx())
12 next
13 call assert_equal(1, argidx())
14 next
15 call assert_equal(2, argidx())
16 1argdelete
17 call assert_equal(1, argidx())
18 1argdelete
19 call assert_equal(0, argidx())
20 1argdelete
21 call assert_equal(0, argidx())
22endfunc
Bram Moolenaara24f0a52016-01-17 19:39:00 +010023
24func Test_argadd()
25 %argdelete
26 argadd a b c
27 call assert_equal(0, argidx())
28
29 %argdelete
30 argadd a
31 call assert_equal(0, argidx())
32 argadd b c d
33 call assert_equal(0, argidx())
34
35 call Init_abc()
36 argadd x
37 call Assert_argc(['a', 'b', 'x', 'c'])
38 call assert_equal(1, argidx())
39
40 call Init_abc()
41 0argadd x
42 call Assert_argc(['x', 'a', 'b', 'c'])
43 call assert_equal(2, argidx())
44
45 call Init_abc()
46 1argadd x
47 call Assert_argc(['a', 'x', 'b', 'c'])
48 call assert_equal(2, argidx())
49
50 call Init_abc()
51 $argadd x
52 call Assert_argc(['a', 'b', 'c', 'x'])
53 call assert_equal(1, argidx())
54
55 call Init_abc()
56 $argadd x
57 +2argadd y
58 call Assert_argc(['a', 'b', 'c', 'x', 'y'])
59 call assert_equal(1, argidx())
60endfunc
61
62func Init_abc()
63 args a b c
64 next
65endfunc
66
67func Assert_argc(l)
68 call assert_equal(len(a:l), argc())
69 let i = 0
70 while i < len(a:l) && i < argc()
71 call assert_equal(a:l[i], argv(i))
72 let i += 1
73 endwhile
74endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +010075
76" Test for [count]argument and [count]argdelete commands
77" Ported from the test_argument_count.in test script
78function Test_argument()
79 " Clean the argument list
80 arga a | %argd
81
82 let save_hidden = &hidden
83 set hidden
84
85 let g:buffers = []
86 augroup TEST
87 au BufEnter * call add(buffers, expand('%:t'))
88 augroup END
89
90 argadd a b c d
91 $argu
92 $-argu
93 -argu
94 1argu
95 +2argu
96
97 augroup TEST
98 au!
99 augroup END
100
101 call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
102
103 redir => result
104 ar
105 redir END
106 call assert_true(result =~# 'a b \[c] d')
107
108 .argd
109 call assert_equal(['a', 'b', 'd'], argv())
110
111 -argd
112 call assert_equal(['a', 'd'], argv())
113
114 $argd
115 call assert_equal(['a'], argv())
116
117 1arga c
118 1arga b
119 $argu
120 $arga x
121 call assert_equal(['a', 'b', 'c', 'x'], argv())
122
123 0arga Y
124 call assert_equal(['Y', 'a', 'b', 'c', 'x'], argv())
125
126 %argd
127 call assert_equal([], argv())
128
129 arga a b c d e f
130 2,$-argd
131 call assert_equal(['a', 'f'], argv())
132
133 let &hidden = save_hidden
134
135 " Setting argument list should fail when the current buffer has unsaved
136 " changes
137 %argd
138 enew!
139 set modified
140 call assert_fails('args x y z', 'E37:')
141 args! x y z
142 call assert_equal(['x', 'y', 'z'], argv())
143 call assert_equal('x', expand('%:t'))
144
145 last | enew | argu
146 call assert_equal('z', expand('%:t'))
147
148 %argdelete
149 call assert_fails('argument', 'E163:')
150endfunction
151
152" Test for 0argadd and 0argedit
153" Ported from the test_argument_0count.in test script
154function Test_zero_argadd()
155 " Clean the argument list
156 arga a | %argd
157
158 arga a b c d
159 2argu
160 0arga added
161 call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
162
163 2argu
164 arga third
165 call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
166
167 %argd
168 arga a b c d
169 2argu
170 0arge edited
171 call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
172
173 2argu
174 arga third
175 call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
176endfunction
177
178function Reset_arglist()
179 args a | %argd
180endfunction
181
182" Test for argc()
183function Test_argc()
184 call Reset_arglist()
185 call assert_equal(0, argc())
186 argadd a b
187 call assert_equal(2, argc())
188endfunction
189
190" Test for arglistid()
191function Test_arglistid()
192 call Reset_arglist()
193 arga a b
194 call assert_equal(0, arglistid())
195 split
196 arglocal
197 call assert_equal(1, arglistid())
198 tabnew | tabfirst
199 call assert_equal(0, arglistid(2))
200 call assert_equal(1, arglistid(1, 1))
201 call assert_equal(0, arglistid(2, 1))
202 call assert_equal(1, arglistid(1, 2))
203 tabonly | only | enew!
204 argglobal
205 call assert_equal(0, arglistid())
206endfunction
207
208" Test for argv()
209function Test_argv()
210 call Reset_arglist()
211 call assert_equal([], argv())
212 call assert_equal("", argv(2))
213 argadd a b c d
214 call assert_equal('c', argv(2))
215endfunction
216
217" Test for the :argedit command
218function Test_argedit()
219 call Reset_arglist()
220 argedit a
221 call assert_equal(['a'], argv())
222 call assert_equal('a', expand('%:t'))
223 argedit b
224 call assert_equal(['a', 'b'], argv())
225 call assert_equal('b', expand('%:t'))
226 argedit a
227 call assert_equal(['a', 'b'], argv())
228 call assert_equal('a', expand('%:t'))
229 call assert_fails('argedit a b', 'E172:')
230 argedit c
231 call assert_equal(['a', 'c', 'b'], argv())
232 0argedit x
233 call assert_equal(['x', 'a', 'c', 'b'], argv())
234 enew! | set modified
235 call assert_fails('argedit y', 'E37:')
236 argedit! y
237 call assert_equal(['x', 'y', 'a', 'c', 'b'], argv())
238 %argd
239endfunction
240
241" Test for the :argdelete command
242function Test_argdelete()
243 call Reset_arglist()
244 args aa a aaa b bb
245 argdelete a*
246 call assert_equal(['b', 'bb'], argv())
247 call assert_equal('aa', expand('%:t'))
248 last
249 argdelete %
250 call assert_equal(['b'], argv())
251 call assert_fails('argdelete', 'E471:')
252 call assert_fails('1,100argdelete', 'E16:')
253 %argd
254endfunction
255
256" Tests for the :next, :prev, :first, :last, :rewind commands
257function Test_argpos()
258 call Reset_arglist()
259 args a b c d
260 last
261 call assert_equal(3, argidx())
262 call assert_fails('next', 'E165:')
263 prev
264 call assert_equal(2, argidx())
265 Next
266 call assert_equal(1, argidx())
267 first
268 call assert_equal(0, argidx())
269 call assert_fails('prev', 'E164:')
270 3next
271 call assert_equal(3, argidx())
272 rewind
273 call assert_equal(0, argidx())
274 %argd
275endfunction