summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_visual.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_visual.vim')
-rw-r--r--src/testdir/test_visual.vim341
1 files changed, 337 insertions, 4 deletions
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index 401a350..fd174a9 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -3,6 +3,7 @@
source shared.vim
source check.vim
source screendump.vim
+import './vim9.vim' as v9
func Test_block_shift_multibyte()
" Uses double-wide character.
@@ -1008,7 +1009,7 @@ endfunc
" Test for changing case
func Test_visual_change_case()
new
- " gUe must uppercase a whole word, also when ß changes to SS
+ " gUe must uppercase a whole word, also when ß changes to ẞ
exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r"
" gUfx must uppercase until x, inclusive.
exe "normal O- youßtußexu -\<Esc>0fogUfx\r"
@@ -1020,9 +1021,9 @@ func Test_visual_change_case()
exe "normal Oblah di\rdoh dut\<Esc>VkUj\r"
" Uppercase part of two lines
exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk"
- call assert_equal(['the YOUTUSSEUU end', '- yOUSSTUSSEXu -',
- \ 'THE YOUTUSSEUU END', '111THE YOUTUSSEUU END', 'BLAH DI', 'DOH DUT',
- \ '222the yoUTUSSEUU END', '333THE YOUTUßeuu end'], getline(2, '$'))
+ call assert_equal(['the YOUTUẞEUU end', '- yOUẞTUẞEXu -',
+ \ 'THE YOUTUẞEUU END', '111THE YOUTUẞEUU END', 'BLAH DI', 'DOH DUT',
+ \ '222the yoUTUẞEUU END', '333THE YOUTUßeuu end'], getline(2, '$'))
bwipe!
endfunc
@@ -1622,4 +1623,336 @@ func Test_visual_drag_out_of_window()
bwipe!
endfunc
+func Test_visual_substitute_visual()
+ new
+ call setline(1, ['one', 'two', 'three'])
+ call feedkeys("Gk\<C-V>j$:s/\\%V\\_.*\\%V/foobar\<CR>", 'tx')
+ call assert_equal(['one', 'foobar'], getline(1, '$'))
+ bwipe!
+endfunc
+
+func Test_visual_getregion()
+ let lines =<< trim END
+ new
+
+ call setline(1, ['one', 'two', 'three'])
+
+ #" Visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>vjl", 'tx')
+ call assert_equal(['one', 'tw'],
+ \ 'v'->getpos()->getregion(getpos('.')))
+ call assert_equal(['one', 'tw'],
+ \ '.'->getpos()->getregion(getpos('v')))
+ call assert_equal(['o'],
+ \ 'v'->getpos()->getregion(getpos('v')))
+ call assert_equal(['w'],
+ \ '.'->getpos()->getregion(getpos('.'), {'type': 'v' }))
+ call assert_equal(['one', 'two'],
+ \ getpos('.')->getregion(getpos('v'), {'type': 'V' }))
+ call assert_equal(['on', 'tw'],
+ \ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" }))
+
+ #" Line visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>Vl", 'tx')
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('v'), {'type': 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('v'), {'type': 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('.'), {'type': 'V' }))
+ call assert_equal(['on'],
+ \ getpos('.')->getregion(getpos('v'), {'type': 'v' }))
+ call assert_equal(['on'],
+ \ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" }))
+
+ #" Block visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>ll", 'tx')
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('v'), {'type': "\<C-v>" }))
+ call assert_equal(['o'],
+ \ getregion(getpos('v'), getpos('v'), {'type': "\<C-v>" }))
+ call assert_equal(['e'],
+ \ getregion(getpos('.'), getpos('.'), {'type': "\<C-v>" }))
+ call assert_equal(['one'],
+ \ '.'->getpos()->getregion(getpos('v'), {'type': 'V' }))
+ call assert_equal(['one'],
+ \ '.'->getpos()->getregion(getpos('v'), {'type': 'v' }))
+
+ #" Using Marks
+ call setpos("'a", [0, 2, 3, 0])
+ call cursor(1, 1)
+ call assert_equal(['one', 'two'],
+ \ "'a"->getpos()->getregion(getpos('.'), {'type': 'v' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), {'type': 'v' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), {'type': 'V' }))
+ call assert_equal(['two'],
+ \ "'a"->getpos()->getregion(getpos("'a"), {'type': 'V' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), {'type': "\<c-v>" }))
+
+ #" Using List
+ call cursor(1, 1)
+ call assert_equal(['one', 'two'],
+ \ [0, 2, 3, 0]->getregion(getpos('.'), {'type': 'v' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'v' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'V' }))
+ call assert_equal(['two'],
+ \ [0, 2, 3, 0]->getregion([0, 2, 3, 0], {'type': 'V' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': "\<c-v>" }))
+
+ #" Multiline with line visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>Vjj", 'tx')
+ call assert_equal(['one', 'two', 'three'],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'V' }))
+
+ #" Multiline with block visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>jj", 'tx')
+ call assert_equal(['o', 't', 't'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>jj$", 'tx')
+ call assert_equal(['one', 'two', 'three'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+
+ #" 'virtualedit'
+ set virtualedit=all
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>10ljj$", 'tx')
+ call assert_equal(['one ', 'two ', 'three '],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ set virtualedit&
+
+ #" using wrong types for positions
+ call cursor(1, 1)
+ call feedkeys("\<ESC>vjj$", 'tx')
+ call assert_fails("call getregion(1, 2)", 'E1211:')
+ call assert_fails("call getregion(getpos('.'), {})", 'E1211:')
+ call assert_fails(':echo "."->getpos()->getregion("$", [])', 'E1211:')
+
+ #" using invalid value for "type"
+ call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '' })", 'E475:')
+
+ #" using a mark from another buffer to current buffer
+ new
+ LET g:buf = bufnr()
+ call setline(1, range(10))
+ normal! GmA
+ wincmd p
+ call assert_equal([g:buf, 10, 1, 0], getpos("'A"))
+ call assert_equal([], getregion(getpos('.'), getpos("'A"), {'type': 'v' }))
+ call assert_equal([], getregion(getpos("'A"), getpos('.'), {'type': 'v' }))
+
+ #" using two marks from another buffer
+ wincmd p
+ normal! GmB
+ wincmd p
+ call assert_equal([g:buf, 10, 1, 0], getpos("'B"))
+ call assert_equal(['9'], getregion(getpos("'B"), getpos("'A"), {'type': 'v' }))
+
+ #" using two positions from another buffer
+ for type in ['v', 'V', "\<C-V>"]
+ for exclusive in [v:false, v:true]
+ call assert_equal(range(10)->mapnew('string(v:val)'),
+ \ getregion([g:buf, 1, 1, 0], [g:buf, 10, 2, 0],
+ \ {'type': type, 'exclusive': exclusive }))
+ call assert_equal(range(10)->mapnew('string(v:val)'),
+ \ getregion([g:buf, 10, 2, 0], [g:buf, 1, 1, 0],
+ \ {'type': type, 'exclusive': exclusive }))
+ endfor
+ endfor
+
+ #" using invalid positions in buffer
+ call assert_fails('call getregion([g:buf, 0, 1, 0], [g:buf, 10, 2, 0])', 'E966:')
+ call assert_fails('call getregion([g:buf, 10, 2, 0], [g:buf, 0, 1, 0])', 'E966:')
+ call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 11, 2, 0])', 'E966:')
+ call assert_fails('call getregion([g:buf, 11, 2, 0], [g:buf, 1, 1, 0])', 'E966:')
+ call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 0, 0])', 'E964:')
+ call assert_fails('call getregion([g:buf, 10, 0, 0], [g:buf, 1, 1, 0])', 'E964:')
+ call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 3, 0])', 'E964:')
+ call assert_fails('call getregion([g:buf, 10, 3, 0], [g:buf, 1, 1, 0])', 'E964:')
+
+ #" using invalid buffer
+ call assert_fails('call getregion([10000, 10, 1, 0], [10000, 10, 1, 0])', 'E681:')
+
+ exe $':{g:buf}bwipe!'
+ unlet g:buf
+ END
+ call v9.CheckLegacyAndVim9Success(lines)
+
+ bwipe!
+
+ let lines =<< trim END
+ #" Selection in starts or ends in the middle of a multibyte character
+ new
+ call setline(1, [
+ \ "abcdefghijk\u00ab",
+ \ "\U0001f1e6\u00ab\U0001f1e7\u00ab\U0001f1e8\u00ab\U0001f1e9",
+ \ "1234567890"
+ \ ])
+ call cursor(1, 3)
+ call feedkeys("\<Esc>\<C-v>ljj", 'xt')
+ call assert_equal(['cd', "\u00ab ", '34'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call cursor(1, 4)
+ call feedkeys("\<Esc>\<C-v>ljj", 'xt')
+ call assert_equal(['de', "\U0001f1e7", '45'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call cursor(1, 5)
+ call feedkeys("\<Esc>\<C-v>jj", 'xt')
+ call assert_equal(['e', ' ', '5'],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>vj", 'xt')
+ call assert_equal(['abcdefghijk«', "\U0001f1e6"],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+
+ #" marks on multibyte chars
+ :set selection=exclusive
+ call setpos("'a", [0, 1, 11, 0])
+ call setpos("'b", [0, 2, 16, 0])
+ call setpos("'c", [0, 2, 0, 0])
+ call cursor(1, 1)
+ call assert_equal(['ghijk', '🇨«🇩'],
+ \ getregion(getpos("'a"), getpos("'b"), {'type': "\<c-v>" }))
+ call assert_equal(['k«', '🇦«🇧«🇨'],
+ \ getregion(getpos("'a"), getpos("'b"), {'type': 'v' }))
+ call assert_equal(['k«'],
+ \ getregion(getpos("'a"), getpos("'c"), {'type': 'v' }))
+
+ #" use inclusive selection, although 'selection' is exclusive
+ call setpos("'a", [0, 1, 11, 0])
+ call setpos("'b", [0, 1, 1, 0])
+ call assert_equal(['abcdefghijk'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': "\<c-v>", 'exclusive': v:false }))
+ call assert_equal(['abcdefghij'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': "\<c-v>", 'exclusive': v:true }))
+ call assert_equal(['abcdefghijk'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': 'v', 'exclusive': 0 }))
+ call assert_equal(['abcdefghij'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': 'v', 'exclusive': 1 }))
+ call assert_equal(['abcdefghijk«'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': 'V', 'exclusive': 0 }))
+ call assert_equal(['abcdefghijk«'],
+ \ getregion(getpos("'a"), getpos("'b"),
+ \ {'type': 'V', 'exclusive': 1 }))
+ :set selection&
+ END
+ call v9.CheckLegacyAndVim9Success(lines)
+
+ bwipe!
+
+ let lines =<< trim END
+ #" Exclusive selection
+ new
+ set selection=exclusive
+ call setline(1, ["a\tc", "x\tz", '', ''])
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v2l", 'xt')
+ call assert_equal(["a\t"],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$G", 'xt')
+ call assert_equal(["a\tc", "x\tz", ''],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$G", 'xt')
+ call assert_equal(["a", "x", '', ''],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>wv2j", 'xt')
+ call assert_equal(["c", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+ set selection&
+
+ #" Exclusive selection 2
+ new
+ call setline(1, ["a\tc", "x\tz", '', ''])
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v2l", 'xt')
+ call assert_equal(["a\t"],
+ \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$G", 'xt')
+ call assert_equal(["a\tc", "x\tz", ''],
+ \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'),
+ \ {'exclusive': v:true, 'type': "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$G", 'xt')
+ call assert_equal(["a", "x", '', ''],
+ \ getregion(getpos('v'), getpos('.'),
+ \ {'exclusive': v:true, 'type': "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>wv2j", 'xt')
+ call assert_equal(["c", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true }))
+
+ #" virtualedit
+ set selection=exclusive
+ set virtualedit=all
+ call cursor(1, 1)
+ call feedkeys("\<Esc>2lv2lj", 'xt')
+ call assert_equal([' c', 'x '],
+ \ getregion(getpos('v'), getpos('.'), {'type': 'v' }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt')
+ call assert_equal([' ', ' ', ' '],
+ \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" }))
+ set virtualedit&
+ set selection&
+
+ bwipe!
+ END
+ call v9.CheckLegacyAndVim9Success(lines)
+endfunc
+
+func Test_getregion_invalid_buf()
+ new
+ help
+ call cursor(5, 7)
+ norm! mA
+ call cursor(5, 18)
+ norm! mB
+ call assert_equal(['Move around:'], getregion(getpos("'A"), getpos("'B")))
+ " close the help window
+ q
+ call assert_fails("call getregion(getpos(\"'A\"), getpos(\"'B\"))", 'E681:')
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab