diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/ex_cmds/ctrl_c_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ex_cmds/print_commands_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/helpers.lua | 9 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 169 | ||||
-rw-r--r-- | test/functional/ui/mode_spec.lua | 227 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 11 | ||||
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 113 |
8 files changed, 349 insertions, 196 deletions
diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 993bfa0dba..091a008814 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -41,7 +41,7 @@ describe("CTRL-C (mapped)", function() local function test_ctrl_c(ms) feed(":global/^/p<CR>") - helpers.sleep(ms) + screen:sleep(ms) feed("<C-C>") screen:expect([[Interrupt]], nil, nil, nil, true) end diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua new file mode 100644 index 0000000000..98c0f74635 --- /dev/null +++ b/test/functional/ex_cmds/print_commands_spec.lua @@ -0,0 +1,12 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, eq, command, funcs = + helpers.clear, helpers.eq, helpers.command, helpers.funcs + +describe(':z^', function() + before_each(clear) + + it('correctly sets the cursor after :z^', function() + command('z^') + eq(1, funcs.line('.')) + end) +end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 5882758b5a..0f30910450 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -392,7 +392,14 @@ end -- sleeps the test runner (_not_ the nvim instance) local function sleep(ms) - run(nil, nil, nil, ms) + local function notification_cb(method, _) + if method == "redraw" then + error("Screen is attached; use screen:sleep() instead.") + end + return true + end + + run(nil, notification_cb, nil, ms) end local function curbuf_contents() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 154374cda9..be0fd9f8ff 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..abe0e0b1fd 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -18,138 +18,155 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - local expected_cursor_style = { - cmdline_hover = { - mouse_shape = 0, - short_name = 'e' }, - cmdline_insert = { + local expected_mode_info = { + [1] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 0, + cursor_shape = 'block', + name = 'normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'ci' }, - cmdline_normal = { + short_name = 'n' }, + [2] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'visual', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'c' }, - cmdline_replace = { + short_name = 'v' }, + [3] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 20, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'insert', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'cr' }, - insert = { + short_name = 'i' }, + [4] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', + cell_percentage = 20, + cursor_shape = 'horizontal', + name = 'replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'i' }, - more = { - mouse_shape = 0, - short_name = 'm' }, - more_lastline = { - mouse_shape = 0, - short_name = 'ml' }, - normal = { + short_name = 'r' }, + [5] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', + name = 'cmdline_normal', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'n' }, - operator = { + short_name = 'c' }, + [6] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 50, - cursor_shape = 'horizontal', + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'cmdline_insert', hl_id = 46, - id_lm = 46, + id_lm = 47, mouse_shape = 0, - short_name = 'o' }, - replace = { + short_name = 'ci' }, + [7] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 20, cursor_shape = 'horizontal', + name = 'cmdline_replace', hl_id = 46, id_lm = 47, mouse_shape = 0, - short_name = 'r' }, - showmatch = { - blinkoff = 150, - blinkon = 175, - blinkwait = 175, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 46, - id_lm = 46, - short_name = 'sm' }, - statusline_drag = { - mouse_shape = 0, - short_name = 'sd' }, - statusline_hover = { - mouse_shape = 0, - short_name = 's' }, - visual = { + short_name = 'cr' }, + [8] = { blinkoff = 250, blinkon = 400, blinkwait = 700, - cell_percentage = 0, - cursor_shape = 'block', + cell_percentage = 50, + cursor_shape = 'horizontal', + name = 'operator', hl_id = 46, - id_lm = 47, + id_lm = 46, mouse_shape = 0, - short_name = 'v' }, - visual_select = { + short_name = 'o' }, + [9] = { blinkoff = 250, blinkon = 400, blinkwait = 700, cell_percentage = 35, cursor_shape = 'vertical', + name = 'visual_select', hl_id = 46, id_lm = 46, mouse_shape = 0, short_name = 've' }, - vsep_drag = { + [10] = { + name = 'cmdline_hover', + mouse_shape = 0, + short_name = 'e' }, + [11] = { + name = 'statusline_hover', + mouse_shape = 0, + short_name = 's' }, + [12] = { + name = 'statusline_drag', + mouse_shape = 0, + short_name = 'sd' }, + [13] = { + name = 'vsep_hover', + mouse_shape = 0, + short_name = 'vs' }, + [14] = { + name = 'vsep_drag', mouse_shape = 0, short_name = 'vd' }, - vsep_hover = { + [15] = { + name = 'more', mouse_shape = 0, - short_name = 'vs' } - } + short_name = 'm' }, + [16] = { + name = 'more_lastline', + mouse_shape = 0, + short_name = 'ml' }, + [17] = { + blinkoff = 150, + blinkon = 175, + blinkwait = 175, + cell_percentage = 0, + cursor_shape = 'block', + name = 'showmatch', + hl_id = 46, + id_lm = 46, + short_name = 'sm' }, + } screen:expect(function() -- Default 'guicursor' published on startup. - eq(expected_cursor_style, screen._cursor_style) + eq(expected_mode_info, screen._mode_info) eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) end) -- Event is published ONLY if the cursor style changed. - screen._cursor_style = nil + screen._mode_info = nil command("echo 'test'") screen:expect([[ ^ | @@ -158,20 +175,24 @@ describe('ui/cursor', function() ~ | test | ]], nil, nil, function() - eq(nil, screen._cursor_style) + eq(nil, screen._mode_info) end) -- Change the cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') screen:expect(function() - eq('vertical', screen._cursor_style.normal.cursor_shape) - eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.operator.cursor_shape) - eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.showmatch.cursor_shape) - eq(171, screen._cursor_style.normal.blinkwait) - eq(172, screen._cursor_style.normal.blinkoff) - eq(173, screen._cursor_style.normal.blinkon) + local named = {} + for _, m in ipairs(screen._mode_info) do + named[m.name] = m + end + eq('vertical', named.normal.cursor_shape) + eq('horizontal', named.visual_select.cursor_shape) + eq('vertical', named.operator.cursor_shape) + eq('block', named.insert.cursor_shape) + eq('vertical', named.showmatch.cursor_shape) + eq(171, named.normal.blinkwait) + eq(172, named.normal.blinkoff) + eq(173, named.normal.blinkon) end) end) @@ -180,11 +201,11 @@ describe('ui/cursor', function() screen:expect(function() -- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled) - for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', - 'showmatch', 'normal', 'replace', 'visual', - 'visual_select', }) do - eq('block', screen._cursor_style[m].cursor_shape) - eq(0, screen._cursor_style[m].blinkon) + for _, m in ipairs(screen._mode_info) do + if m['cursor_shape'] ~= nil then + eq('block', m.cursor_shape) + eq(0, m.blinkon) + end end end) end) 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..bcf2a2e3d6 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -348,9 +348,9 @@ function Screen:_handle_resize(width, height) } end -function Screen:_handle_cursor_style_set(enabled, style) - self._cursor_style_enabled = enabled - self._cursor_style = style +function Screen:_handle_mode_info_set(cursor_style_enabled, mode_info) + self._cursor_style_enabled = cursor_style_enabled + self._mode_info = mode_info end function Screen:_handle_clear() @@ -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(mode == self._mode_info[idx+1].name) 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) |