#include "IPUlisp.h" #include #include #include static char output[128]; static void check(const char *source, int reset, int stress, int status, const char *expected) { int got = IPUlisp_eval(source, strlen(source), output, sizeof(output), 7, reset, stress); if (got != status || (expected && strcmp(output, expected))) { fprintf(stderr, "source: %s\nstatus: %d (expected %d)\noutput: %s\n", source, got, status, output); exit(1); } } int main(void) { for (int stress = 0; stress <= 1; ++stress) { check("(define value 42)", 1, stress, 0, "42\n"); check("value __tileid", 0, stress, 0, "42\n7\n"); const char *invalid[] = {"'", "(. 1)", "(1 .)", "(car)", "(cdr)", "(-)", "(println)", "(defun)", "(+ 1 . 2)", "unknown"}; for (unsigned i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i) { check(invalid[i], 0, stress, 1, NULL); check("value", 0, stress, 0, "42\n"); } check("(define i 0) (while (< i 300) (println i) (setq i (+ i 1)))", 0, stress, 2, NULL); if (output[sizeof(output) - 1] != 0) return 1; check("value", 0, stress, 0, "42\n"); char tiny[2] = {'x', 'y'}; if (IPUlisp_eval("42", 2, tiny, 1, 7, 0, stress) != 2 || tiny[0] || tiny[1] != 'y') return 1; if (IPUlisp_eval("42", 2, tiny, 0, 7, 0, stress) != 2) return 1; check("(+ value 1)", 0, stress, 0, "43\n"); } check("(define xs ()) (while t (setq xs (cons 1 xs)))", 1, 0, 1, NULL); if (!strstr(output, "Memory exhausted")) return 1; check("(+ 20 22)", 1, 0, 0, "42\n"); puts("API regression tests passed."); }