From 9c92eed86f99fa4f423228a5afd0ef8eac9894e3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 21 Jan 2018 10:09:04 +0100 Subject: vim-patch:8.0.0599: diff mode is insufficiently tested Problem: diff mode is insufficiently tested Solution: Add more test cases. (Dominique Pelle, closes vim/vim#1685) https://github.com/vim/vim/commit/79a213d6a4e909703524a7f1ad985c7bd40650a6 NA / already applied: --------------------- vim-patch:8.0.0421: diff mode wrong when adding line at end of buffer Problem: Diff mode is displayed wrong when adding a line at the end of a buffer. Solution: Adjust marks in diff mode. (James McCoy, closes vim/vim#1329) https://github.com/vim/vim/commit/f58a8475e17bd566760fc7e2a17d35ddf4edacf2 --- src/nvim/diff.c | 4 +- src/nvim/testdir/test_diffmode.vim | 189 ++++++++++++++++++++++++++++++++++++- 2 files changed, 189 insertions(+), 4 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index cc0f3b2629..dd489c18e9 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1161,7 +1161,9 @@ void ex_diffoff(exarg_T *eap) } free_string_option(wp->w_p_fdm); - wp->w_p_fdm = vim_strsave(wp->w_p_fdm_save); + wp->w_p_fdm = vim_strsave(*wp->w_p_fdm_save + ? wp->w_p_fdm_save + : (char_u*)"manual"); if (wp->w_p_fdc == diff_foldcolumn) { wp->w_p_fdc = wp->w_p_fdc_save; } diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 33617c9cbe..ad2100e8a2 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -198,14 +198,69 @@ func Test_diffget_diffput() call assert_fails('diffget', 'E101:') windo diffoff - bwipe! - bwipe! - enew! + %bwipe! +endfunc + +func Test_dp_do_buffer() + e! one + let bn1=bufnr('%') + let l = range(60) + call setline(1, l) + diffthis + + new two + let l[10] = 'one' + let l[20] = 'two' + let l[30] = 'three' + let l[40] = 'four' + let l[50] = 'five' + call setline(1, l) + diffthis + + " dp and do with invalid buffer number. + 11 + call assert_fails('norm 99999dp', 'E102:') + call assert_fails('norm 99999do', 'E102:') + call assert_fails('diffput non_existing_buffer', 'E94:') + call assert_fails('diffget non_existing_buffer', 'E94:') + + " dp and do with valid buffer number. + call assert_equal('one', getline('.')) + exe 'norm ' . bn1 . 'do' + call assert_equal('10', getline('.')) + 21 + call assert_equal('two', getline('.')) + diffget one + call assert_equal('20', getline('.')) + + 31 + exe 'norm ' . bn1 . 'dp' + 41 + diffput one + wincmd w + 31 + call assert_equal('three', getline('.')) + 41 + call assert_equal('four', getline('.')) + + " dp and do with buffer number which is not in diff mode. + new not_in_diff_mode + let bn3=bufnr('%') + wincmd w + 51 + call assert_fails('exe "norm" . bn3 . "dp"', 'E103:') + call assert_fails('exe "norm" . bn3 . "do"', 'E103:') + call assert_fails('diffput not_in_diff_mode', 'E94:') + call assert_fails('diffget not_in_diff_mode', 'E94:') + + windo diffoff + %bwipe! endfunc func Test_diffoff() enew! call setline(1, ['Two', 'Three']) + redraw let normattr = screenattr(1, 1) diffthis botright vert new @@ -220,10 +275,107 @@ func Test_diffoff() bwipe! endfunc +func Test_diffopt_icase() + set diffopt=icase,foldcolumn:0 + + e one + call setline(1, ['One', 'Two', 'Three', 'Four']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new two + call setline(1, ['one', 'TWO', 'Three ', 'Four']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_notequal(normattr, screenattr(3, 1)) + call assert_equal(normattr, screenattr(4, 1)) + + diffoff! + %bwipe! + set diffopt& +endfunc + +func Test_diffopt_iwhite() + set diffopt=iwhite,foldcolumn:0 + + e one + " Difference in trailing spaces should be ignored, + " but not other space differences. + call setline(1, ["One \t", 'Two', 'Three', 'Four']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new two + call setline(1, ["One\t ", "Two\t ", 'Three', ' Four']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_equal(normattr, screenattr(3, 1)) + call assert_notequal(normattr, screenattr(4, 1)) + + diffoff! + %bwipe! + set diffopt& +endfunc + +func Test_diffopt_context() + enew! + call setline(1, ['1', '2', '3', '4', '5', '6', '7']) + diffthis + new + call setline(1, ['1', '2', '3', '4', '5x', '6', '7']) + diffthis + + set diffopt=context:2 + call assert_equal('+-- 2 lines: 1', foldtextresult(1)) + set diffopt=context:1 + call assert_equal('+-- 3 lines: 1', foldtextresult(1)) + + diffoff! + %bwipe! + set diffopt& +endfunc + +func Test_diffopt_horizontal() + set diffopt=horizontal + diffsplit + + call assert_equal(&columns, winwidth(1)) + call assert_equal(&columns, winwidth(2)) + call assert_equal(&lines, winheight(1) + winheight(2) + 3) + call assert_inrange(0, 1, winheight(1) - winheight(2)) + + set diffopt& + diffoff! + %bwipe +endfunc + +func Test_diffopt_vertical() + set diffopt=vertical + diffsplit + + call assert_equal(&lines - 2, winheight(1)) + call assert_equal(&lines - 2, winheight(2)) + call assert_equal(&columns, winwidth(1) + winwidth(2) + 1) + call assert_inrange(0, 1, winwidth(1) - winwidth(2)) + + set diffopt& + diffoff! + %bwipe +endfunc + func Test_diffoff_hidden() set diffopt=filler,foldcolumn:0 e! one call setline(1, ['Two', 'Three']) + redraw let normattr = screenattr(1, 1) diffthis botright vert new two @@ -295,6 +447,37 @@ func Test_diff_move_to() %bwipe! endfunc +func Test_diffexpr() + if !executable('diff') + return + endif + + func DiffExpr() + silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>' . v:fname_out + endfunc + set diffexpr=DiffExpr() + set diffopt=foldcolumn:0 + + enew! + call setline(1, ['one', 'two', 'three']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new + call setline(1, ['one', 'two', 'three.']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_notequal(normattr, screenattr(3, 1)) + + diffoff! + %bwipe! + set diffexpr& diffopt& +endfunc + func Test_diffpatch() " The patch program on MS-Windows may fail or hang. if !executable('patch') || !has('unix') -- cgit From ce09d4134b05cfdf6f71bcc93bb5cb9e48e4d9a0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 21 Jan 2018 10:26:40 +0100 Subject: vim-patch:8.0.0433: beeps when running tests Problem: Quite a few beeps when running tests. Solution: Set 'belloff' for these tests. (Christian Brabandt) https://github.com/vim/vim/commit/c3c766ea8c35f5b2bd45fb3d74d0ae46b2d8c24f --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_cmdline.vim | 2 ++ src/nvim/testdir/test_diffmode.vim | 1 + src/nvim/testdir/test_digraph.vim | 1 + src/nvim/testdir/test_normal.vim | 1 + src/nvim/testdir/test_search.vim | 1 + src/nvim/testdir/test_textobjects.vim | 1 + src/nvim/testdir/test_undo.vim | 1 + src/nvim/testdir/test_usercommands.vim | 1 + src/nvim/testdir/test_visual.vim | 2 ++ 10 files changed, 12 insertions(+) (limited to 'src/nvim') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 0e7778decc..6f572e9b79 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -1,6 +1,7 @@ " A series of tests that can run in one Vim invocation. " This makes testing go faster, since Vim doesn't need to restart. +set belloff=all source test_assign.vim source test_changedtick.vim source test_cursor_func.vim diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 115c228ce8..0d2dad80ce 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1,5 +1,7 @@ " Tests for editing the command line. +set belloff=all + func Test_complete_tab() call writefile(['testfile'], 'Xtestfile') call feedkeys(":e Xtestf\t\r", "tx") diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index ad2100e8a2..b5a76909a2 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -1,4 +1,5 @@ " Tests for diff mode +set belloff=all func Test_diff_fold_sync() enew! diff --git a/src/nvim/testdir/test_digraph.vim b/src/nvim/testdir/test_digraph.vim index 6290680305..30dc9a4683 100644 --- a/src/nvim/testdir/test_digraph.vim +++ b/src/nvim/testdir/test_digraph.vim @@ -3,6 +3,7 @@ if !has("digraphs") || !has("multi_byte") finish endif +set belloff=all func! Put_Dig(chars) exe "norm! o\".a:chars diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 8635daa7ad..c28d76e66f 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2,6 +2,7 @@ source shared.vim +set belloff=all func! Setup_NewWindow() 10new call setline(1, range(1,100)) diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 03112df46f..40e373cdd2 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1,5 +1,6 @@ " Test for the search command +set belloff=all func Test_search_cmdline() " See test/functional/legacy/search_spec.lua throw 'skipped: Nvim does not support test_disable_char_avail()' diff --git a/src/nvim/testdir/test_textobjects.vim b/src/nvim/testdir/test_textobjects.vim index 630ae5d3a4..5e67f25286 100644 --- a/src/nvim/testdir/test_textobjects.vim +++ b/src/nvim/testdir/test_textobjects.vim @@ -4,6 +4,7 @@ if !has('textobjects') finish endif +set belloff=all function! CpoM(line, useM, expected) new diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index 171618f6f7..0f9f6c3310 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -3,6 +3,7 @@ " undo-able pieces. Do that by setting 'undolevels'. " Also tests :earlier and :later. +set belloff=all func Test_undotree() exe "normal Aabc\" set ul=100 diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index db603610da..d2574fc0d0 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -1,6 +1,7 @@ " Tests for user defined commands " Test for in user defined commands +set belloff=all function Test_cmdmods() let g:mods = '' diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 69607e642c..6a61942025 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -3,6 +3,8 @@ if !has('visual') finish endif +set belloff=all + func Test_block_shift_multibyte() " Uses double-wide character. if !has('multi_byte') -- cgit From 456cf72974865cecf489bc5a5b4003c22745a77d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 21 Jan 2018 10:28:52 +0100 Subject: vim-patch:8.0.0442: patch shell command not well escaped Problem: Patch shell command uses double quotes around the argument, which allows for $HOME to be expanded. (Etienne) Solution: Use single quotes on Unix. (closes vim/vim#1543) https://github.com/vim/vim/commit/1ef73e33c9414eb02c229d8234aafd9d481a8856 --- src/nvim/diff.c | 2 +- src/nvim/testdir/test_diffmode.vim | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index dd489c18e9..4db81a97a2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -925,7 +925,7 @@ void ex_diffpatch(exarg_T *eap) } else { // Build the patch command and execute it. Ignore errors. #ifdef UNIX - vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", + vim_snprintf((char *)buf, buflen, "patch -o %s %s < '%s'", tmp_new, tmp_orig, fullname != NULL ? fullname : eap->arg); #else vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index b5a76909a2..430d02c2c3 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -501,9 +501,20 @@ func Test_diffpatch() bwipe! new call assert_fails('diffpatch Xpatch', 'E816:') - call setline(1, ['1', '2', '3']) - diffpatch Xpatch - call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) + + for name in ['Xpatch', 'Xpatch$HOME'] + call setline(1, ['1', '2', '3']) + if name != 'Xpatch' + call rename('Xpatch', name) + endif + exe 'diffpatch ' . escape(name, '$') + call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) + if name != 'Xpatch' + call rename(name, 'Xpatch') + endif + bwipe! + endfor + call delete('Xpatch') bwipe! endfunc -- cgit From ab279c6fb8b219cc8accd273fe6e697aa949c16e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 21 Jan 2018 10:36:14 +0100 Subject: vim-patch:8.0.0444: diffpatch fails when the file name has a quote Problem: Diffpatch fails when the file name has a quote. Solution: Escape the name properly. (zetzei) https://github.com/vim/vim/commit/a95ab321200f0239991bf53756b17cd7b90745f9 --- src/nvim/diff.c | 51 ++++++++++++++++++-------------------- src/nvim/testdir/test_diffmode.vim | 2 +- 2 files changed, 25 insertions(+), 28 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 4db81a97a2..a32ac645e3 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -856,11 +856,12 @@ void ex_diffpatch(exarg_T *eap) char_u *buf = NULL; win_T *old_curwin = curwin; char_u *newname = NULL; // name of patched file buffer + char_u *esc_name = NULL; #ifdef UNIX char_u dirbuf[MAXPATHL]; char_u *fullname = NULL; -#endif // ifdef UNIX +#endif // We need two temp file names. // Name of original temp file. char_u *tmp_orig = vim_tempname(); @@ -880,21 +881,21 @@ void ex_diffpatch(exarg_T *eap) #ifdef UNIX // Get the absolute path of the patchfile, changing directory below. - fullname = (char_u *)FullName_save((char *)eap->arg, FALSE); -#endif // ifdef UNIX + fullname = (char_u *)FullName_save((char *)eap->arg, false); +#endif + esc_name = vim_strsave_shellescape( #ifdef UNIX - size_t buflen = STRLEN(tmp_orig) - + (fullname != NULL ? STRLEN(fullname) : STRLEN(eap->arg)) - + STRLEN(tmp_new) + 16; -#else - size_t buflen = STRLEN(tmp_orig) + (STRLEN(eap->arg)) + STRLEN(tmp_new) + 16; -#endif // ifdef UNIX - + fullname != NULL ? fullname : +#endif + eap->arg, true, true); + if (esc_name == NULL) { + goto theend; + } + size_t buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16; buf = xmalloc(buflen); #ifdef UNIX - // Temporarily chdir to /tmp, to avoid patching files in the current // directory when the patch file contains more than one patch. When we // have our own temp dir use that instead, it will be cleaned up when we @@ -911,26 +912,21 @@ void ex_diffpatch(exarg_T *eap) os_chdir(tempdir); shorten_fnames(TRUE); } -#endif // ifdef UNIX +#endif if (*p_pex != NUL) { // Use 'patchexpr' to generate the new file. #ifdef UNIX - eval_patch((char *) tmp_orig, - (char *) (fullname != NULL ? fullname : eap->arg), - (char *) tmp_new); + eval_patch((char *)tmp_orig, + (char *)(fullname != NULL ? fullname : eap->arg), + (char *)tmp_new); #else - eval_patch((char *) tmp_orig, (char *) eap->arg, (char *) tmp_new); -#endif // ifdef UNIX + eval_patch((char *)tmp_orig, (char *)eap->arg, (char *)tmp_new); +#endif } else { // Build the patch command and execute it. Ignore errors. -#ifdef UNIX - vim_snprintf((char *)buf, buflen, "patch -o %s %s < '%s'", - tmp_new, tmp_orig, fullname != NULL ? fullname : eap->arg); -#else - vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", - tmp_new, tmp_orig, eap->arg); -#endif // ifdef UNIX + vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", + tmp_new, tmp_orig, esc_name); block_autocmds(); // Avoid ShellCmdPost stuff (void)call_shell(buf, kShellOptFilter, NULL); unblock_autocmds(); @@ -943,7 +939,7 @@ void ex_diffpatch(exarg_T *eap) } shorten_fnames(TRUE); } -#endif // ifdef UNIX +#endif // patch probably has written over the screen redraw_later(CLEAR); @@ -1012,7 +1008,8 @@ theend: xfree(buf); #ifdef UNIX xfree(fullname); -#endif // ifdef UNIX +#endif + xfree(esc_name); } /// Split the window and edit another file, setting options to show the diffs. @@ -1163,7 +1160,7 @@ void ex_diffoff(exarg_T *eap) free_string_option(wp->w_p_fdm); wp->w_p_fdm = vim_strsave(*wp->w_p_fdm_save ? wp->w_p_fdm_save - : (char_u*)"manual"); + : (char_u *)"manual"); if (wp->w_p_fdc == diff_foldcolumn) { wp->w_p_fdc = wp->w_p_fdc_save; } diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 430d02c2c3..088ec5ccf6 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -502,7 +502,7 @@ func Test_diffpatch() new call assert_fails('diffpatch Xpatch', 'E816:') - for name in ['Xpatch', 'Xpatch$HOME'] + for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch'] call setline(1, ['1', '2', '3']) if name != 'Xpatch' call rename('Xpatch', name) -- cgit