diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2015-07-27 13:39:38 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2015-09-16 21:42:57 +0200 |
commit | c8aaabc09c9cd27aeadf395fc025260054490081 (patch) | |
tree | e29474a57388a7e1cf8269f553c5be8c2ff36aa1 | |
parent | 8c2481806d9d4cc7641968e04be5e9c87e034752 (diff) | |
download | rneovim-c8aaabc09c9cd27aeadf395fc025260054490081.tar.gz rneovim-c8aaabc09c9cd27aeadf395fc025260054490081.tar.bz2 rneovim-c8aaabc09c9cd27aeadf395fc025260054490081.zip |
api: vim_err_write: add tests for multiline handling
-rw-r--r-- | test/functional/api/vim_spec.lua | 102 | ||||
-rw-r--r-- | test/functional/helpers.lua | 5 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 7 |
3 files changed, 111 insertions, 3 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9e880a4f04..8d4e183653 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,6 +1,8 @@ -- Sanity checks for vim_* API calls via msgpack-rpc local helpers = require('test.functional.helpers') -local clear, nvim, eq, neq, ok = helpers.clear, helpers.nvim, helpers.eq, helpers.neq, helpers.ok +local Screen = require('test.functional.ui.screen') +local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq +local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed describe('vim_* functions', function() @@ -177,6 +179,104 @@ describe('vim_* functions', function() end) end) + describe('err_write', function() + before_each(function() + clear() + screen = Screen.new(40, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {foreground = Screen.colors.White, background = Screen.colors.Red}, + [2] = {bold = true, foreground = Screen.colors.SeaGreen} + }) + screen:set_default_attr_ignore( {{bold=true, foreground=Screen.colors.Blue}} ) + end) + + it('can show one line', function() + nvim_async('err_write', 'has bork\n') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + {1:has bork} | + ]]) + end) + + it('shows return prompt when more than &cmdheight lines', function() + nvim_async('err_write', 'something happened\nvery bad\n') + screen:expect([[ + ~ | + ~ | + ~ | + ~ | + ~ | + {1:something happened} | + {1:very bad} | + {2:Press ENTER or type command to continue}^ | + ]]) + end) + + it('shows return prompt after all lines are shown', function() + nvim_async('err_write', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK\n') + screen:expect([[ + ~ | + ~ | + ~ | + {1:FAILURE} | + {1:ERROR} | + {1:EXCEPTION} | + {1:TRACEBACK} | + {2:Press ENTER or type command to continue}^ | + ]]) + end) + + it('handles multiple calls', function() + -- without linebreak text is joined to one line + nvim_async('err_write', 'very ') + nvim_async('err_write', 'fail\n') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + {1:very fail} | + ]]) + + -- shows up to &cmdheight lines + nvim_async('err_write', 'more fail\n') + nvim_async('err_write', 'too fail\n') + screen:expect([[ + ~ | + ~ | + ~ | + ~ | + ~ | + {1:very fail} | + {1:more fail} | + {2:Press ENTER or type command to continue}^ | + ]]) + + -- shows the rest after return + feed('<cr>') + screen:expect([[ + ~ | + ~ | + ~ | + {1:very fail} | + {1:more fail} | + {2:Press ENTER or type command to continue} | + {1:too fail} | + {2:Press ENTER or type command to continue}^ | + ]]) + end) + end) + it('can throw exceptions', function() local status, err = pcall(nvim, 'get_option', 'invalid-option') eq(false, status) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 6055cc3c59..07e0809dbc 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -246,6 +246,10 @@ local function nvim(method, ...) return request('vim_'..method, ...) end +local function nvim_async(method, ...) + session:notify('vim_'..method, ...) +end + local function buffer(method, ...) return request('buffer_'..method, ...) end @@ -341,6 +345,7 @@ return { expect = expect, ok = ok, nvim = nvim, + nvim_async = nvim_async, nvim_prog = nvim_prog, nvim_dir = nvim_dir, buffer = buffer, diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index aba6307d7c..08c4bfae0b 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -489,7 +489,7 @@ function Screen:snapshot_util(attrs, ignore) self:print_snapshot(attrs, ignore) end -function Screen:redraw_debug(attrs, ignore) +function Screen:redraw_debug(attrs, ignore, timeout) self:print_snapshot(attrs, ignore) local function notification_cb(method, args) assert(method == 'redraw') @@ -500,7 +500,10 @@ function Screen:redraw_debug(attrs, ignore) self:print_snapshot(attrs, ignore) return true end - run(nil, notification_cb, nil, 250) + if timeout == nil then + timeout = 250 + end + run(nil, notification_cb, nil, timeout) end function Screen:print_snapshot(attrs, ignore) |