MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / test_match_recursive

Function test_match_recursive

tests/test_pattern_match.py:84–121  ·  view source on GitHub ↗

Nested matching on Name-like types.

(example_lib)

Source from the content-addressed store, hash-verified

82
83
84def test_match_recursive(example_lib):
85 """Nested matching on Name-like types."""
86 # Build a Name.str value manually
87 anon = LeanInductiveValue("Name", "anonymous", 0, ())
88 name = LeanInductiveValue("Name", "str", 1, (anon, "hello"))
89
90 # Create a simple stand-in for Name type ctors
91 class _NameNs:
92 pass
93
94 NameNs = _NameNs()
95 NameNs.str = _CtorMeta(
96 "str",
97 (),
98 {
99 "_ctor_name": "str",
100 "_type_name": "Name",
101 "_tag": 1,
102 "__match_args__": ("_0", "_1"),
103 },
104 )
105 NameNs.anonymous = _CtorMeta(
106 "anonymous",
107 (),
108 {
109 "_ctor_name": "anonymous",
110 "_type_name": "Name",
111 "_tag": 0,
112 "__match_args__": (),
113 },
114 )
115
116 match name:
117 case NameNs.str(parent, leaf):
118 assert leaf == "hello"
119 assert isinstance(parent, NameNs.anonymous)
120 case _:
121 pytest.fail("Should have matched Name.str")
122
123
124# ============================================================================

Callers

nothing calls this directly

Calls 3

LeanInductiveValueClass · 0.90
_CtorMetaClass · 0.90
_NameNsClass · 0.85

Tested by

no test coverage detected