Hash :
5842dc1e
Author :
Thomas de Grivel
Date :
2024-03-04T20:47:29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
/* c3
* Copyright 2022-2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include "../libc3/call.h"
#include "../libc3/compare.h"
#include "../libc3/env.h"
#include "../libc3/frame.h"
#include "../libc3/list.h"
#include "../libc3/sym.h"
#include "../libc3/tag.h"
#include "test.h"
void env_test (void);
TEST_CASE_PROTOTYPE(env_eval_call);
TEST_CASE_PROTOTYPE(env_eval_equal_tag);
TEST_CASE_PROTOTYPE(env_eval_tag);
TEST_CASE_PROTOTYPE(env_init_clean);
void env_test (void)
{
TEST_CASE_RUN(env_init_clean);
TEST_CASE_RUN(env_eval_equal_tag);
TEST_CASE_RUN(env_eval_call);
TEST_CASE_RUN(env_eval_tag);
}
TEST_CASE(env_eval_call)
{
s_env env;
s_call call;
s_tag result;
s_tag expected;
env_init(&env, 0, NULL);
test_context("env_eval_call(1 + 2) -> 3");
call_init(&call);
call.ident.module = sym_1("C3");
call.ident.sym = sym_1("operator_add");
call.arguments = list_new_1("[1, 2]");
tag_init_u8(&expected, 3);
TEST_ASSERT(env_eval_call(&env, &call, &result));
TEST_EQ(compare_tag(&result, &expected), 0);
call_clean(&call);
tag_clean(&result);
tag_clean(&expected);
env_clean(&env);
test_context(NULL);
}
TEST_CASE_END(env_eval_call)
TEST_CASE(env_eval_equal_tag)
{
s_env env;
s_frame frame;
s_tag x;
s_tag y;
s_tag z;
env_init(&env, 0, NULL);
env.frame = frame_init(&frame, env.frame);
test_context("x = 1");
TEST_ASSERT(env_eval_equal_tag(&env, false,
tag_init_1(&x, "x"),
tag_init_1(&y, "1"),
&z));
TEST_ASSERT(frame_get(&frame, x.data.ident.sym));
TEST_EQ(compare_tag(&z, &y), 0);
tag_clean(&z);
env.frame = frame_clean(&frame);
env_clean(&env);
env_init(&env, 0, NULL);
env.frame = frame_init(&frame, env.frame);
test_context("x = (1, 2]");
TEST_ASSERT(env_eval_equal_tag(&env, false,
tag_init_1(&x, "x"),
tag_init_1(&y, "[1, 2]"),
&z));
TEST_ASSERT(frame_get(&frame, sym_1("x")));
TEST_EQ(compare_tag(&z, &y), 0);
tag_clean(&z);
env.frame = frame_clean(&frame);
env_clean(&env);
env_init(&env, 0, NULL);
env.frame = frame_init(&frame, env.frame);
test_context("[] = []");
TEST_ASSERT(env_eval_equal_tag(&env, false,
tag_1(&x, "[]"),
tag_1(&y, "[]"),
&z));
TEST_EQ(compare_tag(&z, &y), 0);
tag_clean(&z);
env.frame = frame_clean(&frame);
env_clean(&env);
env_init(&env, 0, NULL);
env.frame = frame_init(&frame, env.frame);
test_context("[a, b] = [1, 2]");
TEST_ASSERT(env_eval_equal_tag(&env, false,
tag_1(&x, "[a, b]"),
tag_1(&y, "[1, 2]"),
&z));
TEST_ASSERT(frame_get(&frame, sym_1("a")));
TEST_ASSERT(frame_get(&frame, sym_1("b")));
TEST_EQ(compare_tag(&z, &y), 0);
tag_clean(&z);
env.frame = frame_clean(&frame);
env_clean(&env);
env_init(&env, 0, NULL);
env.frame = frame_init(&frame, env.frame);
test_context("x = [1, 2]");
TEST_ASSERT(env_eval_equal_tag(&env, false,
tag_1(&x, "[a | b]"),
tag_1(&y, "[1, 2]"),
&z));
TEST_ASSERT(frame_get(&frame, sym_1("a")));
TEST_ASSERT(frame_get(&frame, sym_1("b")));
TEST_EQ(compare_tag(&z, &y), 0);
tag_clean(&z);
env.frame = frame_clean(&frame);
env_clean(&env);
tag_clean(&x);
tag_clean(&y);
test_context(NULL);
}
TEST_CASE_END(env_eval_equal_tag)
TEST_CASE(env_eval_tag)
{
s_env env;
s_tag x;
s_tag y;
s_tag expected;
env_init(&env, 0, NULL);
test_context("env_eval_tag(1 + 2) -> 3");
TEST_EQ(tag_init_1(&x, "1 + 2"), &x);
TEST_EQ(tag_init_1(&expected, "3"), &expected);
TEST_ASSERT(env_eval_tag(&env, &x, &y));
TEST_EQ(compare_tag(&y, &expected), 0);
tag_clean(&x);
tag_clean(&y);
tag_clean(&expected);
env_clean(&env);
test_context(NULL);
}
TEST_CASE_END(env_eval_tag)
TEST_CASE(env_init_clean)
{
s_env env;
env_init(&env, 0, NULL);
env_clean(&env);
}
TEST_CASE_END(env_init_clean)