feat: add tests

This commit is contained in:
2025-09-07 17:35:30 +02:00
parent be154db6cf
commit 3e0584d139
10 changed files with 165 additions and 129 deletions

37
test/string/str1.c Normal file
View File

@@ -0,0 +1,37 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../string/mystring.h"
void test_str1(void) {
size_t length;
size_t capacity;
char *c_str;
/* Allocate a new dynamic string with an initial capacity */
mcl_string_s *str = mcl_string_new("Hello, world!", 512);
assert(str != NULL);
/* Retrieve a C str from string with mcl_string_cstr() */
c_str = mcl_string_cstr(str);
length = mcl_string_length(str);
capacity = mcl_string_capacity(str);
assert(strcmp(c_str, "Hello, world!") == 0);
assert(length == 13);
assert(capacity == 512);
/* Append text to a mcl_string */
assert(mcl_string_append(str, " How are you?") == 0);
c_str = mcl_string_cstr(str);
length = mcl_string_length(str);
capacity = mcl_string_capacity(str);
assert(strcmp(c_str, "Hello, world! How are you?") == 0);
assert(length == 26);
assert(capacity == 512);
/* Always deallocate memory */
mcl_string_free(str);
}