2017-01-18 05:20:07 -07:00
|
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
|
|
|
|
|
local request = helpers.request
|
|
|
|
|
local eq = helpers.eq
|
|
|
|
|
local ok = helpers.ok
|
|
|
|
|
local curbufmeths = helpers.curbufmeths
|
2019-11-25 08:50:30 -07:00
|
|
|
|
local bufmeths = helpers.bufmeths
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local pcall_err = helpers.pcall_err
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local insert = helpers.insert
|
|
|
|
|
local feed = helpers.feed
|
|
|
|
|
local clear = helpers.clear
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local command = helpers.command
|
2020-01-14 04:45:09 -07:00
|
|
|
|
local meths = helpers.meths
|
|
|
|
|
|
|
|
|
|
local function expect(contents)
|
|
|
|
|
return eq(contents, helpers.curbuf_contents())
|
|
|
|
|
end
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local function set_extmark(ns_id, id, line, col, opts)
|
|
|
|
|
if opts == nil then
|
|
|
|
|
opts = {}
|
|
|
|
|
end
|
2020-01-21 06:01:40 -07:00
|
|
|
|
if id ~= nil and id ~= 0 then
|
|
|
|
|
opts.id = id
|
|
|
|
|
end
|
|
|
|
|
return curbufmeths.set_extmark(ns_id, line, col, opts)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function get_extmarks(ns_id, start, end_, opts)
|
|
|
|
|
if opts == nil then
|
|
|
|
|
opts = {}
|
|
|
|
|
end
|
2020-09-04 10:11:26 -07:00
|
|
|
|
return curbufmeths.get_extmarks(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)
|
|
|
|
|
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")
|
|
|
|
|
rv = get_extmark_by_id(ns, mark)
|
|
|
|
|
eq({sr, sc}, rv)
|
|
|
|
|
feed("<c-r>")
|
|
|
|
|
rv = get_extmark_by_id(ns, mark)
|
|
|
|
|
eq({er, ec}, rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
end
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
local function batch_set(ns_id, positions)
|
|
|
|
|
local ids = {}
|
|
|
|
|
for _, pos in ipairs(positions) do
|
|
|
|
|
table.insert(ids, set_extmark(ns_id, 0, pos[1], pos[2]))
|
|
|
|
|
end
|
|
|
|
|
return ids
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function batch_check(ns_id, ids, positions)
|
|
|
|
|
local actual, expected = {}, {}
|
|
|
|
|
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]}
|
|
|
|
|
end
|
|
|
|
|
eq(expected, actual)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function batch_check_undo_redo(ns_id, ids, before, after)
|
|
|
|
|
batch_check(ns_id, ids, after)
|
|
|
|
|
feed("u")
|
|
|
|
|
batch_check(ns_id, ids, before)
|
|
|
|
|
feed("<c-r>")
|
|
|
|
|
batch_check(ns_id, ids, after)
|
|
|
|
|
end
|
|
|
|
|
|
2019-11-25 02:08:02 -07:00
|
|
|
|
describe('API/extmarks', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local screen
|
2020-01-14 04:45:09 -07:00
|
|
|
|
local marks, positions, init_text, row, col
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local ns, ns2
|
|
|
|
|
|
|
|
|
|
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}}
|
|
|
|
|
|
|
|
|
|
init_text = "12345"
|
|
|
|
|
row = 0
|
|
|
|
|
col = 2
|
|
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
|
|
insert(init_text)
|
2020-01-14 04:45:09 -07:00
|
|
|
|
ns = request('nvim_create_namespace', "my-fancy-plugin")
|
|
|
|
|
ns2 = request('nvim_create_namespace', "my-fancy-plugin2")
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-09-08 05:14:15 -07:00
|
|
|
|
it("can end extranges past final newline using end_col = 0", function()
|
|
|
|
|
set_extmark(ns, marks[1], 0, 0, {
|
|
|
|
|
end_col = 0,
|
|
|
|
|
end_line = 1
|
|
|
|
|
})
|
|
|
|
|
eq("end_col value outside range",
|
|
|
|
|
pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_line = 1 }))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('adds, updates and deletes marks', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(marks[1], rv)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({positions[1][1], positions[1][2]}, rv)
|
|
|
|
|
-- Test adding a second mark on same row works
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(marks[2], rv)
|
|
|
|
|
|
|
|
|
|
-- Test an update, (same pos)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
|
|
|
|
eq(marks[1], rv)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({positions[2][1], positions[2][2]}, rv)
|
|
|
|
|
-- Test an update, (new pos)
|
|
|
|
|
row = positions[1][1]
|
|
|
|
|
col = positions[1][2] + 1
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = set_extmark(ns, marks[1], row, col)
|
|
|
|
|
eq(marks[1], rv)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('can clear a specific namespace range', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, 1, 0, 1)
|
|
|
|
|
set_extmark(ns2, 1, 0, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- force a new undo buffer
|
|
|
|
|
feed('o<esc>')
|
|
|
|
|
curbufmeths.clear_namespace(ns2, 0, -1)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('u')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
2020-01-14 04:45:09 -07:00
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-r>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({{1, 0, 1}}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('can clear a namespace range using 0,-1', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, 1, 0, 1)
|
|
|
|
|
set_extmark(ns2, 1, 0, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- force a new undo buffer
|
|
|
|
|
feed('o<esc>')
|
|
|
|
|
curbufmeths.clear_namespace(-1, 0, -1)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('u')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-r>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({}, get_extmarks(ns, {0, 0}, {-1, -1}))
|
|
|
|
|
eq({}, get_extmarks(ns2, {0, 0}, {-1, -1}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('querying for information and ranges', function()
|
|
|
|
|
--marks = {1, 2, 3}
|
|
|
|
|
--positions = {{0, 0,}, {0, 2}, {0, 3}}
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- add some more marks
|
|
|
|
|
for i, m in ipairs(marks) do
|
|
|
|
|
if positions[i] ~= nil then
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(m, rv)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- {0, 0} and {-1, -1} work as extreme values
|
2019-11-09 04:41:50 -07:00
|
|
|
|
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})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
for i, m in ipairs(marks) do
|
|
|
|
|
if positions[i] ~= nil then
|
|
|
|
|
eq({m, positions[i][1], positions[i][2]}, rv[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 0 and -1 works as short hand extreme values
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({{1, 0, 0}}, get_extmarks(ns, 0, 0))
|
|
|
|
|
eq({}, get_extmarks(ns, -1, -1))
|
|
|
|
|
rv = get_extmarks(ns, 0, -1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
for i, m in ipairs(marks) do
|
|
|
|
|
if positions[i] ~= nil then
|
|
|
|
|
eq({m, positions[i][1], positions[i][2]}, rv[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- next with mark id
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[1], {-1, -1}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[2], {-1, -1}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
|
|
|
|
|
-- next with positional when mark exists at position
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[1], {-1, -1}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
|
|
|
|
|
-- next with positional index (no mark at position)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {-1, -1}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
|
|
|
|
|
-- next with Extremity index
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0,0}, {-1, -1}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
|
|
|
|
|
|
|
|
|
|
-- nextrange with mark id
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[1], marks[3])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({marks[1], positions[1][1], positions[1][2]}, rv[1])
|
|
|
|
|
eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- nextrange with `limit`
|
|
|
|
|
rv = get_extmarks(ns, marks[1], marks[3], {limit=2})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- nextrange with positional when mark exists at position
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[1], positions[3])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({marks[1], positions[1][1], positions[1][2]}, rv[1])
|
|
|
|
|
eq({marks[2], positions[2][1], positions[2][2]}, rv[2])
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[2], positions[3])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- 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}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, lower, upper)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, lower, upper)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({}, rv)
|
|
|
|
|
-- nextrange with extremity index
|
|
|
|
|
lower = {positions[2][1], positions[2][2]+1}
|
|
|
|
|
upper = {-1, -1}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, lower, upper)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
|
|
|
|
|
|
|
|
|
|
-- prev with mark id
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[3], {0, 0}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[2], {0, 0}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[2], positions[2][1], positions[2][2]}}, rv)
|
|
|
|
|
-- prev with positional when mark exists at position
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[3], {0, 0}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
|
|
|
|
|
-- prev with positional index (no mark at position)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {positions[1][1], positions[1][2] +1}, {0, 0}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
|
|
|
|
|
-- prev with Extremity index
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {-1,-1}, {0,0}, {limit=1})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[3], positions[3][1], positions[3][2]}}, rv)
|
|
|
|
|
|
|
|
|
|
-- prevrange with mark id
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[3], marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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])
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- prevrange with limit
|
|
|
|
|
rv = get_extmarks(ns, marks[3], marks[1], {limit=2})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- prevrange with positional when mark exists at position
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[3], positions[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[2], positions[1])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- prevrange with positional index (no mark at position)
|
|
|
|
|
lower = {positions[2][1], positions[2][2] + 1}
|
|
|
|
|
upper = {positions[3][1], positions[3][2] + 1}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, upper, lower)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, upper, lower)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({}, rv)
|
|
|
|
|
-- prevrange with extremity index
|
|
|
|
|
lower = {0,0}
|
|
|
|
|
upper = {positions[2][1], positions[2][2] - 1}
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, upper, lower)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], positions[1][1], positions[1][2]}}, rv)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('querying for information with limit', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- add some more marks
|
|
|
|
|
for i, m in ipairs(marks) do
|
|
|
|
|
if positions[i] ~= nil then
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(m, rv)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-11-25 02:08:02 -07:00
|
|
|
|
local rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(3, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
-- now in reverse
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=2})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1}, {limit=3})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(3, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('get_marks works when mark col > upper col', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>12345<esc>')
|
|
|
|
|
feed('A<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
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
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], 0, 4},
|
|
|
|
|
{marks[2], 1, 1},
|
|
|
|
|
{marks[3], 2, 0}},
|
2019-11-09 04:41:50 -07:00
|
|
|
|
get_extmarks(ns, {0, 3}, {2, 0}))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('get_marks works in reverse when mark col < lower col', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>12345<esc>')
|
|
|
|
|
feed('A<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, 10, 0, 1) -- this shouldn't be found
|
|
|
|
|
set_extmark(ns, 11, 2, 4) -- this shouldn't be found
|
|
|
|
|
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})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({{marks[1], 2, 1},
|
|
|
|
|
{marks[2], 1, 4},
|
|
|
|
|
{marks[3], 0, 2}},
|
|
|
|
|
rv)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('get_marks limit=0 returns nothing', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
2019-11-25 02:08:02 -07:00
|
|
|
|
local rv = get_extmarks(ns, {-1, -1}, {-1, -1}, {limit=0})
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({}, rv)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with line insertations', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("yyP")
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 1, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with multiline insertations', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("a<cr>22<cr>33<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ggVGyP')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 1, 4, 1)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with line join', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_join in ops.c
|
|
|
|
|
feed("a<cr>222<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ggJ')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 0, 0, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('join works when no marks are present', function()
|
|
|
|
|
screen = Screen.new(15, 10)
|
|
|
|
|
screen:attach()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("a<cr>1<esc>")
|
|
|
|
|
feed('kJ')
|
|
|
|
|
-- This shouldn't seg fault
|
|
|
|
|
screen:expect([[
|
|
|
|
|
12345^ 1 |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with multiline join', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_join in ops.c
|
|
|
|
|
feed("a<cr>222<cr>333<cr>444<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 3, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('2GVGJ')
|
|
|
|
|
check_undo_redo(ns, marks[1], 3, 0, 1, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with line deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("a<cr>222<cr>333<cr>444<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 2, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ggjdd')
|
|
|
|
|
check_undo_redo(ns, marks[1], 2, 1, 1, 1)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with multiline deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("a<cr>222<cr>333<cr>444<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 3, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('gg2dd')
|
|
|
|
|
check_undo_redo(ns, marks[1], 3, 0, 1, 0)
|
|
|
|
|
-- regression test, undoing multiline delete when mark is on row 1
|
|
|
|
|
feed('ugg3dd')
|
|
|
|
|
check_undo_redo(ns, marks[1], 3, 0, 0, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with open line', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- open_line in misc1.c
|
|
|
|
|
-- testing marks below are also moved
|
|
|
|
|
feed("yyP")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[2], 1, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('1G<s-o><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 1, 4)
|
|
|
|
|
check_undo_redo(ns, marks[2], 1, 4, 2, 4)
|
|
|
|
|
feed('2Go<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 4, 1, 4)
|
|
|
|
|
check_undo_redo(ns, marks[2], 2, 4, 3, 4)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with char inserts', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- insertchar in edit.c (the ins_str branch)
|
2020-01-14 04:45:09 -07:00
|
|
|
|
screen = Screen.new(15, 10)
|
|
|
|
|
screen:attach()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0')
|
|
|
|
|
insert('abc')
|
|
|
|
|
screen:expect([[
|
|
|
|
|
ab^c12345 |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
|
|
]])
|
2020-09-04 10:11:26 -07:00
|
|
|
|
local rv = get_extmark_by_id(ns, marks[1])
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq({0, 6}, rv)
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- gravity right as definted in tk library
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks have gravity right', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- insertchar in edit.c (the ins_str branch)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('03l')
|
|
|
|
|
insert("X")
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
|
|
|
|
|
-- check multibyte chars
|
|
|
|
|
feed('03l<esc>')
|
|
|
|
|
insert("~~")
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('we can insert multibyte chars', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- insertchar in edit.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- Insert a fullwidth (two col) tilde, NICE
|
|
|
|
|
feed('0i~<esc>')
|
2019-11-14 12:24:17 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 1, 2, 1, 5)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with blockwise inserts', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_insert in ops.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0<c-v>lkI9<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 2, 1, 3)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with line splits (using enter)', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- open_line in misc1.c
|
|
|
|
|
-- testing marks below are also moved
|
|
|
|
|
feed("yyP")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[2], 1, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('1Gla<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 1, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 1, 4, 2, 4)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks at last line move on insert new line', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- open_line in misc1.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0i<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 1, 4)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('yet again marks move with line splits', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- the first test above wasn't catching all errors..
|
|
|
|
|
feed("A67890<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("04li<cr><esc>")
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 1, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('and one last time line splits...', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('multiple marks move with mark splits', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('deleting right before a mark works', function()
|
2019-11-14 12:06:13 -07:00
|
|
|
|
-- op_delete in ops.c
|
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
feed('0lx')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 1)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('deleting right after a mark works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('02lx')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with char deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('02dl')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 0)
|
|
|
|
|
-- from the other side (nothing should happen)
|
|
|
|
|
feed('$x')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 0, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with char deletes over a range', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0l3dl<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 1)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 1)
|
2019-11-26 05:15:14 -07:00
|
|
|
|
-- delete 1, nothing should happen to our marks
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('u')
|
|
|
|
|
feed('$x')
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 3)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('deleting marks at end of line works', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('$x')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 4)
|
|
|
|
|
-- check the copy happened correctly on delete at eol
|
|
|
|
|
feed('$x')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 3)
|
|
|
|
|
feed('u')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 4)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with blockwise deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('h<c-v>hhkd')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 4, 1, 1)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with blockwise deletes over a range', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0<c-v>k3lx')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 1, 0, 0)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 2, 1, 0)
|
2019-11-26 05:15:14 -07:00
|
|
|
|
-- delete 1, nothing should happen to our marks
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('u')
|
|
|
|
|
feed('$<c-v>jx')
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 2, 1, 2)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('works with char deletes over multilines', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('a<cr>12345<cr>test-me<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 2, 5)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('gg')
|
|
|
|
|
feed('dv?-m?<cr>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 2, 5, 0, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks outside of deleted range move with visual char deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0vx<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 2)
|
|
|
|
|
|
|
|
|
|
feed("u")
|
|
|
|
|
feed('0vlx<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
|
|
|
|
|
|
|
|
|
|
feed("u")
|
|
|
|
|
feed('0v2lx<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 0)
|
|
|
|
|
|
|
|
|
|
-- from the other side (nothing should happen)
|
|
|
|
|
feed('$vx')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 0, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks outside of deleted range move with char deletes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_delete in ops.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0x<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 2)
|
|
|
|
|
|
|
|
|
|
feed("u")
|
|
|
|
|
feed('02x<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
|
|
|
|
|
|
|
|
|
|
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('$vx')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with P(backward) paste', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_put in ops.c
|
|
|
|
|
feed('0iabc<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0veyP')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 7, 0, 15)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with p(forward) paste', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_put in ops.c
|
|
|
|
|
feed('0iabc<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0veyp')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 0, 7, 0, 15)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with blockwise P(backward) paste', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_put in ops.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-v>hhkyP<esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 4, 1, 7)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move with blockwise p(forward) paste', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_put in ops.c
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-v>hhkyp<esc>')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 1, 4, 1, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
describe('multiline regions', function()
|
|
|
|
|
before_each(function()
|
|
|
|
|
feed('dd')
|
|
|
|
|
-- Achtung: code has been spiced with some unicode,
|
|
|
|
|
-- to make life more interesting.
|
|
|
|
|
-- luacheck whines about TABs inside strings for whatever reason.
|
|
|
|
|
-- luacheck: push ignore 621
|
|
|
|
|
insert([[
|
|
|
|
|
static int nlua_rpcrequest(lua_State *lstate)
|
|
|
|
|
{
|
|
|
|
|
Ïf (!nlua_is_deferred_safe(lstate)) {
|
|
|
|
|
// strictly not allowed
|
|
|
|
|
Яetörn luaL_error(lstate, e_luv_api_disabled, "rpcrequest");
|
|
|
|
|
}
|
|
|
|
|
return nlua_rpc(lstate, true);
|
|
|
|
|
}]])
|
|
|
|
|
-- luacheck: pop
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
|
})
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- TODO(bfredl): add more tests!
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('replace works', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0r2')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('blockwise replace works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0<c-v>llkr1<esc>')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('shift line', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- shift_line in ops.c
|
|
|
|
|
feed(':set shiftwidth=4<cr><esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0>>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 6)
|
2020-01-14 04:45:09 -07:00
|
|
|
|
expect(' 12345')
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
feed('>>')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
-- this is counter-intuitive. But what happens
|
|
|
|
|
-- is that 4 spaces gets extended to one tab (== 8 spaces)
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 6, 0, 3)
|
|
|
|
|
expect('\t12345')
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
feed('<LT><LT>') -- have to escape, same as <<
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('blockwise shift', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- shift_block in ops.c
|
|
|
|
|
feed(':set shiftwidth=4<cr><esc>')
|
|
|
|
|
feed('a<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0<c-v>k>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 2, 1, 6)
|
|
|
|
|
feed('<c-v>j>')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
expect('\t12345\n\t12345')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 6, 1, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
feed('<c-v>j<LT>')
|
2020-01-14 04:45:09 -07:00
|
|
|
|
check_undo_redo(ns, marks[1], 1, 3, 1, 6)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('tab works with expandtab', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- ins_tab in edit.c
|
|
|
|
|
feed(':set expandtab<cr><esc>')
|
|
|
|
|
feed(':set shiftwidth=2<cr><esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0i<tab><tab><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('tabs work', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- ins_tab in edit.c
|
|
|
|
|
feed(':set noexpandtab<cr><esc>')
|
|
|
|
|
feed(':set shiftwidth=2<cr><esc>')
|
|
|
|
|
feed(':set softtabstop=2<cr><esc>')
|
|
|
|
|
feed(':set tabstop=8<cr><esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('0i<tab><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 4)
|
|
|
|
|
feed('0iX<tab><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move when using :move', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>2<esc>:1move 2<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 1, 0)
|
|
|
|
|
-- test codepath when moving lines up
|
|
|
|
|
feed(':2move 0<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 0, 0, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('marks move when using :move part 2', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- make sure we didn't get lucky with the math...
|
|
|
|
|
feed('A<cr>2<cr>3<cr>4<cr>5<cr>6<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':2,3move 5<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 0, 3, 0)
|
|
|
|
|
-- test codepath when moving lines up
|
|
|
|
|
feed(':4,5move 1<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 3, 0, 1, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('undo and redo of set and unset marks', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- Force a new undo head
|
|
|
|
|
feed('o<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('o<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[2], 0, -1)
|
|
|
|
|
set_extmark(ns, marks[3], 0, -1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
feed("u")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(3, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
feed("<c-r>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(3, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
-- Test updates
|
|
|
|
|
feed('o<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns, marks[1], marks[1], {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("u")
|
|
|
|
|
feed("<c-r>")
|
2020-01-14 04:45:09 -07:00
|
|
|
|
-- 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])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
-- Test unset
|
|
|
|
|
feed('o<esc>')
|
|
|
|
|
curbufmeths.del_extmark(ns, marks[3])
|
|
|
|
|
feed("u")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-01-14 04:45:09 -07:00
|
|
|
|
-- undo does NOT restore deleted marks
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("<c-r>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('undo and redo of marks deleted during edits', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- test extmark_adjust
|
|
|
|
|
feed('A<cr>12345<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('dd')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 2, 1, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('namespaces work properly', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(1, rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(1, rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns2, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
-- Set more marks for testing the ranges
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[2], positions[2][1], positions[2][2])
|
|
|
|
|
set_extmark(ns, marks[3], positions[3][1], positions[3][2])
|
|
|
|
|
set_extmark(ns2, marks[2], positions[2][1], positions[2][2])
|
|
|
|
|
set_extmark(ns2, marks[3], positions[3][1], positions[3][2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- get_next (limit set)
|
|
|
|
|
rv = get_extmarks(ns, {0, 0}, positions[2], {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns2, {0, 0}, positions[2], {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- get_prev (limit set)
|
|
|
|
|
rv = get_extmarks(ns, positions[1], {0, 0}, {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
rv = get_extmarks(ns2, positions[1], {0, 0}, {limit=1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(1, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- get_next (no limit)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[1], positions[2])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns2, positions[1], positions[2])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- get_prev (no limit)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, positions[2], positions[1])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns2, positions[2], positions[1])
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
curbufmeths.del_extmark(ns, marks[1])
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
curbufmeths.del_extmark(ns2, marks[1])
|
2019-11-09 04:41:50 -07:00
|
|
|
|
rv = get_extmarks(ns2, {0, 0}, {-1, -1})
|
2020-07-30 22:33:42 -07:00
|
|
|
|
eq(2, #rv)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('mark set can create unique identifiers', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- create mark with id 1
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq(1, set_extmark(ns, 1, positions[1][1], positions[1][2]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- ask for unique id, it should be the next one, i e 2
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq(2, set_extmark(ns, 0, positions[1][1], positions[1][2]))
|
|
|
|
|
eq(3, set_extmark(ns, 3, positions[2][1], positions[2][2]))
|
|
|
|
|
eq(4, set_extmark(ns, 0, positions[1][1], positions[1][2]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
|
|
|
|
|
-- mixing manual and allocated id:s are not recommened, but it should
|
|
|
|
|
-- do something reasonable
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq(6, set_extmark(ns, 6, positions[2][1], positions[2][2]))
|
|
|
|
|
eq(7, set_extmark(ns, 0, positions[1][1], positions[1][2]))
|
|
|
|
|
eq(8, set_extmark(ns, 0, positions[1][1], positions[1][2]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('auto indenting with enter works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- op_reindent in ops.c
|
|
|
|
|
feed(':set cindent<cr><esc>')
|
|
|
|
|
feed(':set autoindent<cr><esc>')
|
|
|
|
|
feed(':set shiftwidth=2<cr><esc>')
|
|
|
|
|
feed("0iint <esc>A {1M1<esc>b<esc>")
|
|
|
|
|
-- Set the mark on the M, should move..
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 12)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- Set the mark before the cursor, should stay there
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[2], 0, 10)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("i<cr><esc>")
|
2020-09-04 10:11:26 -07:00
|
|
|
|
local rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({1, 3}, rv)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[2])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({0, 10}, rv)
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('auto indenting entire line works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':set cindent<cr><esc>')
|
|
|
|
|
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>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("0i<c-f><esc>")
|
2020-09-04 10:11:26 -07:00
|
|
|
|
local rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
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>")
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({1, 3}, rv)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('removing auto indenting with <C-D> works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':set cindent<cr><esc>')
|
|
|
|
|
feed(':set autoindent<cr><esc>')
|
|
|
|
|
feed(':set shiftwidth=2<cr><esc>')
|
|
|
|
|
feed("0i<tab><esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed("bi<c-d><esc>")
|
2020-09-04 10:11:26 -07:00
|
|
|
|
local rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({0, 1}, rv)
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
|
|
|
|
|
-- check when cursor at eol
|
|
|
|
|
feed("uA<c-d><esc>")
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({0, 1}, rv)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('indenting multiple lines with = works', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':set cindent<cr><esc>')
|
|
|
|
|
feed(':set autoindent<cr><esc>')
|
|
|
|
|
feed(':set shiftwidth=2<cr><esc>')
|
|
|
|
|
feed("0iint <esc>A {<cr><bs>1M1<cr><bs>2M2<esc>")
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 2, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('=gg')
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 2, 1, 2, 5)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitutes by deleting inside the replace matches', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_sub in ex_cmds.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':s/34/xx<cr>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 4)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 4)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitutes when insert text > deleted', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_sub in ex_cmds.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':s/34/xxx<cr>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 5)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 5)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitutes when marks around eol', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_sub in ex_cmds.c
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 5)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':s/5/xxx<cr>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 5, 0, 7)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitutes over range insert text > deleted', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_sub in ex_cmds.c
|
|
|
|
|
feed('A<cr>x34xx<esc>')
|
|
|
|
|
feed('A<cr>xxx34<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 1, 1)
|
|
|
|
|
set_extmark(ns, marks[3], 2, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':1,3s/34/xxx<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 5)
|
|
|
|
|
check_undo_redo(ns, marks[2], 1, 1, 1, 4)
|
|
|
|
|
check_undo_redo(ns, marks[3], 2, 4, 2, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitutes multiple matches in a line', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_sub in ex_cmds.c
|
|
|
|
|
feed('ddi3x3x3<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 0)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed(':s/3/yy/g<cr><esc>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 2, 0, 5)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 4, 0, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions over multiple lines with newline in pattern', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[5], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:5\n:5 <cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 0, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 5, 0, 11)
|
|
|
|
|
check_undo_redo(ns, marks[5], 2, 0, 1, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('inserting', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[5], 2, 0)
|
|
|
|
|
set_extmark(ns, marks[6], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:5\n67:X<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 0, 5)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 0, 0, 5)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 5, 0, 8)
|
|
|
|
|
check_undo_redo(ns, marks[5], 2, 0, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[6], 1, 2, 0, 5)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions with multiple newlines in pattern', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[3], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[5], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:\n.*\n:X<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 4, 0, 4)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 5, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 0, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 5, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[5], 2, 0, 0, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions over multiple lines with replace in substition', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[5], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:3:\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 1, 0, 1)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 2, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 4, 1, 1)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 0, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 2, 0, 3, 0)
|
|
|
|
|
feed('u')
|
|
|
|
|
feed([[:1,2s:3:\rxx<cr>]])
|
2020-09-04 10:11:26 -07:00
|
|
|
|
eq({1, 3}, get_extmark_by_id(ns, marks[3]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions over multiple lines with replace in substition', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>x3<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[2], 1, 1)
|
|
|
|
|
set_extmark(ns, marks[3], 1, 2)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:2,2s:3:\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 1, 0, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[2], 1, 1, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 1, 2, 2, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions over multiple lines with replace in substition', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>x3<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 1)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 1)
|
|
|
|
|
set_extmark(ns, marks[5], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:3:\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 1, 0, 1)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 2, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 4, 1, 1)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 1, 3, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 2, 0, 4, 0)
|
|
|
|
|
feed('u')
|
|
|
|
|
feed([[:1,2s:3:\rxx<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 4, 1, 3)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions with newline in match and sub, delta is 0', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[5], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[6], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,1s:5\n:\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 0, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 1, 5, 1, 5)
|
|
|
|
|
check_undo_redo(ns, marks[6], 2, 0, 2, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions with newline in match and sub, delta > 0', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[5], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[6], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,1s:5\n:\r\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 0, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 1, 5, 2, 5)
|
|
|
|
|
check_undo_redo(ns, marks[6], 2, 0, 3, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions with newline in match and sub, delta < 0', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[5], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[6], 2, 1)
|
|
|
|
|
set_extmark(ns, marks[7], 3, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,2s:5\n.*\n:\r<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 0, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 1, 5, 1, 0)
|
|
|
|
|
check_undo_redo(ns, marks[6], 2, 1, 1, 1)
|
|
|
|
|
check_undo_redo(ns, marks[7], 3, 0, 2, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions with backrefs, newline inserted into sub', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 4)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 1, 0)
|
|
|
|
|
set_extmark(ns, marks[5], 1, 5)
|
|
|
|
|
set_extmark(ns, marks[6], 2, 0)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,1s:5\(\n\):\0\1<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 3, 0, 3)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 4, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[4], 1, 0, 2, 0)
|
|
|
|
|
check_undo_redo(ns, marks[5], 1, 5, 2, 5)
|
|
|
|
|
check_undo_redo(ns, marks[6], 2, 0, 3, 0)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('substitions a ^', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 0)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:s:^:x<cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 0, 0, 1)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 1, 0, 2)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-a> without increase in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_addsub in ops.c
|
|
|
|
|
feed('ddiabc998xxx<esc>Tc')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-a>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 6, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 7, 0, 7)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-a> when increase in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_addsub in ops.c
|
|
|
|
|
feed('ddiabc999xxx<esc>Tc')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-a>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 6, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 7, 0, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-a> when negative and without decrease in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ddiabc-999xxx<esc>T-')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 7)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 8)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-a>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 6, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 7, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 8, 0, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-a> when negative and decrease in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ddiabc-1000xxx<esc>T-')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 7)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 8)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 9)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-a>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 7, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 8, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 9, 0, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-x> without decrease in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_addsub in ops.c
|
|
|
|
|
feed('ddiabc999xxx<esc>Tc')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 5)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 7)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-x>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 5, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 6, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 7, 0, 7)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-x> when decrease in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
-- do_addsub in ops.c
|
|
|
|
|
feed('ddiabc1000xxx<esc>Tc')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 7)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 8)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-x>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 6, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 7, 0, 6)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 8, 0, 7)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-x> when negative and without increase in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ddiabc-998xxx<esc>T-')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 7)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 8)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-x>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 6, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 7, 0, 7)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 8, 0, 8)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('using <c-x> when negative and increase in order of magnitude', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('ddiabc-999xxx<esc>T-')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, 2)
|
|
|
|
|
set_extmark(ns, marks[2], 0, 3)
|
|
|
|
|
set_extmark(ns, marks[3], 0, 6)
|
|
|
|
|
set_extmark(ns, marks[4], 0, 7)
|
|
|
|
|
set_extmark(ns, marks[5], 0, 8)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('<c-x>')
|
|
|
|
|
check_undo_redo(ns, marks[1], 0, 2, 0, 2)
|
|
|
|
|
check_undo_redo(ns, marks[2], 0, 3, 0, 8)
|
|
|
|
|
check_undo_redo(ns, marks[3], 0, 6, 0, 8)
|
|
|
|
|
check_undo_redo(ns, marks[4], 0, 7, 0, 8)
|
|
|
|
|
check_undo_redo(ns, marks[5], 0, 8, 0, 9)
|
|
|
|
|
end)
|
|
|
|
|
|
2019-11-09 04:41:50 -07:00
|
|
|
|
it('throws consistent error codes', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local ns_invalid = ns2 + 1
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
|
|
|
|
|
eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
|
|
|
|
|
eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
|
2020-09-04 10:11:26 -07:00
|
|
|
|
eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('when col = line-length, set the mark on eol', function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, -1)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
local rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({0, init_text:len()}, rv)
|
|
|
|
|
-- Test another
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 0, -1)
|
2020-09-04 10:11:26 -07:00
|
|
|
|
rv = get_extmark_by_id(ns, marks[1])
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq({0, init_text:len()}, rv)
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('when col = line-length, set the mark on eol', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local invalid_col = init_text:len() + 1
|
2019-11-09 04:41:50 -07:00
|
|
|
|
eq("col value outside range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('fails when line > line_count', function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local invalid_col = init_text:len() + 1
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local invalid_lnum = 3
|
|
|
|
|
eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
|
2020-09-04 10:11:26 -07:00
|
|
|
|
eq({}, get_extmark_by_id(ns, marks[1]))
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it('bug from check_col in extmark_set', function()
|
2019-11-25 02:08:02 -07:00
|
|
|
|
-- This bug was caused by extmark_set always using check_col. check_col
|
|
|
|
|
-- always uses the current buffer. This wasn't working during undo so we
|
|
|
|
|
-- now use check_col and check_lnum only when they are required.
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('A<cr>67890<cr>xx<esc>')
|
|
|
|
|
feed('A<cr>12345<cr>67890<cr>xx<esc>')
|
2019-11-09 04:41:50 -07:00
|
|
|
|
set_extmark(ns, marks[1], 3, 4)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed([[:1,5s:5\n:5 <cr>]])
|
|
|
|
|
check_undo_redo(ns, marks[1], 3, 4, 2, 6)
|
|
|
|
|
end)
|
|
|
|
|
|
2019-11-16 03:05:56 -07:00
|
|
|
|
it('in read-only buffer', function()
|
|
|
|
|
command("view! runtime/doc/help.txt")
|
|
|
|
|
eq(true, curbufmeths.get_option('ro'))
|
|
|
|
|
local id = set_extmark(ns, 0, 0, 2)
|
|
|
|
|
eq({{id, 0, 2}}, get_extmarks(ns,0, -1))
|
|
|
|
|
end)
|
2019-11-25 08:50:30 -07:00
|
|
|
|
|
|
|
|
|
it('can set a mark to other buffer', function()
|
|
|
|
|
local buf = request('nvim_create_buf', 0, 1)
|
|
|
|
|
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
|
2020-01-21 06:01:40 -07:00
|
|
|
|
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
|
2020-09-04 10:11:26 -07:00
|
|
|
|
eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
|
2019-11-25 08:50:30 -07:00
|
|
|
|
end)
|
2020-01-14 04:45:09 -07:00
|
|
|
|
|
|
|
|
|
it('does not crash with append/delete/undo seqence', function()
|
|
|
|
|
meths.exec([[
|
|
|
|
|
let ns = nvim_create_namespace('myplugin')
|
2020-01-21 06:01:40 -07:00
|
|
|
|
call nvim_buf_set_extmark(0, ns, 0, 0, {})
|
2020-01-14 04:45:09 -07:00
|
|
|
|
call append(0, '')
|
|
|
|
|
%delete
|
|
|
|
|
undo]],false)
|
|
|
|
|
eq(2, meths.eval('1+1')) -- did not crash
|
|
|
|
|
end)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
describe('Extmarks buffer api with many marks', function()
|
|
|
|
|
local ns1
|
|
|
|
|
local ns2
|
|
|
|
|
local ns_marks = {}
|
|
|
|
|
before_each(function()
|
|
|
|
|
clear()
|
|
|
|
|
ns1 = request('nvim_create_namespace', "ns1")
|
|
|
|
|
ns2 = request('nvim_create_namespace', "ns2")
|
|
|
|
|
ns_marks = {[ns1]={}, [ns2]={}}
|
|
|
|
|
local lines = {}
|
|
|
|
|
for i = 1,30 do
|
|
|
|
|
lines[#lines+1] = string.rep("x ",i)
|
|
|
|
|
end
|
|
|
|
|
curbufmeths.set_lines(0, -1, true, lines)
|
|
|
|
|
local ns = ns1
|
|
|
|
|
local q = 0
|
|
|
|
|
for i = 0,29 do
|
|
|
|
|
for j = 0,i do
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local id = set_extmark(ns,0, i,j)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(nil, ns_marks[ns][id])
|
|
|
|
|
ok(id > 0)
|
|
|
|
|
ns_marks[ns][id] = {i,j}
|
|
|
|
|
ns = ns1+ns2-ns
|
|
|
|
|
q = q + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
eq(233, #ns_marks[ns1])
|
|
|
|
|
eq(232, #ns_marks[ns2])
|
|
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local function get_marks(ns)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
local mark_list = get_extmarks(ns, 0, -1)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
local marks = {}
|
|
|
|
|
for _, mark in ipairs(mark_list) do
|
|
|
|
|
local id, row, col = unpack(mark)
|
|
|
|
|
eq(nil, marks[id], "duplicate mark")
|
|
|
|
|
marks[id] = {row,col}
|
|
|
|
|
end
|
|
|
|
|
return marks
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can get marks", function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
eq(ns_marks[ns1], get_marks(ns1))
|
|
|
|
|
eq(ns_marks[ns2], get_marks(ns2))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can clear all marks in ns", function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
curbufmeths.clear_namespace(ns1, 0, -1)
|
|
|
|
|
eq({}, get_marks(ns1))
|
|
|
|
|
eq(ns_marks[ns2], get_marks(ns2))
|
|
|
|
|
curbufmeths.clear_namespace(ns2, 0, -1)
|
|
|
|
|
eq({}, get_marks(ns1))
|
|
|
|
|
eq({}, get_marks(ns2))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can clear line range", function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
curbufmeths.clear_namespace(ns1, 10, 20)
|
|
|
|
|
for id, mark in pairs(ns_marks[ns1]) do
|
|
|
|
|
if 10 <= mark[1] and mark[1] < 20 then
|
|
|
|
|
ns_marks[ns1][id] = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
eq(ns_marks[ns1], get_marks(ns1))
|
|
|
|
|
eq(ns_marks[ns2], get_marks(ns2))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can delete line", function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('10Gdd')
|
|
|
|
|
for _, marks in pairs(ns_marks) do
|
|
|
|
|
for id, mark in pairs(marks) do
|
|
|
|
|
if mark[1] == 9 then
|
|
|
|
|
marks[id] = {9,0}
|
|
|
|
|
elseif mark[1] >= 10 then
|
|
|
|
|
mark[1] = mark[1] - 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
eq(ns_marks[ns1], get_marks(ns1))
|
|
|
|
|
eq(ns_marks[ns2], get_marks(ns2))
|
|
|
|
|
end)
|
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can delete lines", function()
|
2017-01-18 05:20:07 -07:00
|
|
|
|
feed('10G10dd')
|
|
|
|
|
for _, marks in pairs(ns_marks) do
|
|
|
|
|
for id, mark in pairs(marks) do
|
|
|
|
|
if 9 <= mark[1] and mark[1] < 19 then
|
|
|
|
|
marks[id] = {9,0}
|
|
|
|
|
elseif mark[1] >= 19 then
|
|
|
|
|
mark[1] = mark[1] - 10
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
eq(ns_marks[ns1], get_marks(ns1))
|
|
|
|
|
eq(ns_marks[ns2], get_marks(ns2))
|
|
|
|
|
end)
|
2019-11-09 04:41:50 -07:00
|
|
|
|
|
2020-01-14 04:45:09 -07:00
|
|
|
|
it("can wipe buffer", function()
|
2019-11-09 04:41:50 -07:00
|
|
|
|
command('bwipe!')
|
|
|
|
|
eq({}, get_marks(ns1))
|
|
|
|
|
eq({}, get_marks(ns2))
|
|
|
|
|
end)
|
2017-01-18 05:20:07 -07:00
|
|
|
|
end)
|