Commit 5b270621 authored by Chris Müller's avatar Chris Müller
Browse files

add testcases for environments

parent dc7d5135
......@@ -19,21 +19,78 @@
#include <crystal/unittest.h>
#include <cherry/runtime.h>
static void test_initialization(const_pointer data)
{
assert(IS_NULL(org_cherry_symbol_emptylist));
assert(IS_BOOLEAN(org_cherry_true));
assert(IS_BOOLEAN(org_cherry_false));
assert(IS_SYMBOL(org_cherry_symbol_quote));
assert(IS_SYMBOL(org_cherry_symbol_define));
assert(IS_SYMBOL(org_cherry_symbol_lambda));
assert(IS_SYMBOL(org_cherry_symbol_if));
assert(IS_SYMBOL(org_cherry_symbol_cond));
assert(IS_SYMBOL(org_cherry_symbol_else));
}
static void test_symbollist(const_pointer data)
{
struct org_cherry_symbollist* sym = org_cherry_symbollist();
struct org_cherry_Value* A = org_cherry_symbollist_get(sym, "A");
struct org_cherry_Value* B = org_cherry_symbollist_get(sym, "B");
struct org_cherry_Value* C = org_cherry_symbollist_get(sym, "A");
struct org_cherry_value* A = org_cherry_symbollist_get(sym, "A");
struct org_cherry_value* B = org_cherry_symbollist_get(sym, "B");
struct org_cherry_value* C = org_cherry_symbollist_get(sym, "A");
assert(A != B);
assert(A == C);
assert(B != C);
}
static void test_symbols(const_pointer data)
{
struct org_cherry_value* A = org_cherry_symbol("A");
struct org_cherry_value* B = org_cherry_symbol("B");
struct org_cherry_value* C = org_cherry_symbol("A");
assert(A != B);
assert(A == C);
assert(B != C);
}
static void test_environment(const_pointer data)
{
struct org_cherry_symbollist* env = org_cherry_symbollist();
assert(org_cherry_env_add(env, org_cherry_symbol("A"), org_cherry_fixnum(10)));
assert(org_cherry_env_add(env, org_cherry_symbol("B"), org_cherry_true));
assert(org_cherry_env_lookup(env, org_cherry_symbol("A"))->meta.type == CY_FIXNUM);
assert(org_cherry_env_lookup(env, org_cherry_symbol("A"))->fixnum_value == 10);
assert(org_cherry_env_lookup(env, org_cherry_symbol("B"))->meta.type == CY_BOOLEAN);
assert(org_cherry_env_lookup(env, org_cherry_symbol("B")) == org_cherry_true);
env = org_cherry_env_push(env);
assert(org_cherry_env_add(env, org_cherry_symbol("B"), org_cherry_fixnum(15)));
assert(org_cherry_env_lookup(env, org_cherry_symbol("B"))->meta.type == CY_FIXNUM);
assert(org_cherry_env_lookup(env, org_cherry_symbol("B"))->fixnum_value == 15);
assert(org_cherry_env_lookup(env, org_cherry_symbol("A"))->meta.type == CY_FIXNUM);
assert(org_cherry_env_lookup(env, org_cherry_symbol("A"))->fixnum_value == 10);
env = org_cherry_env_pop(env);
assert(org_cherry_env_lookup(env, org_cherry_symbol("B"))->meta.type != CY_FIXNUM);
}
void test_suite_runtime()
{
cry_unittest_run("org.cherry.runtime/initialize", test_initialization, 0, 100);
cry_unittest_run("org.cherry.runtime/symbols", test_symbols, 0, 100);
cry_unittest_run("org.cherry.runtime/symbollist", test_symbollist, 0, 100);
cry_unittest_run("org.cherry.runtime/environment", test_environment, 0, 100);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment