]> git.madduck.net Git - etc/vim.git/blob - tests/data/pattern_matching_extras.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:

perf: drop the initial stack copy (#2670)
[etc/vim.git] / tests / data / pattern_matching_extras.py
1 import match
2
3 match something:
4     case [a as b]:
5         print(b)
6     case [a as b, c, d, e as f]:
7         print(f)
8     case Point(a as b):
9         print(b)
10     case Point(int() as x, int() as y):
11         print(x, y)
12
13
14 match = 1
15 case: int = re.match(something)
16
17 match re.match(case):
18     case type("match", match):
19         pass
20     case match:
21         pass
22
23
24 def func(match: case, case: match) -> case:
25     match Something():
26         case func(match, case):
27             ...
28         case another:
29             ...
30
31
32 match maybe, multiple:
33     case perhaps, 5:
34         pass
35     case perhaps, 6,:
36         pass
37
38
39 match more := (than, one), indeed,:
40     case _, (5, 6):
41         pass
42     case [[5], (6)], [7],:
43         pass
44     case _:
45         pass
46
47
48 match a, *b, c:
49     case [*_]:
50         assert "seq" == _
51     case {}:
52         assert "map" == b
53
54
55 match match(
56     case,
57     match(
58         match, case, match, looooooooooooooooooooooooooooooooooooong, match, case, match
59     ),
60     case,
61 ):
62     case case(
63         match=case,
64         case=re.match(
65             loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
66         ),
67     ):
68         pass
69
70     case [a as match]:
71         pass
72
73     case case:
74         pass
75
76
77 match match:
78     case case:
79         pass
80
81
82 match a, *b(), c:
83     case d, *f, g:
84         pass