2017-06-14 19:51:50 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local eq = helpers.eq
|
|
|
|
local eval = helpers.eval
|
|
|
|
local feed = helpers.feed
|
2024-01-12 10:59:57 -07:00
|
|
|
local fn = helpers.fn
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2022-05-13 06:20:15 -07:00
|
|
|
local exec = helpers.exec
|
2017-06-14 19:51:50 -07:00
|
|
|
|
|
|
|
describe('search cmdline', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2022-12-03 18:09:00 -07:00
|
|
|
command('set nohlsearch inccommand=')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen = Screen.new(20, 3)
|
|
|
|
screen:attach()
|
|
|
|
screen:set_default_attr_ids({
|
2024-01-02 18:09:18 -07:00
|
|
|
inc = { reverse = true },
|
2019-10-13 11:18:22 -07:00
|
|
|
err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
|
|
|
more = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
|
|
|
tilde = { bold = true, foreground = Screen.colors.Blue1 },
|
2020-08-18 09:49:38 -07:00
|
|
|
hl = { background = Screen.colors.Yellow },
|
2017-06-14 19:51:50 -07:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function tenlines()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, {
|
2024-01-02 18:09:18 -07:00
|
|
|
' 1',
|
|
|
|
' 2 these',
|
|
|
|
' 3 the',
|
|
|
|
' 4 their',
|
|
|
|
' 5 there',
|
|
|
|
' 6 their',
|
|
|
|
' 7 the',
|
|
|
|
' 8 them',
|
|
|
|
' 9 these',
|
|
|
|
' 10 foobar',
|
2017-06-14 19:51:50 -07:00
|
|
|
})
|
|
|
|
command('1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it('history can be navigated with <C-N>/<C-P>', function()
|
|
|
|
tenlines()
|
|
|
|
command('set noincsearch')
|
|
|
|
feed('/foobar<CR>')
|
|
|
|
feed('/the<CR>')
|
|
|
|
eq('the', eval('@/'))
|
|
|
|
feed('/thes<C-P><C-P><CR>')
|
|
|
|
eq('foobar', eval('@/'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('can traverse matches', function()
|
|
|
|
before_each(tenlines)
|
|
|
|
local function forwarditer(wrapscan)
|
2024-01-02 18:09:18 -07:00
|
|
|
command('set incsearch ' .. wrapscan)
|
2017-06-14 19:51:50 -07:00
|
|
|
feed('/the')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 {inc:the} |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 0, 0, 0 }, fn.getpos('"'))
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
3 the |
|
|
|
|
4 {inc:the}ir |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
4 their |
|
|
|
|
5 {inc:the}re |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
5 there |
|
|
|
|
6 {inc:the}ir |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
6 their |
|
|
|
|
7 {inc:the} |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
7 the |
|
|
|
|
8 {inc:the}m |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
8 them |
|
|
|
|
9 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-26 05:49:15 -07:00
|
|
|
screen.bell = false
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
if wrapscan == 'wrapscan' then
|
|
|
|
screen:expect([[
|
|
|
|
2 {inc:the}se |
|
|
|
|
3 the |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
else
|
2024-01-02 18:09:18 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2017-06-14 19:51:50 -07:00
|
|
|
8 them |
|
|
|
|
9 {inc:the}se |
|
|
|
|
/the^ |
|
2024-01-02 18:09:18 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(true, screen.bell)
|
|
|
|
end,
|
|
|
|
}
|
2017-06-25 09:15:58 -07:00
|
|
|
feed('<CR>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 0, 0, 0 }, fn.getpos('"'))
|
2017-06-14 19:51:50 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function backiter(wrapscan)
|
2024-01-02 18:09:18 -07:00
|
|
|
command('set incsearch ' .. wrapscan)
|
2017-06-14 19:51:50 -07:00
|
|
|
command('$')
|
|
|
|
|
|
|
|
feed('?the')
|
|
|
|
screen:expect([[
|
|
|
|
9 {inc:the}se |
|
|
|
|
10 foobar |
|
|
|
|
?the^ |
|
|
|
|
]])
|
2017-06-26 05:49:15 -07:00
|
|
|
screen.bell = false
|
2017-06-14 19:51:50 -07:00
|
|
|
if wrapscan == 'wrapscan' then
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 {inc:the}se |
|
|
|
|
3 the |
|
|
|
|
?the^ |
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
2 ^these |
|
|
|
|
3 the |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
else
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2024-01-02 18:09:18 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2017-06-14 19:51:50 -07:00
|
|
|
9 {inc:the}se |
|
|
|
|
10 foobar |
|
|
|
|
?the^ |
|
2024-01-02 18:09:18 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(true, screen.bell)
|
|
|
|
end,
|
|
|
|
}
|
2017-06-14 19:51:50 -07:00
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
9 ^these |
|
|
|
|
10 foobar |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
|
|
|
screen:expect([[
|
|
|
|
9 {inc:the}se |
|
|
|
|
10 foobar |
|
|
|
|
?the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
8 {inc:the}m |
|
|
|
|
9 these |
|
|
|
|
?the^ |
|
|
|
|
]])
|
|
|
|
for i = 1, 6 do
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
-- Avoid sleep just before expect, otherwise expect will take the full
|
|
|
|
-- timeout
|
|
|
|
if i ~= 6 then
|
|
|
|
screen:sleep(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
screen:expect([[
|
|
|
|
2 {inc:the}se |
|
|
|
|
3 the |
|
|
|
|
?the^ |
|
|
|
|
]])
|
2017-06-26 05:49:15 -07:00
|
|
|
screen.bell = false
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
if wrapscan == 'wrapscan' then
|
|
|
|
screen:expect([[
|
|
|
|
9 {inc:the}se |
|
|
|
|
10 foobar |
|
|
|
|
?the^ |
|
|
|
|
]])
|
|
|
|
else
|
2024-01-02 18:09:18 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2017-06-14 19:51:50 -07:00
|
|
|
2 {inc:the}se |
|
|
|
|
3 the |
|
|
|
|
?the^ |
|
2024-01-02 18:09:18 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(true, screen.bell)
|
|
|
|
end,
|
|
|
|
}
|
2017-06-14 19:51:50 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-25 08:01:16 -07:00
|
|
|
it("using <C-G> and 'nowrapscan'", function()
|
2017-06-14 19:51:50 -07:00
|
|
|
forwarditer('nowrapscan')
|
|
|
|
end)
|
|
|
|
|
2017-06-25 08:01:16 -07:00
|
|
|
it("using <C-G> and 'wrapscan'", function()
|
2017-06-14 19:51:50 -07:00
|
|
|
forwarditer('wrapscan')
|
|
|
|
end)
|
|
|
|
|
2017-06-25 08:01:16 -07:00
|
|
|
it("using <C-T> and 'nowrapscan'", function()
|
2017-06-14 19:51:50 -07:00
|
|
|
backiter('nowrapscan')
|
|
|
|
end)
|
|
|
|
|
2017-06-25 08:01:16 -07:00
|
|
|
it("using <C-T> and 'wrapscan'", function()
|
2017-06-14 19:51:50 -07:00
|
|
|
backiter('wrapscan')
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('expands pattern with <C-L>', function()
|
|
|
|
tenlines()
|
|
|
|
command('set incsearch wrapscan')
|
|
|
|
|
|
|
|
feed('/the')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
feed('<C-L>')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:thes}e |
|
|
|
|
/thes^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
9 {inc:thes}e |
|
|
|
|
10 foobar |
|
|
|
|
/thes^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 {inc:thes}e |
|
|
|
|
3 the |
|
|
|
|
/thes^ |
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
2 ^these |
|
|
|
|
3 the |
|
|
|
|
/thes |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('1')
|
|
|
|
command('set nowrapscan')
|
|
|
|
feed('/the')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
feed('<C-L>')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:thes}e |
|
|
|
|
/thes^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
9 {inc:thes}e |
|
|
|
|
10 foobar |
|
|
|
|
/thes^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G><CR>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
9 ^these |
|
|
|
|
10 foobar |
|
|
|
|
/thes |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('reduces pattern with <BS> and keeps cursor position', function()
|
|
|
|
tenlines()
|
|
|
|
command('set incsearch wrapscan')
|
|
|
|
|
|
|
|
-- First match
|
|
|
|
feed('/thei')
|
|
|
|
screen:expect([[
|
2023-02-15 16:25:16 -07:00
|
|
|
3 the |
|
2017-06-14 19:51:50 -07:00
|
|
|
4 {inc:thei}r |
|
|
|
|
/thei^ |
|
|
|
|
]])
|
2017-06-25 09:15:58 -07:00
|
|
|
-- Match from initial cursor position when modifying search
|
2017-06-14 19:51:50 -07:00
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
2017-06-14 19:51:50 -07:00
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
-- New text advances to next match
|
|
|
|
feed('s')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
1 |
|
|
|
|
2 {inc:thes}e |
|
2017-06-14 19:51:50 -07:00
|
|
|
/thes^ |
|
|
|
|
]])
|
|
|
|
-- Stay on this match when deleting a character
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
2017-06-14 19:51:50 -07:00
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
-- Advance to previous match
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
9 {inc:the}se |
|
|
|
|
10 foobar |
|
2017-06-14 19:51:50 -07:00
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
-- Extend search to include next character
|
|
|
|
feed('<C-L>')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
9 {inc:thes}e |
|
|
|
|
10 foobar |
|
|
|
|
/thes^ |
|
2017-06-14 19:51:50 -07:00
|
|
|
]])
|
|
|
|
-- Deleting all characters resets the cursor position
|
|
|
|
feed('<BS><BS><BS><BS>')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 these |
|
|
|
|
/^ |
|
|
|
|
]])
|
|
|
|
feed('the')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
1 |
|
2017-06-14 19:51:50 -07:00
|
|
|
2 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
feed('\\>')
|
|
|
|
screen:expect([[
|
2017-06-25 09:15:58 -07:00
|
|
|
2 these |
|
2017-06-14 19:51:50 -07:00
|
|
|
3 {inc:the} |
|
|
|
|
/the\>^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2017-06-25 08:01:16 -07:00
|
|
|
it('can traverse matches in the same line with <C-G>/<C-T>', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, { ' 1', ' 2 these', ' 3 the theother' })
|
2017-06-14 19:51:50 -07:00
|
|
|
command('1')
|
|
|
|
command('set incsearch')
|
|
|
|
|
|
|
|
-- First match
|
|
|
|
feed('/the')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 {inc:the}se |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Next match, different line
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 {inc:the} theother |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Next match, same line
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 the {inc:the}other |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-G>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 the theo{inc:the}r |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Previous match, same line
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 the {inc:the}other |
|
|
|
|
/the^ |
|
|
|
|
]])
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 these |
|
|
|
|
3 {inc:the} theother |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Previous match, different line
|
2017-06-25 08:01:16 -07:00
|
|
|
feed('<C-T>')
|
2017-06-14 19:51:50 -07:00
|
|
|
screen:expect([[
|
|
|
|
2 {inc:the}se |
|
|
|
|
3 the theother |
|
|
|
|
/the^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-06-25 09:15:58 -07:00
|
|
|
|
|
|
|
it('keeps the view after deleting a char from the search', function()
|
2019-10-13 11:18:22 -07:00
|
|
|
screen:try_resize(20, 6)
|
2017-06-25 09:15:58 -07:00
|
|
|
tenlines()
|
|
|
|
|
|
|
|
feed('/foo')
|
|
|
|
screen:expect([[
|
|
|
|
6 their |
|
|
|
|
7 the |
|
|
|
|
8 them |
|
|
|
|
9 these |
|
|
|
|
10 {inc:foo}bar |
|
|
|
|
/foo^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
6 their |
|
|
|
|
7 the |
|
|
|
|
8 them |
|
|
|
|
9 these |
|
|
|
|
10 {inc:fo}obar |
|
|
|
|
/fo^ |
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
6 their |
|
|
|
|
7 the |
|
|
|
|
8 them |
|
|
|
|
9 these |
|
|
|
|
10 ^foobar |
|
|
|
|
/fo |
|
|
|
|
]])
|
2024-01-02 18:09:18 -07:00
|
|
|
eq({
|
|
|
|
lnum = 10,
|
|
|
|
leftcol = 0,
|
|
|
|
col = 4,
|
|
|
|
topfill = 0,
|
|
|
|
topline = 6,
|
|
|
|
coladd = 0,
|
|
|
|
skipcol = 0,
|
|
|
|
curswant = 4,
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.winsaveview())
|
2017-06-25 09:15:58 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('restores original view after failed search', function()
|
2019-10-13 11:18:22 -07:00
|
|
|
screen:try_resize(40, 3)
|
2017-06-25 09:15:58 -07:00
|
|
|
tenlines()
|
|
|
|
feed('0')
|
|
|
|
feed('/foo')
|
|
|
|
screen:expect([[
|
|
|
|
9 these |
|
|
|
|
10 {inc:foo}bar |
|
|
|
|
/foo^ |
|
|
|
|
]])
|
|
|
|
feed('<C-W>')
|
|
|
|
screen:expect([[
|
|
|
|
1 |
|
|
|
|
2 these |
|
|
|
|
/^ |
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
/ |
|
|
|
|
{err:E35: No previous regular expression} |
|
|
|
|
{more:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq({
|
|
|
|
lnum = 1,
|
|
|
|
leftcol = 0,
|
|
|
|
col = 0,
|
|
|
|
topfill = 0,
|
|
|
|
topline = 1,
|
|
|
|
coladd = 0,
|
|
|
|
skipcol = 0,
|
|
|
|
curswant = 0,
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.winsaveview())
|
2017-06-25 09:15:58 -07:00
|
|
|
end)
|
2018-02-01 15:50:12 -07:00
|
|
|
|
2022-12-03 18:09:00 -07:00
|
|
|
-- oldtest: Test_search_cmdline4().
|
2018-02-01 15:50:12 -07:00
|
|
|
it("CTRL-G with 'incsearch' and ? goes in the right direction", function()
|
2019-10-13 11:18:22 -07:00
|
|
|
screen:try_resize(40, 4)
|
2018-02-01 15:50:12 -07:00
|
|
|
command('enew!')
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, { ' 1 the first', ' 2 the second', ' 3 the third' })
|
2018-02-01 15:50:12 -07:00
|
|
|
command('set laststatus=0 shortmess+=s')
|
|
|
|
command('set incsearch')
|
|
|
|
command('$')
|
|
|
|
-- Send the input in chunks, so the cmdline logic regards it as
|
|
|
|
-- "interactive". This mimics Vim's test_override("char_avail").
|
|
|
|
-- (See legacy test: test_search.vim)
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 the first |
|
|
|
|
2 the second |
|
|
|
|
3 ^the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 ^the first |
|
|
|
|
2 the second |
|
|
|
|
3 the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-g>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 the first |
|
|
|
|
2 ^the second |
|
|
|
|
3 the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 ^the first |
|
|
|
|
2 the second |
|
|
|
|
3 the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 the first |
|
|
|
|
2 the second |
|
|
|
|
3 ^the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('$')
|
|
|
|
feed('?the')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<c-t>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2018-02-01 15:50:12 -07:00
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
1 the first |
|
|
|
|
2 ^the second |
|
|
|
|
3 the third |
|
|
|
|
?the |
|
|
|
|
]])
|
|
|
|
end)
|
2020-08-18 09:49:38 -07:00
|
|
|
|
2022-12-03 18:09:00 -07:00
|
|
|
-- oldtest: Test_incsearch_sort_dump().
|
2020-08-18 09:49:38 -07:00
|
|
|
it('incsearch works with :sort', function()
|
|
|
|
screen:try_resize(20, 4)
|
|
|
|
command('set incsearch hlsearch scrolloff=0')
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' })
|
2020-08-18 09:49:38 -07:00
|
|
|
|
|
|
|
feed(':sort ni u /on')
|
|
|
|
screen:expect([[
|
|
|
|
another {inc:on}e 2 |
|
|
|
|
that {hl:on}e 3 |
|
|
|
|
the {hl:on}e 1 |
|
|
|
|
:sort ni u /on^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
end)
|
2020-08-18 09:49:51 -07:00
|
|
|
|
2022-12-03 18:09:00 -07:00
|
|
|
-- oldtest: Test_incsearch_vimgrep_dump().
|
2020-08-18 09:49:51 -07:00
|
|
|
it('incsearch works with :vimgrep family', function()
|
|
|
|
screen:try_resize(30, 4)
|
|
|
|
command('set incsearch hlsearch scrolloff=0')
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' })
|
2020-08-18 09:49:51 -07:00
|
|
|
|
|
|
|
feed(':vimgrep on')
|
|
|
|
screen:expect([[
|
|
|
|
another {inc:on}e 2 |
|
|
|
|
that {hl:on}e 3 |
|
|
|
|
the {hl:on}e 1 |
|
|
|
|
:vimgrep on^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
feed(':vimg /on/ *.txt')
|
|
|
|
screen:expect([[
|
|
|
|
another {inc:on}e 2 |
|
|
|
|
that {hl:on}e 3 |
|
|
|
|
the {hl:on}e 1 |
|
|
|
|
:vimg /on/ *.txt^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
feed(':vimgrepadd "\\<LT>on')
|
|
|
|
screen:expect([[
|
|
|
|
another {inc:on}e 2 |
|
|
|
|
that {hl:on}e 3 |
|
|
|
|
the {hl:on}e 1 |
|
|
|
|
:vimgrepadd "\<on^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
feed(':lv "tha')
|
|
|
|
screen:expect([[
|
|
|
|
another one 2 |
|
|
|
|
{inc:tha}t one 3 |
|
|
|
|
the one 1 |
|
|
|
|
:lv "tha^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
feed(':lvimgrepa "the" **/*.txt')
|
|
|
|
screen:expect([[
|
|
|
|
ano{inc:the}r one 2 |
|
|
|
|
that one 3 |
|
|
|
|
{hl:the} one 1 |
|
|
|
|
:lvimgrepa "the" **/*.txt^ |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
end)
|
2022-12-03 18:09:00 -07:00
|
|
|
|
|
|
|
-- oldtest: Test_incsearch_substitute_dump2()
|
2023-08-11 15:32:13 -07:00
|
|
|
it('incsearch detects empty pattern properly vim-patch:8.2.2295', function()
|
2022-12-03 18:09:00 -07:00
|
|
|
screen:try_resize(70, 6)
|
|
|
|
exec([[
|
|
|
|
set incsearch hlsearch scrolloff=0
|
|
|
|
for n in range(1, 4)
|
|
|
|
call setline(n, "foo " . n)
|
|
|
|
endfor
|
|
|
|
call setline(5, "abc|def")
|
|
|
|
3
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed([[:%s/\vabc|]])
|
|
|
|
screen:expect([[
|
|
|
|
foo 1 |
|
|
|
|
foo 2 |
|
|
|
|
foo 3 |
|
|
|
|
foo 4 |
|
|
|
|
abc|def |
|
|
|
|
:%s/\vabc|^ |
|
|
|
|
]])
|
|
|
|
feed('<Esc>')
|
|
|
|
|
|
|
|
-- The following should not be highlighted
|
|
|
|
feed([[:1,5s/\v|]])
|
|
|
|
screen:expect([[
|
|
|
|
foo 1 |
|
|
|
|
foo 2 |
|
|
|
|
foo 3 |
|
|
|
|
foo 4 |
|
|
|
|
abc|def |
|
|
|
|
:1,5s/\v|^ |
|
|
|
|
]])
|
|
|
|
end)
|
2023-08-11 15:32:13 -07:00
|
|
|
|
|
|
|
-- oldtest: Test_incsearch_restore_view()
|
|
|
|
it('incsearch restores viewport', function()
|
|
|
|
screen:try_resize(20, 6)
|
|
|
|
exec([[
|
|
|
|
set incsearch nohlsearch
|
|
|
|
setlocal scrolloff=0 smoothscroll
|
|
|
|
call setline(1, [join(range(25), ' '), '', '', '', '', 'xxx'])
|
|
|
|
call feedkeys("2\<C-E>", 't')
|
|
|
|
]])
|
|
|
|
local s = [[
|
|
|
|
{tilde:<<<} 18 19 20 21 22 2|
|
|
|
|
^3 24 |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*4
|
2023-08-11 15:32:13 -07:00
|
|
|
]]
|
|
|
|
screen:expect(s)
|
2023-08-12 16:10:24 -07:00
|
|
|
feed('/xx')
|
|
|
|
screen:expect([[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*4
|
2023-08-12 16:10:24 -07:00
|
|
|
{inc:xx}x |
|
|
|
|
/xx^ |
|
|
|
|
]])
|
|
|
|
feed('x')
|
2023-08-11 15:32:13 -07:00
|
|
|
screen:expect([[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*4
|
2023-08-11 15:32:13 -07:00
|
|
|
{inc:xxx} |
|
|
|
|
/xxx^ |
|
|
|
|
]])
|
|
|
|
feed('<Esc>')
|
|
|
|
screen:expect(s)
|
|
|
|
end)
|
2017-06-14 19:51:50 -07:00
|
|
|
end)
|
2022-05-13 06:20:15 -07:00
|
|
|
|
|
|
|
describe('Search highlight', function()
|
|
|
|
before_each(clear)
|
2022-10-01 06:29:54 -07:00
|
|
|
|
|
|
|
-- oldtest: Test_hlsearch_dump()
|
|
|
|
it('beyond line end vim-patch:8.2.2542', function()
|
|
|
|
local screen = Screen.new(50, 6)
|
|
|
|
screen:attach()
|
|
|
|
exec([[
|
|
|
|
set hlsearch noincsearch cursorline
|
|
|
|
call setline(1, ["xxx", "xxx", "xxx"])
|
|
|
|
/.*
|
|
|
|
2
|
|
|
|
]])
|
|
|
|
feed([[/\_.*<CR>]])
|
|
|
|
screen:expect([[
|
2024-03-27 02:35:50 -07:00
|
|
|
{10:xxx } |*2
|
|
|
|
{10:^xxx }{21: }|
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2022-10-01 06:29:54 -07:00
|
|
|
/\_.* |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- oldtest: Test_hlsearch_and_visual()
|
|
|
|
it('is combined with Visual highlight vim-patch:8.2.2797', function()
|
2022-05-13 06:20:15 -07:00
|
|
|
local screen = Screen.new(40, 6)
|
|
|
|
screen:set_default_attr_ids({
|
2024-01-02 18:09:18 -07:00
|
|
|
[1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
|
|
|
[2] = { bold = true }, -- ModeMsg, Search
|
2024-02-14 16:49:39 -07:00
|
|
|
[3] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
|
2024-01-02 18:09:18 -07:00
|
|
|
[4] = { background = Screen.colors.Yellow, bold = true }, -- Search
|
2024-02-14 16:49:39 -07:00
|
|
|
[5] = { background = Screen.colors.LightGrey, bold = true, foreground = Screen.colors.Black },
|
2022-05-13 06:20:15 -07:00
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
exec([[
|
|
|
|
set hlsearch noincsearch
|
|
|
|
call setline(1, repeat(["xxx yyy zzz"], 3))
|
|
|
|
hi Search gui=bold
|
|
|
|
/yyy
|
|
|
|
call cursor(1, 6)
|
|
|
|
]])
|
|
|
|
feed('vjj')
|
|
|
|
screen:expect([[
|
|
|
|
xxx {4:y}{5:yy}{3: zzz} |
|
|
|
|
{3:xxx }{5:yyy}{3: zzz} |
|
|
|
|
{3:xxx }{5:y}{4:^yy} zzz |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2022-05-13 06:20:15 -07:00
|
|
|
{2:-- VISUAL --} |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|