robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local eq , matches , pcall_err =t . eq , t . matches , t . pcall_err 6local clear , command , api , fn =n . clear , n . command , n . api , n . fn 7 8describe ( ':retab' , function () 9before_each ( clear ) 10 11it ( 'uses the new tab width for C indentation' , function () 12command ( 'setlocal tabstop=8 shiftwidth=0 expandtab' ) 13api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'int main() {' , 'return 0;' , '}' } ) 14command ( '1retab 4' ) 15command ( 'normal! gg=G' ) 16eq ( 4 , fn . indent ( 2 )) 17end ) 18 19for _ , option in ipairs ( { 'tabstop' , 'vartabstop' } ) do 20it ( 'updates indent folds after changing ' .. option , function () 21command ( 'setlocal shiftwidth=4 foldmethod=indent ' .. option .. '=8' ) 22api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'top' , '\tfirst' , '\tsecond' , 'end' } ) 23eq ( 2 , fn . foldlevel ( 2 )) 24 25-- Leave the tabs on lines 2-3 untouched; their width changes with the option. 26command ( '1retab 4' ) 27eq ( 1 , fn . foldlevel ( 2 )) 28end ) 29end 30 31it ( 'keeps list enabled when the argument is invalid' , function () 32command ( 'setlocal list' ) 33matches ( 'E487:' , pcall_err ( command , 'retab -1' )) 34eq ( true , api . nvim_get_option_value ( 'list' , { win =0 } )) 35end ) 36 37it ( 'keeps the cursor position set by an OptionSet callback in another buffer' , function () 38local other =api . nvim_create_buf ( true , false ) 39api . nvim_buf_set_lines ( other , 0 , - 1 , true , { 'some text' } ) 40command ( 'autocmd OptionSet tabstop buffer ' .. other .. ' | call cursor(1, 6)' ) 41command ( 'retab 4' ) 42eq ( other , api . nvim_get_current_buf ()) 43eq ( { 1 , 5 } , api . nvim_win_get_cursor ( 0 )) 44end ) 45end )