aboutsummaryrefslogtreecommitdiff
path: root/src/tests/slice.c
blob: 1f3875a250738b59f6ce6f3be1f5dd8e176acd4d (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
#include "tests/tests.h"
#include "slice.h"

#include <string.h>

static void
test_slice_cmp(void)
{
	struct slice s1a = {
		.str = "hello world",
		.start = 6,
		.end = 11,
	};
	struct slice s1b = {
		.str = "world",
		.start = 0,
		.end = 5,
	};
	asserteq(slice_cmp(&s1a, &s1b), 0);
}

static void
test_slice_string(void)
{
	struct slice slice = {
		.str = "hello world",
		.start = 6,
		.end = 11,
	};
	sds str = sdsempty();
	slice_string(&slice, str);
	asserteq(strcmp("world", str), 0);
}

int
main(void)
{
	INIT_TESTS();
	RUN_TEST(test_slice_cmp);
	RUN_TEST(test_slice_string);
}