robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
9.5 KiB395 linesraw
1-- Test for a lot of variations of the 'fileformats' option
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5
6local describe, it, setup, teardown = t.describe, t.it, t.setup, t.teardown
7local feed, clear, command = n.feed, n.clear, n.command
8local eq, write_file = t.eq, t.write_file
9local poke_eventloop = n.poke_eventloop
10
11describe('fileformats option', function()
12  setup(function()
13    clear()
14    local dos = 'dos\r\ndos\r\n'
15    local mac = 'mac\rmac\r'
16    local unix = 'unix\nunix\n'
17    local eol = 'noeol'
18    write_file('XXDos', dos)
19    write_file('XXMac', mac)
20    write_file('XXUnix', unix)
21    write_file('XXEol', eol)
22    write_file('XXDosMac', dos..mac)
23    write_file('XXMacEol', mac..eol)
24    write_file('XXUxDs', unix..dos)
25    write_file('XXUxDsMc', unix..dos..mac)
26    write_file('XXUxMac', unix..mac)
27  end)
28
29  teardown(function()
30    os.remove('test.out')
31    os.remove('XXDos')
32    os.remove('XXMac')
33    os.remove('XXUnix')
34    os.remove('XXEol')
35    os.remove('XXDosMac')
36    os.remove('XXMacEol')
37    os.remove('XXUxDs')
38    os.remove('XXUxDsMc')
39    os.remove('XXUxMac')
40    for i = 0, 9 do
41      for j = 1, 4 do
42        os.remove('XXtt'..i..j)
43      end
44    end
45  end)
46
47  it('is working', function()
48
49    -- Try reading and writing with 'fileformats' empty.
50    command('set fileformats=')
51    command('set fileformat=unix')
52    command('e! XXUnix')
53    command('w! test.out')
54    command('e! XXDos')
55    command('w! XXtt01')
56    command('e! XXMac')
57    command('w! XXtt02')
58    command('bwipe XXUnix XXDos XXMac')
59    command('set fileformat=dos')
60    command('e! XXUnix')
61    command('w! XXtt11')
62    command('e! XXDos')
63    command('w! XXtt12')
64    command('e! XXMac')
65    command('w! XXtt13')
66    command('bwipe XXUnix XXDos XXMac')
67    command('set fileformat=mac')
68    command('e! XXUnix')
69    command('w! XXtt21')
70    command('e! XXDos')
71    command('w! XXtt22')
72    command('e! XXMac')
73    command('w! XXtt23')
74    command('bwipe XXUnix XXDos XXMac')
75
76    -- Try reading and writing with 'fileformats' set to one format.
77    command('set fileformats=unix')
78    command('e! XXUxDsMc')
79    command('w! XXtt31')
80    command('bwipe XXUxDsMc')
81    command('set fileformats=dos')
82    command('e! XXUxDsMc')
83    command('w! XXtt32')
84    command('bwipe XXUxDsMc')
85    command('set fileformats=mac')
86    command('e! XXUxDsMc')
87    command('w! XXtt33')
88    command('bwipe XXUxDsMc')
89
90    -- Try reading and writing with 'fileformats' set to two formats.
91    command('set fileformats=unix,dos')
92    command('e! XXUxDsMc')
93    command('w! XXtt41')
94    command('bwipe XXUxDsMc')
95    command('e! XXUxMac')
96    command('w! XXtt42')
97    command('bwipe XXUxMac')
98    command('e! XXDosMac')
99    command('w! XXtt43')
100    command('bwipe XXDosMac')
101    command('set fileformats=unix,mac')
102    command('e! XXUxDs')
103    command('w! XXtt51')
104    command('bwipe XXUxDs')
105    command('e! XXUxDsMc')
106    command('w! XXtt52')
107    command('bwipe XXUxDsMc')
108    command('e! XXDosMac')
109    command('w! XXtt53')
110    command('bwipe XXDosMac')
111    command('e! XXEol')
112    feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
113    poke_eventloop()
114    command('w! XXtt54')
115    command('bwipeout! XXEol')
116    command('set fileformats=dos,mac')
117    command('e! XXUxDs')
118    command('w! XXtt61')
119    command('bwipe XXUxDs')
120    command('e! XXUxMac')
121    feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
122    poke_eventloop()
123    command('w! XXtt62')
124    command('bwipeout! XXUxMac')
125    command('e! XXUxDsMc')
126    command('w! XXtt63')
127    command('bwipe XXUxDsMc')
128    command('e! XXMacEol')
129    feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
130    poke_eventloop()
131    command('w! XXtt64')
132    command('bwipeout! XXMacEol')
133
134    -- Try reading and writing with 'fileformats' set to three formats.
135    command('set fileformats=unix,dos,mac')
136    command('e! XXUxDsMc')
137    command('w! XXtt71')
138    command('bwipe XXUxDsMc')
139    command('e! XXEol')
140    feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
141    poke_eventloop()
142    command('w! XXtt72')
143    command('bwipeout! XXEol')
144    command('set fileformats=mac,dos,unix')
145    command('e! XXUxDsMc')
146    command('w! XXtt81')
147    command('bwipe XXUxDsMc')
148    command('e! XXEol')
149    feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>')
150    poke_eventloop()
151    command('w! XXtt82')
152    command('bwipeout! XXEol')
153    -- Try with 'binary' set.
154    command('set fileformats=mac,unix,dos')
155    command('set binary')
156    command('e! XXUxDsMc')
157    command('w! XXtt91')
158    command('bwipe XXUxDsMc')
159    command('set fileformats=mac')
160    command('e! XXUxDsMc')
161    command('w! XXtt92')
162    command('bwipe XXUxDsMc')
163    command('set fileformats=dos')
164    command('e! XXUxDsMc')
165    command('w! XXtt93')
166
167    -- Append "END" to each file so that we can see what the last written
168    -- char was.
169    command('set fileformat=unix nobin')
170    feed('ggdGaEND<esc>')
171    poke_eventloop()
172    command('w >>XXtt01')
173    command('w >>XXtt02')
174    command('w >>XXtt11')
175    command('w >>XXtt12')
176    command('w >>XXtt13')
177    command('w >>XXtt21')
178    command('w >>XXtt22')
179    command('w >>XXtt23')
180    command('w >>XXtt31')
181    command('w >>XXtt32')
182    command('w >>XXtt33')
183    command('w >>XXtt41')
184    command('w >>XXtt42')
185    command('w >>XXtt43')
186    command('w >>XXtt51')
187    command('w >>XXtt52')
188    command('w >>XXtt53')
189    command('w >>XXtt54')
190    command('w >>XXtt61')
191    command('w >>XXtt62')
192    command('w >>XXtt63')
193    command('w >>XXtt64')
194    command('w >>XXtt71')
195    command('w >>XXtt72')
196    command('w >>XXtt81')
197    command('w >>XXtt82')
198    command('w >>XXtt91')
199    command('w >>XXtt92')
200    command('w >>XXtt93')
201
202    -- Concatenate the results.
203    -- Make fileformat of test.out the native fileformat.
204    -- Add a newline at the end.
205    command('set binary')
206    command('e! test.out')
207    command('$r XXtt01')
208    command('$r XXtt02')
209    feed('Go1<esc>')
210    poke_eventloop()
211    command('$r XXtt11')
212    command('$r XXtt12')
213    command('$r XXtt13')
214    feed('Go2<esc>')
215    poke_eventloop()
216    command('$r XXtt21')
217    command('$r XXtt22')
218    command('$r XXtt23')
219    feed('Go3<esc>')
220    poke_eventloop()
221    command('$r XXtt31')
222    command('$r XXtt32')
223    command('$r XXtt33')
224    feed('Go4<esc>')
225    poke_eventloop()
226    command('$r XXtt41')
227    command('$r XXtt42')
228    command('$r XXtt43')
229    feed('Go5<esc>')
230    poke_eventloop()
231    command('$r XXtt51')
232    command('$r XXtt52')
233    command('$r XXtt53')
234    command('$r XXtt54')
235    feed('Go6<esc>')
236    poke_eventloop()
237    command('$r XXtt61')
238    command('$r XXtt62')
239    command('$r XXtt63')
240    command('$r XXtt64')
241    feed('Go7<esc>')
242    poke_eventloop()
243    command('$r XXtt71')
244    command('$r XXtt72')
245    feed('Go8<esc>')
246    poke_eventloop()
247    command('$r XXtt81')
248    command('$r XXtt82')
249    feed('Go9<esc>')
250    poke_eventloop()
251    command('$r XXtt91')
252    command('$r XXtt92')
253    command('$r XXtt93')
254    feed('Go10<esc>')
255    poke_eventloop()
256    command('$r XXUnix')
257    command('set nobinary ff&')
258
259    -- Assert buffer contents.  This has to be done manually as
260    -- n.expect() calls t.dedent() which messes up the white space
261    -- and carriage returns.
262    eq(
263      'unix\n'..
264      'unix\n'..
265      'dos\r\n'..
266      'dos\r\n'..
267      'END\n'..
268      'mac\rmac\r\n'..
269      'END\n'..
270      '1\n'..
271      'unix\r\n'..
272      'unix\r\n'..
273      'END\n'..
274      'dos\r\n'..
275      'dos\r\n'..
276      'END\n'..
277      'mac\rmac\r\r\n'..
278      'END\n'..
279      '2\n'..
280      'unix\n'..
281      'unix\n'..
282      '\rEND\n'..
283      'dos\r\n'..
284      'dos\r\n'..
285      '\rEND\n'..
286      'mac\rmac\rEND\n'..
287      '3\n'..
288      'unix\n'..
289      'unix\n'..
290      'dos\r\n'..
291      'dos\r\n'..
292      'mac\rmac\r\n'..
293      'END\n'..
294      'unix\r\n'..
295      'unix\r\n'..
296      'dos\r\n'..
297      'dos\r\n'..
298      'mac\rmac\r\r\n'..
299      'END\n'..
300      'unix\n'..
301      'unix\n'..
302      'dos\r\n'..
303      'dos\r\n'..
304      'mac\rmac\rEND\n'..
305      '4\n'..
306      'unix\n'..
307      'unix\n'..
308      'dos\r\n'..
309      'dos\r\n'..
310      'mac\rmac\r\n'..
311      'END\n'..
312      'unix\n'..
313      'unix\n'..
314      'mac\rmac\r\n'..
315      'END\n'..
316      'dos\r\n'..
317      'dos\r\n'..
318      'mac\rmac\r\r\n'..
319      'END\n'..
320      '5\n'..
321      'unix\n'..
322      'unix\n'..
323      'dos\r\n'..
324      'dos\r\n'..
325      'END\n'..
326      'unix\n'..
327      'unix\n'..
328      'dos\r\n'..
329      'dos\r\n'..
330      'mac\rmac\r\n'..
331      'END\n'..
332      'dos\r\n'..
333      'dos\r\n'..
334      'mac\rmac\rEND\n'..
335      'unix,mac:unix\n'..
336      'noeol\n'..
337      'END\n'..
338      '6\n'..
339      'unix\r\n'..
340      'unix\r\n'..
341      'dos\r\n'..
342      'dos\r\n'..
343      'END\n'..
344      'dos,mac:dos\r\n'..
345      'unix\r\n'..
346      'unix\r\n'..
347      'mac\rmac\r\r\n'..
348      'END\n'..
349      'unix\r\n'..
350      'unix\r\n'..
351      'dos\r\n'..
352      'dos\r\n'..
353      'mac\rmac\r\r\n'..
354      'END\n'..
355      'dos,mac:mac\rmac\rmac\rnoeol\rEND\n'..
356      '7\n'..
357      'unix\n'..
358      'unix\n'..
359      'dos\r\n'..
360      'dos\r\n'..
361      'mac\rmac\r\n'..
362      'END\n'..
363      'unix,dos,mac:unix\n'..
364      'noeol\n'..
365      'END\n'..
366      '8\n'..
367      'unix\n'..
368      'unix\n'..
369      'dos\r\n'..
370      'dos\r\n'..
371      'mac\rmac\r\n'..
372      'END\n'..
373      'mac,dos,unix:mac\rnoeol\rEND\n'..
374      '9\n'..
375      'unix\n'..
376      'unix\n'..
377      'dos\r\n'..
378      'dos\r\n'..
379      'mac\rmac\rEND\n'..
380      'unix\n'..
381      'unix\n'..
382      'dos\r\n'..
383      'dos\r\n'..
384      'mac\rmac\rEND\n'..
385      'unix\n'..
386      'unix\n'..
387      'dos\r\n'..
388      'dos\r\n'..
389      'mac\rmac\rEND\n'..
390      '10\n'..
391      'unix\n'..
392      'unix',
393      n.curbuf_contents())
394  end)
395end)