wviminfo_spec.lua (1465B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local clear = n.clear 5 local command, eq, neq, write_file = n.command, t.eq, t.neq, t.write_file 6 local read_file = t.read_file 7 local is_os = t.is_os 8 9 describe(':wshada', function() 10 local shada_file = 'wshada_test' 11 12 before_each(function() 13 clear { 14 args = { 15 '-i', 16 is_os('win') and 'nul' or '/dev/null', 17 -- Need 'swapfile' for these tests. 18 '--cmd', 19 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler', 20 }, 21 args_rm = { '-n', '-i', '--cmd' }, 22 } 23 end) 24 after_each(function() 25 os.remove(shada_file) 26 end) 27 28 it('creates a shada file', function() 29 -- file should _not_ exist 30 eq(nil, vim.uv.fs_stat(shada_file)) 31 command('wsh! ' .. shada_file) 32 -- file _should_ exist 33 neq(nil, vim.uv.fs_stat(shada_file)) 34 end) 35 36 it('overwrites existing files', function() 37 local text = 'wshada test' 38 39 -- Create a dummy file 40 write_file(shada_file, text) 41 42 -- sanity check 43 eq(text, read_file(shada_file)) 44 neq(nil, vim.uv.fs_stat(shada_file)) 45 46 command('wsh! ' .. shada_file) 47 48 -- File should have been overwritten with a shada file. 49 local fp = io.open(shada_file, 'r') 50 local char1 = fp:read(1) 51 fp:close() 52 -- ShaDa file starts with a “header” entry 53 assert(char1:byte() == 0x01, shada_file .. ' should be a shada file') 54 end) 55 end)