unlet g:instr
enddef
+" Disassemble the code generated for a has() function call
+def Test_disassemble_has_shortcircuit()
+ # true && false condition check
+ var lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('jumplist') && has('foobar')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''jumplist'') && has(''foobar'')\_s*' ..
+ 'return ''present''\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '0 PUSHS "missing"\_s*' ..
+ '1 RETURN', g:instr)
+
+ # false && true condition check
+ lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('foobar') && has('jumplist')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''foobar'') && has(''jumplist'')\_s*' ..
+ 'return ''present''\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '0 PUSHS "missing"\_s*' ..
+ '1 RETURN', g:instr)
+
+ # false && false condition check
+ lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('foobar') && has('foobaz')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''foobar'') && has(''foobaz'')\_s*' ..
+ 'return ''present''\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '0 PUSHS "missing"\_s*' ..
+ '1 RETURN', g:instr)
+
+ # true || false condition check
+ lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('jumplist') || has('foobar')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''jumplist'') || has(''foobar'')\_s*' ..
+ 'return ''present''\_s*' ..
+ '0 PUSHS "present"\_s*' ..
+ '1 RETURN\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '2 PUSHS "missing"\_s*' ..
+ '3 RETURN', g:instr)
+
+ # false || true condition check
+ lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('foobar') || has('jumplist')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''foobar'') || has(''jumplist'')\_s*' ..
+ 'return ''present''\_s*' ..
+ '0 PUSHS "present"\_s*' ..
+ '1 RETURN\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '2 PUSHS "missing"\_s*' ..
+ '3 RETURN', g:instr)
+
+ # false || false condition check
+ lines =<< trim END
+ vim9script
+ def Fn(): string
+ if has('foobar') || has('foobaz')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ g:instr = execute('disassemble Fn')
+ END
+ v9.CheckScriptSuccess(lines)
+ assert_match('<SNR>\d\+_Fn\_s*' ..
+ 'if has(''foobar'') || has(''foobaz'')\_s*' ..
+ 'return ''present''\_s*' ..
+ 'endif\_s*' ..
+ 'return ''missing''\_s*' ..
+ '0 PUSHS "missing"\_s*' ..
+ '1 RETURN', g:instr)
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
v9.CheckSourceSuccess(lines)
enddef
+" Test for using more than one has() check in a compound if condition.
+def Test_has_func_shortcircuit()
+ def Has_And1_Cond(): string
+ # true && false
+ if has('jumplist') && has('foobar')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('missing', Has_And1_Cond())
+
+ def Has_And2_Cond(): string
+ # false && true
+ if has('foobar') && has('jumplist')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('missing', Has_And2_Cond())
+
+ def Has_And3_Cond(): string
+ # false && false
+ if has('foobar') && has('foobaz')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('missing', Has_And3_Cond())
+
+ def Has_Or1_Cond(): string
+ # true || false
+ if has('jumplist') || has('foobar')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('present', Has_Or1_Cond())
+
+ def Has_Or2_Cond(): string
+ # false || true
+ if has('foobar') || has('jumplist')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('present', Has_Or2_Cond())
+
+ def Has_Or3_Cond(): string
+ # false || false
+ if has('foobar') || has('foobaz')
+ return 'present'
+ endif
+ return 'missing'
+ enddef
+ assert_equal('missing', Has_Or3_Cond())
+enddef
+
+" Test for using more than one len() function in a compound if condition.
+def Test_len_func_shortcircuit()
+ def Len_And1_Cond(): string
+ # true && false
+ if len('xxx') == 3 && len('yyy') == 2
+ return 'match'
+ endif
+ return 'nomatch'
+ enddef
+ assert_equal('nomatch', Len_And1_Cond())
+
+ def Len_And2_Cond(): string
+ # false && true
+ if len('xxx') == 2 && len('yyy') == 3
+ return 'match'
+ endif
+ return 'nomatch'
+ enddef
+ assert_equal('nomatch', Len_And2_Cond())
+
+ def Len_Or1_Cond(): string
+ # true || false
+ if len('xxx') == 3 || len('yyy') == 2
+ return 'match'
+ endif
+ return 'nomatch'
+ enddef
+ assert_equal('match', Len_Or1_Cond())
+
+ def Len_Or2_Cond(): string
+ # false || true
+ if len('xxx') == 2 || len('yyy') == 3
+ return 'match'
+ endif
+ return 'nomatch'
+ enddef
+ assert_equal('match', Len_Or2_Cond())
+enddef
+
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new