Merge #11805 'vim-patch:8.1.0619'

This commit is contained in:
Justin M. Keyes
2020-02-29 17:37:15 -08:00
6 changed files with 242 additions and 118 deletions

View File

@@ -9459,6 +9459,27 @@ void set_selfdict(typval_T *rettv, dict_T *selfdict)
}
}
// Turn a typeval into a string. Similar to tv_get_string_buf() but uses
// string() on Dict, List, etc.
static const char *tv_stringify(typval_T *varp, char *buf)
FUNC_ATTR_NONNULL_ALL
{
if (varp->v_type == VAR_LIST
|| varp->v_type == VAR_DICT
|| varp->v_type == VAR_FUNC
|| varp->v_type == VAR_PARTIAL
|| varp->v_type == VAR_FLOAT) {
typval_T tmp;
f_string(varp, &tmp, NULL);
const char *const res = tv_get_string_buf(&tmp, buf);
tv_clear(varp);
*varp = tmp;
return res;
}
return tv_get_string_buf(varp, buf);
}
// Find variable "name" in the list of variables.
// Return a pointer to it if found, NULL if not found.
// Careful: "a:0" variables don't have a name.
@@ -10349,7 +10370,10 @@ void ex_execute(exarg_T *eap)
}
if (!eap->skip) {
const char *const argstr = tv_get_string(&rettv);
char buf[NUMBUFLEN];
const char *const argstr = eap->cmdidx == CMD_execute
? tv_get_string_buf(&rettv, buf)
: tv_stringify(&rettv, buf);
const size_t len = strlen(argstr);
ga_grow(&ga, len + 2);
if (!GA_EMPTY(&ga)) {

View File

@@ -9558,7 +9558,7 @@ static void f_stridx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/*
* "string()" function
*/
static void f_string(typval_T *argvars, typval_T *rettv, FunPtr fptr)
void f_string(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (char_u *)encode_tv2string(&argvars[0], NULL);

View File

@@ -265,70 +265,70 @@ static struct
{ const char *name; int canon; }
enc_alias_table[] =
{
{"ansi", IDX_LATIN_1},
{"iso-8859-1", IDX_LATIN_1},
{"latin2", IDX_ISO_2},
{"latin3", IDX_ISO_3},
{"latin4", IDX_ISO_4},
{"cyrillic", IDX_ISO_5},
{"arabic", IDX_ISO_6},
{"greek", IDX_ISO_7},
{"hebrew", IDX_ISO_8},
{"latin5", IDX_ISO_9},
{"turkish", IDX_ISO_9}, /* ? */
{"latin6", IDX_ISO_10},
{"nordic", IDX_ISO_10}, /* ? */
{"thai", IDX_ISO_11}, /* ? */
{"latin7", IDX_ISO_13},
{"latin8", IDX_ISO_14},
{"latin9", IDX_ISO_15},
{"utf8", IDX_UTF8},
{"unicode", IDX_UCS2},
{"ucs2", IDX_UCS2},
{"ucs2be", IDX_UCS2},
{"ucs-2be", IDX_UCS2},
{"ucs2le", IDX_UCS2LE},
{"utf16", IDX_UTF16},
{"utf16be", IDX_UTF16},
{"utf-16be", IDX_UTF16},
{"utf16le", IDX_UTF16LE},
{"ucs4", IDX_UCS4},
{"ucs4be", IDX_UCS4},
{"ucs-4be", IDX_UCS4},
{"ucs4le", IDX_UCS4LE},
{"utf32", IDX_UCS4},
{"utf-32", IDX_UCS4},
{"utf32be", IDX_UCS4},
{"utf-32be", IDX_UCS4},
{"utf32le", IDX_UCS4LE},
{"utf-32le", IDX_UCS4LE},
{"932", IDX_CP932},
{"949", IDX_CP949},
{"936", IDX_CP936},
{"gbk", IDX_CP936},
{"950", IDX_CP950},
{"eucjp", IDX_EUC_JP},
{"unix-jis", IDX_EUC_JP},
{"ujis", IDX_EUC_JP},
{"shift-jis", IDX_SJIS},
{"pck", IDX_SJIS}, /* Sun: PCK */
{"euckr", IDX_EUC_KR},
{"5601", IDX_EUC_KR}, /* Sun: KS C 5601 */
{"euccn", IDX_EUC_CN},
{"gb2312", IDX_EUC_CN},
{"euctw", IDX_EUC_TW},
{"japan", IDX_EUC_JP},
{"korea", IDX_EUC_KR},
{"prc", IDX_EUC_CN},
{"zh-cn", IDX_EUC_CN},
{"chinese", IDX_EUC_CN},
{"zh-tw", IDX_EUC_TW},
{"taiwan", IDX_EUC_TW},
{"cp950", IDX_BIG5},
{"950", IDX_BIG5},
{"mac", IDX_MACROMAN},
{"mac-roman", IDX_MACROMAN},
{NULL, 0}
{ "ansi", IDX_LATIN_1 },
{ "iso-8859-1", IDX_LATIN_1 },
{ "latin2", IDX_ISO_2 },
{ "latin3", IDX_ISO_3 },
{ "latin4", IDX_ISO_4 },
{ "cyrillic", IDX_ISO_5 },
{ "arabic", IDX_ISO_6 },
{ "greek", IDX_ISO_7 },
{ "hebrew", IDX_ISO_8 },
{ "latin5", IDX_ISO_9 },
{ "turkish", IDX_ISO_9 }, // ?
{ "latin6", IDX_ISO_10 },
{ "nordic", IDX_ISO_10 }, // ?
{ "thai", IDX_ISO_11 }, // ?
{ "latin7", IDX_ISO_13 },
{ "latin8", IDX_ISO_14 },
{ "latin9", IDX_ISO_15 },
{ "utf8", IDX_UTF8 },
{ "unicode", IDX_UCS2 },
{ "ucs2", IDX_UCS2 },
{ "ucs2be", IDX_UCS2 },
{ "ucs-2be", IDX_UCS2 },
{ "ucs2le", IDX_UCS2LE },
{ "utf16", IDX_UTF16 },
{ "utf16be", IDX_UTF16 },
{ "utf-16be", IDX_UTF16 },
{ "utf16le", IDX_UTF16LE },
{ "ucs4", IDX_UCS4 },
{ "ucs4be", IDX_UCS4 },
{ "ucs-4be", IDX_UCS4 },
{ "ucs4le", IDX_UCS4LE },
{ "utf32", IDX_UCS4 },
{ "utf-32", IDX_UCS4 },
{ "utf32be", IDX_UCS4 },
{ "utf-32be", IDX_UCS4 },
{ "utf32le", IDX_UCS4LE },
{ "utf-32le", IDX_UCS4LE },
{ "932", IDX_CP932 },
{ "949", IDX_CP949 },
{ "936", IDX_CP936 },
{ "gbk", IDX_CP936 },
{ "950", IDX_CP950 },
{ "eucjp", IDX_EUC_JP },
{ "unix-jis", IDX_EUC_JP },
{ "ujis", IDX_EUC_JP },
{ "shift-jis", IDX_SJIS },
{ "pck", IDX_SJIS }, // Sun: PCK
{ "euckr", IDX_EUC_KR },
{ "5601", IDX_EUC_KR }, // Sun: KS C 5601
{ "euccn", IDX_EUC_CN },
{ "gb2312", IDX_EUC_CN },
{ "euctw", IDX_EUC_TW },
{ "japan", IDX_EUC_JP },
{ "korea", IDX_EUC_KR },
{ "prc", IDX_EUC_CN },
{ "zh-cn", IDX_EUC_CN },
{ "chinese", IDX_EUC_CN },
{ "zh-tw", IDX_EUC_TW },
{ "taiwan", IDX_EUC_TW },
{ "cp950", IDX_BIG5 },
{ "950", IDX_BIG5 },
{ "mac", IDX_MACROMAN },
{ "mac-roman", IDX_MACROMAN },
{ NULL, 0 }
};
/*

View File

@@ -1,4 +1,4 @@
" Tests for :messages
" Tests for :messages, :echomsg, :echoerr
function Test_messages()
let oldmore = &more
@@ -65,6 +65,35 @@ func Test_message_completion()
call assert_equal('"message clear', @:)
endfunc
func Test_echomsg()
call assert_equal("\nhello", execute(':echomsg "hello"'))
call assert_equal("\n", execute(':echomsg ""'))
call assert_equal("\n12345", execute(':echomsg 12345'))
call assert_equal("\n[]", execute(':echomsg []'))
call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]'))
call assert_equal("\n{}", execute(':echomsg {}'))
call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}'))
if has('float')
call assert_equal("\n1.23", execute(':echomsg 1.23'))
endif
call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}'))
endfunc
func Test_echoerr()
throw 'skipped: Nvim does not support test_ignore_error()'
call test_ignore_error('IgNoRe')
call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"'))
call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"'))
call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]'))
call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}'))
if has('float')
call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
endif
call test_ignore_error('<lambda>')
call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
call test_ignore_error('RESET')
endfunc
func Test_echospace()
set noruler noshowcmd laststatus=1
call assert_equal(&columns - 1, v:echospace)