2017-04-17 04:32:22 -07:00
|
|
|
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
|
2019-08-20 08:43:13 -07:00
|
|
|
local command = helpers.command
|
2019-09-25 22:37:51 -07:00
|
|
|
local retry = helpers.retry
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
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()
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('d')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="operator"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in insert mode', function()
|
|
|
|
feed('i')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- INSERT --} |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="insert"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('word<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
wor^d |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
2019-09-25 22:37:51 -07:00
|
|
|
local matchtime = 0
|
2017-04-17 04:32:22 -07:00
|
|
|
command("set showmatch")
|
2019-09-25 22:37:51 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
matchtime = matchtime + 1
|
|
|
|
local screen_timeout = 1000 * matchtime -- fail faster for retry.
|
2017-04-17 04:32:22 -07:00
|
|
|
|
2019-09-25 22:37:51 -07:00
|
|
|
command("set matchtime=" .. matchtime) -- tenths of seconds
|
|
|
|
feed('a(stuff')
|
|
|
|
screen:expect{grid=[[
|
|
|
|
word(stuff^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- INSERT --} |
|
|
|
|
]], mode="insert", timeout=screen_timeout}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
2019-09-25 22:37:51 -07:00
|
|
|
feed(')')
|
|
|
|
screen:expect{grid=[[
|
|
|
|
word^(stuff) |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- INSERT --} |
|
|
|
|
]], mode="showmatch", timeout=screen_timeout}
|
|
|
|
|
|
|
|
screen:expect{grid=[[
|
|
|
|
word(stuff)^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- INSERT --} |
|
|
|
|
]], mode="insert", timeout=screen_timeout}
|
|
|
|
end)
|
2017-04-17 04:32:22 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in replace mode', function()
|
|
|
|
feed('R')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- REPLACE --} |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="replace"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('word<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
wor^d |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in cmdline mode', function()
|
|
|
|
feed(':')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
:^ |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="cmdline_normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('x<left>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
:^x |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="cmdline_insert"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('<insert>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
:^x |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="cmdline_replace"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
feed('<right>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
:x^ |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="cmdline_normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
^ |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
end)
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
it('works in visual mode', function()
|
2017-04-17 04:32:22 -07:00
|
|
|
insert("text")
|
|
|
|
feed('v')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
tex^t |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- VISUAL --} |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="visual"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
tex^t |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
command('set selection=exclusive')
|
|
|
|
feed('v')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
tex^t |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{2:-- VISUAL --} |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="visual_select"}
|
2017-04-17 04:32:22 -07:00
|
|
|
|
|
|
|
feed('<esc>')
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-04-17 04:32:22 -07:00
|
|
|
tex^t |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
]], mode="normal"}
|
2017-04-17 04:32:22 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|