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 {
25 ec_node_space_parse(const struct ec_node *node,
26 struct ec_pnode *state,
27 const struct ec_strvec *strvec)
35 if (ec_strvec_len(strvec) == 0)
36 return EC_PARSE_NOMATCH;
38 str = ec_strvec_val(strvec, 0);
39 while (isspace(str[len]))
41 if (len == 0 || len != strlen(str))
42 return EC_PARSE_NOMATCH;
47 static struct ec_node_type ec_node_space_type = {
49 .parse = ec_node_space_parse,
50 .complete = ec_complete_unknown,
51 .size = sizeof(struct ec_node_space),
54 EC_NODE_TYPE_REGISTER(ec_node_space_type);
57 static int ec_node_space_testcase(void)
62 node = ec_node("space", EC_NO_ID);
64 EC_LOG(EC_LOG_ERR, "cannot create node\n");
67 testres |= EC_TEST_CHECK_PARSE(node, 1, " ");
68 testres |= EC_TEST_CHECK_PARSE(node, 1, " ", "foo");
69 testres |= EC_TEST_CHECK_PARSE(node, -1, "");
70 testres |= EC_TEST_CHECK_PARSE(node, -1, " foo");
71 testres |= EC_TEST_CHECK_PARSE(node, -1, "foo ");
75 node = ec_node("space", EC_NO_ID);
77 EC_LOG(EC_LOG_ERR, "cannot create node\n");
80 /* never completes whatever the input */
81 testres |= EC_TEST_CHECK_COMPLETE(node,
84 testres |= EC_TEST_CHECK_COMPLETE(node,
87 testres |= EC_TEST_CHECK_COMPLETE(node,
96 static struct ec_test ec_node_space_test = {
98 .test = ec_node_space_testcase,
101 EC_TEST_REGISTER(ec_node_space_test);