neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

004_bufenter_with_modelines_spec.lua (2049B)


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