robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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