gux/lang/tests/value.c

30 lines
858 B
C

#include <criterion/criterion.h>
#include <value.h>
static void test_bool_ops(int lhs_val, int rhs_val,
struct value* (*op)(struct value*, struct value*),
int oracle)
{
struct value lhs;
value_init_bool(&lhs, lhs_val, 0);
struct value rhs;
value_init_bool(&rhs, rhs_val, 0);
struct value* res = op(&lhs, &rhs);
cr_assert_neq(res, NULL);
cr_assert(type_equals(&lhs.type, &res->type));
cr_assert_eq(res->data.b, oracle);
value_free(&rhs);
value_free(&lhs);
value_free(res);
}
Test(value, booleans_ops) {
test_bool_ops(VAL_TRUE, VAL_TRUE, &value_try_new_and, VAL_TRUE);
test_bool_ops(VAL_TRUE, VAL_FALSE, &value_try_new_and, VAL_FALSE);
test_bool_ops(VAL_FALSE, VAL_TRUE, &value_try_new_and, VAL_FALSE);
test_bool_ops(VAL_FALSE, VAL_FALSE, &value_try_new_and, VAL_FALSE);
}