2019-04-01 18:46:16 -07:00
|
|
|
" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
|
2018-02-20 13:44:37 -07:00
|
|
|
|
|
|
|
func Test_put_block()
|
|
|
|
new
|
|
|
|
call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x')
|
|
|
|
call feedkeys("\<C-V>y", 'x')
|
|
|
|
call feedkeys("gg0p", 'x')
|
|
|
|
call assert_equal("\u2500x", getline(1))
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
2018-02-21 13:56:47 -07:00
|
|
|
|
|
|
|
func Test_put_char_block()
|
|
|
|
new
|
|
|
|
call setline(1, ['Line 1', 'Line 2'])
|
|
|
|
f Xfile_put
|
|
|
|
" visually select both lines and put the cursor at the top of the visual
|
|
|
|
" selection and then put the buffer name over it
|
|
|
|
exe "norm! G0\<c-v>ke\"%p"
|
|
|
|
call assert_equal(['Xfile_put 1', 'Xfile_put 2'], getline(1,2))
|
|
|
|
bw!
|
|
|
|
endfunc
|
2018-03-04 07:53:50 -07:00
|
|
|
|
|
|
|
func Test_put_char_block2()
|
|
|
|
new
|
|
|
|
call setreg('a', ' one ', 'v')
|
|
|
|
call setline(1, ['Line 1', '', 'Line 3', ''])
|
|
|
|
" visually select the first 3 lines and put register a over it
|
|
|
|
exe "norm! ggl\<c-v>2j2l\"ap"
|
2020-10-18 09:17:42 -07:00
|
|
|
call assert_equal(['L one 1', '', 'L one 3', ''], getline(1, 4))
|
|
|
|
" clean up
|
|
|
|
bw!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_put_lines()
|
|
|
|
new
|
|
|
|
let a = [ getreg('a'), getregtype('a') ]
|
|
|
|
call setline(1, ['Line 1', 'Line2', 'Line 3', ''])
|
|
|
|
exe 'norm! gg"add"AddG""p'
|
|
|
|
call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1, '$'))
|
2018-03-04 07:53:50 -07:00
|
|
|
" clean up
|
|
|
|
bw!
|
2021-10-31 11:10:46 -07:00
|
|
|
eval a[0]->setreg('a', a[1])
|
2018-03-04 07:53:50 -07:00
|
|
|
endfunc
|
2018-08-28 21:06:37 -07:00
|
|
|
|
|
|
|
func Test_put_expr()
|
|
|
|
new
|
|
|
|
call setline(1, repeat(['A'], 6))
|
|
|
|
exec "1norm! \"=line('.')\<cr>p"
|
|
|
|
norm! j0.
|
|
|
|
norm! j0.
|
|
|
|
exec "4norm! \"=\<cr>P"
|
|
|
|
norm! j0.
|
|
|
|
norm! j0.
|
2020-10-18 09:17:42 -07:00
|
|
|
call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1, '$'))
|
2018-08-28 21:06:37 -07:00
|
|
|
bw!
|
|
|
|
endfunc
|
2019-04-01 18:18:42 -07:00
|
|
|
|
2019-04-01 18:46:16 -07:00
|
|
|
func Test_put_fails_when_nomodifiable()
|
|
|
|
new
|
2019-04-01 18:48:06 -07:00
|
|
|
setlocal nomodifiable
|
2019-04-01 18:46:16 -07:00
|
|
|
|
|
|
|
normal! yy
|
|
|
|
call assert_fails(':put', 'E21')
|
|
|
|
call assert_fails(':put!', 'E21')
|
|
|
|
call assert_fails(':normal! p', 'E21')
|
|
|
|
call assert_fails(':normal! gp', 'E21')
|
|
|
|
call assert_fails(':normal! P', 'E21')
|
|
|
|
call assert_fails(':normal! gP', 'E21')
|
|
|
|
|
|
|
|
if has('mouse')
|
|
|
|
set mouse=n
|
|
|
|
call assert_fails('execute "normal! \<MiddleMouse>"', 'E21')
|
|
|
|
set mouse&
|
|
|
|
endif
|
|
|
|
|
|
|
|
bwipeout!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
" A bug was discovered where the Normal mode put commands (e.g., "p") would
|
|
|
|
" output duplicate error messages when invoked in a non-modifiable buffer.
|
|
|
|
func Test_put_p_errmsg_nodup()
|
|
|
|
new
|
2019-04-01 18:48:06 -07:00
|
|
|
setlocal nomodifiable
|
2019-04-01 18:46:16 -07:00
|
|
|
|
|
|
|
normal! yy
|
|
|
|
|
|
|
|
func Capture_p_error()
|
|
|
|
redir => s:p_err
|
|
|
|
normal! p
|
|
|
|
redir END
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
silent! call Capture_p_error()
|
|
|
|
|
|
|
|
" Error message output within a function should be three lines (the function
|
|
|
|
" name, the line number, and the error message).
|
|
|
|
call assert_equal(3, count(s:p_err, "\n"))
|
|
|
|
|
|
|
|
delfunction Capture_p_error
|
|
|
|
bwipeout!
|
|
|
|
endfunc
|
2019-05-23 16:35:44 -07:00
|
|
|
|
|
|
|
func Test_put_p_indent_visual()
|
|
|
|
new
|
|
|
|
call setline(1, ['select this text', 'select that text'])
|
|
|
|
" yank "that" from the second line
|
|
|
|
normal 2Gwvey
|
|
|
|
" select "this" in the first line and put
|
|
|
|
normal k0wve[p
|
|
|
|
call assert_equal('select that text', getline(1))
|
|
|
|
call assert_equal('select that text', getline(2))
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
2021-11-26 04:16:04 -07:00
|
|
|
|
|
|
|
func Test_multibyte_op_end_mark()
|
|
|
|
new
|
|
|
|
call setline(1, 'тест')
|
|
|
|
normal viwdp
|
|
|
|
call assert_equal([0, 1, 7, 0], getpos("'>"))
|
|
|
|
call assert_equal([0, 1, 7, 0], getpos("']"))
|
|
|
|
|
|
|
|
normal Vyp
|
|
|
|
call assert_equal([0, 1, 2147483647, 0], getpos("'>"))
|
|
|
|
call assert_equal([0, 2, 7, 0], getpos("']"))
|
|
|
|
bwipe!
|
|
|
|
endfunc
|