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