summaryrefslogtreecommitdiff
path: root/tests/test_parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-06-06 12:10:38 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-06-06 12:42:07 -0400
commit95c582fd8038a7158ff96baff4186f5fb601afd4 (patch)
treeb870edb23108bdd473df3781d65c74d547bc7a78 /tests/test_parser.py
parent734ee8760df75427753e54b4d8078cfa06484da3 (diff)
downloadpython-coveragepy-git-95c582fd8038a7158ff96baff4186f5fb601afd4.tar.gz
feat: add support for Python 3.10 match-case statements
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r--tests/test_parser.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 7fd87bba..1b4e8aca 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -394,6 +394,24 @@ class ParserMissingArcDescriptionTest(CoverageTest):
""")
assert parser.missing_arc_description(2, -3) == "line 3 didn't finish the lambda on line 3"
+ @pytest.mark.skipif(not env.PYBEHAVIOR.match_case, reason="Match-case is new in 3.10")
+ def test_match_case_with_default(self):
+ parser = self.parse_text("""\
+ for command in ["huh", "go home", "go n"]:
+ match command.split():
+ case ["go", direction] if direction in "nesw":
+ match = f"go: {direction}"
+ case ["go", _]:
+ match = "no go"
+ print(match)
+ """)
+ assert parser.missing_arc_description(3, 4) == (
+ "line 3 didn't jump to line 4, because the pattern on line 3 never matched"
+ )
+ assert parser.missing_arc_description(3, 5) == (
+ "line 3 didn't jump to line 5, because the pattern on line 3 always matched"
+ )
+
class ParserFileTest(CoverageTest):
"""Tests for coverage.py's code parsing from files."""