| 1 |
# flags: --minimum-version=3.10 |
| 2 |
# Cases sampled from Lib/test/test_patma.py |
| 3 |
|
| 4 |
# case black_test_patma_098 |
| 5 |
match x: |
| 6 |
case -0j: |
| 7 |
y = 0 |
| 8 |
# case black_test_patma_142 |
| 9 |
match x: |
| 10 |
case bytes(z): |
| 11 |
y = 0 |
| 12 |
# case black_test_patma_073 |
| 13 |
match x: |
| 14 |
case 0 if 0: |
| 15 |
y = 0 |
| 16 |
case 0 if 1: |
| 17 |
y = 1 |
| 18 |
# case black_test_patma_006 |
| 19 |
match 3: |
| 20 |
case 0 | 1 | 2 | 3: |
| 21 |
x = True |
| 22 |
# case black_test_patma_049 |
| 23 |
match x: |
| 24 |
case [0, 1] | [1, 0]: |
| 25 |
y = 0 |
| 26 |
# case black_check_sequence_then_mapping |
| 27 |
match x: |
| 28 |
case [*_]: |
| 29 |
return "seq" |
| 30 |
case {}: |
| 31 |
return "map" |
| 32 |
# case black_test_patma_035 |
| 33 |
match x: |
| 34 |
case {0: [1, 2, {}]}: |
| 35 |
y = 0 |
| 36 |
case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: |
| 37 |
y = 1 |
| 38 |
case []: |
| 39 |
y = 2 |
| 40 |
# case black_test_patma_107 |
| 41 |
match x: |
| 42 |
case 0.25 + 1.75j: |
| 43 |
y = 0 |
| 44 |
# case black_test_patma_097 |
| 45 |
match x: |
| 46 |
case -0j: |
| 47 |
y = 0 |
| 48 |
# case black_test_patma_007 |
| 49 |
match 4: |
| 50 |
case 0 | 1 | 2 | 3: |
| 51 |
x = True |
| 52 |
# case black_test_patma_154 |
| 53 |
match x: |
| 54 |
case 0 if x: |
| 55 |
y = 0 |
| 56 |
# case black_test_patma_134 |
| 57 |
match x: |
| 58 |
case {1: 0}: |
| 59 |
y = 0 |
| 60 |
case {0: 0}: |
| 61 |
y = 1 |
| 62 |
case {**z}: |
| 63 |
y = 2 |
| 64 |
# case black_test_patma_185 |
| 65 |
match Seq(): |
| 66 |
case [*_]: |
| 67 |
y = 0 |
| 68 |
# case black_test_patma_063 |
| 69 |
match x: |
| 70 |
case 1: |
| 71 |
y = 0 |
| 72 |
case 1: |
| 73 |
y = 1 |
| 74 |
# case black_test_patma_248 |
| 75 |
match x: |
| 76 |
case {"foo": bar}: |
| 77 |
y = bar |
| 78 |
# case black_test_patma_019 |
| 79 |
match (0, 1, 2): |
| 80 |
case [0, 1, *x, 2]: |
| 81 |
y = 0 |
| 82 |
# case black_test_patma_052 |
| 83 |
match x: |
| 84 |
case [0]: |
| 85 |
y = 0 |
| 86 |
case [1, 0] if x := x[:0]: |
| 87 |
y = 1 |
| 88 |
case [1, 0]: |
| 89 |
y = 2 |
| 90 |
# case black_test_patma_191 |
| 91 |
match w: |
| 92 |
case [x, y, *_]: |
| 93 |
z = 0 |
| 94 |
# case black_test_patma_110 |
| 95 |
match x: |
| 96 |
case -0.25 - 1.75j: |
| 97 |
y = 0 |
| 98 |
# case black_test_patma_151 |
| 99 |
match (x,): |
| 100 |
case [y]: |
| 101 |
z = 0 |
| 102 |
# case black_test_patma_114 |
| 103 |
match x: |
| 104 |
case A.B.C.D: |
| 105 |
y = 0 |
| 106 |
# case black_test_patma_232 |
| 107 |
match x: |
| 108 |
case None: |
| 109 |
y = 0 |
| 110 |
# case black_test_patma_058 |
| 111 |
match x: |
| 112 |
case 0: |
| 113 |
y = 0 |
| 114 |
# case black_test_patma_233 |
| 115 |
match x: |
| 116 |
case False: |
| 117 |
y = 0 |
| 118 |
# case black_test_patma_078 |
| 119 |
match x: |
| 120 |
case []: |
| 121 |
y = 0 |
| 122 |
case [""]: |
| 123 |
y = 1 |
| 124 |
case "": |
| 125 |
y = 2 |
| 126 |
# case black_test_patma_156 |
| 127 |
match x: |
| 128 |
case z: |
| 129 |
y = 0 |
| 130 |
# case black_test_patma_189 |
| 131 |
match w: |
| 132 |
case [x, y, *rest]: |
| 133 |
z = 0 |
| 134 |
# case black_test_patma_042 |
| 135 |
match x: |
| 136 |
case (0 as z) | (1 as z) | (2 as z) if z == x % 2: |
| 137 |
y = 0 |
| 138 |
# case black_test_patma_034 |
| 139 |
match x: |
| 140 |
case {0: [1, 2, {}]}: |
| 141 |
y = 0 |
| 142 |
case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: |
| 143 |
y = 1 |
| 144 |
case []: |
| 145 |
y = 2 |
| 146 |
# issue 3790 |
| 147 |
match (X.type, Y): |
| 148 |
case _: |
| 149 |
pass |
| 150 |
# issue 3487 |
| 151 |
match = re.match(r"(?P<grade>LD|MD|HD)(?P<material>AL|SS)", "HDSS") |
| 152 |
|
| 153 |
match (match.group("grade"), match.group("material")): |
| 154 |
case ("MD" | "HD", "SS" as code): |
| 155 |
print("You will get here") |