robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
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 =t . eq 6local eval =n . eval 7local clear =n . clear 8local command =n . command 9local source =n . source 10local request =n . request 11 12describe ( 'autocmd' , function () 13describe ( 'OptionSet modified' , function () 14before_each ( clear ) 15 16it ( 'is triggered when modified and un-modified' , function () 17source ( [[ 18let g:modified = 0 19autocmd OptionSet modified let g:modified += 1 20]] ) 21request ( 'nvim_command' , [[normal! aa\<Esc>]] ) 22eq ( 1 , eval ( 'g:modified' )) 23request ( 'nvim_command' , [[normal! u]] ) 24eq ( 2 , eval ( 'g:modified' )) 25end ) 26 27it ( 'triggers when writes non-current buffer #32817' , function () 28source ( [[ 29let g:modified = 0 30let g:second_trigger_buf = 0 31autocmd OptionSet modified let g:modified += 1 | if g:modified == 2 | let g:second_trigger_buf = bufnr() | endif 32]] ) 33request ( 'nvim_command' , [[edit test_a | badd test_b]] ) 34request ( 'nvim_command' , [[normal! aa\<Esc>]] ) 35request ( 'nvim_command' , [[let g:buf_a = bufnr()]] ) 36request ( 'nvim_command' , [[bn]] ) 37request ( 'nvim_command' , [[wa]] ) 38os . remove ( 'test_a' ) 39eq ( { 2 , true } , { eval ( 'g:modified' ), eval ( 'g:buf_a' ) == eval ( 'g:second_trigger_buf' ) } ) 40end ) 41 42it ( 'OptionSet triggers correctly when modified changes' , function () 43command ( [[ 44autocmd OptionSet modified call add(g:messages, string(!!v:option_old) . ' -> ' . string(!!v:option_new) . ' - actual: ' . &modified) 45]] ) 46command ( 'let g:messages = []' ) 47local fname =t . tmpname () 48command ( 'new ' .. fname ) 49command ( "call setline(1, 'hi')" ) 50command ( 'write' ) 51command ( 'set modified' ) 52eq ( { 53'0 -> 1 - actual: 1' , 54'1 -> 0 - actual: 0' , 55'0 -> 1 - actual: 1' , 56} , eval ( 'g:messages' )) 57os . remove ( fname ) 58end ) 59end ) 60end )