To: vim_dev@googlegroups.com Subject: Patch 8.2.3010 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3010 Problem: Not enough testing for viminfo code. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #8390) Files: src/register.c, src/testdir/test_fileformat.vim, src/testdir/test_smartindent.vim, src/testdir/test_viminfo.vim *** ../vim-8.2.3009/src/register.c 2021-06-10 19:39:07.277697688 +0200 --- src/register.c 2021-06-16 15:36:35.327076363 +0200 *************** *** 462,467 **** --- 462,470 ---- return OK; } + /* + * Last executed register (@ command) + */ static int execreg_lastc = NUL; int *** ../vim-8.2.3009/src/testdir/test_fileformat.vim 2021-03-13 13:14:00.810145346 +0100 --- src/testdir/test_fileformat.vim 2021-06-16 15:36:35.327076363 +0200 *************** *** 1,5 **** --- 1,7 ---- " Test for 'fileformat' + source shared.vim + " Test behavior of fileformat after bwipeout of last buffer func Test_fileformat_after_bw() bwipeout *************** *** 308,311 **** --- 310,327 ---- call assert_fails('e ++abc1 Xfile1', 'E474:') endfunc + " When Vim starts up with an empty buffer the first item in 'fileformats' is + " used as the 'fileformat'. + func Test_fileformat_on_startup() + let after =<< trim END + call writefile([&fileformat], 'Xfile', 'a') + quit + END + call RunVim(["set ffs=dos,unix,mac"], after, '') + call RunVim(["set ffs=mac,dos,unix"], after, '') + call RunVim(["set ffs=unix,mac,dos"], after, '') + call assert_equal(['dos', 'mac', 'unix'], readfile('Xfile')) + call delete('Xfile') + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3009/src/testdir/test_smartindent.vim 2020-03-30 19:37:29.891557513 +0200 --- src/testdir/test_smartindent.vim 2021-06-16 15:36:35.327076363 +0200 *************** *** 111,114 **** --- 111,137 ---- close! endfunc + " When 'paste' is set, 'smartindent' should not take effect. + func Test_si_with_paste() + new + setlocal smartindent autoindent + set paste + " insert text that will trigger smartindent + exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}" + exe "norm! Ok = 3;" + exe "norm! 4G>>" + call assert_equal([' {', 'if (x)', 'i = 1;', '#define FOO 1', + \ 'j = 2;', 'k = 3;', '}'], getline(1, '$')) + call assert_true(&smartindent) + set nopaste + %d _ + exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}" + exe "norm! Ok = 3;" + exe "norm! 4G>>" + call assert_equal([' {', "\t if (x)", "\t\t i = 1;", + \ '#define FOO 1', "\t\t j = 2;", "\t k = 3;", ' }'], + \ getline(1, '$')) + bw! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3009/src/testdir/test_viminfo.vim 2021-03-13 13:14:00.810145346 +0100 --- src/testdir/test_viminfo.vim 2021-06-16 15:36:35.327076363 +0200 *************** *** 4,10 **** source term_util.vim source shared.vim ! function Test_viminfo_read_and_write() " First clear 'history', so that "hislen" is zero. Then set it again, " simulating Vim starting up. set history=0 --- 4,10 ---- source term_util.vim source shared.vim ! func Test_viminfo_read_and_write() " First clear 'history', so that "hislen" is zero. Then set it again, " simulating Vim starting up. set history=0 *************** *** 12,17 **** --- 12,18 ---- set history=1000 call histdel(':') + let @/='' let lines = [ \ '# comment line', \ '*encoding=utf-8', *************** *** 89,94 **** --- 90,125 ---- call assert_equal(test_null, g:MY_GLOBAL_NULL) call assert_equal(test_none, g:MY_GLOBAL_NONE) + " When reading global variables from viminfo, if a variable cannot be + " modified, then the value should not be changed. + unlet g:MY_GLOBAL_STRING + unlet g:MY_GLOBAL_NUM + unlet g:MY_GLOBAL_FLOAT + unlet g:MY_GLOBAL_DICT + unlet g:MY_GLOBAL_LIST + unlet g:MY_GLOBAL_BLOB + + const g:MY_GLOBAL_STRING = 'New Value' + const g:MY_GLOBAL_NUM = 987 + const g:MY_GLOBAL_FLOAT = 1.16 + const g:MY_GLOBAL_DICT = {'editor': 'vim'} + const g:MY_GLOBAL_LIST = [5, 7, 13] + const g:MY_GLOBAL_BLOB = 0zDEADBEEF + call assert_fails('rv! Xviminfo', 'E741:') + call assert_equal('New Value', g:MY_GLOBAL_STRING) + call assert_equal(987, g:MY_GLOBAL_NUM) + call assert_equal(1.16, g:MY_GLOBAL_FLOAT) + call assert_equal({'editor': 'vim'}, g:MY_GLOBAL_DICT) + call assert_equal([5, 7 , 13], g:MY_GLOBAL_LIST) + call assert_equal(0zDEADBEEF, g:MY_GLOBAL_BLOB) + + unlet g:MY_GLOBAL_STRING + unlet g:MY_GLOBAL_NUM + unlet g:MY_GLOBAL_FLOAT + unlet g:MY_GLOBAL_DICT + unlet g:MY_GLOBAL_LIST + unlet g:MY_GLOBAL_BLOB + " Test for invalid values for a blob, list, dict in a viminfo file call writefile([ \ "!GLOB_BLOB_1\tBLO\t123", *************** *** 510,515 **** --- 541,560 ---- call delete('Xviminfo') endfunc + func Test_viminfo_bad_register_syntax() + let lines = [] + call add(lines, '|1,4') + call add(lines, '|3') " invalid number of fields for a register type + call add(lines, '|3,1,1,1,1,,1,"x"') " invalid value for the width field + call add(lines, '|3,0,80,1,1,1,1,"x"') " invalid register number + call add(lines, '|3,0,10,5,1,1,1,"x"') " invalid register type + call add(lines, '|3,0,10,1,20,1,1,"x"') " invalid line count + call add(lines, '|3,0,10,1,0,1,1') " zero line count + call writefile(lines, 'Xviminfo') + rviminfo Xviminfo + call delete('Xviminfo') + endfunc + func Test_viminfo_file_marks() silent! bwipe test_viminfo.vim silent! bwipe Xviminfo *************** *** 664,669 **** --- 709,715 ---- " If there are arguments, then :rviminfo doesn't read the buffer list. " Need to delete all the arguments for :rviminfo to work. %argdelete + set viminfo&vim edit Xfile1 edit Xfile2 *************** *** 684,692 **** call assert_equal('Xfile1', bufname(l[1].bufnr)) call assert_equal('Xfile2', bufname(l[2].bufnr)) call delete('Xviminfo') %bwipe ! set viminfo-=% endfunc " Test for errors in a viminfo file --- 730,771 ---- call assert_equal('Xfile1', bufname(l[1].bufnr)) call assert_equal('Xfile2', bufname(l[2].bufnr)) + " The quickfix, terminal, unlisted, unnamed buffers are not stored in the + " viminfo file + %bw! + edit Xfile1 + new + setlocal nobuflisted + new + copen + if has('terminal') + terminal + endif + wviminfo! Xviminfo + %bwipe! + rviminfo Xviminfo + let l = getbufinfo() + call assert_equal(2, len(l)) + call assert_true(bufexists('Xfile1')) + + " If a count is specified for '%', then only that many buffers should be + " stored in the viminfo file. + %bw! + set viminfo&vim + new Xbuf1 + new Xbuf2 + set viminfo+=%1 + wviminfo! Xviminfo + %bwipe! + rviminfo! Xviminfo + let l = getbufinfo() + call assert_equal(2, len(l)) + call assert_true(bufexists('Xbuf1')) + call assert_false(bufexists('Xbuf2')) + call delete('Xviminfo') %bwipe ! set viminfo&vim endfunc " Test for errors in a viminfo file *************** *** 747,752 **** --- 826,837 ---- \ ' Vim', \ '"a CHAR 0', \ ' red', + \ '"c BLOCK 0', + \ ' a', + \ ' d', + \ '"d LINE 0', + \ ' abc', + \ ' def', \ '"m@ CHAR 0', \ " :echo 'Hello'\", \ "", *************** *** 760,766 **** --- 845,856 ---- silent! normal @t rviminfo! Xviminfo call assert_equal('red', getreg('a')) + call assert_equal("v", getregtype('a')) call assert_equal('two', getreg('b')) + call assert_equal("a\nd", getreg('c')) + call assert_equal("\1", getregtype('c')) + call assert_equal("abc\ndef\n", getreg('d')) + call assert_equal("V", getregtype('d')) call assert_equal(":echo 'Hello'\", getreg('m')) call assert_equal('Vim', getreg('"')) call assert_equal("\nHello", execute('normal @@')) *************** *** 914,917 **** --- 1004,1231 ---- let &viminfofile = save_viminfofile endfunc + " When writing CTRL-V or "\n" to a viminfo file, it is converted to CTRL-V + " CTRL-V and CTRL-V n respectively. + func Test_viminfo_with_Ctrl_V() + silent! exe "normal! /\\\n" + wviminfo Xviminfo + call assert_notequal(-1, readfile('Xviminfo')->index("?/\\")) + let @/ = 'abc' + rviminfo! Xviminfo + call assert_equal("\", @/) + silent! exe "normal! /\\\n" + wviminfo Xviminfo + call assert_notequal(-1, readfile('Xviminfo')->index("?/\n")) + let @/ = 'abc' + rviminfo! Xviminfo + call assert_equal("\n", @/) + call delete('Xviminfo') + endfunc + + " Test for the 'r' field in 'viminfo' (removal media) + func Test_viminfo_removable_media() + CheckUnix + if !isdirectory('/tmp') || getftype('/tmp') != 'dir' + return + endif + let save_viminfo = &viminfo + set viminfo+=r/tmp + edit /tmp/Xvima1b2c3 + wviminfo Xviminfo + let matches = readfile('Xviminfo')->filter("v:val =~ 'Xvima1b2c3'") + call assert_equal(0, matches->len()) + let &viminfo = save_viminfo + call delete('Xviminfo') + endfunc + + " Test for the 'h' flag in 'viminfo'. If 'h' is not present, then the last + " search pattern read from 'viminfo' should be highlighted with 'hlsearch'. + " If 'h' is present, then the last search pattern should not be highlighted. + func Test_viminfo_hlsearch() + set viminfo&vim + + new + call setline(1, ['one two three']) + " save the screen attribute for the Search highlighted text and the normal + " text for later comparison + set hlsearch + let @/ = 'three' + redraw! + let hiSearch = screenattr(1, 9) + let hiNormal = screenattr(1, 1) + + set viminfo-=h + let @/='two' + wviminfo! Xviminfo + let @/='one' + rviminfo! Xviminfo + redraw! + call assert_equal(hiSearch, screenattr(1, 5)) + call assert_equal(hiSearch, screenattr(1, 6)) + call assert_equal(hiSearch, screenattr(1, 7)) + + set viminfo+=h + let @/='two' + wviminfo! Xviminfo + let @/='one' + rviminfo! Xviminfo + redraw! + call assert_equal(hiNormal, screenattr(1, 5)) + call assert_equal(hiNormal, screenattr(1, 6)) + call assert_equal(hiNormal, screenattr(1, 7)) + + call delete('Xviminfo') + set hlsearch& viminfo&vim + bw! + endfunc + + " Test for restoring the magicness of the last search pattern from the viminfo + " file. + func Test_viminfo_last_spat_magic() + set viminfo&vim + new + call setline(1, ' one abc a.c') + + " restore 'nomagic' + set nomagic + exe "normal gg/a.c\" + wviminfo! Xviminfo + set magic + exe "normal gg/one\" + rviminfo! Xviminfo + exe "normal! gg/\" + call assert_equal(10, col('.')) + + " restore 'magic' + set magic + exe "normal gg/a.c\" + wviminfo! Xviminfo + set nomagic + exe "normal gg/one\" + rviminfo! Xviminfo + exe "normal! gg/\" + call assert_equal(6, col('.')) + + call delete('Xviminfo') + set viminfo&vim magic& + bw! + endfunc + + " Test for restoring the smartcase of the last search pattern from the viminfo + " file. + func Test_viminfo_last_spat_smartcase() + new + call setline(1, ' one abc Abc') + set ignorecase smartcase + + " Searching with * should disable smartcase + exe "normal! gg$b*" + wviminfo! Xviminfo + exe "normal gg/one\" + rviminfo! Xviminfo + exe "normal! gg/\" + call assert_equal(6, col('.')) + + call delete('Xviminfo') + set ignorecase& smartcase& viminfo& + bw! + endfunc + + " Test for restoring the last search pattern with a line or character offset + " from the viminfo file. + func Test_viminfo_last_spat_offset() + new + call setline(1, ['one', 'two', 'three', 'four', 'five']) + " line offset + exe "normal! /two/+2\" + wviminfo! Xviminfo + exe "normal gg/five\" + rviminfo! Xviminfo + exe "normal! gg/\" + call assert_equal(4, line('.')) + " character offset + exe "normal! gg/^th/e+2\" + wviminfo! Xviminfo + exe "normal gg/two\" + rviminfo! Xviminfo + exe "normal! gg/\" + call assert_equal([3, 4], [line('.'), col('.')]) + call delete('Xviminfo') + bw! + endfunc + + " Test for saving and restoring the last executed register (@ command) + " from the viminfo file + func Test_viminfo_last_exec_reg() + let g:val = 1 + let @a = ":let g:val += 1\n" + normal! @a + wviminfo! Xviminfo + let @b = '' + normal! @b + rviminfo! Xviminfo + normal @@ + call assert_equal(3, g:val) + call delete('Xviminfo') + endfunc + + " Test for merging file marks in a viminfo file + func Test_viminfo_merge_file_marks() + for [f, l, t] in [['a.txt', 5, 10], ['b.txt', 10, 20]] + call test_settime(t) + exe 'edit ' .. f + call setline(1, range(1, 20)) + exe l . 'mark a' + wviminfo Xviminfo + bw! + endfor + call test_settime(30) + for [f, l] in [['a.txt', 5], ['b.txt', 10]] + exe 'edit ' .. f + rviminfo! Xviminfo + call assert_equal(l, line("'a")) + bw! + endfor + call delete('Xviminfo') + call test_settime(0) + endfunc + + " Test for merging file marks from a old viminfo file + func Test_viminfo_merge_old_filemarks() + let lines = [] + call add(lines, '|1,4') + call add(lines, '> ' .. fnamemodify('a.txt', ':p:~')) + call add(lines, "\tb\t7\t0\n") + call writefile(lines, 'Xviminfo') + edit b.txt + call setline(1, range(1, 20)) + 12mark b + wviminfo Xviminfo + bw! + edit a.txt + rviminfo! Xviminfo + call assert_equal(7, line("'b")) + edit b.txt + rviminfo! Xviminfo + call assert_equal(12, line("'b")) + call delete('Xviminfo') + endfunc + + " Test for merging the jump list from a old viminfo file + func Test_viminfo_merge_old_jumplist() + let lines = [] + call add(lines, "-' 10 1 " .. fnamemodify('a.txt', ':p:~')) + call add(lines, "-' 20 1 " .. fnamemodify('a.txt', ':p:~')) + call add(lines, "-' 30 1 " .. fnamemodify('b.txt', ':p:~')) + call add(lines, "-' 40 1 " .. fnamemodify('b.txt', ':p:~')) + call writefile(lines, 'Xviminfo') + clearjumps + rviminfo! Xviminfo + let l = getjumplist()[0] + call assert_equal([40, 30, 20, 10], [l[0].lnum, l[1].lnum, l[2].lnum, + \ l[3].lnum]) + bw! + call delete('Xviminfo') + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3009/src/version.c 2021-06-16 10:59:32.622998987 +0200 --- src/version.c 2021-06-16 15:52:40.212775948 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 3010, /**/ -- A radioactive cat has eighteen half-lives. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///