diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-08-26 20:57:57 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-08-27 22:13:45 +0200 |
commit | ed60015266356b3c0c42aa34698d9287f22fcba1 (patch) | |
tree | c1ae9ec1da22f94bce1157cd42a74112c2849746 /test | |
parent | 4344ac11119abd20ba911d72cf540321277dd150 (diff) | |
download | rneovim-ed60015266356b3c0c42aa34698d9287f22fcba1.tar.gz rneovim-ed60015266356b3c0c42aa34698d9287f22fcba1.tar.bz2 rneovim-ed60015266356b3c0c42aa34698d9287f22fcba1.zip |
paste: handle vim.paste() failure
- Show error only once per "paste stream".
- Drain remaining chunks until phase=3.
- Lay groundwork for "cancel".
- Constrain semantics of "cancel" to mean "client must stop"; it is
unrelated to presence of error(s).
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/vim_spec.lua | 24 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 51 |
2 files changed, 75 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 212c4f4300..01e4a3a1a0 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -395,6 +395,11 @@ describe('API', function() eq({0,3,6,0}, funcs.getpos('.')) eq(false, nvim('get_option', 'paste')) end) + it('vim.paste() failure', function() + nvim('execute_lua', 'vim._paste = (function(lines, phase) error("fake fail") end)', {}) + expect_err([[Error executing lua: %[string "%<nvim>"]:1: fake fail]], + request, 'nvim_paste', 'line 1\nline 2\nline 3', 1) + end) end) describe('nvim_put', function() @@ -455,6 +460,25 @@ describe('API', function() eq({0,1,2,0}, funcs.getpos('.')) eq('', nvim('eval', 'v:errmsg')) end) + + it('detects charwise/linewise text (empty {type})', function() + -- linewise (final item is empty string) + nvim('put', {'line 1','line 2','line 3',''}, '', true, true) + expect([[ + + line 1 + line 2 + line 3]]) + eq({0,4,1,0}, funcs.getpos('.')) + command('%delete _') + -- charwise (final item is non-empty) + nvim('put', {'line 1','line 2','line 3'}, '', true, true) + expect([[ + line 1 + line 2 + line 3]]) + eq({0,3,6,0}, funcs.getpos('.')) + end) end) describe('nvim_strwidth', function() diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 08ff06e0a5..e7db39b5d0 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -324,6 +324,57 @@ describe('TUI', function() expect_cmdline('"stuff 1 more typed"') end) + it('paste: recovers from vim.paste() failure', function() + child_session:request('nvim_execute_lua', [[ + _G.save_paste_fn = vim._paste + vim._paste = function(lines, phase) error("fake fail") end + ]], {}) + -- Start pasting... + feed_data('\027[200~line 1\nline 2\n') + screen:expect{grid=[[ + | + {4:~ }| + {4:~ }| + {5: }| + {8:paste: Error executing lua: [string "<nvim>"]:2: f}| + {10:Press ENTER or type command to continue}{1: } | + {3:-- TERMINAL --} | + ]]} + -- Remaining chunks are discarded after vim.paste() failure. + feed_data('line 3\nline 4\n') + feed_data('line 5\nline 6\n') + feed_data('line 7\nline 8\n') + -- Stop paste. + feed_data('\027[201~') + feed_data('\n') -- <Enter> + -- Editor should still work after failed/drained paste. + feed_data('ityped input...\027\000') + screen:expect{grid=[[ + typed input..{1:.} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]} + -- Paste works if vim.paste() succeeds. + child_session:request('nvim_execute_lua', [[ + vim._paste = _G.save_paste_fn + ]], {}) + feed_data('\027[200~line A\nline B\n\027[201~') + feed_data('\n') -- <Enter> + screen:expect{grid=[[ + typed input...line A | + line B | + {1: } | + {4:~ }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]} + end) + -- TODO it('paste: other modes', function() -- Other modes act like CTRL-C + paste. |