diff options
author | Tony Chen <tchen1998@gmail.com> | 2020-12-21 17:51:52 -0800 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-01-01 19:51:45 +0100 |
commit | 45b14f88db1b332938f4a73be28966ae60563a50 (patch) | |
tree | 5603556abeb06119df0f30af921ba20f71a498f2 /test/functional/api/buffer_spec.lua | |
parent | 29ad2ebc1688176a1c7acaa81103dac289de0ad1 (diff) | |
download | rneovim-45b14f88db1b332938f4a73be28966ae60563a50.tar.gz rneovim-45b14f88db1b332938f4a73be28966ae60563a50.tar.bz2 rneovim-45b14f88db1b332938f4a73be28966ae60563a50.zip |
api: set_text: rebase, update to new api, and add more tests
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 60ff246436..dbe585a064 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -409,6 +409,14 @@ describe('api/buf', function() set_text(0, 6, 0, 9, {'world'}) eq({'hello world!', 'text'}, get_lines(0, 2, true)) + -- can insert text + set_text(0, 0, 0, 0, {'well '}) + eq({'well hello world!', 'text'}, get_lines(0, 2, true)) + + -- can delete text + set_text(0, 0, 0, 5, {''}) + 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'}) eq({'hello foo', 'wo', 'more!', 'text'}, get_lines(0, 4, true)) @@ -418,6 +426,43 @@ 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! + ]]) + + -- setting text + set_text(0, 0, 0, 0, {'well '}) + feed('u') + eq({'hello world!'}, get_lines(0, 1, true)) + + -- deleting text + set_text(0, 0, 0, 6, {''}) + feed('u') + eq({'hello world!'}, get_lines(0, 1, true)) + + -- inserting newlines + set_text(0, 0, 0, 0, {'hello', 'mr '}) + feed('u') + eq({'hello world!'}, get_lines(0, 1, true)) + end) + it('updates the cursor position', function() insert([[ hello world! @@ -443,34 +488,34 @@ describe('api/buf', function() foo bar baz ]]) - local id1 = curbufmeths.set_extmark(ns, 0, 0, 1, {}) - local id2 = curbufmeths.set_extmark(ns, 0, 0, 7, {}) - local id3 = curbufmeths.set_extmark(ns, 0, 1, 1, {}) + local id1 = curbufmeths.set_extmark(ns, 0, 1, {}) + local id2 = curbufmeths.set_extmark(ns, 0, 7, {}) + 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) + rv = curbufmeths.get_extmark_by_id(ns, id1, {}) eq({0, 1}, rv) -- mark gets shifted back because the replacement was shorter - rv = curbufmeths.get_extmark_by_id(ns, id2) + rv = curbufmeths.get_extmark_by_id(ns, id2, {}) eq({0, 5}, rv) -- mark on the next line is unaffected - rv = curbufmeths.get_extmark_by_id(ns, id3) + rv = curbufmeths.get_extmark_by_id(ns, id3, {}) eq({1, 1}, rv) -- 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) + rv = curbufmeths.get_extmark_by_id(ns, id3, {}) eq({'fooqux', ''}, get_lines(0, 2, true)) eq({0, 6}, rv) -- but mark before replacement point is still unaffected - rv = curbufmeths.get_extmark_by_id(ns, id1) + rv = curbufmeths.get_extmark_by_id(ns, id1, {}) eq({0, 1}, rv) -- and the mark in the middle was shifted to the end of the insertion - rv = curbufmeths.get_extmark_by_id(ns, id2) + rv = curbufmeths.get_extmark_by_id(ns, id2, {}) eq({0, 6}, rv) end) end) |