Nested matching on Name-like types.
(example_lib)
| 82 | |
| 83 | |
| 84 | def 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 | # ============================================================================ |
nothing calls this directly
no test coverage detected