robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
40.5 KiB1287 linesraw
1-- ShaDa merging data support
2local t = require('test.testutil')
3local n = require('test.functional.testnvim')()
4local t_shada = require('test.functional.shada.testutil')
5
6local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
7local nvim_command, fn, eq = n.command, n.fn, t.eq
8local exec_capture = n.exec_capture
9local api = n.api
10local command = n.command
11
12local reset, clear, get_shada_rw = t_shada.reset, t_shada.clear, t_shada.get_shada_rw
13local read_shada_file = t_shada.read_shada_file
14
15local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-merging.shada')
16
17local mock_file_path = '/a/b/'
18if t.is_os('win') then
19  mock_file_path = 'C:/a/'
20end
21
22describe('ShaDa history merging code', function()
23  before_each(reset)
24  after_each(function()
25    clear()
26    os.remove(shada_fname)
27  end)
28
29  it('takes item with greater timestamp from Neovim instance when reading', function()
30    wshada('\004\001\009\147\000\196\002ab\196\001a')
31    command(sdrcmd())
32    wshada('\004\000\009\147\000\196\002ab\196\001b')
33    command(sdrcmd())
34    os.remove(shada_fname)
35    command('wshada! ' .. shada_fname)
36    local found = 0
37    for _, v in ipairs(read_shada_file(shada_fname)) do
38      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
39        eq(1, v.timestamp)
40        eq('a', v.value[3])
41        found = found + 1
42      end
43    end
44    eq(1, found)
45  end)
46
47  it('takes item with equal timestamp from Neovim instance when reading', function()
48    wshada('\004\000\009\147\000\196\002ab\196\001a')
49    command(sdrcmd())
50    wshada('\004\000\009\147\000\196\002ab\196\001b')
51    command(sdrcmd())
52    os.remove(shada_fname)
53    command('wshada! ' .. shada_fname)
54    local found = 0
55    for _, v in ipairs(read_shada_file(shada_fname)) do
56      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
57        eq(0, v.timestamp)
58        eq('a', v.value[3])
59        found = found + 1
60      end
61    end
62    eq(1, found)
63  end)
64
65  it('takes item with greater timestamp from ShaDa when reading', function()
66    wshada('\004\000\009\147\000\196\002ab\196\001a')
67    command(sdrcmd())
68    wshada('\004\001\009\147\000\196\002ab\196\001b')
69    command(sdrcmd())
70    os.remove(shada_fname)
71    command('wshada! ' .. shada_fname)
72    local found = 0
73    for _, v in ipairs(read_shada_file(shada_fname)) do
74      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
75        eq(1, v.timestamp)
76        eq('b', v.value[3])
77        found = found + 1
78      end
79    end
80    eq(1, found)
81  end)
82
83  it('takes item with greater timestamp from Neovim instance when writing', function()
84    wshada('\004\001\009\147\000\196\002ab\196\001a')
85    command(sdrcmd())
86    wshada('\004\000\009\147\000\196\002ab\196\001b')
87    command('wshada ' .. shada_fname)
88    local found = 0
89    for _, v in ipairs(read_shada_file(shada_fname)) do
90      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
91        eq(1, v.timestamp)
92        eq('a', v.value[3])
93        found = found + 1
94      end
95    end
96    eq(1, found)
97  end)
98
99  it('takes item with equal timestamp from Neovim instance when writing', function()
100    wshada('\004\000\009\147\000\196\002ab\196\001a')
101    command(sdrcmd())
102    wshada('\004\000\009\147\000\196\002ab\196\001b')
103    command('wshada ' .. shada_fname)
104    local found = 0
105    for _, v in ipairs(read_shada_file(shada_fname)) do
106      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
107        eq(0, v.timestamp)
108        eq('a', v.value[3])
109        found = found + 1
110      end
111    end
112    eq(1, found)
113  end)
114
115  it('takes item with greater timestamp from ShaDa when writing', function()
116    wshada('\004\000\009\147\000\196\002ab\196\001a')
117    command(sdrcmd())
118    wshada('\004\001\009\147\000\196\002ab\196\001b')
119    command('wshada ' .. shada_fname)
120    local found = 0
121    for _, v in ipairs(read_shada_file(shada_fname)) do
122      if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then
123        eq(1, v.timestamp)
124        eq('b', v.value[3])
125        found = found + 1
126      end
127    end
128    eq(1, found)
129  end)
130
131  it('correctly reads history items with messed up timestamps', function()
132    wshada(
133      '\004\010\009\147\000\196\002ab\196\001a'
134        .. '\004\010\009\147\000\196\002ac\196\001a'
135        .. '\004\005\009\147\000\196\002ad\196\001a'
136        .. '\004\100\009\147\000\196\002ae\196\001a'
137        .. '\004\090\009\147\000\196\002af\196\001a'
138    )
139    command(sdrcmd())
140    os.remove(shada_fname)
141    command('wshada! ' .. shada_fname)
142    local items = { 'ad', 'ab', 'ac', 'af', 'ae' }
143    for i, v in ipairs(items) do
144      eq(v, fn.histget(':', i))
145    end
146    local found = 0
147    for _, v in ipairs(read_shada_file(shada_fname)) do
148      if v.type == 4 and v.value[1] == 0 then
149        found = found + 1
150        eq(items[found], v.value[2])
151        eq('a', v.value[3])
152      end
153    end
154    eq(#items, found)
155  end)
156
157  it('correctly reorders history items with messed up timestamps when writing', function()
158    wshada(
159      '\004\010\009\147\000\196\002ab\196\001a'
160        .. '\004\010\009\147\000\196\002ac\196\001a'
161        .. '\004\005\009\147\000\196\002ad\196\001a'
162        .. '\004\100\009\147\000\196\002ae\196\001a'
163        .. '\004\090\009\147\000\196\002af\196\001a'
164    )
165    command('wshada ' .. shada_fname)
166    local items = { 'ad', 'ab', 'ac', 'af', 'ae' }
167    local found = 0
168    for _, v in ipairs(read_shada_file(shada_fname)) do
169      if v.type == 4 and v.value[1] == 0 then
170        found = found + 1
171        eq(items[found], v.value[2])
172        eq('a', v.value[3])
173      end
174    end
175    eq(#items, found)
176  end)
177
178  it('correctly merges history items with duplicate mid entry when writing', function()
179    -- Regression test: ShaDa code used to crash here.
180    -- Conditions:
181    -- 1. Entry which is duplicate to non-last entry.
182    -- 2. At least one more non-duplicate entry.
183    wshada(
184      '\004\000\009\147\000\196\002ab\196\001a'
185        .. '\004\001\009\147\000\196\002ac\196\001a'
186        .. '\004\002\009\147\000\196\002ad\196\001a'
187        .. '\004\003\009\147\000\196\002ac\196\001a'
188        .. '\004\004\009\147\000\196\002af\196\001a'
189        .. '\004\005\009\147\000\196\002ae\196\001a'
190        .. '\004\006\009\147\000\196\002ag\196\001a'
191        .. '\004\007\009\147\000\196\002ah\196\001a'
192        .. '\004\008\009\147\000\196\002ai\196\001a'
193    )
194    command('wshada ' .. shada_fname)
195    local items = { 'ab', 'ad', 'ac', 'af', 'ae', 'ag', 'ah', 'ai' }
196    local found = 0
197    for _, v in ipairs(read_shada_file(shada_fname)) do
198      if v.type == 4 and v.value[1] == 0 then
199        found = found + 1
200        eq(items[found], v.value[2])
201        eq('a', v.value[3])
202      end
203    end
204    eq(#items, found)
205  end)
206
207  it('correctly merges history items with duplicate adj entry when writing', function()
208    wshada(
209      '\004\000\009\147\000\196\002ab\196\001a'
210        .. '\004\001\009\147\000\196\002ac\196\001a'
211        .. '\004\002\009\147\000\196\002ad\196\001a'
212        .. '\004\003\009\147\000\196\002ad\196\001a'
213        .. '\004\004\009\147\000\196\002af\196\001a'
214        .. '\004\005\009\147\000\196\002ae\196\001a'
215        .. '\004\006\009\147\000\196\002ag\196\001a'
216        .. '\004\007\009\147\000\196\002ah\196\001a'
217        .. '\004\008\009\147\000\196\002ai\196\001a'
218    )
219    command('wshada ' .. shada_fname)
220    local items = { 'ab', 'ac', 'ad', 'af', 'ae', 'ag', 'ah', 'ai' }
221    local found = 0
222    for _, v in ipairs(read_shada_file(shada_fname)) do
223      if v.type == 4 and v.value[1] == 0 then
224        found = found + 1
225        eq(items[found], v.value[2])
226        eq('a', v.value[3])
227      end
228    end
229    eq(#items, found)
230  end)
231end)
232
233describe('ShaDa search pattern support code', function()
234  before_each(reset)
235  after_each(function()
236    clear()
237    os.remove(shada_fname)
238  end)
239
240  it('uses last search pattern with gt timestamp from instance when reading', function()
241    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
242    command(sdrcmd())
243    wshada('\002\000\011\130\162sX\194\162sp\196\001?')
244    command(sdrcmd())
245    eq('-', fn.getreg('/'))
246  end)
247
248  it('uses last search pattern with gt tstamp from file when reading with bang', function()
249    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
250    command(sdrcmd())
251    wshada('\002\000\011\130\162sX\194\162sp\196\001?')
252    command(sdrcmd(true))
253    eq('?', fn.getreg('/'))
254  end)
255
256  it('uses last search pattern with eq timestamp from instance when reading', function()
257    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
258    command(sdrcmd())
259    wshada('\002\001\011\130\162sX\194\162sp\196\001?')
260    command(sdrcmd())
261    eq('-', fn.getreg('/'))
262  end)
263
264  it('uses last search pattern with gt timestamp from file when reading', function()
265    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
266    command(sdrcmd())
267    wshada('\002\002\011\130\162sX\194\162sp\196\001?')
268    command(sdrcmd())
269    eq('?', fn.getreg('/'))
270  end)
271
272  it('uses last search pattern with gt timestamp from instance when writing', function()
273    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
274    command(sdrcmd())
275    wshada('\002\000\011\130\162sX\194\162sp\196\001?')
276    eq('-', fn.getreg('/'))
277    command('wshada ' .. shada_fname)
278    local found = 0
279    for _, v in ipairs(read_shada_file(shada_fname)) do
280      if v.type == 2 and v.value.sp == '-' then
281        found = found + 1
282      end
283    end
284    eq(1, found)
285  end)
286
287  it('uses last search pattern with eq timestamp from instance when writing', function()
288    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
289    command(sdrcmd())
290    wshada('\002\001\011\130\162sX\194\162sp\196\001?')
291    eq('-', fn.getreg('/'))
292    command('wshada ' .. shada_fname)
293    local found = 0
294    for _, v in ipairs(read_shada_file(shada_fname)) do
295      if v.type == 2 and v.value.sp == '-' then
296        found = found + 1
297      end
298    end
299    eq(1, found)
300  end)
301
302  it('uses last search pattern with gt timestamp from file when writing', function()
303    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
304    command(sdrcmd())
305    wshada('\002\002\011\130\162sX\194\162sp\196\001?')
306    eq('-', fn.getreg('/'))
307    command('wshada ' .. shada_fname)
308    local found = 0
309    for _, v in ipairs(read_shada_file(shada_fname)) do
310      if v.type == 2 and v.value.sp == '?' then
311        found = found + 1
312      end
313    end
314    eq(1, found)
315  end)
316
317  it('does not restore a search pattern cleared with :let @/ = ""', function()
318    command('let @/ = "foobar"')
319    command('wshada ' .. shada_fname)
320
321    reset({ shadafile = shada_fname })
322    eq('foobar', fn.getreg('/'))
323    command('let @/ = ""')
324    command('wshada ' .. shada_fname)
325
326    local found = 0
327    for _, v in ipairs(read_shada_file(shada_fname)) do
328      if v.type == 2 and v.value.sp == 'foobar' then
329        found = found + 1
330      end
331    end
332    eq(0, found)
333
334    reset({ shadafile = shada_fname })
335    eq('', fn.getreg('/'))
336  end)
337
338  it('keeps an on-disk search pattern that the instance never set', function()
339    wshada('\002\001\011\130\162sX\194\162sp\196\001-')
340    command('wshada ' .. shada_fname)
341    local found = 0
342    for _, v in ipairs(read_shada_file(shada_fname)) do
343      if v.type == 2 and v.value.sp == '-' then
344        found = found + 1
345      end
346    end
347    eq(1, found)
348  end)
349
350  it('uses last s/ pattern with gt timestamp from instance when reading', function()
351    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
352    command(sdrcmd())
353    wshada('\002\000\011\130\162ss\195\162sp\196\001?')
354    command(sdrcmd())
355    eq('-', fn.getreg('/'))
356  end)
357
358  it('uses last s/ pattern with gt timestamp from file when reading with !', function()
359    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
360    command(sdrcmd())
361    wshada('\002\000\011\130\162ss\195\162sp\196\001?')
362    command(sdrcmd(true))
363    eq('?', fn.getreg('/'))
364  end)
365
366  it('uses last s/ pattern with eq timestamp from instance when reading', function()
367    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
368    command(sdrcmd())
369    wshada('\002\001\011\130\162ss\195\162sp\196\001?')
370    command(sdrcmd())
371    eq('-', fn.getreg('/'))
372  end)
373
374  it('uses last s/ pattern with gt timestamp from file when reading', function()
375    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
376    command(sdrcmd())
377    wshada('\002\002\011\130\162ss\195\162sp\196\001?')
378    command(sdrcmd())
379    eq('?', fn.getreg('/'))
380  end)
381
382  it('uses last s/ pattern with gt timestamp from instance when writing', function()
383    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
384    command(sdrcmd())
385    wshada('\002\000\011\130\162ss\195\162sp\196\001?')
386    eq('-', fn.getreg('/'))
387    command('wshada ' .. shada_fname)
388    local found = 0
389    for _, v in ipairs(read_shada_file(shada_fname)) do
390      if v.type == 2 and v.value.sp == '-' then
391        found = found + 1
392      end
393    end
394    eq(1, found)
395  end)
396
397  it('uses last s/ pattern with eq timestamp from instance when writing', function()
398    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
399    command(sdrcmd())
400    wshada('\002\001\011\130\162ss\195\162sp\196\001?')
401    eq('-', fn.getreg('/'))
402    command('wshada ' .. shada_fname)
403    local found = 0
404    for _, v in ipairs(read_shada_file(shada_fname)) do
405      if v.type == 2 and v.value.sp == '-' then
406        found = found + 1
407      end
408    end
409    eq(1, found)
410  end)
411
412  it('uses last s/ pattern with gt timestamp from file when writing', function()
413    wshada('\002\001\011\130\162ss\195\162sp\196\001-')
414    command(sdrcmd())
415    wshada('\002\002\011\130\162ss\195\162sp\196\001?')
416    eq('-', fn.getreg('/'))
417    command('wshada ' .. shada_fname)
418    local found = 0
419    for _, v in ipairs(read_shada_file(shada_fname)) do
420      if v.type == 2 and v.value.sp == '?' then
421        found = found + 1
422      end
423    end
424    eq(1, found)
425  end)
426end)
427
428describe('ShaDa replacement string support code', function()
429  before_each(reset)
430  after_each(function()
431    clear()
432    os.remove(shada_fname)
433  end)
434
435  it('uses last replacement with gt timestamp from instance when reading', function()
436    wshada('\003\001\004\145\196\001-')
437    command(sdrcmd())
438    wshada('\003\000\004\145\196\001?')
439    command(sdrcmd())
440    nvim_command('s/.*/~')
441    eq('-', fn.getline('.'))
442    nvim_command('bwipeout!')
443  end)
444
445  it('uses last replacement with gt timestamp from file when reading with bang', function()
446    wshada('\003\001\004\145\196\001-')
447    command(sdrcmd())
448    wshada('\003\000\004\145\196\001?')
449    command(sdrcmd(true))
450    nvim_command('s/.*/~')
451    eq('?', fn.getline('.'))
452    nvim_command('bwipeout!')
453  end)
454
455  it('uses last replacement with eq timestamp from instance when reading', function()
456    wshada('\003\001\004\145\196\001-')
457    command(sdrcmd())
458    wshada('\003\001\004\145\196\001?')
459    command(sdrcmd())
460    nvim_command('s/.*/~')
461    eq('-', fn.getline('.'))
462    nvim_command('bwipeout!')
463  end)
464
465  it('uses last replacement with gt timestamp from file when reading', function()
466    wshada('\003\001\004\145\196\001-')
467    command(sdrcmd())
468    wshada('\003\002\004\145\196\001?')
469    command(sdrcmd())
470    nvim_command('s/.*/~')
471    eq('?', fn.getline('.'))
472    nvim_command('bwipeout!')
473  end)
474
475  it('uses last replacement with gt timestamp from instance when writing', function()
476    wshada('\003\001\004\145\196\001-')
477    command(sdrcmd())
478    wshada('\003\000\004\145\196\001?')
479    command('wshada ' .. shada_fname)
480    local found = 0
481    for _, v in ipairs(read_shada_file(shada_fname)) do
482      if v.type == 3 and v.value[1] == '-' then
483        found = found + 1
484      end
485    end
486    eq(1, found)
487  end)
488
489  it('uses last replacement with eq timestamp from instance when writing', function()
490    wshada('\003\001\004\145\196\001-')
491    command(sdrcmd())
492    wshada('\003\001\004\145\196\001?')
493    command('wshada ' .. shada_fname)
494    local found = 0
495    for _, v in ipairs(read_shada_file(shada_fname)) do
496      if v.type == 3 and v.value[1] == '-' then
497        found = found + 1
498      end
499    end
500    eq(1, found)
501  end)
502
503  it('uses last replacement with gt timestamp from file when writing', function()
504    wshada('\003\001\004\145\196\001-')
505    command(sdrcmd())
506    wshada('\003\002\004\145\196\001?')
507    command('wshada ' .. shada_fname)
508    local found = 0
509    for _, v in ipairs(read_shada_file(shada_fname)) do
510      if v.type == 3 and v.value[1] == '?' then
511        found = found + 1
512      end
513    end
514    eq(1, found)
515  end)
516end)
517
518describe('ShaDa marks support code', function()
519  before_each(reset)
520  after_each(function()
521    clear()
522    os.remove(shada_fname)
523  end)
524
525  it('uses last A mark with gt timestamp from instance when reading', function()
526    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
527    command(sdrcmd())
528    wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
529    command(sdrcmd())
530    nvim_command('normal! `A')
531    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
532  end)
533
534  it('can merge with file with mark 9 as the only numeric mark', function()
535    wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9')
536    command(sdrcmd())
537    nvim_command('normal! `9oabc')
538    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
539    command('wshada ' .. shada_fname)
540    local found = {}
541    for _, v in ipairs(read_shada_file(shada_fname)) do
542      if v.type == 7 and v.value.f == mock_file_path .. '-' then
543        local name = ('%c'):format(v.value.n)
544        found[name] = (found[name] or 0) + 1
545      end
546    end
547    eq({ ['0'] = 1, ['1'] = 1 }, found)
548  end)
549
550  it('removes duplicates while merging', function()
551    wshada(
552      '\007\001\014\130\161f\196\006'
553        .. mock_file_path
554        .. '-\161n9'
555        .. '\007\001\014\130\161f\196\006'
556        .. mock_file_path
557        .. '-\161n9'
558    )
559    command(sdrcmd())
560    command('wshada ' .. shada_fname)
561    local found = 0
562    for _, v in ipairs(read_shada_file(shada_fname)) do
563      if v.type == 7 and v.value.f == mock_file_path .. '-' then
564        print(require('test.format_string').format_luav(v))
565        found = found + 1
566      end
567    end
568    eq(1, found)
569  end)
570
571  it('does not leak when no append is performed due to too many marks', function()
572    wshada(
573      '\007\002\018\131\162mX\195\161f\196\006'
574        .. mock_file_path
575        .. 'a\161n0'
576        .. '\007\002\018\131\162mX\195\161f\196\006'
577        .. mock_file_path
578        .. 'b\161n1'
579        .. '\007\002\018\131\162mX\195\161f\196\006'
580        .. mock_file_path
581        .. 'c\161n2'
582        .. '\007\002\018\131\162mX\195\161f\196\006'
583        .. mock_file_path
584        .. 'd\161n3'
585        .. '\007\002\018\131\162mX\195\161f\196\006'
586        .. mock_file_path
587        .. 'e\161n4'
588        .. '\007\002\018\131\162mX\195\161f\196\006'
589        .. mock_file_path
590        .. 'f\161n5'
591        .. '\007\002\018\131\162mX\195\161f\196\006'
592        .. mock_file_path
593        .. 'g\161n6'
594        .. '\007\002\018\131\162mX\195\161f\196\006'
595        .. mock_file_path
596        .. 'h\161n7'
597        .. '\007\002\018\131\162mX\195\161f\196\006'
598        .. mock_file_path
599        .. 'i\161n8'
600        .. '\007\002\018\131\162mX\195\161f\196\006'
601        .. mock_file_path
602        .. 'j\161n9'
603        .. '\007\001\018\131\162mX\195\161f\196\006'
604        .. mock_file_path
605        .. 'k\161n9'
606    )
607    command(sdrcmd())
608    command('wshada ' .. shada_fname)
609    local found = {}
610    for _, v in ipairs(read_shada_file(shada_fname)) do
611      if v.type == 7 and v.value.f:sub(1, #mock_file_path) == mock_file_path then
612        found[#found + 1] = v.value.f:sub(#v.value.f)
613      end
614    end
615    eq({ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }, found)
616  end)
617
618  it('does not leak when last mark in file removes some of the earlier ones', function()
619    wshada(
620      '\007\002\018\131\162mX\195\161f\196\006'
621        .. mock_file_path
622        .. 'a\161n0'
623        .. '\007\002\018\131\162mX\195\161f\196\006'
624        .. mock_file_path
625        .. 'b\161n1'
626        .. '\007\002\018\131\162mX\195\161f\196\006'
627        .. mock_file_path
628        .. 'c\161n2'
629        .. '\007\002\018\131\162mX\195\161f\196\006'
630        .. mock_file_path
631        .. 'd\161n3'
632        .. '\007\002\018\131\162mX\195\161f\196\006'
633        .. mock_file_path
634        .. 'e\161n4'
635        .. '\007\002\018\131\162mX\195\161f\196\006'
636        .. mock_file_path
637        .. 'f\161n5'
638        .. '\007\002\018\131\162mX\195\161f\196\006'
639        .. mock_file_path
640        .. 'g\161n6'
641        .. '\007\002\018\131\162mX\195\161f\196\006'
642        .. mock_file_path
643        .. 'h\161n7'
644        .. '\007\002\018\131\162mX\195\161f\196\006'
645        .. mock_file_path
646        .. 'i\161n8'
647        .. '\007\002\018\131\162mX\195\161f\196\006'
648        .. mock_file_path
649        .. 'j\161n9'
650        .. '\007\003\018\131\162mX\195\161f\196\006'
651        .. mock_file_path
652        .. 'k\161n9'
653    )
654    command(sdrcmd())
655    command('wshada ' .. shada_fname)
656    local found = {}
657    for _, v in ipairs(read_shada_file(shada_fname)) do
658      if v.type == 7 and v.value.f:sub(1, #mock_file_path) == mock_file_path then
659        found[#found + 1] = v.value.f:sub(#v.value.f)
660      end
661    end
662    eq({ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k' }, found)
663  end)
664
665  it('uses last A mark with gt timestamp from file when reading with !', function()
666    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
667    command(sdrcmd())
668    wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
669    command(sdrcmd(true))
670    nvim_command('normal! `A')
671    eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
672  end)
673
674  it('uses last A mark with eq timestamp from instance when reading', function()
675    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
676    command(sdrcmd())
677    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
678    command(sdrcmd())
679    nvim_command('normal! `A')
680    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
681  end)
682
683  it('uses last A mark with gt timestamp from file when reading', function()
684    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
685    command(sdrcmd())
686    wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
687    command(sdrcmd())
688    nvim_command('normal! `A')
689    eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
690  end)
691
692  it('uses last A mark with gt timestamp from instance when writing', function()
693    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
694    command(sdrcmd())
695    wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
696    nvim_command('normal! `A')
697    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
698    command('wshada ' .. shada_fname)
699    local found = {}
700    for _, v in ipairs(read_shada_file(shada_fname)) do
701      if v.type == 7 and v.value.f == mock_file_path .. '-' then
702        local name = ('%c'):format(v.value.n)
703        found[name] = (found[name] or 0) + 1
704      end
705    end
706    eq({ ['0'] = 1, A = 1 }, found)
707  end)
708
709  it('uses last A mark with eq timestamp from instance when writing', function()
710    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
711    command(sdrcmd())
712    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
713    nvim_command('normal! `A')
714    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
715    command('wshada ' .. shada_fname)
716    local found = {}
717    for _, v in ipairs(read_shada_file(shada_fname)) do
718      if v.type == 7 and v.value.f == mock_file_path .. '-' then
719        local name = ('%c'):format(v.value.n)
720        found[name] = (found[name] or 0) + 1
721      end
722    end
723    eq({ ['0'] = 1, A = 1 }, found)
724  end)
725
726  it('uses last A mark with gt timestamp from file when writing', function()
727    wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA')
728    command(sdrcmd())
729    wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
730    nvim_command('normal! `A')
731    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
732    command('wshada ' .. shada_fname)
733    local found = {}
734    for _, v in ipairs(read_shada_file(shada_fname)) do
735      if v.type == 7 then
736        local name = ('%c'):format(v.value.n)
737        local _t = found[name] or {}
738        _t[v.value.f] = (_t[v.value.f] or 0) + 1
739        found[name] = _t
740      end
741    end
742    eq({ ['0'] = { [mock_file_path .. '-'] = 1 }, A = { [mock_file_path .. '?'] = 1 } }, found)
743  end)
744
745  it('uses last a mark with gt timestamp from instance when reading', function()
746    nvim_command('edit ' .. mock_file_path .. '-')
747    fn.setline(1, { '-', '?' })
748    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
749    command(sdrcmd())
750    wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
751    command(sdrcmd())
752    nvim_command('normal! `a')
753    eq('-', fn.getline('.'))
754  end)
755
756  it('uses last a mark with gt timestamp from file when reading with !', function()
757    nvim_command('edit ' .. mock_file_path .. '-')
758    fn.setline(1, { '-', '?' })
759    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
760    command(sdrcmd())
761    wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
762    command(sdrcmd(true))
763    nvim_command('normal! `a')
764    eq('?', fn.getline('.'))
765  end)
766
767  it('uses last a mark with eq timestamp from instance when reading', function()
768    nvim_command('edit ' .. mock_file_path .. '-')
769    fn.setline(1, { '-', '?' })
770    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
771    command(sdrcmd())
772    wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
773    command(sdrcmd())
774    nvim_command('normal! `a')
775    eq('-', fn.getline('.'))
776  end)
777
778  it('uses last a mark with gt timestamp from file when reading', function()
779    nvim_command('edit ' .. mock_file_path .. '-')
780    fn.setline(1, { '-', '?' })
781    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
782    command(sdrcmd())
783    wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
784    command(sdrcmd())
785    nvim_command('normal! `a')
786    eq('?', fn.getline('.'))
787  end)
788
789  it('uses last a mark with gt timestamp from instance when writing', function()
790    nvim_command('edit ' .. mock_file_path .. '-')
791    fn.setline(1, { '-', '?' })
792    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
793    command(sdrcmd())
794    wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
795    nvim_command('normal! `a')
796    eq('-', fn.getline('.'))
797    command('wshada ' .. shada_fname)
798    local found = 0
799    for _, v in ipairs(read_shada_file(shada_fname)) do
800      if
801        v.type == 10
802        and v.value.f == '' .. mock_file_path .. '-'
803        and v.value.n == ('a'):byte()
804      then
805        eq(true, v.value.l == 1 or v.value.l == nil)
806        found = found + 1
807      end
808    end
809    eq(1, found)
810  end)
811
812  it('uses last a mark with eq timestamp from instance when writing', function()
813    nvim_command('edit ' .. mock_file_path .. '-')
814    fn.setline(1, { '-', '?' })
815    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
816    command(sdrcmd())
817    wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
818    nvim_command('normal! `a')
819    eq('-', fn.getline('.'))
820    command('wshada ' .. shada_fname)
821    local found = 0
822    for _, v in ipairs(read_shada_file(shada_fname)) do
823      if
824        v.type == 10
825        and v.value.f == '' .. mock_file_path .. '-'
826        and v.value.n == ('a'):byte()
827      then
828        eq(true, v.value.l == 1 or v.value.l == nil)
829        found = found + 1
830      end
831    end
832    eq(1, found)
833  end)
834
835  it('uses last a mark with gt timestamp from file when writing', function()
836    nvim_command('edit ' .. mock_file_path .. '-')
837    fn.setline(1, { '-', '?' })
838    wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na')
839    command(sdrcmd())
840    wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
841    nvim_command('normal! `a')
842    eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
843    command('wshada ' .. shada_fname)
844    local found = 0
845    for _, v in ipairs(read_shada_file(shada_fname)) do
846      if
847        v.type == 10
848        and v.value.f == '' .. mock_file_path .. '-'
849        and v.value.n == ('a'):byte()
850      then
851        eq(2, v.value.l)
852        found = found + 1
853      end
854    end
855    eq(1, found)
856  end)
857end)
858
859describe('ShaDa registers support code', function()
860  before_each(reset)
861  after_each(function()
862    clear()
863    os.remove(shada_fname)
864  end)
865
866  it('uses last a register with gt timestamp from instance when reading', function()
867    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
868    command(sdrcmd())
869    wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
870    command(sdrcmd())
871    eq('-', fn.getreg('a'))
872  end)
873
874  it('uses last a register with gt timestamp from file when reading with !', function()
875    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
876    command(sdrcmd())
877    wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
878    command(sdrcmd(true))
879    eq('?', fn.getreg('a'))
880  end)
881
882  it('uses last a register with eq timestamp from instance when reading', function()
883    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
884    command(sdrcmd())
885    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?')
886    command(sdrcmd())
887    eq('-', fn.getreg('a'))
888  end)
889
890  it('uses last a register with gt timestamp from file when reading', function()
891    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
892    command(sdrcmd())
893    wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?')
894    command(sdrcmd())
895    eq('?', fn.getreg('a'))
896  end)
897
898  it('uses last a register with gt timestamp from instance when writing', function()
899    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
900    command(sdrcmd())
901    wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?')
902    eq('-', fn.getreg('a'))
903    command('wshada ' .. shada_fname)
904    local found = 0
905    for _, v in ipairs(read_shada_file(shada_fname)) do
906      if v.type == 5 and v.value.n == ('a'):byte() then
907        eq({ '-' }, v.value.rc)
908        found = found + 1
909      end
910    end
911    eq(1, found)
912  end)
913
914  it('uses last a register with eq timestamp from instance when writing', function()
915    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
916    command(sdrcmd())
917    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?')
918    eq('-', fn.getreg('a'))
919    command('wshada ' .. shada_fname)
920    local found = 0
921    for _, v in ipairs(read_shada_file(shada_fname)) do
922      if v.type == 5 and v.value.n == ('a'):byte() then
923        eq({ '-' }, v.value.rc)
924        found = found + 1
925      end
926    end
927    eq(1, found)
928  end)
929
930  it('uses last a register with gt timestamp from file when writing', function()
931    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
932    command(sdrcmd())
933    wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?')
934    eq('-', fn.getreg('a'))
935    command('wshada ' .. shada_fname)
936    local found = 0
937    for _, v in ipairs(read_shada_file(shada_fname)) do
938      if v.type == 5 and v.value.n == ('a'):byte() then
939        eq({ '?' }, v.value.rc)
940        found = found + 1
941      end
942    end
943    eq(1, found)
944  end)
945
946  it('does not restore a register cleared with :let @a = ""', function()
947    command('let @a = "hello"')
948    command('wshada ' .. shada_fname)
949
950    reset({ shadafile = shada_fname })
951    eq('hello', fn.getreg('a'))
952    command('let @a = ""')
953    command('wshada ' .. shada_fname)
954
955    local found = 0
956    for _, v in ipairs(read_shada_file(shada_fname)) do
957      if v.type == 5 and v.value.n == ('a'):byte() then
958        found = found + 1
959      end
960    end
961    eq(0, found)
962
963    reset({ shadafile = shada_fname })
964    eq('', fn.getreg('a'))
965  end)
966
967  it('keeps an on-disk register that the instance never set', function()
968    wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
969    command('wshada ' .. shada_fname)
970    local found = 0
971    for _, v in ipairs(read_shada_file(shada_fname)) do
972      if v.type == 5 and v.value.n == ('a'):byte() then
973        found = found + 1
974      end
975    end
976    eq(1, found)
977  end)
978end)
979
980describe('ShaDa jumps support code', function()
981  before_each(reset)
982  after_each(function()
983    clear()
984    os.remove(shada_fname)
985  end)
986
987  it('merges jumps when reading', function()
988    wshada(
989      '\008\001\018\131\162mX\195\161f\196\006'
990        .. mock_file_path
991        .. 'c\161l\002'
992        .. '\008\004\018\131\162mX\195\161f\196\006'
993        .. mock_file_path
994        .. 'd\161l\002'
995        .. '\008\007\018\131\162mX\195\161f\196\006'
996        .. mock_file_path
997        .. 'e\161l\002'
998    )
999    command(sdrcmd())
1000    wshada(
1001      '\008\001\018\131\162mX\195\161f\196\006'
1002        .. mock_file_path
1003        .. 'c\161l\002'
1004        .. '\008\004\018\131\162mX\195\161f\196\006'
1005        .. mock_file_path
1006        .. 'd\161l\003'
1007        .. '\008\007\018\131\162mX\195\161f\196\006'
1008        .. mock_file_path
1009        .. 'f\161l\002'
1010    )
1011    command(sdrcmd())
1012    eq('', api.nvim_buf_get_name(0))
1013    eq(
1014      ' jump line  col file/text\n'
1015        .. '   5     2    0 '
1016        .. mock_file_path
1017        .. 'c\n'
1018        .. '   4     2    0 '
1019        .. mock_file_path
1020        .. 'd\n'
1021        .. '   3     3    0 '
1022        .. mock_file_path
1023        .. 'd\n'
1024        .. '   2     2    0 '
1025        .. mock_file_path
1026        .. 'e\n'
1027        .. '   1     2    0 '
1028        .. mock_file_path
1029        .. 'f\n'
1030        .. '>',
1031      exec_capture('jumps')
1032    )
1033  end)
1034
1035  it('merges jumps when writing', function()
1036    wshada(
1037      '\008\001\018\131\162mX\195\161f\196\006'
1038        .. mock_file_path
1039        .. 'c\161l\002'
1040        .. '\008\004\018\131\162mX\195\161f\196\006'
1041        .. mock_file_path
1042        .. 'd\161l\002'
1043        .. '\008\007\018\131\162mX\195\161f\196\006'
1044        .. mock_file_path
1045        .. 'e\161l\002'
1046    )
1047    command(sdrcmd())
1048    wshada(
1049      '\008\001\018\131\162mX\195\161f\196\006'
1050        .. mock_file_path
1051        .. 'c\161l\002'
1052        .. '\008\004\018\131\162mX\195\161f\196\006'
1053        .. mock_file_path
1054        .. 'd\161l\003'
1055        .. '\008\007\018\131\162mX\195\161f\196\006'
1056        .. mock_file_path
1057        .. 'f\161l\002'
1058    )
1059    command('wshada ' .. shada_fname)
1060    local jumps = {
1061      { file = '' .. mock_file_path .. 'c', line = 2 },
1062      { file = '' .. mock_file_path .. 'd', line = 2 },
1063      { file = '' .. mock_file_path .. 'd', line = 3 },
1064      { file = '' .. mock_file_path .. 'e', line = 2 },
1065      { file = '' .. mock_file_path .. 'f', line = 2 },
1066    }
1067    local found = 0
1068    for _, v in ipairs(read_shada_file(shada_fname)) do
1069      if v.type == 8 then
1070        found = found + 1
1071        eq(jumps[found].file, v.value.f)
1072        eq(jumps[found].line, v.value.l)
1073      end
1074    end
1075    eq(#jumps, found)
1076  end)
1077
1078  it('merges JUMPLISTSIZE jumps when writing', function()
1079    local jumps = {}
1080    local shada = ''
1081    for i = 1, 100 do
1082      shada = shada
1083        .. ('\008%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i)
1084      jumps[i] = { file = '' .. mock_file_path .. 'c', line = i }
1085    end
1086    wshada(shada)
1087    command(sdrcmd())
1088    shada = ''
1089    for i = 1, 101 do
1090      local _t = i * 2
1091      shada = shada
1092        .. ('\008\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format(
1093          _t,
1094          _t
1095        )
1096      jumps[(_t > #jumps + 1) and (#jumps + 1) or _t] =
1097        { file = '' .. mock_file_path .. 'c', line = _t }
1098    end
1099    wshada(shada)
1100    command('wshada ' .. shada_fname)
1101    local shift = #jumps - 100
1102    for i = 1, 100 do
1103      jumps[i] = jumps[i + shift]
1104    end
1105    local found = 0
1106    for _, v in ipairs(read_shada_file(shada_fname)) do
1107      if v.type == 8 then
1108        found = found + 1
1109        eq(jumps[found].file, v.value.f)
1110        eq(jumps[found].line, v.value.l)
1111      end
1112    end
1113    eq(100, found)
1114  end)
1115end)
1116
1117describe('ShaDa changes support code', function()
1118  before_each(reset)
1119  after_each(function()
1120    clear()
1121    os.remove(shada_fname)
1122  end)
1123
1124  it('merges changes when reading', function()
1125    nvim_command('edit ' .. mock_file_path .. 'c')
1126    nvim_command('keepjumps call setline(1, range(7))')
1127    wshada(
1128      '\011\001\018\131\162mX\195\161f\196\006'
1129        .. mock_file_path
1130        .. 'c\161l\001'
1131        .. '\011\004\018\131\162mX\195\161f\196\006'
1132        .. mock_file_path
1133        .. 'c\161l\002'
1134        .. '\011\007\018\131\162mX\195\161f\196\006'
1135        .. mock_file_path
1136        .. 'c\161l\003'
1137    )
1138    command(sdrcmd())
1139    wshada(
1140      '\011\001\018\131\162mX\194\161f\196\006'
1141        .. mock_file_path
1142        .. 'c\161l\001'
1143        .. '\011\004\018\131\162mX\195\161f\196\006'
1144        .. mock_file_path
1145        .. 'c\161l\005'
1146        .. '\011\008\018\131\162mX\195\161f\196\006'
1147        .. mock_file_path
1148        .. 'c\161l\004'
1149    )
1150    command(sdrcmd())
1151    eq(
1152      'change line  col text\n'
1153        .. '    5     1    0 0\n'
1154        .. '    4     2    0 1\n'
1155        .. '    3     5    0 4\n'
1156        .. '    2     3    0 2\n'
1157        .. '    1     4    0 3\n'
1158        .. '>',
1159      exec_capture('changes')
1160    )
1161  end)
1162
1163  it('merges changes when writing', function()
1164    nvim_command('edit ' .. mock_file_path .. 'c')
1165    nvim_command('keepjumps call setline(1, range(7))')
1166    wshada(
1167      '\011\001\018\131\162mX\195\161f\196\006'
1168        .. mock_file_path
1169        .. 'c\161l\001'
1170        .. '\011\004\018\131\162mX\195\161f\196\006'
1171        .. mock_file_path
1172        .. 'c\161l\002'
1173        .. '\011\007\018\131\162mX\195\161f\196\006'
1174        .. mock_file_path
1175        .. 'c\161l\003'
1176    )
1177    command(sdrcmd())
1178    wshada(
1179      '\011\001\018\131\162mX\194\161f\196\006'
1180        .. mock_file_path
1181        .. 'c\161l\001'
1182        .. '\011\004\018\131\162mX\195\161f\196\006'
1183        .. mock_file_path
1184        .. 'c\161l\005'
1185        .. '\011\008\018\131\162mX\195\161f\196\006'
1186        .. mock_file_path
1187        .. 'c\161l\004'
1188    )
1189    command('wshada ' .. shada_fname)
1190    local changes = {
1191      { line = 1 },
1192      { line = 2 },
1193      { line = 5 },
1194      { line = 3 },
1195      { line = 4 },
1196    }
1197    local found = 0
1198    for _, v in ipairs(read_shada_file(shada_fname)) do
1199      if v.type == 11 and v.value.f == '' .. mock_file_path .. 'c' then
1200        found = found + 1
1201        eq(changes[found].line, v.value.l or 1)
1202      end
1203    end
1204    eq(#changes, found)
1205  end)
1206
1207  it('merges JUMPLISTSIZE changes when writing', function()
1208    nvim_command('edit ' .. mock_file_path .. 'c')
1209    nvim_command('keepjumps call setline(1, range(202))')
1210    local changes = {}
1211    local shada = ''
1212    for i = 1, 100 do
1213      shada = shada
1214        .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i)
1215      changes[i] = { line = i }
1216    end
1217    wshada(shada)
1218    command(sdrcmd())
1219    shada = ''
1220    for i = 1, 101 do
1221      local _t = i * 2
1222      shada = shada
1223        .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format(
1224          _t,
1225          _t
1226        )
1227      changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t }
1228    end
1229    wshada(shada)
1230    command('wshada ' .. shada_fname)
1231    local shift = #changes - 100
1232    for i = 1, 100 do
1233      changes[i] = changes[i + shift]
1234    end
1235    local found = 0
1236    for _, v in ipairs(read_shada_file(shada_fname)) do
1237      if v.type == 11 and v.value.f == '' .. mock_file_path .. 'c' then
1238        found = found + 1
1239        eq(changes[found].line, v.value.l)
1240      end
1241    end
1242    eq(100, found)
1243  end)
1244
1245  it('merges JUMPLISTSIZE changes when writing, with new items between old', function()
1246    nvim_command('edit ' .. mock_file_path .. 'c')
1247    nvim_command('keepjumps call setline(1, range(202))')
1248    local shada = ''
1249    for i = 1, 101 do
1250      local _t = i * 2
1251      shada = shada
1252        .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format(
1253          _t,
1254          _t
1255        )
1256    end
1257    wshada(shada)
1258    command(sdrcmd())
1259    shada = ''
1260    for i = 1, 100 do
1261      shada = shada
1262        .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i)
1263    end
1264    local changes = {}
1265    for i = 1, 100 do
1266      changes[i] = { line = i }
1267    end
1268    for i = 1, 101 do
1269      local _t = i * 2
1270      changes[(_t > #changes + 1) and (#changes + 1) or _t] = { line = _t }
1271    end
1272    wshada(shada)
1273    command('wshada ' .. shada_fname)
1274    local shift = #changes - 100
1275    for i = 1, 100 do
1276      changes[i] = changes[i + shift]
1277    end
1278    local found = 0
1279    for _, v in ipairs(read_shada_file(shada_fname)) do
1280      if v.type == 11 and v.value.f == '' .. mock_file_path .. 'c' then
1281        found = found + 1
1282        eq(changes[found].line, v.value.l)
1283      end
1284    end
1285    eq(100, found)
1286  end)
1287end)