From c814778390de19244b2cb7fc2c887b72fa34898d Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Mon, 31 Aug 2026 13:30:46 +0200 Subject: [PATCH] test(lowering): a where atom reaches the program as the file wrote it Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01P5CbcWjp4KCK5RcCEy7RZ3 --- tests/test_lowering.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_lowering.py b/tests/test_lowering.py index 492fd192..00f5fe0a 100644 --- a/tests/test_lowering.py +++ b/tests/test_lowering.py @@ -57,8 +57,11 @@ from math_spec.where_parser import ( BooleanLiteralNode, DimensionComparisonNode, + DimensionMembershipNode, + LookupMembershipNode, ParameterComparisonNode, ParameterDefinedNode, + ParameterMembershipNode, ) from tests.fixtures import DISPATCH_MODEL, SMALL_MODEL, override, schema_of @@ -167,6 +170,27 @@ def test_where_lowering(dispatch_schema, where, expected): assert where_of(where, Namespace.of(dispatch_schema), 't') == expected +@pytest.mark.parametrize( + ('where', 'expected'), + [ + pytest.param('c in [1.5, 2.5]', ParameterMembershipNode('c', (1.5, 2.5)), id='over-a-parameter'), + pytest.param("g in ['g1', 'g2']", DimensionMembershipNode('g', ('g1', 'g2')), id='over-a-dimension'), + pytest.param("lk in ['h1']", LookupMembershipNode('lk', 'g', ('h1',)), id='over-a-groupable-lookup'), + pytest.param("tag in ['north']", LookupMembershipNode('tag', 'g', ('north',)), id='over-a-label-space'), + ], +) +def test_a_membership_mask_reaches_the_program_unchanged(where, expected): + """A `where` atom *is* the program's predicate — no lowering case rewrites one. + + That is what lets a new atom (#254) cost nothing in `lowering.py`, and it is + the half no other suite covers: resolution proves the node is built and the + typesetter proves it prints, while only this asks whether it survives the + pass in between. + """ + program = lower_program(expand_piecewise(schema_of(SMALL_MODEL, **{'variables.p.where': where}))) + assert program.variables['p'].where == expected, 'the atom the file wrote, not a rewrite of it' + + def test_a_literal_amount_resolves_to_one_signed_number(dispatch_schema): """`offset=-1` parses as a unary minus over `1`; after resolution it is `-1`, for every reader alike.""" ns = Namespace.of(dispatch_schema)