fix a bunch of bugs
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m36s
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m36s
This commit is contained in:
@@ -738,4 +738,36 @@ describe('Range', function()
|
||||
assert.are.same({ 3, 0 }, { details.end_row, details.end_col })
|
||||
end)
|
||||
end)
|
||||
|
||||
it('discerns range bounds from extmarks beyond the end of the buffer', function()
|
||||
local Buffer = require 'u.buffer'
|
||||
|
||||
vim.cmd.vnew()
|
||||
local left = Buffer.current()
|
||||
left:set_tmp_options()
|
||||
vim.cmd.vnew()
|
||||
local right = Buffer.current()
|
||||
right:set_tmp_options()
|
||||
|
||||
left:all():replace {
|
||||
'one',
|
||||
'two',
|
||||
'three',
|
||||
}
|
||||
local left_all_ext = left:all():save_to_extmark()
|
||||
|
||||
right:all():replace {
|
||||
'foo',
|
||||
'bar',
|
||||
}
|
||||
|
||||
vim.api.nvim_set_current_buf(right.bufnr)
|
||||
vim.cmd [[normal! ggyG]]
|
||||
vim.api.nvim_set_current_buf(left.bufnr)
|
||||
vim.cmd [[normal! ggVGp]]
|
||||
|
||||
assert.are.same({ 'foo', 'bar' }, left_all_ext:range():lines())
|
||||
vim.api.nvim_buf_delete(left.bufnr, { force = true })
|
||||
vim.api.nvim_buf_delete(right.bufnr, { force = true })
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -83,13 +83,13 @@ describe('Renderer', function()
|
||||
end)
|
||||
|
||||
--
|
||||
-- get_pos_infos
|
||||
-- get_tags_at
|
||||
--
|
||||
|
||||
it('should return no extmarks for an empty buffer', function()
|
||||
withbuf({}, function()
|
||||
local r = R.Renderer.new(0)
|
||||
local pos_infos = r:get_pos_infos { 0, 0 }
|
||||
local pos_infos = r:get_tags_at { 0, 0 }
|
||||
assert.are.same(pos_infos, {})
|
||||
end)
|
||||
end)
|
||||
@@ -102,25 +102,25 @@ describe('Renderer', function()
|
||||
R.h('text', { hl = 'HighlightGroup2' }, ' World'),
|
||||
}
|
||||
|
||||
local pos_infos = r:get_pos_infos { 0, 2 }
|
||||
local pos_infos = r:get_tags_at { 0, 2 }
|
||||
assert.are.same(#pos_infos, 1)
|
||||
assert.are.same(pos_infos[1].tag.attributes.hl, 'HighlightGroup1')
|
||||
assert.are.same(pos_infos[1].extmark.start, { 0, 0 })
|
||||
assert.are.same(pos_infos[1].extmark.stop, { 0, 5 })
|
||||
pos_infos = r:get_pos_infos { 0, 4 }
|
||||
pos_infos = r:get_tags_at { 0, 4 }
|
||||
assert.are.same(#pos_infos, 1)
|
||||
assert.are.same(pos_infos[1].tag.attributes.hl, 'HighlightGroup1')
|
||||
assert.are.same(pos_infos[1].extmark.start, { 0, 0 })
|
||||
assert.are.same(pos_infos[1].extmark.stop, { 0, 5 })
|
||||
|
||||
pos_infos = r:get_pos_infos { 0, 5 }
|
||||
pos_infos = r:get_tags_at { 0, 5 }
|
||||
assert.are.same(#pos_infos, 1)
|
||||
assert.are.same(pos_infos[1].tag.attributes.hl, 'HighlightGroup2')
|
||||
assert.are.same(pos_infos[1].extmark.start, { 0, 5 })
|
||||
assert.are.same(pos_infos[1].extmark.stop, { 0, 11 })
|
||||
|
||||
-- In insert mode, bounds are eagerly included:
|
||||
pos_infos = r:get_pos_infos({ 0, 5 }, 'i')
|
||||
pos_infos = r:get_tags_at({ 0, 5 }, 'i')
|
||||
assert.are.same(#pos_infos, 2)
|
||||
assert.are.same(pos_infos[1].tag.attributes.hl, 'HighlightGroup1')
|
||||
assert.are.same(pos_infos[2].tag.attributes.hl, 'HighlightGroup2')
|
||||
@@ -141,11 +141,66 @@ describe('Renderer', function()
|
||||
}),
|
||||
}
|
||||
|
||||
local pos_infos = r:get_pos_infos { 0, 5 }
|
||||
local pos_infos = r:get_tags_at { 0, 5 }
|
||||
|
||||
assert.are.same(#pos_infos, 2)
|
||||
assert.are.same(pos_infos[1].tag.attributes.hl, 'HighlightGroup2')
|
||||
assert.are.same(pos_infos[2].tag.attributes.hl, 'HighlightGroup1')
|
||||
end)
|
||||
end)
|
||||
|
||||
it('repeated patch_lines calls should not change the buffer content', function()
|
||||
local lines = {
|
||||
[[{ {]],
|
||||
[[ bounds = {]],
|
||||
[[ start1 = { 1, 1 },]],
|
||||
[[ stop1 = { 4, 1 }]],
|
||||
[[ },]],
|
||||
[[ end_right_gravity = true,]],
|
||||
[[ id = 1,]],
|
||||
[[ ns_id = 623,]],
|
||||
[[ ns_name = "my.renderer:91",]],
|
||||
[[ right_gravity = false]],
|
||||
[[ } }]],
|
||||
[[]],
|
||||
}
|
||||
withbuf(lines, function()
|
||||
local Buffer = require 'u.buffer'
|
||||
R.Renderer.patch_lines(0, nil, lines)
|
||||
assert.are.same(Buffer.current():all():lines(), lines)
|
||||
|
||||
R.Renderer.patch_lines(0, lines, lines)
|
||||
assert.are.same(Buffer.current():all():lines(), lines)
|
||||
|
||||
R.Renderer.patch_lines(0, lines, lines)
|
||||
assert.are.same(Buffer.current():all():lines(), lines)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('should fire text-changed events', function()
|
||||
withbuf({}, function()
|
||||
local Buffer = require 'u.buffer'
|
||||
local buf = Buffer.current()
|
||||
local r = R.Renderer.new(0)
|
||||
local captured_changed_text = ''
|
||||
r:render {
|
||||
R.h('text', {
|
||||
on_change = function(txt) captured_changed_text = txt end,
|
||||
}, {
|
||||
'one\n',
|
||||
'two\n',
|
||||
'three\n',
|
||||
}),
|
||||
}
|
||||
|
||||
vim.fn.setreg('"', 'bleh')
|
||||
vim.cmd [[normal! ggVGp]]
|
||||
-- For some reason, the autocmd does not fire in the busted environment.
|
||||
-- We'll call the handler ourselves:
|
||||
r:_on_text_changed()
|
||||
|
||||
assert.are.same(buf:all():text(), 'bleh')
|
||||
assert.are.same(captured_changed_text, 'bleh')
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user