" Test for reading and writing .viminfo
source check.vim
source term_util.vim
source shared.vim
func Test_viminfo_read_and_write()
" First clear 'history', so that "hislen" is zero. Then set it again,
" simulating Vim starting up.
set history=0
wviminfo Xviminfo
set history=1000
call histdel(':')
let @/=''
let lines = [
\ '# comment line',
\ '*encoding=utf-8',
\ '~MSle0~/asdf',
\ '|copied as-is',
\ '|and one more',
\ ]
call writefile(lines, 'Xviminfo', 'D')
rviminfo Xviminfo
call assert_equal('asdf', @/)
wviminfo Xviminfo
let lines = readfile('Xviminfo')
let done = 0
for line in lines
if line[0] == '|' && line !~ '^|[234],' && line !~ '^|<'
if done == 0
call assert_equal('|1,4', line)
elseif done == 1
call assert_equal('|copied as-is', line)
elseif done == 2
call assert_equal('|and one more', line)
endif
let done += 1
endif
endfor
call assert_equal(3, done)
endfunc
func Test_global_vars()
let g:MY_GLOBAL_STRING = "Vim Editor"
let g:MY_GLOBAL_NUM = 345
let g:MY_GLOBAL_FLOAT = 3.14
let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000}
let g:MY_GLOBAL_DICT = test_dict
" store a really long list, so line wrapping will occur in viminfo file
let test_list = range(1,100)
let g:MY_GLOBAL_LIST = test_list
let test_blob = 0z00112233445566778899aabbccddeeff
let g:MY_GLOBAL_BLOB = test_blob
let test_false = v:false
let g:MY_GLOBAL_FALSE = test_false
let test_true = v:true
let g:MY_GLOBAL_TRUE = test_true
let test_null = v:null
let g:MY_GLOBAL_NULL = test_null
let test_none = v:none
let g:MY_GLOBAL_NONE = test_none
let g:MY_GLOBAL_FUNCREF = function('min')
set viminfo='100,<50,s10,h,!,nviminfo
wv! Xviminfo
unlet g:MY_GLOBAL_STRING
unlet g:MY_GLOBAL_NUM
unlet g:MY_GLOBAL_FLOAT
unlet g:MY_GLOBAL_DICT
unlet g:MY_GLOBAL_LIST
unlet g:MY_GLOBAL_BLOB
unlet g:MY_GLOBAL_FALSE
unlet g:MY_GLOBAL_TRUE
unlet g:MY_GLOBAL_NULL
unlet g:MY_GLOBAL_NONE
unlet g:MY_GLOBAL_FUNCREF
rv! Xviminfo
call assert_equal("Vim Editor", g:MY_GLOBAL_STRING)
call assert_equal(345, g:MY_GLOBAL_NUM)
call assert_equal(3.14, g:MY_GLOBAL_FLOAT)
call assert_equal(test_dict, g:MY_GLOBAL_DICT)
call assert_equal(test_list, g:MY_GLOBAL_LIST)
call assert_equal(test_blob, g:MY_GLOBAL_BLOB)
call assert_equal(test_false, g:MY_GLOBAL_FALSE)
call assert_equal(test_true, g:MY_GLOBAL_TRUE)
call assert_equal(test_null, g:MY_GLOBAL_NULL)
call assert_equal(test_none, g:MY_GLOBAL_NONE)
call assert_false(exists("g:MY_GLOBAL_FUNCREF"))
" When reading global variables from viminfo, if a variable cannot be
" modified, then the value should not be changed.
unlet g:MY_GLOBAL_STRING
unlet g:MY_GLOBAL_NUM
unlet g:MY_GLOBAL_FLOAT
unlet g:MY_GLOBAL_DICT
unlet g:MY_GLOBAL_LIST
unlet g:MY_GLOBAL_BLOB
const g:MY_GLOBAL_STRING = 'New Value'
const g:MY_GLOBAL_NUM = 987
const g:MY_GLOBAL_FLOAT = 1.16
const g:MY_GLOBAL_DICT = {'editor': 'vim'}
const g:MY_GLOBAL_LIST = [5, 7, 13]
const g:MY_GLOBAL_BLOB = 0zDEADBEEF
call assert_fails('rv! Xviminfo', 'E741:')
call assert_equal('New Value'