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
|
local t = require('test.testutil')
local Screen = require('test.functional.ui.screen')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local eval = n.eval
local feed = n.feed
local clear = n.clear
local expect = n.expect
local command = n.command
local fn = n.fn
local api = n.api
local insert = n.insert
describe('macro recording with requeued key', function()
before_each(function()
clear({ args_rm = { '--cmd' } })
end)
it('mapped key does not corrupt the recording', function()
-- Typing over a Select-mode selection puts the key back for Insert mode (requeue_key()).
-- A key produced by a mapping is not "typed", so ungetchars() must not touch the recording.
command('snoremap Z Y')
insert('abc')
feed('qq0ghZ<Esc>q')
-- "Y" replaced the selected "a".
expect('Ybc')
-- The recording holds the typed keys: the "Y" mapping must not have eaten the recorded "Z".
eq('0ghZ\27', eval('@q'))
end)
it('at hit-enter prompt records the key ONCE', function()
-- A non-prompt key typed at the hit-enter prompt is put back to execute
-- as a normal command: it is consumed twice, but must be recorded once.
local screen = Screen.new(40, 6)
insert('abc')
feed('qq0')
feed(':echo "one\\ntwo"<CR>')
-- The prompt must actually engage (needs an attached UI).
screen:expect({ any = 'Press ENTER' })
feed('x')
feed('q')
expect('bc')
eq('0:echo "one\\ntwo"\rx', eval('@q'))
-- Replaying executes "x" once, not twice.
feed('@q')
expect('c')
end)
end)
describe('macros with default mappings', function()
before_each(function()
clear({ args_rm = { '--cmd' } })
end)
it('can be recorded and replayed', function()
feed('qiahello<esc>q')
expect('hello')
eq('ahello', eval('@i'))
feed('@i')
expect('hellohello')
eq('ahello', eval('@i'))
end)
it('applies maps', function()
command('imap x l')
command('nmap l a')
feed('qilxxx<esc>q')
expect('lll')
eq('lxxx', eval('@i'))
feed('@i')
expect('llllll')
eq('lxxx', eval('@i'))
end)
it('can be replayed with @@', function()
insert [[
hello
hello
hello]]
feed [[gg]]
feed [[qqAFOO<esc>q]]
expect [[
helloFOO
hello
hello]]
feed [[@q]]
expect [[
helloFOOFOO
hello
hello]]
feed [[G3@@]]
expect [[
helloFOOFOO
hello
helloFOOFOOFOO]]
feed [[ggV2j@@]]
expect [[
helloFOOFOOFOO
helloFOO
helloFOOFOOFOOFOO]]
end)
it('can be replayed with @ in linewise Visual mode', function()
insert [[
hello
hello
hello]]
feed [[gg]]
feed [[qqAFOO<esc>qu]]
expect [[
hello
hello
hello]]
feed [[qwA123<esc>qu]]
expect [[
hello
hello
hello]]
feed [[V3j@q]]
expect [[
helloFOO
helloFOO
helloFOO]]
feed [[ggVj@w]]
expect [[
helloFOO123
helloFOO123
helloFOO]]
end)
it('can be replayed with @ in blockwise Visual mode', function()
insert [[
hello
hello
hello]]
feed [[gg]]
feed [[qqAFOO<esc>qu]]
expect [[
hello
hello
hello]]
feed [[qwA123<esc>qu]]
expect [[
hello
hello
hello]]
feed [[0<C-v>3jl@q]]
expect [[
heFOOllo
heFOOllo
heFOOllo]]
feed [[gg0<C-v>j@w]]
expect [[
h123eFOOllo
h123eFOOllo
heFOOllo]]
end)
end)
describe('immediately after a macro has finished executing,', function()
before_each(function()
clear()
command([[let @a = 'gg0']])
end)
describe('reg_executing() from RPC returns an empty string', function()
it('if the macro does not end with a <Nop> mapping', function()
feed('@a')
eq('', fn.reg_executing())
end)
it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>')
feed('@a')
eq('', fn.reg_executing())
end)
end)
describe('characters from a mapping are not treated as a part of the macro #18015', function()
before_each(function()
command('nnoremap s qa')
end)
it('if the macro does not end with a <Nop> mapping', function()
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
expect('')
eq('', eval('@a'))
end)
it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>')
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
expect('')
eq('', eval('@a'))
end)
end)
end)
describe('reg_recorded()', function()
before_each(clear)
it('returns the correct value', function()
feed [[qqyyq]]
eq('q', eval('reg_recorded()'))
end)
end)
|