blob: 3ede84f49e78b87ea3a32a4f4b0ad5514841fab9 [file] [log] [blame]
Bram Moolenaarfb0cf232022-10-22 11:25:19 +01001" Tests for 'fixeol', 'eof' and 'eol'
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaar209d3872017-11-16 21:52:51 +01003func 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!
Bram Moolenaarfb0cf232022-10-22 11:25:19 +01008 call setline('.', 'with eol or eof')
Bram Moolenaar209d3872017-11-16 21:52:51 +01009 w! XXEol
10 enew!
Bram Moolenaarfb0cf232022-10-22 11:25:19 +010011 set noeof noeol nofixeol
12 call setline('.', 'without eol or eof')
Bram Moolenaar209d3872017-11-16 21:52:51 +010013 w! XXNoEol
Bram Moolenaarfb0cf232022-10-22 11:25:19 +010014 set eol eof fixeol
Bram Moolenaar209d3872017-11-16 21:52:51 +010015 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', 'END'], readfile('XXEol'))
38 call assert_equal(['without eolEND'], readfile('XXNoEol'))
39 call assert_equal(['with eol', 'stays eol', 'END'], readfile('XXTestEol'))
40 call assert_equal(['without eol', 'stays withoutEND'],
41 \ readfile('XXTestNoEol'))
42
43 call delete('XXEol')
44 call delete('XXNoEol')
45 call delete('XXTestEol')
46 call delete('XXTestNoEol')
Bram Moolenaarfb0cf232022-10-22 11:25:19 +010047 set ff& fixeol& eof& eol&
Bram Moolenaar209d3872017-11-16 21:52:51 +010048 enew!
49endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020050
51" vim: shiftwidth=2 sts=2 expandtab