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 tt =require ( 'test.functional.testterm' ) 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear , eq , api =n . clear , t . eq , n . api 7local feed =n . feed 8local feed_data =tt . feed_data 9local enter_altscreen =tt . enter_altscreen 10local exit_altscreen =tt . exit_altscreen 11 12describe ( ':terminal altscreen' , function () 13local screen 14 15before_each ( function () 16clear () 17screen =tt . setup_screen () 18feed_data ( { 19'line1' , 20'line2' , 21'line3' , 22'line4' , 23'line5' , 24'line6' , 25'line7' , 26'line8' , 27'' , 28} ) 29screen : expect ( [[ 30line4 | 31line5 | 32line6 | 33line7 | 34line8 | 35^ | 36{5:-- TERMINAL --} | 37]] ) 38enter_altscreen () 39screen : expect ( [[ 40|*5 41^ | 42{5:-- TERMINAL --} | 43]] ) 44eq ( 10 , api . nvim_buf_line_count ( 0 )) 45end ) 46 47it ( 'wont clear lines already in the scrollback' , function () 48feed ( '<c-\\><c-n>gg' ) 49screen : expect ( [[ 50^tty ready | 51line1 | 52line2 | 53line3 | 54|*3 55]] ) 56-- ED 3 is no-op in altscreen 57feed_data ( '\027[3J' ) 58screen : expect_unchanged () 59end ) 60 61describe ( 'restores buffer state' , function () 62local function test_exit_altscreen_restores_buffer_state () 63exit_altscreen () 64screen : expect ( [[ 65line4 | 66line5 | 67line6 | 68line7 | 69line8 | 70^ | 71{5:-- TERMINAL --} | 72]] ) 73feed ( '<c-\\><c-n>gg' ) 74screen : expect ( [[ 75^tty ready | 76line1 | 77line2 | 78line3 | 79line4 | 80line5 | 81| 82]] ) 83end 84 85it ( 'after exit' , function () 86test_exit_altscreen_restores_buffer_state () 87end ) 88 89it ( 'after ED 2 and ED 3 and exit' , function () 90feed_data ( '\027[H\027[2J\027[3J' ) 91screen : expect ( [[ 92^ | 93|*5 94{5:-- TERMINAL --} | 95]] ) 96test_exit_altscreen_restores_buffer_state () 97end ) 98end ) 99 100describe ( 'with lines printed after the screen height limit' , function () 101before_each ( function () 102feed_data ( { 103'line9' , 104'line10' , 105'line11' , 106'line12' , 107'line13' , 108'line14' , 109'line15' , 110'line16' , 111'' , 112} ) 113screen : expect ( [[ 114line12 | 115line13 | 116line14 | 117line15 | 118line16 | 119^ | 120{5:-- TERMINAL --} | 121]] ) 122end ) 123 124it ( 'wont modify line count' , function () 125eq ( 10 , api . nvim_buf_line_count ( 0 )) 126end ) 127 128it ( 'wont modify lines in the scrollback' , function () 129feed ( '<c-\\><c-n>gg' ) 130screen : expect ( [[ 131^tty ready | 132line1 | 133line2 | 134line3 | 135line12 | 136line13 | 137| 138]] ) 139end ) 140end ) 141 142describe ( 'after height is decreased by 2' , function () 143local function wait_removal () 144screen : try_resize ( screen . _width , screen . _height - 2 ) 145screen : expect ( [[ 146|*2 147rows: 4, cols: 50 | 148^ | 149{5:-- TERMINAL --} | 150]] ) 151end 152 153it ( 'removes 2 lines from the bottom of the visible buffer' , function () 154wait_removal () 155feed ( '<c-\\><c-n>4k' ) 156screen : expect ( [[ 157^ | 158|*2 159rows: 4, cols: 50 | 160| 161]] ) 162eq ( 9 , api . nvim_buf_line_count ( 0 )) 163end ) 164 165describe ( 'and after exit' , function () 166before_each ( function () 167wait_removal () 168exit_altscreen () 169end ) 170 171it ( 'restore buffer state' , function () 172screen : expect ( t . is_os ( 'win' ) and [[ 173line6 | 174line7 | 175line8 | 176^ | 177{5:-- TERMINAL --} | 178]] or [[ 179line5 | 180line6 | 181line7 | 182^line8 | 183{5:-- TERMINAL --} | 184]] ) 185end ) 186end ) 187end ) 188end )