aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 21:27:01 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 21:27:01 +0100
commited37f7cd80ce92a03ef3fccbbc3246addb29e2e1 (patch)
treeffe6f555fe9284ddd2ee916512726f95a9d17fa3
parent29b18bc1de689f9339f82a9ceb30cad5157b7f56 (diff)
downloadalisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.tar.gz
alisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.tar.bz2
alisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.zip
cons_test written
-rw-r--r--alisp.org1
-rw-r--r--main.c38
2 files changed, 35 insertions, 4 deletions
diff --git a/alisp.org b/alisp.org
index 45e7432..463c429 100644
--- a/alisp.org
+++ b/alisp.org
@@ -49,6 +49,7 @@ Test if ~make_vec~ works with ~as_vec~, ~cons~ with ~as_cons~ AND
We may need to think of effective ways to deal with NILs in ~car~ and
~cdr~. Maybe make functions as well as the macros so I can choose
between them?
+*** TODO Write more tests
** TODO Test system registration of allocated units :test:
In particular, does clean up work as we expect? Do we have situations
where we may double free or not clean up something we should've?
diff --git a/main.c b/main.c
index ba0f33a..4c3796d 100644
--- a/main.c
+++ b/main.c
@@ -126,6 +126,11 @@ void intern_test(void)
void make_vec_test(void)
{
+
+ sys_t system = {0};
+ sys_init(&system);
+
+ // Generating substrings
struct Test
{
u64 start, size;
@@ -135,10 +140,6 @@ void make_vec_test(void)
{32, 64},
{0, ARRSIZE(text)},
};
-
- sys_t system = {0};
- sys_init(&system);
-
for (u64 i = 0; i < ARRSIZE(tests); ++i)
{
struct Test test = tests[i];
@@ -155,6 +156,33 @@ void make_vec_test(void)
sys_cleanup(&system);
}
+void cons_test(void)
+{
+ sys_t system = {0};
+ sys_init(&system);
+
+ // Iterate through each "word" in words, make a large contiguous list which is
+ // its reverse
+ lisp_t *lisp = NIL;
+ for (u64 i = 0; i < ARRSIZE(words); ++i)
+ {
+ char *word = words[i];
+ lisp_t *lword = intern(&system, SV(word, strlen(word)));
+ lisp = cons(&system, lword, lisp);
+ }
+
+ // Then iterate through it
+ printf("[cons_test]: ");
+ for (lisp_t *iter = lisp; iter; iter = cdr(iter))
+ {
+ lisp_t *item = car(iter);
+ printf("%s ", as_sym(item));
+ }
+ printf("\n");
+
+ sys_cleanup(&system);
+}
+
int main(void)
{
vec_test();
@@ -166,5 +194,7 @@ int main(void)
intern_test();
printf("\n");
make_vec_test();
+ printf("\n");
+ cons_test();
return 0;
}