#include #include #include #include #include "strings.h" static void test_str_escape(CuTest * tc) { char scratch[64]; CuAssertStrEquals(tc, "12345678901234567890", str_escape("12345678901234567890", scratch, 16)); CuAssertStrEquals(tc, "123456789\\\"12345", str_escape("123456789\"1234567890", scratch, 16)); CuAssertStrEquals(tc, "1234567890123456", str_escape("1234567890123456\"890", scratch, 16)); CuAssertStrEquals(tc, "hello world", str_escape("hello world", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "hello \\\"world\\\"", str_escape("hello \"world\"", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "\\\"\\\\", str_escape("\"\\", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "\\\\", str_escape("\\", scratch, sizeof(scratch))); } static void test_str_replace(CuTest * tc) { char result[64]; str_replace(result, sizeof(result), "Hello $who!", "$who", "World"); CuAssertStrEquals(tc, "Hello World!", result); } static void test_str_hash(CuTest * tc) { CuAssertIntEquals(tc, 0, str_hash("")); CuAssertIntEquals(tc, 140703196, str_hash("Hodor")); } CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_str_hash); SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_replace); return suite; }