Mercurial > vim
comparison src/testdir/test_viminfo.vim @ 18233:7d147c191ef7 v8.1.2111
patch 8.1.2111: viminfo file not sufficiently tested
Commit: https://github.com/vim/vim/commit/2a8d3b8997d4fe94bc9c02ae04e873eab2f13b09
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Oct 4 21:20:25 2019 +0200
patch 8.1.2111: viminfo file not sufficiently tested
Problem: Viminfo file not sufficiently tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5009)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 04 Oct 2019 21:30:04 +0200 |
parents | 8a2fb21c23c0 |
children | a5de1d88590d |
comparison
equal
deleted
inserted
replaced
18232:4baa5df0f47e | 18233:7d147c191ef7 |
---|---|
38 | 38 |
39 call delete('Xviminfo') | 39 call delete('Xviminfo') |
40 endfunc | 40 endfunc |
41 | 41 |
42 func Test_global_vars() | 42 func Test_global_vars() |
43 let g:MY_GLOBAL_STRING = "Vim Editor" | |
44 let g:MY_GLOBAL_NUM = 345 | |
45 let g:MY_GLOBAL_FLOAT = 3.14 | |
43 let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000} | 46 let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000} |
44 let g:MY_GLOBAL_DICT = test_dict | 47 let g:MY_GLOBAL_DICT = test_dict |
45 " store a really long list, so line wrapping will occur in viminfo file | 48 " store a really long list, so line wrapping will occur in viminfo file |
46 let test_list = range(1,100) | 49 let test_list = range(1,100) |
47 let g:MY_GLOBAL_LIST = test_list | 50 let g:MY_GLOBAL_LIST = test_list |
57 let g:MY_GLOBAL_NONE = test_none | 60 let g:MY_GLOBAL_NONE = test_none |
58 | 61 |
59 set viminfo='100,<50,s10,h,!,nviminfo | 62 set viminfo='100,<50,s10,h,!,nviminfo |
60 wv! Xviminfo | 63 wv! Xviminfo |
61 | 64 |
65 unlet g:MY_GLOBAL_STRING | |
66 unlet g:MY_GLOBAL_NUM | |
67 unlet g:MY_GLOBAL_FLOAT | |
62 unlet g:MY_GLOBAL_DICT | 68 unlet g:MY_GLOBAL_DICT |
63 unlet g:MY_GLOBAL_LIST | 69 unlet g:MY_GLOBAL_LIST |
64 unlet g:MY_GLOBAL_BLOB | 70 unlet g:MY_GLOBAL_BLOB |
65 unlet g:MY_GLOBAL_FALSE | 71 unlet g:MY_GLOBAL_FALSE |
66 unlet g:MY_GLOBAL_TRUE | 72 unlet g:MY_GLOBAL_TRUE |
67 unlet g:MY_GLOBAL_NULL | 73 unlet g:MY_GLOBAL_NULL |
68 unlet g:MY_GLOBAL_NONE | 74 unlet g:MY_GLOBAL_NONE |
69 | 75 |
70 rv! Xviminfo | 76 rv! Xviminfo |
77 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) | |
71 call assert_equal(test_dict, g:MY_GLOBAL_DICT) | 80 call assert_equal(test_dict, g:MY_GLOBAL_DICT) |
72 call assert_equal(test_list, g:MY_GLOBAL_LIST) | 81 call assert_equal(test_list, g:MY_GLOBAL_LIST) |
73 call assert_equal(test_blob, g:MY_GLOBAL_BLOB) | 82 call assert_equal(test_blob, g:MY_GLOBAL_BLOB) |
74 call assert_equal(test_false, g:MY_GLOBAL_FALSE) | 83 call assert_equal(test_false, g:MY_GLOBAL_FALSE) |
75 call assert_equal(test_true, g:MY_GLOBAL_TRUE) | 84 call assert_equal(test_true, g:MY_GLOBAL_TRUE) |
219 set viminfo='100,<600,s10,h,!,nviminfo | 228 set viminfo='100,<600,s10,h,!,nviminfo |
220 for i in range(500) | 229 for i in range(500) |
221 call add(l, 'something') | 230 call add(l, 'something') |
222 endfor | 231 endfor |
223 call setreg('d', l, 'l') | 232 call setreg('d', l, 'l') |
233 call setreg('e', "abc\<C-V>xyz") | |
224 wviminfo Xviminfo | 234 wviminfo Xviminfo |
225 | 235 |
226 call test_settime(10) | 236 call test_settime(10) |
227 call setreg('a', '', 'b10') | 237 call setreg('a', '', 'b10') |
228 call test_settime(15) | 238 call test_settime(15) |
229 call setreg('b', 'drop') | 239 call setreg('b', 'drop') |
230 call test_settime(50) | 240 call test_settime(50) |
231 call setreg('c', 'keep', 'l') | 241 call setreg('c', 'keep', 'l') |
232 call test_settime(30) | 242 call test_settime(30) |
233 call setreg('d', 'drop', 'l') | 243 call setreg('d', 'drop', 'l') |
244 call setreg('e', 'drop') | |
234 rviminfo Xviminfo | 245 rviminfo Xviminfo |
235 | 246 |
236 call assert_equal("", getreg('a')) | 247 call assert_equal("", getreg('a')) |
237 call assert_equal("\<C-V>10", getregtype('a')) | 248 call assert_equal("\<C-V>10", getregtype('a')) |
238 call assert_equal("twenty\nagain\n", getreg('b')) | 249 call assert_equal("twenty\nagain\n", getreg('b')) |
239 call assert_equal("V", getregtype('b')) | 250 call assert_equal("V", getregtype('b')) |
240 call assert_equal("keep\n", getreg('c')) | 251 call assert_equal("keep\n", getreg('c')) |
241 call assert_equal("V", getregtype('c')) | 252 call assert_equal("V", getregtype('c')) |
242 call assert_equal(l, getreg('d', 1, 1)) | 253 call assert_equal(l, getreg('d', 1, 1)) |
243 call assert_equal("V", getregtype('d')) | 254 call assert_equal("V", getregtype('d')) |
255 call assert_equal("abc\<C-V>xyz", getreg('e')) | |
244 | 256 |
245 " Length around 440 switches to line continuation. | 257 " Length around 440 switches to line continuation. |
246 let len = 434 | 258 let len = 434 |
247 while len < 445 | 259 while len < 445 |
248 let s = repeat('a', len) | 260 let s = repeat('a', len) |
512 call delete('Xviminfo') | 524 call delete('Xviminfo') |
513 call assert_equal(1, line("'B")) | 525 call assert_equal(1, line("'B")) |
514 delmark B | 526 delmark B |
515 endfunc | 527 endfunc |
516 | 528 |
529 " Test for saving and restoring file marks in unloaded buffers | |
530 func 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 | |
549 endfunc | |
550 | |
517 func Test_viminfo_oldfiles() | 551 func Test_viminfo_oldfiles() |
518 let v:oldfiles = [] | 552 let v:oldfiles = [] |
519 let lines = [ | 553 let lines = [ |
520 \ '# comment line', | 554 \ '# comment line', |
521 \ '*encoding=utf-8', | 555 \ '*encoding=utf-8', |
556 \ '', | |
557 \ ':h viminfo', | |
558 \ '?/session', | |
559 \ '=myvar', | |
560 \ '@123', | |
561 \ '', | |
562 \ "'E 2 0 /tmp/nothing", | |
522 \ '', | 563 \ '', |
523 \ "> /tmp/file_one.txt", | 564 \ "> /tmp/file_one.txt", |
524 \ "\t\"\t11\t0", | 565 \ "\t\"\t11\t0", |
525 \ "", | 566 \ "", |
526 \ "> /tmp/file_two.txt", | 567 \ "> /tmp/file_two.txt", |
529 \ "> /tmp/another.txt", | 570 \ "> /tmp/another.txt", |
530 \ "\t\"\t11\t0", | 571 \ "\t\"\t11\t0", |
531 \ "", | 572 \ "", |
532 \ ] | 573 \ ] |
533 call writefile(lines, 'Xviminfo') | 574 call writefile(lines, 'Xviminfo') |
575 delmark E | |
534 rviminfo! Xviminfo | 576 rviminfo! Xviminfo |
535 call delete('Xviminfo') | 577 call delete('Xviminfo') |
536 | 578 |
579 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")) | |
537 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/'})) | 584 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/'})) |
538 call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('filter file_ 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/'})) |
539 call assert_equal(['3: /tmp/another.txt'], filter(split(execute('filter /another/ 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/'})) |
540 | 587 |
541 new | 588 new |
542 call feedkeys("3\<CR>", 't') | 589 call feedkeys("3\<CR>", 't') |
543 browse oldfiles | 590 browse oldfiles |
544 call assert_equal("/tmp/another.txt", expand("%")) | 591 call assert_equal("/tmp/another.txt", expand("%")) |
545 bwipe | 592 bwipe |
546 endfunc | 593 delmark E |
594 endfunc | |
595 | |
596 " Test for storing and restoring buffer list in 'viminfo' | |
597 func 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-=% | |
624 endfunc | |
625 | |
626 " Test for errors in a viminfo file | |
627 func 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') | |
654 endfunc | |
655 | |
656 " Test for saving and restoring last substitute string in viminfo | |
657 func 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') | |
669 endfunc | |
670 | |
671 " Test saving and restoring the register values using the older method | |
672 func 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 @" = '' | |
703 endfunc | |
704 | |
705 " Test for saving and restoring large number of lines in a register | |
706 func 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 | |
719 endfunc | |
720 | |
721 " Test for setting 'viminfofile' to NONE | |
722 func 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') | |
729 endfunc | |
730 | |
731 " Test for an unwritable 'viminfo' file | |
732 func 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') | |
740 endfunc |