clipboard_spec.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local eq = t.eq
  4. local retry = t.retry
  5. local clear = n.clear
  6. local fn = n.fn
  7. local testprg = n.testprg
  8. local exec_lua = n.exec_lua
  9. local eval = n.eval
  10. describe(':terminal', function()
  11. before_each(function()
  12. clear()
  13. exec_lua([[
  14. local function clipboard(reg, type)
  15. if type == 'copy' then
  16. return function(lines)
  17. local data = table.concat(lines, '\n')
  18. vim.g.clipboard_data = data
  19. end
  20. end
  21. if type == 'paste' then
  22. return function()
  23. error()
  24. end
  25. end
  26. error('invalid type: ' .. type)
  27. end
  28. vim.g.clipboard = {
  29. name = 'Test',
  30. copy = {
  31. ['+'] = clipboard('+', 'copy'),
  32. ['*'] = clipboard('*', 'copy'),
  33. },
  34. paste = {
  35. ['+'] = clipboard('+', 'paste'),
  36. ['*'] = clipboard('*', 'paste'),
  37. },
  38. }
  39. ]])
  40. end)
  41. it('can write to the system clipboard', function()
  42. eq('Test', eval('g:clipboard.name'))
  43. local text = 'Hello, world! This is some\nexample text\nthat spans multiple\nlines'
  44. local encoded = exec_lua('return vim.base64.encode(...)', text)
  45. local function osc52(arg)
  46. return string.format('\027]52;;%s\027\\', arg)
  47. end
  48. fn.jobstart({ testprg('shell-test'), '-t', osc52(encoded) }, { term = true })
  49. retry(nil, 1000, function()
  50. eq(text, exec_lua([[ return vim.g.clipboard_data ]]))
  51. end)
  52. end)
  53. end)