blob: e425c44f9f766b207e1451431dbab2a9c6d9b636 [file] [log] [blame]
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +02001" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
Bram Moolenaarc8129962017-01-22 20:04:51 +01002
3func Test_put_block()
4 if !has('multi_byte')
5 return
6 endif
7 new
8 call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x')
9 call feedkeys("\<C-V>y", 'x')
10 call feedkeys("gg0p", 'x')
11 call assert_equal("\u2500x", getline(1))
12 bwipe!
13endfunc
Bram Moolenaar9957a102017-01-23 21:53:53 +010014
15func Test_put_char_block()
16 new
17 call setline(1, ['Line 1', 'Line 2'])
18 f Xfile_put
19 " visually select both lines and put the cursor at the top of the visual
20 " selection and then put the buffer name over it
21 exe "norm! G0\<c-v>ke\"%p"
22 call assert_equal(['Xfile_put 1', 'Xfile_put 2'], getline(1,2))
23 bw!
24endfunc
Bram Moolenaar941c12d2017-01-24 19:55:43 +010025
26func Test_put_char_block2()
27 new
28 let a = [ getreg('a'), getregtype('a') ]
29 call setreg('a', ' one ', 'v')
30 call setline(1, ['Line 1', '', 'Line 3', ''])
31 " visually select the first 3 lines and put register a over it
32 exe "norm! ggl\<c-v>2j2l\"ap"
33 call assert_equal(['L one 1', '', 'L one 3', ''], getline(1,4))
34 " clean up
35 bw!
36 call setreg('a', a[0], a[1])
37endfunc
Bram Moolenaar18d90b92017-06-27 15:39:14 +020038
39func Test_put_lines()
40 new
41 let a = [ getreg('a'), getregtype('a') ]
42 call setline(1, ['Line 1', 'Line2', 'Line 3', ''])
43 exe 'norm! gg"add"AddG""p'
44 call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$'))
45 " clean up
46 bw!
47 call setreg('a', a[0], a[1])
48endfunc
Bram Moolenaar833093b2018-05-23 21:53:52 +020049
50func Test_put_expr()
51 new
52 call setline(1, repeat(['A'], 6))
53 exec "1norm! \"=line('.')\<cr>p"
54 norm! j0.
55 norm! j0.
56 exec "4norm! \"=\<cr>P"
57 norm! j0.
58 norm! j0.
59 call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$'))
60 bw!
61endfunc
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020062
63func Test_put_fails_when_nomodifiable()
64 new
65 set nomodifiable
66
67 normal! yy
68 call assert_fails(':put', 'E21')
69 call assert_fails(':put!', 'E21')
70 call assert_fails(':normal! p', 'E21')
71 call assert_fails(':normal! gp', 'E21')
72 call assert_fails(':normal! P', 'E21')
73 call assert_fails(':normal! gP', 'E21')
74
75 if has('mouse')
76 set mouse=n
77 call assert_fails('execute "normal! \<MiddleMouse>"', 'E21')
78 set mouse&
79 endif
80
81 bwipeout!
82endfunc
83
84" A bug was discovered where the Normal mode put commands (e.g., "p") would
85" output duplicate error messages when invoked in a non-modifiable buffer.
86func Test_put_p_errmsg_nodup()
87 new
88 set nomodifiable
89
90 normal! yy
91
92 func Capture_p_error()
93 redir => s:p_err
94 normal! p
95 redir END
96 endfunc
97
98 silent! call Capture_p_error()
99
100 " Error message output within a function should be three lines (the function
101 " name, the line number, and the error message).
102 call assert_equal(3, count(s:p_err, "\n"))
103
104 delfunction Capture_p_error
105 bwipeout!
106endfunc