"Fossies" - the Fresh Open Source Software Archive

Member "neovim-0.3.8/test/functional/legacy/008_autocommands_spec.lua" (3 Jul 2019, 2512 Bytes) of package /linux/misc/neovim-0.3.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 -- Test for BufWritePre autocommand that deletes or unloads the buffer.
    2 -- Test for BufUnload autocommand that unloads all other buffers.
    3 
    4 local helpers = require('test.functional.helpers')(after_each)
    5 local source = helpers.source
    6 local clear, command, expect, eq, eval = helpers.clear, helpers.command, helpers.expect, helpers.eq, helpers.eval
    7 local write_file, dedent = helpers.write_file, helpers.dedent
    8 local read_file = helpers.read_file
    9 
   10 describe('autocommands that delete and unload buffers:', function()
   11   local test_file = 'Xtest-008_autocommands.out'
   12   local text1 = dedent([[
   13     start of Xxx1
   14       test
   15     end of Xxx]])
   16   local text2 = text1:gsub('1', '2')
   17   setup(function()
   18     write_file('Xxx1', text1..'\n')
   19     write_file('Xxx2', text2..'\n')
   20   end)
   21   teardown(function()
   22     os.remove(test_file)
   23     os.remove('Xxx1')
   24     os.remove('Xxx2')
   25   end)
   26   before_each(clear)
   27 
   28   it('BufWritePre, BufUnload', function()
   29     command('au BufWritePre Xxx1 bunload')
   30     command('au BufWritePre Xxx2 bwipe')
   31     command('e Xxx2')
   32     eq('Xxx2', eval('bufname("%")'))
   33     command('e Xxx1')
   34     eq('Xxx1', eval('bufname("%")'))
   35     -- The legacy test file did not check the error message.
   36     command('let v:errmsg = "no error"')
   37     command('silent! write')
   38     eq('E203: Autocommands deleted or unloaded buffer to be written',
   39       eval('v:errmsg'))
   40     eq('Xxx2', eval('bufname("%")'))
   41     expect(text2)
   42     -- Start editing Xxx2.
   43     command('e! Xxx2')
   44     -- The legacy test file did not check the error message.
   45     command('let v:errmsg = "no error"')
   46     -- Write Xxx2, will delete the buffer and give an error msg.
   47     command('silent! write')
   48     eq('E203: Autocommands deleted or unloaded buffer to be written',
   49       eval('v:errmsg'))
   50     eq('Xxx1', eval('bufname("%")'))
   51     expect(text1)
   52   end)
   53   it('BufUnload, VimLeave', function()
   54     source([[
   55       func CloseAll()
   56     let i = 0
   57     while i <= bufnr('$')
   58       if i != bufnr('%') && bufloaded(i)
   59         exe  i . "bunload"
   60       endif
   61       let i += 1
   62     endwhile
   63       endfunc
   64       func WriteToOut()
   65     edit! ]]..test_file..[[
   66 
   67     $put ='VimLeave done'
   68     write
   69       endfunc
   70       set shada='100
   71       au BufUnload * call CloseAll()
   72       au VimLeave * call WriteToOut()
   73     ]])
   74     command('silent! edit Xxx2')
   75     command('silent! edit Xxx1')
   76     command('silent! edit Makefile') -- an existing file
   77     command('silent! split new2')
   78     command('silent! quit')
   79     eq('VimLeave done',
   80        string.match(read_file(test_file), "^%s*(.-)%s*$"))
   81   end)
   82 end)