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