blob: 41d47d6a06974edeb024382d9a349384541b9540 [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
Bram Moolenaar15775372022-10-29 20:01:52 +010037 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'],
Bram Moolenaar209d3872017-11-16 21:52:51 +010041 \ 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
K.Takata3af98212022-11-01 20:36:19 +000051func 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!
116endfunc
117
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200118" vim: shiftwidth=2 sts=2 expandtab