robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e58f29ca3e
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 retry =t . retry 7 8local clear =n . clear 9local fn =n . fn 10local testprg =n . testprg 11local exec_lua =n . exec_lua 12local eval =n . eval 13 14describe ( ':terminal' , function () 15before_each ( function () 16clear () 17 18exec_lua ( [[ 19local function clipboard(reg, type) 20if type == 'copy' then 21return function(lines) 22vim.g.clipboard_lines = lines 23local data = table.concat(lines, '\n') 24vim.g.clipboard_data = data 25end 26end 27 28if type == 'paste' then 29return function() 30error() 31end 32end 33 34error('invalid type: ' .. type) 35end 36 37vim.g.clipboard = { 38name = 'Test', 39copy = { 40['+'] = clipboard('+', 'copy'), 41['*'] = clipboard('*', 'copy'), 42}, 43paste = { 44['+'] = clipboard('+', 'paste'), 45['*'] = clipboard('*', 'paste'), 46}, 47} 48]] ) 49end ) 50 51local function osc52 ( arg ) 52return string . format ( '\027]52;;%s\027\\' , arg ) 53end 54 55it ( 'can write to the system clipboard' , function () 56eq ( 'Test' , eval ( 'g:clipboard.name' )) 57 58local text ='Hello, world! This is some\nexample text\nthat spans multiple\nlines' 59local encoded =exec_lua ( 'return vim.base64.encode(...)' , text ) 60 61fn . jobstart ( { testprg ( 'shell-test' ), '-t' , osc52 ( encoded ) } , { term =true } ) 62 63retry ( nil , 1000 , function () 64eq ( text , exec_lua ( [[ return vim.g.clipboard_data ]] )) 65end ) 66 67-- Multiline payloads must arrive split into separate list items: a newline 68-- inside a single item would be sent to a command-line provider as NUL. 69eq ( { 70'Hello, world! This is some' , 71'example text' , 72'that spans multiple' , 73'lines' , 74} , exec_lua ( [[ return vim.g.clipboard_lines ]] )) 75end ) 76 77it ( 'multiline copy does not send newlines as NUL #41097' , function () 78local text ='\nfoo\n\nbar\n' 79local encoded =exec_lua ( 'return vim.base64.encode(...)' , text ) 80 81fn . jobstart ( { testprg ( 'shell-test' ), '-t' , osc52 ( encoded ) } , { term =true } ) 82 83retry ( nil , 1000 , function () 84eq ( { '' , 'foo' , '' , 'bar' , '' } , exec_lua ( [[ return vim.g.clipboard_lines ]] )) 85end ) 86end ) 87end )