feat(string_utils): insert_into
This commit is contained in:
parent
0c9c5dc1f8
commit
df7cc02eb9
3 changed files with 121 additions and 1 deletions
85
tests/unit/utils/insert_into.c
Normal file
85
tests/unit/utils/insert_into.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <criterion/criterion.h>
|
||||
#include <criterion/new/assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../src/utils/string_utils/string_utils.h"
|
||||
|
||||
TestSuite(insert_into);
|
||||
|
||||
Test(insert_into, basic)
|
||||
{
|
||||
char *dest = strdup("The <WORD> 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue