@@ -301,6 +301,38 @@ static void test_comments_whitespace(void)
301301 TEST_PASS ();
302302}
303303
304+ /**
305+ * @brief Test: Inline comments are stripped from values
306+ */
307+ static void test_inline_comments (void )
308+ {
309+ TEST_START ("Strip inline comments from values" );
310+
311+ const char * ini_data =
312+ "Port=A ; some comment\n"
313+ "key1=value1 # hash comment\n"
314+ "[section1]\n"
315+ "key2 = value2 ; trailing comment\n" ;
316+
317+ dmini_context_t ctx = dmini_create ();
318+ TEST_ASSERT (ctx != NULL , "Failed to create context" );
319+
320+ int result = dmini_parse_string (ctx , ini_data );
321+ TEST_ASSERT (result == 0 , "Failed to parse string" );
322+
323+ const char * val = dmini_get_string (ctx , NULL , "Port" , "" );
324+ TEST_ASSERT (strcmp (val , "A" ) == 0 , "Inline semicolon comment not stripped" );
325+
326+ val = dmini_get_string (ctx , NULL , "key1" , "" );
327+ TEST_ASSERT (strcmp (val , "value1" ) == 0 , "Inline hash comment not stripped" );
328+
329+ val = dmini_get_string (ctx , "section1" , "key2" , "" );
330+ TEST_ASSERT (strcmp (val , "value2" ) == 0 , "Inline comment in section not stripped" );
331+
332+ dmini_destroy (ctx );
333+ TEST_PASS ();
334+ }
335+
304336/**
305337 * @brief Main entry point for test application
306338 */
@@ -320,6 +352,7 @@ int main(int argc, char** argv)
320352 test_generate_string ();
321353 test_file_io ();
322354 test_comments_whitespace ();
355+ test_inline_comments ();
323356
324357 // Print summary
325358 Dmod_Printf ("\n=== Test Summary ===\n" );
0 commit comments