1-- shada buffer list saving/reading support 2local helpers = require('test.functional.helpers')(after_each) 3local nvim_command, funcs, eq, curbufmeths = 4 helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths 5 6local shada_helpers = require('test.functional.shada.helpers') 7local reset, clear = shada_helpers.reset, shada_helpers.clear 8 9describe('shada support code', function() 10 local testfilename = 'Xtestfile-functional-shada-buffers' 11 local testfilename_2 = 'Xtestfile-functional-shada-buffers-2' 12 after_each(clear) 13 14 it('is able to dump and restore buffer list', function() 15 reset('set shada+=%') 16 nvim_command('edit ' .. testfilename) 17 nvim_command('edit ' .. testfilename_2) 18 nvim_command('qall') 19 reset('set shada+=%') 20 eq(3, funcs.bufnr('$')) 21 eq('', funcs.bufname(1)) 22 eq(testfilename, funcs.bufname(2)) 23 eq(testfilename_2, funcs.bufname(3)) 24 end) 25 26 it('does not restore buffer list without % in &shada', function() 27 reset('set shada+=%') 28 nvim_command('edit ' .. testfilename) 29 nvim_command('edit ' .. testfilename_2) 30 nvim_command('qall') 31 reset() 32 eq(1, funcs.bufnr('$')) 33 eq('', funcs.bufname(1)) 34 end) 35 36 it('does not dump buffer list without % in &shada', function() 37 reset() 38 nvim_command('edit ' .. testfilename) 39 nvim_command('edit ' .. testfilename_2) 40 nvim_command('qall') 41 reset('set shada+=%') 42 eq(1, funcs.bufnr('$')) 43 eq('', funcs.bufname(1)) 44 end) 45 46 it('does not dump unlisted buffer', function() 47 reset('set shada+=%') 48 nvim_command('edit ' .. testfilename) 49 nvim_command('edit ' .. testfilename_2) 50 curbufmeths.set_option('buflisted', false) 51 nvim_command('qall') 52 reset('set shada+=%') 53 eq(2, funcs.bufnr('$')) 54 eq('', funcs.bufname(1)) 55 eq(testfilename, funcs.bufname(2)) 56 end) 57 58 it('does not dump quickfix buffer', function() 59 reset('set shada+=%') 60 nvim_command('edit ' .. testfilename) 61 nvim_command('edit ' .. testfilename_2) 62 curbufmeths.set_option('buftype', 'quickfix') 63 nvim_command('qall') 64 reset('set shada+=%') 65 eq(2, funcs.bufnr('$')) 66 eq('', funcs.bufname(1)) 67 eq(testfilename, funcs.bufname(2)) 68 end) 69 70 it('does not dump unnamed buffers', function() 71 reset('set shada+=% hidden') 72 curbufmeths.set_lines(0, 1, true, {'foo'}) 73 nvim_command('enew') 74 curbufmeths.set_lines(0, 1, true, {'bar'}) 75 eq(2, funcs.bufnr('$')) 76 nvim_command('qall!') 77 reset('set shada+=% hidden') 78 eq(1, funcs.bufnr('$')) 79 eq('', funcs.bufname(1)) 80 end) 81 82 it('restores 1 buffer with %1 in &shada, #5759', function() 83 reset('set shada+=%1') 84 nvim_command('edit ' .. testfilename) 85 nvim_command('edit ' .. testfilename_2) 86 nvim_command('qall') 87 reset('set shada+=%1') 88 eq(2, funcs.bufnr('$')) 89 eq('', funcs.bufname(1)) 90 eq(testfilename, funcs.bufname(2)) 91 end) 92end) 93