Merge pull request #12938 from janlazo/vim-8.1.0285

vim-patch:8.1.{285,1782,1972,2261,2263},8.2.{240,817,824,1549,1676,1696}
This commit is contained in:
Jan Edmund Lazo 2020-09-19 17:40:55 -04:00 committed by GitHub
commit 9f704c88a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 8 deletions

View File

@ -4518,7 +4518,6 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
{
char_u *p;
char_u *name;
unsigned int extra = 0;
/*
@ -4526,11 +4525,14 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
*/
for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) {
if (*p == '\\' && p[1] != NUL) {
++p;
/* A "\<x>" form occupies at least 4 characters, and produces up
* to 6 characters: reserve space for 2 extra */
if (*p == '<')
extra += 2;
p++;
// A "\<x>" form occupies at least 4 characters, and produces up
// to 21 characters (3 * 6 for the char and 3 for a modifier):
// reserve space for 18 extra.
// Each byte in the char could be encoded as K_SPECIAL K_EXTRA x.
if (*p == '<') {
extra += 18;
}
}
}
@ -4549,7 +4551,8 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
* Copy the string into allocated memory, handling backslashed
* characters.
*/
name = xmalloc(p - *arg + extra);
const int len = (int)(p - *arg + extra);
char_u *name = xmalloc(len);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = name;
@ -4616,6 +4619,9 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true);
if (extra != 0) {
name += extra;
if (name >= rettv->vval.v_string + len) {
iemsg("get_string_tv() used more space than allocated");
}
break;
}
FALLTHROUGH;

View File

@ -65,3 +65,11 @@ func CheckCanRunGui()
throw 'Skipped: cannot start the GUI'
endif
endfunc
" Command to check that not currently using the GUI
command CheckNotGui call CheckNotGui()
func CheckNotGui()
if has('gui_running')
throw 'Skipped: only works in the terminal'
endif
endfunc

View File

@ -1,9 +1,11 @@
" Test for edit functions
"
if exists("+t_kD")
let &t_kD="[3;*~"
endif
source check.vim
" Needed for testing basic rightleft: Test_edit_rightleft
source view_util.vim
@ -1514,3 +1516,23 @@ func Test_edit_startinsert()
set backspace&
bwipe!
endfunc
func Test_edit_noesckeys()
CheckNotGui
new
" <Left> moves cursor when 'esckeys' is set
exe "set t_kl=\<Esc>OD"
" set esckeys
call feedkeys("axyz\<Esc>ODX", "xt")
" call assert_equal("xyXz", getline(1))
" <Left> exits Insert mode when 'esckeys' is off
" set noesckeys
call setline(1, '')
call feedkeys("axyz\<Esc>ODX", "xt")
call assert_equal(["DX", "xyz"], getline(1, 2))
bwipe!
" set esckeys
endfunc

View File

@ -1221,6 +1221,24 @@ func Test_reg_executing_and_recording()
unlet s:reg_stat
endfunc
func Test_getchar()
throw 'skipped: Nvim does not support test_setmouse()'
call feedkeys('a', '')
call assert_equal(char2nr('a'), getchar())
call test_setmouse(1, 3)
let v:mouse_win = 9
let v:mouse_winid = 9
let v:mouse_lnum = 9
let v:mouse_col = 9
call feedkeys("\<S-LeftMouse>", '')
call assert_equal("\<S-LeftMouse>", getchar())
call assert_equal(1, v:mouse_win)
call assert_equal(win_getid(1), v:mouse_winid)
call assert_equal(1, v:mouse_lnum)
call assert_equal(3, v:mouse_col)
endfunc
func Test_libcall_libcallnr()
if !has('libcall')
return
@ -1341,3 +1359,22 @@ func Test_readdir()
call delete('Xdir', 'rf')
endfunc
" Test for the eval() function
func Test_eval()
call assert_fails("call eval('5 a')", 'E488:')
endfunc
" Test for the nr2char() function
func Test_nr2char()
" set encoding=latin1
call assert_equal('@', nr2char(64))
set encoding=utf8
call assert_equal('a', nr2char(97, 1))
call assert_equal('a', nr2char(97, 0))
call assert_equal("\x80\xfc\b\xf4\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x100000) .. '>"'))
call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab