robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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