summaryrefslogtreecommitdiff
path: root/Build/source/texk/xdvik/tests/test_string_list.c
blob: 1f23158949a8b57fddaa458ede122a71a69f142e (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
#include "run_tests.h"
#include "string_list.h"

static Boolean
string_list_test1(int verbosity)
{
    static char *test_str = "This\nis\na\ntest\n";
    static char *test_str_rotated = "is\na\ntest\nThis\n";
    static char *test_list[] = {
	"This",
	"is",
	"a",
	"test",
	NULL
    };

    char *res_str;
    char **test_list_orig, **test_list_rotated;

    res_str = string_list_to_str(test_list, "\n");
    if (!test_str_equality(verbosity, res_str, test_str)) {
	return False;
    }
    
    test_list_rotated = string_list_rotate_down(test_list);
    if (!test_str_equality(verbosity,
			   string_list_to_str(test_list_rotated, "\n"),
			   test_str_rotated)) {
	return False;
    }

    test_list_orig = string_list_rotate_up(test_list_rotated);
    if (!test_str_list_equality(verbosity,
				test_list_orig,
				test_list)) {
	return False;
    }
    return True;
}

static Boolean
string_list_test2(int verbosity)
{
    static char *test_str = "";
    static char *test_list[] = { NULL };
    char **res_list;
    char *res_str = string_list_to_str(test_list, "#");

    if (!test_str_equality(verbosity, res_str, test_str)) {
	return False;
    }

    /*     string_list_print(test_list); */
    
    res_list = string_list_rotate_down(test_list);

    /*     string_list_print(res_list); */

    if (!test_str_equality(verbosity,
			   test_str,
			   string_list_to_str(res_list, "\n")))
    {
	return False;
    }
    return True;
}

/* todo: append, prepend, reorder */

void
register_all_from_test_string_list(void)
{
    register_test(string_list_test1, "string lists");
    register_test(string_list_test2, "empty string lists");
}