remove match test

This commit is contained in:
Ashwin Naren committed 2025-04-15 11:56:29 -07:00
1 parent 21272025c2
commit 4d53f5925c
2 files changed
-193

No files matched your search

-33
View File
@@ -4596,37 +4596,4 @@ for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):
"
));
}
#[test]
fn test_match() {
assert_dis_snapshot!(compile_exec(
r#"\
class Shape:
pass
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
class Rectangle(Shape):
def __init__(self, width, height):
self.width = width
self.height = height
def describe_shape(shape):
match shape:
case Circle(radius=r):
return f"A circle with radius {r}"
case Rectangle(width=w, height=h):
return f"A rectangle {w} by {h}"
case _:
return "Unknown shape"
# Test it out
shapes = [Circle(5), Rectangle(4, 6), "not a shape"]
for s in shapes:
print(describe_shape(s))
"#
));
}
}
@@ -1,160 +0,0 @@
---
source: compiler/codegen/src/compile.rs
expression: "compile_exec(r#\"\\\nclass Shape:\n pass\n\nclass Circle(Shape):\n def __init__(self, radius):\n self.radius = radius\n\nclass Rectangle(Shape):\n def __init__(self, width, height):\n self.width = width\n self.height = height\n\ndef describe_shape(shape):\n match shape:\n case Circle(radius=r):\n return f\"A circle with radius {r}\"\n case Rectangle(width=w, height=h):\n return f\"A rectangle {w} by {h}\"\n case _:\n return \"Unknown shape\"\n\n# Test it out\nshapes = [Circle(5), Rectangle(4, 6), \"not a shape\"]\nfor s in shapes:\n print(describe_shape(s))\n\"#)"
---
3 0 LoadBuildClass
1 LoadConst (<code object Shape at ??? file "source_path", line 2>): 2 0 LoadGlobal (0, __name__)
1 StoreLocal (1, __module__)
2 LoadConst ("Shape")
3 StoreLocal (2, __qualname__)
4 LoadConst (None)
5 StoreLocal (3, __doc__)
3 6 ReturnConst (None)
2 LoadConst ("Shape")
3 MakeFunction (MakeFunctionFlags(0x0))
4 LoadConst ("Shape")
5 CallFunctionPositional(2)
6 StoreLocal (0, Shape)
7 7 LoadBuildClass
8 LoadConst (<code object Circle at ??? file "source_path", line 5>): 5 0 LoadGlobal (0, __name__)
1 StoreLocal (1, __module__)
2 LoadConst ("Circle")
3 StoreLocal (2, __qualname__)
4 LoadConst (None)
5 StoreLocal (3, __doc__)
7 6 LoadConst (<code object __init__ at ??? file "source_path", line 6>): 7 0 LoadFast (1, radius)
1 LoadFast (0, self)
2 StoreAttr (0, radius)
3 ReturnConst (None)
7 LoadConst ("Circle.__init__")
8 MakeFunction (MakeFunctionFlags(0x0))
9 StoreLocal (4, __init__)
10 ReturnConst (None)
9 LoadConst ("Circle")
10 MakeFunction (MakeFunctionFlags(0x0))
11 LoadConst ("Circle")
5 12 LoadNameAny (0, Shape)
13 CallFunctionPositional(3)
14 StoreLocal (1, Circle)
12 15 LoadBuildClass
16 LoadConst (<code object Rectangle at ??? file "source_path", line 9>): 9 0 LoadGlobal (0, __name__)
1 StoreLocal (1, __module__)
2 LoadConst ("Rectangle")
3 StoreLocal (2, __qualname__)
4 LoadConst (None)
5 StoreLocal (3, __doc__)
12 6 LoadConst (<code object __init__ at ??? file "source_path", line 10>): 11 0 LoadFast (1, width)
1 LoadFast (0, self)
2 StoreAttr (0, width)
12 3 LoadFast (2, height)
4 LoadFast (0, self)
5 StoreAttr (1, height)
6 ReturnConst (None)
7 LoadConst ("Rectangle.__init__")
8 MakeFunction (MakeFunctionFlags(0x0))
9 StoreLocal (4, __init__)
10 ReturnConst (None)
17 LoadConst ("Rectangle")
18 MakeFunction (MakeFunctionFlags(0x0))
19 LoadConst ("Rectangle")
9 20 LoadNameAny (0, Shape)
21 CallFunctionPositional(3)
22 StoreLocal (2, Rectangle)
21 23 LoadConst (<code object describe_shape at ??? file "source_path", line 14>): 15 0 LoadFast (0, shape)
1 CopyItem (1)
16 2 LoadGlobal (0, Circle)
3 LoadConst (("radius"))
4 MatchClass (0)
5 CopyItem (1)
6 LoadConst (None)
7 TestOperation (IsNot)
8 JumpIfFalse (19)
9 UnpackSequence (1)
10 Pop
11 Pop
17 12 LoadConst ("A circle with radius ")
13 LoadConst ("")
14 LoadFast (1, r)
15 FormatValue (None)
16 BuildString (2)
17 ReturnValue
18 Jump (47)
>> 19 Pop
20 CopyItem (1)
18 21 LoadGlobal (1, Rectangle)
22 LoadConst (("width", "height"))
23 MatchClass (0)
24 CopyItem (1)
25 LoadConst (None)
26 TestOperation (IsNot)
27 JumpIfFalse (43)
28 UnpackSequence (2)
29 Pop
30 Pop
31 Pop
19 32 LoadConst ("A rectangle ")
33 LoadConst ("")
34 LoadFast (2, w)
35 FormatValue (None)
36 LoadConst (" by ")
37 LoadConst ("")
38 LoadFast (3, h)
39 FormatValue (None)
40 BuildString (4)
41 ReturnValue
42 Jump (47)
>> 43 Pop
44 Pop
21 45 ReturnConst ("Unknown shape")
46 Jump (47)
>> 47 ReturnConst (None)
24 LoadConst ("describe_shape")
25 MakeFunction (MakeFunctionFlags(0x0))
26 StoreLocal (3, describe_shape)
24 27 LoadNameAny (1, Circle)
28 LoadConst (5)
29 CallFunctionPositional(1)
30 LoadNameAny (2, Rectangle)
31 LoadConst (4)
32 LoadConst (6)
33 CallFunctionPositional(2)
34 LoadConst ("not a shape")
35 BuildList (3)
36 StoreLocal (4, shapes)
25 37 SetupLoop
38 LoadNameAny (4, shapes)
39 GetIter
>> 40 ForIter (49)
41 StoreLocal (5, s)
26 42 LoadNameAny (6, print)
43 LoadNameAny (3, describe_shape)
44 LoadNameAny (5, s)
45 CallFunctionPositional(1)
46 CallFunctionPositional(1)
47 Pop
48 Jump (40)
>> 49 PopBlock
50 ReturnConst (None)