@@ -774,6 +774,37 @@ FOSSIL_TEST(c_test_cstring_number_to_words) {
774774 ASSUME_ITS_TRUE (fossil_io_cstring_number_to_words (123456789 , buffer , 5 ) != 0 );
775775}
776776
777+ // Test fossil_io_cstring_string_to_money with tolerance
778+ FOSSIL_TEST (c_test_cstring_string_to_money ) {
779+ double value ;
780+
781+ ASSUME_ITS_EQUAL_F64 (0 , fossil_io_cstring_string_to_money ("$1,234.56" , & value ), 0.0 );
782+ ASSUME_ITS_EQUAL_F64 (value , 1234.56 , 0.001 );
783+
784+ ASSUME_ITS_EQUAL_F64 (0 , fossil_io_cstring_string_to_money ("-$42.50" , & value ), 0.0 );
785+ ASSUME_ITS_EQUAL_F64 (value , -42.50 , 0.001 );
786+
787+ // Invalid string
788+ ASSUME_ITS_TRUE (fossil_io_cstring_string_to_money ("foobar" , & value ) != 0 );
789+ }
790+
791+ // Test fossil_io_cstring_string_to_money_currency with tolerance
792+ FOSSIL_TEST (c_test_cstring_string_to_money_currency ) {
793+ double value ;
794+
795+ ASSUME_ITS_EQUAL_F64 (0 , fossil_io_cstring_string_to_money_currency ("$1,234.56" , & value ), 0.0 );
796+ ASSUME_ITS_EQUAL_F64 (value , 1234.56 , 0.001 );
797+
798+ ASSUME_ITS_EQUAL_F64 (0 , fossil_io_cstring_string_to_money_currency ("€987.65" , & value ), 0.0 );
799+ ASSUME_ITS_EQUAL_F64 (value , 987.65 , 0.001 );
800+
801+ ASSUME_ITS_EQUAL_F64 (0 , fossil_io_cstring_string_to_money_currency ("-$42.50" , & value ), 0.0 );
802+ ASSUME_ITS_EQUAL_F64 (value , -42.50 , 0.001 );
803+
804+ // Invalid format
805+ ASSUME_ITS_TRUE (fossil_io_cstring_string_to_money_currency ("foobar" , & value ) != 0 );
806+ }
807+
777808// * * * * * * * * * * * * * * * * * * * * * * * *
778809// * Fossil Logic Test Pool
779810// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -855,6 +886,9 @@ FOSSIL_TEST_GROUP(c_string_tests) {
855886 FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_strip_quotes_safe );
856887 FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_normalize_spaces_safe );
857888 FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_index_of_safe );
889+
890+ FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_string_to_money );
891+ FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_string_to_money_currency );
858892
859893 FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_stream_create_and_free );
860894 FOSSIL_TEST_ADD (c_string_suite , c_test_cstring_stream_write_and_read );
0 commit comments