transcendental-lisp/lisp/lang/dlambda-test.lisp

81 lines
2.5 KiB
Common Lisp
Raw Normal View History

2017-03-06 11:00:18 -05:00
(load "../unit/unit-test.lisp")
(load "dlambda.lisp")
2017-03-03 15:06:49 -05:00
(defun test-dlambda ()
2017-03-03 15:06:49 -05:00
(unit
(list
(defun empty-dlambda ()
(assert-equal
'(lambda (&rest arguments) (case (first arguments)))
2017-03-06 11:00:18 -05:00
(dlambda)))
2017-03-03 15:06:49 -05:00
(defun dlambda-default-method-only ()
(assert-equal
'(lambda (&rest arguments)
(case (first arguments)
2017-03-06 11:00:18 -05:00
(t (apply (lambda () (print "nothing")) arguments))))
2017-03-03 15:06:49 -05:00
(dlambda
2017-03-06 11:00:18 -05:00
(t () (print "nothing")))))
2017-03-03 15:06:49 -05:00
(defun dlambda-named-method-only ()
(assert-equal
'(lambda (&rest arguments)
(case (first arguments)
2017-03-06 11:00:18 -05:00
(:write (apply (lambda () (print "something")) (rest arguments)))))
2017-03-03 15:06:49 -05:00
(dlambda
2017-03-06 11:00:18 -05:00
(:write () (print "something")))))
2017-03-03 15:06:49 -05:00
(defun dlambda-named-and-default-method ()
(assert-equal
'(lambda (&rest arguments)
(case (first arguments)
(:write (apply (lambda () (print "something")) (rest arguments)))
2017-03-06 11:00:18 -05:00
(t (apply (lambda () (print "nothing")) arguments))))
2017-03-03 15:06:49 -05:00
(dlambda
(:write () (print "something"))
2017-03-06 11:00:18 -05:00
(t () (print "nothing")))))
2017-03-03 15:06:49 -05:00
(defun dlambda-methods-with-arguments ()
(assert-equal
'(lambda (&rest arguments)
(case (first arguments)
(:write (apply (lambda (message) (print message)) (rest arguments)))
2017-03-06 11:00:18 -05:00
(t (apply (lambda (&rest messages) (print messages)) arguments))))
2017-03-03 15:06:49 -05:00
(dlambda
(:write (message) (print message))
2017-03-06 11:00:18 -05:00
(t (&rest messages) (print messages)))))
2017-03-03 15:06:49 -05:00
(defun dlambda-methods-with-multiple-arguments ()
(assert-equal
'(lambda (&rest arguments)
(case (first arguments)
(:write
(apply
(lambda (message &rest other-stuff)
(print message)
2017-03-06 11:00:18 -05:00
(print other-stuff))
(rest arguments)))
2017-03-03 15:06:49 -05:00
(t
(apply
(lambda (message1 message2 &rest other-stuff)
(print message1)
(print message2)
2017-03-06 11:00:18 -05:00
(print other-stuff))
arguments))))
2017-03-03 15:06:49 -05:00
(dlambda
(:write (message &rest other-stuff)
(print message)
2017-03-06 11:00:18 -05:00
(print other-stuff))
2017-03-03 15:06:49 -05:00
(t (message1 message2 &rest other-stuff)
(print message1)
(print message2)
2017-03-06 11:00:18 -05:00
(print other-stuff))))))))