1
local helpers = require('test.functional.helpers')
2
local clear, eval, eq, insert = helpers.clear, helpers.eval, helpers.eq, helpers.insert
3
local feed, execute, expect, command = helpers.feed, helpers.execute, helpers.expect, helpers.command
4
local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq
6
describe('TextYankPost', function()
10
-- emulate the clipboard so system clipboard isn't affected
11
execute('let &rtp = "test/functional/fixtures,".&rtp')
13
execute('let g:count = 0')
14
execute('autocmd TextYankPost * let g:event = copy(v:event)')
15
execute('autocmd TextYankPost * let g:count += 1')
17
curbufmeths.set_lines(0, -1, true, {
23
it('is executed after yank and handles register types', function()
27
regcontents = { 'foo\nbar' },
31
eq(1, eval('g:count'))
33
-- v:event is cleared after the autocommand is done
34
eq({}, eval('v:event'))
39
regcontents = { 'baz ' },
43
eq(2, eval('g:count'))
48
regcontents = { 'foo', 'baz' },
50
regtype = "\0223" -- ^V + block width
52
eq(3, eval('g:count'))
55
it('makes v:event immutable', function()
59
regcontents = { 'foo\nbar' },
64
execute('set debug=msg')
65
-- the regcontents should not be changed without copy.
66
local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])')
68
neq(nil, string.find(err, ':E742:'))
70
-- can't mutate keys inside the autocommand
71
execute('autocmd! TextYankPost * let v:event.regcontents = 0')
72
status, err = pcall(command,'normal yy')
74
neq(nil, string.find(err, ':E46:'))
76
-- can't add keys inside the autocommand
77
execute('autocmd! TextYankPost * let v:event.mykey = 0')
78
status, err = pcall(command,'normal yy')
80
neq(nil, string.find(err, ':E742:'))
83
it('is not invoked recursively', function()
84
execute('autocmd TextYankPost * normal "+yy')
88
regcontents = { 'foo\nbar' },
92
eq(1, eval('g:count'))
93
eq({ 'foo\nbar' }, funcs.getreg('+',1,1))
96
it('is executed after delete and change', function()
100
regcontents = { 'foo' },
104
eq(1, eval('g:count'))
109
regcontents = { '\nbar' },
113
eq(2, eval('g:count'))
118
regcontents = { 'baz' },
122
eq(3, eval('g:count'))
125
it('is not executed after black-hole operation', function()
127
eq(0, eval('g:count'))
129
feed('"_cwgood<esc>')
130
eq(0, eval('g:count'))
135
eq(0, eval('g:count'))
138
eq(0, eval('g:count'))
141
it('gives the correct register name', function()
145
regcontents = { 'bar' },
153
regcontents = { 'foo\nbar' },
158
execute("set clipboard=unnamed")
160
-- regname still shows the name the user requested
164
regcontents = { 'foo\nbar' },
172
regcontents = { 'foo\nbar' },
178
it('works with Ex commands', function()
182
regcontents = { 'foo\nbar' },
186
eq(1, eval('g:count'))
191
regcontents = { 'baz text' },
195
eq(2, eval('g:count'))
200
regcontents = { 'baz ' },
204
eq(3, eval('g:count'))
206
execute('normal! dd')
209
regcontents = { 'baz text' },
213
eq(4, eval('g:count'))