From 5c9cd009e161fac9d549533f966b930c51877f4f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 2 Sep 2018 21:10:55 -0400 Subject: vim-patch:8.1.0331: insufficient test coverage for :mkview and :loadview Problem: Insufficient test coverage for :mkview and :loadview. Solution: Add tests. (Dominique Pelle, closes vim/vim#3385) https://github.com/vim/vim/commit/627cb6a6b37d17433fe2d7df1f287eefb5b370e3 --- src/nvim/testdir/test_mksession.vim | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'src/nvim') diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index 4774cf4af5..f7836ea4b9 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -151,5 +151,86 @@ func Test_mksession_one_buffer_two_windows() call delete('Xtest_mks.out') endfunc +" Test :mkview with a file argument. +func Test_mkview_file() + " Create a view with line number and a fold. + help :mkview + set number + norm! V}zf + let pos = getpos('.') + let linefoldclosed1 = foldclosed('.') + mkview! Xview + set nonumber + norm! zrj + " We can close the help window, as mkview with a file name should + " generate a command to edit the file. + helpclose + + source Xview + call assert_equal(1, &number) + call assert_match('\*:mkview\*$', getline('.')) + call assert_equal(pos, getpos('.')) + call assert_equal(linefoldclosed1, foldclosed('.')) + + " Creating a view again with the same file name should fail (file + " already exists). But with a !, the previous view should be + " overwritten without error. + help :loadview + call assert_fails('mkview Xview', 'E189:') + call assert_match('\*:loadview\*$', getline('.')) + mkview! Xview + call assert_match('\*:loadview\*$', getline('.')) + + call delete('Xview') + bwipe +endfunc + +" Test :mkview and :loadview with a custom 'viewdir'. +func Test_mkview_loadview_with_viewdir() + set viewdir=Xviewdir + + help :mkview + set number + norm! V}zf + let pos = getpos('.') + let linefoldclosed1 = foldclosed('.') + mkview 1 + set nonumber + norm! zrj + + loadview 1 + + " The directory Xviewdir/ should have been created and the view + " should be stored in that directory. + call assert_equal('Xviewdir/' . + \ substitute( + \ substitute( + \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', + \ glob('Xviewdir/*')) + call assert_equal(1, &number) + call assert_match('\*:mkview\*$', getline('.')) + call assert_equal(pos, getpos('.')) + call assert_equal(linefoldclosed1, foldclosed('.')) + + call delete('Xviewdir', 'rf') + set viewdir& + helpclose +endfunc + +func Test_mkview_no_file_name() + new + " :mkview or :mkview {nr} should fail in a unnamed buffer. + call assert_fails('mkview', 'E32:') + call assert_fails('mkview 1', 'E32:') + + " :mkview {file} should succeed in a unnamed buffer. + mkview Xview + help + source Xview + call assert_equal('', bufname('%')) + + call delete('Xview') + %bwipe +endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit From bd7371f4605032f015df9ab76ab5b25d61854932 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 2 Sep 2018 23:01:52 -0400 Subject: vim-patch:8.1.0333: :mkview does not restore cursor properly after "$" Problem: :mkview does not restore cursor properly after "$". (Dominique Pelle) Solution: Position the cursor with "normal! $". https://github.com/vim/vim/commit/92c1b696413bf0e28f2fec22090d42e8a825eff2 --- src/nvim/ex_docmd.c | 21 +++++++++++++++------ src/nvim/testdir/test_mksession.vim | 16 ++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 5a92a85c97..abefca231c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9239,6 +9239,18 @@ static int ses_do_win(win_T *wp) return true; } +static int put_view_curpos(FILE *fd, const win_T *wp, char *spaces) +{ + int r; + + if (wp->w_curswant == MAXCOL) { + r = fprintf(fd, "%snormal! $", spaces); + } else { + r = fprintf(fd, "%snormal! 0%d|", spaces, wp->w_virtcol + 1); + } + return r < 0 || put_eol(fd) == FAIL ? FAIL : OK; +} + /* * Write commands to "fd" to restore the view of a window. * Caller must make sure 'scrolloff' is zero. @@ -9405,14 +9417,11 @@ put_view( (int64_t)(wp->w_virtcol + 1)) < 0 || put_eol(fd) == FAIL || put_line(fd, "else") == FAIL - || fprintf(fd, " normal! 0%d|", wp->w_virtcol + 1) < 0 - || put_eol(fd) == FAIL + || put_view_curpos(fd, wp, " ") == FAIL || put_line(fd, "endif") == FAIL) return FAIL; - } else { - if (fprintf(fd, "normal! 0%d|", wp->w_virtcol + 1) < 0 - || put_eol(fd) == FAIL) - return FAIL; + } else if (put_view_curpos(fd, wp, "") == FAIL) { + return FAIL; } } } diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index f7836ea4b9..b9012745c0 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -19,7 +19,8 @@ func Test_mksession() \ 'two tabs in one line', \ 'one ä multibyteCharacter', \ 'aä Ä two multiByte characters', - \ 'Aäöü three mulTibyte characters' + \ 'Aäöü three mulTibyte characters', + \ 'short line', \ ]) let tmpfile = 'Xtemp' exec 'w! ' . tmpfile @@ -41,6 +42,8 @@ func Test_mksession() norm! j16| split norm! j16| + split + norm! j$ wincmd l set nowrap @@ -63,7 +66,7 @@ func Test_mksession() split call wincol() mksession! Xtest_mks.out - let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! 0\\|^ *exe ''normal!\\)"') + let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"') let expected = [ \ 'normal! 016|', \ 'normal! 016|', @@ -73,6 +76,7 @@ func Test_mksession() \ 'normal! 016|', \ 'normal! 016|', \ 'normal! 016|', + \ 'normal! $', \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", \ " normal! 016|", \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", @@ -157,7 +161,7 @@ func Test_mkview_file() help :mkview set number norm! V}zf - let pos = getpos('.') + let pos = getcurpos() let linefoldclosed1 = foldclosed('.') mkview! Xview set nonumber @@ -169,7 +173,7 @@ func Test_mkview_file() source Xview call assert_equal(1, &number) call assert_match('\*:mkview\*$', getline('.')) - call assert_equal(pos, getpos('.')) + call assert_equal(pos, getcurpos()) call assert_equal(linefoldclosed1, foldclosed('.')) " Creating a view again with the same file name should fail (file @@ -192,7 +196,7 @@ func Test_mkview_loadview_with_viewdir() help :mkview set number norm! V}zf - let pos = getpos('.') + let pos = getcurpos() let linefoldclosed1 = foldclosed('.') mkview 1 set nonumber @@ -209,7 +213,7 @@ func Test_mkview_loadview_with_viewdir() \ glob('Xviewdir/*')) call assert_equal(1, &number) call assert_match('\*:mkview\*$', getline('.')) - call assert_equal(pos, getpos('.')) + call assert_equal(pos, getcurpos()) call assert_equal(linefoldclosed1, foldclosed('.')) call delete('Xviewdir', 'rf') -- cgit From d7432145ff39bb3827b93009b80be3956aedcc1e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 2 Sep 2018 23:33:48 -0400 Subject: vim-patch:8.1.0335: mkview test fails on CI Problem: mkview test fails on CI. Solution: Attempt to force recomputing curswant after folding. https://github.com/vim/vim/commit/2bf4fe07b651e2a72fcfbfdb0719b402ea0b0a10 --- src/nvim/testdir/test_mksession.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim') diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index b9012745c0..8332f6bb41 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -160,7 +160,7 @@ func Test_mkview_file() " Create a view with line number and a fold. help :mkview set number - norm! V}zf + norm! V}zf0 let pos = getcurpos() let linefoldclosed1 = foldclosed('.') mkview! Xview -- cgit From 6deddb26def6aaf4b18d1c31c319fe9db6dfb399 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 2 Sep 2018 23:34:07 -0400 Subject: vim-patch:8.1.0336: mkview test still fails on CI Problem: mkview test still fails on CI. Solution: Ignore curswant, don't see another solution. https://github.com/vim/vim/commit/dd5d18eadffadc723ff7d3e208a2973d267a6dde --- src/nvim/testdir/test_mksession.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index 8332f6bb41..e30d5f7a40 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -161,7 +161,7 @@ func Test_mkview_file() help :mkview set number norm! V}zf0 - let pos = getcurpos() + let pos = getpos('.') let linefoldclosed1 = foldclosed('.') mkview! Xview set nonumber @@ -173,7 +173,7 @@ func Test_mkview_file() source Xview call assert_equal(1, &number) call assert_match('\*:mkview\*$', getline('.')) - call assert_equal(pos, getcurpos()) + call assert_equal(pos, getpos('.')) call assert_equal(linefoldclosed1, foldclosed('.')) " Creating a view again with the same file name should fail (file @@ -196,7 +196,7 @@ func Test_mkview_loadview_with_viewdir() help :mkview set number norm! V}zf - let pos = getcurpos() + let pos = getpos('.') let linefoldclosed1 = foldclosed('.') mkview 1 set nonumber @@ -213,7 +213,7 @@ func Test_mkview_loadview_with_viewdir() \ glob('Xviewdir/*')) call assert_equal(1, &number) call assert_match('\*:mkview\*$', getline('.')) - call assert_equal(pos, getcurpos()) + call assert_equal(pos, getpos('.')) call assert_equal(linefoldclosed1, foldclosed('.')) call delete('Xviewdir', 'rf') -- cgit From 3e1daa84e91c1e94301419bf1297b4cd88c6498f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 3 Sep 2018 00:09:57 -0400 Subject: oldtests: win: fix pathsep in :mkview test --- src/nvim/testdir/test_mksession.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index e30d5f7a40..9ba264deb6 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -206,10 +206,11 @@ func Test_mkview_loadview_with_viewdir() " The directory Xviewdir/ should have been created and the view " should be stored in that directory. - call assert_equal('Xviewdir/' . + let pathsep = has('win32') ? '\' : '/' + call assert_equal('Xviewdir' . pathsep . \ substitute( \ substitute( - \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', + \ expand('%:p'), pathsep, '=+', 'g'), ':', '=-', 'g') . '=1.vim', \ glob('Xviewdir/*')) call assert_equal(1, &number) call assert_match('\*:mkview\*$', getline('.')) -- cgit