robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.8 KiB75 linesraw
1-- Test for autocommand that deletes the current buffer on BufLeave event.
2-- Also test deleting the last buffer, should give a new, empty buffer.
3
4local n = require('test.functional.testnvim')()
5local t = require('test.testutil')
6
7local describe, it, setup, teardown = t.describe, t.it, t.setup, t.teardown
8local clear, feed, insert = n.clear, n.feed, n.insert
9local command, expect = n.command, n.expect
10local poke_eventloop = n.poke_eventloop
11
12describe('test5', function()
13  setup(clear)
14
15  -- luacheck: ignore 621 (Indentation)
16  it('is working', function()
17    insert([[
18      start of test file Xxx
19      vim: set noai :
20      	this is a test
21      	this is a test
22      	this is a test
23      	this is a test
24      end of test file Xxx]])
25
26    command('w! Xxx0')
27    command('au BufLeave Xxx bwipe')
28    command('/start of')
29
30    -- Write test file Xxx.
31    command('.,/end of/w! Xxx')
32
33    -- Split to Xxx.
34    command('sp Xxx')
35
36    -- Delete buffer Xxx, now we're back here.
37    command('bwipe')
38    feed('G?this is a<cr>')
39    feed('othis is some more text<esc>')
40    poke_eventloop()
41
42    -- Append some text to this file.
43
44    -- Write current file contents.
45    command('?start?,$yank A')
46
47    -- Delete current buffer, get an empty one.
48    command('bwipe!')
49    -- Append an extra line to the output register.
50    feed('ithis is another test line<esc>:yank A<cr>')
51    poke_eventloop()
52
53    -- Output results
54    command('%d')
55    command('0put a')
56    command('$d')
57
58    -- Assert buffer contents.
59    expect([[
60      start of test file Xxx
61      vim: set noai :
62      	this is a test
63      	this is a test
64      	this is a test
65      	this is a test
66      this is some more text
67      end of test file Xxx
68      this is another test line]])
69  end)
70
71  teardown(function()
72    os.remove('Xxx')
73    os.remove('Xxx0')
74  end)
75end)