aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2024-02-05 14:38:42 +0200
committerFred Sundvik <fsundvik@gmail.com>2024-02-05 16:24:21 +0200
commitcbb7632aa0168b6b69f17ec2f97aa3c30eb58553 (patch)
treec3e8699b6f84ea5052bd00622e1aa0d34d2ea6b0
parent43661a0abf6e1698516d78e6dbf9dfdbf76720bc (diff)
downloadrneovim-cbb7632aa0168b6b69f17ec2f97aa3c30eb58553.tar.gz
rneovim-cbb7632aa0168b6b69f17ec2f97aa3c30eb58553.tar.bz2
rneovim-cbb7632aa0168b6b69f17ec2f97aa3c30eb58553.zip
test: add more hlstate tests
-rw-r--r--test/functional/ui/hlstate_spec.lua279
1 files changed, 279 insertions, 0 deletions
diff --git a/test/functional/ui/hlstate_spec.lua b/test/functional/ui/hlstate_spec.lua
index 278e6e5272..8b36ad5431 100644
--- a/test/functional/ui/hlstate_spec.lua
+++ b/test/functional/ui/hlstate_spec.lua
@@ -309,4 +309,283 @@ describe('ext_hlstate detailed highlights', function()
{3: }|
]])
end)
+
+ it('combines deleted extmark highlights', function()
+ insert([[
+ line1
+ line2
+ line3
+ line4
+ line5
+ line6]])
+
+ screen:expect {
+ grid = [[
+ line1 |
+ line2 |
+ line3 |
+ line4 |
+ line5 |
+ line^6 |
+ {1:~ }|
+ {2: }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.Blue, bold = true },
+ { { ui_name = 'EndOfBuffer', hi_name = 'NonText', kind = 'ui' } },
+ },
+ [2] = { {}, { { ui_name = 'MsgArea', hi_name = 'MsgArea', kind = 'ui' } } },
+ },
+ }
+
+ local ns = api.nvim_create_namespace('test')
+
+ local add_indicator = function(line, col)
+ api.nvim_buf_set_extmark(0, ns, line, col, {
+ hl_mode = 'combine',
+ priority = 2,
+ right_gravity = false,
+ virt_text = { { '|', 'Delimiter' } },
+ virt_text_win_col = 0,
+ virt_text_pos = 'overlay',
+ })
+ end
+
+ add_indicator(1, 0)
+ add_indicator(2, 0)
+ add_indicator(3, 0)
+ add_indicator(4, 0)
+
+ screen:expect {
+ grid = [[
+ line1 |
+ {1:|} line2 |
+ {1:|} line3 |
+ {1:|} line4 |
+ {1:|} line5 |
+ line^6 |
+ {2:~ }|
+ {3: }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { hi_name = 'Special', kind = 'syntax' } },
+ },
+ [2] = {
+ { bold = true, foreground = Screen.colors.Blue },
+ { { ui_name = 'EndOfBuffer', kind = 'ui', hi_name = 'NonText' } },
+ },
+ [3] = { {}, { { ui_name = 'MsgArea', kind = 'ui', hi_name = 'MsgArea' } } },
+ },
+ }
+
+ helpers.feed('3ggV2jd')
+ --screen:redraw_debug()
+ screen:expect {
+ grid = [[
+ line1 |
+ {1:|} line2 |
+ {2:^|}ine6 |
+ {3:~ }|*4
+ {4:3 fewer lines }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { kind = 'syntax', hi_name = 'Special' } },
+ },
+ [2] = { { foreground = Screen.colors.SlateBlue }, { 1, 1, 1 } },
+ [3] = {
+ { bold = true, foreground = Screen.colors.Blue },
+ { { kind = 'ui', ui_name = 'EndOfBuffer', hi_name = 'NonText' } },
+ },
+ [4] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
+ },
+ }
+ end)
+
+ it('removes deleted extmark highlights with invalidate', function()
+ insert([[
+ line1
+ line2
+ line3
+ line4
+ line5
+ line6]])
+
+ screen:expect {
+ grid = [[
+ line1 |
+ line2 |
+ line3 |
+ line4 |
+ line5 |
+ line^6 |
+ {1:~ }|
+ {2: }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.Blue, bold = true },
+ { { ui_name = 'EndOfBuffer', hi_name = 'NonText', kind = 'ui' } },
+ },
+ [2] = { {}, { { ui_name = 'MsgArea', hi_name = 'MsgArea', kind = 'ui' } } },
+ },
+ }
+
+ local ns = api.nvim_create_namespace('test')
+
+ local add_indicator = function(line, col)
+ api.nvim_buf_set_extmark(0, ns, line, col, {
+ hl_mode = 'combine',
+ priority = 2,
+ right_gravity = false,
+ virt_text = { { '|', 'Delimiter' } },
+ virt_text_win_col = 0,
+ virt_text_pos = 'overlay',
+ invalidate = true,
+ })
+ end
+
+ add_indicator(1, 0)
+ add_indicator(2, 0)
+ add_indicator(3, 0)
+ add_indicator(4, 0)
+
+ screen:expect {
+ grid = [[
+ line1 |
+ {1:|} line2 |
+ {1:|} line3 |
+ {1:|} line4 |
+ {1:|} line5 |
+ line^6 |
+ {2:~ }|
+ {3: }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { hi_name = 'Special', kind = 'syntax' } },
+ },
+ [2] = {
+ { bold = true, foreground = Screen.colors.Blue },
+ { { ui_name = 'EndOfBuffer', kind = 'ui', hi_name = 'NonText' } },
+ },
+ [3] = { {}, { { ui_name = 'MsgArea', kind = 'ui', hi_name = 'MsgArea' } } },
+ },
+ }
+
+ helpers.feed('3ggV2jd')
+ --screen:redraw_debug()
+ screen:expect {
+ grid = [[
+ line1 |
+ {1:|} line2 |
+ ^line6 |
+ {2:~ }|*4
+ {3:3 fewer lines }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { kind = 'syntax', hi_name = 'Special' } },
+ },
+ [2] = {
+ { foreground = Screen.colors.Blue, bold = true },
+ { { kind = 'ui', ui_name = 'EndOfBuffer', hi_name = 'NonText' } },
+ },
+ [3] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
+ },
+ }
+ end)
+
+ it('does not hang when combining too many highlights', function()
+ local num_lines = 500
+ insert('first line\n')
+ for _ = 1, num_lines do
+ insert([[
+ line
+ ]])
+ end
+ insert('last line')
+
+ helpers.feed('gg')
+ screen:expect {
+ grid = [[
+ ^first line |
+ line |*6
+ {1: }|
+ ]],
+ attr_ids = {
+ [1] = { {}, { { kind = 'ui', hi_name = 'MsgArea', ui_name = 'MsgArea' } } },
+ },
+ }
+ local ns = api.nvim_create_namespace('test')
+
+ local add_indicator = function(line, col)
+ api.nvim_buf_set_extmark(0, ns, line, col, {
+ hl_mode = 'combine',
+ priority = 2,
+ right_gravity = false,
+ virt_text = { { '|', 'Delimiter' } },
+ virt_text_win_col = 0,
+ virt_text_pos = 'overlay',
+ })
+ end
+
+ for i = 1, num_lines do
+ add_indicator(i, 0)
+ end
+
+ screen:expect {
+ grid = [[
+ ^first line |
+ {1:|} line |*6
+ {2: }|
+ ]],
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { kind = 'syntax', hi_name = 'Special' } },
+ },
+ [2] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
+ },
+ }
+
+ helpers.feed(string.format('3ggV%ijd', num_lines - 2))
+ --screen:redraw_debug(nil, nil, 100000)
+
+ local expected_ids = {}
+ for i = 1, num_lines - 1 do
+ expected_ids[i] = 1
+ end
+ screen:expect {
+ grid = string.format(
+ [[
+ first line |
+ {1:|} line |
+ {2:^|}ast line |
+ {3:~ }|*4
+ {4:%-40s}|
+ ]],
+ tostring(num_lines - 1) .. ' fewer lines'
+ ),
+ attr_ids = {
+ [1] = {
+ { foreground = Screen.colors.SlateBlue },
+ { { kind = 'syntax', hi_name = 'Special' } },
+ },
+ [2] = { { foreground = Screen.colors.SlateBlue }, expected_ids },
+ [3] = {
+ { foreground = Screen.colors.Blue, bold = true },
+ { { kind = 'ui', hi_name = 'NonText', ui_name = 'EndOfBuffer' } },
+ },
+ [4] = { {}, { { kind = 'ui', hi_name = 'MsgArea', ui_name = 'MsgArea' } } },
+ },
+ timeout = 100000,
+ }
+ end)
end)