diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2017-04-17 13:32:22 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2017-04-21 12:32:38 +0200 |
commit | 2c5751b9b2b22b8519aeda82088fe4525f2bd713 (patch) | |
tree | 778b00d961d6ebb7a599bd8d1041e698aac504fb | |
parent | 9cdbbd49825561d642705990a2704b2241cf0584 (diff) | |
download | rneovim-2c5751b9b2b22b8519aeda82088fe4525f2bd713.tar.gz rneovim-2c5751b9b2b22b8519aeda82088fe4525f2bd713.tar.bz2 rneovim-2c5751b9b2b22b8519aeda82088fe4525f2bd713.zip |
ui: add tests for new cursor shape modes
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 17 | ||||
-rw-r--r-- | test/functional/ui/mode_spec.lua | 227 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 5 | ||||
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 113 |
5 files changed, 247 insertions, 117 deletions
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 154374cda9..1ed63adcfb 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -26,7 +26,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo X; done]]) helpers.feed([[<C-\><C-N>]]) wait() - helpers.sleep(10) -- Let some terminal activity happen. + screen.sleep(10) -- Let some terminal activity happen. feed_command("messages") screen:expect([[ msg1 | diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 02e9422781..e4c1b17ef3 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -20,9 +20,11 @@ describe('ui/cursor', function() it("'guicursor' is published as a UI event", function() local expected_cursor_style = { cmdline_hover = { + mode_idx = 9, mouse_shape = 0, short_name = 'e' }, cmdline_insert = { + mode_idx = 5, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -33,6 +35,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'ci' }, cmdline_normal = { + mode_idx = 4, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -43,6 +46,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'c' }, cmdline_replace = { + mode_idx = 6, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -53,6 +57,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'cr' }, insert = { + mode_idx = 2, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -63,12 +68,15 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'i' }, more = { + mode_idx = 14, mouse_shape = 0, short_name = 'm' }, more_lastline = { + mode_idx = 15, mouse_shape = 0, short_name = 'ml' }, normal = { + mode_idx = 0, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -79,6 +87,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'n' }, operator = { + mode_idx = 7, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -89,6 +98,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'o' }, replace = { + mode_idx = 3, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -99,6 +109,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'r' }, showmatch = { + mode_idx = 16, blinkoff = 150, blinkon = 175, blinkwait = 175, @@ -108,12 +119,15 @@ describe('ui/cursor', function() id_lm = 46, short_name = 'sm' }, statusline_drag = { + mode_idx = 11, mouse_shape = 0, short_name = 'sd' }, statusline_hover = { + mode_idx = 10, mouse_shape = 0, short_name = 's' }, visual = { + mode_idx = 1, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -124,6 +138,7 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 'v' }, visual_select = { + mode_idx = 8, blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -134,9 +149,11 @@ describe('ui/cursor', function() mouse_shape = 0, short_name = 've' }, vsep_drag = { + mode_idx = 13, mouse_shape = 0, short_name = 'vd' }, vsep_hover = { + mode_idx = 12, mouse_shape = 0, short_name = 'vs' } } diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua new file mode 100644 index 0000000000..f0cedfeeb5 --- /dev/null +++ b/test/functional/ui/mode_spec.lua @@ -0,0 +1,227 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local command, eval = helpers.command, helpers.eval +local eq = helpers.eq + +describe('ui mode_change event', function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 4) + screen:attach({rgb= true}) + screen:set_default_attr_ids( { + [0] = {bold=true, foreground=255}, + [1] = {bold=true, reverse=true}, + [2] = {bold=true}, + [3] = {reverse=true}, + }) + end) + + it('works in normal mode', function() + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + feed('d') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("operator", screen.mode) + end) + + feed('<esc>') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in insert mode', function() + feed('i') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]],nil,nil,function () + eq("insert", screen.mode) + end) + + feed('word<esc>') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + + command("set showmatch") + eq(eval('&matchtime'), 5) -- tenths of seconds + feed('a(stuff') + screen:expect([[ + word(stuff^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + + feed(')') + screen:expect([[ + word^(stuff) | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("showmatch", screen.mode) + end) + + screen:sleep(400) + screen:expect([[ + word(stuff)^ | + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]], nil, nil, function () + eq("insert", screen.mode) + end) + end) + + it('works in replace mode', function() + feed('R') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {2:-- REPLACE --} | + ]], nil, nil, function () + eq("replace", screen.mode) + end) + + feed('word<esc>') + screen:expect([[ + wor^d | + {0:~ }| + {0:~ }| + | + ]], nil, nil, function () + eq("normal", screen.mode) + end) + end) + + it('works in cmdline mode', function() + feed(':') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('x<left>') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_insert", screen.mode) + end) + + feed('<insert>') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :^x | + ]],nil,nil,function () + eq("cmdline_replace", screen.mode) + end) + + + feed('<right>') + screen:expect([[ + | + {0:~ }| + {0:~ }| + :x^ | + ]],nil,nil,function () + eq("cmdline_normal", screen.mode) + end) + + feed('<esc>') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) + + it('works in visal mode', function() + insert("text") + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual", screen.mode) + end) + + feed('<esc>') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + + command('set selection=exclusive') + feed('v') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + {2:-- VISUAL --} | + ]],nil,nil,function () + eq("visual_select", screen.mode) + end) + + feed('<esc>') + screen:expect([[ + tex^t | + {0:~ }| + {0:~ }| + | + ]],nil,nil,function () + eq("normal", screen.mode) + end) + end) +end) + diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index afbcd222c7..ceb82db98f 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -384,9 +384,8 @@ function Screen:_handle_mouse_off() self._mouse_enabled = false end -function Screen:_handle_mode_change(mode) - assert(mode == 'insert' or mode == 'replace' - or mode == 'normal' or mode == 'cmdline') +function Screen:_handle_mode_change(mode, idx) + assert(idx == self._cursor_style[mode].mode_idx) self.mode = mode end diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 8182190b5f..d9cb3d7b6f 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -566,119 +566,6 @@ describe('Screen', function() end) end) - describe('mode change', function() - before_each(function() - screen:try_resize(25, 5) - end) - - it('works in normal mode', function() - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - - it('works in insert mode', function() - feed('i') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- INSERT --} | - ]],nil,nil,function () - eq("insert", screen.mode) - end) - - feed('word<esc>') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in replace mode', function() - feed('R') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- REPLACE --} | - ]], nil, nil, function () - eq("replace", screen.mode) - end) - - feed('word<esc>') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in cmdline mode', function() - feed(':') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - :^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('<esc>/') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - /^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - - feed('<esc>?') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - ?^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('<esc>') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - end) - it('nvim_ui_attach() handles very large width/height #2180', function() screen:detach() screen = Screen.new(999, 999) |