robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local command =n . command 8local exec_lua =n . exec_lua 9local poke_eventloop =n . poke_eventloop 10local api =n . api 11local eval =n . eval 12 13local eq =t . eq 14 15describe ( 'TabMoved' , function () 16before_each ( function () 17clear () 18end ) 19 20it ( 'sets <amatch>, event-data' , function () 21-- start on tabpage 1, create 2 more so tabpage 3 is "current tab" 22command ( 'tabnew' ) 23command ( 'tabnew' ) 24 25exec_lua ( [[ 26_G.tm_events = {} 27vim.api.nvim_create_autocmd('TabMoved', { 28callback = function(ev) 29table.insert(_G.tm_events, ev) 30end, 31}) 32]] ) 33 34command ( 'tabmove 0' ) 35poke_eventloop () 36local events =exec_lua ( 'return _G.tm_events' ) 37eq ( '3' , events [ 1 ]. match ) 38eq ( { tabnr_new =1 , tabnr_old =3 } , events [ 1 ]. data ) 39 40command ( 'tabnext 2' ) 41command ( 'tabmove $' ) 42poke_eventloop () 43events =exec_lua ( 'return _G.tm_events' ) 44eq ( '2' , events [ 2 ]. match ) 45eq ( { tabnr_new =3 , tabnr_old =2 } , events [ 2 ]. data ) 46 47command ( 'tabmove -1' ) 48poke_eventloop () 49events =exec_lua ( 'return _G.tm_events' ) 50eq ( '3' , events [ 3 ]. match ) 51eq ( { tabnr_new =2 , tabnr_old =3 } , events [ 3 ]. data ) 52end ) 53 54it ( 'does not trigger when a tab is moved to same position' , function () 55command ( 'tabnew' ) 56command ( 'tabnew' ) 57command ( 'let g:test = 0' ) 58command ( 'au! TabMoved * let g:test += 1' ) 59 60command ( 'tabmove $' ) -- already at last position, no-op 61poke_eventloop () 62eq ( 0 , eval ( 'g:test' )) 63end ) 64 65it ( 'is not triggered when creating or closing tabs' , function () 66command ( 'let g:test = 0' ) 67command ( 'au! TabMoved * let g:test += 1' ) 68command ( 'file Xtestfile1' ) 69command ( '0tabedit Xtestfile2' ) 70command ( 'tabclose' ) 71poke_eventloop () 72eq ( 0 , eval ( 'g:test' )) 73end ) 74 75it ( 'handles mouse interactions on the tabline' , function () 76local function setup () 77Screen . new ( 25 , 5 ) 78command ( 'set mouse=a' ) 79command ( 'tabnew' ) 80command ( 'tabnew' ) 81exec_lua ( [[ 82_G.tm_events = {} 83vim.api.nvim_create_autocmd('TabMoved', { 84callback = function(ev) 85table.insert(_G.tm_events, ev) 86end, 87}) 88]] ) 89end 90 91-- clicking tab 2 shouldn't trigger the event. 92setup () 93api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 5 ) 94api . nvim_input_mouse ( 'left' , 'release' , '' , 0 , 0 , 5 ) 95poke_eventloop () 96eq ( {} , exec_lua ( 'return _G.tm_events' )) 97clear () 98 99-- dragging tab 1 to the right should trigger the event. 100setup () 101api . nvim_input_mouse ( 'left' , 'press' , '' , 0 , 0 , 4 ) 102poke_eventloop () 103eq ( 0 , # exec_lua ( 'return _G.tm_events' )) 104api . nvim_input_mouse ( 'left' , 'drag' , '' , 0 , 0 , 14 ) 105poke_eventloop () 106local events =exec_lua ( 'return _G.tm_events' ) 107eq ( 1 , # events ) 108eq ( { tabnr_new =2 , tabnr_old =1 } , events [ 1 ]. data ) 109end ) 110end )