aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/extmark_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
commitc324271b99eee4c621463f368914d57cd729bd9c (patch)
tree5d979d333a2d5f9c080991d5482fd5916f8579c6 /test/functional/api/extmark_spec.lua
parent931bffbda3668ddc609fc1da8f9eb576b170aa52 (diff)
parentade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff)
downloadrneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.gz
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.bz2
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.zip
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'test/functional/api/extmark_spec.lua')
-rw-r--r--test/functional/api/extmark_spec.lua1046
1 files changed, 598 insertions, 448 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 44a151cf6a..2acfbfc949 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -4,15 +4,13 @@ local Screen = require('test.functional.ui.screen')
local request = helpers.request
local eq = helpers.eq
local ok = helpers.ok
-local curbufmeths = helpers.curbufmeths
-local bufmeths = helpers.bufmeths
local pcall_err = helpers.pcall_err
local insert = helpers.insert
local feed = helpers.feed
local clear = helpers.clear
local command = helpers.command
local exec = helpers.exec
-local meths = helpers.meths
+local api = helpers.api
local assert_alive = helpers.assert_alive
local function expect(contents)
@@ -26,32 +24,32 @@ local function set_extmark(ns_id, id, line, col, opts)
if id ~= nil and id ~= 0 then
opts.id = id
end
- return curbufmeths.set_extmark(ns_id, line, col, opts)
+ return api.nvim_buf_set_extmark(0, ns_id, line, col, opts)
end
local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then
opts = {}
end
- return curbufmeths.get_extmarks(ns_id, start, end_, opts)
+ return api.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
end
local function get_extmark_by_id(ns_id, id, opts)
if opts == nil then
opts = {}
end
- return curbufmeths.get_extmark_by_id(ns_id, id, opts)
+ return api.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
end
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
local rv = get_extmark_by_id(ns, mark)
- eq({er, ec}, rv)
- feed("u")
+ eq({ er, ec }, rv)
+ feed('u')
rv = get_extmark_by_id(ns, mark)
- eq({sr, sc}, rv)
- feed("<c-r>")
+ eq({ sr, sc }, rv)
+ feed('<c-r>')
rv = get_extmark_by_id(ns, mark)
- eq({er, ec}, rv)
+ eq({ er, ec }, rv)
end
local function batch_set(ns_id, positions)
@@ -64,20 +62,20 @@ end
local function batch_check(ns_id, ids, positions)
local actual, expected = {}, {}
- for i,id in ipairs(ids) do
+ for i, id in ipairs(ids) do
expected[id] = positions[i]
end
for _, mark in pairs(get_extmarks(ns_id, 0, -1, {})) do
- actual[mark[1]] = {mark[2], mark[3]}
+ actual[mark[1]] = { mark[2], mark[3] }
end
eq(expected, actual)
end
local function batch_check_undo_redo(ns_id, ids, before, after)
batch_check(ns_id, ids, after)
- feed("u")
+ feed('u')
batch_check(ns_id, ids, before)
- feed("<c-r>")
+ feed('<c-r>')
batch_check(ns_id, ids, after)
end
@@ -88,49 +86,78 @@ describe('API/extmarks', function()
before_each(function()
-- Initialize some namespaces and insert 12345 into a buffer
- marks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
- positions = {{0, 0,}, {0, 2}, {0, 3}}
+ marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
+ positions = { { 0, 0 }, { 0, 2 }, { 0, 3 } }
- init_text = "12345"
+ init_text = '12345'
row = 0
col = 2
clear()
insert(init_text)
- ns = request('nvim_create_namespace', "my-fancy-plugin")
- ns2 = request('nvim_create_namespace', "my-fancy-plugin2")
+ ns = request('nvim_create_namespace', 'my-fancy-plugin')
+ ns2 = request('nvim_create_namespace', 'my-fancy-plugin2')
end)
it('validation', function()
- eq("Invalid 'end_col': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 }))
- eq("Invalid 'end_row': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} }))
- eq("Invalid 'virt_text_pos': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 }))
- eq("Invalid 'virt_text_pos': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' }))
- eq("Invalid 'hl_mode': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 }))
+ eq(
+ "Invalid 'end_col': expected Integer, got Array",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })
+ )
+ eq(
+ "Invalid 'end_row': expected Integer, got Array",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })
+ )
+ eq(
+ "Invalid 'virt_text_pos': expected String, got Integer",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 })
+ )
+ eq(
+ "Invalid 'virt_text_pos': 'foo'",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })
+ )
+ eq(
+ "Invalid 'hl_mode': expected String, got Integer",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })
+ )
eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' }))
- eq("Invalid 'id': expected Integer, got Array", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 }))
- eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1}))
- eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1}))
+ eq(
+ "Invalid 'id': expected Integer, got Array",
+ pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })
+ )
+ eq(
+ 'Invalid mark position: expected 2 Integer items',
+ pcall_err(get_extmarks, ns, {}, { -1, -1 })
+ )
+ eq(
+ 'Invalid mark position: expected mark id Integer or 2-item Array',
+ pcall_err(get_extmarks, ns, true, { -1, -1 })
+ )
-- No memory leak with virt_text, virt_lines, sign_text
- eq("right_gravity is not a boolean", pcall_err(set_extmark, ns, marks[2], 0, 0, {
- virt_text = {{'foo', 'Normal'}},
- virt_lines = {{{'bar', 'Normal'}}},
- sign_text = 'a',
- right_gravity = 'baz',
- }))
+ eq(
+ 'right_gravity is not a boolean',
+ pcall_err(set_extmark, ns, marks[2], 0, 0, {
+ virt_text = { { 'foo', 'Normal' } },
+ virt_lines = { { { 'bar', 'Normal' } } },
+ sign_text = 'a',
+ right_gravity = 'baz',
+ })
+ )
end)
- it("can end extranges past final newline using end_col = 0", function()
+ it('can end extranges past final newline using end_col = 0', function()
set_extmark(ns, marks[1], 0, 0, {
end_col = 0,
- end_row = 1
+ end_row = 1,
})
- eq("Invalid 'end_col': out of range",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 }))
+ eq(
+ "Invalid 'end_col': out of range",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })
+ )
end)
- it("can end extranges past final newline when strict mode is false", function()
+ it('can end extranges past final newline when strict mode is false', function()
set_extmark(ns, marks[1], 0, 0, {
end_col = 1,
end_row = 1,
@@ -138,7 +165,7 @@ describe('API/extmarks', function()
})
end)
- it("can end extranges past final column when strict mode is false", function()
+ it('can end extranges past final column when strict mode is false', function()
set_extmark(ns, marks[1], 0, 0, {
end_col = 6,
end_row = 0,
@@ -150,7 +177,7 @@ describe('API/extmarks', function()
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
rv = get_extmark_by_id(ns, marks[1])
- eq({positions[1][1], positions[1][2]}, rv)
+ eq({ positions[1][1], positions[1][2] }, rv)
-- Test adding a second mark on same row works
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
eq(marks[2], rv)
@@ -159,21 +186,21 @@ describe('API/extmarks', function()
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
rv = get_extmark_by_id(ns, marks[2])
- eq({positions[2][1], positions[2][2]}, rv)
+ eq({ positions[2][1], positions[2][2] }, rv)
-- Test an update, (new pos)
row = positions[1][1]
col = positions[1][2] + 1
rv = set_extmark(ns, marks[1], row, col)
eq(marks[1], rv)
rv = get_extmark_by_id(ns, marks[1])
- eq({row, col}, rv)
+ eq({ row, col }, rv)
-- remove the test marks
- eq(true, curbufmeths.del_extmark(ns, marks[1]))
- eq(false, curbufmeths.del_extmark(ns, marks[1]))
- eq(true, curbufmeths.del_extmark(ns, marks[2]))
- eq(false, curbufmeths.del_extmark(ns, marks[3]))
- eq(false, curbufmeths.del_extmark(ns, 1000))
+ eq(true, api.nvim_buf_del_extmark(0, ns, marks[1]))
+ eq(false, api.nvim_buf_del_extmark(0, ns, marks[1]))
+ eq(true, api.nvim_buf_del_extmark(0, ns, marks[2]))
+ eq(false, api.nvim_buf_del_extmark(0, ns, marks[3]))
+ eq(false, api.nvim_buf_del_extmark(0, ns, 1000))
end)
it('can clear a specific namespace range', function()
@@ -181,15 +208,15 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer
feed('o<esc>')
- curbufmeths.clear_namespace(ns2, 0, -1)
- eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ api.nvim_buf_clear_namespace(0, ns2, 0, -1)
+ eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u')
- eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('<c-r>')
- eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
end)
it('can clear a namespace range using 0,-1', function()
@@ -197,32 +224,32 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer
feed('o<esc>')
- curbufmeths.clear_namespace(-1, 0, -1)
- eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ api.nvim_buf_clear_namespace(0, -1, 0, -1)
+ eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u')
- eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('<c-r>')
- eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
- eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
+ eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
end)
it('can undo with extmarks (#25147)', function()
feed('itest<esc>')
set_extmark(ns, 1, 0, 0)
set_extmark(ns, 2, 1, 0)
- eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('dd')
- eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
- curbufmeths.clear_namespace(ns, 0, -1)
- eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
+ eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ api.nvim_buf_clear_namespace(0, ns, 0, -1)
+ eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
set_extmark(ns, 1, 0, 0, { right_gravity = false })
set_extmark(ns, 2, 1, 0, { right_gravity = false })
- eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('u')
- eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, {0, 0}, {-1, -1}))
- curbufmeths.clear_namespace(ns, 0, -1)
+ eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
+ api.nvim_buf_clear_namespace(0, ns, 0, -1)
end)
it('querying for information and ranges', function()
@@ -237,112 +264,114 @@ describe('API/extmarks', function()
end
-- {0, 0} and {-1, -1} work as extreme values
- eq({{1, 0, 0}}, get_extmarks(ns, {0, 0}, {0, 0}))
- eq({}, get_extmarks(ns, {-1, -1}, {-1, -1}))
- local rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ eq({ { 1, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { 0, 0 }))
+ eq({}, get_extmarks(ns, { -1, -1 }, { -1, -1 }))
+ local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
for i, m in ipairs(marks) do
if positions[i] ~= nil then
- eq({m, positions[i][1], positions[i][2]}, rv[i])
+ eq({ m, positions[i][1], positions[i][2] }, rv[i])
end
end
-- 0 and -1 works as short hand extreme values
- eq({{1, 0, 0}}, get_extmarks(ns, 0, 0))
+ eq({ { 1, 0, 0 } }, get_extmarks(ns, 0, 0))
eq({}, get_extmarks(ns, -1, -1))
rv = get_extmarks(ns, 0, -1)
for i, m in ipairs(marks) do
if positions[i] ~= nil then
- eq({m, positions[i][1], positions[i][2]}, rv[i])
+ eq({ m, positions[i][1], positions[i][2] }, rv[i])
end
end
-- next with mark id
- rv = get_extmarks(ns, marks[1], {-1, -1}, {limit=1})
- eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
- rv = get_extmarks(ns, marks[2], {-1, -1}, {limit=1})
- eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
+ rv = get_extmarks(ns, marks[1], { -1, -1 }, { limit = 1 })
+ eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
+ rv = get_extmarks(ns, marks[2], { -1, -1 }, { limit = 1 })
+ eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
-- next with positional when mark exists at position
- rv = get_extmarks(ns, positions[1], {-1, -1}, {limit=1})
- eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
+ rv = get_extmarks(ns, positions[1], { -1, -1 }, { limit = 1 })
+ eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
-- next with positional index (no mark at position)
- rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {-1, -1}, {limit=1})
- eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
+ rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { -1, -1 }, { limit = 1 })
+ eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
-- next with Extremity index
- rv = get_extmarks(ns, {0,0}, {-1, -1}, {limit=1})
- eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
+ eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
-- nextrange with mark id
rv = get_extmarks(ns, marks[1], marks[3])
- eq({marks[1], positions[1][1], positions[1][2]}, rv[1])
- eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
+ eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
+ eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
-- nextrange with `limit`
- rv = get_extmarks(ns, marks[1], marks[3], {limit=2})
+ rv = get_extmarks(ns, marks[1], marks[3], { limit = 2 })
eq(2, #rv)
-- nextrange with positional when mark exists at position
rv = get_extmarks(ns, positions[1], positions[3])
- eq({marks[1], positions[1][1], positions[1][2]}, rv[1])
- eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
+ eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
+ eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
rv = get_extmarks(ns, positions[2], positions[3])
eq(2, #rv)
-- nextrange with positional index (no mark at position)
- local lower = {positions[1][1], positions[2][2] -1}
- local upper = {positions[2][1], positions[3][2] - 1}
+ local lower = { positions[1][1], positions[2][2] - 1 }
+ local upper = { positions[2][1], positions[3][2] - 1 }
rv = get_extmarks(ns, lower, upper)
- eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
- lower = {positions[3][1], positions[3][2] + 1}
- upper = {positions[3][1], positions[3][2] + 2}
+ eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
+ lower = { positions[3][1], positions[3][2] + 1 }
+ upper = { positions[3][1], positions[3][2] + 2 }
rv = get_extmarks(ns, lower, upper)
eq({}, rv)
-- nextrange with extremity index
- lower = {positions[2][1], positions[2][2]+1}
- upper = {-1, -1}
+ lower = { positions[2][1], positions[2][2] + 1 }
+ upper = { -1, -1 }
rv = get_extmarks(ns, lower, upper)
- eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
+ eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
-- prev with mark id
- rv = get_extmarks(ns, marks[3], {0, 0}, {limit=1})
- eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
- rv = get_extmarks(ns, marks[2], {0, 0}, {limit=1})
- eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
+ rv = get_extmarks(ns, marks[3], { 0, 0 }, { limit = 1 })
+ eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
+ rv = get_extmarks(ns, marks[2], { 0, 0 }, { limit = 1 })
+ eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
-- prev with positional when mark exists at position
- rv = get_extmarks(ns, positions[3], {0, 0}, {limit=1})
- eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
+ rv = get_extmarks(ns, positions[3], { 0, 0 }, { limit = 1 })
+ eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
-- prev with positional index (no mark at position)
- rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {0, 0}, {limit=1})
- eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
+ rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { 0, 0 }, { limit = 1 })
+ eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
-- prev with Extremity index
- rv = get_extmarks(ns, {-1,-1}, {0,0}, {limit=1})
- eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
+ rv = get_extmarks(ns, { -1, -1 }, { 0, 0 }, { limit = 1 })
+ eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
-- prevrange with mark id
rv = get_extmarks(ns, marks[3], marks[1])
- eq({marks[3], positions[3][1], positions[3][2]}, rv[1])
- eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
- eq({marks[1], positions[1][1], positions[1][2]}, rv[3])
+ eq({ marks[3], positions[3][1], positions[3][2] }, rv[1])
+ eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
+ eq({ marks[1], positions[1][1], positions[1][2] }, rv[3])
-- prevrange with limit
- rv = get_extmarks(ns, marks[3], marks[1], {limit=2})
+ rv = get_extmarks(ns, marks[3], marks[1], { limit = 2 })
eq(2, #rv)
-- prevrange with positional when mark exists at position
rv = get_extmarks(ns, positions[3], positions[1])
- eq({{marks[3], positions[3][1], positions[3][2]},
- {marks[2], positions[2][1], positions[2][2]},
- {marks[1], positions[1][1], positions[1][2]}}, rv)
+ eq({
+ { marks[3], positions[3][1], positions[3][2] },
+ { marks[2], positions[2][1], positions[2][2] },
+ { marks[1], positions[1][1], positions[1][2] },
+ }, rv)
rv = get_extmarks(ns, positions[2], positions[1])
eq(2, #rv)
-- prevrange with positional index (no mark at position)
- lower = {positions[2][1], positions[2][2] + 1}
- upper = {positions[3][1], positions[3][2] + 1}
+ lower = { positions[2][1], positions[2][2] + 1 }
+ upper = { positions[3][1], positions[3][2] + 1 }
rv = get_extmarks(ns, upper, lower)
- eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
- lower = {positions[3][1], positions[3][2] + 1}
- upper = {positions[3][1], positions[3][2] + 2}
+ eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
+ lower = { positions[3][1], positions[3][2] + 1 }
+ upper = { positions[3][1], positions[3][2] + 2 }
rv = get_extmarks(ns, upper, lower)
eq({}, rv)
-- prevrange with extremity index
- lower = {0,0}
- upper = {positions[2][1], positions[2][2] - 1}
+ lower = { 0, 0 }
+ upper = { positions[2][1], positions[2][2] - 1 }
rv = get_extmarks(ns, upper, lower)
- eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
+ eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
end)
it('querying for information with limit', function()
@@ -354,34 +383,34 @@ describe('API/extmarks', function()
end
end
- local rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
+ local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
eq(1, #rv)
- rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
eq(2, #rv)
- rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
eq(3, #rv)
-- now in reverse
- rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
eq(1, #rv)
- rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
eq(2, #rv)
- rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
eq(3, #rv)
end)
it('get_marks works when mark col > upper col', function()
feed('A<cr>12345<esc>')
feed('A<cr>12345<esc>')
- set_extmark(ns, 10, 0, 2) -- this shouldn't be found
- set_extmark(ns, 11, 2, 1) -- this shouldn't be found
+ set_extmark(ns, 10, 0, 2) -- this shouldn't be found
+ set_extmark(ns, 11, 2, 1) -- this shouldn't be found
set_extmark(ns, marks[1], 0, 4) -- check col > our upper bound
set_extmark(ns, marks[2], 1, 1) -- check col < lower bound
set_extmark(ns, marks[3], 2, 0) -- check is inclusive
- eq({{marks[1], 0, 4},
- {marks[2], 1, 1},
- {marks[3], 2, 0}},
- get_extmarks(ns, {0, 3}, {2, 0}))
+ eq(
+ { { marks[1], 0, 4 }, { marks[2], 1, 1 }, { marks[3], 2, 0 } },
+ get_extmarks(ns, { 0, 3 }, { 2, 0 })
+ )
end)
it('get_marks works in reverse when mark col < lower col', function()
@@ -392,28 +421,24 @@ describe('API/extmarks', function()
set_extmark(ns, marks[1], 2, 1) -- check col < our lower bound
set_extmark(ns, marks[2], 1, 4) -- check col > upper bound
set_extmark(ns, marks[3], 0, 2) -- check is inclusive
- local rv = get_extmarks(ns, {2, 3}, {0, 2})
- eq({{marks[1], 2, 1},
- {marks[2], 1, 4},
- {marks[3], 0, 2}},
- rv)
+ local rv = get_extmarks(ns, { 2, 3 }, { 0, 2 })
+ eq({ { marks[1], 2, 1 }, { marks[2], 1, 4 }, { marks[3], 0, 2 } }, rv)
end)
it('get_marks limit=0 returns nothing', function()
set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- local rv = get_extmarks(ns, {-1, -1}, {-1, -1}, {limit=0})
+ local rv = get_extmarks(ns, { -1, -1 }, { -1, -1 }, { limit = 0 })
eq({}, rv)
end)
-
it('marks move with line insertations', function()
set_extmark(ns, marks[1], 0, 0)
- feed("yyP")
+ feed('yyP')
check_undo_redo(ns, marks[1], 0, 0, 1, 0)
end)
it('marks move with multiline insertations', function()
- feed("a<cr>22<cr>33<esc>")
+ feed('a<cr>22<cr>33<esc>')
set_extmark(ns, marks[1], 1, 1)
feed('ggVGyP')
check_undo_redo(ns, marks[1], 1, 1, 4, 1)
@@ -421,7 +446,7 @@ describe('API/extmarks', function()
it('marks move with line join', function()
-- do_join in ops.c
- feed("a<cr>222<esc>")
+ feed('a<cr>222<esc>')
set_extmark(ns, marks[1], 1, 0)
feed('ggJ')
check_undo_redo(ns, marks[1], 1, 0, 0, 6)
@@ -430,40 +455,33 @@ describe('API/extmarks', function()
it('join works when no marks are present', function()
screen = Screen.new(15, 10)
screen:attach()
- feed("a<cr>1<esc>")
+ feed('a<cr>1<esc>')
feed('kJ')
-- This shouldn't seg fault
screen:expect([[
12345^ 1 |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ ~ |*8
|
]])
end)
it('marks move with multiline join', function()
-- do_join in ops.c
- feed("a<cr>222<cr>333<cr>444<esc>")
+ feed('a<cr>222<cr>333<cr>444<esc>')
set_extmark(ns, marks[1], 3, 0)
feed('2GVGJ')
check_undo_redo(ns, marks[1], 3, 0, 1, 8)
end)
it('marks move with line deletes', function()
- feed("a<cr>222<cr>333<cr>444<esc>")
+ feed('a<cr>222<cr>333<cr>444<esc>')
set_extmark(ns, marks[1], 2, 1)
feed('ggjdd')
check_undo_redo(ns, marks[1], 2, 1, 1, 1)
end)
it('marks move with multiline deletes', function()
- feed("a<cr>222<cr>333<cr>444<esc>")
+ feed('a<cr>222<cr>333<cr>444<esc>')
set_extmark(ns, marks[1], 3, 0)
feed('gg2dd')
check_undo_redo(ns, marks[1], 3, 0, 1, 0)
@@ -475,7 +493,7 @@ describe('API/extmarks', function()
it('marks move with open line', function()
-- open_line in change.c
-- testing marks below are also moved
- feed("yyP")
+ feed('yyP')
set_extmark(ns, marks[1], 0, 4)
set_extmark(ns, marks[2], 1, 4)
feed('1G<s-o><esc>')
@@ -495,18 +513,11 @@ describe('API/extmarks', function()
insert('abc')
screen:expect([[
ab^c12345 |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ ~ |*8
|
]])
local rv = get_extmark_by_id(ns, marks[1])
- eq({0, 6}, rv)
+ eq({ 0, 6 }, rv)
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
end)
@@ -515,12 +526,12 @@ describe('API/extmarks', function()
-- insertchar in edit.c (the ins_str branch)
set_extmark(ns, marks[1], 0, 2)
feed('03l')
- insert("X")
+ insert('X')
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
-- check multibyte chars
feed('03l<esc>')
- insert("~~")
+ insert('~~')
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
end)
@@ -544,7 +555,7 @@ describe('API/extmarks', function()
it('marks move with line splits (using enter)', function()
-- open_line in change.c
-- testing marks below are also moved
- feed("yyP")
+ feed('yyP')
set_extmark(ns, marks[1], 0, 4)
set_extmark(ns, marks[2], 1, 4)
feed('1Gla<cr><esc>')
@@ -561,16 +572,16 @@ describe('API/extmarks', function()
it('yet again marks move with line splits', function()
-- the first test above wasn't catching all errors..
- feed("A67890<esc>")
+ feed('A67890<esc>')
set_extmark(ns, marks[1], 0, 4)
- feed("04li<cr><esc>")
+ feed('04li<cr><esc>')
check_undo_redo(ns, marks[1], 0, 4, 1, 0)
end)
it('and one last time line splits...', function()
set_extmark(ns, marks[1], 0, 1)
set_extmark(ns, marks[2], 0, 2)
- feed("02li<cr><esc>")
+ feed('02li<cr><esc>')
check_undo_redo(ns, marks[1], 0, 1, 0, 1)
check_undo_redo(ns, marks[2], 0, 2, 1, 0)
end)
@@ -578,7 +589,7 @@ describe('API/extmarks', function()
it('multiple marks move with mark splits', function()
set_extmark(ns, marks[1], 0, 1)
set_extmark(ns, marks[2], 0, 3)
- feed("0li<cr><esc>")
+ feed('0li<cr><esc>')
check_undo_redo(ns, marks[1], 0, 1, 1, 0)
check_undo_redo(ns, marks[2], 0, 3, 1, 2)
end)
@@ -670,11 +681,11 @@ describe('API/extmarks', function()
feed('0vx<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 2)
- feed("u")
+ feed('u')
feed('0vlx<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
- feed("u")
+ feed('u')
feed('0v2lx<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 0)
@@ -689,16 +700,16 @@ describe('API/extmarks', function()
feed('0x<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 2)
- feed("u")
+ feed('u')
feed('02x<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
- feed("u")
+ feed('u')
feed('0v3lx<esc>')
check_undo_redo(ns, marks[1], 0, 3, 0, 0)
-- from the other side (nothing should happen)
- feed("u")
+ feed('u')
feed('$vx')
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
end)
@@ -756,27 +767,44 @@ describe('API/extmarks', function()
it('delete', function()
local pos1 = {
- {2, 4}, {2, 12}, {2, 13}, {2, 14}, {2, 25},
- {4, 8}, {4, 10}, {4, 20},
- {5, 3}, {6, 10}
+ { 2, 4 },
+ { 2, 12 },
+ { 2, 13 },
+ { 2, 14 },
+ { 2, 25 },
+ { 4, 8 },
+ { 4, 10 },
+ { 4, 20 },
+ { 5, 3 },
+ { 6, 10 },
}
local ids = batch_set(ns, pos1)
batch_check(ns, ids, pos1)
feed('3Gfiv2+ftd')
batch_check_undo_redo(ns, ids, pos1, {
- {2, 4}, {2, 12}, {2, 13}, {2, 13}, {2, 13},
- {2, 13}, {2, 15}, {2, 25},
- {3, 3}, {4, 10}
+ { 2, 4 },
+ { 2, 12 },
+ { 2, 13 },
+ { 2, 13 },
+ { 2, 13 },
+ { 2, 13 },
+ { 2, 15 },
+ { 2, 25 },
+ { 3, 3 },
+ { 4, 10 },
})
end)
it('can get overlapping extmarks', function()
- set_extmark(ns, 1, 0, 0, {end_row = 5, end_col=0})
- set_extmark(ns, 2, 2, 5, {end_row = 2, end_col=30})
- set_extmark(ns, 3, 0, 5, {end_row = 2, end_col=10})
- set_extmark(ns, 4, 0, 0, {end_row = 1, end_col=0})
- eq({{ 2, 2, 5 }}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=false }))
- eq({{ 1, 0, 0 }, { 3, 0, 5}, {2, 2, 5}}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=true }))
+ set_extmark(ns, 1, 0, 0, { end_row = 5, end_col = 0 })
+ set_extmark(ns, 2, 2, 5, { end_row = 2, end_col = 30 })
+ set_extmark(ns, 3, 0, 5, { end_row = 2, end_col = 10 })
+ set_extmark(ns, 4, 0, 0, { end_row = 1, end_col = 0 })
+ eq({ { 2, 2, 5 } }, get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = false }))
+ eq(
+ { { 1, 0, 0 }, { 3, 0, 5 }, { 2, 2, 5 } },
+ get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = true })
+ )
end)
end)
@@ -876,33 +904,40 @@ describe('API/extmarks', function()
set_extmark(ns, marks[2], 0, -1)
set_extmark(ns, marks[3], 0, -1)
- feed("u")
- local rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ feed('u')
+ local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(3, #rv)
- feed("<c-r>")
- rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ feed('<c-r>')
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(3, #rv)
-- Test updates
feed('o<esc>')
set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- rv = get_extmarks(ns, marks[1], marks[1], {limit=1})
+ rv = get_extmarks(ns, marks[1], marks[1], { limit = 1 })
eq(1, #rv)
- feed("u")
- feed("<c-r>")
+ feed('u')
+ feed('<c-r>')
-- old value is NOT kept in history
- check_undo_redo(ns, marks[1], positions[1][1], positions[1][2], positions[1][1], positions[1][2])
+ check_undo_redo(
+ ns,
+ marks[1],
+ positions[1][1],
+ positions[1][2],
+ positions[1][1],
+ positions[1][2]
+ )
-- Test unset
feed('o<esc>')
- curbufmeths.del_extmark(ns, marks[3])
- feed("u")
- rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ api.nvim_buf_del_extmark(0, ns, marks[3])
+ feed('u')
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
-- undo does NOT restore deleted marks
eq(2, #rv)
- feed("<c-r>")
- rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ feed('<c-r>')
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(2, #rv)
end)
@@ -919,9 +954,9 @@ describe('API/extmarks', function()
eq(1, rv)
rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2])
eq(1, rv)
- rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(1, #rv)
- rv = get_extmarks(ns2, {0, 0}, {-1, -1})
+ rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
eq(1, #rv)
-- Set more marks for testing the ranges
@@ -931,14 +966,14 @@ describe('API/extmarks', function()
set_extmark(ns2, marks[3], positions[3][1], positions[3][2])
-- get_next (limit set)
- rv = get_extmarks(ns, {0, 0}, positions[2], {limit=1})
+ rv = get_extmarks(ns, { 0, 0 }, positions[2], { limit = 1 })
eq(1, #rv)
- rv = get_extmarks(ns2, {0, 0}, positions[2], {limit=1})
+ rv = get_extmarks(ns2, { 0, 0 }, positions[2], { limit = 1 })
eq(1, #rv)
-- get_prev (limit set)
- rv = get_extmarks(ns, positions[1], {0, 0}, {limit=1})
+ rv = get_extmarks(ns, positions[1], { 0, 0 }, { limit = 1 })
eq(1, #rv)
- rv = get_extmarks(ns2, positions[1], {0, 0}, {limit=1})
+ rv = get_extmarks(ns2, positions[1], { 0, 0 }, { limit = 1 })
eq(1, #rv)
-- get_next (no limit)
@@ -952,11 +987,11 @@ describe('API/extmarks', function()
rv = get_extmarks(ns2, positions[2], positions[1])
eq(2, #rv)
- curbufmeths.del_extmark(ns, marks[1])
- rv = get_extmarks(ns, {0, 0}, {-1, -1})
+ api.nvim_buf_del_extmark(0, ns, marks[1])
+ rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(2, #rv)
- curbufmeths.del_extmark(ns2, marks[1])
- rv = get_extmarks(ns2, {0, 0}, {-1, -1})
+ api.nvim_buf_del_extmark(0, ns2, marks[1])
+ rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
eq(2, #rv)
end)
@@ -980,16 +1015,16 @@ describe('API/extmarks', function()
feed(':set cindent<cr><esc>')
feed(':set autoindent<cr><esc>')
feed(':set shiftwidth=2<cr><esc>')
- feed("0iint <esc>A {1M1<esc>b<esc>")
+ feed('0iint <esc>A {1M1<esc>b<esc>')
-- Set the mark on the M, should move..
set_extmark(ns, marks[1], 0, 12)
-- Set the mark before the cursor, should stay there
set_extmark(ns, marks[2], 0, 10)
- feed("i<cr><esc>")
+ feed('i<cr><esc>')
local rv = get_extmark_by_id(ns, marks[1])
- eq({1, 3}, rv)
+ eq({ 1, 3 }, rv)
rv = get_extmark_by_id(ns, marks[2])
- eq({0, 10}, rv)
+ eq({ 0, 10 }, rv)
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
end)
@@ -998,39 +1033,39 @@ describe('API/extmarks', function()
feed(':set autoindent<cr><esc>')
feed(':set shiftwidth=2<cr><esc>')
-- <c-f> will force an indent of 2
- feed("0iint <esc>A {<cr><esc>0i1M1<esc>")
+ feed('0iint <esc>A {<cr><esc>0i1M1<esc>')
set_extmark(ns, marks[1], 1, 1)
- feed("0i<c-f><esc>")
+ feed('0i<c-f><esc>')
local rv = get_extmark_by_id(ns, marks[1])
- eq({1, 3}, rv)
+ eq({ 1, 3 }, rv)
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
-- now check when cursor at eol
- feed("uA<c-f><esc>")
+ feed('uA<c-f><esc>')
rv = get_extmark_by_id(ns, marks[1])
- eq({1, 3}, rv)
+ eq({ 1, 3 }, rv)
end)
it('removing auto indenting with <C-D> works', function()
feed(':set cindent<cr><esc>')
feed(':set autoindent<cr><esc>')
feed(':set shiftwidth=2<cr><esc>')
- feed("0i<tab><esc>")
+ feed('0i<tab><esc>')
set_extmark(ns, marks[1], 0, 3)
- feed("bi<c-d><esc>")
+ feed('bi<c-d><esc>')