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
|
-- ShaDa marks saving/reading support
local helpers = require('test.functional.helpers')(after_each)
local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq
local feed = helpers.feed
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear
local nvim_current_line = function()
return api.nvim_win_get_cursor(0)[1]
end
describe('ShaDa support code', function()
local testfilename = 'Xtestfile-functional-shada-marks'
local testfilename_2 = 'Xtestfile-functional-shada-marks-2'
local non_existent_testfilename = testfilename .. '.nonexistent'
before_each(function()
reset()
os.remove(non_existent_testfilename)
local fd = io.open(testfilename, 'w')
fd:write('test\n')
fd:write('test2\n')
fd:close()
fd = io.open(testfilename_2, 'w')
fd:write('test3\n')
fd:write('test4\n')
fd:close()
end)
after_each(function()
clear()
os.remove(testfilename)
os.remove(testfilename_2)
end)
it('is able to dump and read back global mark', function()
nvim_command('edit ' .. testfilename)
nvim_command('mark A')
nvim_command('2')
nvim_command('kB')
nvim_command('wshada')
reset()
nvim_command('rshada')
nvim_command('normal! `A')
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line())
nvim_command('normal! `B')
eq(2, nvim_current_line())
end)
it('does not dump global mark with `f0` in shada', function()
nvim_command('set shada+=f0')
nvim_command('edit ' .. testfilename)
nvim_command('mark A')
nvim_command('2')
nvim_command('kB')
nvim_command('wshada')
reset()
nvim_command('language C')
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
end)
it("does read back global mark even with `'0` and `f0` in shada", function()
nvim_command('edit ' .. testfilename)
nvim_command('mark A')
nvim_command('2')
nvim_command('kB')
nvim_command('wshada')
reset("set shada='0,f0")
nvim_command('language C')
nvim_command('normal! `A')
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line())
end)
it('is able to dump and read back local mark', function()
nvim_command('edit ' .. testfilename)
nvim_command('mark a')
nvim_command('2')
nvim_command('kb')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `a')
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line())
nvim_command('normal! `b')
eq(2, nvim_current_line())
end)
it('is able to dump and read back mark "', function()
nvim_command('edit ' .. testfilename)
nvim_command('2')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `"')
eq(2, nvim_current_line())
end)
it('is able to dump and read back mark " from a closed tab', function()
nvim_command('edit ' .. testfilename)
nvim_command('tabedit ' .. testfilename_2)
nvim_command('2')
nvim_command('q!')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('edit ' .. testfilename_2)
nvim_command('normal! `"')
eq(2, nvim_current_line())
end)
it('is able to populate v:oldfiles', function()
nvim_command('edit ' .. testfilename)
local tf_full = api.nvim_buf_get_name(0)
nvim_command('edit ' .. testfilename_2)
local tf_full_2 = api.nvim_buf_get_name(0)
expect_exit(nvim_command, 'qall')
reset()
local oldfiles = api.nvim_get_vvar('oldfiles')
table.sort(oldfiles)
eq(2, #oldfiles)
eq(testfilename, oldfiles[1]:sub(-#testfilename))
eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2))
eq(tf_full, oldfiles[1])
eq(tf_full_2, oldfiles[2])
nvim_command('rshada!')
oldfiles = api.nvim_get_vvar('oldfiles')
table.sort(oldfiles)
eq(2, #oldfiles)
eq(testfilename, oldfiles[1]:sub(-#testfilename))
eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2))
eq(tf_full, oldfiles[1])
eq(tf_full_2, oldfiles[2])
end)
it('is able to dump and restore jump list', function()
nvim_command('edit ' .. testfilename_2)
nvim_command('normal! G')
nvim_command('normal! gg')
nvim_command('edit ' .. testfilename)
nvim_command('normal! G')
nvim_command('normal! gg')
nvim_command('enew')
nvim_command('normal! gg')
local saved = exec_capture('jumps')
expect_exit(nvim_command, 'qall')
reset()
eq(saved, exec_capture('jumps'))
end)
it('when dumping jump list also dumps current position', function()
nvim_command('edit ' .. testfilename)
nvim_command('normal! G')
nvim_command('split ' .. testfilename_2)
nvim_command('normal! G')
nvim_command('wshada')
nvim_command('quit')
nvim_command('rshada')
nvim_command('normal! \15') -- <C-o>
eq(testfilename_2, fn.bufname('%'))
eq({ 2, 0 }, api.nvim_win_get_cursor(0))
end)
it('is able to dump and restore jump list with different times (slow!)', function()
nvim_command('edit ' .. testfilename_2)
nvim_command('sleep 2')
nvim_command('normal! G')
nvim_command('sleep 2')
nvim_command('normal! gg')
nvim_command('sleep 2')
nvim_command('edit ' .. testfilename)
nvim_command('sleep 2')
nvim_command('normal! G')
nvim_command('sleep 2')
nvim_command('normal! gg')
expect_exit(nvim_command, 'qall')
reset()
nvim_command('redraw')
nvim_command('edit ' .. testfilename)
eq(testfilename, fn.bufname('%'))
eq(1, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename, fn.bufname('%'))
eq(2, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename_2, fn.bufname('%'))
eq(1, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename_2, fn.bufname('%'))
eq(2, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename_2, fn.bufname('%'))
eq(2, nvim_current_line())
end)
it('is able to dump and restore change list', function()
nvim_command('edit ' .. testfilename)
nvim_command('normal! Gra')
nvim_command('normal! ggrb')
expect_exit(nvim_command, 'qall!')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! Gg;')
-- Note: without “sync” “commands” test has good changes to fail for unknown
-- reason (in first eq expected 1 is compared with 2). Any command inserted
-- causes this to work properly.
nvim_command('" sync')
eq(1, nvim_current_line())
nvim_command('normal! g;')
nvim_command('" sync 2')
eq(2, nvim_current_line())
end)
-- -c temporary sets lnum to zero to make `+/pat` work, so calling setpcmark()
-- during -c used to add item with zero lnum to jump list.
it('does not create incorrect file for non-existent buffers when writing from -c', function()
local argv = helpers.new_argv {
args_rm = {
'-i',
'--embed', -- no --embed
},
args = {
'-i',
api.nvim_get_var('tmpname'), -- Use same shada file as parent.
'--cmd',
'silent edit ' .. non_existent_testfilename,
'-c',
'qall',
},
}
eq('', fn.system(argv))
eq(0, exc_exec('rshada'))
end)
it('does not create incorrect file for non-existent buffers opened from -c', function()
local argv = helpers.new_argv {
args_rm = {
'-i',
'--embed', -- no --embed
},
args = {
'-i',
api.nvim_get_var('tmpname'), -- Use same shada file as parent.
'-c',
'silent edit ' .. non_existent_testfilename,
'-c',
'autocmd VimEnter * qall',
},
}
eq('', fn.system(argv))
eq(0, exc_exec('rshada'))
end)
it('updates deleted marks with :delmarks', function()
nvim_command('edit ' .. testfilename)
nvim_command('mark A')
nvim_command('mark a')
-- create a change to set the '.' mark,
-- since it can't be set via :mark
feed('ggifoobar<esc>')
nvim_command('wshada')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `A`a`.')
nvim_command('delmarks A a .')
nvim_command('wshada')
reset()
nvim_command('edit ' .. testfilename)
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
end)
it('updates deleted marks with :delmarks!', function()
nvim_command('edit ' .. testfilename)
nvim_command('mark A')
nvim_command('mark a')
feed('ggifoobar<esc>')
nvim_command('wshada')
reset()
nvim_command('edit ' .. testfilename)
nvim_command('normal! `A`a`.')
nvim_command('delmarks!')
nvim_command('wshada')
reset()
nvim_command('edit ' .. testfilename)
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
-- Make sure that uppercase marks aren't deleted.
nvim_command('normal! `A')
end)
end)
|