aboutsummaryrefslogtreecommitdiff
path: root/test/functional/shada/buffers_spec.lua
blob: b1c4ded541988296156406b4108024c8d95a170a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- shada buffer list saving/reading support
local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq, curbufmeths, meths =
  helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths
local expect_exit = helpers.expect_exit

local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear

describe('shada support code', function()
  local testfilename = 'Xtestfile-functional-shada-buffers'
  local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
  after_each(clear)

  it('is able to dump and restore buffer list', function()
    reset('set shada+=%')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%')
    eq(3, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
    eq(testfilename, funcs.bufname(2))
    eq(testfilename_2, funcs.bufname(3))
  end)

  it('does not restore buffer list without % in &shada', function()
    reset('set shada+=%')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset()
    eq(1, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
  end)

  it('does not dump buffer list without % in &shada', function()
    reset()
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%')
    eq(1, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
  end)

  it('does not dump unlisted buffer', function()
    reset('set shada+=%')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    meths.set_option_value('buflisted', false, {})
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%')
    eq(2, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
    eq(testfilename, funcs.bufname(2))
  end)

  it('does not dump quickfix buffer', function()
    reset('set shada+=%')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    meths.set_option_value('buftype', 'quickfix', {})
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%')
    eq(2, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
    eq(testfilename, funcs.bufname(2))
  end)

  it('does not dump unnamed buffers', function()
    reset('set shada+=% hidden')
    curbufmeths.set_lines(0, 1, true, {'foo'})
    nvim_command('enew')
    curbufmeths.set_lines(0, 1, true, {'bar'})
    eq(2, funcs.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, funcs.bufnr('$'))
    eq('', funcs.bufname(1))
    eq(testfilename, funcs.bufname(2))
  end)
end)