From 4c779e9e8b8dd46f481a26505cac0d11afa411d9 Mon Sep 17 00:00:00 2001 From: cozis Date: Sun, 6 Mar 2022 17:17:23 +0100 Subject: [PATCH] more tests and boolean compare --- src/objects/o_bool.c | 12 ++++++++++++ tests/test.noja | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/objects/o_bool.c b/src/objects/o_bool.c index 8e284a7..ccf5152 100644 --- a/src/objects/o_bool.c +++ b/src/objects/o_bool.c @@ -4,6 +4,7 @@ static _Bool to_bool(Object *obj, Error *err); static void print(Object *obj, FILE *fp); +static _Bool op_eql(Object *self, Object *other); static TypeObject t_bool = { .base = (Object) { .type = &t_type, .flags = Object_STATIC }, @@ -12,6 +13,7 @@ static TypeObject t_bool = { .atomic = ATMTP_BOOL, .to_bool = to_bool, .print = print, + .op_eql = op_eql, }; static Object the_true_object = { @@ -24,6 +26,16 @@ static Object the_false_object = { .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) { assert(obj); diff --git a/tests/test.noja b/tests/test.noja index 1bf5b4a..24b8ad8 100644 --- a/tests/test.noja +++ b/tests/test.noja @@ -44,4 +44,36 @@ 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'); \ No newline at end of file