]> git.madduck.net Git - etc/vim.git/blob - tests/data/cases/pattern_matching_generic.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix cache versioning when BLACK_CACHE_DIR is set (#3937)
[etc/vim.git] / tests / data / cases / pattern_matching_generic.py
1 # flags: --minimum-version=3.10
2 re.match()
3 match = a
4 with match() as match:
5     match = f"{match}"
6
7 re.match()
8 match = a
9 with match() as match:
10     match = f"{match}"
11
12
13 def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
14     if not target_versions:
15         # No target_version specified, so try all grammars.
16         return [
17             # Python 3.7+
18             pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords,
19             # Python 3.0-3.6
20             pygram.python_grammar_no_print_statement_no_exec_statement,
21             # Python 2.7 with future print_function import
22             pygram.python_grammar_no_print_statement,
23             # Python 2.7
24             pygram.python_grammar,
25         ]
26
27     match match:
28         case case:
29             match match:
30                 case case:
31                     pass
32
33     if all(version.is_python2() for version in target_versions):
34         # Python 2-only code, so try Python 2 grammars.
35         return [
36             # Python 2.7 with future print_function import
37             pygram.python_grammar_no_print_statement,
38             # Python 2.7
39             pygram.python_grammar,
40         ]
41
42     re.match()
43     match = a
44     with match() as match:
45         match = f"{match}"
46
47     def test_patma_139(self):
48         x = False
49         match x:
50             case bool(z):
51                 y = 0
52         self.assertIs(x, False)
53         self.assertEqual(y, 0)
54         self.assertIs(z, x)
55
56     # Python 3-compatible code, so only try Python 3 grammar.
57     grammars = []
58     if supports_feature(target_versions, Feature.PATTERN_MATCHING):
59         # Python 3.10+
60         grammars.append(pygram.python_grammar_soft_keywords)
61     # If we have to parse both, try to parse async as a keyword first
62     if not supports_feature(
63         target_versions, Feature.ASYNC_IDENTIFIERS
64     ) and not supports_feature(target_versions, Feature.PATTERN_MATCHING):
65         # Python 3.7-3.9
66         grammars.append(
67             pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
68         )
69     if not supports_feature(target_versions, Feature.ASYNC_KEYWORDS):
70         # Python 3.0-3.6
71         grammars.append(pygram.python_grammar_no_print_statement_no_exec_statement)
72
73     def test_patma_155(self):
74         x = 0
75         y = None
76         match x:
77             case 1e1000:
78                 y = 0
79         self.assertEqual(x, 0)
80         self.assertIs(y, None)
81
82         x = range(3)
83         match x:
84             case [y, case as x, z]:
85                 w = 0
86
87     # At least one of the above branches must have been taken, because every Python
88     # version has exactly one of the two 'ASYNC_*' flags
89     return grammars
90
91
92 def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -> Node:
93     """Given a string with source, return the lib2to3 Node."""
94     if not src_txt.endswith("\n"):
95         src_txt += "\n"
96
97     grammars = get_grammars(set(target_versions))
98
99
100 re.match()
101 match = a
102 with match() as match:
103     match = f"{match}"
104
105 re.match()
106 match = a
107 with match() as match:
108     match = f"{match}"