@@ -722,28 +722,56 @@ def test_negation_literal_or_assign(self, match_cfg):
722722 assert cppcheckdata .match (bit_or .previous , '%var% !!|=' )
723723 assert cppcheckdata .match (find_token (match_cfg , '=' ).previous , '%var% !!|=' )
724724
725+ def test_negation_literal_bitwise_or (self , match_cfg ):
726+ bit_or = find_token (match_cfg , '|' )
727+ assert not cppcheckdata .match (bit_or .previous , '%var% !!|' )
728+ assert cppcheckdata .match (find_token (match_cfg , '||' ).previous , '%var% !!|' )
729+ assert cppcheckdata .match (find_token (match_cfg , '|=' ).previous , '%var% !!|' )
730+
731+ def test_negation_literal_logical_or (self , match_cfg ):
732+ log_or = find_token (match_cfg , '||' )
733+ assert not cppcheckdata .match (log_or .previous , '%var% !!||' )
734+ assert cppcheckdata .match (find_token (match_cfg , '|' ).previous , '%var% !!||' )
735+ assert cppcheckdata .match (find_token (match_cfg , '|=' ).previous , '%var% !!||' )
736+
725737 def test_negation_alternatives (self , match_cfg ):
726- # '!!a|b' is "not a, or b", as in the C++ Token::Match
738+ # as in the C++ Token::Match, the word after '!!' is not split into
739+ # alternatives: '!!a|b' is "not the token a|b"
727740 struct_tok = find_token (match_cfg , 'struct' )
728- assert not cppcheckdata .match (struct_tok , 'struct !!Point|Foo' )
741+ assert cppcheckdata .match (struct_tok , 'struct !!Point|Foo' )
729742 assert cppcheckdata .match (struct_tok , 'struct !!Foo|Point' )
730743 assert cppcheckdata .match (struct_tok , 'struct !!Foo|Bar' )
744+ assert cppcheckdata .match (struct_tok , 'struct !!%name%|;' )
731745
732746 def test_find_forward_alternatives (self , match_cfg ):
733- # '**a|b' is "a somewhere ahead, or b here"
747+ # '**a|b' searches ahead for the first token that is a or b
734748 calc_def = find_token (match_cfg , 'calc' )
735749 res = cppcheckdata .match (calc_def , 'calc **{|nosuchtoken' )
736750 assert res
737751 assert res .end .str == '{'
738- res = cppcheckdata .match (calc_def , 'calc **nosuchtoken|(' )
752+ res = cppcheckdata .match (calc_def , 'calc **nosuchtoken|{' )
753+ assert res
754+ assert res .end .str == '{'
755+ res = cppcheckdata .match (calc_def , 'calc **{|(' )
739756 assert res
740757 assert res .end .str == '('
741- assert not cppcheckdata .match (calc_def , 'calc **nosuchtoken|{' )
742- # but a literal word is searched for as a whole
743- arr_decl = find_token (match_cfg , 'arr' )
744- res = cppcheckdata .match (arr_decl , 'arr **|=' )
758+ res = cppcheckdata .match (calc_def , 'calc **%op%|{' )
745759 assert res
746- assert res .end .str == '|='
760+ assert res .end .str == '{'
761+ assert not cppcheckdata .match (calc_def , 'calc **nosuchtoken|nosuchtoken2' )
762+
763+ def test_find_forward_literal_or_operators (self , match_cfg ):
764+ # '**|', '**||' and '**|=' search for the operator as a whole
765+ bit_or_decl = find_token (match_cfg , 'bit_or' )
766+ for op in ('|' , '||' , '|=' ):
767+ res = cppcheckdata .match (bit_or_decl , 'bit_or **' + op )
768+ assert res
769+ assert res .end .str == op
770+ # past the last '|' and '||' only the '|=' is left to find
771+ arr_decl = find_token (match_cfg , 'arr' )
772+ assert not cppcheckdata .match (arr_decl , 'arr **|' )
773+ assert not cppcheckdata .match (arr_decl , 'arr **||' )
774+ assert cppcheckdata .match (arr_decl , 'arr **|=' )
747775
748776 @pytest .mark .xfail (strict = False ,
749777 reason = 'in the C++ Token::Match a negation also matches when there is no token, '
0 commit comments