local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local command = n.command
local eq = t.eq
local exec = n.exec
local eval = n.eval
local exec_lua = n.exec_lua
local feed = n.feed
local api = n.api
local pcall_err = t.pcall_err
local assert_alive = n.assert_alive
describe('statuscolumn', function()
local screen
before_each(function()
clear('--cmd', 'set number nuw=1 | call setline(1, repeat(["aaaaa"], 16)) | norm GM')
screen = Screen.new()
screen:add_extra_attr_ids {
[100] = { foreground = Screen.colors.Red, background = Screen.colors.LightGray },
[101] = { background = Screen.colors.Gray90, bold = true },
[102] = { foreground = Screen.colors.Brown, background = Screen.colors.Grey },
[103] = { bold = true, background = Screen.colors.Grey, foreground = Screen.colors.Blue1 },
[104] = { undercurl = true, special = Screen.colors.Red },
[105] = { foreground = Screen.colors.Red, underline = true },
[106] = { foreground = Screen.colors.Orange1 },
[107] = { foreground = Screen.colors.LightBlue },
}
exec_lua('ns = vim.api.nvim_create_namespace("")')
end)
it("fails with invalid 'statuscolumn'", function()
command(
[[set stc=%{v:relnum?v:relnum:(v:lnum==5?'truncate':v:lnum)}%{!v:relnum&&v:lnum==5?invalid:''}\ ]]
)
screen:expect([[
{8:4 }aaaaa |
{8:3 }aaaaa |
{8:2 }aaaaa |
{8:1 }aaaaa |
{8:8 }^aaaaa |
{8:1 }aaaaa |
{8:2 }aaaaa |
{8:3 }aaaaa |
{8:4 }aaaaa |
{8:5 }aaaaa |
{8:6 }aaaaa |
{8:7 }aaaaa |
{8:8 }aaaaa |
|
]])
command('norm 5G')
eq('Vim(redraw):E121: Undefined variable: invalid', pcall_err(command, 'redraw!'))
eq('', eval('&statuscolumn'))
screen:expect([[
{8: 4 }aaaaa |
{8: 5 }^aaaaa |
{8: 6 }aaaaa |
{8: 7 }aaaaa |
{8: 8 }aaaaa |
{8: 9 }aaaaa |
{8:10 }aaaaa |
{8:11 }aaaaa |
{8:12 }aaaaa |
{8:13 }aaaaa |
{8:14 }aaaaa |
{8:15 }aaaaa |
{8:16 }aaaaa |
|
]])
end)
it("widens with irregular 'statuscolumn' width", function()
screen:try_resize(screen._width, 4)
command([=[
set stc=%{v:relnum?v:relnum:(v:lnum==5?'bbbbb':v:lnum)}
let ns = nvim_create_namespace('')
call nvim_buf_set_extmark(0, ns, 3, 0, {'virt_text':[['virt_text']]})
norm 5G | redraw!
]=])
screen:expect([[
{8:1 }aaaaa virt_text |
{8:bbbbb}a^eaaa |
{8:1 }aaaaa |
|
]])
-- Doesn't crash when trying to fill click defs that do not fit (#26845)
command('norm gg')
command([=[
set stc=%@Click@%{v:relnum?v:relnum:(v:lnum==5?'bbbbb':v:lnum)}%T
norm 5Gzt | redraw!
]=])
screen:expect([[
{8:bbbbb}a^eaaa |
{8:1 }aaaaa |
{8:2 }aaaaa |
|
]])
-- Doesn't crash when clicking inside padded area without click_defs
command('set numberwidth=10')
api.nvim_input_mouse('left', 'press', '', 0, 0, 5)
assert_alive()
end)
it("works with 'number' and 'relativenumber'", function()
screen:expect([[
{8: 4 }aaaaa |
{8: 5 }aaaaa |
{8: 6 }aaaaa |
{8: 7 }aaaaa |
{8: 8 }^aaaaa |
{8: 9 }aaaaa |
{8:10 }aaaaa |
{8:11 }aaaaa |
{8:12 }aaaaa |
{8:13 }aaaaa |
{8:14 }aaaaa |
{8:15 }aaaaa |
{8:16 }aaaaa |
|
]])
command([[set stc=%l\ ]])
screen:expect_unchanged()
command('set relativenumber')
screen:expect([[
{8: 4 }aaaaa |
{8: 3 }aaaaa |
{8: 2 }aaaaa |
{8: 1 }aaaaa |
{8:8 }^aaaaa |
{8: 1 }aaaaa |
{8: 2 }aaaaa |
{8: 3 }aaaaa |
{8: 4 }aaaaa |
{8: 5 }aaaaa |
{8: 6 }aaaaa
|