gux/lang/tests/type.c

64 lines
1.2 KiB
C
Raw Normal View History

2024-02-10 15:16:00 +00:00
#include "commons.h"
#include <criterion/criterion.h>
#include <type.h>
Test(type, atomic_type) {
struct type ty;
type_init(&ty, TYPE_BOOL);
char buf[GUX_STR_SIZE];
type_str(&ty, buf, GUX_STR_SIZE);
cr_assert_str_eq(buf, "BOOL");
type_free(&ty);
}
Test(type, compound_type) {
struct type ty;
type_init(&ty, TYPE_BOOL);
type_add_subtype(&ty, TYPE_VOID);
type_add_subtype(&ty, TYPE_BOOL);
char buf[GUX_STR_SIZE];
type_str(&ty, buf, GUX_STR_SIZE);
cr_assert_str_eq(buf, "BOOL(VOID,BOOL)");
type_free(&ty);
}
Test(type, equals) {
struct type lhs;
type_init(&lhs, TYPE_BOOL);
type_add_subtype(&lhs, TYPE_VOID);
type_add_subtype(&lhs, TYPE_BOOL);
struct type rhs;
type_init(&rhs, TYPE_BOOL);
type_add_subtype(&rhs, TYPE_VOID);
type_add_subtype(&rhs, TYPE_BOOL);
cr_assert(type_equals(&lhs, &rhs));
type_free(&rhs);
type_free(&lhs);
}
Test(type, no_equals) {
struct type lhs;
type_init(&lhs, TYPE_BOOL);
type_add_subtype(&lhs, TYPE_VOID);
type_add_subtype(&lhs, TYPE_BOOL);
struct type rhs;
type_init(&rhs, TYPE_BOOL);
type_add_subtype(&rhs, TYPE_BOOL);
type_add_subtype(&rhs, TYPE_BOOL);
cr_assert(!type_equals(&lhs, &rhs));
type_free(&rhs);
type_free(&lhs);
}