Skip to content

Commit

Permalink
Fix malformed list tail on Read
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmdln committed Nov 9, 2023
1 parent 17d35c7 commit 9437cfb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ read_form(size_t *index, char const **input)

if (!object) return Error("read_form: object is NULL");
if (object->type == ERROR) return object;

objects = Cons(object, objects);
if (object->type == NIL) break;
objects = Cons(object, objects);
}

*input = cursor;
Expand Down
9 changes: 5 additions & 4 deletions test/core/read.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <assert.h>
#include <stdlib.h>

#include <gc/gc.h>
#include <string.h>

#include <ploy.h>

Expand All @@ -12,17 +11,18 @@ main(void)
assert(null != NULL);
assert(null->type == ERROR);

Object *nil = Read("\0");
Object *nil = Read("");
assert(nil != NULL);
assert(nil->type == NIL);

Object *list = Cons(Number(42), Cons(String("wew"), Nil));
Object *list = Car(Read("(42 \"wew\")"));
assert(list != NULL);
assert(list->type == LIST);

Object *car = Car(list);
assert(car != NULL);
assert(car->type == NUMBER);
assert(car->number == 42);

Object *cdr = Cdr(list);
assert(cdr != NULL);
Expand All @@ -31,6 +31,7 @@ main(void)
Object *cadr = Car(cdr);
assert(cadr != NULL);
assert(cadr->type == STRING);
assert(strcmp(cadr->string, "wew") == 0);

Object *cddr = Cdr(cdr);
assert(cddr != NULL);
Expand Down

0 comments on commit 9437cfb

Please sign in to comment.