more tests and boolean compare
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
static _Bool to_bool(Object *obj, Error *err);
|
static _Bool to_bool(Object *obj, Error *err);
|
||||||
static void print(Object *obj, FILE *fp);
|
static void print(Object *obj, FILE *fp);
|
||||||
|
static _Bool op_eql(Object *self, Object *other);
|
||||||
|
|
||||||
static TypeObject t_bool = {
|
static TypeObject t_bool = {
|
||||||
.base = (Object) { .type = &t_type, .flags = Object_STATIC },
|
.base = (Object) { .type = &t_type, .flags = Object_STATIC },
|
||||||
@@ -12,6 +13,7 @@ static TypeObject t_bool = {
|
|||||||
.atomic = ATMTP_BOOL,
|
.atomic = ATMTP_BOOL,
|
||||||
.to_bool = to_bool,
|
.to_bool = to_bool,
|
||||||
.print = print,
|
.print = print,
|
||||||
|
.op_eql = op_eql,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Object the_true_object = {
|
static Object the_true_object = {
|
||||||
@@ -24,6 +26,16 @@ static Object the_false_object = {
|
|||||||
.flags = Object_STATIC,
|
.flags = Object_STATIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static _Bool op_eql(Object *self, Object *other)
|
||||||
|
{
|
||||||
|
assert(self != NULL);
|
||||||
|
assert(self->type == &t_bool);
|
||||||
|
assert(other != NULL);
|
||||||
|
assert(other->type == &t_bool);
|
||||||
|
|
||||||
|
return self == other;
|
||||||
|
}
|
||||||
|
|
||||||
static _Bool to_bool(Object *obj, Error *err)
|
static _Bool to_bool(Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(obj);
|
assert(obj);
|
||||||
|
|||||||
@@ -44,4 +44,36 @@
|
|||||||
assert(4.0 != 3.0);
|
assert(4.0 != 3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Test operations on strings.
|
||||||
|
{
|
||||||
|
assert('hey' == 'hey');
|
||||||
|
assert('hey' != 'hey2');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test operations on bools.
|
||||||
|
{
|
||||||
|
assert(true);
|
||||||
|
assert(true == true);
|
||||||
|
assert(true != false);
|
||||||
|
assert(false == false);
|
||||||
|
assert(false != true);
|
||||||
|
assert(true == not false);
|
||||||
|
assert(false == not true);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test if-else statements.
|
||||||
|
{
|
||||||
|
if true: r = true; else r = false;
|
||||||
|
assert(r);
|
||||||
|
|
||||||
|
if true: { r = true; } else { r = false; }
|
||||||
|
assert(r);
|
||||||
|
|
||||||
|
if false: r = false; else r = true;
|
||||||
|
assert(r);
|
||||||
|
|
||||||
|
if false: { r = false; } else { r = true; }
|
||||||
|
assert(r);
|
||||||
|
}
|
||||||
|
|
||||||
print('No assertion failed.\n');
|
print('No assertion failed.\n');
|
||||||
Reference in New Issue
Block a user