1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
10 #include <ecoli_log.h>
11 #include <ecoli_test.h>
12 #include <ecoli_malloc.h>
13 #include <ecoli_strvec.h>
14 #include <ecoli_node.h>
15 #include <ecoli_parse.h>
16 #include <ecoli_complete.h>
17 #include <ecoli_node_space.h>
19 EC_LOG_TYPE_REGISTER(node_space);
21 struct ec_node_space {
26 ec_node_space_parse(const struct ec_node *gen_node,
27 struct ec_parse *state,
28 const struct ec_strvec *strvec)
36 if (ec_strvec_len(strvec) == 0)
37 return EC_PARSE_NOMATCH;
39 str = ec_strvec_val(strvec, 0);
40 while (isspace(str[len]))
42 if (len == 0 || len != strlen(str))
43 return EC_PARSE_NOMATCH;
48 static struct ec_node_type ec_node_space_type = {
50 .parse = ec_node_space_parse,
51 .complete = ec_node_complete_unknown,
52 .size = sizeof(struct ec_node_space),
55 EC_NODE_TYPE_REGISTER(ec_node_space_type);
58 static int ec_node_space_testcase(void)
63 node = ec_node("space", EC_NO_ID);
65 EC_LOG(EC_LOG_ERR, "cannot create node\n");
68 testres |= EC_TEST_CHECK_PARSE(node, 1, " ");
69 testres |= EC_TEST_CHECK_PARSE(node, 1, " ", "foo");
70 testres |= EC_TEST_CHECK_PARSE(node, -1, "");
71 testres |= EC_TEST_CHECK_PARSE(node, -1, " foo");
72 testres |= EC_TEST_CHECK_PARSE(node, -1, "foo ");
76 node = ec_node("space", EC_NO_ID);
78 EC_LOG(EC_LOG_ERR, "cannot create node\n");
81 /* never completes whatever the input */
82 testres |= EC_TEST_CHECK_COMPLETE(node,
85 testres |= EC_TEST_CHECK_COMPLETE(node,
88 testres |= EC_TEST_CHECK_COMPLETE(node,
89 "foo", EC_NODE_ENDLIST,
97 static struct ec_test ec_node_space_test = {
99 .test = ec_node_space_testcase,
102 EC_TEST_REGISTER(ec_node_space_test);