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