From d37eb3feb226623431a464b189edf2fc2f31beed Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Thu, 11 May 2023 17:26:15 +0200 Subject: Add tests --- test/test_split.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/test_split.c (limited to 'test/test_split.c') diff --git a/test/test_split.c b/test/test_split.c new file mode 100644 index 0000000..7b19caa --- /dev/null +++ b/test/test_split.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ + +#include +#include +#include + +#define assert(c) if (c == 0) { printf("%s:%d\n", __FILE__, __LINE__); exit(1);} +#define log(str) printf("%s: %s\n", __func__, str); + +void +test_split1() +{ + log("Running..."); + + char *str = "STR_1\nSTR_2"; + int size; + char **tokens = strsplit(str, '\n', &size); + + assert(size == 2); + assert(strncmp("STR_1", tokens[0], 5) == 0); + assert(strncmp("STR_2", tokens[1], 5) == 0); + + log("OK\n"); +} + +void +test_split2() +{ + log("Running..."); + + char *str = "\nSTR_1\nSTR_2"; + int size; + char **tokens = strsplit(str, '\n', &size); + + assert(size == 3); + assert(strlen(tokens[0]) == 0); + assert(strncmp("STR_1", tokens[1], 5) == 0); + assert(strncmp("STR_2", tokens[2], 5) == 0); + + log("OK\n"); +} -- cgit v1.2.3