neovim

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

fixeol_spec.lua (1838B)


      1 -- Tests for 'fixeol'
      2 
      3 local n = require('test.functional.testnvim')()
      4 
      5 local feed = n.feed
      6 local clear, feed_command, expect = n.clear, n.feed_command, n.expect
      7 
      8 describe('fixeol', function()
      9  local function rmtestfiles()
     10    os.remove('test.out')
     11    os.remove('XXEol')
     12    os.remove('XXNoEol')
     13    os.remove('XXTestEol')
     14    os.remove('XXTestNoEol')
     15  end
     16  setup(function()
     17    clear()
     18    rmtestfiles()
     19  end)
     20  teardown(function()
     21    rmtestfiles()
     22  end)
     23 
     24  it('is working', function()
     25    -- First write two test files – with and without trailing EOL.
     26    feed_command('enew!')
     27    feed('awith eol<esc>:w! XXEol<cr>')
     28    feed_command('enew!')
     29    feed_command('set noeol nofixeol')
     30    feed('awithout eol<esc>:w! XXNoEol<cr>')
     31    feed_command('set eol fixeol')
     32    feed_command('bwipe XXEol XXNoEol')
     33 
     34    -- Try editing files with 'fixeol' disabled.
     35    feed_command('e! XXEol')
     36    feed('ostays eol<esc>:set nofixeol<cr>')
     37    feed_command('w! XXTestEol')
     38    feed_command('e! XXNoEol')
     39    feed('ostays without<esc>:set nofixeol<cr>')
     40    feed_command('w! XXTestNoEol')
     41    feed_command('bwipe! XXEol XXNoEol XXTestEol XXTestNoEol')
     42    feed_command('set fixeol')
     43 
     44    -- Append "END" to each file so that we can see what the last written char was.
     45    feed('ggdGaEND<esc>:w >>XXEol<cr>')
     46    feed_command('w >>XXNoEol')
     47    feed_command('w >>XXTestEol')
     48    feed_command('w >>XXTestNoEol')
     49 
     50    -- Concatenate the results.
     51    feed_command('e! test.out')
     52    feed('a0<esc>:$r XXEol<cr>')
     53    feed_command('$r XXNoEol')
     54    feed('Go1<esc>:$r XXTestEol<cr>')
     55    feed_command('$r XXTestNoEol')
     56    feed_command('w')
     57 
     58    -- Assert buffer contents.
     59    expect([=[
     60      0
     61      with eol
     62      END
     63      without eolEND
     64      1
     65      with eol
     66      stays eol
     67      END
     68      without eol
     69      stays withoutEND]=])
     70  end)
     71 end)