From ad99d0bf7e291564dd858f8206db52311f8878cc Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 18 Apr 2016 20:58:18 +0200 Subject: vim-patch:5a46a58 Add missing test file. https://github.com/vim/vim/commit/5a46a58eb6e50cb5204909cc2202e3400761263f --- src/nvim/testdir/test_cursor_func.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/nvim/testdir/test_cursor_func.vim (limited to 'src') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim new file mode 100644 index 0000000000..684391e2a5 --- /dev/null +++ b/src/nvim/testdir/test_cursor_func.vim @@ -0,0 +1,35 @@ +" Tests for cursor(). + +func Test_wrong_arguments() + try + call cursor(1. 3) + " not reached + call assert_false(1) + catch + call assert_exception('E474:') + endtry +endfunc + +func Test_move_cursor() + new + call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) + + call cursor([1, 1, 0, 1]) + call assert_equal([1, 1, 0, 1], getcurpos()[1:]) + call cursor([4, 3, 0, 3]) + call assert_equal([4, 3, 0, 3], getcurpos()[1:]) + + call cursor(2, 2) + call assert_equal([2, 2, 0, 3], getcurpos()[1:]) + " line number zero keeps the line number + call cursor(0, 1) + call assert_equal([2, 1, 0, 3], getcurpos()[1:]) + " col number zero keeps the column + call cursor(3, 0) + call assert_equal([3, 1, 0, 3], getcurpos()[1:]) + " below last line goes to last line + call cursor(9, 1) + call assert_equal([4, 1, 0, 3], getcurpos()[1:]) + + quit! +endfunc -- cgit From 11fd9655542fd2676e13d00791b4bc9e96772300 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 18 Apr 2016 21:06:04 +0200 Subject: vim-patch:7.4.1300 Problem: Cannot test CursorMovedI because there is typeahead. Solution: Add disable_char_avail_for_testing(). https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63 Most of it manually applied. --- src/nvim/eval.c | 11 +++++++++++ src/nvim/getchar.c | 5 +++++ src/nvim/globals.h | 2 ++ src/nvim/testdir/test_cursor_func.vim | 27 +++++++++++++++++++++++---- src/nvim/version.c | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9553c7a7ed..60ebc34ea9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6707,6 +6707,7 @@ static struct fst { { "did_filetype", 0, 0, f_did_filetype }, { "diff_filler", 1, 1, f_diff_filler }, { "diff_hlID", 2, 2, f_diff_hlID }, + {"disable_char_avail_for_testing", 1, 1, f_disable_char_avail_for_testing}, { "empty", 1, 1, f_empty }, { "escape", 2, 2, f_escape }, { "eval", 1, 1, f_eval }, @@ -8582,6 +8583,15 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; } +// +// "disable_char_avail_for_testing({expr})" function +// +static void f_disable_char_avail_for_testing(typval_T *argvars, typval_T *rettv) + FUNC_ATTR_NONNULL_ARG(1) +{ + disable_char_avail_for_testing = get_tv_number(&argvars[0]); +} + /* * "empty({expr})" function */ @@ -10173,6 +10183,7 @@ static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos) list_append_number(l, (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0); if (getcurpos) { + update_curswant(); list_append_number(l, curwin->w_curswant == MAXCOL ? (varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1); diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 437495faa4..74e5526caa 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1562,6 +1562,11 @@ int char_avail(void) { int retval; + // When disable_char_avail_for_testing(1) was called pretend + // there is no typeahead + if (disable_char_avail_for_testing) { + return FALSE; + } ++no_mapping; retval = vpeekc(); --no_mapping; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 49d1de21d9..d8331d608c 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1239,6 +1239,8 @@ EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */ EXTERN int ignored; EXTERN char *ignoredp; +EXTERN int disable_char_avail_for_testing INIT(= 0); + // If a msgpack-rpc channel should be started over stdin/stdout EXTERN bool embedded_mode INIT(= false); EXTERN Loop loop; diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 684391e2a5..d3236e6e01 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -20,16 +20,35 @@ func Test_move_cursor() call assert_equal([4, 3, 0, 3], getcurpos()[1:]) call cursor(2, 2) - call assert_equal([2, 2, 0, 3], getcurpos()[1:]) + call assert_equal([2, 2, 0, 2], getcurpos()[1:]) " line number zero keeps the line number call cursor(0, 1) - call assert_equal([2, 1, 0, 3], getcurpos()[1:]) + call assert_equal([2, 1, 0, 1], getcurpos()[1:]) " col number zero keeps the column call cursor(3, 0) - call assert_equal([3, 1, 0, 3], getcurpos()[1:]) + call assert_equal([3, 1, 0, 1], getcurpos()[1:]) " below last line goes to last line call cursor(9, 1) - call assert_equal([4, 1, 0, 3], getcurpos()[1:]) + call assert_equal([4, 1, 0, 1], getcurpos()[1:]) quit! endfunc + +" Very short version of what matchparen does. +function s:Highlight_Matching_Pair() + let save_cursor = getcurpos() + call setpos('.', save_cursor) +endfunc + +func Test_curswant_with_autocommand() + new + call setline(1, ['func()', '{', '}', '----']) + autocmd! CursorMovedI * call s:Highlight_Matching_Pair() + call disable_char_avail_for_testing(1) + exe "normal! 3Ga\X\" + call disable_char_avail_for_testing(0) + call assert_equal('-X---', getline(4)) + autocmd! CursorMovedI * + quit! +endfunc + diff --git a/src/nvim/version.c b/src/nvim/version.c index a492c8d7ec..ed16b1b0d5 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -377,7 +377,7 @@ static int included_patches[] = { // 1303 NA // 1302 NA // 1301 NA - // 1300, + 1300, // 1299 NA // 1298 NA // 1297 NA -- cgit From cf434d2ae4834e0e7149e8c0e3c3739cbdf2fe1f Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 18 Apr 2016 21:56:40 +0200 Subject: Satisfy the linter. --- src/nvim/eval.c | 4 ++-- src/nvim/getchar.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 60ebc34ea9..7849a340ab 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6707,7 +6707,7 @@ static struct fst { { "did_filetype", 0, 0, f_did_filetype }, { "diff_filler", 1, 1, f_diff_filler }, { "diff_hlID", 2, 2, f_diff_hlID }, - {"disable_char_avail_for_testing", 1, 1, f_disable_char_avail_for_testing}, + { "disable_char_avail_for_testing", 1, 1, f_disable_char_avail_for_testing }, { "empty", 1, 1, f_empty }, { "escape", 2, 2, f_escape }, { "eval", 1, 1, f_eval }, @@ -8585,7 +8585,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv) // // "disable_char_avail_for_testing({expr})" function -// +// static void f_disable_char_avail_for_testing(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ARG(1) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 74e5526caa..b5e1e586bd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1565,9 +1565,9 @@ int char_avail(void) // When disable_char_avail_for_testing(1) was called pretend // there is no typeahead if (disable_char_avail_for_testing) { - return FALSE; + return false; } - ++no_mapping; + no_mapping++; retval = vpeekc(); --no_mapping; return retval != NUL; -- cgit From db9c22adb9e1843a8b5aafb1d4976adac65eace6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 25 Apr 2016 05:51:22 -0400 Subject: legacy test: Makefile --- src/nvim/testdir/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 4debdd9acc..82c7cd4de9 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -41,6 +41,7 @@ SCRIPTS := \ # Keep test_alot*.res as the last one, sort the others. NEW_TESTS = \ test_viml.res \ + test_cursor_func.res \ test_alot.res SCRIPTS_GUI := test16.out -- cgit From 67d5a1aae2b4564cddc1883b01a926ab29b8be64 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 25 Apr 2016 05:52:25 -0400 Subject: vim-patch:7.4.1092 Problem: It is not simple to test for an exception and give a proper error message. Solution: Add assert_exception(). https://github.com/vim/vim/commit/a803c7f94070f94b831fdfd1984f288c8b825b5d --- src/nvim/eval.c | 21 +++++++++++++++++++++ src/nvim/version.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7849a340ab..4d28996d55 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6665,6 +6665,7 @@ static struct fst { { "argv", 0, 1, f_argv }, { "asin", 1, 1, f_asin }, // WJMc { "assert_equal", 2, 3, f_assert_equal }, + { "assert_exception", 1, 2, f_assert_exception }, { "assert_false", 1, 2, f_assert_false }, { "assert_true", 1, 2, f_assert_true }, { "atan", 1, 1, f_atan }, @@ -7628,6 +7629,26 @@ static void f_assert_equal(typval_T *argvars, typval_T *rettv) } } +/// "assert_exception(string[, msg])" function +static void f_assert_exception(typval_T *argvars, typval_T *rettv) +{ + garray_T ga; + + char *error = (char *)get_tv_string_chk(&argvars[0]); + if (vimvars[VV_EXCEPTION].vv_str == NULL) { + prepare_assert_error(&ga); + ga_concat(&ga, (char_u *)"v:exception is not set"); + assert_error(&ga); + ga_clear(&ga); + } else if (strstr((char *)vimvars[VV_EXCEPTION].vv_str, error) == NULL) { + prepare_assert_error(&ga); + fill_assert_error(&ga, &argvars[1], NULL, &argvars[0], + &vimvars[VV_EXCEPTION].vv_tv); + assert_error(&ga); + ga_clear(&ga); + } +} + // Common for assert_true() and assert_false(). static void assert_bool(typval_T *argvars, bool is_true) { diff --git a/src/nvim/version.c b/src/nvim/version.c index ed16b1b0d5..e913d84223 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -585,7 +585,7 @@ static int included_patches[] = { // 1095 NA // 1094, 1093, - // 1092, + 1092, // 1091, // 1090, 1089, -- cgit From 0d6fe73d7b4dbba5bcea4559896c92f9c7e3f10a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 26 Apr 2016 22:34:12 -0400 Subject: vim-patch:7.4.1118 Problem: Tests hang in 24 line terminal. Solution: Set the 'more' option off. https://github.com/vim/vim/commit/a99b90437af730dcafd9143c0942c87777a00d52 --- src/nvim/testdir/runtest.vim | 1 + src/nvim/version.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 1c610eab51..6601dcf52f 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -62,6 +62,7 @@ else endif " Locate Test_ functions and execute them. +set nomore redir @q function /^Test_ redir END diff --git a/src/nvim/version.c b/src/nvim/version.c index e913d84223..89aef16f07 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -559,7 +559,7 @@ static int included_patches[] = { // 1121, 1120, // 1119, - // 1118, + 1118, 1117, 1116, // 1115 NA -- cgit From e4146dd7df0f1ba932a01a79d6dd511914763c72 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 26 Apr 2016 23:29:55 -0400 Subject: remove disable_char_avail_for_testing() test_cursor_func.vim hangs at the call to disable_char_avail_for_testing(). The test does not actually need this function (and it correctly fails if the fix from 7.4.1300 is reverted). Given that disable_char_avail_for_testing is a gigantic hack, if we can avoid it let's do so. --- src/nvim/eval.c | 10 ---------- src/nvim/getchar.c | 5 ----- src/nvim/globals.h | 2 -- src/nvim/testdir/test_cursor_func.vim | 2 -- src/nvim/version.c | 2 +- 5 files changed, 1 insertion(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4d28996d55..944ec1829a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6708,7 +6708,6 @@ static struct fst { { "did_filetype", 0, 0, f_did_filetype }, { "diff_filler", 1, 1, f_diff_filler }, { "diff_hlID", 2, 2, f_diff_hlID }, - { "disable_char_avail_for_testing", 1, 1, f_disable_char_avail_for_testing }, { "empty", 1, 1, f_empty }, { "escape", 2, 2, f_escape }, { "eval", 1, 1, f_eval }, @@ -8604,15 +8603,6 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; } -// -// "disable_char_avail_for_testing({expr})" function -// -static void f_disable_char_avail_for_testing(typval_T *argvars, typval_T *rettv) - FUNC_ATTR_NONNULL_ARG(1) -{ - disable_char_avail_for_testing = get_tv_number(&argvars[0]); -} - /* * "empty({expr})" function */ diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b5e1e586bd..cf4174f702 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1562,11 +1562,6 @@ int char_avail(void) { int retval; - // When disable_char_avail_for_testing(1) was called pretend - // there is no typeahead - if (disable_char_avail_for_testing) { - return false; - } no_mapping++; retval = vpeekc(); --no_mapping; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index d8331d608c..49d1de21d9 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1239,8 +1239,6 @@ EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */ EXTERN int ignored; EXTERN char *ignoredp; -EXTERN int disable_char_avail_for_testing INIT(= 0); - // If a msgpack-rpc channel should be started over stdin/stdout EXTERN bool embedded_mode INIT(= false); EXTERN Loop loop; diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index d3236e6e01..d819b7b092 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -44,9 +44,7 @@ func Test_curswant_with_autocommand() new call setline(1, ['func()', '{', '}', '----']) autocmd! CursorMovedI * call s:Highlight_Matching_Pair() - call disable_char_avail_for_testing(1) exe "normal! 3Ga\X\" - call disable_char_avail_for_testing(0) call assert_equal('-X---', getline(4)) autocmd! CursorMovedI * quit! diff --git a/src/nvim/version.c b/src/nvim/version.c index 89aef16f07..553f45b91a 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -377,7 +377,7 @@ static int included_patches[] = { // 1303 NA // 1302 NA // 1301 NA - 1300, + // 1300 NA // 1299 NA // 1298 NA // 1297 NA -- cgit