diff --git a/t-lack.asd b/t-lack.asd index df6876e..7391025 100644 --- a/t-lack.asd +++ b/t-lack.asd @@ -15,7 +15,7 @@ :prove) :components ((:module "t" :components - ((:test-file "lack")))) + ((:test-file "builder")))) :defsystem-depends-on (:prove-asdf) :perform (test-op :after (op c) diff --git a/t/builder.lisp b/t/builder.lisp new file mode 100644 index 0000000..5be4df5 --- /dev/null +++ b/t/builder.lisp @@ -0,0 +1,50 @@ +(in-package :cl-user) +(defpackage t.lack.builder + (:use :cl + :prove + :lack.builder)) +(in-package :t.lack.builder) + +(plan 8) + +(defvar *app* + (lambda (env) + (declare (ignore env)) + '(200 (:content-type "text/html") ("ok from app")))) + +(is-type (builder (lambda (app) + (lambda (env) + (funcall app env))) + *app*) + 'function + "builder") + +(is-type (builder + (if t + (lambda (app) + (lambda (env) + (funcall app env))) + nil) + *app*) + 'function + "Can embed CL code") + +(is-type (builder nil (if t nil nil) nil *app*) + 'function + "NIL is ignored") + +(let ((mount-app (builder + (:mount "/admin" (lambda (env) `(200 () ("admin" ,(getf env :path-info))))) + *app*))) + (is (nth 2 (funcall mount-app '(:path-info "/login"))) + '("ok from app")) + (is (nth 2 (funcall mount-app '(:path-info "/admin/login"))) + '("admin" "/login")) + (is (nth 2 (funcall mount-app '(:path-info "/admin"))) + '("admin" "/")) + (is (nth 2 (funcall mount-app '(:path-info "/admin/"))) + '("admin" "/")) + (is (nth 2 (funcall mount-app '(:path-info "/administrators"))) + '("ok from app"))) + +(finalize) diff --git a/t/lack.lisp b/t/lack.lisp deleted file mode 100644 index 8e5bd5d..0000000 --- a/t/lack.lisp +++ /dev/null @@ -1,14 +0,0 @@ -(in-package :cl-user) -(defpackage t.lack - (:use :cl - :lack - :prove)) -(in-package :t.lack) - -;; NOTE: To run this test file, execute `(asdf:test-system :lack)' in your Lisp. - -(plan nil) - -;; blah blah blah. - -(finalize)