neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

030_fileformats_spec.lua (9638B)


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