comparison src/testdir/test_vim9_disassemble.vim @ 22842:f2fbbb72ff28 v8.2.1968

patch 8.2.1968: Vim9: has() assumes a feature does not change dynamically Commit: https://github.com/vim/vim/commit/8cebd43e9774d2624af43ee5b86939886f2ba490 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Nov 8 12:49:47 2020 +0100 patch 8.2.1968: Vim9: has() assumes a feature does not change dynamically Problem: Vim9: has() assumes a feature does not change dynamically. Solution: Check whether a feature may change dynamically. (closes https://github.com/vim/vim/issues/7265)
author Bram Moolenaar <Bram@vim.org>
date Sun, 08 Nov 2020 13:00:04 +0100
parents 8a5369f5f2b4
children 53acb89ec9f2
comparison
equal deleted inserted replaced
22841:079dd4d56017 22842:f2fbbb72ff28
627 elseif has("less") 627 elseif has("less")
628 echo "less" 628 echo "less"
629 endif 629 endif
630 enddef 630 enddef
631 631
632 def HasGuiRunning()
633 if has("gui_running")
634 echo "yes"
635 else
636 echo "no"
637 endif
638 enddef
639
632 def Test_disassemble_const_expr() 640 def Test_disassemble_const_expr()
633 assert_equal("\nyes", execute('HasEval()')) 641 assert_equal("\nyes", execute('HasEval()'))
634 var instr = execute('disassemble HasEval') 642 var instr = execute('disassemble HasEval')
635 assert_match('HasEval\_s*' .. 643 assert_match('HasEval\_s*' ..
636 'if has("eval")\_s*' .. 644 'if has("eval")\_s*' ..
674 instr) 682 instr)
675 assert_notmatch('PUSHS "nothing"', instr) 683 assert_notmatch('PUSHS "nothing"', instr)
676 assert_notmatch('PUSHS "something"', instr) 684 assert_notmatch('PUSHS "something"', instr)
677 assert_notmatch('PUSHS "less"', instr) 685 assert_notmatch('PUSHS "less"', instr)
678 assert_notmatch('JUMP', instr) 686 assert_notmatch('JUMP', instr)
687
688 var result: string
689 var instr_expected: string
690 if has('gui')
691 if has('gui_running')
692 # GUI already running, always returns "yes"
693 result = "\nyes"
694 instr_expected = 'HasGuiRunning.*' ..
695 'if has("gui_running")\_s*' ..
696 ' echo "yes"\_s*' ..
697 '\d PUSHS "yes"\_s*' ..
698 '\d ECHO 1\_s*' ..
699 'else\_s*' ..
700 ' echo "no"\_s*' ..
701 'endif'
702 else
703 result = "\nno"
704 if has('unix')
705 # GUI not running but can start later, call has()
706 instr_expected = 'HasGuiRunning.*' ..
707 'if has("gui_running")\_s*' ..
708 '\d PUSHS "gui_running"\_s*' ..
709 '\d BCALL has(argc 1)\_s*' ..
710 '\d JUMP_IF_FALSE -> \d\_s*' ..
711 ' echo "yes"\_s*' ..
712 '\d PUSHS "yes"\_s*' ..
713 '\d ECHO 1\_s*' ..
714 'else\_s*' ..
715 '\d JUMP -> \d\_s*' ..
716 ' echo "no"\_s*' ..
717 '\d PUSHS "no"\_s*' ..
718 '\d ECHO 1\_s*' ..
719 'endif'
720 else
721 # GUI not running, always return "no"
722 instr_expected = 'HasGuiRunning.*' ..
723 'if has("gui_running")\_s*' ..
724 ' echo "yes"\_s*' ..
725 'else\_s*' ..
726 ' echo "no"\_s*' ..
727 '\d PUSHS "no"\_s*' ..
728 '\d ECHO 1\_s*' ..
729 'endif'
730 endif
731 endif
732 else
733 # GUI not supported, always return "no"
734 result = "\nno"
735 instr_expected = 'HasGuiRunning.*' ..
736 'if has("gui_running")\_s*' ..
737 ' echo "yes"\_s*' ..
738 'else\_s*' ..
739 ' echo "no"\_s*' ..
740 '\d PUSHS "no"\_s*' ..
741 '\d ECHO 1\_s*' ..
742 'endif'
743 endif
744
745 assert_equal(result, execute('HasGuiRunning()'))
746 instr = execute('disassemble HasGuiRunning')
747 assert_match(instr_expected, instr)
679 enddef 748 enddef
680 749
681 def ReturnInIf(): string 750 def ReturnInIf(): string
682 if g:cond 751 if g:cond
683 return "yes" 752 return "yes"