diff options
| author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-08-21 21:27:01 +0100 | 
|---|---|---|
| committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-08-21 21:27:01 +0100 | 
| commit | ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1 (patch) | |
| tree | ffe6f555fe9284ddd2ee916512726f95a9d17fa3 | |
| parent | 29b18bc1de689f9339f82a9ceb30cad5157b7f56 (diff) | |
| download | alisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.tar.gz alisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.tar.bz2 alisp-ed37f7cd80ce92a03ef3fccbbc3246addb29e2e1.zip  | |
cons_test written
| -rw-r--r-- | alisp.org | 1 | ||||
| -rw-r--r-- | main.c | 38 | 
2 files changed, 35 insertions, 4 deletions
@@ -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? @@ -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;  }  | 
