Mercurial > vim
comparison src/testdir/test_viminfo.vim @ 9240:636cfa97200e v7.4.1903
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jun 6 21:07:52 2016 +0200
patch 7.4.1903
Problem: When writing viminfo merging current history with history in
viminfo may drop recent history entries.
Solution: Add new format for viminfo lines, use it for history entries. Use
a timestamp for ordering the entries. Add test_settime().
Add the viminfo version. Does not do merging on timestamp yet.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 06 Jun 2016 21:15:07 +0200 |
parents | fb764adba294 |
children | 26c7bf23ec1d |
comparison
equal
deleted
inserted
replaced
9239:a744b63c4ed0 | 9240:636cfa97200e |
---|---|
1 " Test for reading and writing .viminfo | 1 " Test for reading and writing .viminfo |
2 | 2 |
3 function Test_read_and_write() | 3 function Test_read_and_write() |
4 call histdel(':') | |
4 let lines = [ | 5 let lines = [ |
5 \ '# comment line', | 6 \ '# comment line', |
6 \ '*encoding=utf-8', | 7 \ '*encoding=utf-8', |
7 \ '~MSle0~/asdf', | 8 \ '~MSle0~/asdf', |
8 \ '|copied as-is', | 9 \ '|copied as-is', |
16 let lines = readfile('Xviminfo') | 17 let lines = readfile('Xviminfo') |
17 let done = 0 | 18 let done = 0 |
18 for line in lines | 19 for line in lines |
19 if line[0] == '|' | 20 if line[0] == '|' |
20 if done == 0 | 21 if done == 0 |
22 call assert_equal('|1,2', line) | |
23 elseif done == 1 | |
21 call assert_equal('|copied as-is', line) | 24 call assert_equal('|copied as-is', line) |
22 elseif done == 1 | 25 elseif done == 2 |
23 call assert_equal('|and one more', line) | 26 call assert_equal('|and one more', line) |
24 endif | 27 endif |
25 let done += 1 | 28 let done += 1 |
26 endif | 29 endif |
27 endfor | 30 endfor |
28 call assert_equal(2, done) | 31 call assert_equal(3, done) |
29 | 32 |
30 call delete('Xviminfo') | 33 call delete('Xviminfo') |
31 endfunc | 34 endfunc |
32 | 35 |
33 func Test_global_vars() | 36 func Test_global_vars() |
46 call assert_equal(test_list, g:MY_GLOBAL_LIST) | 49 call assert_equal(test_list, g:MY_GLOBAL_LIST) |
47 | 50 |
48 call delete('Xviminfo') | 51 call delete('Xviminfo') |
49 set viminfo-=! | 52 set viminfo-=! |
50 endfunc | 53 endfunc |
54 | |
55 func Test_cmdline_history() | |
56 call histdel(':') | |
57 call test_settime(11) | |
58 call histadd(':', "echo 'one'") | |
59 call test_settime(12) | |
60 " split into two lines | |
61 let long800 = repeat(" 'eight'", 100) | |
62 call histadd(':', "echo " . long800) | |
63 call test_settime(13) | |
64 " split into three lines | |
65 let long1400 = repeat(" 'fourteeeeen'", 100) | |
66 call histadd(':', "echo " . long1400) | |
67 wviminfo Xviminfo | |
68 let lines = readfile('Xviminfo') | |
69 let done_colon = 0 | |
70 let done_bar = 0 | |
71 let lnum = 0 | |
72 while lnum < len(lines) | |
73 let line = lines[lnum] | let lnum += 1 | |
74 if line[0] == ':' | |
75 if done_colon == 0 | |
76 call assert_equal(":\x161408", line) | |
77 let line = lines[lnum] | let lnum += 1 | |
78 call assert_equal('<echo ' . long1400, line) | |
79 elseif done_colon == 1 | |
80 call assert_equal(":\x16808", line) | |
81 let line = lines[lnum] | let lnum += 1 | |
82 call assert_equal("<echo " . long800, line) | |
83 elseif done_colon == 2 | |
84 call assert_equal(":echo 'one'", line) | |
85 endif | |
86 let done_colon += 1 | |
87 elseif line[0:4] == '|2,0,' | |
88 if done_bar == 0 | |
89 call assert_equal("|2,0,13,,>1407", line) | |
90 let line = lines[lnum] | let lnum += 1 | |
91 call assert_equal('|<"echo ' . long1400[0:484], line) | |
92 let line = lines[lnum] | let lnum += 1 | |
93 call assert_equal('|<' . long1400[485:974], line) | |
94 let line = lines[lnum] | let lnum += 1 | |
95 call assert_equal('|<' . long1400[975:] . '"', line) | |
96 elseif done_bar == 1 | |
97 call assert_equal('|2,0,12,,>807', line) | |
98 let line = lines[lnum] | let lnum += 1 | |
99 call assert_equal('|<"echo ' . long800[0:484], line) | |
100 let line = lines[lnum] | let lnum += 1 | |
101 call assert_equal('|<' . long800[485:] . '"', line) | |
102 elseif done_bar == 2 | |
103 call assert_equal("|2,0,11,,\"echo 'one'\"", line) | |
104 endif | |
105 let done_bar += 1 | |
106 endif | |
107 endwhile | |
108 call assert_equal(3, done_colon) | |
109 call assert_equal(3, done_bar) | |
110 | |
111 call histdel(':') | |
112 rviminfo Xviminfo | |
113 call assert_equal("echo " . long1400, histget(':', -1)) | |
114 call assert_equal("echo " . long800, histget(':', -2)) | |
115 call assert_equal("echo 'one'", histget(':', -3)) | |
116 | |
117 call delete('Xviminfo') | |
118 endfunc |