neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 5c22feac06aeb85ef3e17d6780478dd5e9a7c85d
parent 02def1a32ef7acb6b7d940193815ba06e3775ecf
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Wed, 17 Dec 2025 07:12:08 +0800

Merge pull request #36989 from zeertzjq/vim-9.0.1758

vim-patch:9.{0.1758,1.1983,1.1987}
Diffstat:
Msrc/nvim/runtime.c | 41+++++++++++++++++++++++------------------
Mtest/old/testdir/test_assert.vim | 13+++++++++++++
2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c @@ -195,39 +195,44 @@ char *estack_sfile(estack_arg_T which) for (int idx = 0; idx < exestack.ga_len; idx++) { entry = ((estack_T *)exestack.ga_data) + idx; if (entry->es_name != NULL) { - size_t len = strlen(entry->es_name) + 15; - char *type_name = ""; + String type_name = STATIC_CSTR_AS_STRING(""); + String es_name = cstr_as_string(entry->es_name); if (entry->es_type != last_type) { switch (entry->es_type) { case ETYPE_SCRIPT: - type_name = "script "; break; + type_name = STATIC_CSTR_AS_STRING("script "); break; case ETYPE_UFUNC: - type_name = "function "; break; + type_name = STATIC_CSTR_AS_STRING("function "); break; default: - type_name = ""; break; + break; } last_type = entry->es_type; } - len += strlen(type_name); - ga_grow(&ga, (int)len); linenr_T lnum = idx == exestack.ga_len - 1 ? which == ESTACK_STACK ? SOURCING_LNUM : 0 : entry->es_lnum; - char *dots = idx == exestack.ga_len - 1 ? "" : ".."; - if (lnum == 0) { - // For the bottom entry of <sfile>: do not add the line number, - // it is used in <slnum>. Also leave it out when the number is - // not set. - vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", - type_name, entry->es_name, dots); - } else { - vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%" PRIdLINENR "]%s", - type_name, entry->es_name, lnum, dots); + + size_t len = es_name.size + type_name.size + 26; + ga_grow(&ga, (int)len); + ga_concat_len(&ga, type_name.data, type_name.size); + ga_concat_len(&ga, es_name.data, es_name.size); + // For the bottom entry of <sfile>: do not add the line number, it is used in + // <slnum>. Also leave it out when the number is not set. + if (lnum != 0) { + ga.ga_len += (int)vim_snprintf_safelen((char *)ga.ga_data + ga.ga_len, + len - (size_t)ga.ga_len, + "[%" PRIdLINENR "]", lnum); + } + if (idx != exestack.ga_len - 1) { + ga_concat_len(&ga, S_LEN("..")); } - ga.ga_len += (int)strlen((char *)ga.ga_data + ga.ga_len); } } + // Only NUL-terminate when not returning NULL. + if (ga.ga_data != NULL) { + ga_append(&ga, NUL); + } return (char *)ga.ga_data; } diff --git a/test/old/testdir/test_assert.vim b/test/old/testdir/test_assert.vim @@ -386,6 +386,19 @@ func Test_assert_fails_in_timer() call StopVimInTerminal(buf) endfunc +" Check that a typed assert_equal() doesn't prepend an unnecessary ':'. +func Test_assert_equal_typed() + let after =<< trim END + call feedkeys(":call assert_equal(0, 1)\<CR>", 't') + call feedkeys(":call writefile(v:errors, 'Xerrors')\<CR>", 't') + call feedkeys(":qa!\<CR>", 't') + END + call assert_equal(1, RunVim([], after, '')) + call assert_equal(['Expected 0 but got 1'], readfile('Xerrors')) + + call delete('Xerrors') +endfunc + func Test_assert_beeps() new call assert_equal(0, assert_beeps('normal h'))