feat(utils): string utils + corresponding tests

This commit is contained in:
Matteo Flebus 2026-01-08 17:03:52 +01:00
parent 453a8ab0da
commit af1af49ae1
4 changed files with 140 additions and 22 deletions

View file

@ -0,0 +1,97 @@
#include <criterion/criterion.h>
#include <criterion/new/assert.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "utils/string_utils/string_utils.h"
TestSuite(string_utils);
Test(string_utils, skipblank_basic)
{
char input[] = " Hello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 2;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_noblank)
{
char input[] = "Hello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 0;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_tab)
{
char input[] = "\tHello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 1;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_space_tab)
{
char input[] = " \tHello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 2;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_2tab_1space)
{
char input[] = "\t \tHello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 3;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_a_lot)
{
char input[] = "\t \t \tHello World";
char expected_str[] = "Hello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 8;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_newline)
{
char input[] = "\nHello World";
char expected_str[] = "\nHello World";
ssize_t actual = skip_blanks(input);
ssize_t expected = 0;
cr_expect(eq(str, input, expected_str));
cr_expect(actual == expected);
}
Test(string_utils, skipblank_nul)
{
char *input = NULL;
ssize_t actual = skip_blanks(input);
ssize_t expected = 0;
cr_expect(input == NULL);
cr_expect(actual == expected);
}