aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/buffer_spec.lua
blob: 1e8909f0d0d64f5e0760c7b117e145e1dd005112 (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
local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source
local call, eq, meths = helpers.call, helpers.eq, helpers.meths

local function expected_empty()
  eq({}, meths.get_vvar('errors'))
end

describe('buffer', function()
  before_each(function()
    clear()
    meths.ui_attach(80, 24, {})
    meths.set_option_value('hidden', false, {})
  end)

  it('deleting a modified buffer with :confirm', function()
    source([[
      func Test_bdel_with_confirm()
        new
        call setline(1, 'test')
        call assert_fails('bdel', 'E89:')
        call nvim_input('c')
        confirm bdel
        call assert_equal(2, winnr('$'))
        call assert_equal(1, &modified)
        call nvim_input('n')
        confirm bdel
        call assert_equal(1, winnr('$'))
      endfunc
    ]])
    call('Test_bdel_with_confirm')
    expected_empty()
  end)

  it('editing another buffer from a modified buffer with :confirm', function()
    source([[
      func Test_goto_buf_with_confirm()
        new Xfile
        enew
        call setline(1, 'test')
        call assert_fails('b Xfile', 'E37:')
        call nvim_input('c')
        call assert_fails('confirm b Xfile', 'E37:')
        call assert_equal(1, &modified)
        call assert_equal('', @%)
        call nvim_input('y')
        call assert_fails('confirm b Xfile', 'E37:')
        call assert_equal(1, &modified)
        call assert_equal('', @%)
        call nvim_input('n')
        confirm b Xfile
        call assert_equal('Xfile', @%)
        close!
      endfunc
    ]])
    call('Test_goto_buf_with_confirm')
    expected_empty()
  end)
end)