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 api =n . api 8local eq =t . eq 9local poke_eventloop =n . poke_eventloop 10local assert_alive =n . assert_alive 11 12local CSI ='\027[' 13 14describe ( ':terminal synchronized output (mode 2026)' , function () 15local screen , chan , buf 16 17before_each ( function () 18clear () 19screen =Screen . new ( 50 , 7 ) 20buf =api . nvim_create_buf ( true , true ) 21chan =api . nvim_open_term ( buf , {} ) 22api . nvim_win_set_buf ( 0 , buf ) 23end ) 24 25it ( 'renders content sent inside a synchronized update' , function () 26api . nvim_chan_send ( chan , CSI .. '?2026h' ) 27api . nvim_chan_send ( chan , 'synced line 1\r\n' ) 28api . nvim_chan_send ( chan , 'synced line 2\r\n' ) 29api . nvim_chan_send ( chan , CSI .. '?2026l' ) 30screen : expect ( [[ 31^synced line 1 | 32synced line 2 | 33|*4 34| 35]] ) 36end ) 37 38it ( 'renders all lines from a synchronized update' , function () 39api . nvim_chan_send ( chan , CSI .. '?2026h' ) 40for i =1 , 5 do 41api . nvim_chan_send ( chan , 'line ' .. i .. '\r\n' ) 42end 43api . nvim_chan_send ( chan , CSI .. '?2026l' ) 44screen : expect ( [[ 45^line 1 | 46line 2 | 47line 3 | 48line 4 | 49line 5 | 50| 51| 52]] ) 53-- Buffer lines should also match. 54local lines =api . nvim_buf_get_lines ( buf , 0 , - 1 , true ) 55eq ( 'line 1' , lines [ 1 ]) 56eq ( 'line 2' , lines [ 2 ]) 57eq ( 'line 5' , lines [ 5 ]) 58end ) 59 60it ( 'handles multiple synchronized update cycles' , function () 61-- First cycle. 62api . nvim_chan_send ( chan , CSI .. '?2026h' ) 63api . nvim_chan_send ( chan , 'cycle 1\r\n' ) 64api . nvim_chan_send ( chan , CSI .. '?2026l' ) 65screen : expect ( [[ 66^cycle 1 | 67|*5 68| 69]] ) 70 71-- Second cycle. 72api . nvim_chan_send ( chan , CSI .. '?2026h' ) 73api . nvim_chan_send ( chan , 'cycle 2\r\n' ) 74api . nvim_chan_send ( chan , CSI .. '?2026l' ) 75screen : expect ( [[ 76^cycle 1 | 77cycle 2 | 78|*4 79| 80]] ) 81end ) 82 83it ( 'works with content before and after sync' , function () 84-- Unsynchronized content. 85api . nvim_chan_send ( chan , 'before\r\n' ) 86poke_eventloop () 87screen : expect ( [[ 88^before | 89|*5 90| 91]] ) 92 93-- Synchronized content. 94api . nvim_chan_send ( chan , CSI .. '?2026h' ) 95api . nvim_chan_send ( chan , 'during\r\n' ) 96api . nvim_chan_send ( chan , CSI .. '?2026l' ) 97screen : expect ( [[ 98^before | 99during | 100|*4 101| 102]] ) 103 104-- More unsynchronized content. 105api . nvim_chan_send ( chan , 'after\r\n' ) 106screen : expect ( [[ 107^before | 108during | 109after | 110|*3 111| 112]] ) 113end ) 114 115it ( 'does not crash when mode 2026 is set and queried' , function () 116api . nvim_chan_send ( chan , CSI .. '?2026h' ) 117assert_alive () 118api . nvim_chan_send ( chan , CSI .. '?2026l' ) 119assert_alive () 120end ) 121 122it ( 'defers screen update during sync mode' , function () 123-- Establish a known screen state first. 124api . nvim_chan_send ( chan , 'visible\r\n' ) 125screen : expect ( [[ 126^visible | 127|*5 128| 129]] ) 130-- Begin sync and send more content — screen should not change. 131api . nvim_chan_send ( chan , CSI .. '?2026h' ) 132api . nvim_chan_send ( chan , 'deferred\r\n' ) 133screen : expect_unchanged () 134-- End sync — now the deferred content should appear. 135api . nvim_chan_send ( chan , CSI .. '?2026l' ) 136screen : expect ( [[ 137^visible | 138deferred | 139|*4 140| 141]] ) 142end ) 143 144it ( 'handles rapid sync on/off toggling' , function () 145for i =1 , 5 do 146api . nvim_chan_send ( chan , CSI .. '?2026h' ) 147api . nvim_chan_send ( chan , 'rapid ' .. i .. '\r\n' ) 148api . nvim_chan_send ( chan , CSI .. '?2026l' ) 149end 150screen : expect ( [[ 151^rapid 1 | 152rapid 2 | 153rapid 3 | 154rapid 4 | 155rapid 5 | 156| 157| 158]] ) 159end ) 160end )