refactor(test): use builtin meson test

This commit is contained in:
2026-03-16 23:22:37 +01:00
parent 21806e77a7
commit 47fc8b50a6
10 changed files with 92 additions and 114 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>
void test_str1(void) {
int main(void) {
size_t length;
size_t capacity;
char *c_str;
+19 -1
View File
@@ -2,7 +2,7 @@
#include <assert.h>
#include <string.h>
void test_str2(void) {
int main(void) {
string_s *s1 = string_new("Hello, world!", 0);
assert(s1 != NULL);
string_s *s2 = string_new("Hello, world!", 0);
@@ -27,6 +27,21 @@ void test_str2(void) {
assert(string_len(s1) == 50);
assert(string_cap(s1) == 64);
/* Regression: when need == capacity, extend still needs room for '\0'. */
string_s *tight_dst = string_new("abc", 4);
string_s *tight_src = string_new("d", 0);
assert(tight_dst != NULL);
assert(tight_src != NULL);
assert(string_extend(tight_dst, tight_src) == 0);
assert(strcmp(string_cstr(tight_dst), "abcd") == 0);
assert(string_cap(tight_dst) >= 5);
/* Self-extend should be safe and deterministic. */
string_s *self = string_new("xy", 0);
assert(self != NULL);
assert(string_extend(self, self) == 0);
assert(strcmp(string_cstr(self), "xyxy") == 0);
/* Find substring in string */
int pos = string_find(s1, " is ");
assert(pos == 11);
@@ -34,4 +49,7 @@ void test_str2(void) {
string_free(s1);
string_free(s2);
string_free(extend_me);
string_free(tight_dst);
string_free(tight_src);
string_free(self);
}
+12 -1
View File
@@ -2,7 +2,7 @@
#include <assert.h>
#include <string.h>
void test_str3(void) {
int main(void) {
/* Make a new string from format */
string_s *s = string_format("My name is %s (%d)", "John", 21);
assert(strcmp(s->data, "My name is John (21)") == 0);
@@ -16,6 +16,16 @@ void test_str3(void) {
/* Test delete */
string_remove(ms, 5, 5);
assert(strcmp(ms->data, "Hello!") == 0);
assert(string_remove(ms, string_len(ms), 1) == -1);
string_s *remove_mid = string_new("abcdef", 0);
assert(remove_mid != NULL);
assert(string_remove(remove_mid, 2, 2) == 0);
assert(strcmp(remove_mid->data, "abef") == 0);
assert(string_remove(remove_mid, 2, 2) == 0);
assert(strcmp(remove_mid->data, "ab") == 0);
assert(string_remove(remove_mid, 0, 2) == 0);
assert(strcmp(remove_mid->data, "") == 0);
/* Test replace */
string_s *replace_me = string_new("My car doesn't bark!", 0);
@@ -25,5 +35,6 @@ void test_str3(void) {
string_free(ms);
string_free(s);
string_free(remove_mid);
string_free(replace_me);
}