robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local n =require ( 'test.functional.testnvim' )() 2local t =require ( 'test.testutil' ) 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local api =n . api 6local assert_alive =n . assert_alive 7local clear =n . clear 8local exec_lua =n . exec_lua 9 10local OSC_PREFIX =string . char ( 0x1b , 0x5d ) 11local BEL =string . char ( 0x07 ) 12local ST =string . char ( 0x1b , 0x5c ) 13local NUL =string . char ( 0x00 ) 14 15describe ( ':terminal' , function () 16before_each ( clear ) 17 18it ( 'handles invalid OSC terminators #30084' , function () 19local chan =api . nvim_open_term ( 0 , {} ) 20api . nvim_chan_send ( chan , '\027]8;;https://example.com\027\\Example\027]8;;\027\n' ) 21assert_alive () 22end ) 23 24it ( 'handles OSC-2 title setting' , function () 25-- OSC-2 should set title. 26local chan =api . nvim_open_term ( 0 , {} ) 27local input =OSC_PREFIX .. '2;This title set with OSC 2' .. BEL 28api . nvim_chan_send ( chan , input ) 29--- @type string 30local term_title =api . nvim_buf_get_var ( 0 , 'term_title' ) 31t . eq ( 'This title set with OSC 2' , term_title ) 32assert_alive () 33end ) 34 35it ( 'handles OSC-0 title and icon setting' , function () 36-- OSC-0 should set title and icon name to the same string. We currently ignore the icon name, 37-- but the title should still be reflected. 38local chan =api . nvim_open_term ( 0 , {} ) 39local input =OSC_PREFIX .. '0;This title set with OSC 0' .. BEL 40api . nvim_chan_send ( chan , input ) 41--- @type string 42local term_title =api . nvim_buf_get_var ( 0 , 'term_title' ) 43t . eq ( 'This title set with OSC 0' , term_title ) 44assert_alive () 45end ) 46 47it ( 'handles control character following OSC prefix #34028' , function () 48local chan =api . nvim_open_term ( 0 , {} ) 49-- In order to test for the crash found in #34028 we need a ctrl char following the OSC_PREFIX 50-- which causes `string_fragment()` to be called while in OSC_COMMAND mode, this caused 51-- initial_string to be flipped back to false. At the end we need two more non-BEL control 52-- characters, one to write into the 1 byte buffer, then another to trigger the callback one 53-- more time so that realloc notices that it's internal data has been overwritten. 54local input =OSC_PREFIX .. NUL .. '0;aaaaaaaaaaaaaaaaaaaaaaaaaaa' .. NUL .. NUL 55api . nvim_chan_send ( chan , input ) 56assert_alive () 57 58-- On some platforms such as MacOS we need a longer string to reproduce the crash from #34028. 59input =OSC_PREFIX .. NUL .. '0;' 60for _ =1 , 256 do 61input =input .. 'a' 62end 63input =input .. NUL .. NUL 64api . nvim_chan_send ( chan , input ) 65assert_alive () 66end ) 67 68it ( 'uses terminator matching query for OSC TermRequest #37018' , function () 69local chan =api . nvim_open_term ( 0 , {} ) 70exec_lua ( [[ 71vim.api.nvim_create_autocmd("TermRequest", { 72callback = function(ev) 73_G.osc10_response = {sequence = ev.data.sequence, terminator = ev.data.terminator } 74end 75}) 76]] ) 77 78local function send_osc_with_terminator ( terminator ) 79local input =OSC_PREFIX .. '10;?' .. terminator 80api . nvim_chan_send ( chan , input ) 81end 82 83send_osc_with_terminator ( BEL ) 84--- @type string 85t . eq ( 86{ sequence =OSC_PREFIX .. '10;?' , terminator =BEL } , 87exec_lua ( [[return _G.osc10_response]] ) 88) 89 90send_osc_with_terminator ( ST ) 91--- @type string 92t . eq ( 93{ sequence =OSC_PREFIX .. '10;?' , terminator =ST } , 94exec_lua ( [[return _G.osc10_response]] ) 95) 96end ) 97 98it ( 'does not leak pending TermRequest on buffer destroy #39332' , function () 99-- Send all OSC sequences in one exec_lua so that the event loop does not drain between the sends. 100exec_lua ( function ( prefix , st ) 101local buf =vim . api . nvim_create_buf ( false , true ) 102local chan =vim . api . nvim_open_term ( buf , {} ) 103vim . api . nvim_create_autocmd ( 'TermRequest' , { buffer =buf , callback =function () end } ) 104vim . api . nvim_chan_send ( chan , prefix .. '7;file:///a' .. st ) 105vim . api . nvim_chan_send ( chan , prefix .. '7;file:///b' .. st ) 106vim . api . nvim_buf_delete ( buf , { force =true } ) 107end , OSC_PREFIX , ST ) 108assert_alive () 109end ) 110end )