mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ui: add tests for new cursor shape modes
This commit is contained in:
parent
9cdbbd4982
commit
2c5751b9b2
@ -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 |
|
||||
|
@ -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' }
|
||||
}
|
||||
|
227
test/functional/ui/mode_spec.lua
Normal file
227
test/functional/ui/mode_spec.lua
Normal file
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user