aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-02-23 06:57:07 +0800
committerGitHub <noreply@github.com>2024-02-23 06:57:07 +0800
commit564fd1cc51db4f5a954da236d1abad9d8acc3b6e (patch)
tree8ae78d3ec9a066e878bee42195d1da8896fa8fca /test
parentbb15fa035610bb9765ca16900703804a88faa3bb (diff)
parent1f75184b5cd4db7c250b1eb4d39ea06d3c906e5f (diff)
downloadrneovim-564fd1cc51db4f5a954da236d1abad9d8acc3b6e.tar.gz
rneovim-564fd1cc51db4f5a954da236d1abad9d8acc3b6e.tar.bz2
rneovim-564fd1cc51db4f5a954da236d1abad9d8acc3b6e.zip
Merge pull request #27578 from zeertzjq/vim-9.1.0120
vim-patch:9.1.{0120,0126,0127): add getregion() function
Diffstat (limited to 'test')
-rw-r--r--test/old/testdir/test_visual.vim164
1 files changed, 164 insertions, 0 deletions
diff --git a/test/old/testdir/test_visual.vim b/test/old/testdir/test_visual.vim
index 262a3a4fd9..88f587a83a 100644
--- a/test/old/testdir/test_visual.vim
+++ b/test/old/testdir/test_visual.vim
@@ -1634,4 +1634,168 @@ func Test_visual_substitute_visual()
bwipe!
endfunc
+func Test_visual_getregion()
+ new
+
+ call setline(1, ['one', 'two', 'three'])
+
+ " Visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>vjl", 'tx')
+ call assert_equal(['one', 'tw'], 'v'->getregion('.', 'v'))
+ call assert_equal(['one', 'tw'], '.'->getregion('v', 'v'))
+ call assert_equal(['o'], 'v'->getregion('v', 'v'))
+ call assert_equal(['w'], '.'->getregion('.', 'v'))
+ call assert_equal(['one', 'two'], '.'->getregion('v', 'V'))
+ call assert_equal(['on', 'tw'], '.'->getregion('v', "\<C-v>"))
+
+ " Line visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>Vl", 'tx')
+ call assert_equal(['one'], getregion('v', '.', 'V'))
+ call assert_equal(['one'], getregion('.', 'v', 'V'))
+ call assert_equal(['one'], getregion('v', 'v', 'V'))
+ call assert_equal(['one'], getregion('.', '.', 'V'))
+ call assert_equal(['on'], '.'->getregion('v', 'v'))
+ call assert_equal(['on'], '.'->getregion('v', "\<C-v>"))
+
+ " Block visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>ll", 'tx')
+ call assert_equal(['one'], getregion('v', '.', "\<C-v>"))
+ call assert_equal(['one'], getregion('.', 'v', "\<C-v>"))
+ call assert_equal(['o'], getregion('v', 'v', "\<C-v>"))
+ call assert_equal(['e'], getregion('.', '.', "\<C-v>"))
+ call assert_equal(['one'], '.'->getregion('v', 'V'))
+ call assert_equal(['one'], '.'->getregion('v', 'v'))
+
+ " Using Marks
+ call setpos("'a", [0, 2, 3, 0])
+ call cursor(1, 1)
+ call assert_equal(['one', 'two'], "'a"->getregion('.', 'v'))
+ call assert_equal(['one', 'two'], "."->getregion("'a", 'v'))
+ call assert_equal(['one', 'two'], "."->getregion("'a", 'V'))
+ call assert_equal(['two'], "'a"->getregion("'a", 'V'))
+ call assert_equal(['one', 'two'], "."->getregion("'a", "\<c-v>"))
+
+ " Multiline with line visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>Vjj", 'tx')
+ call assert_equal(['one', 'two', 'three'], getregion('v', '.', 'V'))
+
+ " Multiline with block visual mode
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>jj", 'tx')
+ call assert_equal(['o', 't', 't'], getregion('v', '.', "\<C-v>"))
+
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>jj$", 'tx')
+ call assert_equal(['one', 'two', 'three'], getregion('v', '.', "\<C-v>"))
+
+ " 'virtualedit'
+ set virtualedit=all
+ call cursor(1, 1)
+ call feedkeys("\<ESC>\<C-v>10ljj$", 'tx')
+ call assert_equal(['one ', 'two ', 'three '],
+ \ getregion('v', '.', "\<C-v>"))
+ set virtualedit&
+
+ " Invalid position
+ call cursor(1, 1)
+ call feedkeys("\<ESC>vjj$", 'tx')
+ call assert_fails("call getregion(1, 2, 'v')", 'E1174:')
+ call assert_fails("call getregion('.', {}, 'v')", 'E1174:')
+ call assert_equal([], getregion('', '.', 'v'))
+ call assert_equal([], getregion('.', '.', ''))
+ call feedkeys("\<ESC>", 'tx')
+ call assert_equal([], getregion('v', '.', 'v'))
+
+ " using an unset mark
+ call assert_equal([], "'z"->getregion(".", 'V'))
+ " using the wrong type
+ call assert_fails(':echo "."->getregion([],"V")', 'E1174:')
+ call assert_fails(':echo "."->getregion("$", {})', 'E1174:')
+ call assert_fails(':echo [0, 1, 1, 0]->getregion("$", "v")', 'E1174:')
+ " using a mark in another buffer
+ new
+ let newbuf = bufnr()
+ call setline(1, range(10))
+ normal! GmA
+ wincmd p
+ call assert_equal([newbuf, 10, 1, 0], getpos("'A"))
+ call assert_equal([], getregion(".", "'A", 'v'))
+ call assert_equal([], getregion("'A", ".", 'v'))
+ exe newbuf .. 'bwipe!'
+
+ bwipe!
+ " 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('v', '.', "\<C-v>"))
+ call cursor(1, 4)
+ call feedkeys("\<Esc>\<C-v>ljj", 'xt')
+ call assert_equal(['de', "\U0001f1e7", '45'],
+ \ getregion('v', '.', "\<C-v>"))
+ call cursor(1, 5)
+ call feedkeys("\<Esc>\<C-v>jj", 'xt')
+ call assert_equal(['e', ' ', '5'], getregion('v', '.', "\<C-v>"))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>vj", 'xt')
+ call assert_equal(['abcdefghijk«', "\U0001f1e6"], getregion('v', '.', "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("'a", "'b", "\<c-v>"))
+ call assert_equal(['k«', '🇦«🇧«🇨'], getregion("'a", "'b", "v"))
+ call assert_equal(['k«'], getregion("'a", "'c", "v"))
+
+ bwipe!
+
+ " 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('v', '.', 'v'))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$G", 'xt')
+ call assert_equal(["a\tc", "x\tz", ''], getregion('v', '.', 'v'))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"], getregion('v', '.', 'v'))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"], getregion('v', '.', "\<C-v>"))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$G", 'xt')
+ call assert_equal(["a", "x", '', ''], getregion('v', '.', "\<C-v>"))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>wv2j", 'xt')
+ call assert_equal(["c", "x\tz"], getregion('v', '.', 'v'))
+
+ " virtualedit
+ set virtualedit=all
+ call cursor(1, 1)
+ call feedkeys("\<Esc>2lv2lj", 'xt')
+ call assert_equal([' c', 'x '], getregion('v', '.', 'v'))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt')
+ call assert_equal([' ', ' ', ' '], getregion('v', '.', "\<C-v>"))
+ set virtualedit&
+ set selection&
+
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab