diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:37:28 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:41:20 +0800 |
commit | 0d8293364f78237afb83d4822611d6fd8add66f8 (patch) | |
tree | 00f1c7cb6b2863db300a06f720cbae8233ba34b7 /src/nvim/testing.c | |
parent | b33de61cc3e14cc6160a972205f6543e82b843aa (diff) | |
download | rneovim-0d8293364f78237afb83d4822611d6fd8add66f8.tar.gz rneovim-0d8293364f78237afb83d4822611d6fd8add66f8.tar.bz2 rneovim-0d8293364f78237afb83d4822611d6fd8add66f8.zip |
vim-patch:8.2.1479: Vim9: error for list index uses wrong line number
Problem: Vim9: error for list index uses wrong line number.
Solution: Set source line number. (closes vim/vim#6724) Add a way to assert the
line number of the error with assert_fails().
https://github.com/vim/vim/commit/1d634542cf5ebcd1d5d83bd124b3e1d5e7c96c58
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/testing.c')
-rw-r--r-- | src/nvim/testing.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/nvim/testing.c b/src/nvim/testing.c index e1a28fbde3..7651122cce 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -124,7 +124,10 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s bool did_copy = false; int omitted = 0; - if (opt_msg_tv->v_type != VAR_UNKNOWN) { + if (opt_msg_tv->v_type != VAR_UNKNOWN + && !(opt_msg_tv->v_type == VAR_STRING + && (opt_msg_tv->vval.v_string == NULL + || *opt_msg_tv->vval.v_string == NUL))) { tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL); ga_concat(gap, (char *)tofree); xfree(tofree); @@ -497,6 +500,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char buf[NUMBUFLEN]; const char *expected; bool error_found = false; + bool lnum_error_found = false; char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg; if (argvars[1].v_type == VAR_STRING) { @@ -525,12 +529,25 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) goto theend; } + if (!error_found && argvars[3].v_type == VAR_NUMBER + && argvars[3].vval.v_number >= 0 + && argvars[3].vval.v_number != emsg_assert_fails_lnum) { + error_found = true; + lnum_error_found = true; + } + if (error_found) { typval_T actual_tv; - actual_tv.v_type = VAR_STRING; - actual_tv.vval.v_string = actual; prepare_assert_error(&ga); - fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], + if (lnum_error_found) { + actual_tv.v_type = VAR_NUMBER; + actual_tv.vval.v_number = emsg_assert_fails_lnum; + } else { + actual_tv.v_type = VAR_STRING; + actual_tv.vval.v_string = actual; + } + fill_assert_error(&ga, &argvars[2], NULL, + &argvars[lnum_error_found ? 3 : 1], &actual_tv, ASSERT_OTHER); ga_concat(&ga, ": "); assert_append_cmd_or_arg(&ga, argvars, cmd); |