robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
115.8 KiB3660 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4local t_shada = require('test.functional.shada.testutil')
5
6local describe, it, before_each, setup, teardown, finally =
7  t.describe, t.it, t.before_each, t.setup, t.teardown, t.finally
8local clear = n.clear
9local eq, api, nvim_eval, nvim_command, fn, nvim_feed = t.eq, n.api, n.eval, n.command, n.fn, n.feed
10local neq = t.neq
11local pcall_err = t.pcall_err
12local read_file = t.read_file
13
14local get_shada_rw = t_shada.get_shada_rw
15
16local function reset(shada_file)
17  clear { args = { '-u', 'NORC', '-i', shada_file or 'NONE' } }
18end
19
20local mpack_eq = function(expected, mpack_result)
21  local mpack_keys = { 'type', 'timestamp', 'length', 'value' }
22
23  local unpack = vim.mpack.Unpacker()
24  local actual = {}
25  local cur, val
26  local i = 0
27  local off = 1
28  while off <= #mpack_result do
29    val, off = unpack(mpack_result, off)
30    if i % 4 == 0 then
31      cur = {}
32      actual[#actual + 1] = cur
33    end
34    local key = mpack_keys[(i % 4) + 1]
35    if key ~= 'length' then
36      if key == 'timestamp' and math.abs(val - os.time()) < 2 then
37        val = 'current'
38      end
39      cur[key] = val
40    end
41    i = i + 1
42  end
43  eq(expected, actual)
44end
45
46local wshada, _, fname = get_shada_rw('Xtest-functional-plugin-shada.shada')
47
48local wshada_tmp, _, fname_tmp = get_shada_rw('Xtest-functional-plugin-shada.shada.tmp.f')
49
50describe('autoload/shada.vim', function()
51  local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
52  setup(function()
53    reset()
54    nvim_command([[
55    function ModifyVal(val)
56      if type(a:val) == type([])
57        if len(a:val) == 2 && type(a:val[0]) == type('') && a:val[0][0] is# '!' && has_key(v:msgpack_types, a:val[0][1:])
58          return {'_TYPE': v:msgpack_types[ a:val[0][1:] ], '_VAL': a:val[1]}
59        else
60          return map(copy(a:val), 'ModifyVal(v:val)')
61        endif
62      elseif type(a:val) == type({})
63        let keys = sort(keys(a:val))
64        let ret = {'_TYPE': v:msgpack_types.map, '_VAL': []}
65        for key in keys
66          let k = {'_TYPE': v:msgpack_types.string, '_VAL': split(key, "\n", 1)}
67          let v = ModifyVal(a:val[key])
68          call add(ret._VAL, [k, v])
69          unlet v
70        endfor
71        return ret
72      elseif type(a:val) == type('')
73        return {'_TYPE': v:msgpack_types.string, '_VAL': split(a:val, "\n", 1)}
74      else
75        return a:val
76      endif
77    endfunction
78    ]])
79  end)
80
81  local sp = function(typ, val)
82    return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val)
83  end
84
85  describe('function shada#mpack_to_sd', function()
86    local mpack2sd = function(arg)
87      return ('shada#mpack_to_sd(%s)'):format(arg)
88    end
89
90    it('works', function()
91      eq({}, nvim_eval(mpack2sd('[]')))
92      eq({ { type = 1, timestamp = 5, length = 1, data = 7 } }, nvim_eval(mpack2sd('[1, 5, 1, 7]')))
93      eq({
94        { type = 1, timestamp = 5, length = 1, data = 7 },
95        { type = 1, timestamp = 10, length = 1, data = 5 },
96      }, nvim_eval(mpack2sd('[1, 5, 1, 7, 1, 10, 1, 5]')))
97      t.matches(
98        'zero%-uint:Entry 1 has type element which is zero',
99        pcall_err(nvim_command, 'call ' .. mpack2sd('[0, 5, 1, 7]'))
100      )
101      t.matches(
102        'zero%-uint:Entry 1 has type element which is zero',
103        pcall_err(
104          nvim_command,
105          'call ' .. mpack2sd(('[%s, 5, 1, 7]'):format(sp('integer', '[1, 0, 0, 0]')))
106        )
107      )
108      t.matches(
109        'not%-uint:Entry 1 has timestamp element which is not an unsigned integer',
110        pcall_err(nvim_command, 'call ' .. mpack2sd('[1, -1, 1, 7]'))
111      )
112      t.matches(
113        'not%-uint:Entry 1 has length element which is not an unsigned integer',
114        pcall_err(nvim_command, 'call ' .. mpack2sd('[1, 1, -1, 7]'))
115      )
116      t.matches(
117        'not%-uint:Entry 1 has type element which is not an unsigned integer',
118        pcall_err(nvim_command, 'call ' .. mpack2sd('["", 1, -1, 7]'))
119      )
120    end)
121  end)
122
123  describe('function shada#sd_to_strings', function()
124    local sd2strings_eq = function(expected, arg)
125      if type(arg) == 'table' then
126        eq(expected, fn['shada#sd_to_strings'](arg))
127      else
128        eq(expected, nvim_eval(('shada#sd_to_strings(%s)'):format(arg)))
129      end
130    end
131
132    it('works with empty input', function()
133      sd2strings_eq({}, '[]')
134    end)
135
136    it('works with unknown items', function()
137      sd2strings_eq({
138        'Unknown (0x64) with timestamp ' .. epoch .. ':',
139        '  = 100',
140      }, { { type = 100, timestamp = 0, length = 1, data = 100 } })
141
142      sd2strings_eq(
143        {
144          'Unknown (0x4000001180000006) with timestamp ' .. epoch .. ':',
145          '  = 100',
146        },
147        ('[{"type": %s, "timestamp": 0, "length": 1, "data": 100}]'):format(
148          sp('integer', '[1, 1, 35, 6]')
149        )
150      )
151    end)
152
153    it('works with multiple unknown items', function()
154      sd2strings_eq({
155        'Unknown (0x64) with timestamp ' .. epoch .. ':',
156        '  = 100',
157        'Unknown (0x65) with timestamp ' .. epoch .. ':',
158        '  = 500',
159      }, {
160        { type = 100, timestamp = 0, length = 1, data = 100 },
161        { type = 101, timestamp = 0, length = 1, data = 500 },
162      })
163    end)
164
165    it('works with header items', function()
166      sd2strings_eq({
167        'Header with timestamp ' .. epoch .. ':',
168        '  % Key______  Value',
169        '  + generator  "test"',
170      }, { { type = 1, timestamp = 0, data = { generator = 'test' } } })
171      sd2strings_eq({
172        'Header with timestamp ' .. epoch .. ':',
173        '  % Key  Description  Value',
174        '  + a                 1',
175        '  + b                 2',
176        '  + c    column       3',
177        '  + d                 4',
178      }, { { type = 1, timestamp = 0, data = { a = 1, b = 2, c = 3, d = 4 } } })
179      sd2strings_eq({
180        'Header with timestamp ' .. epoch .. ':',
181        '  % Key  Value',
182        '  + t    "test"',
183      }, { { type = 1, timestamp = 0, data = { t = 'test' } } })
184      sd2strings_eq({
185        'Header with timestamp ' .. epoch .. ':',
186        '  # Unexpected type: array instead of map',
187        '  = [1, 2, 3]',
188      }, { { type = 1, timestamp = 0, data = { 1, 2, 3 } } })
189    end)
190
191    it('processes standard keys correctly, even in header', function()
192      sd2strings_eq(
193        {
194          'Header with timestamp ' .. epoch .. ':',
195          '  % Key  Description________  Value',
196          '  + c    column               0',
197          '  + f    file name            "/tmp/foo"',
198          '  + l    line number          10',
199          "  + n    name                 '@'",
200          '  + rc   contents             ["abc", "def"]',
201          '  + rt   type                 CHARACTERWISE',
202          '  + ru   is_unnamed           FALSE',
203          '  + rw   block width          10',
204          '  + sb   search backward      TRUE',
205          '  + sc   smartcase value      FALSE',
206          '  + se   place cursor at end  TRUE',
207          '  + sh   v:hlsearch value     TRUE',
208          '  + sl   has line offset      FALSE',
209          '  + sm   magic value          TRUE',
210          '  + so   offset value         10',
211          '  + sp   pattern              "100"',
212          '  + ss   is :s pattern        TRUE',
213          '  + su   is last used         FALSE',
214        },
215        ([[ [{'type': 1, 'timestamp': 0, 'data': {
216        'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
217        'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
218        'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
219        'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
220        'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
221        'so': 10,
222        'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
223        'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
224        'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
225        'sp': '100',
226        'rt': 0,
227        'rw': 10,
228        'rc': ['abc', 'def'],
229        'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
230        'n': 0x40,
231        'l': 10,
232        'c': 0,
233        'f': '/tmp/foo',
234      }}] ]]):gsub('\n', '')
235      )
236      sd2strings_eq(
237        {
238          'Header with timestamp ' .. epoch .. ':',
239          '  % Key  Description____  Value',
240          '  # Expected integer',
241          '  + c    column           "abc"',
242          '  # Expected no NUL bytes',
243          '  + f    file name        "abc\\0def"',
244          '  # Value is negative',
245          '  + l    line number      -10',
246          '  # Value is negative',
247          '  + n    name             -64',
248          '  # Expected array value',
249          '  + rc   contents         "10"',
250          '  # Unexpected enum value: expected one of '
251            .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
252          '  + rt   type             10',
253          '  # Expected boolean',
254          '  + ru   is_unnamed       10',
255          '  # Expected boolean',
256          '  + sc   smartcase value  NIL',
257          '  # Expected boolean',
258          '  + sm   magic value      "TRUE"',
259          '  # Expected integer',
260          '  + so   offset value     "TRUE"',
261          '  + sp   pattern          "abc"',
262        },
263        ([[ [{'type': 1, 'timestamp': 0, 'data': {
264        'sm': 'TRUE',
265        'sc': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
266        'so': 'TRUE',
267        'sp': {'_TYPE': v:msgpack_types.string, '_VAL': ["abc"]},
268        'rt': 10,
269        'rc': '10',
270        'ru': 10,
271        'n': -0x40,
272        'l': -10,
273        'c': 'abc',
274        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["abc\ndef"]},
275      }}] ]]):gsub('\n', '')
276      )
277      sd2strings_eq(
278        {
279          'Header with timestamp ' .. epoch .. ':',
280          '  % Key  Description  Value',
281          '  # Expected no NUL bytes',
282          '  + f    file name    "abc\\0def"',
283          '  + rc   contents     ["abc", "abc"]',
284          '  # Expected integer',
285          '  + rt   type         "ABC"',
286        },
287        ([[ [{'type': 1, 'timestamp': 0, 'data': {
288        'rt': 'ABC',
289        'rc': ["abc", {'_TYPE': v:msgpack_types.string, '_VAL': ["abc"]}],
290        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["abc\ndef"]},
291      }}] ]]):gsub('\n', '')
292      )
293      sd2strings_eq(
294        {
295          'Header with timestamp ' .. epoch .. ':',
296          '  % Key  Description  Value',
297          '  # Expected no NUL bytes',
298          '  + rc   contents     ["abc", "a\\nd\\0"]',
299        },
300        ([[ [{'type': 1, 'timestamp': 0, 'data': {
301        'rc': ["abc", {'_TYPE': v:msgpack_types.string, '_VAL': ["a", "d\n"]}],
302      }}] ]]):gsub('\n', '')
303      )
304    end)
305
306    it('works with search pattern items', function()
307      sd2strings_eq({
308        'Search pattern with timestamp ' .. epoch .. ':',
309        '  # Unexpected type: array instead of map',
310        '  = [1, 2, 3]',
311      }, { { type = 2, timestamp = 0, data = { 1, 2, 3 } } })
312      sd2strings_eq(
313        {
314          'Search pattern with timestamp ' .. epoch .. ':',
315          '  % Key  Description________  Value',
316          '  + sp   pattern              "abc"',
317          '  + sh   v:hlsearch value     FALSE',
318          '  + ss   is :s pattern        FALSE',
319          '  + sb   search backward      FALSE',
320          '  + sm   magic value          TRUE',
321          '  + sc   smartcase value      FALSE',
322          '  + sl   has line offset      FALSE',
323          '  + se   place cursor at end  FALSE',
324          '  + so   offset value         0',
325          '  + su   is last used         TRUE',
326        },
327        ([[ [{'type': 2, 'timestamp': 0, 'data': {
328        'sp': 'abc',
329      }}] ]]):gsub('\n', '')
330      )
331      sd2strings_eq(
332        {
333          'Search pattern with timestamp ' .. epoch .. ':',
334          '  % Key  Description________  Value',
335          '  + sp   pattern              "abc"',
336          '  + sh   v:hlsearch value     FALSE',
337          '  + ss   is :s pattern        FALSE',
338          '  + sb   search backward      FALSE',
339          '  + sm   magic value          TRUE',
340          '  + sc   smartcase value      FALSE',
341          '  + sl   has line offset      FALSE',
342          '  + se   place cursor at end  FALSE',
343          '  + so   offset value         0',
344          '  + su   is last used         TRUE',
345          '  + sX                        NIL',
346          '  + sY                        NIL',
347          '  + sZ                        NIL',
348        },
349        ([[ [{'type': 2, 'timestamp': 0, 'data': {
350        'sp': 'abc',
351        'sZ': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
352        'sY': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
353        'sX': {'_TYPE': v:msgpack_types.nil, '_VAL': 0},
354      }}] ]]):gsub('\n', '')
355      )
356      sd2strings_eq(
357        {
358          'Search pattern with timestamp ' .. epoch .. ':',
359          '  % Key  Description________  Value',
360          '  + sp   pattern              "abc"',
361          '  + sh   v:hlsearch value     FALSE',
362          '  + ss   is :s pattern        FALSE',
363          '  + sb   search backward      FALSE',
364          '  + sm   magic value          TRUE',
365          '  + sc   smartcase value      FALSE',
366          '  + sl   has line offset      FALSE',
367          '  + se   place cursor at end  FALSE',
368          '  + so   offset value         0',
369          '  + su   is last used         TRUE',
370        },
371        ([[ [{'type': 2, 'timestamp': 0, 'data': {
372        'sp': 'abc',
373        'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
374        'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
375        'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
376        'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
377        'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
378        'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
379        'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
380        'so': 0,
381        'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
382      }}] ]]):gsub('\n', '')
383      )
384      sd2strings_eq(
385        {
386          'Search pattern with timestamp ' .. epoch .. ':',
387          '  % Key  Description________  Value',
388          '  # Required key missing: sp',
389          '  + sh   v:hlsearch value     FALSE',
390          '  + ss   is :s pattern        FALSE',
391          '  + sb   search backward      FALSE',
392          '  + sm   magic value          TRUE',
393          '  + sc   smartcase value      FALSE',
394          '  + sl   has line offset      FALSE',
395          '  + se   place cursor at end  FALSE',
396          '  + so   offset value         0',
397          '  + su   is last used         TRUE',
398        },
399        ([[ [{'type': 2, 'timestamp': 0, 'data': {
400      }}] ]]):gsub('\n', '')
401      )
402      sd2strings_eq(
403        {
404          'Search pattern with timestamp ' .. epoch .. ':',
405          '  % Key  Description________  Value',
406          '  + sp   pattern              ""',
407          '  + sh   v:hlsearch value     TRUE',
408          '  + ss   is :s pattern        TRUE',
409          '  + sb   search backward      TRUE',
410          '  + sm   magic value          FALSE',
411          '  + sc   smartcase value      TRUE',
412          '  + sl   has line offset      TRUE',
413          '  + se   place cursor at end  TRUE',
414          '  + so   offset value         -10',
415          '  + su   is last used         FALSE',
416        },
417        ([[ [{'type': 2, 'timestamp': 0, 'data': {
418        'sp': '',
419        'sh': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
420        'ss': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
421        'sb': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
422        'sm': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
423        'sc': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
424        'sl': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
425        'se': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
426        'so': -10,
427        'su': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
428      }}] ]]):gsub('\n', '')
429      )
430      sd2strings_eq(
431        {
432          'Search pattern with timestamp ' .. epoch .. ':',
433          '  % Key  Description________  Value',
434          '  # Expected binary string',
435          '  + sp   pattern              0',
436          '  # Expected boolean',
437          '  + sh   v:hlsearch value     0',
438          '  # Expected boolean',
439          '  + ss   is :s pattern        0',
440          '  # Expected boolean',
441          '  + sb   search backward      0',
442          '  # Expected boolean',
443          '  + sm   magic value          0',
444          '  # Expected boolean',
445          '  + sc   smartcase value      0',
446          '  # Expected boolean',
447          '  + sl   has line offset      0',
448          '  # Expected boolean',
449          '  + se   place cursor at end  0',
450          '  # Expected integer',
451          '  + so   offset value         ""',
452          '  # Expected boolean',
453          '  + su   is last used         0',
454        },
455        ([[ [{'type': 2, 'timestamp': 0, 'data': {
456        'sp': 0,
457        'sh': 0,
458        'ss': 0,
459        'sb': 0,
460        'sm': 0,
461        'sc': 0,
462        'sl': 0,
463        'se': 0,
464        'so': '',
465        'su': 0,
466      }}] ]]):gsub('\n', '')
467      )
468    end)
469
470    it('works with replacement string items', function()
471      sd2strings_eq({
472        'Replacement string with timestamp ' .. epoch .. ':',
473        '  # Unexpected type: map instead of array',
474        '  = {"a": [10]}',
475      }, { { type = 3, timestamp = 0, data = { a = { 10 } } } })
476      sd2strings_eq(
477        {
478          'Replacement string with timestamp ' .. epoch .. ':',
479          '  @ Description__________  Value',
480          '  # Expected more elements in list',
481        },
482        ([[ [{'type': 3, 'timestamp': 0, 'data': [
483      ]}] ]]):gsub('\n', '')
484      )
485      sd2strings_eq(
486        {
487          'Replacement string with timestamp ' .. epoch .. ':',
488          '  @ Description__________  Value',
489          '  # Expected binary string',
490          '  - :s replacement string  0',
491        },
492        ([[ [{'type': 3, 'timestamp': 0, 'data': [
493        0,
494      ]}] ]]):gsub('\n', '')
495      )
496      sd2strings_eq(
497        {
498          'Replacement string with timestamp ' .. epoch .. ':',
499          '  @ Description__________  Value',
500          '  # Expected no NUL bytes',
501          '  - :s replacement string  "abc\\0def"',
502        },
503        ([[ [{'type': 3, 'timestamp': 0, 'data': [
504        {'_TYPE': v:msgpack_types.string, '_VAL': ["abc\ndef"]},
505      ]}] ]]):gsub('\n', '')
506      )
507      sd2strings_eq(
508        {
509          'Replacement string with timestamp ' .. epoch .. ':',
510          '  @ Description__________  Value',
511          '  - :s replacement string  "abc\\ndef"',
512        },
513        ([[ [{'type': 3, 'timestamp': 0, 'data': [
514        {'_TYPE': v:msgpack_types.string, '_VAL': ["abc", "def"]},
515      ]}] ]]):gsub('\n', '')
516      )
517      sd2strings_eq(
518        {
519          'Replacement string with timestamp ' .. epoch .. ':',
520          '  @ Description__________  Value',
521          '  - :s replacement string  "abc\\ndef"',
522          '  -                        0',
523        },
524        ([[ [{'type': 3, 'timestamp': 0, 'data': [
525        {'_TYPE': v:msgpack_types.string, '_VAL': ["abc", "def"]},
526        0,
527      ]}] ]]):gsub('\n', '')
528      )
529    end)
530
531    it('works with history entry items', function()
532      sd2strings_eq({
533        'History entry with timestamp ' .. epoch .. ':',
534        '  # Unexpected type: map instead of array',
535        '  = {"a": [10]}',
536      }, { { type = 4, timestamp = 0, data = { a = { 10 } } } })
537      sd2strings_eq(
538        {
539          'History entry with timestamp ' .. epoch .. ':',
540          '  @ Description_  Value',
541          '  # Expected more elements in list',
542        },
543        ([[ [{'type': 4, 'timestamp': 0, 'data': [
544      ]}] ]]):gsub('\n', '')
545      )
546      sd2strings_eq(
547        {
548          'History entry with timestamp ' .. epoch .. ':',
549          '  @ Description_  Value',
550          '  # Expected integer',
551          '  - history type  ""',
552          '  # Expected more elements in list',
553        },
554        ([[ [{'type': 4, 'timestamp': 0, 'data': [
555        '',
556      ]}] ]]):gsub('\n', '')
557      )
558      sd2strings_eq(
559        {
560          'History entry with timestamp ' .. epoch .. ':',
561          '  @ Description_  Value',
562          '  # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
563            .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
564          '  - history type  5',
565          '  - contents      ""',
566        },
567        ([[ [{'type': 4, 'timestamp': 0, 'data': [
568        5,
569        ''
570      ]}] ]]):gsub('\n', '')
571      )
572      sd2strings_eq(
573        {
574          'History entry with timestamp ' .. epoch .. ':',
575          '  @ Description_  Value',
576          '  # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
577            .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
578          '  - history type  5',
579          '  - contents      ""',
580          '  -               32',
581        },
582        ([[ [{'type': 4, 'timestamp': 0, 'data': [
583        5,
584        '',
585        0x20
586      ]}] ]]):gsub('\n', '')
587      )
588      sd2strings_eq(
589        {
590          'History entry with timestamp ' .. epoch .. ':',
591          '  @ Description_  Value',
592          '  - history type  CMD',
593          '  - contents      ""',
594          '  -               32',
595        },
596        ([[ [{'type': 4, 'timestamp': 0, 'data': [
597        0,
598        '',
599        0x20
600      ]}] ]]):gsub('\n', '')
601      )
602      sd2strings_eq(
603        {
604          'History entry with timestamp ' .. epoch .. ':',
605          '  @ Description_  Value',
606          '  - history type  SEARCH',
607          '  - contents      ""',
608          "  - separator     ' '",
609        },
610        ([[ [{'type': 4, 'timestamp': 0, 'data': [
611        1,
612        '',
613        0x20
614      ]}] ]]):gsub('\n', '')
615      )
616      sd2strings_eq(
617        {
618          'History entry with timestamp ' .. epoch .. ':',
619          '  @ Description_  Value',
620          '  - history type  SEARCH',
621          '  - contents      ""',
622          '  # Expected more elements in list',
623        },
624        ([[ [{'type': 4, 'timestamp': 0, 'data': [
625        1,
626        '',
627      ]}] ]]):gsub('\n', '')
628      )
629      sd2strings_eq(
630        {
631          'History entry with timestamp ' .. epoch .. ':',
632          '  @ Description_  Value',
633          '  - history type  EXPR',
634          '  - contents      ""',
635        },
636        ([[ [{'type': 4, 'timestamp': 0, 'data': [
637        2,
638        '',
639      ]}] ]]):gsub('\n', '')
640      )
641      sd2strings_eq(
642        {
643          'History entry with timestamp ' .. epoch .. ':',
644          '  @ Description_  Value',
645          '  - history type  INPUT',
646          '  - contents      ""',
647        },
648        ([[ [{'type': 4, 'timestamp': 0, 'data': [
649        3,
650        '',
651      ]}] ]]):gsub('\n', '')
652      )
653      sd2strings_eq(
654        {
655          'History entry with timestamp ' .. epoch .. ':',
656          '  @ Description_  Value',
657          '  - history type  DEBUG',
658          '  - contents      ""',
659        },
660        ([[ [{'type': 4, 'timestamp': 0, 'data': [
661        4,
662        '',
663      ]}] ]]):gsub('\n', '')
664      )
665      sd2strings_eq(
666        {
667          'History entry with timestamp ' .. epoch .. ':',
668          '  @ Description_  Value',
669          '  - history type  DEBUG',
670          '  # Expected binary string',
671          '  - contents      10',
672        },
673        ([[ [{'type': 4, 'timestamp': 0, 'data': [
674        4,
675        10,
676      ]}] ]]):gsub('\n', '')
677      )
678      sd2strings_eq(
679        {
680          'History entry with timestamp ' .. epoch .. ':',
681          '  @ Description_  Value',
682          '  - history type  DEBUG',
683          '  # Expected no NUL bytes',
684          '  - contents      "abc\\0def"',
685        },
686        ([[ [{'type': 4, 'timestamp': 0, 'data': [
687        4,
688        {'_TYPE': v:msgpack_types.string, '_VAL': ["abc\ndef"]},
689      ]}] ]]):gsub('\n', '')
690      )
691      sd2strings_eq(
692        {
693          'History entry with timestamp ' .. epoch .. ':',
694          '  @ Description_  Value',
695          '  - history type  SEARCH',
696          '  - contents      "abc"',
697          '  # Expected integer',
698          '  - separator     ""',
699        },
700        ([[ [{'type': 4, 'timestamp': 0, 'data': [
701        1,
702        'abc',
703        '',
704      ]}] ]]):gsub('\n', '')
705      )
706      sd2strings_eq(
707        {
708          'History entry with timestamp ' .. epoch .. ':',
709          '  @ Description_  Value',
710          '  - history type  SEARCH',
711          '  - contents      "abc"',
712          '  # Value is negative',
713          '  - separator     -1',
714        },
715        ([[ [{'type': 4, 'timestamp': 0, 'data': [
716        1,
717        'abc',
718        -1,
719      ]}] ]]):gsub('\n', '')
720      )
721      -- Regression: NUL separator must be properly supported
722      sd2strings_eq(
723        {
724          'History entry with timestamp ' .. epoch .. ':',
725          '  @ Description_  Value',
726          '  - history type  SEARCH',
727          '  - contents      ""',
728          "  - separator     '\\0'",
729        },
730        ([[ [{'type': 4, 'timestamp': 0, 'data': [
731        1,
732        '',
733        0x0
734      ]}] ]]):gsub('\n', '')
735      )
736    end)
737
738    it('works with register items', function()
739      sd2strings_eq({
740        'Register with timestamp ' .. epoch .. ':',
741        '  # Unexpected type: array instead of map',
742        '  = [1, 2, 3]',
743      }, { { type = 5, timestamp = 0, data = { 1, 2, 3 } } })
744      sd2strings_eq(
745        {
746          'Register with timestamp ' .. epoch .. ':',
747          '  % Key  Description  Value',
748          '  # Required key missing: n',
749          '  # Required key missing: rc',
750          '  + rw   block width  0',
751          '  + rt   type         CHARACTERWISE',
752          '  + ru   is_unnamed   FALSE',
753        },
754        ([[ [{'type': 5, 'timestamp': 0, 'data': {
755      }}] ]]):gsub('\n', '')
756      )
757      sd2strings_eq(
758        {
759          'Register with timestamp ' .. epoch .. ':',
760          '  % Key  Description  Value',
761          "  + n    name         ' '",
762          '  # Required key missing: rc',
763          '  + rw   block width  0',
764          '  + rt   type         CHARACTERWISE',
765          '  + ru   is_unnamed   FALSE',
766        },
767        ([[ [{'type': 5, 'timestamp': 0, 'data': {
768        'n': 0x20,
769      }}] ]]):gsub('\n', '')
770      )
771      sd2strings_eq(
772        {
773          'Register with timestamp ' .. epoch .. ':',
774          '  % Key  Description  Value',
775          "  + n    name         ' '",
776          '  + rc   contents     ["abc", "def"]',
777          '  + rw   block width  0',
778          '  + rt   type         CHARACTERWISE',
779          '  + ru   is_unnamed   FALSE',
780        },
781        ([[ [{'type': 5, 'timestamp': 0, 'data': {
782        'n': 0x20,
783        'rc': ["abc", "def"],
784        'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 0},
785      }}] ]]):gsub('\n', '')
786      )
787      sd2strings_eq(
788        {
789          'Register with timestamp ' .. epoch .. ':',
790          '  % Key  Description  Value',
791          "  + n    name         ' '",
792          '  + rc   contents     @',
793          '  | - "abcdefghijklmnopqrstuvwxyz"',
794          '  | - "abcdefghijklmnopqrstuvwxyz"',
795          '  + rw   block width  0',
796          '  + rt   type         CHARACTERWISE',
797          '  + ru   is_unnamed   TRUE',
798        },
799        ([[ [{'type': 5, 'timestamp': 0, 'data': {
800        'n': 0x20,
801        'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
802        'ru': {'_TYPE': v:msgpack_types.boolean, '_VAL': 1},
803      }}] ]]):gsub('\n', '')
804      )
805      sd2strings_eq(
806        {
807          'Register with timestamp ' .. epoch .. ':',
808          '  % Key  Description  Value',
809          "  + n    name         ' '",
810          '  + rc   contents     @',
811          '  | - "abcdefghijklmnopqrstuvwxyz"',
812          '  | - "abcdefghijklmnopqrstuvwxyz"',
813          '  + rw   block width  0',
814          '  + rt   type         CHARACTERWISE',
815          '  + ru   is_unnamed   FALSE',
816        },
817        ([[ [{'type': 5, 'timestamp': 0, 'data': {
818        'n': 0x20,
819        'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
820        'rw': 0,
821        'rt': 0,
822      }}] ]]):gsub('\n', '')
823      )
824      sd2strings_eq(
825        {
826          'Register with timestamp ' .. epoch .. ':',
827          '  % Key  Description  Value',
828          "  + n    name         ' '",
829          '  + rc   contents     @',
830          '  | - "abcdefghijklmnopqrstuvwxyz"',
831          '  | - "abcdefghijklmnopqrstuvwxyz"',
832          '  + rw   block width  5',
833          '  + rt   type         LINEWISE',
834          '  + ru   is_unnamed   FALSE',
835        },
836        ([[ [{'type': 5, 'timestamp': 0, 'data': {
837        'n': 0x20,
838        'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
839        'rw': 5,
840        'rt': 1,
841      }}] ]]):gsub('\n', '')
842      )
843      sd2strings_eq(
844        {
845          'Register with timestamp ' .. epoch .. ':',
846          '  % Key  Description  Value',
847          "  + n    name         ' '",
848          '  + rc   contents     @',
849          '  | - "abcdefghijklmnopqrstuvwxyz"',
850          '  | - "abcdefghijklmnopqrstuvwxyz"',
851          '  # Expected integer',
852          '  + rw   block width  ""',
853          '  + rt   type         BLOCKWISE',
854          '  # Expected boolean',
855          '  + ru   is_unnamed   ""',
856        },
857        ([[ [{'type': 5, 'timestamp': 0, 'data': {
858        'n': 0x20,
859        'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
860        'rw': "",
861        'rt': 2,
862        'ru': ""
863      }}] ]]):gsub('\n', '')
864      )
865      sd2strings_eq(
866        {
867          'Register with timestamp ' .. epoch .. ':',
868          '  % Key  Description  Value',
869          "  + n    name         ' '",
870          '  # Expected array value',
871          '  + rc   contents     0',
872          '  # Value is negative',
873          '  + rw   block width  -1',
874          '  # Unexpected enum value: expected one of 0 (CHARACTERWISE), '
875            .. '1 (LINEWISE), 2 (BLOCKWISE)',
876          '  + rt   type         10',
877          '  # Expected boolean',
878          '  + ru   is_unnamed   ["abc", "def"]',
879        },
880        ([[ [{'type': 5, 'timestamp': 0, 'data': {
881        'n': 0x20,
882        'rc': 0,
883        'rw': -1,
884        'rt': 10,
885        'ru': ['abc', 'def'],
886      }}] ]]):gsub('\n', '')
887      )
888      sd2strings_eq(
889        {
890          'Register with timestamp ' .. epoch .. ':',
891          '  % Key  Description  Value',
892          "  + n    name         ' '",
893          '  + rc   contents     @',
894          '  | - "abcdefghijklmnopqrstuvwxyz"',
895          '  | - "abcdefghijklmnopqrstuvwxyz"',
896          '  + rw   block width  5',
897          '  + rt   type         LINEWISE',
898          '  # Expected boolean',
899          '  + ru   is_unnamed   0',
900        },
901        ([[ [{'type': 5, 'timestamp': 0, 'data': {
902        'n': 0x20,
903        'rc': ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
904        'rw': 5,
905        'rt': 1,
906        'ru': 0,
907      }}] ]]):gsub('\n', '')
908      )
909    end)
910
911    it('works with variable items', function()
912      sd2strings_eq({
913        'Variable with timestamp ' .. epoch .. ':',
914        '  # Unexpected type: map instead of array',
915        '  = {"a": [10]}',
916      }, { { type = 6, timestamp = 0, data = { a = { 10 } } } })
917      sd2strings_eq(
918        {
919          'Variable with timestamp ' .. epoch .. ':',
920          '  @ Description  Value',
921          '  # Expected more elements in list',
922        },
923        ([[ [{'type': 6, 'timestamp': 0, 'data': [
924      ]}] ]]):gsub('\n', '')
925      )
926      sd2strings_eq(
927        {
928          'Variable with timestamp ' .. epoch .. ':',
929          '  @ Description  Value',
930          '  # Expected binary string',
931          '  - name         1',
932          '  # Expected more elements in list',
933        },
934        ([[ [{'type': 6, 'timestamp': 0, 'data': [
935        1
936      ]}] ]]):gsub('\n', '')
937      )
938      sd2strings_eq(
939        {
940          'Variable with timestamp ' .. epoch .. ':',
941          '  @ Description  Value',
942          '  # Expected no NUL bytes',
943          '  - name         "\\0"',
944          '  # Expected more elements in list',
945        },
946        ([[ [{'type': 6, 'timestamp': 0, 'data': [
947        {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]},
948      ]}] ]]):gsub('\n', '')
949      )
950      sd2strings_eq(
951        {
952          'Variable with timestamp ' .. epoch .. ':',
953          '  @ Description  Value',
954          '  - name         "foo"',
955          '  # Expected more elements in list',
956        },
957        ([[ [{'type': 6, 'timestamp': 0, 'data': [
958        {'_TYPE': v:msgpack_types.string, '_VAL': ["foo"]},
959      ]}] ]]):gsub('\n', '')
960      )
961      sd2strings_eq(
962        {
963          'Variable with timestamp ' .. epoch .. ':',
964          '  @ Description  Value',
965          '  - name         "foo"',
966          '  - value        NIL',
967        },
968        ([[ [{'type': 6, 'timestamp': 0, 'data': [
969        {'_TYPE': v:msgpack_types.string, '_VAL': ["foo"]},
970        {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
971      ]}] ]]):gsub('\n', '')
972      )
973      sd2strings_eq(
974        {
975          'Variable with timestamp ' .. epoch .. ':',
976          '  @ Description  Value',
977          '  - name         "foo"',
978          '  - value        NIL',
979          '  -              NIL',
980        },
981        ([[ [{'type': 6, 'timestamp': 0, 'data': [
982        {'_TYPE': v:msgpack_types.string, '_VAL': ["foo"]},
983        {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
984        {'_TYPE': v:msgpack_types.nil, '_VAL': ["foo"]},
985      ]}] ]]):gsub('\n', '')
986      )
987    end)
988
989    it('works with global mark items', function()
990      sd2strings_eq({
991        'Global mark with timestamp ' .. epoch .. ':',
992        '  # Unexpected type: array instead of map',
993        '  = [1, 2, 3]',
994      }, { { type = 7, timestamp = 0, data = { 1, 2, 3 } } })
995      sd2strings_eq(
996        {
997          'Global mark with timestamp ' .. epoch .. ':',
998          '  % Key  Description  Value',
999          '  # Required key missing: n',
1000          '  # Required key missing: f',
1001          '  + l    line number  1',
1002          '  + c    column       0',
1003        },
1004        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1005      }}] ]]):gsub('\n', '')
1006      )
1007      sd2strings_eq(
1008        {
1009          'Global mark with timestamp ' .. epoch .. ':',
1010          '  % Key  Description  Value',
1011          '  # Expected integer',
1012          '  + n    name         "foo"',
1013          '  # Required key missing: f',
1014          '  + l    line number  1',
1015          '  + c    column       0',
1016        },
1017        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1018        'n': 'foo',
1019      }}] ]]):gsub('\n', '')
1020      )
1021      sd2strings_eq(
1022        {
1023          'Global mark with timestamp ' .. epoch .. ':',
1024          '  % Key  Description  Value',
1025          '  # Required key missing: n',
1026          '  + f    file name    "foo"',
1027          '  + l    line number  1',
1028          '  + c    column       0',
1029        },
1030        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1031        'f': 'foo',
1032      }}] ]]):gsub('\n', '')
1033      )
1034      sd2strings_eq(
1035        {
1036          'Global mark with timestamp ' .. epoch .. ':',
1037          '  % Key  Description  Value',
1038          '  # Value is negative',
1039          '  + n    name         -10',
1040          '  # Expected no NUL bytes',
1041          '  + f    file name    "\\0"',
1042          '  + l    line number  1',
1043          '  + c    column       0',
1044        },
1045        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1046        'n': -10,
1047        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]},
1048      }}] ]]):gsub('\n', '')
1049      )
1050      sd2strings_eq(
1051        {
1052          'Global mark with timestamp ' .. epoch .. ':',
1053          '  % Key  Description  Value',
1054          "  + n    name         '\\20'",
1055          '  + f    file name    "foo"',
1056          '  # Value is negative',
1057          '  + l    line number  -10',
1058          '  # Value is negative',
1059          '  + c    column       -10',
1060        },
1061        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1062        'n': 20,
1063        'f': 'foo',
1064        'l': -10,
1065        'c': -10,
1066      }}] ]]):gsub('\n', '')
1067      )
1068      sd2strings_eq(
1069        {
1070          'Global mark with timestamp ' .. epoch .. ':',
1071          '  % Key  Description  Value',
1072          '  + n    name         128',
1073          '  + f    file name    "foo"',
1074          '  + l    line number  1',
1075          '  + c    column       0',
1076        },
1077        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1078        'n': 128,
1079        'f': 'foo',
1080      }}] ]]):gsub('\n', '')
1081      )
1082      sd2strings_eq(
1083        {
1084          'Global mark with timestamp ' .. epoch .. ':',
1085          '  % Key  Description  Value',
1086          "  + n    name         '\\20'",
1087          '  + f    file name    "foo"',
1088          '  # Expected integer',
1089          '  + l    line number  "FOO"',
1090          '  # Expected integer',
1091          '  + c    column       "foo"',
1092          '  + mX                10',
1093        },
1094        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1095        'n': 20,
1096        'f': 'foo',
1097        'l': 'FOO',
1098        'c': 'foo',
1099        'mX': 10,
1100      }}] ]]):gsub('\n', '')
1101      )
1102      sd2strings_eq(
1103        {
1104          'Global mark with timestamp ' .. epoch .. ':',
1105          '  % Key________  Description  Value',
1106          "  + n            name         'A'",
1107          '  + f            file name    "foo"',
1108          '  + l            line number  2',
1109          '  + c            column       200',
1110          '  + mX                        10',
1111          '  + mYYYYYYYYYY               10',
1112        },
1113        ([[ [{'type': 7, 'timestamp': 0, 'data': {
1114        'n': char2nr('A'),
1115        'f': 'foo',
1116        'l': 2,
1117        'c': 200,
1118        'mX': 10,
1119        'mYYYYYYYYYY': 10,
1120      }}] ]]):gsub('\n', '')
1121      )
1122    end)
1123
1124    it('works with jump items', function()
1125      sd2strings_eq({
1126        'Jump with timestamp ' .. epoch .. ':',
1127        '  # Unexpected type: array instead of map',
1128        '  = [1, 2, 3]',
1129      }, { { type = 8, timestamp = 0, data = { 1, 2, 3 } } })
1130      sd2strings_eq(
1131        {
1132          'Jump with timestamp ' .. epoch .. ':',
1133          '  % Key  Description  Value',
1134          '  # Required key missing: f',
1135          '  + l    line number  1',
1136          '  + c    column       0',
1137        },
1138        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1139      }}] ]]):gsub('\n', '')
1140      )
1141      sd2strings_eq(
1142        {
1143          'Jump with timestamp ' .. epoch .. ':',
1144          '  % Key  Description  Value',
1145          '  # Required key missing: f',
1146          '  + l    line number  1',
1147          '  + c    column       0',
1148          '  # Expected integer',
1149          '  + n    name         "foo"',
1150        },
1151        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1152        'n': 'foo',
1153      }}] ]]):gsub('\n', '')
1154      )
1155      sd2strings_eq(
1156        {
1157          'Jump with timestamp ' .. epoch .. ':',
1158          '  % Key  Description  Value',
1159          '  + f    file name    "foo"',
1160          '  + l    line number  1',
1161          '  + c    column       0',
1162        },
1163        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1164        'f': 'foo',
1165      }}] ]]):gsub('\n', '')
1166      )
1167      sd2strings_eq(
1168        {
1169          'Jump with timestamp ' .. epoch .. ':',
1170          '  % Key  Description  Value',
1171          '  # Expected no NUL bytes',
1172          '  + f    file name    "\\0"',
1173          '  + l    line number  1',
1174          '  + c    column       0',
1175          '  # Value is negative',
1176          '  + n    name         -10',
1177        },
1178        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1179        'n': -10,
1180        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]},
1181      }}] ]]):gsub('\n', '')
1182      )
1183      sd2strings_eq(
1184        {
1185          'Jump with timestamp ' .. epoch .. ':',
1186          '  % Key  Description  Value',
1187          '  + f    file name    "foo"',
1188          '  # Value is negative',
1189          '  + l    line number  -10',
1190          '  # Value is negative',
1191          '  + c    column       -10',
1192        },
1193        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1194        'f': 'foo',
1195        'l': -10,
1196        'c': -10,
1197      }}] ]]):gsub('\n', '')
1198      )
1199      sd2strings_eq(
1200        {
1201          'Jump with timestamp ' .. epoch .. ':',
1202          '  % Key  Description  Value',
1203          '  + f    file name    "foo"',
1204          '  # Expected integer',
1205          '  + l    line number  "FOO"',
1206          '  # Expected integer',
1207          '  + c    column       "foo"',
1208          '  + mX                10',
1209        },
1210        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1211        'f': 'foo',
1212        'l': 'FOO',
1213        'c': 'foo',
1214        'mX': 10,
1215      }}] ]]):gsub('\n', '')
1216      )
1217      sd2strings_eq(
1218        {
1219          'Jump with timestamp ' .. epoch .. ':',
1220          '  % Key________  Description  Value',
1221          '  + f            file name    "foo"',
1222          '  + l            line number  2',
1223          '  + c            column       200',
1224          '  + mX                        10',
1225          '  + mYYYYYYYYYY               10',
1226          "  + n            name         ' '",
1227        },
1228        ([[ [{'type': 8, 'timestamp': 0, 'data': {
1229        'n': 0x20,
1230        'f': 'foo',
1231        'l': 2,
1232        'c': 200,
1233        'mX': 10,
1234        'mYYYYYYYYYY': 10,
1235      }}] ]]):gsub('\n', '')
1236      )
1237    end)
1238
1239    it('works with buffer list items', function()
1240      sd2strings_eq({
1241        'Buffer list with timestamp ' .. epoch .. ':',
1242        '  # Unexpected type: map instead of array',
1243        '  = {"a": [10]}',
1244      }, { { type = 9, timestamp = 0, data = { a = { 10 } } } })
1245      sd2strings_eq({
1246        'Buffer list with timestamp ' .. epoch .. ':',
1247        '  # Expected array of maps',
1248        '  = [[], []]',
1249      }, { { type = 9, timestamp = 0, data = { {}, {} } } })
1250      sd2strings_eq({
1251        'Buffer list with timestamp ' .. epoch .. ':',
1252        '  # Expected array of maps',
1253        '  = [{"a": 10}, []]',
1254      }, { { type = 9, timestamp = 0, data = { { a = 10 }, {} } } })
1255      sd2strings_eq({
1256        'Buffer list with timestamp ' .. epoch .. ':',
1257        '  % Key  Description  Value',
1258        '  # Required key missing: f',
1259        '  + l    line number  1',
1260        '  + c    column       0',
1261        '  + a                 10',
1262      }, { { type = 9, timestamp = 0, data = { { a = 10 } } } })
1263      sd2strings_eq({
1264        'Buffer list with timestamp ' .. epoch .. ':',
1265        '  % Key  Description  Value',
1266        '  # Required key missing: f',
1267        '  # Expected integer',
1268        '  + l    line number  "10"',
1269        '  # Expected integer',
1270        '  + c    column       "10"',
1271        '  + a                 10',
1272      }, { { type = 9, timestamp = 0, data = { { l = '10', c = '10', a = 10 } } } })
1273      sd2strings_eq({
1274        'Buffer list with timestamp ' .. epoch .. ':',
1275        '  % Key  Description  Value',
1276        '  # Required key missing: f',
1277        '  + l    line number  10',
1278        '  + c    column       10',
1279        '  + a                 10',
1280      }, { { type = 9, timestamp = 0, data = { { l = 10, c = 10, a = 10 } } } })
1281      sd2strings_eq({
1282        'Buffer list with timestamp ' .. epoch .. ':',
1283        '  % Key  Description  Value',
1284        '  # Required key missing: f',
1285        '  # Value is negative',
1286        '  + l    line number  -10',
1287        '  # Value is negative',
1288        '  + c    column       -10',
1289      }, { { type = 9, timestamp = 0, data = { { l = -10, c = -10 } } } })
1290      sd2strings_eq({
1291        'Buffer list with timestamp ' .. epoch .. ':',
1292        '  % Key  Description  Value',
1293        '  + f    file name    "abc"',
1294        '  + l    line number  1',
1295        '  + c    column       0',
1296      }, { { type = 9, timestamp = 0, data = { { f = 'abc' } } } })
1297      sd2strings_eq({
1298        'Buffer list with timestamp ' .. epoch .. ':',
1299        '  % Key  Description  Value',
1300        '  # Expected binary string',
1301        '  + f    file name    10',
1302        '  + l    line number  1',
1303        '  + c    column       0',
1304        '',
1305        '  % Key  Description  Value',
1306        '  # Expected binary string',
1307        '  + f    file name    20',
1308        '  + l    line number  1',
1309        '  + c    column       0',
1310      }, { { type = 9, timestamp = 0, data = { { f = 10 }, { f = 20 } } } })
1311      sd2strings_eq(
1312        {
1313          'Buffer list with timestamp ' .. epoch .. ':',
1314          '  % Key  Description  Value',
1315          '  # Expected binary string',
1316          '  + f    file name    10',
1317          '  + l    line number  1',
1318          '  + c    column       0',
1319          '',
1320          '  % Key  Description  Value',
1321          '  # Expected no NUL bytes',
1322          '  + f    file name    "\\0"',
1323          '  + l    line number  1',
1324          '  + c    column       0',
1325        },
1326        ([[ [{'type': 9, 'timestamp': 0, 'data': [
1327        {'f': 10},
1328        {'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]}},
1329      ]}] ]]):gsub('\n', '')
1330      )
1331    end)
1332
1333    it('works with local mark items', function()
1334      sd2strings_eq({
1335        'Local mark with timestamp ' .. epoch .. ':',
1336        '  # Unexpected type: array instead of map',
1337        '  = [1, 2, 3]',
1338      }, { { type = 10, timestamp = 0, data = { 1, 2, 3 } } })
1339      sd2strings_eq(
1340        {
1341          'Local mark with timestamp ' .. epoch .. ':',
1342          '  % Key  Description  Value',
1343          '  # Required key missing: f',
1344          "  + n    name         '\"'",
1345          '  + l    line number  1',
1346          '  + c    column       0',
1347        },
1348        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1349      }}] ]]):gsub('\n', '')
1350      )
1351      sd2strings_eq(
1352        {
1353          'Local mark with timestamp ' .. epoch .. ':',
1354          '  % Key  Description  Value',
1355          '  # Required key missing: f',
1356          '  # Expected integer',
1357          '  + n    name         "foo"',
1358          '  + l    line number  1',
1359          '  + c    column       0',
1360        },
1361        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1362        'n': 'foo',
1363      }}] ]]):gsub('\n', '')
1364      )
1365      sd2strings_eq(
1366        {
1367          'Local mark with timestamp ' .. epoch .. ':',
1368          '  % Key  Description  Value',
1369          '  + f    file name    "foo"',
1370          "  + n    name         '\"'",
1371          '  + l    line number  1',
1372          '  + c    column       0',
1373        },
1374        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1375        'f': 'foo',
1376      }}] ]]):gsub('\n', '')
1377      )
1378      sd2strings_eq(
1379        {
1380          'Local mark with timestamp ' .. epoch .. ':',
1381          '  % Key  Description  Value',
1382          '  # Expected no NUL bytes',
1383          '  + f    file name    "\\0"',
1384          '  # Value is negative',
1385          '  + n    name         -10',
1386          '  + l    line number  1',
1387          '  + c    column       0',
1388        },
1389        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1390        'n': -10,
1391        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]},
1392      }}] ]]):gsub('\n', '')
1393      )
1394      sd2strings_eq(
1395        {
1396          'Local mark with timestamp ' .. epoch .. ':',
1397          '  % Key  Description  Value',
1398          '  + f    file name    "foo"',
1399          "  + n    name         '\\20'",
1400          '  # Value is negative',
1401          '  + l    line number  -10',
1402          '  # Value is negative',
1403          '  + c    column       -10',
1404        },
1405        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1406        'n': 20,
1407        'f': 'foo',
1408        'l': -10,
1409        'c': -10,
1410      }}] ]]):gsub('\n', '')
1411      )
1412      sd2strings_eq(
1413        {
1414          'Local mark with timestamp ' .. epoch .. ':',
1415          '  % Key  Description  Value',
1416          '  + f    file name    "foo"',
1417          "  + n    name         '\\20'",
1418          '  # Expected integer',
1419          '  + l    line number  "FOO"',
1420          '  # Expected integer',
1421          '  + c    column       "foo"',
1422          '  + mX                10',
1423        },
1424        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1425        'n': 20,
1426        'f': 'foo',
1427        'l': 'FOO',
1428        'c': 'foo',
1429        'mX': 10,
1430      }}] ]]):gsub('\n', '')
1431      )
1432      sd2strings_eq(
1433        {
1434          'Local mark with timestamp ' .. epoch .. ':',
1435          '  % Key________  Description  Value',
1436          '  + f            file name    "foo"',
1437          "  + n            name         'a'",
1438          '  + l            line number  2',
1439          '  + c            column       200',
1440          '  + mX                        10',
1441          '  + mYYYYYYYYYY               10',
1442        },
1443        ([[ [{'type': 10, 'timestamp': 0, 'data': {
1444        'n': char2nr('a'),
1445        'f': 'foo',
1446        'l': 2,
1447        'c': 200,
1448        'mX': 10,
1449        'mYYYYYYYYYY': 10,
1450      }}] ]]):gsub('\n', '')
1451      )
1452    end)
1453
1454    it('works with change items', function()
1455      sd2strings_eq({
1456        'Change with timestamp ' .. epoch .. ':',
1457        '  # Unexpected type: array instead of map',
1458        '  = [1, 2, 3]',
1459      }, { { type = 11, timestamp = 0, data = { 1, 2, 3 } } })
1460      sd2strings_eq(
1461        {
1462          'Change with timestamp ' .. epoch .. ':',
1463          '  % Key  Description  Value',
1464          '  # Required key missing: f',
1465          '  + l    line number  1',
1466          '  + c    column       0',
1467        },
1468        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1469      }}] ]]):gsub('\n', '')
1470      )
1471      sd2strings_eq(
1472        {
1473          'Change with timestamp ' .. epoch .. ':',
1474          '  % Key  Description  Value',
1475          '  # Required key missing: f',
1476          '  + l    line number  1',
1477          '  + c    column       0',
1478          '  # Expected integer',
1479          '  + n    name         "foo"',
1480        },
1481        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1482        'n': 'foo',
1483      }}] ]]):gsub('\n', '')
1484      )
1485      sd2strings_eq(
1486        {
1487          'Change with timestamp ' .. epoch .. ':',
1488          '  % Key  Description  Value',
1489          '  + f    file name    "foo"',
1490          '  + l    line number  1',
1491          '  + c    column       0',
1492        },
1493        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1494        'f': 'foo',
1495      }}] ]]):gsub('\n', '')
1496      )
1497      sd2strings_eq(
1498        {
1499          'Change with timestamp ' .. epoch .. ':',
1500          '  % Key  Description  Value',
1501          '  # Expected no NUL bytes',
1502          '  + f    file name    "\\0"',
1503          '  + l    line number  1',
1504          '  + c    column       0',
1505          '  # Value is negative',
1506          '  + n    name         -10',
1507        },
1508        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1509        'n': -10,
1510        'f': {'_TYPE': v:msgpack_types.string, '_VAL': ["\n"]},
1511      }}] ]]):gsub('\n', '')
1512      )
1513      sd2strings_eq(
1514        {
1515          'Change with timestamp ' .. epoch .. ':',
1516          '  % Key  Description  Value',
1517          '  + f    file name    "foo"',
1518          '  # Value is negative',
1519          '  + l    line number  -10',
1520          '  # Value is negative',
1521          '  + c    column       -10',
1522        },
1523        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1524        'f': 'foo',
1525        'l': -10,
1526        'c': -10,
1527      }}] ]]):gsub('\n', '')
1528      )
1529      sd2strings_eq(
1530        {
1531          'Change with timestamp ' .. epoch .. ':',
1532          '  % Key  Description  Value',
1533          '  + f    file name    "foo"',
1534          '  # Expected integer',
1535          '  + l    line number  "FOO"',
1536          '  # Expected integer',
1537          '  + c    column       "foo"',
1538          '  + mX                10',
1539        },
1540        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1541        'f': 'foo',
1542        'l': 'FOO',
1543        'c': 'foo',
1544        'mX': 10,
1545      }}] ]]):gsub('\n', '')
1546      )
1547      sd2strings_eq(
1548        {
1549          'Change with timestamp ' .. epoch .. ':',
1550          '  % Key________  Description  Value',
1551          '  + f            file name    "foo"',
1552          '  + l            line number  2',
1553          '  + c            column       200',
1554          '  + mX                        10',
1555          '  + mYYYYYYYYYY               10',
1556          "  + n            name         ' '",
1557        },
1558        ([[ [{'type': 11, 'timestamp': 0, 'data': {
1559        'n': 0x20,
1560        'f': 'foo',
1561        'l': 2,
1562        'c': 200,
1563        'mX': 10,
1564        'mYYYYYYYYYY': 10,
1565      }}] ]]):gsub('\n', '')
1566      )
1567    end)
1568  end)
1569
1570  describe('function shada#get_strings', function()
1571    it('works', function()
1572      eq({
1573        'Header with timestamp ' .. epoch .. ':',
1574        '  % Key  Value',
1575      }, nvim_eval('shada#get_strings(msgpackdump([1, 0, 0, {}]))'))
1576    end)
1577  end)
1578
1579  describe('function shada#strings_to_sd', function()
1580    local strings2sd_eq = function(expected, input)
1581      api.nvim_set_var('__input', input)
1582      nvim_command(
1583        'let g:__actual = map(shada#strings_to_sd(g:__input), '
1584          .. '"filter(v:val, \\"v:key[0] isnot# \'_\' '
1585          .. '&& v:key isnot# \'length\'\\")")'
1586      )
1587      -- print()
1588      if type(expected) == 'table' then
1589        api.nvim_set_var('__expected', expected)
1590        nvim_command('let g:__expected = ModifyVal(g:__expected)')
1591        expected = 'g:__expected'
1592        -- print(nvim_eval('msgpack#string(g:__expected)'))
1593      end
1594      -- print(nvim_eval('msgpack#string(g:__actual)'))
1595      eq(1, nvim_eval(('msgpack#equal(%s, g:__actual)'):format(expected)))
1596      if type(expected) == 'table' then
1597        nvim_command('unlet g:__expected')
1598      end
1599      nvim_command('unlet g:__input')
1600      nvim_command('unlet g:__actual')
1601    end
1602
1603    it('works with multiple items', function()
1604      strings2sd_eq({
1605        {
1606          type = 11,
1607          timestamp = 0,
1608          data = {
1609            f = 'foo',
1610            l = 2,
1611            c = 200,
1612            mX = 10,
1613            mYYYYYYYYYY = 10,
1614            n = (' '):byte(),
1615          },
1616        },
1617        {
1618          type = 1,
1619          timestamp = 0,
1620          data = {
1621            c = 'abc',
1622            f = { '!string', { 'abc\ndef' } },
1623            l = -10,
1624            n = -64,
1625            rc = '10',
1626            rt = 10,
1627            sc = { '!nil', 0 },
1628            sm = 'TRUE',
1629            so = 'TRUE',
1630            sp = { '!string', { 'abc' } },
1631          },
1632        },
1633      }, {
1634        'Change with timestamp ' .. epoch .. ':',
1635        '  % Key________  Description  Value',
1636        '  + f            file name    "foo"',
1637        '  + l            line number  2',
1638        '  + c            column       200',
1639        '  + mX                        10',
1640        '  + mYYYYYYYYYY               10',
1641        "  + n            name         ' '",
1642        'Header with timestamp ' .. epoch .. ':',
1643        '  % Key  Description____  Value',
1644        '  # Expected integer',
1645        '  + c    column           "abc"',
1646        '  # Expected no NUL bytes',
1647        '  + f    file name        "abc\\0def"',
1648        '  # Value is negative',
1649        '  + l    line number      -10',
1650        '  # Value is negative',
1651        '  + n    name             -64',
1652        '  # Expected array value',
1653        '  + rc   contents         "10"',
1654        '  # Unexpected enum value: expected one of '
1655          .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
1656        '  + rt   type             10',
1657        '  # Expected boolean',
1658        '  + sc   smartcase value  NIL',
1659        '  # Expected boolean',
1660        '  + sm   magic value      "TRUE"',
1661        '  # Expected integer',
1662        '  + so   offset value     "TRUE"',
1663        '  # Expected binary string',
1664        '  + sp   pattern          ="abc"',
1665      })
1666    end)
1667
1668    it('works with empty list', function()
1669      strings2sd_eq({}, {})
1670    end)
1671
1672    it('works with header items', function()
1673      strings2sd_eq({ { type = 1, timestamp = 0, data = {
1674        generator = 'test',
1675      } } }, {
1676        'Header with timestamp ' .. epoch .. ':',
1677        '  % Key______  Value',
1678        '  + generator  "test"',
1679      })
1680      strings2sd_eq(
1681        { { type = 1, timestamp = 0, data = {
1682          1,
1683          2,
1684          3,
1685        } } },
1686        {
1687          'Header with timestamp ' .. epoch .. ':',
1688          '  # Unexpected type: array instead of map',
1689          '  = [1, 2, 3]',
1690        }
1691      )
1692      strings2sd_eq({
1693        {
1694          type = 1,
1695          timestamp = 0,
1696          data = {
1697            a = 1,
1698            b = 2,
1699            c = 3,
1700            d = 4,
1701          },
1702        },
1703      }, {
1704        'Header with timestamp ' .. epoch .. ':',
1705        '  % Key  Description  Value',
1706        '  + a                 1',
1707        '  + b                 2',
1708        '  + c    column       3',
1709        '  + d                 4',
1710      })
1711      strings2sd_eq({
1712        {
1713          type = 1,
1714          timestamp = 0,
1715          data = {
1716            c = 'abc',
1717            f = { '!string', { 'abc\ndef' } },
1718            l = -10,
1719            n = -64,
1720            rc = '10',
1721            rt = 10,
1722            sc = { '!nil', 0 },
1723            sm = 'TRUE',
1724            so = 'TRUE',
1725            sp = { '!string', { 'abc' } },
1726          },
1727        },
1728      }, {
1729        'Header with timestamp ' .. epoch .. ':',
1730        '  % Key  Description____  Value',
1731        '  # Expected integer',
1732        '  + c    column           "abc"',
1733        '  # Expected no NUL bytes',
1734        '  + f    file name        "abc\\0def"',
1735        '  # Value is negative',
1736        '  + l    line number      -10',
1737        '  # Value is negative',
1738        '  + n    name             -64',
1739        '  # Expected array value',
1740        '  + rc   contents         "10"',
1741        '  # Unexpected enum value: expected one of '
1742          .. '0 (CHARACTERWISE), 1 (LINEWISE), 2 (BLOCKWISE)',
1743        '  + rt   type             10',
1744        '  # Expected boolean',
1745        '  + sc   smartcase value  NIL',
1746        '  # Expected boolean',
1747        '  + sm   magic value      "TRUE"',
1748        '  # Expected integer',
1749        '  + so   offset value     "TRUE"',
1750        '  # Expected binary string',
1751        '  + sp   pattern          ="abc"',
1752      })
1753    end)
1754
1755    it('works with search pattern items', function()
1756      strings2sd_eq(
1757        { { type = 2, timestamp = 0, data = {
1758          1,
1759          2,
1760          3,
1761        } } },
1762        {
1763          'Search pattern with timestamp ' .. epoch .. ':',
1764          '  # Unexpected type: array instead of map',
1765          '  = [1, 2, 3]',
1766        }
1767      )
1768      strings2sd_eq({ { type = 2, timestamp = 0, data = {
1769        sp = 'abc',
1770      } } }, {
1771        'Search pattern with timestamp ' .. epoch .. ':',
1772        '  % Key  Description________  Value',
1773        '  + sp   pattern              "abc"',
1774        '  + sh   v:hlsearch value     FALSE',
1775        '  + ss   is :s pattern        FALSE',
1776        '  + sm   magic value          TRUE',
1777        '  + sc   smartcase value      FALSE',
1778        '  + sl   has line offset      FALSE',
1779        '  + se   place cursor at end  FALSE',
1780        '  + so   offset value         0',
1781        '  + su   is last used         TRUE',
1782      })
1783      strings2sd_eq({
1784        {
1785          type = 2,
1786          timestamp = 0,
1787          data = {
1788            sp = 'abc',
1789            sX = { '!nil', 0 },
1790            sY = { '!nil', 0 },
1791            sZ = { '!nil', 0 },
1792          },
1793        },
1794      }, {
1795        'Search pattern with timestamp ' .. epoch .. ':',
1796        '  % Key  Description________  Value',
1797        '  + sp   pattern              "abc"',
1798        '  + sh   v:hlsearch value     FALSE',
1799        '  + ss   is :s pattern        FALSE',
1800        '  + sm   magic value          TRUE',
1801        '  + sc   smartcase value      FALSE',
1802        '  + sl   has line offset      FALSE',
1803        '  + se   place cursor at end  FALSE',
1804        '  + so   offset value         0',
1805        '  + su   is last used         TRUE',
1806        '  + sX                        NIL',
1807        '  + sY                        NIL',
1808        '  + sZ                        NIL',
1809      })
1810      strings2sd_eq({ { type = 2, timestamp = 0, data = { '!map', {} } } }, {
1811        'Search pattern with timestamp ' .. epoch .. ':',
1812        '  % Key  Description________  Value',
1813        '  # Required key missing: sp',
1814        '  + sh   v:hlsearch value     FALSE',
1815        '  + ss   is :s pattern        FALSE',
1816        '  + sm   magic value          TRUE',
1817        '  + sc   smartcase value      FALSE',
1818        '  + sl   has line offset      FALSE',
1819        '  + se   place cursor at end  FALSE',
1820        '  + so   offset value         0',
1821        '  + su   is last used         TRUE',
1822      })
1823      strings2sd_eq({
1824        {
1825          type = 2,
1826          timestamp = 0,
1827          data = {
1828            sp = '',
1829            sh = { '!boolean', 1 },
1830            ss = { '!boolean', 1 },
1831            sc = { '!boolean', 1 },
1832            sl = { '!boolean', 1 },
1833            se = { '!boolean', 1 },
1834            sm = { '!boolean', 0 },
1835            su = { '!boolean', 0 },
1836            so = -10,
1837          },
1838        },
1839      }, {
1840        'Search pattern with timestamp ' .. epoch .. ':',
1841        '  % Key  Description________  Value',
1842        '  + sp   pattern              ""',
1843        '  + sh   v:hlsearch value     TRUE',
1844        '  + ss   is :s pattern        TRUE',
1845        '  + sm   magic value          FALSE',
1846        '  + sc   smartcase value      TRUE',
1847        '  + sl   has line offset      TRUE',
1848        '  + se   place cursor at end  TRUE',
1849        '  + so   offset value         -10',
1850        '  + su   is last used         FALSE',
1851      })
1852      strings2sd_eq({
1853        {
1854          type = 2,
1855          timestamp = 0,
1856          data = {
1857            sp = 0,
1858            sh = 0,
1859            ss = 0,
1860            sc = 0,
1861            sl = 0,
1862            se = 0,
1863            sm = 0,
1864            su = 0,
1865            so = '',
1866          },
1867        },
1868      }, {
1869        'Search pattern with timestamp ' .. epoch .. ':',
1870        '  % Key  Description________  Value',
1871        '  # Expected binary string',
1872        '  + sp   pattern              0',
1873        '  # Expected boolean',
1874        '  + sh   v:hlsearch value     0',
1875        '  # Expected boolean',
1876        '  + ss   is :s pattern        0',
1877        '  # Expected boolean',
1878        '  + sm   magic value          0',
1879        '  # Expected boolean',
1880        '  + sc   smartcase value      0',
1881        '  # Expected boolean',
1882        '  + sl   has line offset      0',
1883        '  # Expected boolean',
1884        '  + se   place cursor at end  0',
1885        '  # Expected integer',
1886        '  + so   offset value         ""',
1887        '  # Expected boolean',
1888        '  + su   is last used         0',
1889      })
1890    end)
1891
1892    it('works with replacement string items', function()
1893      strings2sd_eq({ { type = 3, timestamp = 0, data = {
1894        a = { 10 },
1895      } } }, {
1896        'Replacement string with timestamp ' .. epoch .. ':',
1897        '  # Unexpected type: map instead of array',
1898        '  = {"a": [10]}',
1899      })
1900      strings2sd_eq({ { type = 3, timestamp = 0, data = {} } }, {
1901        'Replacement string with timestamp ' .. epoch .. ':',
1902        '  @ Description__________  Value',
1903        '  # Expected more elements in list',
1904      })
1905      strings2sd_eq({ { type = 3, timestamp = 0, data = {
1906        0,
1907      } } }, {
1908        'Replacement string with timestamp ' .. epoch .. ':',
1909        '  @ Description__________  Value',
1910        '  # Expected binary string',
1911        '  - :s replacement string  0',
1912      })
1913      strings2sd_eq(
1914        { { type = 3, timestamp = 0, data = {
1915          'abc\ndef',
1916          0,
1917        } } },
1918        {
1919          'Replacement string with timestamp ' .. epoch .. ':',
1920          '  @ Description__________  Value',
1921          '  - :s replacement string  "abc\\ndef"',
1922          '  -                        0',
1923        }
1924      )
1925      strings2sd_eq({ { type = 3, timestamp = 0, data = {
1926        'abc\ndef',
1927      } } }, {
1928        'Replacement string with timestamp ' .. epoch .. ':',
1929        '  @ Description__________  Value',
1930        '  - :s replacement string  "abc\\ndef"',
1931      })
1932    end)
1933
1934    it('works with history entry items', function()
1935      strings2sd_eq({ { type = 4, timestamp = 0, data = {
1936        a = { 10 },
1937      } } }, {
1938        'History entry with timestamp ' .. epoch .. ':',
1939        '  # Unexpected type: map instead of array',
1940        '  = {"a": [10]}',
1941      })
1942      strings2sd_eq({ { type = 4, timestamp = 0, data = {} } }, {
1943        'History entry with timestamp ' .. epoch .. ':',
1944        '  @ Description_  Value',
1945        '  # Expected more elements in list',
1946      })
1947      strings2sd_eq({ { type = 4, timestamp = 0, data = {
1948        '',
1949      } } }, {
1950        'History entry with timestamp ' .. epoch .. ':',
1951        '  @ Description_  Value',
1952        '  # Expected integer',
1953        '  - history type  ""',
1954        '  # Expected more elements in list',
1955      })
1956      strings2sd_eq({ { type = 4, timestamp = 0, data = {
1957        5,
1958        '',
1959      } } }, {
1960        'History entry with timestamp ' .. epoch .. ':',
1961        '  @ Description_  Value',
1962        '  # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
1963          .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
1964        '  - history type  5',
1965        '  - contents      ""',
1966      })
1967      strings2sd_eq(
1968        { { type = 4, timestamp = 0, data = {
1969          5,
1970          '',
1971          32,
1972        } } },
1973        {
1974          'History entry with timestamp ' .. epoch .. ':',
1975          '  @ Description_  Value',
1976          '  # Unexpected enum value: expected one of 0 (CMD), 1 (SEARCH), '
1977            .. '2 (EXPR), 3 (INPUT), 4 (DEBUG)',
1978          '  - history type  5',
1979          '  - contents      ""',
1980          '  -               32',
1981        }
1982      )
1983      strings2sd_eq(
1984        { { type = 4, timestamp = 0, data = {
1985          0,
1986          '',
1987          32,
1988        } } },
1989        {
1990          'History entry with timestamp ' .. epoch .. ':',
1991          '  @ Description_  Value',
1992          '  - history type  CMD',
1993          '  - contents      ""',
1994          '  -               32',
1995        }
1996      )
1997      strings2sd_eq(
1998        { { type = 4, timestamp = 0, data = {
1999          1,
2000          '',
2001          32,
2002        } } },
2003        {
2004          'History entry with timestamp ' .. epoch .. ':',
2005          '  @ Description_  Value',
2006          '  - history type  SEARCH',
2007          '  - contents      ""',
2008          "  - separator     ' '",
2009        }
2010      )
2011      strings2sd_eq({ { type = 4, timestamp = 0, data = {
2012        1,
2013        '',
2014      } } }, {
2015        'History entry with timestamp ' .. epoch .. ':',
2016        '  @ Description_  Value',
2017        '  - history type  SEARCH',
2018        '  - contents      ""',
2019        '  # Expected more elements in list',
2020      })
2021      strings2sd_eq({ { type = 4, timestamp = 0, data = {
2022        2,
2023        '',
2024      } } }, {
2025        'History entry with timestamp ' .. epoch .. ':',
2026        '  @ Description_  Value',
2027        '  - history type  EXPR',
2028        '  - contents      ""',
2029      })
2030      strings2sd_eq({ { type = 4, timestamp = 0, data = {
2031        3,
2032        '',
2033      } } }, {
2034        'History entry with timestamp ' .. epoch .. ':',
2035        '  @ Description_  Value',
2036        '  - history type  INPUT',
2037        '  - contents      ""',
2038      })
2039      strings2sd_eq({ { type = 4, timestamp = 0, data = {
2040        4,
2041        '',
2042      } } }, {
2043        'History entry with timestamp ' .. epoch .. ':',
2044        '  @ Description_  Value',
2045        '  - history type  DEBUG',
2046        '  - contents      ""',
2047      })
2048    end)
2049
2050    it('works with register items', function()
2051      strings2sd_eq(
2052        { { type = 5, timestamp = 0, data = {
2053          1,
2054          2,
2055          3,
2056        } } },
2057        {
2058          'Register with timestamp ' .. epoch .. ':',
2059          '  # Unexpected type: array instead of map',
2060          '  = [1, 2, 3]',
2061        }
2062      )
2063      strings2sd_eq({ { type = 5, timestamp = 0, data = { '!map', {} } } }, {
2064        'Register with timestamp ' .. epoch .. ':',
2065        '  % Key  Description  Value',
2066        '  # Required key missing: n',
2067        '  # Required key missing: rc',
2068        '  + rw   block width  0',
2069        '  + rt   type         CHARACTERWISE',
2070      })
2071      strings2sd_eq({ { type = 5, timestamp = 0, data = {
2072        n = (' '):byte(),
2073      } } }, {
2074        'Register with timestamp ' .. epoch .. ':',
2075        '  % Key  Description  Value',
2076        "  + n    name         ' '",
2077        '  # Required key missing: rc',
2078        '  + rw   block width  0',
2079        '  + rt   type         CHARACTERWISE',
2080      })
2081      strings2sd_eq({
2082        {
2083          type = 5,
2084          timestamp = 0,
2085          data = {
2086            n = (' '):byte(),
2087            rc = { 'abc', 'def' },
2088          },
2089        },
2090      }, {
2091        'Register with timestamp ' .. epoch .. ':',
2092        '  % Key  Description  Value',
2093        "  + n    name         ' '",
2094        '  + rc   contents     ["abc", "def"]',
2095        '  + rw   block width  0',
2096        '  + rt   type         CHARACTERWISE',
2097      })
2098      strings2sd_eq({
2099        {
2100          type = 5,
2101          timestamp = 0,
2102          data = {
2103            n = (' '):byte(),
2104            rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' },
2105          },
2106        },
2107      }, {
2108        'Register with timestamp ' .. epoch .. ':',
2109        '  % Key  Description  Value',
2110        "  + n    name         ' '",
2111        '  + rc   contents     @',
2112        '  | - "abcdefghijklmnopqrstuvwxyz"',
2113        '  | - "abcdefghijklmnopqrstuvwxyz"',
2114        '  + rw   block width  0',
2115        '  + rt   type         CHARACTERWISE',
2116      })
2117      strings2sd_eq({
2118        {
2119          type = 5,
2120          timestamp = 0,
2121          data = {
2122            n = (' '):byte(),
2123            rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' },
2124            rw = 5,
2125            rt = 1,
2126          },
2127        },
2128      }, {
2129        'Register with timestamp ' .. epoch .. ':',
2130        '  % Key  Description  Value',
2131        "  + n    name         ' '",
2132        '  + rc   contents     @',
2133        '  | - "abcdefghijklmnopqrstuvwxyz"',
2134        '  | - "abcdefghijklmnopqrstuvwxyz"',
2135        '  + rw   block width  5',
2136        '  + rt   type         LINEWISE',
2137      })
2138      strings2sd_eq({
2139        {
2140          type = 5,
2141          timestamp = 0,
2142          data = {
2143            n = (' '):byte(),
2144            rc = { 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz' },
2145            rw = 5,
2146            rt = 2,
2147          },
2148        },
2149      }, {
2150        'Register with timestamp ' .. epoch .. ':',
2151        '  % Key  Description  Value',
2152        "  + n    name         ' '",
2153        '  + rc   contents     @',
2154        '  | - "abcdefghijklmnopqrstuvwxyz"',
2155        '  | - "abcdefghijklmnopqrstuvwxyz"',
2156        '  + rw   block width  5',
2157        '  + rt   type         BLOCKWISE',
2158      })
2159      strings2sd_eq({
2160        {
2161          type = 5,
2162          timestamp = 0,
2163          data = {
2164            n = (' '):byte(),
2165            rc = 0,
2166            rw = -1,
2167            rt = 10,
2168          },
2169        },
2170      }, {
2171        'Register with timestamp ' .. epoch .. ':',
2172        '  % Key  Description  Value',
2173        "  + n    name         ' '",
2174        '  # Expected array value',
2175        '  + rc   contents     0',
2176        '  # Value is negative',
2177        '  + rw   block width  -1',
2178        '  # Unexpected enum value: expected one of 0 (CHARACTERWISE), '
2179          .. '1 (LINEWISE), 2 (BLOCKWISE)',
2180        '  + rt   type         10',
2181      })
2182    end)
2183
2184    it('works with variable items', function()
2185      strings2sd_eq({ { type = 6, timestamp = 0, data = {
2186        a = { 10 },
2187      } } }, {
2188        'Variable with timestamp ' .. epoch .. ':',
2189        '  # Unexpected type: map instead of array',
2190        '  = {"a": [10]}',
2191      })
2192      strings2sd_eq({ { type = 6, timestamp = 0, data = {} } }, {
2193        'Variable with timestamp ' .. epoch .. ':',
2194        '  @ Description  Value',
2195        '  # Expected more elements in list',
2196      })
2197      strings2sd_eq({ { type = 6, timestamp = 0, data = {
2198        'foo',
2199      } } }, {
2200        'Variable with timestamp ' .. epoch .. ':',
2201        '  @ Description  Value',
2202        '  - name         "foo"',
2203        '  # Expected more elements in list',
2204      })
2205      strings2sd_eq({
2206        {
2207          type = 6,
2208          timestamp = 0,
2209          data = {
2210            'foo',
2211            { '!nil', 0 },
2212          },
2213        },
2214      }, {
2215        'Variable with timestamp ' .. epoch .. ':',
2216        '  @ Description  Value',
2217        '  - name         "foo"',
2218        '  - value        NIL',
2219      })
2220      strings2sd_eq({
2221        {
2222          type = 6,
2223          timestamp = 0,
2224          data = {
2225            'foo',
2226            { '!nil', 0 },
2227            { '!nil', 0 },
2228          },
2229        },
2230      }, {
2231        'Variable with timestamp ' .. epoch .. ':',
2232        '  @ Description  Value',
2233        '  - name         "foo"',
2234        '  - value        NIL',
2235        '  -              NIL',
2236      })
2237    end)
2238
2239    it('works with global mark items', function()
2240      strings2sd_eq(
2241        { { type = 7, timestamp = 0, data = {
2242          1,
2243          2,
2244          3,
2245        } } },
2246        {
2247          'Global mark with timestamp ' .. epoch .. ':',
2248          '  # Unexpected type: array instead of map',
2249          '  = [1, 2, 3]',
2250        }
2251      )
2252      strings2sd_eq({
2253        {
2254          type = 7,
2255          timestamp = 0,
2256          data = {
2257            n = ('A'):byte(),
2258            f = 'foo',
2259            l = 2,
2260            c = 200,
2261            mX = 10,
2262            mYYYYYYYYYY = 10,
2263          },
2264        },
2265      }, {
2266        'Global mark with timestamp ' .. epoch .. ':',
2267        '  % Key________  Description  Value',
2268        "  + n            name         'A'",
2269        '  + f            file name    "foo"',
2270        '  + l            line number  2',
2271        '  + c            column       200',
2272        '  + mX                        10',
2273        '  + mYYYYYYYYYY               10',
2274      })
2275    end)
2276
2277    it('works with jump items', function()
2278      strings2sd_eq(
2279        { { type = 8, timestamp = 0, data = {
2280          1,
2281          2,
2282          3,
2283        } } },
2284        {
2285          'Jump with timestamp ' .. epoch .. ':',
2286          '  # Unexpected type: array instead of map',
2287          '  = [1, 2, 3]',
2288        }
2289      )
2290      strings2sd_eq({
2291        {
2292          type = 8,
2293          timestamp = 0,
2294          data = {
2295            n = ('A'):byte(),
2296            f = 'foo',
2297            l = 2,
2298            c = 200,
2299            mX = 10,
2300            mYYYYYYYYYY = 10,
2301          },
2302        },
2303      }, {
2304        'Jump with timestamp ' .. epoch .. ':',
2305        '  % Key________  Description  Value',
2306        "  + n            name         'A'",
2307        '  + f            file name    "foo"',
2308        '  + l            line number  2',
2309        '  + c            column       200',
2310        '  + mX                        10',
2311        '  + mYYYYYYYYYY               10',
2312      })
2313    end)
2314
2315    it('works with buffer list items', function()
2316      strings2sd_eq({ { type = 9, timestamp = 0, data = {
2317        a = { 10 },
2318      } } }, {
2319        'Buffer list with timestamp ' .. epoch .. ':',
2320        '  # Unexpected type: map instead of array',
2321        '  = {"a": [10]}',
2322      })
2323      strings2sd_eq(
2324        { { type = 9, timestamp = 0, data = {
2325          { a = 10 },
2326          {},
2327        } } },
2328        {
2329          'Buffer list with timestamp ' .. epoch .. ':',
2330          '  # Expected array of maps',
2331          '  = [{"a": 10}, []]',
2332        }
2333      )
2334      strings2sd_eq({ { type = 9, timestamp = 0, data = {
2335        { a = 10 },
2336      } } }, {
2337        'Buffer list with timestamp ' .. epoch .. ':',
2338        '  % Key  Description  Value',
2339        '  # Required key missing: f',
2340        '  + l    line number  1',
2341        '  + c    column       0',
2342        '  + a                 10',
2343      })
2344      strings2sd_eq({
2345        {
2346          type = 9,
2347          timestamp = 0,
2348          data = {
2349            { l = '10', c = '10', a = 10 },
2350          },
2351        },
2352      }, {
2353        'Buffer list with timestamp ' .. epoch .. ':',
2354        '  % Key  Description  Value',
2355        '  # Required key missing: f',
2356        '  # Expected integer',
2357        '  + l    line number  "10"',
2358        '  # Expected integer',
2359        '  + c    column       "10"',
2360        '  + a                 10',
2361      })
2362      strings2sd_eq(
2363        { { type = 9, timestamp = 0, data = {
2364          { l = 10, c = 10, a = 10 },
2365        } } },
2366        {
2367          'Buffer list with timestamp ' .. epoch .. ':',
2368          '  % Key  Description  Value',
2369          '  # Required key missing: f',
2370          '  + l    line number  10',
2371          '  + c    column       10',
2372          '  + a                 10',
2373        }
2374      )
2375      strings2sd_eq(
2376        { { type = 9, timestamp = 0, data = {
2377          { l = -10, c = -10 },
2378        } } },
2379        {
2380          'Buffer list with timestamp ' .. epoch .. ':',
2381          '  % Key  Description  Value',
2382          '  # Required key missing: f',
2383          '  # Value is negative',
2384          '  + l    line number  -10',
2385          '  # Value is negative',
2386          '  + c    column       -10',
2387        }
2388      )
2389      strings2sd_eq({ { type = 9, timestamp = 0, data = {
2390        { f = 'abc' },
2391      } } }, {
2392        'Buffer list with timestamp ' .. epoch .. ':',
2393        '  % Key  Description  Value',
2394        '  + f    file name    "abc"',
2395        '  + l    line number  1',
2396        '  + c    column       0',
2397      })
2398      strings2sd_eq({
2399        {
2400          type = 9,
2401          timestamp = 0,
2402          data = {
2403            { f = 10 },
2404            { f = 20 },
2405          },
2406        },
2407      }, {
2408        'Buffer list with timestamp ' .. epoch .. ':',
2409        '  % Key  Description  Value',
2410        '  # Expected binary string',
2411        "  + f    file name    '\\10'",
2412        '  + l    line number  1',
2413        '  + c    column       0',
2414        '',
2415        '  % Key  Description  Value',
2416        '  # Expected binary string',
2417        "  + f    file name    '\\20'",
2418        '  + l    line number  1',
2419        '  + c    column       0',
2420      })
2421      strings2sd_eq({
2422        {
2423          type = 9,
2424          timestamp = 0,
2425          data = {
2426            { f = 10 },
2427            { f = { '!string', { '\n' } } },
2428          },
2429        },
2430      }, {
2431        'Buffer list with timestamp ' .. epoch .. ':',
2432        '  % Key  Description  Value',
2433        '  # Expected binary string',
2434        "  + f    file name    '\\10'",
2435        '  + l    line number  1',
2436        '  + c    column       0',
2437        '',
2438        '  % Key  Description  Value',
2439        '  # Expected no NUL bytes',
2440        '  + f    file name    "\\0"',
2441        '  + l    line number  1',
2442        '  + c    column       0',
2443      })
2444    end)
2445
2446    it('works with local mark items', function()
2447      strings2sd_eq(
2448        { { type = 10, timestamp = 0, data = {
2449          1,
2450          2,
2451          3,
2452        } } },
2453        {
2454          'Local mark with timestamp ' .. epoch .. ':',
2455          '  # Unexpected type: array instead of map',
2456          '  = [1, 2, 3]',
2457        }
2458      )
2459      strings2sd_eq({
2460        {
2461          type = 10,
2462          timestamp = 0,
2463          data = {
2464            n = ('A'):byte(),
2465            f = 'foo',
2466            l = 2,
2467            c = 200,
2468            mX = 10,
2469            mYYYYYYYYYY = 10,
2470          },
2471        },
2472      }, {
2473        'Local mark with timestamp ' .. epoch .. ':',
2474        '  % Key________  Description  Value',
2475        "  + n            name         'A'",
2476        '  + f            file name    "foo"',
2477        '  + l            line number  2',
2478        '  + c            column       200',
2479        '  + mX                        10',
2480        '  + mYYYYYYYYYY               10',
2481      })
2482    end)
2483
2484    it('works with change items', function()
2485      strings2sd_eq(
2486        { { type = 11, timestamp = 0, data = {
2487          1,
2488          2,
2489          3,
2490        } } },
2491        {
2492          'Change with timestamp ' .. epoch .. ':',
2493          '  # Unexpected type: array instead of map',
2494          '  = [1, 2, 3]',
2495        }
2496      )
2497      strings2sd_eq({
2498        {
2499          type = 11,
2500          timestamp = 0,
2501          data = {
2502            n = ('A'):byte(),
2503            f = 'foo',
2504            l = 2,
2505            c = 200,
2506            mX = 10,
2507            mYYYYYYYYYY = 10,
2508          },
2509        },
2510      }, {
2511        'Change with timestamp ' .. epoch .. ':',
2512        '  % Key________  Description  Value',
2513        "  + n            name         'A'",
2514        '  + f            file name    "foo"',
2515        '  + l            line number  2',
2516        '  + c            column       200',
2517        '  + mX                        10',
2518        '  + mYYYYYYYYYY               10',
2519      })
2520    end)
2521  end)
2522
2523  describe('function shada#get_binstrings', function()
2524    local getbstrings_eq = function(expected, input)
2525      local result = fn['shada#get_binstrings'](input)
2526      for i, s in ipairs(result) do
2527        result[i] = s:gsub('\n', '\0')
2528      end
2529      local mpack_result = table.concat(result, '\n')
2530      return mpack_eq(expected, mpack_result)
2531    end
2532
2533    it('works', function()
2534      local version = api.nvim_get_vvar('version')
2535      getbstrings_eq({
2536        {
2537          timestamp = 'current',
2538          type = 1,
2539          value = {
2540            generator = 'shada.vim',
2541            version = version,
2542          },
2543        },
2544      }, {})
2545      getbstrings_eq({
2546        {
2547          timestamp = 'current',
2548          type = 1,
2549          value = {
2550            generator = 'shada.vim',
2551            version = version,
2552          },
2553        },
2554        { timestamp = 0, type = 1, value = { generator = 'test' } },
2555      }, {
2556        'Header with timestamp ' .. epoch .. ':',
2557        '  % Key______  Value',
2558        '  + generator  "test"',
2559      })
2560      api.nvim_set_var('shada#add_own_header', 1)
2561      getbstrings_eq({
2562        {
2563          timestamp = 'current',
2564          type = 1,
2565          value = {
2566            generator = 'shada.vim',
2567            version = version,
2568          },
2569        },
2570      }, {})
2571      getbstrings_eq({
2572        {
2573          timestamp = 'current',
2574          type = 1,
2575          value = {
2576            generator = 'shada.vim',
2577            version = version,
2578          },
2579        },
2580        { timestamp = 0, type = 1, value = { generator = 'test' } },
2581      }, {
2582        'Header with timestamp ' .. epoch .. ':',
2583        '  % Key______  Value',
2584        '  + generator  "test"',
2585      })
2586      api.nvim_set_var('shada#add_own_header', 0)
2587      getbstrings_eq({}, {})
2588      getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, {
2589        'Header with timestamp ' .. epoch .. ':',
2590        '  % Key______  Value',
2591        '  + generator  "test"',
2592      })
2593      api.nvim_set_var('shada#keep_old_header', 0)
2594      getbstrings_eq({}, {
2595        'Header with timestamp ' .. epoch .. ':',
2596        '  % Key______  Value',
2597        '  + generator  "test"',
2598      })
2599      getbstrings_eq({
2600        { type = 3, timestamp = 0, value = { 'abc\ndef' } },
2601        { type = 3, timestamp = 0, value = { 'abc\ndef' } },
2602        { type = 3, timestamp = 0, value = { 'abc\ndef' } },
2603      }, {
2604        'Replacement string with timestamp ' .. epoch .. ':',
2605        '  @ Description__________  Value',
2606        '  - :s replacement string  "abc\\ndef"',
2607        'Replacement string with timestamp ' .. epoch .. ':',
2608        '  @ Description__________  Value',
2609        '  - :s replacement string  "abc\\ndef"',
2610        'Replacement string with timestamp ' .. epoch .. ':',
2611        '  @ Description__________  Value',
2612        '  - :s replacement string  "abc\\ndef"',
2613      })
2614    end)
2615  end)
2616end)
2617
2618describe('plugin/shada.vim', function()
2619  local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
2620  local eol = t.is_os('win') and '\r\n' or '\n'
2621  before_each(function()
2622    -- Note: reset() is called explicitly in each test.
2623    os.remove(fname)
2624    os.remove(fname .. '.tst')
2625    os.remove(fname_tmp)
2626  end)
2627
2628  teardown(function()
2629    os.remove(fname)
2630    os.remove(fname .. '.tst')
2631    os.remove(fname_tmp)
2632  end)
2633
2634  local shada_eq = function(expected, fname_)
2635    local mpack_result = read_file(fname_)
2636    mpack_eq(expected, mpack_result)
2637  end
2638
2639  it('event BufReadCmd', function()
2640    reset()
2641    wshada('\004\000\009\147\000\196\002ab\196\001a')
2642    wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
2643
2644    local bufread_commands = api.nvim_get_autocmds({ group = 'nvim.shada', event = 'BufReadCmd' })
2645    eq(2, #bufread_commands--[[, vim.inspect(bufread_commands) ]])
2646
2647    -- Need to set nohidden so that the buffer containing 'fname' is not unloaded
2648    -- after loading 'fname_tmp', otherwise the '++opt not supported' test below
2649    -- won't work since the BufReadCmd autocmd won't be triggered.
2650    nvim_command('set nohidden')
2651
2652    nvim_command('edit ' .. fname)
2653    eq({
2654      'History entry with timestamp ' .. epoch .. ':',
2655      '  @ Description_  Value',
2656      '  - history type  CMD',
2657      '  - contents      "ab"',
2658      '  -               "a"',
2659    }, nvim_eval('getline(1, "$")'))
2660    eq(false, api.nvim_get_option_value('modified', {}))
2661    eq('shada', api.nvim_get_option_value('filetype', {}))
2662    nvim_command('edit ' .. fname_tmp)
2663    eq({
2664      'History entry with timestamp ' .. epoch .. ':',
2665      '  @ Description_  Value',
2666      '  - history type  CMD',
2667      '  - contents      "ab"',
2668      '  -               "b"',
2669    }, nvim_eval('getline(1, "$")'))
2670    eq(false, api.nvim_get_option_value('modified', {}))
2671    eq('shada', api.nvim_get_option_value('filetype', {}))
2672    t.matches(
2673      '++opt not supported',
2674      t.pcall_err(function()
2675        nvim_command('edit ++enc=latin1 ' .. fname)
2676      end)
2677    )
2678    neq({
2679      'History entry with timestamp ' .. epoch .. ':',
2680      '  @ Description_  Value',
2681      '  - history type  CMD',
2682      '  - contents      "ab"',
2683      '  -               "a"',
2684    }, nvim_eval('getline(1, "$")'))
2685    neq(true, api.nvim_get_option_value('modified', {}))
2686  end)
2687
2688  it('event FileReadCmd', function()
2689    reset()
2690    wshada('\004\000\009\147\000\196\002ab\196\001a')
2691    wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
2692    nvim_command('$read ' .. fname)
2693    eq({
2694      '',
2695      'History entry with timestamp ' .. epoch .. ':',
2696      '  @ Description_  Value',
2697      '  - history type  CMD',
2698      '  - contents      "ab"',
2699      '  -               "a"',
2700    }, nvim_eval('getline(1, "$")'))
2701    eq(true, api.nvim_get_option_value('modified', {}))
2702    neq('shada', api.nvim_get_option_value('filetype', {}))
2703    nvim_command('1,$read ' .. fname_tmp)
2704    eq({
2705      '',
2706      'History entry with timestamp ' .. epoch .. ':',
2707      '  @ Description_  Value',
2708      '  - history type  CMD',
2709      '  - contents      "ab"',
2710      '  -               "a"',
2711      'History entry with timestamp ' .. epoch .. ':',
2712      '  @ Description_  Value',
2713      '  - history type  CMD',
2714      '  - contents      "ab"',
2715      '  -               "b"',
2716    }, nvim_eval('getline(1, "$")'))
2717    eq(true, api.nvim_get_option_value('modified', {}))
2718    neq('shada', api.nvim_get_option_value('filetype', {}))
2719    api.nvim_set_option_value('modified', false, {})
2720    t.matches(
2721      '++opt not supported',
2722      t.pcall_err(function()
2723        nvim_command('$read ++enc=latin1 ' .. fname)
2724      end)
2725    )
2726    eq({
2727      '',
2728      'History entry with timestamp ' .. epoch .. ':',
2729      '  @ Description_  Value',
2730      '  - history type  CMD',
2731      '  - contents      "ab"',
2732      '  -               "a"',
2733      'History entry with timestamp ' .. epoch .. ':',
2734      '  @ Description_  Value',
2735      '  - history type  CMD',
2736      '  - contents      "ab"',
2737      '  -               "b"',
2738    }, nvim_eval('getline(1, "$")'))
2739    neq(true, api.nvim_get_option_value('modified', {}))
2740  end)
2741
2742  it('event BufWriteCmd', function()
2743    reset()
2744    api.nvim_set_var('shada#add_own_header', 0)
2745    api.nvim_buf_set_lines(0, 0, 1, true, {
2746      'Jump with timestamp ' .. epoch .. ':',
2747      '  % Key________  Description  Value',
2748      "  + n            name         'A'",
2749      '  + f            file name    ["foo"]',
2750      '  + l            line number  2',
2751      '  + c            column       -200',
2752      'Jump with timestamp ' .. epoch .. ':',
2753      '  % Key________  Description  Value',
2754      "  + n            name         'A'",
2755      '  + f            file name    ["foo"]',
2756      '  + l            line number  2',
2757      '  + c            column       -200',
2758    })
2759
2760    nvim_command('set cpoptions-=+')
2761    nvim_command('w ' .. fname)
2762    eq(false, api.nvim_get_option_value('modified', {}))
2763
2764    api.nvim_set_option_value('modified', true, {})
2765    nvim_command('w ' .. fname .. '.tst')
2766    eq(true, api.nvim_get_option_value('modified', {}))
2767
2768    nvim_command('set cpoptions+=+')
2769    nvim_command('w ' .. fname_tmp)
2770    eq(false, api.nvim_get_option_value('modified', {}))
2771
2772    api.nvim_set_option_value('modified', true, {})
2773    nvim_command('w ' .. fname)
2774    eq(false, api.nvim_get_option_value('modified', {}))
2775
2776    t.matches(
2777      '++opt not supported',
2778      t.pcall_err(function()
2779        nvim_command('w! ++enc=latin1 ' .. fname)
2780      end)
2781    )
2782    eq(table.concat({
2783      'Jump with timestamp ' .. epoch .. ':',
2784      '  % Key________  Description  Value',
2785      "  + n            name         'A'",
2786      '  + f            file name    ["foo"]',
2787      '  + l            line number  2',
2788      '  + c            column       -200',
2789      'Jump with timestamp ' .. epoch .. ':',
2790      '  % Key________  Description  Value',
2791      "  + n            name         'A'",
2792      '  + f            file name    ["foo"]',
2793      '  + l            line number  2',
2794      '  + c            column       -200',
2795    }, eol) .. eol, read_file(fname .. '.tst'))
2796    shada_eq({
2797      {
2798        timestamp = 0,
2799        type = 8,
2800        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2801      },
2802      {
2803        timestamp = 0,
2804        type = 8,
2805        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2806      },
2807    }, fname)
2808    shada_eq({
2809      {
2810        timestamp = 0,
2811        type = 8,
2812        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2813      },
2814      {
2815        timestamp = 0,
2816        type = 8,
2817        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2818      },
2819    }, fname_tmp)
2820  end)
2821
2822  it('event FileWriteCmd', function()
2823    reset()
2824    api.nvim_set_var('shada#add_own_header', 0)
2825    api.nvim_buf_set_lines(0, 0, 1, true, {
2826      'Jump with timestamp ' .. epoch .. ':',
2827      '  % Key________  Description  Value',
2828      "  + n            name         'A'",
2829      '  + f            file name    ["foo"]',
2830      '  + l            line number  2',
2831      '  + c            column       -200',
2832      'Jump with timestamp ' .. epoch .. ':',
2833      '  % Key________  Description  Value',
2834      "  + n            name         'A'",
2835      '  + f            file name    ["foo"]',
2836      '  + l            line number  2',
2837      '  + c            column       -200',
2838    })
2839    nvim_command('1,3w ' .. fname .. '.tst')
2840    nvim_command('1,3w ' .. fname)
2841    nvim_command('1,3w ' .. fname_tmp)
2842    t.matches(
2843      '++opt not supported',
2844      t.pcall_err(function()
2845        nvim_command('1,3w! ++enc=latin1 ' .. fname)
2846      end)
2847    )
2848    eq(table.concat({
2849      'Jump with timestamp ' .. epoch .. ':',
2850      '  % Key________  Description  Value',
2851      "  + n            name         'A'",
2852    }, eol) .. eol, read_file(fname .. '.tst'))
2853    shada_eq(
2854      { {
2855        timestamp = 0,
2856        type = 8,
2857        value = { n = ('A'):byte() },
2858      } },
2859      fname
2860    )
2861    shada_eq(
2862      { {
2863        timestamp = 0,
2864        type = 8,
2865        value = { n = ('A'):byte() },
2866      } },
2867      fname_tmp
2868    )
2869  end)
2870
2871  it('event FileAppendCmd', function()
2872    reset()
2873    api.nvim_set_var('shada#add_own_header', 0)
2874    api.nvim_buf_set_lines(0, 0, 1, true, {
2875      'Jump with timestamp ' .. epoch .. ':',
2876      '  % Key________  Description  Value',
2877      "  + n            name         'A'",
2878      '  + f            file name    ["foo"]',
2879      '  + l            line number  2',
2880      '  + c            column       -200',
2881      'Jump with timestamp ' .. epoch .. ':',
2882      '  % Key________  Description  Value',
2883      "  + n            name         'A'",
2884      '  + f            file name    ["foo"]',
2885      '  + l            line number  2',
2886      '  + c            column       -200',
2887    })
2888    fn.writefile({ '' }, fname .. '.tst', 'b')
2889    fn.writefile({ '' }, fname, 'b')
2890    fn.writefile({ '' }, fname_tmp, 'b')
2891    nvim_command('1,3w >> ' .. fname .. '.tst')
2892    nvim_command('1,3w >> ' .. fname)
2893    nvim_command('1,3w >> ' .. fname_tmp)
2894    nvim_command('w >> ' .. fname .. '.tst')
2895    nvim_command('w >> ' .. fname)
2896    nvim_command('w >> ' .. fname_tmp)
2897    t.matches(
2898      '++opt not supported',
2899      t.pcall_err(function()
2900        nvim_command('1,3w! ++enc=latin1 >> ' .. fname)
2901      end)
2902    )
2903    eq(table.concat({
2904      'Jump with timestamp ' .. epoch .. ':',
2905      '  % Key________  Description  Value',
2906      "  + n            name         'A'",
2907      'Jump with timestamp ' .. epoch .. ':',
2908      '  % Key________  Description  Value',
2909      "  + n            name         'A'",
2910      '  + f            file name    ["foo"]',
2911      '  + l            line number  2',
2912      '  + c            column       -200',
2913      'Jump with timestamp ' .. epoch .. ':',
2914      '  % Key________  Description  Value',
2915      "  + n            name         'A'",
2916      '  + f            file name    ["foo"]',
2917      '  + l            line number  2',
2918      '  + c            column       -200',
2919    }, eol) .. eol, read_file(fname .. '.tst'))
2920    shada_eq({
2921      {
2922        timestamp = 0,
2923        type = 8,
2924        value = { n = ('A'):byte() },
2925      },
2926      {
2927        timestamp = 0,
2928        type = 8,
2929        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2930      },
2931      {
2932        timestamp = 0,
2933        type = 8,
2934        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2935      },
2936    }, fname)
2937    shada_eq({
2938      {
2939        timestamp = 0,
2940        type = 8,
2941        value = { n = ('A'):byte() },
2942      },
2943      {
2944        timestamp = 0,
2945        type = 8,
2946        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2947      },
2948      {
2949        timestamp = 0,
2950        type = 8,
2951        value = { c = -200, f = { 'foo' }, l = 2, n = ('A'):byte() },
2952      },
2953    }, fname_tmp)
2954  end)
2955
2956  it('event SourceCmd', function()
2957    reset(fname)
2958    finally(function()
2959      nvim_command('set shadafile=NONE') -- Avoid writing shada file on exit
2960    end)
2961    wshada('\004\000\006\146\000\196\002ab')
2962    wshada_tmp('\004\001\006\146\000\196\002bc')
2963    nvim_command('source ' .. fname)
2964    nvim_command('source ' .. fname_tmp)
2965    eq('bc', fn.histget(':', -1))
2966    eq('ab', fn.histget(':', -2))
2967  end)
2968end)
2969
2970describe('ftplugin/shada.vim', function()
2971  local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
2972  before_each(reset)
2973
2974  it('sets indentexpr correctly', function()
2975    nvim_command('filetype plugin indent on')
2976    nvim_command('setlocal filetype=shada')
2977    fn.setline(1, {
2978      'Jump with timestamp ' .. epoch .. ':',
2979      '% Key________  Description  Value',
2980      "+ n            name         'A'",
2981      '+ f            file name    "foo"',
2982      '+ l            line number  2',
2983      '+ c            column       200',
2984      '+ mX                        10',
2985      '+ mYYYYYYYYYY               10',
2986      'Register with timestamp ' .. epoch .. ':',
2987      '% Key  Description  Value',
2988      "+ n    name         ' '",
2989      '+ rc   contents     @',
2990      '| - "abcdefghijklmnopqrstuvwxyz"',
2991      '| - "abcdefghijklmnopqrstuvwxyz"',
2992      '+ rw   block width  0',
2993      '+ rt   type         CHARACTERWISE',
2994      'Replacement string with timestamp ' .. epoch .. ':',
2995      '    @ Description__________  Value',
2996      '    - :s replacement string  "abc\\ndef"',
2997      '   Buffer list with timestamp ' .. epoch .. ':',
2998      '    # Expected array of maps',
2999      '= [{"a": 10}, []]',
3000      '    Buffer list with timestamp ' .. epoch .. ':',
3001      '   % Key  Description  Value',
3002      '  # Expected binary string',
3003      '+ f    file name    10',
3004      ' + l    line number  1',
3005      '   + c    column       0',
3006      '',
3007      ' % Key  Description  Value',
3008      '    # Expected binary string',
3009      ' + f    file name    20',
3010      '+ l    line number  1',
3011      '    + c    column       0',
3012    })
3013    nvim_command('normal! gg=G')
3014    eq({
3015      'Jump with timestamp ' .. epoch .. ':',
3016      '  % Key________  Description  Value',
3017      "  + n            name         'A'",
3018      '  + f            file name    "foo"',
3019      '  + l            line number  2',
3020      '  + c            column       200',
3021      '  + mX                        10',
3022      '  + mYYYYYYYYYY               10',
3023      'Register with timestamp ' .. epoch .. ':',
3024      '  % Key  Description  Value',
3025      "  + n    name         ' '",
3026      '  + rc   contents     @',
3027      '  | - "abcdefghijklmnopqrstuvwxyz"',
3028      '  | - "abcdefghijklmnopqrstuvwxyz"',
3029      '  + rw   block width  0',
3030      '  + rt   type         CHARACTERWISE',
3031      'Replacement string with timestamp ' .. epoch .. ':',
3032      '  @ Description__________  Value',
3033      '  - :s replacement string  "abc\\ndef"',
3034      'Buffer list with timestamp ' .. epoch .. ':',
3035      '  # Expected array of maps',
3036      '  = [{"a": 10}, []]',
3037      'Buffer list with timestamp ' .. epoch .. ':',
3038      '  % Key  Description  Value',
3039      '  # Expected binary string',
3040      '  + f    file name    10',
3041      '  + l    line number  1',
3042      '  + c    column       0',
3043      '',
3044      '  % Key  Description  Value',
3045      '  # Expected binary string',
3046      '  + f    file name    20',
3047      '  + l    line number  1',
3048      '  + c    column       0',
3049    }, fn.getline(1, fn.line('$')))
3050  end)
3051
3052  it('sets options correctly', function()
3053    nvim_command('filetype plugin indent on')
3054    nvim_command('setlocal filetype=shada')
3055    eq(true, api.nvim_get_option_value('expandtab', {}))
3056    eq(2, api.nvim_get_option_value('tabstop', {}))
3057    eq(2, api.nvim_get_option_value('softtabstop', {}))
3058    eq(2, api.nvim_get_option_value('shiftwidth', {}))
3059  end)
3060
3061  it('sets indentkeys correctly', function()
3062    nvim_command('filetype plugin indent on')
3063    nvim_command('setlocal filetype=shada')
3064    fn.setline(1, '  Replacement with timestamp ' .. epoch)
3065    nvim_feed('ggA:\027')
3066    eq('Replacement with timestamp ' .. epoch .. ':', api.nvim_buf_get_lines(0, 0, 1, true)[1])
3067    nvim_feed('o-\027')
3068    eq({ '  -' }, api.nvim_buf_get_lines(0, 1, 2, true))
3069    nvim_feed('ggO+\027')
3070    eq({ '+' }, api.nvim_buf_get_lines(0, 0, 1, true))
3071    nvim_feed('GO*\027')
3072    eq({ '  *' }, api.nvim_buf_get_lines(0, 2, 3, true))
3073    nvim_feed('ggO  /\027')
3074    eq({ '  /' }, api.nvim_buf_get_lines(0, 0, 1, true))
3075    nvim_feed('ggOx\027')
3076    eq({ 'x' }, api.nvim_buf_get_lines(0, 0, 1, true))
3077  end)
3078end)
3079
3080describe('syntax/shada.vim', function()
3081  local epoch = os.date('!%Y-%m-%dT%H:%M:%S', 0)
3082  before_each(reset)
3083
3084  it('works', function()
3085    nvim_command('syntax on')
3086    nvim_command('setlocal syntax=shada')
3087    nvim_command('set laststatus&')
3088    local screen = Screen.new(60, 37)
3089    screen:set_default_attr_ids {
3090      [1] = { bold = true, foreground = Screen.colors.Brown },
3091      [2] = { foreground = tonumber('0x6a0dad') },
3092      [3] = { foreground = Screen.colors.Fuchsia },
3093      [4] = { foreground = Screen.colors.Blue1 },
3094      [5] = { bold = true, foreground = Screen.colors.SeaGreen4 },
3095      [6] = { foreground = Screen.colors.SlateBlue },
3096      [7] = { bold = true, reverse = true },
3097      [8] = { bold = true, foreground = Screen.colors.Blue },
3098    }
3099
3100    api.nvim_buf_set_lines(0, 0, 1, true, {
3101      'Header with timestamp ' .. epoch .. ':',
3102      '  % Key  Value',
3103      '  + t    "test"',
3104      'Jump with timestamp ' .. epoch .. ':',
3105      '  % Key________  Description  Value',
3106      "  + n            name         'A'",
3107      '  + f            file name    ["foo"]',
3108      '  + l            line number  2',
3109      '  + c            column       -200',
3110      'Register with timestamp ' .. epoch .. ':',
3111      '  % Key  Description  Value',
3112      '  + rc   contents     @',
3113      '  | - {"abcdefghijklmnopqrstuvwxyz": 1.0}',
3114      '  + rt   type         CHARACTERWISE',
3115      '  + rt   type         LINEWISE',
3116      '  + rt   type         BLOCKWISE',
3117      'Replacement string with timestamp ' .. epoch .. ':',
3118      '  @ Description__________  Value',
3119      '  - :s replacement string  CMD',
3120      '  - :s replacement string  SEARCH',
3121      '  - :s replacement string  EXPR',
3122      '  - :s replacement string  INPUT',
3123      '  - :s replacement string  DEBUG',
3124      'Buffer list with timestamp ' .. epoch .. ':',
3125      '  # Expected array of maps',
3126      '  = [{"a": +(10)"ac\\0df\\ngi\\"tt\\.", TRUE: FALSE}, [NIL, +(-10)""]]',
3127      'Buffer list with timestamp ' .. epoch .. ':',
3128      '  % Key  Description  Value',
3129      '',
3130      '  % Key  Description  Value',
3131      'Header with timestamp ' .. epoch .. ':',
3132      '  % Key  Description________  Value',
3133      '  + se   place cursor at end  TRUE',
3134    })
3135    screen:expect {
3136      grid = [=[
3137      {1:^Header} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:                  |
3138      {2:  % Key  Value}                                              |
3139       {1: +} {3:t  }  {1:"}{3:test}{1:"}                                             |
3140      {1:Jump} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:                    |
3141      {2:  % Key________  Description  Value}                         |
3142       {1: +} {3:n          }  {4:name       }  {3:'A'}                           |
3143       {1: +} {3:f          }  {4:file name  }  {1:["}{3:foo}{1:"]}                       |
3144       {1: +} {3:l          }  {4:line number}  {3:2}                             |
3145       {1: +} {3:c          }  {4:column     }  {3:-200}                          |
3146      {1:Register} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:                |
3147      {2:  % Key  Description  Value}                                 |
3148       {1: +} {3:rc }  {4:contents   }  {1:@}                                     |
3149       {1: | -} {1:{"}{3:abcdefghijklmnopqrstuvwxyz}{1:":} {3:1.0}{1:}}                   |
3150       {1: +} {3:rt }  {4:type       }  {1:CHARACTERWISE}                         |
3151       {1: +} {3:rt }  {4:type       }  {1:LINEWISE}                              |
3152       {1: +} {3:rt }  {4:type       }  {1:BLOCKWISE}                             |
3153      {1:Replacement string} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:      |
3154      {2:  @ Description__________  Value}                            |
3155       {1: -} {4::s replacement string}  {1:CMD}                              |
3156       {1: -} {4::s replacement string}  {1:SEARCH}                           |
3157       {1: -} {4::s replacement string}  {1:EXPR}                             |
3158       {1: -} {4::s replacement string}  {1:INPUT}                            |
3159       {1: -} {4::s replacement string}  {1:DEBUG}                            |
3160      {1:Buffer list} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:             |
3161      {4:  # Expected array of maps}                                  |
3162        = {1:[{"}{3:a}{1:":} {1:+(}{5:10}{1:)"}{3:ac}{6:\0}{3:df}{6:\n}{3:gi}{6:\"}{3:tt\.}{1:",} {1:TRUE:} {1:FALSE},} {1:[NIL,} {1:+(}{5:-1}|
3163      {5:0}{1:)""]]}                                                      |
3164      {1:Buffer list} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:             |
3165      {2:  % Key  Description  Value}                                 |
3166                                                                  |
3167      {2:  % Key  Description  Value}                                 |
3168      {1:Header} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00:                  |
3169      {2:  % Key  Description________  Value}                         |
3170       {1: +} {3:se }  {4:place cursor at end}  {1:TRUE}                          |
3171      {8:~                                                           }|
3172      {7:[No Name] [+]                                               }|
3173                                                                  |
3174    ]=],
3175    }
3176
3177    nvim_command([[
3178      function GetSyntax()
3179        let lines = []
3180        for l in range(1, line('$'))
3181          let columns = []
3182          let line = getline(l)
3183          for c in range(1, col([l, '$']) - 1)
3184            let synstack = map(synstack(l, c), 'synIDattr(v:val, "name")')
3185            if !empty(columns) && columns[-1][0] ==# synstack
3186              let columns[-1][1] .= line[c - 1]
3187            else
3188              call add(columns, [ synstack, line[c - 1] ])
3189            endif
3190          endfor
3191          call add(lines, columns)
3192        endfor
3193        return lines
3194      endfunction
3195    ]])
3196    local hname = function(s)
3197      return { { 'ShaDaEntryHeader', 'ShaDaEntryName' }, s }
3198    end
3199    local h = function(s)
3200      return { { 'ShaDaEntryHeader' }, s }
3201    end
3202    local htsnum = function(s)
3203      return {
3204        { 'ShaDaEntryHeader', 'ShaDaEntryTimestamp', 'ShaDaEntryTimestampNumber' },
3205        s,
3206      }
3207    end
3208    local synhtssep = function(s)
3209      return { { 'ShaDaEntryHeader', 'ShaDaEntryTimestamp' }, s }
3210    end
3211    local synepoch = {
3212      year = htsnum(os.date('!%Y', 0)),
3213      month = htsnum(os.date('!%m', 0)),
3214      day = htsnum(os.date('!%d', 0)),
3215      hour = htsnum(os.date('!%H', 0)),
3216      minute = htsnum(os.date('!%M', 0)),
3217      second = htsnum(os.date('!%S', 0)),
3218    }
3219    local msh = function(s)
3220      return {
3221        { 'ShaDaEntryMapShort', 'ShaDaEntryMapHeader' },
3222        s,
3223      }
3224    end
3225    local mlh = function(s)
3226      return { { 'ShaDaEntryMapLong', 'ShaDaEntryMapHeader' }, s }
3227    end
3228    local ah = function(s)
3229      return { { 'ShaDaEntryArray', 'ShaDaEntryArrayHeader' }, s }
3230    end
3231    -- luacheck: ignore
3232    local mses = function(s)
3233      return {
3234        {
3235          'ShaDaEntryMapShort',
3236          'ShaDaEntryMapShortEntryStart',
3237        },
3238        s,
3239      }
3240    end
3241    local mles = function(s)
3242      return {
3243        { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongEntryStart' },
3244        s,
3245      }
3246    end
3247    local act = fn.GetSyntax()
3248    local ms = function(syn)
3249      return {
3250        { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart' },
3251        '  + ',
3252      }
3253    end
3254    local as = function()
3255      return { { 'ShaDaEntryArray', 'ShaDaEntryArrayEntryStart' }, '  - ' }
3256    end
3257    local ad = function(s)
3258      return {
3259        { 'ShaDaEntryArray', 'ShaDaEntryArrayDescription' },
3260        s,
3261      }
3262    end
3263    local mbas = function(syn)
3264      return {
3265        { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMapBinArrayStart' },
3266        '  | - ',
3267      }
3268    end
3269    local msk = function(s)
3270      return {
3271        { 'ShaDaEntryMapShort', 'ShaDaEntryMapShortKey' },
3272        s,
3273      }
3274    end
3275    local mlk = function(s)
3276      return {
3277        { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongKey' },
3278        s,
3279      }
3280    end
3281    local mld = function(s)
3282      return {
3283        { 'ShaDaEntryMapLong', 'ShaDaEntryMapLongDescription' },
3284        s,
3285      }
3286    end
3287    local c = function(s)
3288      return { { 'ShaDaComment' }, s }
3289    end
3290    local exp = {
3291      {
3292        hname('Header'),
3293        h(' with timestamp '),
3294        synepoch.year,
3295        synhtssep('-'),
3296        synepoch.month,
3297        synhtssep('-'),
3298        synepoch.day,
3299        synhtssep('T'),
3300        synepoch.hour,
3301        synhtssep(':'),
3302        synepoch.minute,
3303        synhtssep(':'),
3304        synepoch.second,
3305        h(':'),
3306      },
3307      {
3308        msh('  % Key  Value'),
3309      },
3310      {
3311        ms('Short'),
3312        msk('t    '),
3313        {
3314          { 'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString', 'ShaDaMsgpackStringQuotes' },
3315          '"',
3316        },
3317        { { 'ShaDaEntryMapShort', 'ShaDaMsgpackBinaryString' }, 'test' },
3318        { { 'ShaDaEntryMapShort', 'ShaDaMsgpackStringQuotes' }, '"' },
3319      },
3320      {
3321        hname('Jump'),
3322        h(' with timestamp '),
3323        synepoch.year,
3324        synhtssep('-'),
3325        synepoch.month,
3326        synhtssep('-'),
3327        synepoch.day,
3328        synhtssep('T'),
3329        synepoch.hour,
3330        synhtssep(':'),
3331        synepoch.minute,
3332        synhtssep(':'),
3333        synepoch.second,
3334        h(':'),
3335      },
3336      {
3337        mlh('  % Key________  Description  Value'),
3338      },
3339      {
3340        ms('Long'),
3341        mlk('n            '),
3342        mld('name         '),
3343        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackCharacter' }, "'A'" },
3344      },
3345      {
3346        ms('Long'),
3347        mlk('f            '),
3348        mld('file name    '),
3349        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' },
3350        {
3351          {
3352            'ShaDaEntryMapLong',
3353            'ShaDaMsgpackArray',
3354            'ShaDaMsgpackBinaryString',
3355            'ShaDaMsgpackStringQuotes',
3356          },
3357          '"',
3358        },
3359        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackBinaryString' }, 'foo' },
3360        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes' }, '"' },
3361        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackArrayBraces' }, ']' },
3362      },
3363      {
3364        ms('Long'),
3365        mlk('l            '),
3366        mld('line number  '),
3367        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackInteger' }, '2' },
3368      },
3369      {
3370        ms('Long'),
3371        mlk('c            '),
3372        mld('column       '),
3373        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackInteger' }, '-200' },
3374      },
3375      {
3376        hname('Register'),
3377        h(' with timestamp '),
3378        synepoch.year,
3379        synhtssep('-'),
3380        synepoch.month,
3381        synhtssep('-'),
3382        synepoch.day,
3383        synhtssep('T'),
3384        synepoch.hour,
3385        synhtssep(':'),
3386        synepoch.minute,
3387        synhtssep(':'),
3388        synepoch.second,
3389        h(':'),
3390      },
3391      {
3392        mlh('  % Key  Description  Value'),
3393      },
3394      {
3395        ms('Long'),
3396        mlk('rc   '),
3397        mld('contents     '),
3398        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMultilineArray' }, '@' },
3399      },
3400      {
3401        mbas('Long'),
3402        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces' }, '{' },
3403        {
3404          {
3405            'ShaDaEntryMapLong',
3406            'ShaDaMsgpackMap',
3407            'ShaDaMsgpackBinaryString',
3408            'ShaDaMsgpackStringQuotes',
3409          },
3410          '"',
3411        },
3412        {
3413          { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' },
3414          'abcdefghijklmnopqrstuvwxyz',
3415        },
3416        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' },
3417        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' },
3418        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap' }, ' ' },
3419        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMap', 'ShaDaMsgpackFloat' }, '1.0' },
3420        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackMapBraces' }, '}' },
3421      },
3422      {
3423        ms('Long'),
3424        mlk('rt   '),
3425        mld('type         '),
3426        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'CHARACTERWISE' },
3427      },
3428      {
3429        ms('Long'),
3430        mlk('rt   '),
3431        mld('type         '),
3432        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'LINEWISE' },
3433      },
3434      {
3435        ms('Long'),
3436        mlk('rt   '),
3437        mld('type         '),
3438        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackShaDaKeyword' }, 'BLOCKWISE' },
3439      },
3440      {
3441        hname('Replacement string'),
3442        h(' with timestamp '),
3443        synepoch.year,
3444        synhtssep('-'),
3445        synepoch.month,
3446        synhtssep('-'),
3447        synepoch.day,
3448        synhtssep('T'),
3449        synepoch.hour,
3450        synhtssep(':'),
3451        synepoch.minute,
3452        synhtssep(':'),
3453        synepoch.second,
3454        h(':'),
3455      },
3456      {
3457        ah('  @ Description__________  Value'),
3458      },
3459      {
3460        as(),
3461        ad(':s replacement string  '),
3462        { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'CMD' },
3463      },
3464      {
3465        as(),
3466        ad(':s replacement string  '),
3467        { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'SEARCH' },
3468      },
3469      {
3470        as(),
3471        ad(':s replacement string  '),
3472        { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'EXPR' },
3473      },
3474      {
3475        as(),
3476        ad(':s replacement string  '),
3477        { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'INPUT' },
3478      },
3479      {
3480        as(),
3481        ad(':s replacement string  '),
3482        { { 'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword' }, 'DEBUG' },
3483      },
3484      {
3485        hname('Buffer list'),
3486        h(' with timestamp '),
3487        synepoch.year,
3488        synhtssep('-'),
3489        synepoch.month,
3490        synhtssep('-'),
3491        synepoch.day,
3492        synhtssep('T'),
3493        synepoch.hour,
3494        synhtssep(':'),
3495        synepoch.minute,
3496        synhtssep(':'),
3497        synepoch.second,
3498        h(':'),
3499      },
3500      {
3501        c('  # Expected array of maps'),
3502      },
3503      {
3504        { { 'ShaDaEntryRawMsgpack' }, '  = ' },
3505        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' },
3506        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackMapBraces' }, '{' },
3507        {
3508          {
3509            'ShaDaMsgpackArray',
3510            'ShaDaMsgpackMap',
3511            'ShaDaMsgpackBinaryString',
3512            'ShaDaMsgpackStringQuotes',
3513          },
3514          '"',
3515        },
3516        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'a' },
3517        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' },
3518        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' },
3519        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' },
3520        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt' }, '+(' },
3521        {
3522          {
3523            'ShaDaMsgpackArray',
3524            'ShaDaMsgpackMap',
3525            'ShaDaMsgpackExt',
3526            'ShaDaMsgpackExtType',
3527          },
3528          '10',
3529        },
3530        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackExt' }, ')' },
3531        {
3532          {
3533            'ShaDaMsgpackArray',
3534            'ShaDaMsgpackMap',
3535            'ShaDaMsgpackBinaryString',
3536            'ShaDaMsgpackStringQuotes',
3537          },
3538          '"',
3539        },
3540        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'ac' },
3541        {
3542          {
3543            'ShaDaMsgpackArray',
3544            'ShaDaMsgpackMap',
3545            'ShaDaMsgpackBinaryString',
3546            'ShaDaMsgpackBinaryStringEscape',
3547          },
3548          '\\0',
3549        },
3550        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'df' },
3551        {
3552          {
3553            'ShaDaMsgpackArray',
3554            'ShaDaMsgpackMap',
3555            'ShaDaMsgpackBinaryString',
3556            'ShaDaMsgpackBinaryStringEscape',
3557          },
3558          '\\n',
3559        },
3560        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'gi' },
3561        {
3562          {
3563            'ShaDaMsgpackArray',
3564            'ShaDaMsgpackMap',
3565            'ShaDaMsgpackBinaryString',
3566            'ShaDaMsgpackBinaryStringEscape',
3567          },
3568          '\\"',
3569        },
3570        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackBinaryString' }, 'tt\\.' },
3571        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackStringQuotes' }, '"' },
3572        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackComma' }, ',' },
3573        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' },
3574        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword' }, 'TRUE' },
3575        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackColon' }, ':' },
3576        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap' }, ' ' },
3577        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMap', 'ShaDaMsgpackKeyword' }, 'FALSE' },
3578        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackMapBraces' }, '}' },
3579        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackComma' }, ',' },
3580        { { 'ShaDaMsgpackArray' }, ' ' },
3581        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, '[' },
3582        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackKeyword' }, 'NIL' },
3583        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackComma' }, ',' },
3584        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray' }, ' ' },
3585        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt' }, '+(' },
3586        {
3587          {
3588            'ShaDaMsgpackArray',
3589            'ShaDaMsgpackArray',
3590            'ShaDaMsgpackExt',
3591            'ShaDaMsgpackExtType',
3592          },
3593          '-10',
3594        },
3595        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackExt' }, ')' },
3596        {
3597          {
3598            'ShaDaMsgpackArray',
3599            'ShaDaMsgpackArray',
3600            'ShaDaMsgpackBinaryString',
3601            'ShaDaMsgpackStringQuotes',
3602          },
3603          '"',
3604        },
3605        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArray', 'ShaDaMsgpackStringQuotes' }, '"' },
3606        { { 'ShaDaMsgpackArray', 'ShaDaMsgpackArrayBraces' }, ']' },
3607        { { 'ShaDaMsgpackArrayBraces' }, ']' },
3608      },
3609      {
3610        hname('Buffer list'),
3611        h(' with timestamp '),
3612        synepoch.year,
3613        synhtssep('-'),
3614        synepoch.month,
3615        synhtssep('-'),
3616        synepoch.day,
3617        synhtssep('T'),
3618        synepoch.hour,
3619        synhtssep(':'),
3620        synepoch.minute,
3621        synhtssep(':'),
3622        synepoch.second,
3623        h(':'),
3624      },
3625      {
3626        mlh('  % Key  Description  Value'),
3627      },
3628      {},
3629      {
3630        mlh('  % Key  Description  Value'),
3631      },
3632      {
3633        hname('Header'),
3634        h(' with timestamp '),
3635        synepoch.year,
3636        synhtssep('-'),
3637        synepoch.month,
3638        synhtssep('-'),
3639        synepoch.day,
3640        synhtssep('T'),
3641        synepoch.hour,
3642        synhtssep(':'),
3643        synepoch.minute,
3644        synhtssep(':'),
3645        synepoch.second,
3646        h(':'),
3647      },
3648      {
3649        mlh('  % Key  Description________  Value'),
3650      },
3651      {
3652        mles('  + '),
3653        mlk('se   '),
3654        mld('place cursor at end  '),
3655        { { 'ShaDaEntryMapLong', 'ShaDaMsgpackKeyword' }, 'TRUE' },
3656      },
3657    }
3658    eq(exp, act)
3659  end)
3660end)