Debian Codegraph @

texk/xdvik/tests/test_string_list.c

raw
1 #include "run_tests.h"
2 #include "string_list.h"
3
4 static Boolean
5 string_list_test1(int verbosity)
6 {
7 static char *test_str = "This\nis\na\ntest\n";
8 static char *test_str_rotated = "is\na\ntest\nThis\n";
9 static char *test_list[] = {
10 "This",
11 "is",
12 "a",
13 "test",
14 NULL
15 };
16
17 char *res_str;
18 char **test_list_orig, **test_list_rotated;
19
20 res_str = string_list_to_str(test_list, "\n");
21 if (!test_str_equality(verbosity, res_str, test_str)) {
22 return False;
23 }
24
25 test_list_rotated = string_list_rotate_down(test_list);
26 if (!test_str_equality(verbosity,
27 string_list_to_str(test_list_rotated, "\n"),
28 test_str_rotated)) {
29 return False;
30 }
31
32 test_list_orig = string_list_rotate_up(test_list_rotated);
33 if (!test_str_list_equality(verbosity,
34 test_list_orig,
35 test_list)) {
36 return False;
37 }
38 return True;
39 }
40
41 static Boolean
42 string_list_test2(int verbosity)
43 {
44 static char *test_str = "";
45 static char *test_list[] = { NULL };
46 char **res_list;
47 char *res_str = string_list_to_str(test_list, "#");
48
49 if (!test_str_equality(verbosity, res_str, test_str)) {
50 return False;
51 }
52
53 /* string_list_print(test_list); */
54
55 res_list = string_list_rotate_down(test_list);
56
57 /* string_list_print(res_list); */
58
59 if (!test_str_equality(verbosity,
60 test_str,
61 string_list_to_str(res_list, "\n")))
62 {
63 return False;
64 }
65 return True;
66 }
67
68 /* todo: append, prepend, reorder */
69
70 void
71 register_all_from_test_string_list(void)
72 {
73 register_test(string_list_test1, "string lists");
74 register_test(string_list_test2, "empty string lists");
75 }