fixeol_spec.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. feed_command('enew!')
  24. feed('awith eol<esc>:w! XXEol<cr>')
  25. feed_command('enew!')
  26. feed_command('set noeol nofixeol')
  27. feed('awithout eol<esc>:w! XXNoEol<cr>')
  28. feed_command('set eol fixeol')
  29. feed_command('bwipe XXEol XXNoEol')
  30. -- Try editing files with 'fixeol' disabled.
  31. feed_command('e! XXEol')
  32. feed('ostays eol<esc>:set nofixeol<cr>')
  33. feed_command('w! XXTestEol')
  34. feed_command('e! XXNoEol')
  35. feed('ostays without<esc>:set nofixeol<cr>')
  36. feed_command('w! XXTestNoEol')
  37. feed_command('bwipe! XXEol XXNoEol XXTestEol XXTestNoEol')
  38. feed_command('set fixeol')
  39. -- Append "END" to each file so that we can see what the last written char was.
  40. feed('ggdGaEND<esc>:w >>XXEol<cr>')
  41. feed_command('w >>XXNoEol')
  42. feed_command('w >>XXTestEol')
  43. feed_command('w >>XXTestNoEol')
  44. -- Concatenate the results.
  45. feed_command('e! test.out')
  46. feed('a0<esc>:$r XXEol<cr>')
  47. feed_command('$r XXNoEol')
  48. feed('Go1<esc>:$r XXTestEol<cr>')
  49. feed_command('$r XXTestNoEol')
  50. feed_command('w')
  51. -- Assert buffer contents.
  52. expect([=[
  53. 0
  54. with eol
  55. END
  56. without eolEND
  57. 1
  58. with eol
  59. stays eol
  60. END
  61. without eol
  62. stays withoutEND]=])
  63. end)
  64. end)