fixeol_spec.lua 1.8 KB

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