0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.0224: compiling :elseif not tested yet

Problem:    compiling :elseif not tested yet.
Solution:   Add test for :elseif.  Fix generating jumps.
This commit is contained in:
Bram Moolenaar
2020-02-06 20:39:45 +01:00
parent 5cab73f8cc
commit 158906cffc
4 changed files with 79 additions and 26 deletions

View File

@@ -216,5 +216,67 @@ def Test_disassembleCall()
\, res) \, res)
enddef enddef
def HasEval()
if has("eval")
echo "yes"
else
echo "no"
endif
enddef
def HasNothing()
if has("nothing")
echo "yes"
else
echo "no"
endif
enddef
def HasSomething()
if has("nothing")
echo "nothing"
elseif has("something")
echo "something"
elseif has("eval")
echo "eval"
elseif has("less")
echo "less"
endif
enddef
def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
assert_match('HasEval.*'
\ .. 'if has("eval").*'
\ .. ' PUSHS "yes".*'
\, instr)
assert_notmatch('JUMP', instr)
assert_equal("\nno", execute('call HasNothing()'))
instr = execute('disassemble HasNothing')
assert_match('HasNothing.*'
\ .. 'if has("nothing").*'
\ .. 'else.*'
\ .. ' PUSHS "no".*'
\, instr)
assert_notmatch('PUSHS "yes"', instr)
assert_notmatch('JUMP', instr)
assert_equal("\neval", execute('call HasSomething()'))
instr = execute('disassemble HasSomething')
assert_match('HasSomething.*'
\ .. 'if has("nothing").*'
\ .. 'elseif has("something").*'
\ .. 'elseif has("eval").*'
\ .. ' PUSHS "eval".*'
\ .. 'elseif has("less").*'
\, instr)
assert_notmatch('PUSHS "nothing"', instr)
assert_notmatch('PUSHS "something"', instr)
assert_notmatch('PUSHS "less"', instr)
assert_notmatch('JUMP', instr)
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -459,34 +459,22 @@ def do_something():
EOF EOF
endfunc endfunc
def HasEval() def IfElse(what: number): string
if has('eval') let res = ''
echo 'yes' if what == 1
res = "one"
elseif what == 2
res = "two"
else else
echo 'no' res = "three"
endif endif
return res
enddef enddef
def HasNothing() def Test_if_elseif_else()
if has('nothing') assert_equal('one', IfElse(1))
echo 'yes' assert_equal('two', IfElse(2))
else assert_equal('three', IfElse(3))
echo 'no'
endif
enddef
def Test_compile_const_expr()
assert_equal("\nyes", execute('call HasEval()'))
let instr = execute('disassemble HasEval')
assert_match('PUSHS "yes"', instr)
assert_notmatch('PUSHS "no"', instr)
assert_notmatch('JUMP', instr)
assert_equal("\nno", execute('call HasNothing()'))
instr = execute('disassemble HasNothing')
assert_notmatch('PUSHS "yes"', instr)
assert_match('PUSHS "no"', instr)
assert_notmatch('JUMP', instr)
enddef enddef

View File

@@ -742,6 +742,8 @@ 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 */
/**/
224,
/**/ /**/
223, 223,
/**/ /**/

View File

@@ -3891,7 +3891,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
} }
cctx->ctx_locals.ga_len = scope->se_local_count; cctx->ctx_locals.ga_len = scope->se_local_count;
if (cctx->ctx_skip != TRUE) if (cctx->ctx_skip == MAYBE)
{ {
if (compile_jump_to_end(&scope->se_u.se_if.is_end_label, if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
JUMP_ALWAYS, cctx) == FAIL) JUMP_ALWAYS, cctx) == FAIL)
@@ -3947,13 +3947,14 @@ compile_else(char_u *arg, cctx_T *cctx)
return NULL; return NULL;
} }
if (cctx->ctx_skip != TRUE) if (cctx->ctx_skip == MAYBE)
{ {
if (scope->se_u.se_if.is_if_label >= 0) if (scope->se_u.se_if.is_if_label >= 0)
{ {
// previous "if" or "elseif" jumps here // previous "if" or "elseif" jumps here
isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label; isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
isn->isn_arg.jump.jump_where = instr->ga_len; isn->isn_arg.jump.jump_where = instr->ga_len;
scope->se_u.se_if.is_if_label = -1;
} }
} }