diff options
Diffstat (limited to 'tests/lisp')
| -rw-r--r-- | tests/lisp/arithmetic.lisp | 11 | ||||
| -rw-r--r-- | tests/lisp/comment.lisp | 7 | ||||
| -rw-r--r-- | tests/lisp/control-flow.lisp | 33 | ||||
| -rw-r--r-- | tests/lisp/lambda.lisp | 12 | ||||
| -rw-r--r-- | tests/lisp/let-binding.lisp | 7 | ||||
| -rw-r--r-- | tests/lisp/macro.lisp | 10 | ||||
| -rw-r--r-- | tests/lisp/test.lisp | 8 |
7 files changed, 88 insertions, 0 deletions
diff --git a/tests/lisp/arithmetic.lisp b/tests/lisp/arithmetic.lisp new file mode 100644 index 0000000..658bcda --- /dev/null +++ b/tests/lisp/arithmetic.lisp @@ -0,0 +1,11 @@ +(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 new file mode 100644 index 0000000..d84a2f7 --- /dev/null +++ b/tests/lisp/comment.lisp @@ -0,0 +1,7 @@ +(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 new file mode 100644 index 0000000..5d7290d --- /dev/null +++ b/tests/lisp/control-flow.lisp @@ -0,0 +1,33 @@ +(assert-error (if (error "") 1 2)) + +(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 () (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 new file mode 100644 index 0000000..5c93bdb --- /dev/null +++ b/tests/lisp/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/lisp/let-binding.lisp b/tests/lisp/let-binding.lisp new file mode 100644 index 0000000..33d021e --- /dev/null +++ b/tests/lisp/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/macro.lisp b/tests/lisp/macro.lisp new file mode 100644 index 0000000..4564cb9 --- /dev/null +++ b/tests/lisp/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/lisp/test.lisp b/tests/lisp/test.lisp new file mode 100644 index 0000000..b42cc60 --- /dev/null +++ b/tests/lisp/test.lisp @@ -0,0 +1,8 @@ +(load "arithmetic.lisp") +(load "control-flow.lisp") +(load "lambda.lisp") +(load "comment.lisp") +(load "macro.lisp") +(load "let-binding.lisp") + +(exit) |
