2022-09-26 22:58:36 +02:00
|
|
|
;;;; SPDX-License-Identifier AGPL-3.0-or-later
|
|
|
|
|
|
|
|
;;;; compound.lisp Compound artifact implementation
|
|
|
|
;;;; Copyright (C) 2022 Alejandro "HiPhish" Sanchez
|
|
|
|
;;;;
|
|
|
|
;;;; This file is part of CL-HSSG.
|
|
|
|
;;;;
|
|
|
|
;;;; CL-HSSG is free software: you can redistribute it and/or modify it under
|
|
|
|
;;;; the terms of the GNU Affero General Public License as published by the
|
|
|
|
;;;; Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
;;;; option) any later version.
|
|
|
|
;;;;
|
|
|
|
;;;; CL-HSSG 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 Affero General Public License for
|
|
|
|
;;;; more details.
|
|
|
|
;;;;
|
|
|
|
;;;; You should have received a copy of the GNU Affero General Public License
|
|
|
|
;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact)
|
|
|
|
(defpackage #:hssg/test/reader
|
|
|
|
(:use #:cl))
|
|
|
|
(in-package #:hssg/test/reader)
|
|
|
|
|
|
|
|
(defun dummy-reader (pathname)
|
|
|
|
"A dummy reader which does nothing useful."
|
|
|
|
(declare (ignore pathname))
|
|
|
|
'())
|
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
;; "Tests for the reader interface"
|
|
|
|
(clunit:defsuite hssg.reader (hssg/test:hssg))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deffixture hssg.reader (@body)
|
|
|
|
"Installs the dummy \"foo\" reader."
|
|
|
|
(let ((hssg.reader::*file-readers* `(("foo" . ,#'dummy-reader))))
|
|
|
|
@body))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest retrieve-reader (hssg.reader)
|
2022-09-26 22:58:36 +02:00
|
|
|
"A registered reader can be retrieved by its type"
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:assert-true (eq #'dummy-reader (hssg.reader:get-reader "foo"))))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest retrieve-missing-reader (hssg.reader)
|
2022-09-26 22:58:36 +02:00
|
|
|
"Retrieving a reader that has not been registered signals a condition"
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:assert-condition error
|
|
|
|
(hssg.reader:get-reader "bar")))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest add-reader (hssg.reader)
|
2022-09-26 22:58:36 +02:00
|
|
|
"A new reader can be added by file type"
|
2022-10-01 15:51:26 +02:00
|
|
|
(hssg.reader:register-reader "bar" #'dummy-reader)
|
|
|
|
(let ((reader (hssg.reader:get-reader "bar")))
|
|
|
|
(clunit:assert-eq #'dummy-reader reader reader)))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest remove-reader (hssg.reader)
|
2022-09-26 22:58:36 +02:00
|
|
|
"An added reader can be removed"
|
2022-10-01 15:51:26 +02:00
|
|
|
(hssg.reader:register-reader "bar" #'dummy-reader)
|
|
|
|
(hssg.reader:unregister-reader "bar")
|
|
|
|
(clunit:assert-condition error (hssg.reader:get-reader "bar")))
|
2022-09-26 22:58:36 +02:00
|
|
|
|
2022-10-01 15:51:26 +02:00
|
|
|
(clunit:deftest temporary-reader (hssg.reader)
|
2022-09-26 22:58:36 +02:00
|
|
|
"Register a reader for the duration of the body expressions only"
|
2022-10-01 15:51:26 +02:00
|
|
|
(hssg.reader:with-readers (("bar" #'dummy-reader))
|
|
|
|
(clunit:assert-eq #'dummy-reader (hssg.reader:get-reader "bar")))
|
|
|
|
(clunit:assert-condition error (hssg.reader:get-reader "bar")))
|