mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	api: vim_err_write: add tests for multiline handling
This commit is contained in:
		| @@ -1,6 +1,8 @@ | |||||||
| -- Sanity checks for vim_* API calls via msgpack-rpc | -- Sanity checks for vim_* API calls via msgpack-rpc | ||||||
| local helpers = require('test.functional.helpers') | 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() | describe('vim_* functions', function() | ||||||
| @@ -177,6 +179,104 @@ describe('vim_* functions', function() | |||||||
|     end) |     end) | ||||||
|   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() |   it('can throw exceptions', function() | ||||||
|     local status, err = pcall(nvim, 'get_option', 'invalid-option') |     local status, err = pcall(nvim, 'get_option', 'invalid-option') | ||||||
|     eq(false, status) |     eq(false, status) | ||||||
|   | |||||||
| @@ -246,6 +246,10 @@ local function nvim(method, ...) | |||||||
|   return request('vim_'..method, ...) |   return request('vim_'..method, ...) | ||||||
| end | end | ||||||
|  |  | ||||||
|  | local function nvim_async(method, ...) | ||||||
|  |   session:notify('vim_'..method, ...) | ||||||
|  | end | ||||||
|  |  | ||||||
| local function buffer(method, ...) | local function buffer(method, ...) | ||||||
|   return request('buffer_'..method, ...) |   return request('buffer_'..method, ...) | ||||||
| end | end | ||||||
| @@ -341,6 +345,7 @@ return { | |||||||
|   expect = expect, |   expect = expect, | ||||||
|   ok = ok, |   ok = ok, | ||||||
|   nvim = nvim, |   nvim = nvim, | ||||||
|  |   nvim_async = nvim_async, | ||||||
|   nvim_prog = nvim_prog, |   nvim_prog = nvim_prog, | ||||||
|   nvim_dir = nvim_dir, |   nvim_dir = nvim_dir, | ||||||
|   buffer = buffer, |   buffer = buffer, | ||||||
|   | |||||||
| @@ -489,7 +489,7 @@ function Screen:snapshot_util(attrs, ignore) | |||||||
|   self:print_snapshot(attrs, ignore) |   self:print_snapshot(attrs, ignore) | ||||||
| end | end | ||||||
|  |  | ||||||
| function Screen:redraw_debug(attrs, ignore) | function Screen:redraw_debug(attrs, ignore, timeout) | ||||||
|   self:print_snapshot(attrs, ignore) |   self:print_snapshot(attrs, ignore) | ||||||
|   local function notification_cb(method, args) |   local function notification_cb(method, args) | ||||||
|     assert(method == 'redraw') |     assert(method == 'redraw') | ||||||
| @@ -500,7 +500,10 @@ function Screen:redraw_debug(attrs, ignore) | |||||||
|     self:print_snapshot(attrs, ignore) |     self:print_snapshot(attrs, ignore) | ||||||
|     return true |     return true | ||||||
|   end |   end | ||||||
|   run(nil, notification_cb, nil, 250) |   if timeout == nil then | ||||||
|  |     timeout = 250 | ||||||
|  |   end | ||||||
|  |   run(nil, notification_cb, nil, timeout) | ||||||
| end | end | ||||||
|  |  | ||||||
| function Screen:print_snapshot(attrs, ignore) | function Screen:print_snapshot(attrs, ignore) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Björn Linse
					Björn Linse