aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoraltermo <107814000+altermo@users.noreply.github.com>2024-06-07 17:33:40 +0200
committerGitHub <noreply@github.com>2024-06-07 08:33:40 -0700
commitf3632e14e3a75114415050ab01c2d04a06036009 (patch)
treeb3a7067d7cbde9305b01324384a0aac76e6a56ae /test
parent2ce4a4d91e4abee0aab8b98c47eea9fbd4849ba6 (diff)
downloadrneovim-f3632e14e3a75114415050ab01c2d04a06036009.tar.gz
rneovim-f3632e14e3a75114415050ab01c2d04a06036009.tar.bz2
rneovim-f3632e14e3a75114415050ab01c2d04a06036009.zip
feat: get/set namespace properties #28728
ref https://github.com/neovim/neovim/pull/28432 ref https://github.com/neovim/neovim/issues/28469
Diffstat (limited to 'test')
-rw-r--r--test/functional/lua/highlight_spec.lua14
-rw-r--r--test/functional/ui/decorations_spec.lua218
2 files changed, 123 insertions, 109 deletions
diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua
index 66095121b0..ad709a06f1 100644
--- a/test/functional/lua/highlight_spec.lua
+++ b/test/functional/lua/highlight_spec.lua
@@ -4,7 +4,6 @@ local Screen = require('test.functional.ui.screen')
local exec_lua = n.exec_lua
local eq = t.eq
-local neq = t.neq
local eval = n.eval
local command = n.command
local clear = n.clear
@@ -142,9 +141,11 @@ describe('vim.highlight.on_yank', function()
vim.api.nvim_buf_set_mark(0,"]",1,1,{})
vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}})
]])
- neq({}, api.nvim__win_get_ns(0))
+ local ns = api.nvim_create_namespace('hlyank')
+ local win = api.nvim_get_current_win()
+ eq({ win }, api.nvim__ns_get(ns).wins)
command('wincmd w')
- eq({}, api.nvim__win_get_ns(0))
+ eq({ win }, api.nvim__ns_get(ns).wins)
end)
it('removes old highlight if new one is created before old one times out', function()
@@ -154,14 +155,17 @@ describe('vim.highlight.on_yank', function()
vim.api.nvim_buf_set_mark(0,"]",1,1,{})
vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}})
]])
- neq({}, api.nvim__win_get_ns(0))
+ local ns = api.nvim_create_namespace('hlyank')
+ eq(api.nvim_get_current_win(), api.nvim__ns_get(ns).wins[1])
command('wincmd w')
exec_lua([[
vim.api.nvim_buf_set_mark(0,"[",1,1,{})
vim.api.nvim_buf_set_mark(0,"]",1,1,{})
vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}})
]])
+ local win = api.nvim_get_current_win()
+ eq({ win }, api.nvim__ns_get(ns).wins)
command('wincmd w')
- eq({}, api.nvim__win_get_ns(0))
+ eq({ win }, api.nvim__ns_get(ns).wins)
end)
end)
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 3e67e33ddb..318dc8c197 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -5595,20 +5595,26 @@ describe('decorations: virt_text', function()
end)
describe('decorations: window scoped', function()
- local screen, ns
+ local screen, ns, win_other
local url = 'https://example.com'
before_each(function()
clear()
screen = Screen.new(20, 10)
screen:attach()
screen:add_extra_attr_ids {
- [100] = { special = Screen.colors.Red, undercurl = true },
- [101] = { url = "https://example.com" },
+ [100] = { special = Screen.colors.Red, undercurl = true },
+ [101] = { url = 'https://example.com' },
}
ns = api.nvim_create_namespace 'test'
insert('12345')
+
+ win_other = api.nvim_open_win(0, false, {
+ col=0,row=0,width=20,height=10,
+ relative = 'win',style = 'minimal',
+ hide = true
+ })
end)
local noextmarks = {
@@ -5616,28 +5622,28 @@ describe('decorations: window scoped', function()
1234^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
- local function set_scoped_extmark(line, col, opts)
- return api.nvim_buf_set_extmark(0, ns, line, col, vim.tbl_extend('error', { scoped = true }, opts))
+ local function set_extmark(line, col, opts)
+ return api.nvim_buf_set_extmark(0, ns, line, col, opts)
end
it('hl_group', function()
- set_scoped_extmark(0, 0, {
+ set_extmark(0, 0, {
hl_group = 'Comment',
end_col = 3,
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
{18:123}4^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5646,48 +5652,55 @@ describe('decorations: window scoped', function()
end)
it('virt_text', function()
- set_scoped_extmark(0, 0, {
+ set_extmark(0, 0, {
virt_text = { { 'a', 'Comment' } },
virt_text_pos = 'eol',
})
- set_scoped_extmark(0, 5, {
+ set_extmark(0, 5, {
virt_text = { { 'b', 'Comment' } },
virt_text_pos = 'inline',
})
- set_scoped_extmark(0, 1, {
+ set_extmark(0, 1, {
virt_text = { { 'c', 'Comment' } },
virt_text_pos = 'overlay',
})
- set_scoped_extmark(0, 1, {
+ set_extmark(0, 1, {
virt_text = { { 'd', 'Comment' } },
virt_text_pos = 'right_align',
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
1{18:c}34^5{18:b} {18:a} {18:d}|
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
screen:expect(noextmarks)
+
+ api.nvim__ns_set(ns, { wins = {} })
+
+ screen:expect {
+ grid = [[
+ 1{18:c}34^5{18:b} {18:a} {18:d}|
+ {1:~ }|*8
+ |
+ ]],
+ }
end)
it('virt_lines', function()
- set_scoped_extmark(0, 0, {
+ set_extmark(0, 0, {
virt_lines = { { { 'a', 'Comment' } } },
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
@@ -5695,7 +5708,8 @@ describe('decorations: window scoped', function()
{18:a} |
{1:~ }|*7
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5704,14 +5718,12 @@ describe('decorations: window scoped', function()
end)
it('redraws correctly with inline virt_text and wrapping', function()
- set_scoped_extmark(0, 2, {
- virt_text = {{ ('b'):rep(18), 'Comment' }},
- virt_text_pos = 'inline'
+ set_extmark(0, 2, {
+ virt_text = { { ('b'):rep(18), 'Comment' } },
+ virt_text_pos = 'inline',
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
@@ -5719,9 +5731,10 @@ describe('decorations: window scoped', function()
34^5 |
{1:~ }|*7
|
- ]]}
+ ]],
+ }
- api.nvim__win_del_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { win_other } })
screen:expect(noextmarks)
end)
@@ -5729,21 +5742,20 @@ describe('decorations: window scoped', function()
pending('sign_text', function()
-- TODO(altermo): The window signcolumn width is calculated wrongly (when `signcolumn=auto`)
-- This happens in function `win_redraw_signcols` on line containing `buf_meta_total(buf, kMTMetaSignText) > 0`
- set_scoped_extmark(0, 0, {
+ set_extmark(0, 0, {
sign_text = 'a',
sign_hl_group = 'Comment',
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
a 1234^5 |
{2:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5752,30 +5764,34 @@ describe('decorations: window scoped', function()
end)
it('statuscolumn hl group', function()
- set_scoped_extmark(0, 0, {
- number_hl_group='comment',
+ set_extmark(0, 0, {
+ number_hl_group = 'comment',
})
- set_scoped_extmark(0, 0, {
- line_hl_group='comment',
+ set_extmark(0, 0, {
+ line_hl_group = 'comment',
})
command 'set number'
+ api.nvim__ns_set(ns, { wins = { win_other } })
+
screen:expect {
grid = [[
{8: 1 }1234^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
{18: 1 1234^5 }|
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5785,36 +5801,43 @@ describe('decorations: window scoped', function()
{8: 1 }1234^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
end)
it('spell', function()
- api.nvim_buf_set_lines(0,0,-1,true,{'aa'})
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'aa' })
- set_scoped_extmark(0, 0, {
- spell=true,
- end_col=2,
+ set_extmark(0, 0, {
+ spell = true,
+ end_col = 2,
})
command 'set spelloptions=noplainbuffer'
command 'set spell'
command 'syntax off'
+ screen:expect({ unchanged = true })
+
+ api.nvim__ns_set(ns, { wins = { win_other } })
+
screen:expect {
grid = [[
a^a |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
{100:a^a} |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5824,25 +5847,25 @@ describe('decorations: window scoped', function()
a^a |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
end)
it('url', function()
- set_scoped_extmark(0, 0, {
- end_col=3,
- url=url,
+ set_extmark(0, 0, {
+ end_col = 3,
+ url = url,
})
- screen:expect(noextmarks)
-
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
screen:expect {
grid = [[
{101:123}4^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
@@ -5850,85 +5873,72 @@ describe('decorations: window scoped', function()
screen:expect(noextmarks)
end)
- it('change extmarks scoped option', function()
- local id = set_scoped_extmark(0, 0, {
+ it('change namespace scope', function()
+ set_extmark(0, 0, {
hl_group = 'Comment',
end_col = 3,
})
- api.nvim__win_add_ns(0, ns)
+ api.nvim__ns_set(ns, { wins = { 0 } })
+ eq({ wins={ api.nvim_get_current_win() } }, api.nvim__ns_get(ns))
screen:expect {
grid = [[
{18:123}4^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
command 'split'
command 'only'
screen:expect(noextmarks)
- api.nvim_buf_set_extmark(0, ns, 0, 0, {
- id = id,
- hl_group = 'Comment',
- end_col = 3,
- scoped = false,
- })
+ api.nvim__ns_set(ns, { wins = { 0 } })
+ eq({ wins={ api.nvim_get_current_win() } }, api.nvim__ns_get(ns))
screen:expect {
grid = [[
{18:123}4^5 |
{1:~ }|*8
|
- ]]}
+ ]],
+ }
- api.nvim_buf_set_extmark(0, ns, 0, 0, {
- id = id,
- hl_group = 'Comment',
- end_col = 3,
- scoped = true,
+ local win_new = api.nvim_open_win(0, false, {
+ col=0,row=0,width=20,height=10,
+ relative = 'win',style = 'minimal',
+ hide = true
})
+ api.nvim__ns_set(ns, { wins = { win_new } })
+ eq({ wins={ win_new } }, api.nvim__ns_get(ns))
+
screen:expect(noextmarks)
end)
- it('change namespace scope', function()
- set_scoped_extmark(0, 0, {
- hl_group = 'Comment',
- end_col = 3,
- })
+ it('namespace get works', function()
+ eq({ wins = {} }, api.nvim__ns_get(ns))
- eq(true, api.nvim__win_add_ns(0, ns))
- eq({ ns }, api.nvim__win_get_ns(0))
+ api.nvim__ns_set(ns, { wins = { 0 } })
- screen:expect {
- grid = [[
- {18:123}4^5 |
- {1:~ }|*8
- |
- ]]}
+ eq({ wins = { api.nvim_get_current_win() } }, api.nvim__ns_get(ns))
- command 'split'
- command 'only'
- eq({}, api.nvim__win_get_ns(0))
+ api.nvim__ns_set(ns, { wins = {} })
- screen:expect(noextmarks)
+ eq({ wins = {} }, api.nvim__ns_get(ns))
+ end)
- eq(true, api.nvim__win_add_ns(0, ns))
- eq({ ns }, api.nvim__win_get_ns(0))
+ it('remove window from namespace scope when deleted', function ()
+ api.nvim__ns_set(ns, { wins = { 0 } })
- screen:expect {
- grid = [[
- {18:123}4^5 |
- {1:~ }|*8
- |
- ]]}
+ eq({ wins = { api.nvim_get_current_win() } }, api.nvim__ns_get(ns))
- eq(true, api.nvim__win_del_ns(0, ns))
- eq({}, api.nvim__win_get_ns(0))
+ command 'split'
+ command 'only'
- screen:expect(noextmarks)
+ eq({ wins = {} }, api.nvim__ns_get(ns))
end)
end)
+