summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_phystokens.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py
index 82b887e6..3c214c63 100644
--- a/tests/test_phystokens.py
+++ b/tests/test_phystokens.py
@@ -103,6 +103,42 @@ class PhysTokensTest(CoverageTest):
self.check_file_tokenization(stress)
+@pytest.mark.skipif(not env.PYBEHAVIOR.soft_keywords, reason="Soft keywords are new in Python 3.10")
+class SoftKeywordTest(CoverageTest):
+ """Tests the tokenizer handling soft keywords."""
+
+ run_in_temp_dir = False
+
+ def test_soft_keywords(self):
+ source = textwrap.dedent("""\
+ match re.match(something):
+ case ["what"]:
+ match = case("hello")
+ case [_]:
+ match("hello")
+ match another.thing:
+ case 1:
+ pass
+
+ class case(): pass
+ def match():
+ global case
+ """)
+ tokens = list(source_token_lines(source))
+ assert tokens[0][0] == ("key", "match")
+ assert tokens[0][4] == ("nam", "match")
+ assert tokens[1][1] == ("key", "case")
+ assert tokens[2][1] == ("nam", "match")
+ assert tokens[2][5] == ("nam", "case")
+ assert tokens[3][1] == ("key", "case")
+ assert tokens[4][1] == ("nam", "match")
+ assert tokens[5][1] == ("key", "match")
+ assert tokens[6][1] == ("key", "case")
+ assert tokens[9][2] == ("nam", "case")
+ assert tokens[10][2] == ("nam", "match")
+ assert tokens[11][3] == ("nam", "case")
+
+
# The default encoding is different in Python 2 and Python 3.
DEF_ENCODING = "utf-8"