Hash :
83a9986c
Author :
Thomas de Grivel
Date :
2023-09-05T15:22:30
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
/* c3
* Copyright 2022,2023 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/compare.h"
#include "../libc3/env.h"
#include "../libc3/frame.h"
#include "../libc3/sym.h"
#include "../libc3/tag.h"
#include "test.h"
void env_test ();
TEST_CASE_PROTOTYPE(env_eval_equal_tag);
TEST_CASE_PROTOTYPE(env_init_clean);
void env_test ()
{
TEST_CASE_RUN(env_init_clean);
TEST_CASE_RUN(env_eval_equal_tag);
}
TEST_CASE(env_eval_equal_tag)
{
s_env env;
s_frame frame;
s_tag x;
s_tag y;
s_tag z;
env_init(&env);
env.frame = frame_init(&frame, env.frame);
test_context("x = 1");
TEST_ASSERT(env_eval_equal_tag(&env, 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);
env.frame = frame_init(&frame, env.frame);
test_context("x = (1, 2)");
TEST_ASSERT(env_eval_equal_tag(&env, 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);
env.frame = frame_init(&frame, env.frame);
test_context("() = ()");
TEST_ASSERT(env_eval_equal_tag(&env, 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);
env.frame = frame_init(&frame, env.frame);
test_context("(a, b) = (1, 2)");
TEST_ASSERT(env_eval_equal_tag(&env, 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);
env.frame = frame_init(&frame, env.frame);
test_context("x = (1, 2)");
TEST_ASSERT(env_eval_equal_tag(&env, 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_init_clean)
{
s_env env;
env_init(&env);
test_ok();
env_clean(&env);
test_ok();
}
TEST_CASE_END(env_init_clean)