diff --git a/tests/unit_tests/test_lambda_dedup.py b/tests/unit_tests/test_lambda_dedup.py index a0691e29dc..c112631f2d 100644 --- a/tests/unit_tests/test_lambda_dedup.py +++ b/tests/unit_tests/test_lambda_dedup.py @@ -201,11 +201,21 @@ def test_static_variable_detection() -> None: assert cg._has_static_variables("static bool flag = false; return flag;") assert cg._has_static_variables(" static float value = 1.0; ") - # Should NOT detect static_cast, static_assert, etc. + # Should NOT detect static_cast, static_assert, etc. (with underscores) assert not cg._has_static_variables("return static_cast(value);") assert not cg._has_static_variables("static_assert(sizeof(int) == 4);") assert not cg._has_static_variables("auto ptr = static_pointer_cast(bar);") + # Edge case: 'cast', 'assert', 'pointer_cast' are NOT C++ keywords + # Someone could use them as type names, but we should NOT flag them + # because they're not actually static variables with state + # NOTE: These are valid C++ but extremely unlikely in ESPHome lambdas + assert not cg._has_static_variables("static cast obj;") # 'cast' as type name + assert not cg._has_static_variables("static assert value;") # 'assert' as type name + assert not cg._has_static_variables( + "static pointer_cast ptr;" + ) # 'pointer_cast' as type + # Should NOT detect in comments assert not cg._has_static_variables("// static int x = 0;\nreturn 42;") assert not cg._has_static_variables("/* static int y = 0; */ return 42;")