1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
source check.vim
source screendump.vim
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
func Test_put_block_unicode()
new
call setreg('a', "À\nÀÀ\naaaaaaaaaaaa", "\<C-V>")
call setline(1, [' 1', ' 2', ' 3'])
exe "norm! \<C-V>jj\"ap"
let expected = ['À 1', 'ÀÀ 2', 'aaaaaaaaaaaa3']
call assert_equal(expected, getline(1, 3))
bw!
endfunc
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
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"
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, '$'))
" clean up
bw!
eval a[0]->setreg('a', a[1])
endfunc
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.
call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1, '$'))
bw!
endfunc
func Test_put_fails_when_nomodifiable()
new
setlocal nomodifiable
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
setlocal nomodifiable
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
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
" Test for deleting all the contents of a buffer with a put
func Test_put_visual_delete_all_lines()
new
call setline(1, ['one', 'two', 'three'])
let @r = ''
normal! VG"rgp
call assert_equal(1, line('$'))
close!
endfunc
func Test_gp_with_count_leaves_cursor_at_end()
new
call setline(1, '<---->')
call setreg('@', "foo\nbar", 'c')
normal 1G3|3gp
call assert_equal([0, 4, 4, 0], getpos("."))
call assert_equal(['<--foo', 'barfoo', 'barfoo', 'bar-->'], getline(1, '$'))
call assert_equal([0, 4, 3, 0], getpos("']"))
bwipe!
endfunc
func Test_p_with_count_leaves_mark_at_end()
new
call setline(1, '<---->')
call setreg('@', "start\nend", 'c')
normal 1G3|3p
call assert_equal([0, 1, 4, 0], getpos("."))
call assert_equal(['<--start', 'endstart', 'endstart', 'end-->'], getline(1, '$'))
call assert_equal([0, 4, 3, 0], getpos("']"))
bwipe!
endfunc
func Test_very_large_count()
new
" total put-length (21474837 * 100) brings 32 bit int overflow
let @" = repeat('x', 100)
call assert_fails('norm 21474837p', 'E1240:')
bwipe!
endfunc
func Test_very_large_count_64bit()
if v:sizeoflong < 8
throw 'Skipped: only works with 64 bit long ints'
endif
new
let @" = repeat('x', 100)
call assert_fails('norm 999999999p', 'E1240:')
bwipe!
endfunc
func Test_very_large_count_block()
new
" total put-length (21474837 * 100) brings 32 bit int overflow
call setline(1, repeat('x', 100))
exe "norm \<C-V>99ly"
call assert_fails('norm 21474837p', 'E1240:')
bwipe!
endfunc
func Test_very_large_count_block_64bit()
if v:sizeoflong < 8
throw 'Skipped: only works with 64 bit long ints'
endif
new
call setline(1, repeat('x', 100))
exe "norm \<C-V>$y"
call assert_fails('norm 999999999p', 'E1240:')
bwipe!
endfunc
func Test_put_above_first_line()
new
let @" = 'text'
silent! normal 0o00
0put
call assert_equal('text', getline(1))
bwipe!
endfunc
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, v:maxcol, 0], getpos("'>"))
call assert_equal([0, 2, 7, 0], getpos("']"))
bwipe!
endfunc
" this was putting a mark before the start of a line
func Test_put_empty_register()
new
norm yy
norm [Pi00ggv)s0
sil! norm [P
bwipe!
endfunc
" this was putting the end mark after the end of the line
func Test_put_visual_mode()
edit! SomeNewBuffer
set selection=exclusive
exe "norm o\t"
m0
sil! norm
p
p
bwipe!
set selection&
endfunc
func Test_put_visual_block_mode()
enew
exe "norm 0R\<CR>\<C-C>V"
sil exe "norm \<C-V>c \<MiddleDrag>"
set ve=all
sil norm vz=p
bwipe!
set ve=
endfunc
func Test_put_other_window()
CheckRunVimInTerminal
let lines =<< trim END
40vsplit
0put ='some text at the top'
put =' one more text'
put =' two more text'
put =' three more text'
put =' four more text'
END
call writefile(lines, 'Xtest_put_other', 'D')
let buf = RunVimInTerminal('-S Xtest_put_other', #{rows: 10})
call VerifyScreenDump(buf, 'Test_put_other_window_1', {})
call StopVimInTerminal(buf)
endfunc
func Test_put_in_last_displayed_line()
CheckRunVimInTerminal
let lines =<< trim END
vim9script
autocmd CursorMoved * eval line('w$')
@a = 'x'->repeat(&columns * 2 - 2)
range(&lines)->setline(1)
feedkeys('G"ap')
END
call writefile(lines, 'Xtest_put_last_line', 'D')
let buf = RunVimInTerminal('-S Xtest_put_last_line', #{rows: 10})
call VerifyScreenDump(buf, 'Test_put_in_last_displayed_line_1', {})
call StopVimInTerminal(buf)
endfunc
func Test_put_visual_replace_whole_fold()
new
let lines = repeat(['{{{1', 'foo', 'bar', ''], 2)
call setline(1, lines)
setlocal foldmethod=marker
call setreg('"', 'baz')
call setreg('1', '')
normal! Vp
call assert_equal("{{{1\nfoo\nbar\n\n", getreg('1'))
call assert_equal(['baz', '{{{1', 'foo', 'bar', ''], getline(1, '$'))
bwipe!
endfunc
func Test_put_visual_replace_fold_marker()
new
let lines = repeat(['{{{1', 'foo', 'bar', ''], 4)
call setline(1, lines)
setlocal foldmethod=marker
normal! Gkzo
call setreg('"', '{{{1')
call setreg('1', '')
normal! Vp
call assert_equal("{{{1\n", getreg('1'))
call assert_equal(lines, getline(1, '$'))
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
|