src/server/test/object.c

Tue, 12 Sep 2023 18:08:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 12 Sep 2023 18:08:11 +0200
changeset 511
a5a142fea2ae
parent 490
d218607f5a7e
permissions
-rw-r--r--

update uwproj

423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "../util/object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <cx/linked_list.h>
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <cx/compare.h>
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 UCX_TEST(test_expr_parse_expr_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
42 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 cxstring token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
424
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
60 UCX_TEST(test_expr_parse_expr_neg_value) {
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
61 pool_handle_t *pool = pool_create();
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
62
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
63 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
424
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
64 cxstring token = cx_str("-123");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
65 cxListAdd(tokens, &token);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
66
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
67 UCX_TEST_BEGIN;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
68
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
69 size_t pos = 0;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
70 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
71
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
72 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
73 UCX_TEST_ASSERT(expr, "expression is null");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
74 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
75 UCX_TEST_ASSERT(expr->value.i == -123, "wrong value");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
76
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
77 UCX_TEST_END;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
78
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
79 pool_destroy(pool);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
80 }
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
81
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 UCX_TEST(test_expr_parse_expr_value_str) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
85 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 cxstring token = cx_str("\"hello world\"");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_STRING, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 UCX_TEST_ASSERT(!cx_strcmp(expr->value.str, cx_str("hello world")), "wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 UCX_TEST(test_expr_parse_expr_value_bool) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
107 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 cxstring token = cx_str("true");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BOOL, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 UCX_TEST_ASSERT(expr->value.b == 1, "wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 UCX_TEST(test_expr_parse_expr_value_var) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
129 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 cxstring token = cx_str("$test");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_VARIABLE, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 UCX_TEST_ASSERT(!cx_strcmp(expr->value.var, cx_str("test")), "wrong var name");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 UCX_TEST(test_expr_parse_expr_not_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
151 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 cxstring token = cx_str("not");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 token = cx_str("true");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 UCX_TEST_ASSERT(pos == 2, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong root expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 UCX_TEST_ASSERT(expr->left, "missing left expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 UCX_TEST_ASSERT(!expr->right, "right expression should be null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL, "left expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 UCX_TEST_ASSERT(expr->left->value.b == 1, "left expression has wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UCX_TEST(test_expr_parse_expr_sign_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
179 CxList *tokens1 = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 cxstring token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 cxListAdd(tokens1, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 cxListAdd(tokens1, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
185 CxList *tokens2 = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 token = cx_str("-");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 cxListAdd(tokens2, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 cxListAdd(tokens2, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens1, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 UCX_TEST_ASSERT(pos == 2, "test1: wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 UCX_TEST_ASSERT(expr, "test1: expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 expr = expr_parse_logical_expr(pool, tokens2, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 UCX_TEST_ASSERT(pos == 2, "test2: wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 UCX_TEST_ASSERT(expr, "test2: expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_SUB, "wrong expression operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 UCX_TEST_ASSERT(expr->left, "missing left expresion");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_INT, "left expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 UCX_TEST_ASSERT(expr->left->value.i == 123, "left expression has wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 UCX_TEST(test_expr_parse_expr_compare2values) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
221 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 UCX_TEST_ASSERT(pos == 3, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 UCX_TEST(test_expr_parse_expr_compare2value_expr) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
252 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 UCX_TEST_ASSERT(pos == 5, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_ADD, "right should be a binary expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 UCX_TEST(test_expr_parse_expr_compare2expr_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
287 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 cxstring token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 UCX_TEST_ASSERT(pos == 5, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 UCX_TEST_ASSERT(expr->right->value.i == 2, "right wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_ADD, "left should be a binary operation");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be NOOP");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 UCX_TEST_ASSERT(expr->left->left, "ADD-op missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 UCX_TEST_ASSERT(expr->left->right, "ADD-op missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 UCX_TEST_ASSERT(expr->left->left->value.i == 1, "ADD-op: wrong left value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 UCX_TEST_ASSERT(expr->left->right->value.i == 1, "ADD-op: wrong right value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 UCX_TEST(test_expr_parse_expr_bracket) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 // expression: 2 * (1 + 2) == 6
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
328 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 token = cx_str("*");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 token = cx_str("(");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 token = cx_str(")");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 token = cx_str("6");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 UCX_TEST_ASSERT(pos == 9, "wrong token pos");
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
354 UCX_TEST_ASSERT(expr, "expression is null");
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ, "root: wrong operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 UCX_TEST_ASSERT(expr->left, "missing left expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 UCX_TEST_ASSERT(expr->right, "missing right expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 UCX_TEST_ASSERT(expr->right->type == NSAPI_EXPRESSION_INT, "right expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_MUL, "left expression has wrong operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 UCX_TEST_ASSERT(expr->left->left, "mul: missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 UCX_TEST_ASSERT(expr->left->right, "mul: missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 UCX_TEST_ASSERT(expr->left->right->operator == NSAPI_EXPRESSION_ADD, "missing add operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 UCX_TEST_ASSERT(expr->left->right->left, "add: missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 UCX_TEST_ASSERT(expr->left->right->left, "add: missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 }
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
370
452
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
371 UCX_TEST(test_expr_op_defined_simple) {
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
372 pool_handle_t *pool = pool_create();
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
373
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
374 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
452
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
375 cxstring token = cx_str("defined");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
376 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
377
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
378 token = cx_str("$testvar1");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
379 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
380
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
381 UCX_TEST_BEGIN;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
382
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
383 size_t pos = 0;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
384 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
385
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
386 UCX_TEST_ASSERT(pos == 2, "wrong token pos");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
387 UCX_TEST_ASSERT(expr, "expression is null");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
388 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong type");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
389 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_VALUE_DEFINED, "wrong operator");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
390 UCX_TEST_ASSERT(expr->left, "missing left operand");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
391 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_VARIABLE, "operand is not a variable");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
392
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
393 UCX_TEST_END;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
394
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
395 pool_destroy(pool);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
396 }
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
397
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
398 UCX_TEST(test_expr_op_defined) {
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
399 pool_handle_t *pool = pool_create();
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
400
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
401 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
452
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
402 cxstring token = cx_str("true");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
403 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
404
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
405 token = cx_str("==");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
406 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
407
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
408 token = cx_str("not");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
409 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
410
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
411 token = cx_str("defined");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
412 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
413
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
414 token = cx_str("$var");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
415 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
416
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
417 UCX_TEST_BEGIN;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
418
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
419 size_t pos = 0;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
420 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
421
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
422 UCX_TEST_ASSERT(pos == 5, "wrong token pos");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
423 UCX_TEST_ASSERT(expr, "expression is null");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
424 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ, "wrong operator");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
425 UCX_TEST_ASSERT(expr->left, "missing left");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
426 UCX_TEST_ASSERT(expr->right, "missing right");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
427 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL, "left expression is not a bool");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
428 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOT, "right: wrong operator");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
429 UCX_TEST_ASSERT(expr->right->left, "not op: missing left");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
430 UCX_TEST_ASSERT(expr->right->left->operator == NSAPI_EXPRESSION_VALUE_DEFINED, "missing defined operator");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
431
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
432 UCX_TEST_END;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
433
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
434 pool_destroy(pool);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
435 }
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
436
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
437 UCX_TEST(test_expr_op_file_exists_simple) {
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
438 pool_handle_t *pool = pool_create();
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
439
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
440 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
452
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
441 cxstring token = cx_str("-e");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
442 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
443
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
444 token = cx_str("\"/path/file\"");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
445 cxListAdd(tokens, &token);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
446
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
447 UCX_TEST_BEGIN;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
448
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
449 size_t pos = 0;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
450 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
451
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
452 UCX_TEST_ASSERT(pos == 2, "wrong token pos");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
453 UCX_TEST_ASSERT(expr, "expression is null");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
454 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong type");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
455 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_FILE_DIR_EXISTS, "wrong operator");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
456 UCX_TEST_ASSERT(expr->left, "missing left operand");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
457 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_STRING, "operand is not a string");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
458 UCX_TEST_ASSERT(!cx_strcmp(expr->left->value.str, cx_str("/path/file")), "wrong string operand");
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
459
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
460 UCX_TEST_END;
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
461
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
462 pool_destroy(pool);
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
463 }
ce359a2b51fe implement most nsapi expression operators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 435
diff changeset
464
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
465 UCX_TEST(test_expr_parse_expr_func_arg0) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
466 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
467
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
468 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
469 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
470 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
471 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
472 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
473 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
474 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
475
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
476 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
477
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
478 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
479 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
480
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
481 UCX_TEST_ASSERT(pos == 3, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
482 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
483 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
484 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
485 UCX_TEST_ASSERT(!expr->left, "left is not null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
486 UCX_TEST_ASSERT(!expr->right, "right is not null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
487
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
488 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
489
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
490 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
491 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
492
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
493
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
494 int test_get_args(NSAPIExpression *arglist, size_t maxArgs, size_t *numArgs, NSAPIExpression *arg) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
495 if(!arg) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
496 return 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
497 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
498 if(arg->operator == NSAPI_EXPRESSION_ARG) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
499 if(arg->left) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
500 if(test_get_args(arglist, maxArgs, numArgs, arg->left)) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
501 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
502 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
503 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
504 if(arg->right) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
505 if(test_get_args(arglist, maxArgs, numArgs, arg->right)) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
506 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
507 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
508 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
509 } else {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
510 if(*numArgs >= maxArgs) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
511 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
512 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
513 arglist[*numArgs] = *arg;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
514 (*numArgs)++;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
515 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
516
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
517 return 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
518 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
519
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
520
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
521 UCX_TEST(test_expr_parse_expr_func_arg1) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
522 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
523
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
524 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
525 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
526 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
527 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
528 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
529 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
530 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
531 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
532 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
533
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
534 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
535
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
536 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
537 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
538
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
539 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
540 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
541 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
542 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
543
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
544 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
545 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
546 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
547 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
548 UCX_TEST_ASSERT(numArgs == 1, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
549 UCX_TEST_ASSERT(args[0].value.i == 1, "wrong arg value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
550
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
551 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
552
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
553 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
554 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
555
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
556 UCX_TEST(test_expr_parse_expr_func_arg3) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
557 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
558
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
559 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
560 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
561 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
562 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
563 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
564 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
565 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
566 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
567 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
568 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
569 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
570 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
571 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
572 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
573 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
574 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
575 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
576
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
577 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
578
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
579 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
580 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
581
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
582 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
583 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
584 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
585 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
586
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
587 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
588 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
589 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
590 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
591 UCX_TEST_ASSERT(numArgs == 3, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
592 UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
593 UCX_TEST_ASSERT(args[1].value.i == 2, "arg1: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
594 UCX_TEST_ASSERT(args[2].value.i == 3, "arg2: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
595
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
596 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
597
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
598 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
599 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
600
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
601 UCX_TEST(test_expr_parse_expr_func_expr1) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
602 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
603
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
604 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
605 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
606 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
607 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
608 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
609 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
610 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
611 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
612 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
613 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
614 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
615 token = cx_str("+");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
616 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
617 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
618 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
619 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
620 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
621
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
622 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
623
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
624 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
625 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
626
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
627 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
628 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
629 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
630 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
631
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
632 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
633 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
634 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
635 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
636 UCX_TEST_ASSERT(numArgs == 2, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
637 UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
638 UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_ADD, "arg1: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
639 UCX_TEST_ASSERT(args[1].left && args[1].right, "arg1: missing operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
640 UCX_TEST_ASSERT(args[1].left->value.i == 2 && args[1].right->value.i == 3, "arg1: wrong operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
641
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
642 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
643
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
644 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
645 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
646
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
647 UCX_TEST(test_expr_parse_expr_func_expr2) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
648 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
649
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 452
diff changeset
650 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring));
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
651 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
652 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
653 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
654 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
655 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
656 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
657 token = cx_str("+");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
658 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
659 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
660 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
661 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
662 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
663 token = cx_str("sub");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
664 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
665 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
666 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
667 token = cx_str("4");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
668 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
669 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
670 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
671 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
672 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
673 token = cx_str("6");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
674 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
675 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
676 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
677
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
678 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
679
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
680 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
681 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
682
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
683 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
684 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
685 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
686 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
687
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
688 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
689 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
690 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
691 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
692 UCX_TEST_ASSERT(numArgs == 3, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
693 UCX_TEST_ASSERT(args[0].operator == NSAPI_EXPRESSION_ADD, "arg0: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
694 UCX_TEST_ASSERT(args[0].left && args[0].right, "arg0: missing operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
695 UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_CALL, "arg1: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
696 UCX_TEST_ASSERT(args[1].left, "arg1: missing args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
697 UCX_TEST_ASSERT(args[2].type == NSAPI_EXPRESSION_INT, "arg2: wrong type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
698 UCX_TEST_ASSERT(args[2].value.i == 6, "arg2: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
699
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
700 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
701
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
702 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
703 }

mercurial