aboutsummaryrefslogtreecommitdiff
path: root/test/test_split.c
blob: 7b19caa80ec28f75488e7ae39b21df6b062ac6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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");
}