From bb0067f517648a0f48736a4031884831a7ccc2b5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 17 Apr 2026 18:49:04 -0500 Subject: [PATCH] [core] Strengthen RawExpression-as-arg test Exercise the actual CallExpression(..., RawExpression) pattern that components use for passing raw arguments. The previous test used RawStatement filler which didn't exercise the detection path we wanted to assert doesn't trigger. --- tests/unit_tests/test_core.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_core.py b/tests/unit_tests/test_core.py index b26fee8c9a..ba35475003 100644 --- a/tests/unit_tests/test_core.py +++ b/tests/unit_tests/test_core.py @@ -9,6 +9,7 @@ from strategies import mac_addr_strings from esphome import const, core from esphome.cpp_generator import ( AssignmentExpression, + CallExpression, ComponentMarker, ExpressionStatement, IIFEUnsafeStatement, @@ -1068,15 +1069,20 @@ def test_cpp_main_section_raw_expression_as_call_arg_still_sub_splits() -> None: # `var.set_program(RawExpression("&foo"))`) produces # `ExpressionStatement(CallExpression(..., RawExpression))` — the # outer expression is a CallExpression, not a RawExpression, so - # the group is still sub-splittable. + # the group is still sub-splittable. Exercise this with actual + # CallExpression-wrapping-RawExpression statements filling the + # group past the 50-statement cap. target = core.EsphomeCore() stmts: list = [ComponentMarker("rp2040_pio_led_strip")] - # Emit >50 plain statements with one being an ExpressionStatement - # wrapping a non-RawExpression inner (RawStatement for simplicity - # here — the real codegen wraps a CallExpression). - stmts.extend(RawStatement(f"s{i}();") for i in range(120)) + stmts.extend( + ExpressionStatement( + CallExpression(MockObj(f"var_{i}.set_program"), RawExpression("&foo")) + ) + for i in range(120) + ) target.main_statements = stmts out = target.cpp_main_section + # 120 statements / 50-cap -> 3 sub-chunks. assert out.count("[]() {") == 3