From 40977e78a27ac7449f759cefa103e356bc2ca5dd Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Tue, 9 Dec 2014 14:12:12 -0300 Subject: input: Recognize mouse events for abstract_ui --- test/functional/ui/mouse_spec.lua | 157 ++++++++++++++++++++++++++++++++++++++ test/functional/ui/screen.lua | 6 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 test/functional/ui/mouse_spec.lua (limited to 'test') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua new file mode 100644 index 0000000000..507b5aacae --- /dev/null +++ b/test/functional/ui/mouse_spec.lua @@ -0,0 +1,157 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local clear, feed, nvim = helpers.clear, helpers.feed, helpers.nvim + +describe('Mouse input', function() + local screen, hlgroup_colors + + setup(function() + hlgroup_colors = { + Visual = nvim('name_to_color', 'LightGrey'), + } + end) + + before_each(function() + clear() + nvim('set_option', 'mouse', 'a') + -- set mouset to very high value to ensure that even in valgrind/travis, + -- nvim will still pick multiple clicks + nvim('set_option', 'mouset', 5000) + screen = Screen.new(25, 5) + screen:attach() + screen:set_default_attr_ids({ + [1] = {background = hlgroup_colors.Visual} + }) + feed('itestingmousesupport and selection') + screen:expect([[ + testing | + mouse | + support and selectio^ | + ~ | + | + ]]) + end) + + after_each(function() + screen:detach() + end) + + it('left click moves cursor', function() + feed('<2,1>') + screen:expect([[ + testing | + mo^se | + support and selection | + ~ | + | + ]]) + feed('<0,0>') + screen:expect([[ + ^esting | + mouse | + support and selection | + ~ | + | + ]]) + end) + + it('left drag changes visual selection', function() + -- drag events must be preceded by a click + feed('<2,1>') + screen:expect([[ + testing | + mo^se | + support and selection | + ~ | + | + ]]) + feed('<4,1>') + screen:expect([[ + testing | + mo{1:us}^ | + support and selection | + ~ | + -- VISUAL -- | + ]]) + feed('<2,2>') + screen:expect([[ + testing | + mo{1:use } | + {1:su}^port and selection | + ~ | + -- VISUAL -- | + ]]) + feed('<0,0>') + screen:expect([[ + ^{1:esting } | + {1:mou}se | + support and selection | + ~ | + -- VISUAL -- | + ]]) + end) + + it('two clicks will select the word and enter VISUAL', function() + feed('<2,2><2,2>') + screen:expect([[ + testing | + mouse | + {1:suppor}^ and selection | + ~ | + -- VISUAL -- | + ]]) + end) + + it('three clicks will select the line and enter VISUAL LINE', function() + feed('<2,2><2,2><2,2>') + screen:expect([[ + testing | + mouse | + {1:su}^{1:port and selection } | + ~ | + -- VISUAL LINE -- | + ]]) + end) + + it('four clicks will enter VISUAL BLOCK', function() + feed('<2,2><2,2><2,2><2,2>') + screen:expect([[ + testing | + mouse | + su^port and selection | + ~ | + -- VISUAL BLOCK -- | + ]]) + end) + + it('right click extends visual selection to the clicked location', function() + feed('<0,0>') + screen:expect([[ + ^esting | + mouse | + support and selection | + ~ | + | + ]]) + feed('<2,2>') + screen:expect([[ + {1:testing } | + {1:mouse } | + {1:su}^port and selection | + ~ | + -- VISUAL -- | + ]]) + end) + + it('ctrl + left click will search for a tag', function() + feed('<0,0>') + screen:expect([[ + E433: No tags file | + E426: tag not found: test| + ing | + Press ENTER or type comma| + nd to continue^ | + ]]) + feed('') + end) +end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index ff22321e4e..8e7d1ed798 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -147,17 +147,21 @@ function Screen:expect(expected, attr_ids) end function Screen:_wait(check, timeout) - local err + local err, checked = false local function notification_cb(method, args) assert(method == 'redraw') self:_redraw(args) err = check() + checked = true if not err then stop() end return true end run(nil, notification_cb, nil, timeout or 5000) + if not checked then + err = check() + end if err then error(err) end -- cgit