diff options
| author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-08-21 08:35:32 +0100 | 
|---|---|---|
| committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-08-21 08:35:32 +0100 | 
| commit | 742f19886cce986d0d01606b07dd533fbffe2cdd (patch) | |
| tree | bc6d84335362240ea7384bd44532d18e770def37 | |
| parent | e9eaba12d196e0b526fb24f549466ce76168634b (diff) | |
| download | alisp-742f19886cce986d0d01606b07dd533fbffe2cdd.tar.gz alisp-742f19886cce986d0d01606b07dd533fbffe2cdd.tar.bz2 alisp-742f19886cce986d0d01606b07dd533fbffe2cdd.zip  | |
Designed tests for make_int and intern with their destructors
| -rw-r--r-- | alisp.org | 2 | ||||
| -rw-r--r-- | main.c | 37 | 
2 files changed, 37 insertions, 2 deletions
@@ -42,7 +42,7 @@ perspective.  Should we capitalise symbols?  This way, we limit the symbol table's  possible options a bit (potentially we could design a better hashing  algorithm?) and it would be kinda like an actual Lisp. -** TODO Test value constructors and destructors :test: +** DONE Test value constructors and destructors :test:  Test if ~make_int~ works with ~as_int,~ ~intern~ with ~as_sym~.  Latter will require a symbol table.  ** TODO Test containers constructors and destructors :test: @@ -26,7 +26,7 @@ sv_t sv_copy(sv_t old)    return SV(newstr, old.size);  } -const char *words[] = { +char *words[] = {      "aliquam",      "erat",      "volutpat",  "nunc",      "eleifend",      "leo",          "vitae",     "magna",     "in",        "id",      "erat",         "non",       "orci",      "commodo",   "lobortis", @@ -80,10 +80,45 @@ void symtable_test(void)    sym_table_cleanup(&table);  } +void make_int_test(void) +{ +  i64 ints[] = { +      1,       -1,      (1 << 10) - 1, (-1) * ((1 << 10) - 1), +      INT_MIN, INT_MAX, INT64_MAX,     INT64_MIN, +  }; + +  for (u64 i = 0; i < ARRSIZE(ints); ++i) +  { +    i64 in       = ints[i]; +    lisp_t *lisp = make_int(in); +    i64 out      = as_int(lisp); + +    printf("[make_int_test]: %#16lx => %#16lx => %#16lx\n", in, (u64)lisp, out); +  } +} + +void intern_test(void) +{ +  sys_t system = {0}; +  sys_init(&system); +  for (u64 i = 0; i < ARRSIZE(words); ++i) +  { +    char *in     = words[i]; +    lisp_t *lisp = intern(&system, SV(in, strlen(in))); +    char *out    = as_sym(lisp); +    printf("[intern test]: `%s` -> %p -> `%s`\n", in, lisp, out); +  } +  sys_cleanup(&system); +} +  int main(void)  {    vec_test();    printf("\n");    symtable_test(); +  printf("\n"); +  make_int_test(); +  printf("\n"); +  intern_test();    return 0;  }  | 
