aboutsummaryrefslogtreecommitdiff
path: root/libutil/tests/string_tests.c
blob: b2132cffeb5b94f388a2ae93a0195b04c9f88c01 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
 * @file string_tests.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon
 * @author Philippe Elie
 */

#include "op_string.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void error(char const * str)
{
	fprintf(stderr, "%s\n", str);
	exit(EXIT_FAILURE);
}


int main()
{
	if (!strisprefix("", ""))
		error("\"\" is not a prefix of \"\"");
	if (!strisprefix("a", ""))
		error("\"\" is not a prefix of a");
	if (!strisprefix("a", "a"))
		error("a is not a prefix of a");
	if (!strisprefix("aa", "a"))
		error("a is not a prefix of aa");
	if (strisprefix("a", "b"))
		error("b is a prefix of a");

	if (strcmp(skip_ws(""), ""))
		error("skip_ws of \"\" is not \"\"");
	if (strcmp(skip_ws("\na"), "a"))
		error("skip_ws of \\na is not a");
	if (strcmp(skip_ws("\n\na"), "a"))
		error("skip_ws of \\n\\na is not a");
	if (strcmp(skip_ws("\n a"), "a"))
		error("skip_ws of \\n a is not a");
	if (strcmp(skip_ws("\n \ta"), "a"))
		error("skip_ws of \\n \\ta is not a");
	if (strcmp(skip_ws("\n \t"), ""))
		error("skip_ws of \\n \\t is not \"\"");
	if (strcmp(skip_ws(" "), ""))
		error("skip_ws of \" \" is not \"\"");

	if (strcmp(skip_nonws(""), ""))
		error("skip_nonws of \"\" is not \"\"");
	if (strcmp(skip_nonws("a"), ""))
		error("skip_nonws of a is not \"\"");
	if (strcmp(skip_nonws("\n"), "\n"))
		error("skip_nonws of \\n is not \\n");
	if (strcmp(skip_nonws(" "), " "))
		error("skip_nonws of \" \" is not \" \"");
	if (strcmp(skip_nonws("\t"), "\t"))
		error("skip_nonws of \\t is not \\t");
	if (strcmp(skip_nonws("a\n"), "\n"))
		error("skip_nonws of a\\n is not \\n");
	if (strcmp(skip_nonws("ab"), ""))
		error("skip_nonws of ab is not \"\"");

	if (!empty_line(""))
		error("empty_line is false for \"\"");
	if (!empty_line("\n\t "))
		error("empty_line is false for \"\\n\\n \"");
	if (!empty_line(" "))
		error("empty_line is false for \" \"");
	if (empty_line("\r"))
		error("empty_line is true for \\r");

	if (comment_line(""))
		error("comment_line is true for \"\"");
	if (comment_line("\n"))
		error("comment_line is true for \n");
	if (!comment_line("#"))
		error("comment_line is false for #");
	if (!comment_line(" #"))
		error("comment_line is false for \" #\"");
	/* this is what the spec says */
	if (!comment_line("\n#"))
		error("comment_line is false for \\n#");
	if (!comment_line("\t#"))
		error("comment_line is false for \\t#");

	return EXIT_SUCCESS;
}