#define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include "../../../src/utils/string_utils/string_utils.h" TestSuite(insert_into); Test(insert_into, basic) { char *dest = strdup("The is nice."); const char *src = "weather"; size_t pos = 4; char *result = insert_into(dest, src, pos, 6); cr_expect(result != NULL); cr_expect(eq(str, result, "The weather is nice.")); if (result) free(result); } Test(insert_into, begin) { char *dest = strdup("Hello World!"); const char *src = "Hi"; size_t pos = 0; char *result = insert_into(dest, src, pos, 5); cr_expect(result != NULL); cr_expect(eq(str, result, "Hi World!")); if (result) free(result); } Test(insert_into, end) { char *dest = strdup("The number is 1024"); const char *src = "2048"; size_t pos = 14; char *result = insert_into(dest, src, pos, 4); cr_expect(result != NULL); cr_expect(eq(str, result, "The number is 2048")); if (result) free(result); } Test(insert_into, big) { char *dest = strdup("I could insert [VAR] here."); const char *src = "a very very long string"; size_t pos = 15; char *result = insert_into(dest, src, pos, 5); cr_expect(result != NULL); cr_expect(eq(str, result, "I could insert a very very long string here.")); if (result) free(result); } Test(insert_into, small) { char *dest = strdup("I could insert [VARNAME_IS_SO_LONG] string here."); const char *src = "a short"; size_t pos = 15; char *result = insert_into(dest, src, pos, 20); cr_expect(result != NULL); cr_expect(eq(str, result, "I could insert a short string here.")); if (result) free(result); }