2017-03-09 11:19:15 -05:00
|
|
|
(load "../unit/unit-tester.lisp")
|
2017-03-03 11:56:27 -05:00
|
|
|
(load "dlambda.lisp")
|
|
|
|
|
2017-03-09 11:19:15 -05:00
|
|
|
(setq assertions (unit-tester-assertions))
|
|
|
|
|
|
|
|
(setq tests
|
2017-03-06 12:44:06 -05:00
|
|
|
(list
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun empty-dlambda ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments) (case (first arguments)))
|
2017-03-03 15:06:49 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda)))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun dlambda-default-method-only ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(t (apply (lambda () (print "nothing")) arguments))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda
|
|
|
|
(t () (print "nothing")))))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun dlambda-named-method-only ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(:write (apply (lambda () (print "something")) (rest arguments)))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda
|
|
|
|
(:write () (print "something")))))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
2017-03-07 16:27:11 -05:00
|
|
|
(defun dlambda-many-named-methods ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-07 16:27:11 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(:write1 (apply (lambda () (print "something")) (rest arguments)))
|
|
|
|
(:write2 (apply (lambda () (print "something")) (rest arguments)))
|
|
|
|
(:write3 (apply (lambda () (print "something")) (rest arguments)))))
|
|
|
|
|
|
|
|
(dlambda
|
|
|
|
(:write1 () (print "something"))
|
|
|
|
(:write2 () (print "something"))
|
|
|
|
(:write3 () (print "something")))))
|
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun dlambda-named-and-default-method ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(:write (apply (lambda () (print "something")) (rest arguments)))
|
|
|
|
(t (apply (lambda () (print "nothing")) arguments))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda
|
|
|
|
(:write () (print "something"))
|
|
|
|
(t () (print "nothing")))))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun dlambda-methods-with-arguments ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(:write (apply (lambda (message) (print message)) (rest arguments)))
|
|
|
|
(t (apply (lambda (&rest messages) (print messages)) arguments))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda
|
|
|
|
(:write (message) (print message))
|
|
|
|
(t (&rest messages) (print messages)))))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(defun dlambda-methods-with-multiple-arguments ()
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert-equal
|
2017-03-06 12:44:06 -05:00
|
|
|
'(lambda (&rest arguments)
|
|
|
|
(case (first arguments)
|
|
|
|
(:write
|
|
|
|
(apply
|
|
|
|
(lambda (message &rest other-stuff)
|
|
|
|
(print message)
|
|
|
|
(print other-stuff))
|
|
|
|
(rest arguments)))
|
|
|
|
(t
|
|
|
|
(apply
|
|
|
|
(lambda (message1 message2 &rest other-stuff)
|
|
|
|
(print message1)
|
|
|
|
(print message2)
|
|
|
|
(print other-stuff))
|
|
|
|
arguments))))
|
2017-03-03 11:56:27 -05:00
|
|
|
|
2017-03-06 12:44:06 -05:00
|
|
|
(dlambda
|
|
|
|
(:write (message &rest other-stuff)
|
|
|
|
(print message)
|
|
|
|
(print other-stuff))
|
|
|
|
(t (message1 message2 &rest other-stuff)
|
|
|
|
(print message1)
|
|
|
|
(print message2)
|
|
|
|
(print other-stuff)))))))
|
2017-03-09 11:19:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
(setq tester (unit-tester tests))
|
|
|
|
(call tester :run)
|