mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
api: set_text: more tests, and fixing lint
removing pending virtcol tests Allow passing in empty array as a shorthand for array with empty string; add more documentation add check for start_row as well
This commit is contained in:
@@ -394,7 +394,6 @@ describe('api/buf', function()
|
||||
|
||||
describe('nvim_buf_get_lines, nvim_buf_set_text', function()
|
||||
local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text
|
||||
local line_count = curbufmeths.line_count
|
||||
|
||||
it('works', function()
|
||||
insert([[
|
||||
@@ -418,7 +417,7 @@ describe('api/buf', function()
|
||||
eq({'hello world!', 'text'}, get_lines(0, 2, true))
|
||||
|
||||
-- can replace with multiple lines
|
||||
local err = set_text(0, 6, 0, 11, {'foo', 'wo', 'more'})
|
||||
set_text(0, 6, 0, 11, {'foo', 'wo', 'more'})
|
||||
eq({'hello foo', 'wo', 'more!', 'text'}, get_lines(0, 4, true))
|
||||
|
||||
-- will join multiple lines if needed
|
||||
@@ -426,25 +425,10 @@ describe('api/buf', function()
|
||||
eq({'hello bar'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
pending('can handle multibyte characters', function()
|
||||
insert([[
|
||||
hellØ world!
|
||||
]])
|
||||
|
||||
eq({'hellØ world!'}, get_lines(0, 1, true))
|
||||
|
||||
-- inserting multibyte
|
||||
set_text(0, 11, 0, 11, {'Ø'})
|
||||
eq({'hellØ worldØ!'}, get_lines(0, 1, true))
|
||||
|
||||
-- deleting multibyte
|
||||
set_text(0, 0, 0, 6, {''})
|
||||
eq({'worldØ!'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
it('works with undo', function()
|
||||
insert([[
|
||||
hello world!
|
||||
foo bar
|
||||
]])
|
||||
|
||||
-- setting text
|
||||
@@ -461,6 +445,11 @@ describe('api/buf', function()
|
||||
set_text(0, 0, 0, 0, {'hello', 'mr '})
|
||||
feed('u')
|
||||
eq({'hello world!'}, get_lines(0, 1, true))
|
||||
|
||||
-- deleting newlines
|
||||
set_text(0, 0, 1, 4, {'hello'})
|
||||
feed('u')
|
||||
eq({'hello world!'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
it('updates the cursor position', function()
|
||||
@@ -493,30 +482,36 @@ describe('api/buf', function()
|
||||
local id3 = curbufmeths.set_extmark(ns, 1, 1, {})
|
||||
set_text(0, 4, 0, 7, {"q"})
|
||||
|
||||
-- TODO: if we set text at 0,3, what happens to the mark at 0,3
|
||||
|
||||
eq({'foo q', 'baz'}, get_lines(0, 2, true))
|
||||
-- mark before replacement point is unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1, {})
|
||||
eq({0, 1}, rv)
|
||||
eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
|
||||
-- mark gets shifted back because the replacement was shorter
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2, {})
|
||||
eq({0, 5}, rv)
|
||||
eq({0, 5}, curbufmeths.get_extmark_by_id(ns, id2, {}))
|
||||
-- mark on the next line is unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3, {})
|
||||
eq({1, 1}, rv)
|
||||
eq({1, 1}, curbufmeths.get_extmark_by_id(ns, id3, {}))
|
||||
|
||||
-- replacing the text spanning two lines will adjust the mark on the next line
|
||||
set_text(0, 3, 1, 3, {"qux"})
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3, {})
|
||||
eq({'fooqux', ''}, get_lines(0, 2, true))
|
||||
eq({0, 6}, rv)
|
||||
eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
|
||||
-- but mark before replacement point is still unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1, {})
|
||||
eq({0, 1}, rv)
|
||||
eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
|
||||
-- and the mark in the middle was shifted to the end of the insertion
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2, {})
|
||||
eq({0, 6}, rv)
|
||||
eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
|
||||
|
||||
-- marks should be put back into the same place after undoing
|
||||
set_text(0, 0, 0, 2, {''})
|
||||
feed('u')
|
||||
eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
|
||||
eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
|
||||
eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
|
||||
|
||||
-- marks should be shifted over by the correct number of bytes for multibyte
|
||||
-- chars
|
||||
set_text(0, 0, 0, 0, {'Ø'})
|
||||
eq({0, 3}, curbufmeths.get_extmark_by_id(ns, id1, {}))
|
||||
eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {}))
|
||||
eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user