Compare commits

...

6 Commits

Author SHA1 Message Date
Yegappan Lakshmanan
5958549760 patch 8.2.2979: not all options code is covered by tests
Problem:    Not all options code is covered by tests.
Solution:   Add more tests for options. (Yegappan Lakshmanan, closes #8369)
2021-06-12 13:46:41 +02:00
Bram Moolenaar
744aecf877 patch 8.2.2978: warning for uninitialized variable
Problem:    Warning for uninitialized variable.
Solution:   Set return value to FAIL.
2021-06-12 12:33:48 +02:00
Bram Moolenaar
22db0d549f patch 8.2.2977: crash when using a null function reference
Problem:    Crash when using a null function reference. (Naohiro Ono)
Solution:   Check for an invalid function name. (closes #8367)
2021-06-12 12:16:55 +02:00
Bram Moolenaar
8de901e1f1 patch 8.2.2976: build failure without the +eval feature
Problem:    Build failure without the +eval feature.
Solution:   Add #ifdefs.
2021-06-11 22:21:24 +02:00
Bram Moolenaar
f0a4069e3d patch 8.2.2975: Vim9: can only use an autoload function name as a string
Problem:    Vim9: can only use an autoload function name as a string.
Solution:   Load the autoload script when encountered. (closes #8124)
2021-06-11 22:05:47 +02:00
Bram Moolenaar
4f13527598 patch 8.2.2974: Greek spell checking uses wrong case folding
Problem:    Greek spell checking uses wrong case folding.
Solution:   Fold capital sigma depending on whether it is at the end of a
            word or not. (closes #299)
2021-06-11 19:07:40 +02:00
19 changed files with 206 additions and 18 deletions

View File

@@ -425,3 +425,5 @@ EXTERN char e_nr_arguments_too_few[]
INIT(= N_("E1190: %d arguments too few")); INIT(= N_("E1190: %d arguments too few"));
EXTERN char e_call_to_function_that_failed_to_compile_str[] EXTERN char e_call_to_function_that_failed_to_compile_str[]
INIT(= N_("E1191: Call to function that failed to compile: %s")); INIT(= N_("E1191: Call to function that failed to compile: %s"));
EXTERN char e_empty_function_name[]
INIT(= N_("E1192: Empty function name"));

View File

@@ -3772,7 +3772,15 @@ call_func_rettv(
s = partial_name(pt); s = partial_name(pt);
} }
else else
{
s = functv.vval.v_string; s = functv.vval.v_string;
if (s == NULL || *s == NUL)
{
emsg(_(e_empty_function_name));
ret = FAIL;
goto theend;
}
}
} }
else else
s = (char_u *)""; s = (char_u *)"";
@@ -3786,6 +3794,7 @@ call_func_rettv(
funcexe.basetv = basetv; funcexe.basetv = basetv;
ret = get_func_tv(s, -1, rettv, arg, evalarg, &funcexe); ret = get_func_tv(s, -1, rettv, arg, evalarg, &funcexe);
theend:
// Clear the funcref afterwards, so that deleting it while // Clear the funcref afterwards, so that deleting it while
// evaluating the arguments is possible (see test55). // evaluating the arguments is possible (see test55).
if (evaluate) if (evaluate)

View File

@@ -2921,8 +2921,9 @@ find_var_ht(char_u *name, char_u **varname)
if (ht != NULL) if (ht != NULL)
return ht; // local variable return ht; // local variable
// in Vim9 script items at the script level are script-local // In Vim9 script items at the script level are script-local, except
if (in_vim9script()) // for autoload names.
if (in_vim9script() && vim_strchr(name, AUTOLOAD_CHAR) == NULL)
{ {
ht = get_script_local_ht(); ht = get_script_local_ht();
if (ht != NULL) if (ht != NULL)

View File

@@ -27,7 +27,7 @@ void clear_spell_chartab(spelltab_T *sp);
void init_spell_chartab(void); void init_spell_chartab(void);
int spell_iswordp(char_u *p, win_T *wp); int spell_iswordp(char_u *p, win_T *wp);
int spell_iswordp_nmw(char_u *p, win_T *wp); int spell_iswordp_nmw(char_u *p, win_T *wp);
int spell_casefold(char_u *str, int len, char_u *buf, int buflen); int spell_casefold(win_T *wp, char_u *str, int len, char_u *buf, int buflen);
int check_need_cap(linenr_T lnum, colnr_T col); int check_need_cap(linenr_T lnum, colnr_T col);
void ex_spellrepall(exarg_T *eap); void ex_spellrepall(exarg_T *eap);
void onecap_copy(char_u *word, char_u *wcopy, int upper); void onecap_copy(char_u *word, char_u *wcopy, int upper);

View File

@@ -1119,6 +1119,7 @@ do_source(
int save_debug_break_level = debug_break_level; int save_debug_break_level = debug_break_level;
int sid; int sid;
scriptitem_T *si = NULL; scriptitem_T *si = NULL;
int save_estack_compiling = estack_compiling;
#endif #endif
#ifdef STARTUPTIME #ifdef STARTUPTIME
struct timeval tv_rel; struct timeval tv_rel;
@@ -1142,8 +1143,9 @@ do_source(
smsg(_("Cannot source a directory: \"%s\""), fname); smsg(_("Cannot source a directory: \"%s\""), fname);
goto theend; goto theend;
} }
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
estack_compiling = FALSE;
// See if we loaded this script before. // See if we loaded this script before.
for (sid = script_items.ga_len; sid > 0; --sid) for (sid = script_items.ga_len; sid > 0; --sid)
{ {
@@ -1508,6 +1510,9 @@ almosttheend:
theend: theend:
vim_free(fname_exp); vim_free(fname_exp);
#ifdef FEAT_EVAL
estack_compiling = save_estack_compiling;
#endif
return retval; return retval;
} }

View File

@@ -249,7 +249,7 @@ spell_check(
if (*mi.mi_fend != NUL) if (*mi.mi_fend != NUL)
MB_PTR_ADV(mi.mi_fend); MB_PTR_ADV(mi.mi_fend);
(void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, (void)spell_casefold(wp, ptr, (int)(mi.mi_fend - ptr), mi.mi_fword,
MAXWLEN + 1); MAXWLEN + 1);
mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); mi.mi_fwordlen = (int)STRLEN(mi.mi_fword);
@@ -736,7 +736,8 @@ find_word(matchinf_T *mip, int mode)
{ {
// "fword" is only needed for checking syllables. // "fword" is only needed for checking syllables.
if (ptr == mip->mi_word) if (ptr == mip->mi_word)
(void)spell_casefold(ptr, wlen, fword, MAXWLEN); (void)spell_casefold(mip->mi_win,
ptr, wlen, fword, MAXWLEN);
else else
vim_strncpy(fword, ptr, endlen[endidxcnt]); vim_strncpy(fword, ptr, endlen[endidxcnt]);
} }
@@ -1213,7 +1214,7 @@ fold_more(matchinf_T *mip)
if (*mip->mi_fend != NUL) if (*mip->mi_fend != NUL)
MB_PTR_ADV(mip->mi_fend); MB_PTR_ADV(mip->mi_fend);
(void)spell_casefold(p, (int)(mip->mi_fend - p), (void)spell_casefold(mip->mi_win, p, (int)(mip->mi_fend - p),
mip->mi_fword + mip->mi_fwordlen, mip->mi_fword + mip->mi_fwordlen,
MAXWLEN - mip->mi_fwordlen); MAXWLEN - mip->mi_fwordlen);
flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen); flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen);
@@ -2737,6 +2738,7 @@ spell_iswordp_w(int *p, win_T *wp)
*/ */
int int
spell_casefold( spell_casefold(
win_T *wp,
char_u *str, char_u *str,
int len, int len,
char_u *buf, char_u *buf,
@@ -2765,7 +2767,21 @@ spell_casefold(
return FAIL; return FAIL;
} }
c = mb_cptr2char_adv(&p); c = mb_cptr2char_adv(&p);
outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi);
// Exception: greek capital sigma 0x03A3 folds to 0x03C3, except
// when it is the last character in a word, then it folds to
// 0x03C2.
if (c == 0x03a3 || c == 0x03c2)
{
if (p == str + len || !spell_iswordp(p, wp))
c = 0x03c2;
else
c = 0x03c3;
}
else
c = SPELL_TOFOLD(c);
outi += mb_char2bytes(c, buf + outi);
} }
buf[outi] = NUL; buf[outi] = NUL;
} }
@@ -3097,7 +3113,8 @@ spell_soundfold(
word = inword; word = inword;
else else
{ {
(void)spell_casefold(inword, (int)STRLEN(inword), fword, MAXWLEN); (void)spell_casefold(curwin,
inword, (int)STRLEN(inword), fword, MAXWLEN);
word = fword; word = fword;
} }

View File

@@ -3429,9 +3429,9 @@ add_fromto(
if (ga_grow(gap, 1) == OK) if (ga_grow(gap, 1) == OK)
{ {
ftp = ((fromto_T *)gap->ga_data) + gap->ga_len; ftp = ((fromto_T *)gap->ga_data) + gap->ga_len;
(void)spell_casefold(from, (int)STRLEN(from), word, MAXWLEN); (void)spell_casefold(curwin, from, (int)STRLEN(from), word, MAXWLEN);
ftp->ft_from = getroom_save(spin, word); ftp->ft_from = getroom_save(spin, word);
(void)spell_casefold(to, (int)STRLEN(to), word, MAXWLEN); (void)spell_casefold(curwin, to, (int)STRLEN(to), word, MAXWLEN);
ftp->ft_to = getroom_save(spin, word); ftp->ft_to = getroom_save(spin, word);
++gap->ga_len; ++gap->ga_len;
} }
@@ -4391,7 +4391,7 @@ store_word(
int res = OK; int res = OK;
char_u *p; char_u *p;
(void)spell_casefold(word, len, foldword, MAXWLEN); (void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
for (p = pfxlist; res == OK; ++p) for (p = pfxlist; res == OK; ++p)
{ {
if (!need_affix || (p != NULL && *p != NUL)) if (!need_affix || (p != NULL && *p != NUL))

View File

@@ -791,7 +791,7 @@ spell_find_suggest(
if (su->su_badlen >= MAXWLEN) if (su->su_badlen >= MAXWLEN)
su->su_badlen = MAXWLEN - 1; // just in case su->su_badlen = MAXWLEN - 1; // just in case
vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen); vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen);
(void)spell_casefold(su->su_badptr, su->su_badlen, (void)spell_casefold(curwin, su->su_badptr, su->su_badlen,
su->su_fbadword, MAXWLEN); su->su_fbadword, MAXWLEN);
// TODO: make this work if the case-folded text is longer than the original // TODO: make this work if the case-folded text is longer than the original
// text. Currently an illegal byte causes wrong pointer computations. // text. Currently an illegal byte causes wrong pointer computations.
@@ -1176,7 +1176,7 @@ suggest_try_change(suginfo_T *su)
STRCPY(fword, su->su_fbadword); STRCPY(fword, su->su_fbadword);
n = (int)STRLEN(fword); n = (int)STRLEN(fword);
p = su->su_badptr + su->su_badlen; p = su->su_badptr + su->su_badlen;
(void)spell_casefold(p, (int)STRLEN(p), fword + n, MAXWLEN - n); (void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n);
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
{ {
@@ -3005,7 +3005,8 @@ stp_sal_score(
else else
{ {
// soundfold the bad word with more characters following // soundfold the bad word with more characters following
(void)spell_casefold(su->su_badptr, stp->st_orglen, fword, MAXWLEN); (void)spell_casefold(curwin,
su->su_badptr, stp->st_orglen, fword, MAXWLEN);
// When joining two words the sound often changes a lot. E.g., "t he" // When joining two words the sound often changes a lot. E.g., "t he"
// sounds like "t h" while "the" sounds like "@". Avoid that by // sounds like "t h" while "the" sounds like "@". Avoid that by

View File

@@ -1871,4 +1871,28 @@ func Test_read_invalid()
set encoding=utf-8 set encoding=utf-8
endfunc endfunc
" Test for the 'revins' option
func Test_edit_revins()
CheckFeature rightleft
new
set revins
exe "normal! ione\ttwo three"
call assert_equal("eerht owt\teno", getline(1))
call setline(1, "one\ttwo three")
normal! gg$bi a
call assert_equal("one\ttwo a three", getline(1))
exe "normal! $bi\<BS>\<BS>"
call assert_equal("one\ttwo a ree", getline(1))
exe "normal! 0wi\<C-W>"
call assert_equal("one\t a ree", getline(1))
exe "normal! 0wi\<C-U>"
call assert_equal("one\t ", getline(1))
" newline in insert mode starts at the end of the line
call setline(1, 'one two three')
exe "normal! wi\nfour"
call assert_equal(['one two three', 'ruof'], getline(1, '$'))
set revins&
bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -593,6 +593,12 @@ func Sandbox_tests()
if has('unix') if has('unix')
call assert_fails('cd `pwd`', 'E48:') call assert_fails('cd `pwd`', 'E48:')
endif endif
" some options cannot be changed in a sandbox
call assert_fails('set exrc', 'E48:')
call assert_fails('set cdpath', 'E48:')
if has('xim')
call assert_fails('set imstyle', 'E48:')
endif
endfunc endfunc
func Test_sandbox() func Test_sandbox()

View File

@@ -2174,9 +2174,11 @@ func Test_call()
call assert_fails("call call('Mylen', [], 0)", 'E715:') call assert_fails("call call('Mylen', [], 0)", 'E715:')
call assert_fails('call foo', 'E107:') call assert_fails('call foo', 'E107:')
" This once caused a crash. " These once caused a crash.
call call(test_null_function(), []) call call(test_null_function(), [])
call call(test_null_partial(), []) call call(test_null_partial(), [])
call assert_fails('call test_null_function()()', 'E1192:')
call assert_fails('call test_null_partial()()', 'E117:')
endfunc endfunc
func Test_char2nr() func Test_char2nr()

View File

@@ -123,5 +123,15 @@ func Test_helptag_cmd_readonly()
call delete('Xdir', 'rf') call delete('Xdir', 'rf')
endfunc endfunc
" Test for setting the 'helpheight' option in the help window
func Test_help_window_height()
let &cmdheight = &lines - 24
set helpheight=10
help
set helpheight=14
call assert_equal(14, winheight(0))
set helpheight& cmdheight=1
close
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1019,6 +1019,19 @@ func Test_mkvimrc()
endfor endfor
call s:ClearMappings() call s:ClearMappings()
" the 'pastetoggle', 'wildchar' and 'wildcharm' option values should be
" stored as key names in the vimrc file
set pastetoggle=<F5>
set wildchar=<F6>
set wildcharm=<F7>
call assert_fails('mkvimrc Xtestvimrc')
mkvimrc! Xtestvimrc
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=<F5>'))
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildchar=<F6>'))
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildcharm=<F7>'))
set pastetoggle& wildchar& wildcharm&
call delete('Xtestvimrc') call delete('Xtestvimrc')
endfunc endfunc

View File

@@ -434,6 +434,7 @@ func Test_set_errors()
set nomodifiable set nomodifiable
call assert_fails('set fileencoding=latin1', 'E21:') call assert_fails('set fileencoding=latin1', 'E21:')
set modifiable& set modifiable&
call assert_fails('set t_#-&', 'E522:')
endfunc endfunc
func CheckWasSet(name) func CheckWasSet(name)
@@ -946,6 +947,18 @@ func Test_opt_local_to_global()
call assert_equal('gnewprg', &l:equalprg) call assert_equal('gnewprg', &l:equalprg)
call assert_equal('gnewprg', &equalprg) call assert_equal('gnewprg', &equalprg)
set equalprg& set equalprg&
" Test for setting the global/local value of a boolean option
setglobal autoread
setlocal noautoread
call assert_false(&autoread)
set autoread<
call assert_true(&autoread)
setglobal noautoread
setlocal autoread
setlocal autoread<
call assert_false(&autoread)
set autoread&
endfunc endfunc
" Test for incrementing, decrementing and multiplying a number option value " Test for incrementing, decrementing and multiplying a number option value
@@ -1121,4 +1134,22 @@ func Test_VIM_POSIX()
call setenv('VIM_POSIX', saved_VIM_POSIX) call setenv('VIM_POSIX', saved_VIM_POSIX)
endfunc endfunc
" Test for setting an option to a Vi or Vim default
func Test_opt_default()
set formatoptions&vi
call assert_equal('vt', &formatoptions)
set formatoptions&vim
call assert_equal('tcq', &formatoptions)
endfunc
" Test for the 'cmdheight' option
func Test_cmdheight()
%bw!
let ht = &lines
set cmdheight=9999
call assert_equal(1, winheight(0))
call assert_equal(ht - 1, &cmdheight)
set cmdheight&
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -419,4 +419,17 @@ func Test_varsofttabstop()
close! close!
endfunc endfunc
" Setting 'shiftwidth' to a negative value, should set it to either the value
" of 'tabstop' (if 'vartabstop' is not set) or to the first value in
" 'vartabstop'
func Test_shiftwidth_vartabstop()
setlocal tabstop=7 vartabstop=
call assert_fails('set shiftwidth=-1', 'E487:')
call assert_equal(7, &shiftwidth)
setlocal tabstop=7 vartabstop=5,7,10
call assert_fails('set shiftwidth=-1', 'E487:')
call assert_equal(5, &shiftwidth)
setlocal shiftwidth& vartabstop& tabstop&
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -114,6 +114,34 @@ def Test_autoload_name_mismatch()
delete(dir, 'rf') delete(dir, 'rf')
enddef enddef
def Test_autoload_names()
var dir = 'Xdir/autoload'
mkdir(dir, 'p')
var lines =<< trim END
func foobar#function()
return 'yes'
endfunc
let foobar#var = 'no'
END
writefile(lines, dir .. '/foobar.vim')
var save_rtp = &rtp
exe 'set rtp=' .. getcwd() .. '/Xdir'
lines =<< trim END
assert_equal('yes', foobar#function())
var Function = foobar#function
assert_equal('yes', Function())
assert_equal('no', foobar#var)
END
CheckDefAndScriptSuccess(lines)
&rtp = save_rtp
delete(dir, 'rf')
enddef
def CallRecursive(n: number): number def CallRecursive(n: number): number
return CallRecursive(n + 1) return CallRecursive(n + 1)
enddef enddef

View File

@@ -397,7 +397,15 @@ func Test_window_width()
call assert_inrange(ww1, ww1 + 1, ww2) call assert_inrange(ww1, ww1 + 1, ww2)
call assert_inrange(ww3, ww3 + 1, ww2) call assert_inrange(ww3, ww3 + 1, ww2)
bw Xa Xb Xc " when the current window width is less than the new 'winwidth', the current
" window width should be increased.
enew | only
split
10vnew
set winwidth=15
call assert_equal(15, winwidth(0))
%bw!
endfunc endfunc
func Test_equalalways_on_close() func Test_equalalways_on_close()

View File

@@ -750,6 +750,18 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2979,
/**/
2978,
/**/
2977,
/**/
2976,
/**/
2975,
/**/
2974,
/**/ /**/
2973, 2973,
/**/ /**/

View File

@@ -3084,7 +3084,13 @@ compile_load(
if (name == NULL) if (name == NULL)
return FAIL; return FAIL;
if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) == OK) if (vim_strchr(name, AUTOLOAD_CHAR) != NULL)
{
script_autoload(name, FALSE);
res = generate_LOAD(cctx, ISN_LOADAUTO, 0, name, &t_any);
}
else if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx)
== OK)
{ {
if (gen_load_outer == 0) if (gen_load_outer == 0)
gen_load = TRUE; gen_load = TRUE;