comparison src/testdir/test_vim9_expr.vim @ 28103:1615d305c71d v8.2.4576

patch 8.2.4576: Vim9: error for comparing with null can be annoying Commit: https://github.com/vim/vim/commit/056678184f679c2989b73bd48eda112f3c79a62f Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 15 20:21:33 2022 +0000 patch 8.2.4576: Vim9: error for comparing with null can be annoying Problem: Vim9: error for comparing with null can be annoying. Solution: Allow comparing anything with null. (closes https://github.com/vim/vim/issues/9948)
author Bram Moolenaar <Bram@vim.org>
date Tue, 15 Mar 2022 21:30:03 +0100
parents 4aa79224acd2
children 9ef1bbe6707e
comparison
equal deleted inserted replaced
28102:9aa6dfbd4698 28103:1615d305c71d
714 714
715 def Test_expr4_compare_null() 715 def Test_expr4_compare_null()
716 g:null_dict = test_null_dict() 716 g:null_dict = test_null_dict()
717 g:not_null_list = [] 717 g:not_null_list = []
718 var lines =<< trim END 718 var lines =<< trim END
719 assert_false(true == null)
720 assert_false(false == null)
721 assert_false(null == true)
722 assert_false(null == false)
723 assert_true(true != null)
724 assert_true(false != null)
725 assert_true(null != true)
726 assert_true(null != false)
727
728 assert_false(123 == null)
729 assert_false(0 == null)
730 assert_false(null == 123)
731 assert_false(null == 0)
732 assert_true(123 != null)
733 assert_true(0 != null)
734 assert_true(null != 123)
735 assert_true(null != 0)
736
737 if has('float')
738 assert_false(12.3 == null)
739 assert_false(0.0 == null)
740 assert_false(null == 12.3)
741 assert_false(null == 0.0)
742 assert_true(12.3 != null)
743 assert_true(0.0 != null)
744 assert_true(null != 12.3)
745 assert_true(null != 0.0)
746 endif
747
719 assert_true(test_null_blob() == v:null) 748 assert_true(test_null_blob() == v:null)
720 assert_true(null_blob == null) 749 assert_true(null_blob == null)
721 assert_true(v:null == test_null_blob()) 750 assert_true(v:null == test_null_blob())
722 assert_true(null == null_blob) 751 assert_true(null == null_blob)
723 assert_false(test_null_blob() != v:null) 752 assert_false(test_null_blob() != v:null)
816 lines =<< trim END 845 lines =<< trim END
817 var d: dict<func> = {f: null_function} 846 var d: dict<func> = {f: null_function}
818 assert_equal(null_function, d.f) 847 assert_equal(null_function, d.f)
819 END 848 END
820 v9.CheckDefAndScriptSuccess(lines) 849 v9.CheckDefAndScriptSuccess(lines)
821
822 v9.CheckDefAndScriptFailure(['echo 123 == v:null'], 'E1072: Cannot compare number with special')
823 v9.CheckDefAndScriptFailure(['echo v:null == 123'], 'E1072: Cannot compare special with number')
824 v9.CheckDefAndScriptFailure(['echo 123 != v:null'], 'E1072: Cannot compare number with special')
825 v9.CheckDefAndScriptFailure(['echo v:null != 123'], 'E1072: Cannot compare special with number')
826 v9.CheckDefAndScriptFailure(['echo true == v:null'], 'E1072: Cannot compare bool with special')
827 v9.CheckDefAndScriptFailure(['echo v:null == true'], 'E1072: Cannot compare special with bool')
828 v9.CheckDefAndScriptFailure(['echo true != v:null'], 'E1072: Cannot compare bool with special')
829 v9.CheckDefAndScriptFailure(['echo v:null != true'], 'E1072: Cannot compare special with bool')
830 v9.CheckDefAndScriptFailure(['echo false == v:null'], 'E1072: Cannot compare bool with special')
831 enddef 850 enddef
832 851
833 def Test_expr4_compare_none() 852 def Test_expr4_compare_none()
834 var lines =<< trim END 853 var lines =<< trim END
835 assert_false('' == v:none) 854 assert_false('' == v:none)