aboutsummaryrefslogtreecommitdiff
path: root/test/test_split.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_split.c')
-rw-r--r--test/test_split.c41
1 files changed, 41 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string2.h>
+
+#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");
+}