1 #include "util/debug.h"
6 static int test(struct parse_ctx *ctx, const char *e, double val2)
10 if (expr__parse(&val, ctx, &e))
11 TEST_ASSERT_VAL("parse test failed", 0);
12 TEST_ASSERT_VAL("unexpected value", val == val2);
16 int test__expr(int subtest __maybe_unused)
26 expr__add_id(&ctx, "FOO", 1);
27 expr__add_id(&ctx, "BAR", 2);
29 ret = test(&ctx, "1+1", 2);
30 ret |= test(&ctx, "FOO+BAR", 3);
31 ret |= test(&ctx, "(BAR/2)%2", 1);
32 ret |= test(&ctx, "1 - -4", 5);
33 ret |= test(&ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5);
39 ret = expr__parse(&val, &ctx, &p);
40 TEST_ASSERT_VAL("division by zero", ret == 1);
43 ret = expr__parse(&val, &ctx, &p);
44 TEST_ASSERT_VAL("missing operand", ret == 1);
46 TEST_ASSERT_VAL("find other",
47 expr__find_other("FOO + BAR + BAZ + BOZO", "FOO", &other, &num_other) == 0);
48 TEST_ASSERT_VAL("find other", num_other == 3);
49 TEST_ASSERT_VAL("find other", !strcmp(other[0], "BAR"));
50 TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
51 TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
52 TEST_ASSERT_VAL("find other", other[3] == NULL);