neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

clipboard_spec.lua (1545B)


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