To: vim_dev@googlegroups.com Subject: Patch 8.2.1316 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1316 Problem: Test 42 is still old style. Solution: Turn it into a new style test. (Yegappan Lakshmanan, closes #6561) Files: src/Makefile, src/testdir/Make_all.mak, src/testdir/Make_dos.mak, src/testdir/Make_ming.mak, src/testdir/Make_vms.mms, src/testdir/test42.in, src/testdir/test42.ok, src/testdir/test_writefile.vim *** ../vim-8.2.1315/src/Makefile 2020-07-27 20:02:21.008597321 +0200 --- src/Makefile 2020-07-29 16:05:36.078728215 +0200 *************** *** 2310,2316 **** # Run individual OLD style test. # These do not depend on the executable, compile it when needed. ! test1 test42 test49 test59: cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) # Run individual NEW style test. --- 2310,2316 ---- # Run individual OLD style test. # These do not depend on the executable, compile it when needed. ! test1 test49 test59: cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) # Run individual NEW style test. *** ../vim-8.2.1315/src/testdir/Make_all.mak 2020-07-27 20:02:21.008597321 +0200 --- src/testdir/Make_all.mak 2020-07-29 16:05:36.078728215 +0200 *************** *** 11,17 **** SCRIPTS_FIRST = test1.out # Tests that run on all systems. ! SCRIPTS_ALL = test42.out # Tests that run on most systems, but not on Amiga. SCRIPTS_MORE1 = --- 11,17 ---- SCRIPTS_FIRST = test1.out # Tests that run on all systems. ! SCRIPTS_ALL = # Tests that run on most systems, but not on Amiga. SCRIPTS_MORE1 = *** ../vim-8.2.1315/src/testdir/Make_dos.mak 2020-04-21 22:19:26.055486850 +0200 --- src/testdir/Make_dos.mak 2020-07-29 16:05:36.078728215 +0200 *************** *** 10,19 **** !include Make_all.mak # Omitted: - # test2 "\\tmp" doesn't work. - # test10 'errorformat' is different # test49 fails in various ways - # test97 \{ and \$ are not escaped characters. SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE1) $(SCRIPTS_MORE4) --- 10,16 ---- *** ../vim-8.2.1315/src/testdir/Make_ming.mak 2020-04-21 22:19:26.055486850 +0200 --- src/testdir/Make_ming.mak 2020-07-29 16:05:36.078728215 +0200 *************** *** 28,38 **** include Make_all.mak - # Omitted: - # test2 "\\tmp" doesn't work. - # test10 'errorformat' is different - # test97 \{ and \$ are not escaped characters - SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE1) $(SCRIPTS_MORE4) $(SCRIPTS_WIN32) SCRIPTS_BENCH = test_bench_regexp.res --- 28,33 ---- *** ../vim-8.2.1315/src/testdir/Make_vms.mms 2020-07-27 20:02:21.008597321 +0200 --- src/testdir/Make_vms.mms 2020-07-29 16:05:36.078728215 +0200 *************** *** 73,80 **** .SUFFIXES : .out .in ! SCRIPT = test1.out \ ! test42.out test49.out test77a.out # Known problems: # --- 73,79 ---- .SUFFIXES : .out .in ! SCRIPT = test1.out test49.out test77a.out # Known problems: # *** ../vim-8.2.1315/src/testdir/test42.in 2019-10-19 18:34:42.000000000 +0200 --- src/testdir/test42.in 1970-01-01 01:00:00.000000000 +0100 *************** *** 1,131 **** - Test for writing and reading a file starting with a BOM - - STARTTEST - :so mbyte.vim - :set cpoptions+=S - :set encoding=utf-8 - :set fileencodings=ucs-bom,latin-1 - :set ff=unix ffs=unix " This changes the file for DOS and MAC - :" --- Write the test files - :/^latin-1$/+1w! Xtest0 - :/^utf-8$/+1w! Xtest1 - :/^utf-8-err$/+1w! Xtest2 - :/^ucs-2$/+1w! Xtest3 - :/^ucs-2le$/+1w! Xtest4 - :" Need to add a NUL byte after the NL byte - :set bin - :e! Xtest4 " Ignore change from setting 'ff' - o:set noeol - :w - :set ffs& nobinary " Allow default test42.in format - :e # - :set ff=unix " Format for files to write - :/^ucs-4$/+1w! Xtest5 - :/^ucs-4le$/+1w! Xtest6 - :" Need to add three NUL bytes after the NL byte - :set bin - :e! Xtest6 " ! for when setting 'ff' is a change - o:set noeol - :w - :set nobin - :e # - :" - :" --- Check that editing a latin-1 file doesn't see a BOM - :e! Xtest0 - :redir! >test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set bomb fenc=latin-1 - :w! Xtest0x - :" - :" --- Check utf-8 - :e! Xtest1 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=utf-8 - :w! Xtest1x - :" - :" --- Check utf-8 with an error (will fall back to latin-1) - :e! Xtest2 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=utf-8 - :w! Xtest2x - :" - :" --- Check ucs-2 - :e! Xtest3 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=ucs-2 - :w! Xtest3x - :" - :" --- Check ucs-2le - :e! Xtest4 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=ucs-2le - :w! Xtest4x - :" - :" --- Check ucs-4 - :e! Xtest5 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=ucs-4 - :w! Xtest5x - :" - :" --- Check ucs-4le - :e! Xtest6 - :redir >>test.out - :set fileencoding bomb? - :redir END - :set fenc=latin-1 - :w >>test.out - :set fenc=ucs-4le - :w! Xtest6x - :" - :" --- Check the files written with BOM - :set bin - :e! test.out - :$r Xtest0x - :$r Xtest1x - :$r Xtest2x - :$r Xtest3x - :$r Xtest4x - :$r Xtest5x - :$r Xtest6x - :set nobin ff& " Write the file in default format - :w! test.out - :qa! - ENDTEST - - latin-1 - þþlatin-1 - utf-8 - utf-8 - utf-8-err - utf-8€err - ucs-2 - þÿucs-2 - ucs-2le - ÿþucs-2le - ucs-4 - þÿucs-4 - ucs-4le - ÿþucs-4le --- 0 ---- *** ../vim-8.2.1315/src/testdir/test42.ok 2010-05-15 13:04:10.000000000 +0200 --- src/testdir/test42.ok 1970-01-01 01:00:00.000000000 +0100 *************** *** 1,44 **** - - - fileencoding=latin1 - nobomb - þþlatin-1 - - - fileencoding=utf-8 - bomb - utf-8 - - - fileencoding=latin1 - nobomb - utf-8€err - - - fileencoding=utf-16 - bomb - ucs-2 - - - fileencoding=utf-16le - bomb - ucs-2le - - - fileencoding=ucs-4 - bomb - ucs-4 - - - fileencoding=ucs-4le - bomb - ucs-4le - þþlatin-1 - utf-8 - utf-8€err - þÿucs-2 - ÿþucs-2le - - þÿucs-4 - ÿþucs-4le - --- 0 ---- *** ../vim-8.2.1315/src/testdir/test_writefile.vim 2020-07-27 20:02:21.008597321 +0200 --- src/testdir/test_writefile.vim 2020-07-29 16:05:36.078728215 +0200 *************** *** 556,559 **** --- 556,687 ---- %bw! endfunc + " Test for writing and reading a file starting with a BOM. + " Byte Order Mark (BOM) character for various encodings is below: + " UTF-8 : EF BB BF + " UTF-16 (BE): FE FF + " UTF-16 (LE): FF FE + " UTF-32 (BE): 00 00 FE FF + " UTF-32 (LE): FF FE 00 00 + func Test_readwrite_file_with_bom() + let utf8_bom = "\xEF\xBB\xBF" + let utf16be_bom = "\xFE\xFF" + let utf16le_bom = "\xFF\xFE" + let utf32be_bom = "\n\n\xFE\xFF" + let utf32le_bom = "\xFF\xFE\n\n" + let save_fileencoding = &fileencoding + set cpoptions+=S + + " Check that editing a latin1 file doesn't see a BOM + call writefile(["\xFE\xFElatin-1"], 'Xtest1') + edit Xtest1 + call assert_equal('latin1', &fileencoding) + call assert_equal(0, &bomb) + set fenc=latin1 + write Xfile2 + call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xfile2', 'b')) + set bomb fenc=latin1 + write Xtest3 + call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xtest3', 'b')) + set bomb& + + " Check utf-8 BOM + %bw! + call writefile([utf8_bom .. "utf-8"], 'Xtest1') + edit! Xtest1 + call assert_equal('utf-8', &fileencoding) + call assert_equal(1, &bomb) + call assert_equal('utf-8', getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal(['utf-8', ''], readfile('Xfile2', 'b')) + set fenc=utf-8 + w! Xtest3 + call assert_equal([utf8_bom .. "utf-8", ''], readfile('Xtest3', 'b')) + + " Check utf-8 with an error (will fall back to latin-1) + %bw! + call writefile([utf8_bom .. "utf-8\x80err"], 'Xtest1') + edit! Xtest1 + call assert_equal('latin1', &fileencoding) + call assert_equal(0, &bomb) + call assert_equal("\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal([utf8_bom .. "utf-8\x80err", ''], readfile('Xfile2', 'b')) + set fenc=utf-8 + w! Xtest3 + call assert_equal(["\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", ''], + \ readfile('Xtest3', 'b')) + + " Check ucs-2 BOM + %bw! + call writefile([utf16be_bom .. "\nu\nc\ns\n-\n2\n"], 'Xtest1') + edit! Xtest1 + call assert_equal('utf-16', &fileencoding) + call assert_equal(1, &bomb) + call assert_equal('ucs-2', getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal(["ucs-2", ''], readfile('Xfile2', 'b')) + set fenc=ucs-2 + w! Xtest3 + call assert_equal([utf16be_bom .. "\nu\nc\ns\n-\n2\n", ''], + \ readfile('Xtest3', 'b')) + + " Check ucs-2le BOM + %bw! + call writefile([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n"], 'Xtest1') + " Need to add a NUL byte after the NL byte + call writefile(0z00, 'Xtest1', 'a') + edit! Xtest1 + call assert_equal('utf-16le', &fileencoding) + call assert_equal(1, &bomb) + call assert_equal('ucs-2le', getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal(["ucs-2le", ''], readfile('Xfile2', 'b')) + set fenc=ucs-2le + w! Xtest3 + call assert_equal([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n", "\n"], + \ readfile('Xtest3', 'b')) + + " Check ucs-4 BOM + %bw! + call writefile([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n"], 'Xtest1') + edit! Xtest1 + call assert_equal('ucs-4', &fileencoding) + call assert_equal(1, &bomb) + call assert_equal('ucs-4', getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal(["ucs-4", ''], readfile('Xfile2', 'b')) + set fenc=ucs-4 + w! Xtest3 + 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')) + + " Check ucs-4le BOM + %bw! + 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') + " Need to add three NUL bytes after the NL byte + call writefile(0z000000, 'Xtest1', 'a') + edit! Xtest1 + call assert_equal('ucs-4le', &fileencoding) + call assert_equal(1, &bomb) + call assert_equal('ucs-4le', getline(1)) + set fenc=latin1 + write! Xfile2 + call assert_equal(["ucs-4le", ''], readfile('Xfile2', 'b')) + set fenc=ucs-4le + w! Xtest3 + 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')) + + set cpoptions-=S + let &fileencoding = save_fileencoding + call delete('Xtest1') + call delete('Xtest2') + call delete('Xtest3') + %bw! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.1315/src/version.c 2020-07-29 15:02:57.870298502 +0200 --- src/version.c 2020-07-29 16:07:24.742126576 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1316, /**/ -- From "know your smileys": +<(:-) The Pope /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///