1" Tests for the writefile() function and some :write commands. 2 3source check.vim 4source term_util.vim 5 6func Test_writefile() 7 let f = tempname() 8 call writefile(["over","written"], f, "b") 9 call writefile(["hello","world"], f, "b") 10 call writefile(["!", "good"], f, "a") 11 call writefile(["morning"], f, "ab") 12 call writefile(["", "vimmers"], f, "ab") 13 let l = readfile(f) 14 call assert_equal("hello", l[0]) 15 call assert_equal("world!", l[1]) 16 call assert_equal("good", l[2]) 17 call assert_equal("morning", l[3]) 18 call assert_equal("vimmers", l[4]) 19 call delete(f) 20 21 call assert_fails('call writefile("text", "Xfile")', 'E475: Invalid argument: writefile() first argument must be a List or a Blob') 22endfunc 23 24func Test_writefile_ignore_regexp_error() 25 write Xt[z-a]est.txt 26 call delete('Xt[z-a]est.txt') 27endfunc 28 29func Test_writefile_fails_gently() 30 call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:') 31 call assert_false(filereadable("Xfile")) 32 call delete("Xfile") 33 34 call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:') 35 call assert_false(filereadable("Xfile")) 36 call delete("Xfile") 37 38 call assert_fails('call writefile([], "Xfile", [])', 'E730:') 39 call assert_false(filereadable("Xfile")) 40 call delete("Xfile") 41 42 call assert_fails('call writefile([], [])', 'E730:') 43endfunc 44 45func Test_writefile_fails_conversion() 46 if !has('iconv') || has('sun') 47 return 48 endif 49 " Without a backup file the write won't happen if there is a conversion 50 " error. 51 set nobackup nowritebackup backupdir=. backupskip= 52 new 53 let contents = ["line one", "line two"] 54 call writefile(contents, 'Xfile') 55 edit Xfile 56 call setline(1, ["first line", "cannot convert \u010b", "third line"]) 57 call assert_fails('write ++enc=cp932', 'E513:') 58 call assert_equal(contents, readfile('Xfile')) 59 60 call delete('Xfile') 61 bwipe! 62 set backup& writebackup& backupdir&vim backupskip&vim 63endfunc 64 65func Test_writefile_fails_conversion2() 66 if !has('iconv') || has('sun') 67 return 68 endif 69 " With a backup file the write happens even if there is a conversion error, 70 " but then the backup file must remain 71 set nobackup writebackup backupdir=. backupskip= 72 let contents = ["line one", "line two"] 73 call writefile(contents, 'Xfile_conversion_err') 74 edit Xfile_conversion_err 75 call setline(1, ["first line", "cannot convert \u010b", "third line"]) 76 set fileencoding=latin1 77 let output = execute('write') 78 call assert_match('CONVERSION ERROR', output) 79 call assert_equal(contents, readfile('Xfile_conversion_err~')) 80 81 call delete('Xfile_conversion_err') 82 call delete('Xfile_conversion_err~') 83 bwipe! 84 set backup& writebackup& backupdir&vim backupskip&vim 85endfunc 86 87func SetFlag(timer) 88 let g:flag = 1 89endfunc 90 91func Test_write_quit_split() 92 " Prevent exiting by splitting window on file write. 93 augroup testgroup 94 autocmd BufWritePre * split 95 augroup END 96 e! Xfile 97 call setline(1, 'nothing') 98 wq 99 100 if has('timers') 101 " timer will not run if "exiting" is still set 102 let g:flag = 0 103 call timer_start(1, 'SetFlag') 104 sleep 50m 105 call assert_equal(1, g:flag) 106 unlet g:flag 107 endif 108 au! testgroup 109 bwipe Xfile 110 call delete('Xfile') 111endfunc 112 113func Test_nowrite_quit_split() 114 " Prevent exiting by opening a help window. 115 e! Xfile 116 help 117 wincmd w 118 exe winnr() . 'q' 119 120 if has('timers') 121 " timer will not run if "exiting" is still set 122 let g:flag = 0 123 call timer_start(1, 'SetFlag') 124 sleep 50m 125 call assert_equal(1, g:flag) 126 unlet g:flag 127 endif 128 bwipe Xfile 129endfunc 130 131func Test_writefile_sync_arg() 132 " This doesn't check if fsync() works, only that the argument is accepted. 133 call writefile(['one'], 'Xtest', 's') 134 call writefile(['two'], 'Xtest', 'S') 135 call delete('Xtest') 136endfunc 137 138func Test_writefile_sync_dev_stdout() 139 CheckUnix 140 if filewritable('/dev/stdout') 141 " Just check that this doesn't cause an error. 142 call writefile(['one'], '/dev/stdout') 143 else 144 throw 'Skipped: /dev/stdout is not writable' 145 endif 146endfunc 147 148func Test_writefile_autowrite() 149 set autowrite 150 new 151 next Xa Xb Xc 152 call setline(1, 'aaa') 153 next 154 call assert_equal(['aaa'], readfile('Xa')) 155 call setline(1, 'bbb') 156 call assert_fails('edit XX') 157 call assert_false(filereadable('Xb')) 158 159 set autowriteall 160 edit XX 161 call assert_equal(['bbb'], readfile('Xb')) 162 163 bwipe! 164 call delete('Xa') 165 call delete('Xb') 166 set noautowrite 167endfunc 168 169func Test_writefile_autowrite_nowrite() 170 set autowrite 171 new 172 next Xa Xb Xc 173 set buftype=nowrite 174 call setline(1, 'aaa') 175 let buf = bufnr('%') 176 " buffer contents silently lost 177 edit XX 178 call assert_false(filereadable('Xa')) 179 rewind 180 call assert_equal('', getline(1)) 181 182 bwipe! 183 set noautowrite 184endfunc 185 186" Test for ':w !<cmd>' to pipe lines from the current buffer to an external 187" command. 188func Test_write_pipe_to_cmd() 189 CheckUnix 190 new 191 call setline(1, ['L1', 'L2', 'L3', 'L4']) 192 2,3w !cat > Xfile 193 call assert_equal(['L2', 'L3'], readfile('Xfile')) 194 close! 195 call delete('Xfile') 196endfunc 197 198" Test for :saveas 199func Test_saveas() 200 call assert_fails('saveas', 'E471:') 201 call writefile(['L1'], 'Xfile') 202 new Xfile 203 new 204 call setline(1, ['L1']) 205 call assert_fails('saveas Xfile', 'E139:') 206 close! 207 enew | only 208 call delete('Xfile') 209endfunc 210 211func Test_write_errors() 212 " Test for writing partial buffer 213 call writefile(['L1', 'L2', 'L3'], 'Xfile') 214 new Xfile 215 call assert_fails('1,2write', 'E140:') 216 close! 217 218 call assert_fails('w > Xtest', 'E494:') 219 220 " Try to overwrite a directory 221 if has('unix') 222 call mkdir('Xdir1') 223 call assert_fails('write Xdir1', 'E17:') 224 call delete('Xdir1', 'd') 225 endif 226 227 " Test for :wall for a buffer with no name 228 enew | only 229 call setline(1, ['L1']) 230 call assert_fails('wall', 'E141:') 231 enew! 232 233 " Test for writing a 'readonly' file 234 new Xfile 235 set readonly 236 call assert_fails('write', 'E45:') 237 close 238 239 " Test for writing to a read-only file 240 new Xfile 241 call setfperm('Xfile', 'r--r--r--') 242 call assert_fails('write', 'E505:') 243 call setfperm('Xfile', 'rw-rw-rw-') 244 close 245 246 call delete('Xfile') 247 248 call writefile(test_null_list(), 'Xfile') 249 call assert_false(filereadable('Xfile')) 250 call writefile(test_null_blob(), 'Xfile') 251 call assert_false(filereadable('Xfile')) 252 call assert_fails('call writefile([], "")', 'E482:') 253 254 " very long file name 255 let long_fname = repeat('n', 5000) 256 call assert_fails('exe "w " .. long_fname', 'E75:') 257 call assert_fails('call writefile([], long_fname)', 'E482:') 258endfunc 259 260" Test for writing to a file which is modified after Vim read it 261func Test_write_file_mtime() 262 CheckEnglish 263 CheckRunVimInTerminal 264 265 " First read the file into a buffer 266 call writefile(["Line1", "Line2"], 'Xfile') 267 let old_ftime = getftime('Xfile') 268 let buf = RunVimInTerminal('Xfile', #{rows : 10}) 269 call term_wait(buf) 270 call term_sendkeys(buf, ":set noswapfile\<CR>") 271 call term_wait(buf) 272 273 " Modify the file directly. Make sure the file modification time is 274 " different. Note that on Linux/Unix, the file is considered modified 275 " outside, only if the difference is 2 seconds or more 276 sleep 1 277 call writefile(["Line3", "Line4"], 'Xfile') 278 let new_ftime = getftime('Xfile') 279 while new_ftime - old_ftime < 2 280 sleep 100m 281 call writefile(["Line3", "Line4"], 'Xfile') 282 let new_ftime = getftime('Xfile') 283 endwhile 284 285 " Try to overwrite the file and check for the prompt 286 call term_sendkeys(buf, ":w\<CR>") 287 call term_wait(buf) 288 call WaitForAssert({-> assert_equal("WARNING: The file has been changed since reading it!!!", term_getline(buf, 9))}) 289 call assert_equal("Do you really want to write to it (y/n)?", 290 \ term_getline(buf, 10)) 291 call term_sendkeys(buf, "n\<CR>") 292 call term_wait(buf) 293 call assert_equal(new_ftime, getftime('Xfile')) 294 call term_sendkeys(buf, ":w\<CR>") 295 call term_wait(buf) 296 call term_sendkeys(buf, "y\<CR>") 297 call term_wait(buf) 298 call WaitForAssert({-> assert_equal('Line2', readfile('Xfile')[1])}) 299 300 " clean up 301 call StopVimInTerminal(buf) 302 call delete('Xfile') 303endfunc 304 305" Test for an autocmd unloading a buffer during a write command 306func Test_write_autocmd_unloadbuf_lockmark() 307 augroup WriteTest 308 autocmd BufWritePre Xfile enew | write 309 augroup END 310 e Xfile 311 call assert_fails('lockmarks write', ['E32', 'E203:']) 312 augroup WriteTest 313 au! 314 augroup END 315 augroup! WriteTest 316endfunc 317 318" Test for writing a buffer with 'acwrite' but without autocmds 319func Test_write_acwrite_error() 320 new Xfile 321 call setline(1, ['line1', 'line2', 'line3']) 322 set buftype=acwrite 323 call assert_fails('write', 'E676:') 324 call assert_fails('1,2write!', 'E676:') 325 call assert_fails('w >>', 'E676:') 326 close! 327endfunc 328 329" Test for adding and removing lines from an autocmd when writing a buffer 330func Test_write_autocmd_add_remove_lines() 331 new Xfile 332 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) 333 334 " Autocmd deleting lines from the file when writing a partial file 335 augroup WriteTest2 336 au! 337 autocmd FileWritePre Xfile 1,2d 338 augroup END 339 call assert_fails('2,3w!', 'E204:') 340 341 " Autocmd adding lines to a file when writing a partial file 342 augroup WriteTest2 343 au! 344 autocmd FileWritePre Xfile call append(0, ['xxx', 'yyy']) 345 augroup END 346 %d 347 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) 348 1,2w! 349 call assert_equal(['xxx', 'yyy', 'aaa', 'bbb'], readfile('Xfile')) 350 351 " Autocmd deleting lines from the file when writing the whole file 352 augroup WriteTest2 353 au! 354 autocmd BufWritePre Xfile 1,2d 355 augroup END 356 %d 357 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) 358 w 359 call assert_equal(['ccc', 'ddd'], readfile('Xfile')) 360 361 augroup WriteTest2 362 au! 363 augroup END 364 augroup! WriteTest2 365 366 close! 367 call delete('Xfile') 368endfunc 369 370" Test for writing to a readonly file 371func Test_write_readonly() 372 call writefile([], 'Xfile') 373 call setfperm('Xfile', "r--------") 374 edit Xfile 375 set noreadonly backupskip= 376 call assert_fails('write', 'E505:') 377 let save_cpo = &cpo 378 set cpo+=W 379 call assert_fails('write!', 'E504:') 380 let &cpo = save_cpo 381 call setline(1, ['line1']) 382 write! 383 call assert_equal(['line1'], readfile('Xfile')) 384 set backupskip& 385 call delete('Xfile') 386endfunc 387 388" Test for 'patchmode' 389func Test_patchmode() 390 call writefile(['one'], 'Xfile') 391 set patchmode=.orig nobackup backupskip= writebackup 392 new Xfile 393 call setline(1, 'two') 394 " first write should create the .orig file 395 write 396 call assert_equal(['one'], readfile('Xfile.orig')) 397 call setline(1, 'three') 398 " subsequent writes should not create/modify the .orig file 399 write 400 call assert_equal(['one'], readfile('Xfile.orig')) 401 set patchmode& backup& backupskip& writebackup& 402 call delete('Xfile') 403 call delete('Xfile.orig') 404endfunc 405 406" Test for writing to a file in a readonly directory 407func Test_write_readonly_dir() 408 " On MS-Windows, modifying files in a read-only directory is allowed. 409 CheckUnix 410 call mkdir('Xdir') 411 call writefile(['one'], 'Xdir/Xfile1') 412 call setfperm('Xdir', 'r-xr--r--') 413 " try to create a new file in the directory 414 new Xdir/Xfile2 415 call setline(1, 'two') 416 call assert_fails('write', 'E212:') 417 " try to create a backup file in the directory 418 edit! Xdir/Xfile1 419 set backupdir=./Xdir backupskip= 420 set patchmode=.orig 421 call assert_fails('write', 'E509:') 422 call setfperm('Xdir', 'rwxr--r--') 423 call delete('Xdir', 'rf') 424 set backupdir& backupskip& patchmode& 425endfunc 426 427" Test for writing a file using invalid file encoding 428func Test_write_invalid_encoding() 429 new 430 call setline(1, 'abc') 431 call assert_fails('write ++enc=axbyc Xfile', 'E213:') 432 close! 433endfunc 434 435" Tests for reading and writing files with conversion for Win32. 436func Test_write_file_encoding() 437 CheckMSWindows 438 let save_encoding = &encoding 439 let save_fileencodings = &fileencodings 440 set encoding& fileencodings& 441 let text =<< trim END 442 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 443 2 cp1251 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 444 3 cp866 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 445 END 446 call writefile(text, 'Xfile') 447 edit Xfile 448 449 " write tests: 450 " combine three values for 'encoding' with three values for 'fileencoding' 451 " also write files for read tests 452 call cursor(1, 1) 453 set encoding=utf-8 454 .w! ++enc=utf-8 Xtest 455 .w ++enc=cp1251 >> Xtest 456 .w ++enc=cp866 >> Xtest 457 .w! ++enc=utf-8 Xutf8 458 let expected =<< trim END 459 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 460 1 utf-8 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 461 1 utf-8 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 462 END 463 call assert_equal(expected, readfile('Xtest')) 464 465 call cursor(2, 1) 466 set encoding=cp1251 467 .w! ++enc=utf-8 Xtest 468 .w ++enc=cp1251 >> Xtest 469 .w ++enc=cp866 >> Xtest 470 .w! ++enc=cp1251 Xcp1251 471 let expected =<< trim END 472 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 473 2 cp1251 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 474 2 cp1251 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 475 END 476 call assert_equal(expected, readfile('Xtest')) 477 478 call cursor(3, 1) 479 set encoding=cp866 480 .w! ++enc=utf-8 Xtest 481 .w ++enc=cp1251 >> Xtest 482 .w ++enc=cp866 >> Xtest 483 .w! ++enc=cp866 Xcp866 484 let expected =<< trim END 485 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 486 3 cp866 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 487 3 cp866 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 488 END 489 call assert_equal(expected, readfile('Xtest')) 490 491 " read three 'fileencoding's with utf-8 'encoding' 492 set encoding=utf-8 fencs=utf-8,cp1251 493 e Xutf8 494 .w! ++enc=utf-8 Xtest 495 e Xcp1251 496 .w ++enc=utf-8 >> Xtest 497 set fencs=utf-8,cp866 498 e Xcp866 499 .w ++enc=utf-8 >> Xtest 500 let expected =<< trim END 501 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 502 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 503 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 504 END 505 call assert_equal(expected, readfile('Xtest')) 506 507 " read three 'fileencoding's with cp1251 'encoding' 508 set encoding=utf-8 fencs=utf-8,cp1251 509 e Xutf8 510 .w! ++enc=cp1251 Xtest 511 e Xcp1251 512 .w ++enc=cp1251 >> Xtest 513 set fencs=utf-8,cp866 514 e Xcp866 515 .w ++enc=cp1251 >> Xtest 516 let expected =<< trim END 517 1 utf-8 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 518 2 cp1251 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 519 3 cp866 text: ��� Vim version 6.2. ��������� ���������: 1970 Jan 01 520 END 521 call assert_equal(expected, readfile('Xtest')) 522 523 " read three 'fileencoding's with cp866 'encoding' 524 set encoding=cp866 fencs=utf-8,cp1251 525 e Xutf8 526 .w! ++enc=cp866 Xtest 527 e Xcp1251 528 .w ++enc=cp866 >> Xtest 529 set fencs=utf-8,cp866 530 e Xcp866 531 .w ++enc=cp866 >> Xtest 532 let expected =<< trim END 533 1 utf-8 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 534 2 cp1251 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 535 3 cp866 text: ��� Vim version 6.2. ������ ���������: 1970 Jan 01 536 END 537 call assert_equal(expected, readfile('Xtest')) 538 539 call delete('Xfile') 540 call delete('Xtest') 541 call delete('Xutf8') 542 call delete('Xcp1251') 543 call delete('Xcp866') 544 let &encoding = save_encoding 545 let &fileencodings = save_fileencodings 546 %bw! 547endfunc 548 549" Test for writing and reading a file starting with a BOM. 550" Byte Order Mark (BOM) character for various encodings is below: 551" UTF-8 : EF BB BF 552" UTF-16 (BE): FE FF 553" UTF-16 (LE): FF FE 554" UTF-32 (BE): 00 00 FE FF 555" UTF-32 (LE): FF FE 00 00 556func Test_readwrite_file_with_bom() 557 let utf8_bom = "\xEF\xBB\xBF" 558 let utf16be_bom = "\xFE\xFF" 559 let utf16le_bom = "\xFF\xFE" 560 let utf32be_bom = "\n\n\xFE\xFF" 561 let utf32le_bom = "\xFF\xFE\n\n" 562 let save_fileencoding = &fileencoding 563 set cpoptions+=S 564 565 " Check that editing a latin1 file doesn't see a BOM 566 call writefile(["\xFE\xFElatin-1"], 'Xtest1') 567 edit Xtest1 568 call assert_equal('latin1', &fileencoding) 569 call assert_equal(0, &bomb) 570 set fenc=latin1 571 write Xfile2 572 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xfile2', 'b')) 573 set bomb fenc=latin1 574 write Xtest3 575 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xtest3', 'b')) 576 set bomb& 577 578 " Check utf-8 BOM 579 %bw! 580 call writefile([utf8_bom .. "utf-8"], 'Xtest1') 581 edit! Xtest1 582 call assert_equal('utf-8', &fileencoding) 583 call assert_equal(1, &bomb) 584 call assert_equal('utf-8', getline(1)) 585 set fenc=latin1 586 write! Xfile2 587 call assert_equal(['utf-8', ''], readfile('Xfile2', 'b')) 588 set fenc=utf-8 589 w! Xtest3 590 call assert_equal([utf8_bom .. "utf-8", ''], readfile('Xtest3', 'b')) 591 592 " Check utf-8 with an error (will fall back to latin-1) 593 %bw! 594 call writefile([utf8_bom .. "utf-8\x80err"], 'Xtest1') 595 edit! Xtest1 596 call assert_equal('latin1', &fileencoding) 597 call assert_equal(0, &bomb) 598 call assert_equal("\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", getline(1)) 599 set fenc=latin1 600 write! Xfile2 601 call assert_equal([utf8_bom .. "utf-8\x80err", ''], readfile('Xfile2', 'b')) 602 set fenc=utf-8 603 w! Xtest3 604 call assert_equal(["\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", ''], 605 \ readfile('Xtest3', 'b')) 606 607 " Check ucs-2 BOM 608 %bw! 609 call writefile([utf16be_bom .. "\nu\nc\ns\n-\n2\n"], 'Xtest1') 610 edit! Xtest1 611 call assert_equal('utf-16', &fileencoding) 612 call assert_equal(1, &bomb) 613 call assert_equal('ucs-2', getline(1)) 614 set fenc=latin1 615 write! Xfile2 616 call assert_equal(["ucs-2", ''], readfile('Xfile2', 'b')) 617 set fenc=ucs-2 618 w! Xtest3 619 call assert_equal([utf16be_bom .. "\nu\nc\ns\n-\n2\n", ''], 620 \ readfile('Xtest3', 'b')) 621 622 " Check ucs-2le BOM 623 %bw! 624 call writefile([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n"], 'Xtest1') 625 " Need to add a NUL byte after the NL byte 626 call writefile(0z00, 'Xtest1', 'a') 627 edit! Xtest1 628 call assert_equal('utf-16le', &fileencoding) 629 call assert_equal(1, &bomb) 630 call assert_equal('ucs-2le', getline(1)) 631 set fenc=latin1 632 write! Xfile2 633 call assert_equal(["ucs-2le", ''], readfile('Xfile2', 'b')) 634 set fenc=ucs-2le 635 w! Xtest3 636 call assert_equal([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n", "\n"], 637 \ readfile('Xtest3', 'b')) 638 639 " Check ucs-4 BOM 640 %bw! 641 call writefile([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n"], 'Xtest1') 642 edit! Xtest1 643 call assert_equal('ucs-4', &fileencoding) 644 call assert_equal(1, &bomb) 645 call assert_equal('ucs-4', getline(1)) 646 set fenc=latin1 647 write! Xfile2 648 call assert_equal(["ucs-4", ''], readfile('Xfile2', 'b')) 649 set fenc=ucs-4 650 w! Xtest3 651 call assert_equal([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n", ''], readfile('Xtest3', 'b')) 652 653 " Check ucs-4le BOM 654 %bw! 655 call writefile([utf32le_bom .. "u\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\nl\n\n\ne\n\n\n"], 'Xtest1') 656 " Need to add three NUL bytes after the NL byte 657 call writefile(0z000000, 'Xtest1', 'a') 658 edit! Xtest1 659 call assert_equal('ucs-4le', &fileencoding) 660 call assert_equal(1, &bomb) 661 call assert_equal('ucs-4le', getline(1)) 662 set fenc=latin1 663 write! Xfile2 664 call assert_equal(["ucs-4le", ''], readfile('Xfile2', 'b')) 665 set fenc=ucs-4le 666 w! Xtest3 667 call assert_equal([utf32le_bom .. "u\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\nl\n\n\ne\n\n\n", "\n\n\n"], readfile('Xtest3', 'b')) 668 669 set cpoptions-=S 670 let &fileencoding = save_fileencoding 671 call delete('Xtest1') 672 call delete('Xtest2') 673 call delete('Xtest3') 674 %bw! 675endfunc 676 677" vim: shiftwidth=2 sts=2 expandtab 678