0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.1.0313: information about a swap file is unavailable

Problem:    Information about a swap file is unavailable.
Solution:   Add swapinfo(). (Enzo Ferber)
This commit is contained in:
Bram Moolenaar
2018-08-21 20:28:54 +02:00
parent 8e82c057ff
commit 00f123a565
6 changed files with 110 additions and 1 deletions

View File

@@ -97,3 +97,37 @@ func Test_missing_dir()
set directory&
call delete('Xswapdir', 'rf')
endfunc
func Test_swapinfo()
new Xswapinfo
call setline(1, ['one', 'two', 'three'])
w
let fname = trim(execute('swapname'))
call assert_match('Xswapinfo', fname)
let info = swapinfo(fname)
call assert_match('8\.', info.version)
call assert_match('\w', info.user)
call assert_equal(hostname(), info.host)
call assert_match('Xswapinfo', info.fname)
call assert_equal(getpid(), info.pid)
call assert_match('^\d*$', info.mtime)
if has_key(info, 'inode')
call assert_match('\d', info.inode)
endif
bwipe!
call delete(fname)
call delete('Xswapinfo')
let info = swapinfo('doesnotexist')
call assert_equal('Cannot open file', info.error)
call writefile(['burp'], 'Xnotaswapfile')
let info = swapinfo('Xnotaswapfile')
call assert_equal('Cannot read file', info.error)
call delete('Xnotaswapfile')
call writefile([repeat('x', 10000)], 'Xnotaswapfile')
let info = swapinfo('Xnotaswapfile')
call assert_equal('magic number mismatch', info.error)
call delete('Xnotaswapfile')
endfunc