2015-03-21 16:47:39 -07:00
|
|
|
-- Test for Visual mode and operators.
|
|
|
|
--
|
|
|
|
-- Tests for the two kinds of operations: Those executed with Visual mode
|
|
|
|
-- followed by an operator and those executed via Operator-pending mode. Also
|
|
|
|
-- part of the test are mappings, counts, and repetition with the . command.
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local feed, insert, source = n.feed, n.insert, n.source
|
|
|
|
local clear, feed_command, expect = n.clear, n.feed_command, n.expect
|
2015-03-21 16:47:39 -07:00
|
|
|
|
|
|
|
-- Vim script user functions needed for some of the test cases.
|
|
|
|
local function source_user_functions()
|
|
|
|
source([[
|
|
|
|
function MoveToCap()
|
|
|
|
call search('\u', 'W')
|
|
|
|
endfunction
|
|
|
|
function SelectInCaps()
|
|
|
|
let [line1, col1] = searchpos('\u', 'bcnW')
|
|
|
|
let [line2, col2] = searchpos('.\u', 'nW')
|
|
|
|
call setpos("'<", [0, line1, col1, 0])
|
|
|
|
call setpos("'>", [0, line2, col2, 0])
|
|
|
|
normal! gv
|
|
|
|
endfunction
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
local function put_abc()
|
|
|
|
source([[
|
|
|
|
$put ='a'
|
|
|
|
$put ='b'
|
|
|
|
$put ='c']])
|
|
|
|
end
|
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
local function put_aaabbbccc()
|
|
|
|
source([[
|
|
|
|
$put ='aaa'
|
|
|
|
$put ='bbb'
|
|
|
|
$put ='ccc']])
|
|
|
|
end
|
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
local function define_select_mode_maps()
|
|
|
|
source([[
|
|
|
|
snoremap <lt>End> <End>
|
|
|
|
snoremap <lt>Down> <Down>
|
|
|
|
snoremap <lt>Del> <Del>]])
|
|
|
|
end
|
|
|
|
|
2015-03-21 16:47:39 -07:00
|
|
|
describe('Visual mode and operator', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
source_user_functions()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('simple change in Visual mode', function()
|
|
|
|
insert([[
|
|
|
|
apple banana cherry
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-03-21 16:47:39 -07:00
|
|
|
line 1 line 1
|
|
|
|
line 2 line 2
|
|
|
|
line 3 line 3
|
|
|
|
line 4 line 4
|
|
|
|
line 5 line 5
|
|
|
|
line 6 line 6
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-03-21 16:47:39 -07:00
|
|
|
xxxxxxxxxxxxx
|
|
|
|
xxxxxxxxxxxxx
|
|
|
|
xxxxxxxxxxxxx
|
|
|
|
xxxxxxxxxxxxx]])
|
|
|
|
|
|
|
|
-- Exercise characterwise Visual mode plus operator, with count and repeat.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^apple')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('lvld.l3vd.')
|
|
|
|
|
|
|
|
-- Same in linewise Visual mode.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^line 1')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('Vcnewline<esc>j.j2Vd.')
|
|
|
|
|
|
|
|
-- Same in blockwise Visual mode.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^xxxx')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('<c-v>jlc <esc>l.l2<c-v>c----<esc>l.')
|
|
|
|
|
|
|
|
-- Assert buffer contents.
|
|
|
|
expect([[
|
|
|
|
a y
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-03-21 16:47:39 -07:00
|
|
|
newline
|
|
|
|
newline
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-03-21 16:47:39 -07:00
|
|
|
--------x
|
|
|
|
--------x
|
|
|
|
xxxx--------x
|
|
|
|
xxxx--------x]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('Visual mode mapping', function()
|
|
|
|
insert([[
|
|
|
|
KiwiRaspberryDateWatermelonPeach
|
|
|
|
JambuRambutanBananaTangerineMango]])
|
|
|
|
|
|
|
|
-- Set up Visual mode mappings.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('vnoremap W /\\u/s-1<CR>')
|
|
|
|
feed_command('vnoremap iW :<C-U>call SelectInCaps()<CR>')
|
2015-03-21 16:47:39 -07:00
|
|
|
|
|
|
|
-- Do a simple change using the simple vmap, also with count and repeat.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^Kiwi')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('vWcNo<esc>l.fD2vd.')
|
|
|
|
|
|
|
|
-- Same, using the vmap that maps to an Ex command.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^Jambu')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('llviWc-<esc>l.l2vdl.')
|
|
|
|
|
|
|
|
-- Assert buffer contents.
|
|
|
|
expect([[
|
|
|
|
NoNoberryach
|
|
|
|
--ago]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('Operator-pending mode mapping', function()
|
|
|
|
insert([[
|
|
|
|
PineappleQuinceLoganberryOrangeGrapefruitKiwiZ
|
|
|
|
JuniperDurianZ
|
|
|
|
LemonNectarineZ]])
|
|
|
|
|
|
|
|
-- Set up Operator-pending mode mappings.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('onoremap W /\\u/<CR>')
|
|
|
|
feed_command('onoremap <Leader>W :<C-U>call MoveToCap()<CR>')
|
|
|
|
feed_command('onoremap iW :<C-U>call SelectInCaps()<CR>')
|
2015-03-21 16:47:39 -07:00
|
|
|
|
|
|
|
-- Do a simple change using the simple omap, also with count and repeat.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^Pineapple')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('cW-<esc>l.l2.l.')
|
|
|
|
|
|
|
|
-- Same, using the omap that maps to an Ex command to move the cursor.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^Juniper')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('g?\\WfD.')
|
|
|
|
|
|
|
|
-- Same, using the omap that uses Ex and Visual mode (custom text object).
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^Lemon')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed('yiWPlciWNew<esc>fr.')
|
|
|
|
|
|
|
|
-- Assert buffer contents.
|
|
|
|
expect([[
|
|
|
|
----Z
|
|
|
|
WhavcreQhevnaZ
|
|
|
|
LemonNewNewZ]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Vim patch 7.3.879 addressed a bug where typing ":" (the start of an Ex
|
|
|
|
-- command) in Operator-pending mode couldn't be aborted with Escape, the
|
|
|
|
-- change operation implied by the operator was always executed.
|
|
|
|
it('patch 7.3.879', function()
|
|
|
|
insert([[
|
|
|
|
zzzz
|
|
|
|
zzzz]])
|
|
|
|
|
|
|
|
-- Start a change operation consisting of operator plus Ex command, like
|
|
|
|
-- "dV:..." etc., then either
|
|
|
|
-- - complete the operation by pressing Enter: as a result the buffer is
|
|
|
|
-- changed, taking into account the v/V/<c-v> modifier given; or
|
|
|
|
-- - abort the operation by pressing Escape: no change to the buffer is
|
|
|
|
-- carried out.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('/^zzzz')
|
2015-03-21 16:47:39 -07:00
|
|
|
feed([[dV:<cr>dv:<cr>:set noma | let v:errmsg = ''<cr>]])
|
|
|
|
feed([[d:<cr>:set ma | put = v:errmsg =~# '^E21' ? 'ok' : 'failed'<cr>]])
|
|
|
|
feed([[dv:<esc>dV:<esc>:set noma | let v:errmsg = ''<cr>]])
|
|
|
|
feed([[d:<esc>:set ma | put = v:errmsg =~# '^E21' ? 'failed' : 'ok'<cr>]])
|
|
|
|
|
|
|
|
-- Assert buffer contents.
|
|
|
|
expect([[
|
|
|
|
zzz
|
|
|
|
ok
|
|
|
|
ok]])
|
|
|
|
end)
|
2016-02-06 17:58:52 -07:00
|
|
|
|
|
|
|
describe('characterwise visual mode:', function()
|
|
|
|
it('replace last line', function()
|
|
|
|
source([[
|
|
|
|
$put ='a'
|
|
|
|
let @" = 'x']])
|
|
|
|
feed('v$p')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
x]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kkv$d')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
b
|
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kkvj$d')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('v$d')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kvj$d')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('characterwise select mode:', function()
|
|
|
|
before_each(function()
|
|
|
|
define_select_mode_maps()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kkgh<End><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
b
|
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kkgh<Down><End><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('gh<End><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kgh<Down><End><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('linewise select mode:', function()
|
|
|
|
before_each(function()
|
|
|
|
define_select_mode_maps()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle line', function()
|
|
|
|
put_abc()
|
|
|
|
feed(' kkgH<Del> ')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
b
|
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete middle two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kkgH<Down><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
c]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('gH<Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a
|
|
|
|
b]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('delete last two line', function()
|
|
|
|
put_abc()
|
|
|
|
feed('kgH<Down><Del>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 17:58:52 -07:00
|
|
|
a]])
|
|
|
|
end)
|
|
|
|
end)
|
2016-02-06 20:12:07 -07:00
|
|
|
|
|
|
|
describe('v_p:', function()
|
|
|
|
it('replace last character with line register at middle line', function()
|
|
|
|
put_aaabbbccc()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('-2yank')
|
2016-02-06 20:12:07 -07:00
|
|
|
feed('k$vp')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
aaa
|
|
|
|
bb
|
|
|
|
aaa
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
ccc]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('replace last character with line register at middle line selecting newline', function()
|
|
|
|
put_aaabbbccc()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('-2yank')
|
2016-02-06 20:12:07 -07:00
|
|
|
feed('k$v$p')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
aaa
|
|
|
|
bb
|
|
|
|
aaa
|
|
|
|
ccc]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('replace last character with line register at last line', function()
|
|
|
|
put_aaabbbccc()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('-2yank')
|
2016-02-06 20:12:07 -07:00
|
|
|
feed('$vp')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
aaa
|
|
|
|
bbb
|
|
|
|
cc
|
|
|
|
aaa
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('replace last character with line register at last line selecting newline', function()
|
|
|
|
put_aaabbbccc()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('-2yank')
|
2016-02-06 20:12:07 -07:00
|
|
|
feed('$v$p')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 20:12:07 -07:00
|
|
|
aaa
|
|
|
|
bbb
|
|
|
|
cc
|
|
|
|
aaa
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
2016-02-06 21:14:43 -07:00
|
|
|
|
2017-09-24 11:42:48 -07:00
|
|
|
-- luacheck: ignore 613 (Trailing whitespace in a string)
|
2016-02-06 21:14:43 -07:00
|
|
|
it('gv in exclusive select mode after operation', function()
|
|
|
|
source([[
|
|
|
|
$put ='zzz '
|
|
|
|
$put ='äà '
|
|
|
|
set selection=exclusive]])
|
|
|
|
feed('kv3lyjv3lpgvcxxx<Esc>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 21:14:43 -07:00
|
|
|
zzz
|
|
|
|
xxx ]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('gv in exclusive select mode without operation', function()
|
|
|
|
source([[
|
|
|
|
$put ='zzz '
|
|
|
|
set selection=exclusive]])
|
|
|
|
feed('0v3l<Esc>gvcxxx<Esc>')
|
|
|
|
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-02-06 21:14:43 -07:00
|
|
|
xxx ]])
|
|
|
|
end)
|
2015-03-21 16:47:39 -07:00
|
|
|
end)
|