Compare commits

..

3 Commits

Author SHA1 Message Date
241572794f patch 8.2.1471: :const only locks the variable, not the value
Problem:    :const only locks the variable, not the value.
Solution:   Lock the value as ":lockvar 1 var" would do. (closes #6719)
2020-08-16 22:50:01 +02:00
c0f8823ee4 patch 8.2.1470: errors in spell file not tested
Problem:    Errors in spell file not tested.
Solution:   Add test for spell file errors. (Yegappan Lakshmanan,
            closes #6721)
2020-08-16 21:51:49 +02:00
0aae4809fd patch 8.2.1469: Vim9: cannot assign string to string option
Problem:    Vim9: cannot assign string to string option.
Solution:   Change checks for option value. (closes #6720)
2020-08-16 21:29:05 +02:00
5 changed files with 235 additions and 32 deletions

View File

@ -1294,28 +1294,36 @@ ex_let_one(
emsg(_(e_letunexp));
else
{
long n;
long n = 0;
int opt_type;
long numval;
char_u *stringval = NULL;
char_u *s = NULL;
int failed = FALSE;
c1 = *p;
*p = NUL;
n = (long)tv_get_number(tv);
// avoid setting a string option to the text "v:false" or similar.
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL)
s = tv_get_string_chk(tv); // != NULL if number or string
if (s != NULL && op != NULL && *op != '=')
opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
if ((opt_type == 1 || opt_type == -1)
&& (tv->v_type != VAR_STRING || !in_vim9script()))
// number, possibly hidden
n = (long)tv_get_number(tv);
// Avoid setting a string option to the text "v:false" or similar.
// In Vim9 script also don't convert a number to string.
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL
&& (!in_vim9script() || tv->v_type != VAR_NUMBER))
s = tv_get_string_chk(tv);
if (op != NULL && *op != '=')
{
opt_type = get_option_value(arg, &numval,
&stringval, opt_flags);
if ((opt_type == 1 && *op == '.')
|| (opt_type == 0 && *op != '.'))
{
semsg(_(e_letwrong), op);
s = NULL; // don't set the value
failed = TRUE; // don't set the value
}
else
{
@ -1330,19 +1338,25 @@ ex_let_one(
case '%': n = (long)num_modulus(numval, n); break;
}
}
else if (opt_type == 0 && stringval != NULL) // string
else if (opt_type == 0 && stringval != NULL && s != NULL)
{
// string
s = concat_str(stringval, s);
vim_free(stringval);
stringval = s;
}
}
}
if (s != NULL || tv->v_type == VAR_BOOL
|| tv->v_type == VAR_SPECIAL)
if (!failed)
{
set_option_value(arg, n, s, opt_flags);
arg_end = p;
if (opt_type != 0 || s != NULL)
{
set_option_value(arg, n, s, opt_flags);
arg_end = p;
}
else
emsg(_(e_stringreq));
}
*p = c1;
vim_free(stringval);
@ -3073,7 +3087,7 @@ set_var_const(
}
if (flags & LET_IS_CONST)
di->di_tv.v_lock |= VAR_LOCKED;
item_lock(&di->di_tv, 1, TRUE);
}
/*

View File

@ -41,6 +41,7 @@ func Test_define_var_with_lock()
call assert_fails('let s = "vim"', 'E741:')
call assert_fails('let F = funcref("s:noop")', 'E741:')
call assert_fails('let l = [1, 2, 3]', 'E741:')
call assert_fails('call filter(l, "v:val % 2 == 0")', 'E741:')
call assert_fails('let d = {"foo": 10}', 'E741:')
if has('channel')
call assert_fails('let j = test_null_job()', 'E741:')
@ -276,13 +277,16 @@ func Test_lock_depth_is_1()
const l = [1, 2, 3]
const d = {'foo': 10}
" Modify list
call add(l, 4)
" Modify list - setting item is OK, adding/removing items not
let l[0] = 42
call assert_fails('call add(l, 4)', 'E741:')
call assert_fails('unlet l[1]', 'E741:')
" Modify dict
let d['bar'] = 'hello'
" Modify dict - changing item is OK, adding/removing items not
let d['foo'] = 'hello'
let d.foo = 44
call assert_fails("let d['bar'] = 'hello'", 'E741:')
call assert_fails("unlet d['foo']", 'E741:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -167,8 +167,173 @@ func Test_spell_normal()
call assert_equal([], glob('Xspellfile.add',0,1))
call assert_equal([], glob('Xspellfile2.add',0,1))
set spellfile=
set spellfile= spell& spelllang&
bw!
endfunc
" Test for spell file format errors
func Test_spellfile_format_error()
let save_rtp = &rtp
call mkdir('Xtest/spell', 'p')
" empty spell file
call writefile([], './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E757:')
set nospell spelllang&
" invalid file ID
call writefile(['vim'], './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E757:')
set nospell spelllang&
" missing version number
call writefile(['VIMspell'], './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E771:')
set nospell spelllang&
" invalid version number
call writefile(['VIMspellz'], './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E772:')
set nospell spelllang&
" no sections
call writefile(0z56494D7370656C6C32, './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" missing section length
call writefile(['VIMspell200'], './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" unsupported required section
call writefile(['VIMspell2z' .. nr2char(1) .. ' ' .. nr2char(4)],
\ './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E770:')
set nospell spelllang&
" unsupported not-required section
call writefile(['VIMspell2z' .. nr2char(0) .. ' ' .. nr2char(4)],
\ './Xtest/spell/Xtest.utf-8.spl')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" SN_REGION: invalid number of region names
call writefile(0z56494D7370656C6C320000000000FF,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
" SN_CHARFLAGS: missing <charflagslen> length
call writefile(0z56494D7370656C6C32010000000004,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" SN_CHARFLAGS: invalid <charflagslen> length
call writefile(0z56494D7370656C6C320100000000010201,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
set spell
" FIXME: There are no error messages. How to check for the test result?
set nospell spelllang&
" SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0
call writefile(0z56494D7370656C6C3201000000000400000101,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
" SN_CHARFLAGS: missing <folcharslen> length
call writefile(0z56494D7370656C6C3201000000000100,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" SN_PREFCOND: invalid prefcondcnt
call writefile(0z56494D7370656C6C3203000000000100,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
" SN_PREFCOND: invalid condlen
call writefile(0z56494D7370656C6C320300000000020001,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
" SN_REP: invalid repcount
call writefile(0z56494D7370656C6C3204000000000100,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" SN_REP: missing rep
call writefile(0z56494D7370656C6C320400000000020004,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E758:')
set nospell spelllang&
" SN_REP: zero repfromlen
call writefile(0z56494D7370656C6C32040000000003000100,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
" SN_REP: invalid reptolen
call writefile(0z56494D7370656C6C320400000000050001014101,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
" FIXME: There are no error messages. How to check for the test result?
set spell
set nospell spelllang&
" SN_REP: zero reptolen
call writefile(0z56494D7370656C6C320400000000050001014100,
\ './Xtest/spell/Xtest.utf-8.spl', 'b')
set runtimepath=./Xtest
set spelllang=Xtest
call assert_fails('set spell', 'E759:')
set nospell spelllang&
let &rtp = save_rtp
call delete('Xtest', 'rf')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -96,22 +96,36 @@ def Test_assignment()
&ts += 3
assert_equal(9, &ts)
END
call CheckScriptSuccess(lines)
CheckScriptSuccess(lines)
call CheckDefFailure(['&notex += 3'], 'E113:')
call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
call CheckDefFailure(['&ts = [7]'], 'E1012:')
call CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list')
call CheckDefFailure(['&ts = "xx"'], 'E1012:')
call CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string')
call CheckDefFailure(['&path += 3'], 'E1012:')
call CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
CheckDefFailure(['&notex += 3'], 'E113:')
CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
CheckDefFailure(['&ts = [7]'], 'E1012:')
CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list')
CheckDefFailure(['&ts = "xx"'], 'E1012:')
CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string')
CheckDefFailure(['&path += 3'], 'E1012:')
CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
# test freeing ISN_STOREOPT
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
&ts = 8
call CheckDefFailure(['let s:var = 123'], 'E1101:')
call CheckDefFailure(['let s:var: number'], 'E1101:')
lines =<< trim END
let save_TI = &t_TI
&t_TI = ''
assert_equal('', &t_TI)
&t_TI = 'xxx'
assert_equal('xxx', &t_TI)
&t_TI = save_TI
END
CheckDefSuccess(lines)
CheckScriptSuccess(['vim9script'] + lines)
CheckDefFailure(['&t_TI = 123'], 'E1012:')
CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:')
CheckDefFailure(['let s:var = 123'], 'E1101:')
CheckDefFailure(['let s:var: number'], 'E1101:')
lines =<< trim END
vim9script

View File

@ -754,6 +754,12 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1471,
/**/
1470,
/**/
1469,
/**/
1468,
/**/