2015-05-15 10:03:45 -07:00
|
|
|
-- Test for a lot of variations of the 'fileformats' option
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local feed, clear, command = n.feed, n.clear, n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq, write_file = t.eq, t.write_file
|
2024-04-20 08:44:13 -07:00
|
|
|
local poke_eventloop = n.poke_eventloop
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
describe('fileformats option', function()
|
|
|
|
setup(function()
|
|
|
|
clear()
|
|
|
|
local dos = 'dos\r\ndos\r\n'
|
|
|
|
local mac = 'mac\rmac\r'
|
|
|
|
local unix = 'unix\nunix\n'
|
2016-02-06 01:15:00 -07:00
|
|
|
local eol = 'noeol'
|
2015-05-15 10:03:45 -07:00
|
|
|
write_file('XXDos', dos)
|
|
|
|
write_file('XXMac', mac)
|
|
|
|
write_file('XXUnix', unix)
|
2016-02-06 01:15:00 -07:00
|
|
|
write_file('XXEol', eol)
|
2015-05-15 10:03:45 -07:00
|
|
|
write_file('XXDosMac', dos..mac)
|
2016-02-06 01:15:00 -07:00
|
|
|
write_file('XXMacEol', mac..eol)
|
2015-05-15 10:03:45 -07:00
|
|
|
write_file('XXUxDs', unix..dos)
|
|
|
|
write_file('XXUxDsMc', unix..dos..mac)
|
|
|
|
write_file('XXUxMac', unix..mac)
|
|
|
|
end)
|
2016-07-28 11:35:06 -07:00
|
|
|
|
2015-05-15 10:03:45 -07:00
|
|
|
teardown(function()
|
|
|
|
os.remove('test.out')
|
|
|
|
os.remove('XXDos')
|
|
|
|
os.remove('XXMac')
|
|
|
|
os.remove('XXUnix')
|
2016-02-06 01:15:00 -07:00
|
|
|
os.remove('XXEol')
|
2015-05-15 10:03:45 -07:00
|
|
|
os.remove('XXDosMac')
|
2016-02-06 01:15:00 -07:00
|
|
|
os.remove('XXMacEol')
|
2015-05-15 10:03:45 -07:00
|
|
|
os.remove('XXUxDs')
|
|
|
|
os.remove('XXUxDsMc')
|
|
|
|
os.remove('XXUxMac')
|
|
|
|
for i = 0, 9 do
|
2016-02-06 01:15:00 -07:00
|
|
|
for j = 1, 4 do
|
2016-07-28 11:35:06 -07:00
|
|
|
os.remove('XXtt'..i..j)
|
2015-05-15 10:03:45 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('is working', function()
|
|
|
|
|
|
|
|
-- Try reading and writing with 'fileformats' empty.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=')
|
|
|
|
command('set fileformat=unix')
|
|
|
|
command('e! XXUnix')
|
|
|
|
command('w! test.out')
|
|
|
|
command('e! XXDos')
|
|
|
|
command('w! XXtt01')
|
|
|
|
command('e! XXMac')
|
|
|
|
command('w! XXtt02')
|
|
|
|
command('bwipe XXUnix XXDos XXMac')
|
|
|
|
command('set fileformat=dos')
|
|
|
|
command('e! XXUnix')
|
|
|
|
command('w! XXtt11')
|
|
|
|
command('e! XXDos')
|
|
|
|
command('w! XXtt12')
|
|
|
|
command('e! XXMac')
|
|
|
|
command('w! XXtt13')
|
|
|
|
command('bwipe XXUnix XXDos XXMac')
|
|
|
|
command('set fileformat=mac')
|
|
|
|
command('e! XXUnix')
|
|
|
|
command('w! XXtt21')
|
|
|
|
command('e! XXDos')
|
|
|
|
command('w! XXtt22')
|
|
|
|
command('e! XXMac')
|
|
|
|
command('w! XXtt23')
|
|
|
|
command('bwipe XXUnix XXDos XXMac')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
-- Try reading and writing with 'fileformats' set to one format.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=unix')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt31')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('set fileformats=dos')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt32')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('set fileformats=mac')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt33')
|
|
|
|
command('bwipe XXUxDsMc')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
-- Try reading and writing with 'fileformats' set to two formats.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=unix,dos')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt41')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('e! XXUxMac')
|
|
|
|
command('w! XXtt42')
|
|
|
|
command('bwipe XXUxMac')
|
|
|
|
command('e! XXDosMac')
|
|
|
|
command('w! XXtt43')
|
|
|
|
command('bwipe XXDosMac')
|
|
|
|
command('set fileformats=unix,mac')
|
|
|
|
command('e! XXUxDs')
|
|
|
|
command('w! XXtt51')
|
|
|
|
command('bwipe XXUxDs')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt52')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('e! XXDosMac')
|
|
|
|
command('w! XXtt53')
|
|
|
|
command('bwipe XXDosMac')
|
|
|
|
command('e! XXEol')
|
2016-02-06 01:15:00 -07:00
|
|
|
feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w! XXtt54')
|
2017-04-08 15:38:50 -07:00
|
|
|
command('bwipeout! XXEol')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=dos,mac')
|
|
|
|
command('e! XXUxDs')
|
|
|
|
command('w! XXtt61')
|
|
|
|
command('bwipe XXUxDs')
|
|
|
|
command('e! XXUxMac')
|
2016-02-06 01:15:00 -07:00
|
|
|
feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w! XXtt62')
|
2017-04-08 15:38:50 -07:00
|
|
|
command('bwipeout! XXUxMac')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt63')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('e! XXMacEol')
|
2016-02-06 01:15:00 -07:00
|
|
|
feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w! XXtt64')
|
2017-04-08 15:38:50 -07:00
|
|
|
command('bwipeout! XXMacEol')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
-- Try reading and writing with 'fileformats' set to three formats.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=unix,dos,mac')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt71')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('e! XXEol')
|
2016-02-06 01:15:00 -07:00
|
|
|
feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w! XXtt72')
|
2017-04-08 15:38:50 -07:00
|
|
|
command('bwipeout! XXEol')
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=mac,dos,unix')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt81')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('e! XXEol')
|
2016-02-06 01:15:00 -07:00
|
|
|
feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w! XXtt82')
|
2017-04-08 15:38:50 -07:00
|
|
|
command('bwipeout! XXEol')
|
2015-05-15 10:03:45 -07:00
|
|
|
-- Try with 'binary' set.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformats=mac,unix,dos')
|
|
|
|
command('set binary')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt91')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('set fileformats=mac')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt92')
|
|
|
|
command('bwipe XXUxDsMc')
|
|
|
|
command('set fileformats=dos')
|
|
|
|
command('e! XXUxDsMc')
|
|
|
|
command('w! XXtt93')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
2016-07-28 11:35:06 -07:00
|
|
|
-- Append "END" to each file so that we can see what the last written
|
|
|
|
-- char was.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set fileformat=unix nobin')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('ggdGaEND<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('w >>XXtt01')
|
|
|
|
command('w >>XXtt02')
|
|
|
|
command('w >>XXtt11')
|
|
|
|
command('w >>XXtt12')
|
|
|
|
command('w >>XXtt13')
|
|
|
|
command('w >>XXtt21')
|
|
|
|
command('w >>XXtt22')
|
|
|
|
command('w >>XXtt23')
|
|
|
|
command('w >>XXtt31')
|
|
|
|
command('w >>XXtt32')
|
|
|
|
command('w >>XXtt33')
|
|
|
|
command('w >>XXtt41')
|
|
|
|
command('w >>XXtt42')
|
|
|
|
command('w >>XXtt43')
|
|
|
|
command('w >>XXtt51')
|
|
|
|
command('w >>XXtt52')
|
|
|
|
command('w >>XXtt53')
|
|
|
|
command('w >>XXtt54')
|
|
|
|
command('w >>XXtt61')
|
|
|
|
command('w >>XXtt62')
|
|
|
|
command('w >>XXtt63')
|
|
|
|
command('w >>XXtt64')
|
|
|
|
command('w >>XXtt71')
|
|
|
|
command('w >>XXtt72')
|
|
|
|
command('w >>XXtt81')
|
|
|
|
command('w >>XXtt82')
|
|
|
|
command('w >>XXtt91')
|
|
|
|
command('w >>XXtt92')
|
|
|
|
command('w >>XXtt93')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
-- Concatenate the results.
|
|
|
|
-- Make fileformat of test.out the native fileformat.
|
|
|
|
-- Add a newline at the end.
|
2017-04-08 14:12:26 -07:00
|
|
|
command('set binary')
|
|
|
|
command('e! test.out')
|
|
|
|
command('$r XXtt01')
|
|
|
|
command('$r XXtt02')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go1<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt11')
|
|
|
|
command('$r XXtt12')
|
|
|
|
command('$r XXtt13')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go2<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt21')
|
|
|
|
command('$r XXtt22')
|
|
|
|
command('$r XXtt23')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go3<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt31')
|
|
|
|
command('$r XXtt32')
|
|
|
|
command('$r XXtt33')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go4<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt41')
|
|
|
|
command('$r XXtt42')
|
|
|
|
command('$r XXtt43')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go5<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt51')
|
|
|
|
command('$r XXtt52')
|
|
|
|
command('$r XXtt53')
|
|
|
|
command('$r XXtt54')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go6<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt61')
|
|
|
|
command('$r XXtt62')
|
|
|
|
command('$r XXtt63')
|
|
|
|
command('$r XXtt64')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go7<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt71')
|
|
|
|
command('$r XXtt72')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go8<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt81')
|
|
|
|
command('$r XXtt82')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go9<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXtt91')
|
|
|
|
command('$r XXtt92')
|
|
|
|
command('$r XXtt93')
|
2015-05-15 10:03:45 -07:00
|
|
|
feed('Go10<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$r XXUnix')
|
|
|
|
command('set nobinary ff&')
|
2015-05-15 10:03:45 -07:00
|
|
|
|
|
|
|
-- Assert buffer contents. This has to be done manually as
|
2024-04-20 08:44:13 -07:00
|
|
|
-- n.expect() calls t.dedent() which messes up the white space
|
2015-05-15 10:03:45 -07:00
|
|
|
-- and carriage returns.
|
|
|
|
eq(
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'1\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'mac\rmac\r\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'2\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'\rEND\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'\rEND\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
|
|
|
'3\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
|
|
|
'4\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'5\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
2016-02-06 01:15:00 -07:00
|
|
|
'unix,mac:unix\n'..
|
|
|
|
'noeol\n'..
|
|
|
|
'END\n'..
|
2015-05-15 10:03:45 -07:00
|
|
|
'6\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'END\n'..
|
2016-02-06 01:15:00 -07:00
|
|
|
'dos,mac:dos\r\n'..
|
2015-05-15 10:03:45 -07:00
|
|
|
'unix\r\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'mac\rmac\r\r\n'..
|
|
|
|
'END\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'unix\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\r\n'..
|
|
|
|
'END\n'..
|
2016-02-06 01:15:00 -07:00
|
|
|
'dos,mac:mac\rmac\rmac\rnoeol\rEND\n'..
|
2015-05-15 10:03:45 -07:00
|
|
|
'7\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
2016-02-06 01:15:00 -07:00
|
|
|
'unix,dos,mac:unix\n'..
|
|
|
|
'noeol\n'..
|
|
|
|
'END\n'..
|
2015-05-15 10:03:45 -07:00
|
|
|
'8\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\r\n'..
|
|
|
|
'END\n'..
|
2016-02-06 01:15:00 -07:00
|
|
|
'mac,dos,unix:mac\rnoeol\rEND\n'..
|
2015-05-15 10:03:45 -07:00
|
|
|
'9\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'dos\r\n'..
|
|
|
|
'mac\rmac\rEND\n'..
|
|
|
|
'10\n'..
|
|
|
|
'unix\n'..
|
|
|
|
'unix',
|
2024-04-20 08:44:13 -07:00
|
|
|
n.curbuf_contents())
|
2015-05-15 10:03:45 -07:00
|
|
|
end)
|
|
|
|
end)
|