neovim

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

screenchar_spec.lua (3383B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 local Screen = require('test.functional.ui.screen')
      4 
      5 local clear, eq, neq = n.clear, t.eq, t.neq
      6 local command, api, fn = n.command, n.api, n.fn
      7 local tbl_deep_extend = vim.tbl_deep_extend
      8 
      9 -- Set up two overlapping floating windows
     10 local setup_floating_windows = function()
     11  local base_opts = {
     12    relative = 'editor',
     13    height = 1,
     14    width = 2,
     15    anchor = 'NW',
     16    style = 'minimal',
     17    border = 'none',
     18  }
     19 
     20  local bufnr_1 = api.nvim_create_buf(false, true)
     21  api.nvim_buf_set_lines(bufnr_1, 0, -1, true, { 'aa' })
     22  local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts)
     23  api.nvim_open_win(bufnr_1, false, opts_1)
     24 
     25  local bufnr_2 = api.nvim_create_buf(false, true)
     26  api.nvim_buf_set_lines(bufnr_2, 0, -1, true, { 'bb' })
     27  local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts)
     28  api.nvim_open_win(bufnr_2, false, opts_2)
     29 
     30  command('redraw')
     31 end
     32 
     33 describe('screenchar() and family respect floating windows', function()
     34  local function with_ext_multigrid(multigrid)
     35    setup(function()
     36      clear()
     37      Screen.new(40, 7, { ext_multigrid = multigrid })
     38      -- These commands result into visible text `aabc`.
     39      -- `aab` - from floating windows, `c` - from text in regular window.
     40      api.nvim_buf_set_lines(0, 0, -1, true, { 'cccc' })
     41      setup_floating_windows()
     42    end)
     43 
     44    it('screenattr()', function()
     45      local attr_1 = fn.screenattr(1, 1)
     46      local attr_2 = fn.screenattr(1, 2)
     47      local attr_3 = fn.screenattr(1, 3)
     48      local attr_4 = fn.screenattr(1, 4)
     49      eq(attr_1, attr_2)
     50      eq(attr_1, attr_3)
     51      neq(attr_1, attr_4)
     52    end)
     53 
     54    it('screenchar()', function()
     55      eq(97, fn.screenchar(1, 1))
     56      eq(97, fn.screenchar(1, 2))
     57      eq(98, fn.screenchar(1, 3))
     58      eq(99, fn.screenchar(1, 4))
     59    end)
     60 
     61    it('screenchars()', function()
     62      eq({ 97 }, fn.screenchars(1, 1))
     63      eq({ 97 }, fn.screenchars(1, 2))
     64      eq({ 98 }, fn.screenchars(1, 3))
     65      eq({ 99 }, fn.screenchars(1, 4))
     66    end)
     67 
     68    it('screenstring()', function()
     69      eq('a', fn.screenstring(1, 1))
     70      eq('a', fn.screenstring(1, 2))
     71      eq('b', fn.screenstring(1, 3))
     72      eq('c', fn.screenstring(1, 4))
     73    end)
     74  end
     75 
     76  describe('with ext_multigrid', function()
     77    with_ext_multigrid(true)
     78  end)
     79 
     80  describe('without ext_multigrid', function()
     81    with_ext_multigrid(false)
     82  end)
     83 
     84  describe('hidden windows', function()
     85    before_each(function()
     86      clear()
     87      Screen.new(40, 7, {})
     88      api.nvim_buf_set_lines(0, 0, -1, true, { 'aaa', 'aaa' })
     89    end)
     90 
     91    local assert_screen_funcs = function()
     92      eq('a', fn.screenstring(1, 1))
     93      eq(97, fn.screenchar(1, 1))
     94      eq({ 97 }, fn.screenchars(1, 1))
     95      eq(fn.screenattr(2, 1), fn.screenattr(1, 1))
     96    end
     97 
     98    it('manual', function()
     99      local bufnr = api.nvim_create_buf(false, true)
    100      api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'bb' })
    101      local win_opts = { relative = 'editor', row = 0, col = 0, height = 1, width = 2, hide = true }
    102      api.nvim_open_win(bufnr, false, win_opts)
    103 
    104      assert_screen_funcs()
    105    end)
    106 
    107    it('from ui2', function()
    108      n.exec_lua('require("vim._core.ui2").enable({ enable = true })')
    109      command('echo "foo"')
    110 
    111      assert_screen_funcs()
    112    end)
    113  end)
    114 end)