robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.5 KiB56 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
5local clear = n.clear
6local command, eq, neq, write_file = n.command, t.eq, t.neq, t.write_file
7local read_file = t.read_file
8local is_os = t.is_os
9
10describe(':wshada', function()
11  local shada_file = 'wshada_test'
12
13  before_each(function()
14    clear {
15      args = {
16        '-i',
17        is_os('win') and 'nul' or '/dev/null',
18        -- Need 'swapfile' for these tests.
19        '--cmd',
20        'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler',
21      },
22      args_rm = { '-n', '-i', '--cmd' },
23    }
24  end)
25  after_each(function()
26    os.remove(shada_file)
27  end)
28
29  it('creates a shada file', function()
30    -- file should _not_ exist
31    eq(nil, vim.uv.fs_stat(shada_file))
32    command('wsh! ' .. shada_file)
33    -- file _should_ exist
34    neq(nil, vim.uv.fs_stat(shada_file))
35  end)
36
37  it('overwrites existing files', function()
38    local text = 'wshada test'
39
40    -- Create a dummy file
41    write_file(shada_file, text)
42
43    -- sanity check
44    eq(text, read_file(shada_file))
45    neq(nil, vim.uv.fs_stat(shada_file))
46
47    command('wsh! ' .. shada_file)
48
49    -- File should have been overwritten with a shada file.
50    local fp = io.open(shada_file, 'r')
51    local char1 = fp:read(1)
52    fp:close()
53    -- ShaDa file starts with a “header” entry
54    assert(char1:byte() == 0x01, shada_file .. ' should be a shada file')
55  end)
56end)