From 18c3dd8af70430e563ae7d4983000bef20a97c2e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 08:35:46 -1000 Subject: [PATCH] make sure new stringref functions work --- .../fixtures/select_stringref_trigger.yaml | 18 ++++++++++++++ .../test_select_stringref_trigger.py | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/integration/fixtures/select_stringref_trigger.yaml b/tests/integration/fixtures/select_stringref_trigger.yaml index ca9b81ae26..2ee64741fd 100644 --- a/tests/integration/fixtures/select_stringref_trigger.yaml +++ b/tests/integration/fixtures/select_stringref_trigger.yaml @@ -37,3 +37,21 @@ select: # Test 4: Use index parameter (variable name is 'i') - lambda: |- ESP_LOGI("test", "Select index: %d", (int)i); + # Test 5: StringRef.length() method + - lambda: |- + ESP_LOGI("test", "Length: %d", (int)x.length()); + # Test 6: StringRef.find() method with substring + - lambda: |- + if (x.find("Option") != StringRef::npos) { + ESP_LOGI("test", "Found 'Option' in value"); + } + # Test 7: StringRef.find() method with character + - lambda: |- + size_t space_pos = x.find(' '); + if (space_pos != StringRef::npos) { + ESP_LOGI("test", "Space at position: %d", (int)space_pos); + } + # Test 8: StringRef.substr() method + - lambda: |- + std::string prefix = x.substr(0, 6); + ESP_LOGI("test", "Substr prefix: %s", prefix.c_str()); diff --git a/tests/integration/test_select_stringref_trigger.py b/tests/integration/test_select_stringref_trigger.py index 6a1ecdac2a..f6c3efb72d 100644 --- a/tests/integration/test_select_stringref_trigger.py +++ b/tests/integration/test_select_stringref_trigger.py @@ -24,12 +24,20 @@ async def test_select_stringref_trigger( concatenated_future = loop.create_future() comparison_future = loop.create_future() index_logged_future = loop.create_future() + length_future = loop.create_future() + find_substr_future = loop.create_future() + find_char_future = loop.create_future() + substr_future = loop.create_future() # Patterns to match in logs value_pattern = re.compile(r"Select value: Option B") concatenated_pattern = re.compile(r"Concatenated: Option B selected") comparison_pattern = re.compile(r"Option B was selected") index_pattern = re.compile(r"Select index: 1") + length_pattern = re.compile(r"Length: 8") # "Option B" is 8 chars + find_substr_pattern = re.compile(r"Found 'Option' in value") + find_char_pattern = re.compile(r"Space at position: 6") # space at index 6 + substr_pattern = re.compile(r"Substr prefix: Option") def check_output(line: str) -> None: """Check log output for expected messages.""" @@ -41,6 +49,14 @@ async def test_select_stringref_trigger( comparison_future.set_result(True) if not index_logged_future.done() and index_pattern.search(line): index_logged_future.set_result(True) + if not length_future.done() and length_pattern.search(line): + length_future.set_result(True) + if not find_substr_future.done() and find_substr_pattern.search(line): + find_substr_future.set_result(True) + if not find_char_future.done() and find_char_pattern.search(line): + find_char_future.set_result(True) + if not substr_future.done() and substr_pattern.search(line): + substr_future.set_result(True) async with ( run_compiled(yaml_config, line_callback=check_output), @@ -71,6 +87,10 @@ async def test_select_stringref_trigger( concatenated_future, comparison_future, index_logged_future, + length_future, + find_substr_future, + find_char_future, + substr_future, ), timeout=5.0, ) @@ -80,5 +100,9 @@ async def test_select_stringref_trigger( "concatenated": concatenated_future.done(), "comparison": comparison_future.done(), "index_logged": index_logged_future.done(), + "length": length_future.done(), + "find_substr": find_substr_future.done(), + "find_char": find_char_future.done(), + "substr": substr_future.done(), } pytest.fail(f"StringRef operations failed - received: {results}")