@@ -547,6 +547,22 @@ def test_match_case_with_false_guard():
547547 assert [(3 ,7 )] == g [br .BRANCH_NAME ]
548548
549549
550+ @pytest .mark .skipif (PYTHON_VERSION < (3 ,10 ), reason = "New in 3.10" )
551+ def test_match_case_with_guard_isnt_wildcard ():
552+ t = ast_parse ("""
553+ def fun(v):
554+ match v:
555+ case _ if v > 0:
556+ print("not default")
557+ """ )
558+
559+
560+ t = br .preinstrument (t )
561+ check_locations (t )
562+ code = compile (t , "foo" , "exec" )
563+ assert [(2 ,0 ), (2 ,4 )] == get_branches (code )
564+
565+
550566@pytest .mark .skipif (PYTHON_VERSION < (3 ,10 ), reason = "New in 3.10" )
551567def test_match_branch_to_exit ():
552568 t = ast_parse ("""
@@ -693,6 +709,39 @@ def test_branch_after_case_with_next():
693709 assert [(2 ,4 ), (4 ,9 )] == g [br .BRANCH_NAME ]
694710
695711
712+ @pytest .mark .skipif (PYTHON_VERSION < (3 ,10 ), reason = "New in 3.10" )
713+ def test_match_wildcard_in_match_or ():
714+ # Thanks to Ned Batchelder for this test case
715+ t = ast_parse (f"""
716+ def absurd(x):
717+ match x:
718+ case (3 | 99 | (999 | _)):
719+ print("default")
720+ absurd(5)
721+ """ )
722+
723+ t = br .preinstrument (t )
724+ check_locations (t )
725+ code = compile (t , "foo" , "exec" )
726+ assert [(2 ,4 )] == get_branches (code )
727+
728+
729+ @pytest .mark .skipif (PYTHON_VERSION < (3 ,10 ), reason = "New in 3.10" )
730+ def test_match_capture ():
731+ t = ast_parse (f"""
732+ def capture(x):
733+ match x:
734+ case y:
735+ print("default")
736+ capture(5)
737+ """ )
738+
739+ t = br .preinstrument (t )
740+ check_locations (t )
741+ code = compile (t , "foo" , "exec" )
742+ assert [(2 ,4 )] == get_branches (code )
743+
744+
696745@pytest .mark .parametrize ("star" , ['' , '*' ] if PYTHON_VERSION >= (3 ,11 ) else ['' ])
697746def test_try_except (star ):
698747 t = ast_parse (f"""
@@ -781,3 +830,4 @@ def foo(x):
781830 check_locations (t )
782831 code = compile (t , "foo" , "exec" )
783832 assert [(4 ,5 ), (4 ,10 ), (7 ,8 ), (7 ,13 ), (10 ,11 ), (10 ,13 )] == get_branches (code )
833+
0 commit comments