robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- shada buffer list saving/reading support 2local t =require ( 'test.testutil' ) 3local n =require ( 'test.functional.testnvim' )() 4local t_shada =require ( 'test.functional.shada.testutil' ) 5 6local describe , it , after_each =t . describe , t . it , t . after_each 7local nvim_command , fn , eq , api =n . command , n . fn , t . eq , n . api 8local expect_exit =n . expect_exit 9 10local reset , clear =t_shada . reset , t_shada . clear 11 12describe ( 'shada support code' , function () 13local testfilename ='Xtestfile-functional-shada-buffers' 14local testfilename_2 ='Xtestfile-functional-shada-buffers-2' 15after_each ( clear ) 16 17it ( 'is able to dump and restore buffer list' , function () 18reset ( 'set shada+=%' ) 19nvim_command ( 'edit ' .. testfilename ) 20nvim_command ( 'edit ' .. testfilename_2 ) 21expect_exit ( nvim_command , 'qall' ) 22reset ( 'set shada+=%' ) 23eq ( 3 , fn . bufnr ( '$' )) 24eq ( '' , fn . bufname ( 1 )) 25eq ( testfilename , fn . bufname ( 2 )) 26eq ( testfilename_2 , fn . bufname ( 3 )) 27end ) 28 29it ( 'does not restore buffer list without % in &shada' , function () 30reset ( 'set shada+=%' ) 31nvim_command ( 'edit ' .. testfilename ) 32nvim_command ( 'edit ' .. testfilename_2 ) 33expect_exit ( nvim_command , 'qall' ) 34reset () 35eq ( 1 , fn . bufnr ( '$' )) 36eq ( '' , fn . bufname ( 1 )) 37end ) 38 39it ( 'does not dump buffer list without % in &shada' , function () 40reset () 41nvim_command ( 'edit ' .. testfilename ) 42nvim_command ( 'edit ' .. testfilename_2 ) 43expect_exit ( nvim_command , 'qall' ) 44reset ( 'set shada+=%' ) 45eq ( 1 , fn . bufnr ( '$' )) 46eq ( '' , fn . bufname ( 1 )) 47end ) 48 49it ( 'does not dump unlisted buffer' , function () 50reset ( 'set shada+=%' ) 51nvim_command ( 'edit ' .. testfilename ) 52nvim_command ( 'edit ' .. testfilename_2 ) 53api . nvim_set_option_value ( 'buflisted' , false , {} ) 54expect_exit ( nvim_command , 'qall' ) 55reset ( 'set shada+=%' ) 56eq ( 2 , fn . bufnr ( '$' )) 57eq ( '' , fn . bufname ( 1 )) 58eq ( testfilename , fn . bufname ( 2 )) 59end ) 60 61it ( 'does not dump quickfix buffer' , function () 62reset ( 'set shada+=%' ) 63nvim_command ( 'edit ' .. testfilename ) 64nvim_command ( 'edit ' .. testfilename_2 ) 65api . nvim_set_option_value ( 'buftype' , 'quickfix' , {} ) 66expect_exit ( nvim_command , 'qall' ) 67reset ( 'set shada+=%' ) 68eq ( 2 , fn . bufnr ( '$' )) 69eq ( '' , fn . bufname ( 1 )) 70eq ( testfilename , fn . bufname ( 2 )) 71end ) 72 73it ( 'does not dump unnamed buffers' , function () 74reset ( 'set shada+=% hidden' ) 75api . nvim_buf_set_lines ( 0 , 0 , 1 , true , { 'foo' } ) 76nvim_command ( 'enew' ) 77api . nvim_buf_set_lines ( 0 , 0 , 1 , true , { 'bar' } ) 78eq ( 2 , fn . bufnr ( '$' )) 79expect_exit ( nvim_command , 'qall!' ) 80reset ( 'set shada+=% hidden' ) 81eq ( 1 , fn . bufnr ( '$' )) 82eq ( '' , fn . bufname ( 1 )) 83end ) 84 85it ( 'restores 1 buffer with %1 in &shada, #5759' , function () 86reset ( 'set shada+=%1' ) 87nvim_command ( 'edit ' .. testfilename ) 88nvim_command ( 'edit ' .. testfilename_2 ) 89expect_exit ( nvim_command , 'qall' ) 90reset ( 'set shada+=%1' ) 91eq ( 2 , fn . bufnr ( '$' )) 92eq ( '' , fn . bufname ( 1 )) 93eq ( testfilename , fn . bufname ( 2 )) 94end ) 95 96it ( "does not add 'nobuflisted' buffers to v:oldfiles" , function () 97reset ( "set shada='100" ) 98nvim_command ( 'edit ' .. testfilename ) 99nvim_command ( 'setlocal nobuflisted' ) 100nvim_command ( 'edit ' .. testfilename_2 ) 101nvim_command ( 'setlocal buflisted' ) 102expect_exit ( nvim_command , 'qall' ) 103reset ( "set shada='100" ) 104local oldfiles =api . nvim_get_vvar ( 'oldfiles' ) 105eq ( 1 , # oldfiles ) 106t . matches ( vim . pesc ( testfilename_2 ), oldfiles [ 1 ]) 107end ) 108 109it ( "saves bdelete'd buffer to v:oldfiles #39010" , function () 110reset ( "set shada='100" ) 111nvim_command ( 'edit ' .. testfilename ) 112nvim_command ( 'bdelete' ) 113nvim_command ( 'edit ' .. testfilename_2 ) 114expect_exit ( nvim_command , 'qall' ) 115reset ( "set shada='100" ) 116local oldfiles =api . nvim_get_vvar ( 'oldfiles' ) 117eq ( 2 , # oldfiles ) 118end ) 119 120it ( "does not dump bdelete'd buffer to buffer list" , function () 121reset ( 'set shada+=%' ) 122nvim_command ( 'edit ' .. testfilename ) 123nvim_command ( 'edit ' .. testfilename_2 ) 124nvim_command ( 'bdelete ' .. testfilename ) 125expect_exit ( nvim_command , 'qall' ) 126reset ( 'set shada+=%' ) 127eq ( 2 , fn . bufnr ( '$' )) 128eq ( '' , fn . bufname ( 1 )) 129eq ( testfilename_2 , fn . bufname ( 2 )) 130end ) 131end )