diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-06 06:56:24 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-03-15 18:15:18 +0800 |
commit | fcc6f66cf2a67cf85e72727a08e19d0f800badb9 (patch) | |
tree | cdb0d4d64e7e9c91da458b0537ba120c3cd0df72 /test/functional/api/vim_spec.lua | |
parent | 21ba2d81a848e7b85739fc3e9aa2eb0b5e35c879 (diff) | |
download | rneovim-fcc6f66cf2a67cf85e72727a08e19d0f800badb9.tar.gz rneovim-fcc6f66cf2a67cf85e72727a08e19d0f800badb9.tar.bz2 rneovim-fcc6f66cf2a67cf85e72727a08e19d0f800badb9.zip |
fix(paste): avoid edges cases caused by empty chunk
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index eaee9211f4..761cbb4036 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -630,6 +630,10 @@ describe('API', function() end) describe('nvim_paste', function() + before_each(function() + -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. + feed('ifoo<Esc>u') + end) it('validates args', function() eq('Invalid phase: -2', pcall_err(request, 'nvim_paste', 'foo', true, -2)) @@ -702,7 +706,7 @@ describe('API', function() feed('u') expect('||') end) - it('stream: Visual mode either end not at the end of a line', function() + it('stream: Visual mode neither end at the end of a line', function() feed('i|xxx<CR>xxx|<Esc>hvhk') nvim('paste', 'aaaaaa', false, 1) nvim('paste', 'bbbbbb', false, 2) @@ -714,6 +718,30 @@ describe('API', function() |xxx xxx|]]) end) + it('stream: Visual mode neither end at the end of a line with empty first chunk', function() + feed('i|xxx<CR>xxx|<Esc>hvhk') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('|bbbbbbccccccdddddd|') + feed('u') + expect([[ + |xxx + xxx|]]) + end) + it('stream: Visual mode neither end at the end of a line with all chunks empty', function() + feed('i|xxx<CR>xxx|<Esc>hvhk') + nvim('paste', '', false, 1) + nvim('paste', '', false, 2) + nvim('paste', '', false, 2) + nvim('paste', '', false, 3) + expect('||') + feed('u') + expect([[ + |xxx + xxx|]]) + end) it('stream: Visual mode cursor at the end of a line', function() feed('i||xxx<CR>xxx<Esc>vko') nvim('paste', 'aaaaaa', false, 1) @@ -726,6 +754,18 @@ describe('API', function() ||xxx xxx]]) end) + it('stream: Visual mode cursor at the end of a line with empty first chunk', function() + feed('i||xxx<CR>xxx<Esc>vko') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) it('stream: Visual mode other end at the end of a line', function() feed('i||xxx<CR>xxx<Esc>vk') nvim('paste', 'aaaaaa', false, 1) @@ -738,6 +778,18 @@ describe('API', function() ||xxx xxx]]) end) + it('stream: Visual mode other end at the end of a line with empty first chunk', function() + feed('i||xxx<CR>xxx<Esc>vk') + nvim('paste', '', false, 1) + nvim('paste', 'bbbbbb', false, 2) + nvim('paste', 'cccccc', false, 2) + nvim('paste', 'dddddd', false, 3) + expect('||bbbbbbccccccdddddd') + feed('u') + expect([[ + ||xxx + xxx]]) + end) it('non-streaming', function() -- With final "\n". nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) @@ -817,6 +869,19 @@ describe('API', function() eq('aabbccdd', funcs.getcmdline()) expect('') end) + it('pasting with empty last chunk in Cmdline mode', function() + local screen = Screen.new(20, 4) + screen:attach() + feed(':') + nvim('paste', 'Foo', true, 1) + nvim('paste', '', true, 3) + screen:expect([[ + | + ~ | + ~ | + :Foo^ | + ]]) + end) it('crlf=false does not break lines at CR, CRLF', function() nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') |