robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.1 KiB83 linesraw
1-- Test for autocommand that changes current buffer on BufEnter event.
2-- Check if modelines are interpreted for the correct 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 feed_command, expect = n.feed_command, n.expect
10
11describe('BufEnter with modelines', function()
12  setup(clear)
13
14  it('is working', function()
15    insert([[
16      startstart
17      start of test file Xxx
18      vim: set noai :
19          this is a test
20          this is a test
21          this is a test
22          this is a test
23      end of test file Xxx]])
24
25    feed_command('au BufEnter Xxx brew')
26
27    -- Write test file Xxx
28    feed_command('/start of')
29    feed_command('.,/end of/w! Xxx')
30    feed_command('set ai modeline modelines=3')
31
32    -- Split to Xxx, autocmd will do :brew
33    feed_command('sp Xxx')
34
35    -- Append text with autoindent to this file
36    feed('G?this is a<CR>')
37    feed('othis should be auto-indented<Esc>')
38
39    -- Go to Xxx, no autocmd anymore
40    feed_command('au! BufEnter Xxx')
41    feed_command('buf Xxx')
42
43    -- Append text without autoindent to Xxx
44    feed('G?this is a<CR>')
45    feed('othis should be in column 1<Esc>')
46    feed_command('wq')
47
48    -- Include Xxx in the current file
49    feed('G:r Xxx<CR>')
50
51    -- Vim issue #57 do not move cursor on <c-o> when autoindent is set
52    feed_command('set fo+=r')
53    feed('G')
54    feed('o# abcdef<Esc>2hi<CR><c-o>d0<Esc>')
55    feed('o# abcdef<Esc>2hi<c-o>d0<Esc>')
56
57    expect([[
58      startstart
59      start of test file Xxx
60      vim: set noai :
61          this is a test
62          this is a test
63          this is a test
64          this is a test
65          this should be auto-indented
66      end of test file Xxx
67      start of test file Xxx
68      vim: set noai :
69          this is a test
70          this is a test
71          this is a test
72          this is a test
73      this should be in column 1
74      end of test file Xxx
75      # abc
76      def
77      def]])
78  end)
79
80  teardown(function()
81    os.remove('Xxx')
82  end)
83end)