blob: 6e3116271e77d8970d9febe3c1ee10973493458c [file] [log] [blame]
Bram Moolenaarb20e3342016-01-18 23:29:01 +01001" Test for reading and writing .viminfo
2
Bram Moolenaar156919f2016-10-15 20:46:20 +02003function Test_viminfo_read_and_write()
Bram Moolenaar26b654a2019-07-22 20:50:17 +02004 " First clear 'history', so that "hislen" is zero. Then set it again,
5 " simulating Vim starting up.
6 set history=0
7 wviminfo Xviminfo
8 set history=1000
9
Bram Moolenaar45d2eea2016-06-06 21:07:52 +020010 call histdel(':')
Bram Moolenaarb20e3342016-01-18 23:29:01 +010011 let lines = [
12 \ '# comment line',
13 \ '*encoding=utf-8',
14 \ '~MSle0~/asdf',
15 \ '|copied as-is',
16 \ '|and one more',
17 \ ]
18 call writefile(lines, 'Xviminfo')
19 rviminfo Xviminfo
20 call assert_equal('asdf', @/)
21
22 wviminfo Xviminfo
23 let lines = readfile('Xviminfo')
24 let done = 0
25 for line in lines
Bram Moolenaar156919f2016-10-15 20:46:20 +020026 if line[0] == '|' && line !~ '^|[234],' && line !~ '^|<'
Bram Moolenaarb20e3342016-01-18 23:29:01 +010027 if done == 0
Bram Moolenaar2d358992016-06-12 21:20:54 +020028 call assert_equal('|1,4', line)
Bram Moolenaarb20e3342016-01-18 23:29:01 +010029 elseif done == 1
Bram Moolenaar45d2eea2016-06-06 21:07:52 +020030 call assert_equal('|copied as-is', line)
31 elseif done == 2
Bram Moolenaarb20e3342016-01-18 23:29:01 +010032 call assert_equal('|and one more', line)
33 endif
34 let done += 1
35 endif
36 endfor
Bram Moolenaar45d2eea2016-06-06 21:07:52 +020037 call assert_equal(3, done)
Bram Moolenaarb20e3342016-01-18 23:29:01 +010038
39 call delete('Xviminfo')
40endfunc
41
42func Test_global_vars()
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +020043 let g:MY_GLOBAL_STRING = "Vim Editor"
44 let g:MY_GLOBAL_NUM = 345
45 let g:MY_GLOBAL_FLOAT = 3.14
Bram Moolenaarb20e3342016-01-18 23:29:01 +010046 let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000}
47 let g:MY_GLOBAL_DICT = test_dict
48 " store a really long list, so line wrapping will occur in viminfo file
49 let test_list = range(1,100)
50 let g:MY_GLOBAL_LIST = test_list
Bram Moolenaar8c8b8bb2019-01-13 17:48:04 +010051 let test_blob = 0z00112233445566778899aabbccddeeff
52 let g:MY_GLOBAL_BLOB = test_blob
53 let test_false = v:false
54 let g:MY_GLOBAL_FALSE = test_false
55 let test_true = v:true
56 let g:MY_GLOBAL_TRUE = test_true
57 let test_null = v:null
58 let g:MY_GLOBAL_NULL = test_null
59 let test_none = v:none
60 let g:MY_GLOBAL_NONE = test_none
61
Bram Moolenaare9c07272016-03-30 20:50:46 +020062 set viminfo='100,<50,s10,h,!,nviminfo
Bram Moolenaarb20e3342016-01-18 23:29:01 +010063 wv! Xviminfo
Bram Moolenaar8c8b8bb2019-01-13 17:48:04 +010064
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +020065 unlet g:MY_GLOBAL_STRING
66 unlet g:MY_GLOBAL_NUM
67 unlet g:MY_GLOBAL_FLOAT
Bram Moolenaarb20e3342016-01-18 23:29:01 +010068 unlet g:MY_GLOBAL_DICT
69 unlet g:MY_GLOBAL_LIST
Bram Moolenaar8c8b8bb2019-01-13 17:48:04 +010070 unlet g:MY_GLOBAL_BLOB
71 unlet g:MY_GLOBAL_FALSE
72 unlet g:MY_GLOBAL_TRUE
73 unlet g:MY_GLOBAL_NULL
74 unlet g:MY_GLOBAL_NONE
Bram Moolenaarb20e3342016-01-18 23:29:01 +010075
76 rv! Xviminfo
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +020077 call assert_equal("Vim Editor", g:MY_GLOBAL_STRING)
78 call assert_equal(345, g:MY_GLOBAL_NUM)
79 call assert_equal(3.14, g:MY_GLOBAL_FLOAT)
Bram Moolenaarb20e3342016-01-18 23:29:01 +010080 call assert_equal(test_dict, g:MY_GLOBAL_DICT)
81 call assert_equal(test_list, g:MY_GLOBAL_LIST)
Bram Moolenaar8c8b8bb2019-01-13 17:48:04 +010082 call assert_equal(test_blob, g:MY_GLOBAL_BLOB)
83 call assert_equal(test_false, g:MY_GLOBAL_FALSE)
84 call assert_equal(test_true, g:MY_GLOBAL_TRUE)
85 call assert_equal(test_null, g:MY_GLOBAL_NULL)
86 call assert_equal(test_none, g:MY_GLOBAL_NONE)
Bram Moolenaarb20e3342016-01-18 23:29:01 +010087
88 call delete('Xviminfo')
89 set viminfo-=!
90endfunc
Bram Moolenaar45d2eea2016-06-06 21:07:52 +020091
92func Test_cmdline_history()
93 call histdel(':')
94 call test_settime(11)
95 call histadd(':', "echo 'one'")
96 call test_settime(12)
97 " split into two lines
98 let long800 = repeat(" 'eight'", 100)
99 call histadd(':', "echo " . long800)
100 call test_settime(13)
101 " split into three lines
102 let long1400 = repeat(" 'fourteeeeen'", 100)
103 call histadd(':', "echo " . long1400)
104 wviminfo Xviminfo
105 let lines = readfile('Xviminfo')
106 let done_colon = 0
107 let done_bar = 0
108 let lnum = 0
109 while lnum < len(lines)
110 let line = lines[lnum] | let lnum += 1
111 if line[0] == ':'
112 if done_colon == 0
113 call assert_equal(":\x161408", line)
114 let line = lines[lnum] | let lnum += 1
115 call assert_equal('<echo ' . long1400, line)
116 elseif done_colon == 1
117 call assert_equal(":\x16808", line)
118 let line = lines[lnum] | let lnum += 1
119 call assert_equal("<echo " . long800, line)
120 elseif done_colon == 2
121 call assert_equal(":echo 'one'", line)
122 endif
123 let done_colon += 1
124 elseif line[0:4] == '|2,0,'
125 if done_bar == 0
126 call assert_equal("|2,0,13,,>1407", line)
127 let line = lines[lnum] | let lnum += 1
128 call assert_equal('|<"echo ' . long1400[0:484], line)
129 let line = lines[lnum] | let lnum += 1
130 call assert_equal('|<' . long1400[485:974], line)
131 let line = lines[lnum] | let lnum += 1
132 call assert_equal('|<' . long1400[975:] . '"', line)
133 elseif done_bar == 1
134 call assert_equal('|2,0,12,,>807', line)
135 let line = lines[lnum] | let lnum += 1
136 call assert_equal('|<"echo ' . long800[0:484], line)
137 let line = lines[lnum] | let lnum += 1
138 call assert_equal('|<' . long800[485:] . '"', line)
139 elseif done_bar == 2
140 call assert_equal("|2,0,11,,\"echo 'one'\"", line)
141 endif
142 let done_bar += 1
143 endif
144 endwhile
145 call assert_equal(3, done_colon)
146 call assert_equal(3, done_bar)
147
148 call histdel(':')
149 rviminfo Xviminfo
150 call assert_equal("echo " . long1400, histget(':', -1))
151 call assert_equal("echo " . long800, histget(':', -2))
152 call assert_equal("echo 'one'", histget(':', -3))
153
154 call delete('Xviminfo')
155endfunc
Bram Moolenaar1fd99c12016-06-09 20:24:28 +0200156
157func Test_cmdline_history_order()
158 call histdel(':')
159 call test_settime(11)
160 call histadd(':', "echo '11'")
161 call test_settime(22)
162 call histadd(':', "echo '22'")
163 call test_settime(33)
164 call histadd(':', "echo '33'")
165 wviminfo Xviminfo
166
167 call histdel(':')
168 " items go in between
169 call test_settime(15)
170 call histadd(':', "echo '15'")
171 call test_settime(27)
172 call histadd(':', "echo '27'")
173
174 rviminfo Xviminfo
175 call assert_equal("echo '33'", histget(':', -1))
176 call assert_equal("echo '27'", histget(':', -2))
177 call assert_equal("echo '22'", histget(':', -3))
178 call assert_equal("echo '15'", histget(':', -4))
179 call assert_equal("echo '11'", histget(':', -5))
180
181 call histdel(':')
182 " items go before and after
Bram Moolenaarce90e362019-09-08 18:58:44 +0200183 eval 8->test_settime()
Bram Moolenaar1fd99c12016-06-09 20:24:28 +0200184 call histadd(':', "echo '8'")
185 call test_settime(39)
186 call histadd(':', "echo '39'")
187
188 rviminfo Xviminfo
189 call assert_equal("echo '39'", histget(':', -1))
190 call assert_equal("echo '33'", histget(':', -2))
191 call assert_equal("echo '22'", histget(':', -3))
192 call assert_equal("echo '11'", histget(':', -4))
193 call assert_equal("echo '8'", histget(':', -5))
194
195 " Check sorting works when writing with merge.
196 call histdel(':')
197 call test_settime(8)
198 call histadd(':', "echo '8'")
199 call test_settime(15)
200 call histadd(':', "echo '15'")
201 call test_settime(27)
202 call histadd(':', "echo '27'")
203 call test_settime(39)
204 call histadd(':', "echo '39'")
205 wviminfo Xviminfo
206
207 call histdel(':')
208 rviminfo Xviminfo
209 call assert_equal("echo '39'", histget(':', -1))
210 call assert_equal("echo '33'", histget(':', -2))
211 call assert_equal("echo '27'", histget(':', -3))
212 call assert_equal("echo '22'", histget(':', -4))
213 call assert_equal("echo '15'", histget(':', -5))
214 call assert_equal("echo '11'", histget(':', -6))
215 call assert_equal("echo '8'", histget(':', -7))
216
217 call delete('Xviminfo')
218endfunc
Bram Moolenaar01227092016-06-11 14:47:40 +0200219
Bram Moolenaare80ff742016-06-11 21:14:18 +0200220func Test_viminfo_registers()
221 call test_settime(8)
222 call setreg('a', "eight", 'c')
223 call test_settime(20)
224 call setreg('b', ["twenty", "again"], 'l')
225 call test_settime(40)
226 call setreg('c', ["four", "agai"], 'b4')
227 let l = []
228 set viminfo='100,<600,s10,h,!,nviminfo
229 for i in range(500)
230 call add(l, 'something')
231 endfor
232 call setreg('d', l, 'l')
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200233 call setreg('e', "abc\<C-V>xyz")
Bram Moolenaare80ff742016-06-11 21:14:18 +0200234 wviminfo Xviminfo
235
236 call test_settime(10)
237 call setreg('a', '', 'b10')
238 call test_settime(15)
239 call setreg('b', 'drop')
240 call test_settime(50)
241 call setreg('c', 'keep', 'l')
242 call test_settime(30)
243 call setreg('d', 'drop', 'l')
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200244 call setreg('e', 'drop')
Bram Moolenaare80ff742016-06-11 21:14:18 +0200245 rviminfo Xviminfo
246
247 call assert_equal("", getreg('a'))
248 call assert_equal("\<C-V>10", getregtype('a'))
249 call assert_equal("twenty\nagain\n", getreg('b'))
250 call assert_equal("V", getregtype('b'))
251 call assert_equal("keep\n", getreg('c'))
252 call assert_equal("V", getregtype('c'))
253 call assert_equal(l, getreg('d', 1, 1))
254 call assert_equal("V", getregtype('d'))
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200255 call assert_equal("abc\<C-V>xyz", getreg('e'))
Bram Moolenaare80ff742016-06-11 21:14:18 +0200256
Bram Moolenaar25709572016-08-26 20:41:16 +0200257 " Length around 440 switches to line continuation.
258 let len = 434
259 while len < 445
260 let s = repeat('a', len)
261 call setreg('"', s)
262 wviminfo Xviminfo
263 call setreg('"', '')
264 rviminfo Xviminfo
265 call assert_equal(s, getreg('"'), 'wrong register at length: ' . len)
266
267 let len += 1
268 endwhile
269
Bram Moolenaare80ff742016-06-11 21:14:18 +0200270 call delete('Xviminfo')
271endfunc
272
Bram Moolenaar2d358992016-06-12 21:20:54 +0200273func Test_viminfo_marks()
274 sp bufa
275 let bufa = bufnr('%')
276 sp bufb
277 let bufb = bufnr('%')
278
279 call test_settime(8)
280 call setpos("'A", [bufa, 1, 1, 0])
281 call test_settime(20)
282 call setpos("'B", [bufb, 9, 1, 0])
283 call setpos("'C", [bufa, 7, 1, 0])
284
285 delmark 0-9
286 call test_settime(25)
287 call setpos("'1", [bufb, 12, 1, 0])
288 call test_settime(35)
289 call setpos("'0", [bufa, 11, 1, 0])
290
291 call test_settime(45)
292 wviminfo Xviminfo
293
294 " Writing viminfo inserts the '0 mark.
295 call assert_equal([bufb, 1, 1, 0], getpos("'0"))
296 call assert_equal([bufa, 11, 1, 0], getpos("'1"))
297 call assert_equal([bufb, 12, 1, 0], getpos("'2"))
298
299 call test_settime(4)
300 call setpos("'A", [bufa, 9, 1, 0])
301 call test_settime(30)
302 call setpos("'B", [bufb, 2, 3, 0])
303 delmark C
304
305 delmark 0-9
306 call test_settime(30)
307 call setpos("'1", [bufb, 22, 1, 0])
308 call test_settime(55)
309 call setpos("'0", [bufa, 21, 1, 0])
310
311 rviminfo Xviminfo
312
313 call assert_equal([bufa, 1, 1, 0], getpos("'A"))
314 call assert_equal([bufb, 2, 3, 0], getpos("'B"))
315 call assert_equal([bufa, 7, 1, 0], getpos("'C"))
316
317 " numbered marks are merged
318 call assert_equal([bufa, 21, 1, 0], getpos("'0")) " time 55
319 call assert_equal([bufb, 1, 1, 0], getpos("'1")) " time 45
320 call assert_equal([bufa, 11, 1, 0], getpos("'2")) " time 35
321 call assert_equal([bufb, 22, 1, 0], getpos("'3")) " time 30
322 call assert_equal([bufb, 12, 1, 0], getpos("'4")) " time 25
323
324 call delete('Xviminfo')
325 exe 'bwipe ' . bufa
326 exe 'bwipe ' . bufb
327endfunc
328
329func Test_viminfo_jumplist()
330 split testbuf
331 clearjumps
332 call setline(1, ['time 05', 'time 10', 'time 15', 'time 20', 'time 30', 'last pos'])
333 call cursor(2, 1)
334 call test_settime(10)
335 exe "normal /20\r"
336 call test_settime(20)
337 exe "normal /30\r"
338 call test_settime(30)
339 exe "normal /last pos\r"
340 wviminfo Xviminfo
341
342 clearjumps
343 call cursor(1, 1)
344 call test_settime(5)
345 exe "normal /15\r"
346 call test_settime(15)
347 exe "normal /last pos\r"
348 call test_settime(40)
349 exe "normal ?30\r"
350 rviminfo Xviminfo
351
352 call assert_equal('time 30', getline('.'))
353 exe "normal \<C-O>"
354 call assert_equal('last pos', getline('.'))
355 exe "normal \<C-O>"
356 " duplicate for 'time 30' was removed
357 call assert_equal('time 20', getline('.'))
358 exe "normal \<C-O>"
359 call assert_equal('time 15', getline('.'))
360 exe "normal \<C-O>"
361 call assert_equal('time 10', getline('.'))
362 exe "normal \<C-O>"
363 call assert_equal('time 05', getline('.'))
364
Bram Moolenaarece74ab2016-06-13 22:22:15 +0200365 clearjumps
366 call cursor(1, 1)
367 call test_settime(5)
368 exe "normal /15\r"
369 call test_settime(15)
370 exe "normal /last pos\r"
371 call test_settime(40)
372 exe "normal ?30\r"
373 " Test merge when writing
374 wviminfo Xviminfo
375 clearjumps
376 rviminfo Xviminfo
377
Bram Moolenaar28607ba2016-06-15 21:44:51 +0200378 let last_line = line('.')
Bram Moolenaarece74ab2016-06-13 22:22:15 +0200379 exe "normal \<C-O>"
380 call assert_equal('time 30', getline('.'))
381 exe "normal \<C-O>"
382 call assert_equal('last pos', getline('.'))
383 exe "normal \<C-O>"
384 " duplicate for 'time 30' was removed
385 call assert_equal('time 20', getline('.'))
386 exe "normal \<C-O>"
387 call assert_equal('time 15', getline('.'))
388 exe "normal \<C-O>"
389 call assert_equal('time 10', getline('.'))
390 exe "normal \<C-O>"
391 call assert_equal('time 05', getline('.'))
392
Bram Moolenaar28607ba2016-06-15 21:44:51 +0200393 " Test with jumplist full.
394 clearjumps
395 call setline(1, repeat(['match here'], 101))
396 call cursor(1, 1)
397 call test_settime(10)
398 for i in range(100)
399 exe "normal /here\r"
400 endfor
401 rviminfo Xviminfo
402
403 " must be newest mark that comes from viminfo.
404 exe "normal \<C-O>"
405 call assert_equal(last_line, line('.'))
406
Bram Moolenaar2d358992016-06-12 21:20:54 +0200407 bwipe!
408 call delete('Xviminfo')
409endfunc
410
Bram Moolenaar01227092016-06-11 14:47:40 +0200411func Test_viminfo_encoding()
Bram Moolenaar01227092016-06-11 14:47:40 +0200412 set enc=latin1
413 call histdel(':')
414 call histadd(':', "echo '\xe9'")
415 wviminfo Xviminfo
416
417 set fencs=utf-8,latin1
418 set enc=utf-8
419 sp Xviminfo
420 call assert_equal('latin1', &fenc)
421 close
422
423 call histdel(':')
424 rviminfo Xviminfo
425 call assert_equal("echo 'é'", histget(':', -1))
426
427 call delete('Xviminfo')
428endfunc
Bram Moolenaar62f8b4e2016-06-11 15:31:47 +0200429
430func Test_viminfo_bad_syntax()
431 let lines = []
432 call add(lines, '|<') " empty continuation line
433 call add(lines, '|234234234234234324,nothing')
434 call add(lines, '|1+"no comma"')
435 call add(lines, '|1,2,3,4,5,6,7') " too many items
436 call add(lines, '|1,"string version"')
437 call add(lines, '|1,>x') " bad continuation line
438 call add(lines, '|1,"x') " missing quote
439 call add(lines, '|1,"x\') " trailing backslash
440 call add(lines, '|1,,,,') "trailing comma
441 call add(lines, '|1,>234') " trailing continuation line
442 call writefile(lines, 'Xviminfo')
Bram Moolenaare80ff742016-06-11 21:14:18 +0200443 rviminfo Xviminfo
Bram Moolenaar62f8b4e2016-06-11 15:31:47 +0200444
445 call delete('Xviminfo')
446endfunc
447
Bram Moolenaarab9c89b2016-07-03 17:47:26 +0200448func Test_viminfo_file_marks()
449 silent! bwipe test_viminfo.vim
450 silent! bwipe Xviminfo
451
452 call test_settime(10)
453 edit ten
454 call test_settime(25)
455 edit again
456 call test_settime(30)
457 edit thirty
458 wviminfo Xviminfo
459
460 call test_settime(20)
461 edit twenty
462 call test_settime(35)
463 edit again
464 call test_settime(40)
465 edit fourty
466 wviminfo Xviminfo
467
468 sp Xviminfo
469 1
470 for name in ['fourty', 'again', 'thirty', 'twenty', 'ten']
471 /^>
472 call assert_equal(name, substitute(getline('.'), '.*/', '', ''))
473 endfor
474 close
475
476 call delete('Xviminfo')
477endfunc
Bram Moolenaare59215c2016-08-14 19:08:45 +0200478
479func Test_viminfo_file_mark_tabclose()
480 tabnew Xtestfileintab
481 call setline(1, ['a','b','c','d','e'])
482 4
483 q!
484 wviminfo Xviminfo
485 sp Xviminfo
486 /^> .*Xtestfileintab
487 let lnum = line('.')
488 while 1
489 if lnum == line('$')
Bram Moolenaar37175402017-03-18 20:18:45 +0100490 call assert_report('mark not found in Xtestfileintab')
Bram Moolenaare59215c2016-08-14 19:08:45 +0200491 break
492 endif
493 let lnum += 1
494 let line = getline(lnum)
495 if line == ''
Bram Moolenaar37175402017-03-18 20:18:45 +0100496 call assert_report('mark not found in Xtestfileintab')
Bram Moolenaare59215c2016-08-14 19:08:45 +0200497 break
498 endif
499 if line =~ "^\t\""
500 call assert_equal('4', substitute(line, ".*\"\t\\(\\d\\).*", '\1', ''))
501 break
502 endif
503 endwhile
504
505 call delete('Xviminfo')
506 silent! bwipe Xtestfileintab
507endfunc
Bram Moolenaare11d61a2016-08-20 18:36:54 +0200508
Bram Moolenaar156919f2016-10-15 20:46:20 +0200509func Test_viminfo_file_mark_zero_time()
510 let lines = [
511 \ '# Viminfo version',
512 \ '|1,4',
513 \ '',
514 \ '*encoding=utf-8',
515 \ '',
516 \ '# File marks:',
517 \ "'B 1 0 /tmp/nothing",
518 \ '|4,66,1,0,0,"/tmp/nothing"',
519 \ "",
520 \ ]
521 call writefile(lines, 'Xviminfo')
522 delmark B
523 rviminfo Xviminfo
524 call delete('Xviminfo')
525 call assert_equal(1, line("'B"))
526 delmark B
527endfunc
528
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200529" Test for saving and restoring file marks in unloaded buffers
530func Test_viminfo_file_mark_unloaded_buf()
531 let save_viminfo = &viminfo
532 set viminfo&vim
533 call writefile(repeat(['vim'], 10), 'Xfile1')
534 %bwipe
535 edit! Xfile1
536 call setpos("'u", [0, 3, 1, 0])
537 call setpos("'v", [0, 5, 1, 0])
538 enew
539 wviminfo Xviminfo
540 %bwipe
541 edit Xfile1
542 rviminfo! Xviminfo
543 call assert_equal([0, 3, 1, 0], getpos("'u"))
544 call assert_equal([0, 5, 1, 0], getpos("'v"))
545 %bwipe
546 call delete('Xfile1')
547 call delete('Xviminfo')
548 let &viminfo = save_viminfo
549endfunc
550
Bram Moolenaar156919f2016-10-15 20:46:20 +0200551func Test_viminfo_oldfiles()
Bram Moolenaare11d61a2016-08-20 18:36:54 +0200552 let v:oldfiles = []
553 let lines = [
554 \ '# comment line',
555 \ '*encoding=utf-8',
556 \ '',
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200557 \ ':h viminfo',
558 \ '?/session',
559 \ '=myvar',
560 \ '@123',
561 \ '',
562 \ "'E 2 0 /tmp/nothing",
563 \ '',
Bram Moolenaare11d61a2016-08-20 18:36:54 +0200564 \ "> /tmp/file_one.txt",
565 \ "\t\"\t11\t0",
566 \ "",
567 \ "> /tmp/file_two.txt",
568 \ "\t\"\t11\t0",
569 \ "",
570 \ "> /tmp/another.txt",
571 \ "\t\"\t11\t0",
572 \ "",
573 \ ]
574 call writefile(lines, 'Xviminfo')
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200575 delmark E
Bram Moolenaare11d61a2016-08-20 18:36:54 +0200576 rviminfo! Xviminfo
577 call delete('Xviminfo')
578
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200579 call assert_equal('h viminfo', histget(':'))
580 call assert_equal('session', histget('/'))
581 call assert_equal('myvar', histget('='))
582 call assert_equal('123', histget('@'))
583 call assert_equal(2, line("'E"))
Bram Moolenaar7b668e82016-08-23 23:51:21 +0200584 call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt', '3: /tmp/another.txt'], filter(split(execute('oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
585 call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('filter file_ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
586 call assert_equal(['3: /tmp/another.txt'], filter(split(execute('filter /another/ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'}))
Bram Moolenaar5328cb82019-07-27 23:27:51 +0200587
588 new
589 call feedkeys("3\<CR>", 't')
590 browse oldfiles
591 call assert_equal("/tmp/another.txt", expand("%"))
592 bwipe
Bram Moolenaar2a8d3b82019-10-04 21:20:25 +0200593 delmark E
594endfunc
595
596" Test for storing and restoring buffer list in 'viminfo'
597func Test_viminfo_bufferlist()
598 " If there are arguments, then :rviminfo doesn't read the buffer list.
599 " Need to delete all the arguments for :rviminfo to work.
600 %argdelete
601
602 edit Xfile1
603 edit Xfile2
604 set viminfo-=%
605 wviminfo Xviminfo
606 %bwipe
607 rviminfo Xviminfo
608 call assert_equal(1, len(getbufinfo()))
609
610 edit Xfile1
611 edit Xfile2
612 set viminfo^=%
613 wviminfo Xviminfo
614 %bwipe
615 rviminfo Xviminfo
616 let l = getbufinfo()
617 call assert_equal(3, len(l))
618 call assert_equal('Xfile1', bufname(l[1].bufnr))
619 call assert_equal('Xfile2', bufname(l[2].bufnr))
620
621 call delete('Xviminfo')
622 %bwipe
623 set viminfo-=%
624endfunc
625
626" Test for errors in a viminfo file
627func Test_viminfo_error()
628 " Non-existing viminfo files
629 call assert_fails('rviminfo xyz', 'E195:')
630
631 " Illegal starting character
632 call writefile(["a 123"], 'Xviminfo')
633 call assert_fails('rv Xviminfo', 'E575:')
634
635 " Illegal register name in the viminfo file
636 call writefile(['"@ LINE 0'], 'Xviminfo')
637 call assert_fails('rv Xviminfo', 'E577:')
638
639 " Invalid file mark line
640 call writefile(['>', '@'], 'Xviminfo')
641 call assert_fails('rv Xviminfo', 'E576:')
642
643 " Too many errors in viminfo file
644 call writefile(repeat(["a 123"], 15), 'Xviminfo')
645 call assert_fails('rv Xviminfo', 'E136:')
646
647 call writefile(['>'] + repeat(['@'], 10), 'Xviminfo')
648 call assert_fails('rv Xviminfo', 'E136:')
649
650 call writefile(repeat(['"@'], 15), 'Xviminfo')
651 call assert_fails('rv Xviminfo', 'E136:')
652
653 call delete('Xviminfo')
654endfunc
655
656" Test for saving and restoring last substitute string in viminfo
657func Test_viminfo_lastsub()
658 enew
659 call append(0, "blue blue blue")
660 call cursor(1, 1)
661 s/blue/green/
662 wviminfo Xviminfo
663 s/blue/yellow/
664 rviminfo! Xviminfo
665 &
666 call assert_equal("green yellow green", getline(1))
667 enew!
668 call delete('Xviminfo')
669endfunc
670
671" Test saving and restoring the register values using the older method
672func Test_viminfo_registers_old()
673 let lines = [
674 \ '# Viminfo version',
675 \ '|1,1',
676 \ '',
677 \ '*encoding=utf-8',
678 \ '',
679 \ '# Registers:',
680 \ '""0 CHAR 0',
681 \ ' Vim',
682 \ '"a CHAR 0',
683 \ ' red',
684 \ '"m@ CHAR 0',
685 \ " :echo 'Hello'\<CR>",
686 \ "",
687 \ ]
688 call writefile(lines, 'Xviminfo')
689 let @a = 'one'
690 let @b = 'two'
691 let @m = 'three'
692 let @" = 'four'
693 let @t = ":echo 'Unix'\<CR>"
694 silent! normal @t
695 rviminfo! Xviminfo
696 call assert_equal('red', getreg('a'))
697 call assert_equal('two', getreg('b'))
698 call assert_equal(":echo 'Hello'\<CR>", getreg('m'))
699 call assert_equal('Vim', getreg('"'))
700 call assert_equal("\nHello", execute('normal @@'))
701 call delete('Xviminfo')
702 let @" = ''
703endfunc
704
705" Test for saving and restoring large number of lines in a register
706func Test_viminfo_large_register()
707 let save_viminfo = &viminfo
708 set viminfo&vim
709 set viminfo-=<50
710 set viminfo+=<200
711 let lines = ['"r CHAR 0']
712 call extend(lines, repeat(["\tsun is rising"], 200))
713 call writefile(lines, 'Xviminfo')
714 let @r = ''
715 rviminfo! Xviminfo
716 call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r)
717 call delete('Xviminfo')
718 let &viminfo = save_viminfo
719endfunc
720
721" Test for setting 'viminfofile' to NONE
722func Test_viminfofile_none()
723 set viminfofile=NONE
724 wviminfo Xviminfo
725 call assert_false(filereadable('Xviminfo'))
726 call writefile([''], 'Xviminfo')
727 call assert_fails('rviminfo Xviminfo', 'E195:')
728 call delete('Xviminfo')
729endfunc
730
731" Test for an unwritable 'viminfo' file
732func Test_viminfo_readonly()
733 if !has('unix')
734 return
735 endif
736 call writefile([''], 'Xviminfo')
737 call setfperm('Xviminfo', 'r-x------')
738 call assert_fails('wviminfo Xviminfo', 'E137:')
739 call delete('Xviminfo')
Bram Moolenaare11d61a2016-08-20 18:36:54 +0200740endfunc