Requires libisds >= 0.10.7
[shigofumi.git] / test / tokenize.c
blob2227cf72a2a754483a9a89597d5602e1680acc5d
1 #include "test.h"
2 #include <completion.h>
3 #include <isds.h>
4 #include <string.h>
6 /* Copy from shigofumi.c until sources will be split properly */
7 struct command base_commands[] = {
8 { NULL, NULL, NULL, NULL, ARGTYPE_NONE }
9 };
10 struct command message_commands[] ={
11 { NULL, NULL, NULL, NULL, ARGTYPE_NONE }
13 struct command list_commands[] = {
14 { NULL, NULL, NULL, NULL, ARGTYPE_NONE }
16 struct command (*commands)[] = NULL;
17 char *prompt = NULL;
18 struct isds_list *boxes = NULL;
19 struct isds_message *message = NULL;
20 struct isds_list *messages = NULL;
23 static int test_completion(const void *line, const char **correct_argv,
24 int correct_argc, const char *correct_shell) {
25 char *shell = NULL;
26 char **argv;
27 int argc;
29 argv = tokenize(line, &argc, &shell);
31 if ((correct_argv != NULL && argv == NULL) ||
32 (correct_argv == NULL && argv != NULL)) {
33 FAIL_TEST("Wrong returned value");
35 if (argc != correct_argc) {
36 FAIL_TEST("Wrong argc: expected=%d, returned=%d", correct_argc, argc);
38 TEST_STRING_DUPLICITY(correct_shell, shell);
39 for (int i = 0; i != argc; i++) {
40 TEST_STRING_DUPLICITY(correct_argv[i], argv[i]);
43 free(shell);
44 PASS_TEST;
47 int main(int argc, char **argv) {
48 const char *line[] = {
49 "a",
50 "a b",
51 "a\\ b",
52 "a \\ b",
53 "a \\ b\\ ",
54 "\\ ",
55 "a|b",
56 "a\\|b",
57 "\"a b\"",
58 "\"\\\"\"",
59 "\\ \"a \"",
60 "\"a | b\"",
61 "\"a | b\"|c",
63 const char *arg_values[][3] = {
64 { "a", NULL },
65 { "a", "b", NULL },
66 { "a b", NULL },
67 { "a", " b", NULL },
68 { "a", " b ", NULL },
69 { " ", NULL },
70 { "a", NULL },
71 { "a|b", NULL },
72 { "a b", NULL },
73 { "\"", NULL },
74 { " a ", NULL },
75 { "a | b", NULL},
76 { "a | b", NULL},
78 int arg_counter[] = {
93 const char *shell[] = {
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 "b",
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL,
109 INIT_TEST("completion");
111 for (int i = 0; i < sizeof(line)/sizeof(line[0]); i++) {
112 TEST(line[i], test_completion,
113 line[i], arg_values[i], arg_counter[i], shell[i]);
116 SUM_TEST();