diff --git a/Makefile b/Makefile index 482e6e7..d79e8d0 100644 --- a/Makefile +++ b/Makefile @@ -18,3 +18,9 @@ build: --eval '(ql:quickload :mirror-img/unix)' \ --eval '(asdf:make :mirror-img/unix)' \ --eval '(quit)' + +test: + $(LISP) --load mirror-img.asd \ + --eval '(ql:quickload :mirror-img)' \ + --eval '(asdf:test-system :mirror-img)' \ + --eval '(quit)' diff --git a/mirror-img.asd b/mirror-img.asd index 3fe8ce2..93051aa 100644 --- a/mirror-img.asd +++ b/mirror-img.asd @@ -6,7 +6,8 @@ :author "Jaidyn Ann " :depends-on (:dexador :lquery :split-sequence) :components ((:file "src/mirror-img")) - :in-order-to ((build-op (build-op "mirror-img/unix")))) + :in-order-to ((test-op (test-op "mirror-img/tests")) + (build-op (build-op "mirror-img/unix")))) (asdf:defsystem "mirror-img/unix" :version "0.1" @@ -18,3 +19,22 @@ :entry-point "mirror-img/unix:main" :depends-on (:mirror-img :unix-opts :cl-strings) :components ((:file "src/unix"))) + + + +;;; Tests +;;; ————————————————————————————————————— +(asdf:defsystem "mirror-img/tests" + :version "0.1" + :license "GPLv3" + :author "Jaidyn Ann " + :description "Tests for the the mirror-img package." + :depends-on (:mirror-img :lisp-unit2) + :components ((:file "t/mirror-img"))) + +;; Following method borrowed from lisp-unit2’s documentation: +;; https://github.com/AccelerationNet/lisp-unit2/blob/master/README.md#asdf +(defmethod asdf:perform ((o asdf:test-op) (c (eql (asdf:find-system :mirror-img/tests)))) + (eval (read-from-string + "(lisp-unit2:with-summary () + (lisp-unit2:run-tests :package :mirror-img/tests))"))) diff --git a/t/mirror-img.lisp b/t/mirror-img.lisp new file mode 100644 index 0000000..80076a4 --- /dev/null +++ b/t/mirror-img.lisp @@ -0,0 +1,36 @@ +;;;; mirror-img/tests: Tests for the mirror-img package. + +;; Copyright © 2024 Jaidyn Ann +;; +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of +;; the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +(defpackage :mirror-img/tests + (:use :cl :lisp-unit2)) + +(in-package :mirror-img/tests) + +(define-test mirrored-pathname (:tags '(base)) + (assert-equal + (mirror-img::mirrored-pathname "https://invalid.tld/dir/bird apple.txt" #p"base/") + #p"base/invalid.tld/bird apple.txt")) + +(define-test url-encode-uri.space (:tags '(util)) + (assert-equal + (mirror-img::url-encode-uri "https://invalid.tld/dad alive.jpg") + "https://invalid.tld/dad%20alive.jpg")) + +(define-test url-encode-path.space+exclamation (:tags '(util)) + (assert-equal + (mirror-img::url-encode-path "/images!/dad alive.jpg") + "/images%21/dad%20alive.jpg"))