aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/extmark_spec.lua30
-rw-r--r--test/functional/api/vim_spec.lua25
2 files changed, 31 insertions, 24 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 6f53076f1f..31bb9841dc 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -83,7 +83,7 @@ end
describe('API/extmarks', function()
local screen
local marks, positions, init_text, row, col
- local ns, ns2
+ local ns, ns2 ---@type integer, integer
before_each(function()
-- Initialize some namespaces and insert 12345 into a buffer
@@ -1425,14 +1425,12 @@ describe('API/extmarks', function()
end)
it('throws consistent error codes', function()
- local ns_invalid = ns2 + 1
- eq(
- "Invalid 'ns_id': 3",
- pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
- )
- eq("Invalid 'ns_id': 3", pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
- eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
- eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
+ local ns_invalid = ns2 + 1 ---@type integer
+ local err = string.format("Invalid 'ns_id': %d", ns_invalid)
+ eq(err, pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
+ eq(err, pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
+ eq(err, pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
+ eq(err, pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end)
it('when col = line-length, set the mark on eol', function()
@@ -1535,7 +1533,7 @@ describe('API/extmarks', function()
0,
0,
{
- ns_id = 1,
+ ns_id = ns,
end_col = 0,
end_row = 1,
right_gravity = true,
@@ -1595,7 +1593,7 @@ describe('API/extmarks', function()
hl_group = 'String',
hl_mode = 'blend',
line_hl_group = 'Statement',
- ns_id = 1,
+ ns_id = ns,
number_hl_group = 'Statement',
priority = 0,
right_gravity = false,
@@ -1626,7 +1624,7 @@ describe('API/extmarks', function()
0,
0,
{
- ns_id = 1,
+ ns_id = ns,
right_gravity = true,
priority = 0,
virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } },
@@ -1647,7 +1645,7 @@ describe('API/extmarks', function()
0,
0,
{
- ns_id = 1,
+ ns_id = ns,
right_gravity = true,
ui_watched = true,
priority = 0,
@@ -1663,7 +1661,7 @@ describe('API/extmarks', function()
0,
0,
{
- ns_id = 1,
+ ns_id = ns,
cursorline_hl_group = 'Statement',
priority = 4096,
right_gravity = true,
@@ -1683,7 +1681,7 @@ describe('API/extmarks', function()
end_col = 1,
end_right_gravity = false,
end_row = 0,
- ns_id = 1,
+ ns_id = ns,
right_gravity = true,
spell = true,
},
@@ -1700,7 +1698,7 @@ describe('API/extmarks', function()
end_col = 1,
end_right_gravity = false,
end_row = 0,
- ns_id = 1,
+ ns_id = ns,
right_gravity = true,
spell = false,
},
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index b5fcd88f71..18e6dbd9b6 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -3167,14 +3167,23 @@ describe('API', function()
describe('nvim_create_namespace', function()
it('works', function()
- eq({}, api.nvim_get_namespaces())
- eq(1, api.nvim_create_namespace('ns-1'))
- eq(2, api.nvim_create_namespace('ns-2'))
- eq(1, api.nvim_create_namespace('ns-1'))
- eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, api.nvim_get_namespaces())
- eq(3, api.nvim_create_namespace(''))
- eq(4, api.nvim_create_namespace(''))
- eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, api.nvim_get_namespaces())
+ local orig = api.nvim_get_namespaces()
+ local base = vim.iter(orig):fold(0, function(acc, _, v)
+ return math.max(acc, v)
+ end)
+ eq(base + 1, api.nvim_create_namespace('ns-1'))
+ eq(base + 2, api.nvim_create_namespace('ns-2'))
+ eq(base + 1, api.nvim_create_namespace('ns-1'))
+
+ local expected = vim.tbl_extend('error', orig, {
+ ['ns-1'] = base + 1,
+ ['ns-2'] = base + 2,
+ })
+
+ eq(expected, api.nvim_get_namespaces())
+ eq(base + 3, api.nvim_create_namespace(''))
+ eq(base + 4, api.nvim_create_namespace(''))
+ eq(expected, api.nvim_get_namespaces())
end)
end)