test_fixeol.vim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. " Tests for 'fixeol', 'eof' and 'eol'
  2. func Test_fixeol()
  3. " first write two test files – with and without trailing EOL
  4. " use Unix fileformat for consistency
  5. set ff=unix
  6. enew!
  7. call setline('.', 'with eol or eof')
  8. w! XXEol
  9. enew!
  10. set noeof noeol nofixeol
  11. call setline('.', 'without eol or eof')
  12. w! XXNoEol
  13. set eol eof fixeol
  14. bwipe XXEol XXNoEol
  15. " try editing files with 'fixeol' disabled
  16. e! XXEol
  17. normal ostays eol
  18. set nofixeol
  19. w! XXTestEol
  20. e! XXNoEol
  21. normal ostays without
  22. set nofixeol
  23. w! XXTestNoEol
  24. bwipe! XXEol XXNoEol XXTestEol XXTestNoEol
  25. set fixeol
  26. " Append "END" to each file so that we can see what the last written char
  27. " was.
  28. normal ggdGaEND
  29. w >>XXEol
  30. w >>XXNoEol
  31. w >>XXTestEol
  32. w >>XXTestNoEol
  33. call assert_equal(['with eol or eof', 'END'], readfile('XXEol'))
  34. call assert_equal(['without eol or eofEND'], readfile('XXNoEol'))
  35. call assert_equal(['with eol or eof', 'stays eol', 'END'], readfile('XXTestEol'))
  36. call assert_equal(['without eol or eof', 'stays withoutEND'],
  37. \ readfile('XXTestNoEol'))
  38. call delete('XXEol')
  39. call delete('XXNoEol')
  40. call delete('XXTestEol')
  41. call delete('XXTestNoEol')
  42. set ff& fixeol& eof& eol&
  43. enew!
  44. endfunc
  45. func Test_eof()
  46. let data = 0z68656c6c6f.0d0a.776f726c64 " "hello\r\nworld"
  47. " 1. Eol, Eof
  48. " read
  49. call writefile(data + 0z0d0a.1a, 'XXEolEof')
  50. e! XXEolEof
  51. call assert_equal(['hello', 'world'], getline(1, 2))
  52. call assert_equal([1, 1], [&eol, &eof])
  53. " write
  54. set fixeol
  55. w!
  56. call assert_equal(data + 0z0d0a, readblob('XXEolEof'))
  57. set nofixeol
  58. w!
  59. call assert_equal(data + 0z0d0a.1a, readblob('XXEolEof'))
  60. " 2. NoEol, Eof
  61. " read
  62. call writefile(data + 0z1a, 'XXNoEolEof')
  63. e! XXNoEolEof
  64. call assert_equal(['hello', 'world'], getline(1, 2))
  65. call assert_equal([0, 1], [&eol, &eof])
  66. " write
  67. set fixeol
  68. w!
  69. call assert_equal(data + 0z0d0a, readblob('XXNoEolEof'))
  70. set nofixeol
  71. w!
  72. call assert_equal(data + 0z1a, readblob('XXNoEolEof'))
  73. " 3. Eol, NoEof
  74. " read
  75. call writefile(data + 0z0d0a, 'XXEolNoEof')
  76. e! XXEolNoEof
  77. call assert_equal(['hello', 'world'], getline(1, 2))
  78. call assert_equal([1, 0], [&eol, &eof])
  79. " write
  80. set fixeol
  81. w!
  82. call assert_equal(data + 0z0d0a, readblob('XXEolNoEof'))
  83. set nofixeol
  84. w!
  85. call assert_equal(data + 0z0d0a, readblob('XXEolNoEof'))
  86. " 4. NoEol, NoEof
  87. " read
  88. call writefile(data, 'XXNoEolNoEof')
  89. e! XXNoEolNoEof
  90. call assert_equal(['hello', 'world'], getline(1, 2))
  91. call assert_equal([0, 0], [&eol, &eof])
  92. " write
  93. set fixeol
  94. w!
  95. call assert_equal(data + 0z0d0a, readblob('XXNoEolNoEof'))
  96. set nofixeol
  97. w!
  98. call assert_equal(data, readblob('XXNoEolNoEof'))
  99. call delete('XXEolEof')
  100. call delete('XXNoEolEof')
  101. call delete('XXEolNoEof')
  102. call delete('XXNoEolNoEof')
  103. set ff& fixeol& eof& eol&
  104. enew!
  105. endfunc
  106. " vim: shiftwidth=2 sts=2 expandtab