2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2022-07-11 16:22:17 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local eval = n.eval
|
|
|
|
local feed = n.feed
|
|
|
|
local api = n.api
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
2022-02-07 23:47:23 -07:00
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('Ex mode', function()
|
|
|
|
it('supports command line editing', function()
|
|
|
|
local function test_ex_edit(expected, cmd)
|
|
|
|
feed('gQ' .. cmd .. '<C-b>"<CR>')
|
|
|
|
local ret = eval('@:[1:]') -- Remove leading quote.
|
|
|
|
feed('visual<CR>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(api.nvim_replace_termcodes(expected, true, true, true), ret)
|
2022-02-07 23:47:23 -07:00
|
|
|
end
|
|
|
|
command('set sw=2')
|
|
|
|
test_ex_edit('bar', 'foo bar<C-u>bar')
|
|
|
|
test_ex_edit('1<C-u>2', '1<C-v><C-u>2')
|
|
|
|
test_ex_edit('213', '1<C-b>2<C-e>3')
|
|
|
|
test_ex_edit('2013', '01<Home>2<End>3')
|
|
|
|
test_ex_edit('0213', '01<Left>2<Right>3')
|
|
|
|
test_ex_edit('0342', '012<Left><Left><Insert>3<Insert>4')
|
|
|
|
test_ex_edit('foo ', 'foo bar<C-w>')
|
|
|
|
test_ex_edit('foo', 'fooba<Del><Del>')
|
|
|
|
test_ex_edit('foobar', 'foo<Tab>bar')
|
|
|
|
test_ex_edit('abbreviate', 'abbrev<Tab>')
|
|
|
|
test_ex_edit('1<C-t><C-t>', '1<C-t><C-t>')
|
|
|
|
test_ex_edit('1<C-t><C-t>', '1<C-t><C-t><C-d>')
|
|
|
|
test_ex_edit(' foo', ' foo<C-d>')
|
|
|
|
test_ex_edit(' foo0', ' foo0<C-d>')
|
|
|
|
test_ex_edit(' foo^', ' foo^<C-d>')
|
2022-04-19 16:56:19 -07:00
|
|
|
test_ex_edit('foo', '<BS><C-H><Del><kDel>foo')
|
|
|
|
-- default wildchar <Tab> interferes with this test
|
|
|
|
command('set wildchar=<c-e>')
|
|
|
|
test_ex_edit('a\tb', 'a\t\t<C-H>b')
|
|
|
|
test_ex_edit('\tm<C-T>n', '\tm<C-T>n')
|
|
|
|
command('set wildchar&')
|
2022-02-07 23:47:23 -07:00
|
|
|
end)
|
2022-07-11 16:22:17 -07:00
|
|
|
|
|
|
|
it('substitute confirmation prompt', function()
|
|
|
|
command('set noincsearch nohlsearch inccommand=')
|
|
|
|
local screen = Screen.new(60, 6)
|
2024-07-14 01:28:05 -07:00
|
|
|
command([[call setline(1, repeat(['foo foo'], 4))]])
|
2022-07-11 16:22:17 -07:00
|
|
|
command([[set number]])
|
|
|
|
feed('gQ')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
|
|
|
{8: 2 }foo foo |
|
|
|
|
{8: 3 }foo foo |
|
|
|
|
{3: }|
|
2022-07-11 16:22:17 -07:00
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed('%s/foo/bar/gc<CR>')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
|
|
|
{3: }|
|
2022-07-11 16:22:17 -07:00
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
|
|
|
:%s/foo/bar/gc |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
^^^^ |
|
|
|
|
]])
|
2022-07-11 21:37:23 -07:00
|
|
|
feed('N<CR>')
|
2022-07-11 16:22:17 -07:00
|
|
|
screen:expect([[
|
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
|
|
|
:%s/foo/bar/gc |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 21:37:23 -07:00
|
|
|
^^^N |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 21:37:23 -07:00
|
|
|
^^^^ |
|
|
|
|
]])
|
|
|
|
feed('n<CR>')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 21:37:23 -07:00
|
|
|
^^^N |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
^^^n |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
^^^^ |
|
|
|
|
]])
|
|
|
|
feed('y<CR>')
|
|
|
|
|
|
|
|
feed('q<CR>')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
^^^y |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 2 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
^^^q |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 2 }foo foo |
|
2022-07-11 16:22:17 -07:00
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
2022-07-11 17:28:56 -07:00
|
|
|
-- Pressing enter in ex mode should print the current line
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
^^^y |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 2 }foo foo |
|
2022-07-11 17:28:56 -07:00
|
|
|
^^^q |
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 2 }foo foo |
|
|
|
|
{8: 3 }foo foo |
|
2022-07-11 17:28:56 -07:00
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
2024-07-14 01:28:05 -07:00
|
|
|
-- The printed line should overwrite the colon
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
{8: 2 }foo foo |
|
|
|
|
^^^q |
|
|
|
|
{8: 2 }foo foo |
|
|
|
|
{8: 3 }foo foo |
|
|
|
|
{8: 4 }foo foo |
|
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
|
2022-07-11 16:22:17 -07:00
|
|
|
feed(':vi<CR>')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{8: 1 }foo bar |
|
|
|
|
{8: 2 }foo foo |
|
2024-07-14 01:28:05 -07:00
|
|
|
{8: 3 }foo foo |
|
|
|
|
{8: 4 }^foo foo |
|
|
|
|
{1:~ }|
|
2022-07-11 16:22:17 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2022-07-14 14:43:27 -07:00
|
|
|
|
|
|
|
it('pressing Ctrl-C in :append inside a loop in Ex mode does not hang', function()
|
|
|
|
local screen = Screen.new(60, 6)
|
|
|
|
feed('gQ')
|
|
|
|
feed('for i in range(1)<CR>')
|
|
|
|
feed('append<CR>')
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{3: }|
|
2022-07-14 14:43:27 -07:00
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
|
|
|
:for i in range(1) |
|
|
|
|
|
|
|
|
|
: append |
|
|
|
|
^ |
|
|
|
|
]])
|
|
|
|
feed('<C-C>')
|
2022-08-16 00:21:46 -07:00
|
|
|
poke_eventloop() -- Wait for input to be flushed
|
2022-07-14 14:43:27 -07:00
|
|
|
feed('foo<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
|
|
|
:for i in range(1) |
|
|
|
|
|
|
|
|
|
: append |
|
|
|
|
foo |
|
|
|
|
^ |
|
|
|
|
]])
|
|
|
|
feed('.<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
:for i in range(1) |
|
|
|
|
|
|
|
|
|
: append |
|
|
|
|
foo |
|
|
|
|
. |
|
|
|
|
: ^ |
|
|
|
|
]])
|
|
|
|
feed('endfor<CR>')
|
|
|
|
feed('vi<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
^foo |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*4
|
2022-07-14 14:43:27 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2022-02-07 23:47:23 -07:00
|
|
|
end)
|