comparison src/testdir/test_arglist.vim @ 7666:8edd1afaf6b7 v7.4.1132

commit https://github.com/vim/vim/commit/99dbe291f55022bd5166c9c3c7967b8693cd9d1b Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 19 13:07:23 2016 +0100 patch 7.4.1132 Problem: Old style tests for the argument list. Solution: Add more new style tests. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Tue, 19 Jan 2016 13:15:05 +0100
parents 65b2d593c203
children fd31843c7b58
comparison
equal deleted inserted replaced
7665:ccc0c96b2eda 7666:8edd1afaf6b7
70 while i < len(a:l) && i < argc() 70 while i < len(a:l) && i < argc()
71 call assert_equal(a:l[i], argv(i)) 71 call assert_equal(a:l[i], argv(i))
72 let i += 1 72 let i += 1
73 endwhile 73 endwhile
74 endfunc 74 endfunc
75
76 " Test for [count]argument and [count]argdelete commands
77 " Ported from the test_argument_count.in test script
78 function 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:')
150 endfunction
151
152 " Test for 0argadd and 0argedit
153 " Ported from the test_argument_0count.in test script
154 function 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())
176 endfunction
177
178 function Reset_arglist()
179 args a | %argd
180 endfunction
181
182 " Test for argc()
183 function Test_argc()
184 call Reset_arglist()
185 call assert_equal(0, argc())
186 argadd a b
187 call assert_equal(2, argc())
188 endfunction
189
190 " Test for arglistid()
191 function 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())
206 endfunction
207
208 " Test for argv()
209 function 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))
215 endfunction
216
217 " Test for the :argedit command
218 function 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
239 endfunction
240
241 " Test for the :argdelete command
242 function 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
254 endfunction
255
256 " Tests for the :next, :prev, :first, :last, :rewind commands
257 function 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
275 endfunction