robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

master
4.7 KiB221 linesraw
1local t = require('test.testutil')
2local Screen = require('test.functional.ui.screen')
3local n = require('test.functional.testnvim')()
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local eq = t.eq
7local eval = n.eval
8local feed = n.feed
9local clear = n.clear
10local expect = n.expect
11local command = n.command
12local fn = n.fn
13local api = n.api
14local insert = n.insert
15
16describe('macro recording with requeued key', function()
17  before_each(function()
18    clear({ args_rm = { '--cmd' } })
19  end)
20
21  it('mapped key does not corrupt the recording', function()
22    -- Typing over a Select-mode selection puts the key back for Insert mode (requeue_key()).
23    -- A key produced by a mapping is not "typed", so ungetchars() must not touch the recording.
24    command('snoremap Z Y')
25    insert('abc')
26    feed('qq0ghZ<Esc>q')
27    -- "Y" replaced the selected "a".
28    expect('Ybc')
29    -- The recording holds the typed keys: the "Y" mapping must not have eaten the recorded "Z".
30    eq('0ghZ\27', eval('@q'))
31  end)
32
33  it('at hit-enter prompt records the key ONCE', function()
34    -- A non-prompt key typed at the hit-enter prompt is put back to execute
35    -- as a normal command: it is consumed twice, but must be recorded once.
36    local screen = Screen.new(40, 6)
37    insert('abc')
38    feed('qq0')
39    feed(':echo "one\\ntwo"<CR>')
40    -- The prompt must actually engage (needs an attached UI).
41    screen:expect({ any = 'Press ENTER' })
42    feed('x')
43    feed('q')
44    expect('bc')
45    eq('0:echo "one\\ntwo"\rx', eval('@q'))
46    -- Replaying executes "x" once, not twice.
47    feed('@q')
48    expect('c')
49  end)
50end)
51
52describe('macros with default mappings', function()
53  before_each(function()
54    clear({ args_rm = { '--cmd' } })
55  end)
56
57  it('can be recorded and replayed', function()
58    feed('qiahello<esc>q')
59    expect('hello')
60    eq('ahello', eval('@i'))
61    feed('@i')
62    expect('hellohello')
63    eq('ahello', eval('@i'))
64  end)
65
66  it('applies maps', function()
67    command('imap x l')
68    command('nmap l a')
69    feed('qilxxx<esc>q')
70    expect('lll')
71    eq('lxxx', eval('@i'))
72    feed('@i')
73    expect('llllll')
74    eq('lxxx', eval('@i'))
75  end)
76
77  it('can be replayed with @@', function()
78    insert [[
79hello
80hello
81hello]]
82    feed [[gg]]
83
84    feed [[qqAFOO<esc>q]]
85    expect [[
86helloFOO
87hello
88hello]]
89
90    feed [[@q]]
91    expect [[
92helloFOOFOO
93hello
94hello]]
95
96    feed [[G3@@]]
97    expect [[
98helloFOOFOO
99hello
100helloFOOFOOFOO]]
101
102    feed [[ggV2j@@]]
103    expect [[
104helloFOOFOOFOO
105helloFOO
106helloFOOFOOFOOFOO]]
107  end)
108
109  it('can be replayed with @ in linewise Visual mode', function()
110    insert [[
111hello
112hello
113hello]]
114    feed [[gg]]
115
116    feed [[qqAFOO<esc>qu]]
117    expect [[
118hello
119hello
120hello]]
121
122    feed [[qwA123<esc>qu]]
123    expect [[
124hello
125hello
126hello]]
127
128    feed [[V3j@q]]
129    expect [[
130helloFOO
131helloFOO
132helloFOO]]
133
134    feed [[ggVj@w]]
135    expect [[
136helloFOO123
137helloFOO123
138helloFOO]]
139  end)
140
141  it('can be replayed with @ in blockwise Visual mode', function()
142    insert [[
143hello
144hello
145hello]]
146    feed [[gg]]
147
148    feed [[qqAFOO<esc>qu]]
149    expect [[
150hello
151hello
152hello]]
153
154    feed [[qwA123<esc>qu]]
155    expect [[
156hello
157hello
158hello]]
159
160    feed [[0<C-v>3jl@q]]
161    expect [[
162heFOOllo
163heFOOllo
164heFOOllo]]
165
166    feed [[gg0<C-v>j@w]]
167    expect [[
168h123eFOOllo
169h123eFOOllo
170heFOOllo]]
171  end)
172end)
173
174describe('immediately after a macro has finished executing,', function()
175  before_each(function()
176    clear()
177    command([[let @a = 'gg0']])
178  end)
179
180  describe('reg_executing() from RPC returns an empty string', function()
181    it('if the macro does not end with a <Nop> mapping', function()
182      feed('@a')
183      eq('', fn.reg_executing())
184    end)
185
186    it('if the macro ends with a <Nop> mapping', function()
187      command('nnoremap 0 <Nop>')
188      feed('@a')
189      eq('', fn.reg_executing())
190    end)
191  end)
192
193  describe('characters from a mapping are not treated as a part of the macro #18015', function()
194    before_each(function()
195      command('nnoremap s qa')
196    end)
197
198    it('if the macro does not end with a <Nop> mapping', function()
199      feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
200      eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
201      expect('')
202      eq('', eval('@a'))
203    end)
204
205    it('if the macro ends with a <Nop> mapping', function()
206      command('nnoremap 0 <Nop>')
207      feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
208      eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
209      expect('')
210      eq('', eval('@a'))
211    end)
212  end)
213end)
214
215describe('reg_recorded()', function()
216  before_each(clear)
217  it('returns the correct value', function()
218    feed [[qqyyq]]
219    eq('q', eval('reg_recorded()'))
220  end)
221end)