robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.0 KiB82 linesraw
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 clear, eq, api = n.clear, t.eq, n.api
6local command, fn = n.command, n.fn
7local feed = n.feed
8
9before_each(clear)
10
11describe('screenpos() function', function()
12  it('works in floating window with border', function()
13    local opts = {
14      relative = 'editor',
15      height = 8,
16      width = 12,
17      row = 6,
18      col = 8,
19      anchor = 'NW',
20      style = 'minimal',
21      border = 'none',
22      focusable = 1,
23    }
24    local float = api.nvim_open_win(api.nvim_create_buf(false, true), false, opts)
25    command('redraw')
26    eq({ row = 7, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1))
27
28    -- only left border
29    opts.border = { '', '', '', '', '', '', '', '|' }
30    api.nvim_win_set_config(float, opts)
31    command('redraw')
32    eq({ row = 7, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1))
33
34    -- only top border
35    opts.border = { '', '_', '', '', '', '', '', '' }
36    api.nvim_win_set_config(float, opts)
37    command('redraw')
38    eq({ row = 8, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1))
39
40    -- both left and top border
41    opts.border = 'single'
42    api.nvim_win_set_config(float, opts)
43    command('redraw')
44    eq({ row = 8, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1))
45  end)
46
47  it('works for folded line with virt_lines attached to line above', function()
48    api.nvim_buf_set_lines(0, 0, -1, true, { 'aaa', 'bbb', 'ccc', 'ddd' })
49    local ns = api.nvim_create_namespace('')
50    api.nvim_buf_set_extmark(
51      0,
52      ns,
53      0,
54      0,
55      { virt_lines = { { { 'abb' } }, { { 'acc' } }, { { 'add' } } } }
56    )
57    command('2,3fold')
58    eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
59    eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
60    eq({ row = 6, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
61
62    feed('<C-E>')
63    eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
64    eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
65    eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
66
67    feed('<C-E>')
68    eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
69    eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
70    eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
71
72    feed('<C-E>')
73    eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
74    eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
75    eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
76
77    feed('<C-E>')
78    eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
79    eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
80    eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
81  end)
82end)