diff options
author | chentau <tchen1998@gmail.com> | 2020-12-21 18:24:15 -0800 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-01-01 19:51:58 +0100 |
commit | f7d01a65d50a4783527acd2de3998b65e7b78331 (patch) | |
tree | 8dd1055411158dd97284d1615ad8bb0394de3254 /test/functional/api/buffer_spec.lua | |
parent | 45b14f88db1b332938f4a73be28966ae60563a50 (diff) | |
download | rneovim-f7d01a65d50a4783527acd2de3998b65e7b78331.tar.gz rneovim-f7d01a65d50a4783527acd2de3998b65e7b78331.tar.bz2 rneovim-f7d01a65d50a4783527acd2de3998b65e7b78331.zip |
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
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index dbe585a064..fb8ed6a9d7 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -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) |