fixeol_spec.lua 2.0 KB

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