robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
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 () 12setup ( function () 13clear () 14local dos ='dos\r\ndos\r\n' 15local mac ='mac\rmac\r' 16local unix ='unix\nunix\n' 17local eol ='noeol' 18write_file ( 'XXDos' , dos ) 19write_file ( 'XXMac' , mac ) 20write_file ( 'XXUnix' , unix ) 21write_file ( 'XXEol' , eol ) 22write_file ( 'XXDosMac' , dos .. mac ) 23write_file ( 'XXMacEol' , mac .. eol ) 24write_file ( 'XXUxDs' , unix .. dos ) 25write_file ( 'XXUxDsMc' , unix .. dos .. mac ) 26write_file ( 'XXUxMac' , unix .. mac ) 27end ) 28 29teardown ( function () 30os . remove ( 'test.out' ) 31os . remove ( 'XXDos' ) 32os . remove ( 'XXMac' ) 33os . remove ( 'XXUnix' ) 34os . remove ( 'XXEol' ) 35os . remove ( 'XXDosMac' ) 36os . remove ( 'XXMacEol' ) 37os . remove ( 'XXUxDs' ) 38os . remove ( 'XXUxDsMc' ) 39os . remove ( 'XXUxMac' ) 40for i =0 , 9 do 41for j =1 , 4 do 42os . remove ( 'XXtt' .. i .. j ) 43end 44end 45end ) 46 47it ( 'is working' , function () 48 49-- Try reading and writing with 'fileformats' empty. 50command ( 'set fileformats=' ) 51command ( 'set fileformat=unix' ) 52command ( 'e! XXUnix' ) 53command ( 'w! test.out' ) 54command ( 'e! XXDos' ) 55command ( 'w! XXtt01' ) 56command ( 'e! XXMac' ) 57command ( 'w! XXtt02' ) 58command ( 'bwipe XXUnix XXDos XXMac' ) 59command ( 'set fileformat=dos' ) 60command ( 'e! XXUnix' ) 61command ( 'w! XXtt11' ) 62command ( 'e! XXDos' ) 63command ( 'w! XXtt12' ) 64command ( 'e! XXMac' ) 65command ( 'w! XXtt13' ) 66command ( 'bwipe XXUnix XXDos XXMac' ) 67command ( 'set fileformat=mac' ) 68command ( 'e! XXUnix' ) 69command ( 'w! XXtt21' ) 70command ( 'e! XXDos' ) 71command ( 'w! XXtt22' ) 72command ( 'e! XXMac' ) 73command ( 'w! XXtt23' ) 74command ( 'bwipe XXUnix XXDos XXMac' ) 75 76-- Try reading and writing with 'fileformats' set to one format. 77command ( 'set fileformats=unix' ) 78command ( 'e! XXUxDsMc' ) 79command ( 'w! XXtt31' ) 80command ( 'bwipe XXUxDsMc' ) 81command ( 'set fileformats=dos' ) 82command ( 'e! XXUxDsMc' ) 83command ( 'w! XXtt32' ) 84command ( 'bwipe XXUxDsMc' ) 85command ( 'set fileformats=mac' ) 86command ( 'e! XXUxDsMc' ) 87command ( 'w! XXtt33' ) 88command ( 'bwipe XXUxDsMc' ) 89 90-- Try reading and writing with 'fileformats' set to two formats. 91command ( 'set fileformats=unix,dos' ) 92command ( 'e! XXUxDsMc' ) 93command ( 'w! XXtt41' ) 94command ( 'bwipe XXUxDsMc' ) 95command ( 'e! XXUxMac' ) 96command ( 'w! XXtt42' ) 97command ( 'bwipe XXUxMac' ) 98command ( 'e! XXDosMac' ) 99command ( 'w! XXtt43' ) 100command ( 'bwipe XXDosMac' ) 101command ( 'set fileformats=unix,mac' ) 102command ( 'e! XXUxDs' ) 103command ( 'w! XXtt51' ) 104command ( 'bwipe XXUxDs' ) 105command ( 'e! XXUxDsMc' ) 106command ( 'w! XXtt52' ) 107command ( 'bwipe XXUxDsMc' ) 108command ( 'e! XXDosMac' ) 109command ( 'w! XXtt53' ) 110command ( 'bwipe XXDosMac' ) 111command ( 'e! XXEol' ) 112feed ( 'ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>' ) 113poke_eventloop () 114command ( 'w! XXtt54' ) 115command ( 'bwipeout! XXEol' ) 116command ( 'set fileformats=dos,mac' ) 117command ( 'e! XXUxDs' ) 118command ( 'w! XXtt61' ) 119command ( 'bwipe XXUxDs' ) 120command ( 'e! XXUxMac' ) 121feed ( 'ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>' ) 122poke_eventloop () 123command ( 'w! XXtt62' ) 124command ( 'bwipeout! XXUxMac' ) 125command ( 'e! XXUxDsMc' ) 126command ( 'w! XXtt63' ) 127command ( 'bwipe XXUxDsMc' ) 128command ( 'e! XXMacEol' ) 129feed ( 'ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>' ) 130poke_eventloop () 131command ( 'w! XXtt64' ) 132command ( 'bwipeout! XXMacEol' ) 133 134-- Try reading and writing with 'fileformats' set to three formats. 135command ( 'set fileformats=unix,dos,mac' ) 136command ( 'e! XXUxDsMc' ) 137command ( 'w! XXtt71' ) 138command ( 'bwipe XXUxDsMc' ) 139command ( 'e! XXEol' ) 140feed ( 'ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>' ) 141poke_eventloop () 142command ( 'w! XXtt72' ) 143command ( 'bwipeout! XXEol' ) 144command ( 'set fileformats=mac,dos,unix' ) 145command ( 'e! XXUxDsMc' ) 146command ( 'w! XXtt81' ) 147command ( 'bwipe XXUxDsMc' ) 148command ( 'e! XXEol' ) 149feed ( 'ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>' ) 150poke_eventloop () 151command ( 'w! XXtt82' ) 152command ( 'bwipeout! XXEol' ) 153-- Try with 'binary' set. 154command ( 'set fileformats=mac,unix,dos' ) 155command ( 'set binary' ) 156command ( 'e! XXUxDsMc' ) 157command ( 'w! XXtt91' ) 158command ( 'bwipe XXUxDsMc' ) 159command ( 'set fileformats=mac' ) 160command ( 'e! XXUxDsMc' ) 161command ( 'w! XXtt92' ) 162command ( 'bwipe XXUxDsMc' ) 163command ( 'set fileformats=dos' ) 164command ( 'e! XXUxDsMc' ) 165command ( 'w! XXtt93' ) 166 167-- Append "END" to each file so that we can see what the last written 168-- char was. 169command ( 'set fileformat=unix nobin' ) 170feed ( 'ggdGaEND<esc>' ) 171poke_eventloop () 172command ( 'w >>XXtt01' ) 173command ( 'w >>XXtt02' ) 174command ( 'w >>XXtt11' ) 175command ( 'w >>XXtt12' ) 176command ( 'w >>XXtt13' ) 177command ( 'w >>XXtt21' ) 178command ( 'w >>XXtt22' ) 179command ( 'w >>XXtt23' ) 180command ( 'w >>XXtt31' ) 181command ( 'w >>XXtt32' ) 182command ( 'w >>XXtt33' ) 183command ( 'w >>XXtt41' ) 184command ( 'w >>XXtt42' ) 185command ( 'w >>XXtt43' ) 186command ( 'w >>XXtt51' ) 187command ( 'w >>XXtt52' ) 188command ( 'w >>XXtt53' ) 189command ( 'w >>XXtt54' ) 190command ( 'w >>XXtt61' ) 191command ( 'w >>XXtt62' ) 192command ( 'w >>XXtt63' ) 193command ( 'w >>XXtt64' ) 194command ( 'w >>XXtt71' ) 195command ( 'w >>XXtt72' ) 196command ( 'w >>XXtt81' ) 197command ( 'w >>XXtt82' ) 198command ( 'w >>XXtt91' ) 199command ( 'w >>XXtt92' ) 200command ( 'w >>XXtt93' ) 201 202-- Concatenate the results. 203-- Make fileformat of test.out the native fileformat. 204-- Add a newline at the end. 205command ( 'set binary' ) 206command ( 'e! test.out' ) 207command ( '$r XXtt01' ) 208command ( '$r XXtt02' ) 209feed ( 'Go1<esc>' ) 210poke_eventloop () 211command ( '$r XXtt11' ) 212command ( '$r XXtt12' ) 213command ( '$r XXtt13' ) 214feed ( 'Go2<esc>' ) 215poke_eventloop () 216command ( '$r XXtt21' ) 217command ( '$r XXtt22' ) 218command ( '$r XXtt23' ) 219feed ( 'Go3<esc>' ) 220poke_eventloop () 221command ( '$r XXtt31' ) 222command ( '$r XXtt32' ) 223command ( '$r XXtt33' ) 224feed ( 'Go4<esc>' ) 225poke_eventloop () 226command ( '$r XXtt41' ) 227command ( '$r XXtt42' ) 228command ( '$r XXtt43' ) 229feed ( 'Go5<esc>' ) 230poke_eventloop () 231command ( '$r XXtt51' ) 232command ( '$r XXtt52' ) 233command ( '$r XXtt53' ) 234command ( '$r XXtt54' ) 235feed ( 'Go6<esc>' ) 236poke_eventloop () 237command ( '$r XXtt61' ) 238command ( '$r XXtt62' ) 239command ( '$r XXtt63' ) 240command ( '$r XXtt64' ) 241feed ( 'Go7<esc>' ) 242poke_eventloop () 243command ( '$r XXtt71' ) 244command ( '$r XXtt72' ) 245feed ( 'Go8<esc>' ) 246poke_eventloop () 247command ( '$r XXtt81' ) 248command ( '$r XXtt82' ) 249feed ( 'Go9<esc>' ) 250poke_eventloop () 251command ( '$r XXtt91' ) 252command ( '$r XXtt92' ) 253command ( '$r XXtt93' ) 254feed ( 'Go10<esc>' ) 255poke_eventloop () 256command ( '$r XXUnix' ) 257command ( '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. 262eq ( 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' , 393n . curbuf_contents ()) 394end ) 395end )