From fec7a34cdc55f226e69d98267e42fa4b52b0193c Mon Sep 17 00:00:00 2001 From: Mistivia Date: Sat, 21 Jun 2025 17:19:11 +0800 Subject: move test files --- Makefile | 8 ++++---- tests/arithmetic.lisp | 12 ++++++++++++ tests/comment.lisp | 8 ++++++++ tests/control-flow.lisp | 36 ++++++++++++++++++++++++++++++++++++ tests/lambda.lisp | 12 ++++++++++++ tests/let-binding.lisp | 7 +++++++ tests/lisp/arithmetic.lisp | 12 ------------ tests/lisp/comment.lisp | 8 -------- tests/lisp/control-flow.lisp | 36 ------------------------------------ tests/lisp/lambda.lisp | 12 ------------ tests/lisp/let-binding.lisp | 7 ------- tests/lisp/macro.lisp | 10 ---------- tests/lisp/test.lisp | 14 -------------- tests/macro.lisp | 10 ++++++++++ tests/test.lisp | 14 ++++++++++++++ 15 files changed, 103 insertions(+), 103 deletions(-) create mode 100644 tests/arithmetic.lisp create mode 100644 tests/comment.lisp create mode 100644 tests/control-flow.lisp create mode 100644 tests/lambda.lisp create mode 100644 tests/let-binding.lisp delete mode 100644 tests/lisp/arithmetic.lisp delete mode 100644 tests/lisp/comment.lisp delete mode 100644 tests/lisp/control-flow.lisp delete mode 100644 tests/lisp/lambda.lisp delete mode 100644 tests/lisp/let-binding.lisp delete mode 100644 tests/lisp/macro.lisp delete mode 100644 tests/lisp/test.lisp create mode 100644 tests/macro.lisp create mode 100644 tests/test.lisp diff --git a/Makefile b/Makefile index ec5b5da..5871061 100644 --- a/Makefile +++ b/Makefile @@ -29,13 +29,13 @@ bamboo-lisp: $(obj) src/main.c 3rdparty/algds/build/lib/libalgds.a cd 3rdparty/algds && \ make profile=$(mode) -test: $(tests_bin) +test: bamboo-lisp $(tests_bin) @echo @echo "Run tests:" - @scripts/runall.sh $^ + @scripts/runall.sh $(tests_bin) @echo "Run scripts:" - cd tests/lisp && \ - ../../bamboo-lisp test.lisp + cd tests/ && \ + ../bamboo-lisp test.lisp $(obj):%.o:%.c diff --git a/tests/arithmetic.lisp b/tests/arithmetic.lisp new file mode 100644 index 0000000..2764b10 --- /dev/null +++ b/tests/arithmetic.lisp @@ -0,0 +1,12 @@ +(assert (= 1 (+ 1 0))) +(assert (= -1 (- 0 1))) +(assert (= -1 (- 1))) +(assert (= 1.1 (+ 1 0.1))) +(assert (= 2 (i/ 11 5))) +(assert (= 1 (mod 11 5))) + +(assert-error (+ 1 "a")) +(assert-error (- 1 "a")) +(assert-error (* 1 "a")) +(assert-error (/ 1 "a")) + diff --git a/tests/comment.lisp b/tests/comment.lisp new file mode 100644 index 0000000..40d5081 --- /dev/null +++ b/tests/comment.lisp @@ -0,0 +1,8 @@ +(list 1 2 3) ;; comment +(list 1;; comment + 2 3) +(list 1 ;; comment +;; comment + 2 3) +;; comment + diff --git a/tests/control-flow.lisp b/tests/control-flow.lisp new file mode 100644 index 0000000..75095ec --- /dev/null +++ b/tests/control-flow.lisp @@ -0,0 +1,36 @@ +(assert-error (if (error "") 1 2)) + +(defmacro inmacro x (progn ,@x)) + +(let ((i 0)) + (while #t + (if (> i 4) + (break) + nil) + (incq i)) + (assert (= i 5))) + +(let ((i 0)) + (while #t + (if (> i 4) + (let () (break)) + nil) + (incq i)) + (assert (= i 5))) + +(let ((flag 0) + (i 0)) + (while (< i 10) + (incq i) + (continue) + (setq flag 1)) + (assert (= i 10)) + (assert (= flag 0))) + +(assert-error (funcall (lambda () (break)))) +(assert-error (funcall (lambda () (continue)))) +(assert (= 1 (funcall (lambda () (return 1))))) +(assert (= 1 (funcall (lambda () (inmacro (return 1) (return 2)))))) +(assert (= 1 (funcall (lambda () (while #t (return 1)))))) +(assert (= 1 (funcall (lambda () (let () (return 1)))))) +(assert (= 1 (funcall (lambda () (let ((x (return 1))) (return 2)))))) diff --git a/tests/lambda.lisp b/tests/lambda.lisp new file mode 100644 index 0000000..5c93bdb --- /dev/null +++ b/tests/lambda.lisp @@ -0,0 +1,12 @@ +(defun Y (f) + (funcall + (lambda (g) (funcall g g)) + (lambda (h) + (funcall f (lambda args (apply (funcall h h) args)))))) +(defun fibo-impl (self) + (lambda (n) + (if (<= n 2) + 1 + (+ (funcall self (- n 1)) (funcall self (- n 2)))))) +(defvar fibo (Y #'fibo-impl)) +(assert (= 55 (funcall fibo 10))) diff --git a/tests/let-binding.lisp b/tests/let-binding.lisp new file mode 100644 index 0000000..33d021e --- /dev/null +++ b/tests/let-binding.lisp @@ -0,0 +1,7 @@ +(assert-error (let ((i 0)) (i > 4))) + +(assert (= 3 +(let ((a 1) + (b 2)) + (+ a b)))) + diff --git a/tests/lisp/arithmetic.lisp b/tests/lisp/arithmetic.lisp deleted file mode 100644 index 2764b10..0000000 --- a/tests/lisp/arithmetic.lisp +++ /dev/null @@ -1,12 +0,0 @@ -(assert (= 1 (+ 1 0))) -(assert (= -1 (- 0 1))) -(assert (= -1 (- 1))) -(assert (= 1.1 (+ 1 0.1))) -(assert (= 2 (i/ 11 5))) -(assert (= 1 (mod 11 5))) - -(assert-error (+ 1 "a")) -(assert-error (- 1 "a")) -(assert-error (* 1 "a")) -(assert-error (/ 1 "a")) - diff --git a/tests/lisp/comment.lisp b/tests/lisp/comment.lisp deleted file mode 100644 index 40d5081..0000000 --- a/tests/lisp/comment.lisp +++ /dev/null @@ -1,8 +0,0 @@ -(list 1 2 3) ;; comment -(list 1;; comment - 2 3) -(list 1 ;; comment -;; comment - 2 3) -;; comment - diff --git a/tests/lisp/control-flow.lisp b/tests/lisp/control-flow.lisp deleted file mode 100644 index 75095ec..0000000 --- a/tests/lisp/control-flow.lisp +++ /dev/null @@ -1,36 +0,0 @@ -(assert-error (if (error "") 1 2)) - -(defmacro inmacro x (progn ,@x)) - -(let ((i 0)) - (while #t - (if (> i 4) - (break) - nil) - (incq i)) - (assert (= i 5))) - -(let ((i 0)) - (while #t - (if (> i 4) - (let () (break)) - nil) - (incq i)) - (assert (= i 5))) - -(let ((flag 0) - (i 0)) - (while (< i 10) - (incq i) - (continue) - (setq flag 1)) - (assert (= i 10)) - (assert (= flag 0))) - -(assert-error (funcall (lambda () (break)))) -(assert-error (funcall (lambda () (continue)))) -(assert (= 1 (funcall (lambda () (return 1))))) -(assert (= 1 (funcall (lambda () (inmacro (return 1) (return 2)))))) -(assert (= 1 (funcall (lambda () (while #t (return 1)))))) -(assert (= 1 (funcall (lambda () (let () (return 1)))))) -(assert (= 1 (funcall (lambda () (let ((x (return 1))) (return 2)))))) diff --git a/tests/lisp/lambda.lisp b/tests/lisp/lambda.lisp deleted file mode 100644 index 5c93bdb..0000000 --- a/tests/lisp/lambda.lisp +++ /dev/null @@ -1,12 +0,0 @@ -(defun Y (f) - (funcall - (lambda (g) (funcall g g)) - (lambda (h) - (funcall f (lambda args (apply (funcall h h) args)))))) -(defun fibo-impl (self) - (lambda (n) - (if (<= n 2) - 1 - (+ (funcall self (- n 1)) (funcall self (- n 2)))))) -(defvar fibo (Y #'fibo-impl)) -(assert (= 55 (funcall fibo 10))) diff --git a/tests/lisp/let-binding.lisp b/tests/lisp/let-binding.lisp deleted file mode 100644 index 33d021e..0000000 --- a/tests/lisp/let-binding.lisp +++ /dev/null @@ -1,7 +0,0 @@ -(assert-error (let ((i 0)) (i > 4))) - -(assert (= 3 -(let ((a 1) - (b 2)) - (+ a b)))) - diff --git a/tests/lisp/macro.lisp b/tests/lisp/macro.lisp deleted file mode 100644 index 4564cb9..0000000 --- a/tests/lisp/macro.lisp +++ /dev/null @@ -1,10 +0,0 @@ -(defmacro for (start pred inc . body) - `(let (,start) - (while ,pred - ,@body - ,inc))) -(assert (= 10 - (let ((sum 0)) - (for (i 0) (< i 5) (incq i) - (setq sum (+ sum i))) - sum))) diff --git a/tests/lisp/test.lisp b/tests/lisp/test.lisp deleted file mode 100644 index 07bdd5b..0000000 --- a/tests/lisp/test.lisp +++ /dev/null @@ -1,14 +0,0 @@ -(defmacro test-module (name) - `(progn - (princ (format "[TEST] %s\n" ,name)) - (load (format "%s.lisp" ,name)) - (princ (format "[PASS] %s\n" ,name)))) - -(test-module "arithmetic") -(test-module "control-flow") -(test-module "lambda") -(test-module "comment") -(test-module "macro") -(test-module "let-binding") - -(exit) diff --git a/tests/macro.lisp b/tests/macro.lisp new file mode 100644 index 0000000..4564cb9 --- /dev/null +++ b/tests/macro.lisp @@ -0,0 +1,10 @@ +(defmacro for (start pred inc . body) + `(let (,start) + (while ,pred + ,@body + ,inc))) +(assert (= 10 + (let ((sum 0)) + (for (i 0) (< i 5) (incq i) + (setq sum (+ sum i))) + sum))) diff --git a/tests/test.lisp b/tests/test.lisp new file mode 100644 index 0000000..07bdd5b --- /dev/null +++ b/tests/test.lisp @@ -0,0 +1,14 @@ +(defmacro test-module (name) + `(progn + (princ (format "[TEST] %s\n" ,name)) + (load (format "%s.lisp" ,name)) + (princ (format "[PASS] %s\n" ,name)))) + +(test-module "arithmetic") +(test-module "control-flow") +(test-module "lambda") +(test-module "comment") +(test-module "macro") +(test-module "let-binding") + +(exit) -- cgit v1.0