;;;; 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 .(in-package #:hssg.artifact) (in-package #:hssg/test) (def-suite hssg/template :description "Tests for the HTML template engine" :in hssg) (in-suite hssg/template) (test let-metadata-form "The LET-METADATA form can bind data from an association list" (let ((data '((:foo . "foo") (:bar . "bar")))) (hssg:let-metadata data ((foo :foo) (bar :bar) (baz :baz) (qux :qux "qux")) (is-every equal (foo "foo") (bar "bar") (baz nil) (qux "qux"))))) (test identity-template-unchanged "The identity template returns its input unchanged" (let* ((data '((:foo . "foo") (:bar . "bar"))) (out (hssg:apply-template 'hssg:identity-template data))) (is-true (equal data out)))) (test identity-template-eq "Applying the identity template does not produce a new object" (let* ((data '((:foo . "foo") (:bar . "bar"))) (out (hssg:apply-template 'hssg:identity-template data))) (is-true (eq data out)))) (test anonymous-template "Defines an anonous template" (let* ((data '((:foo . "foo") (:bar . "bar"))) (template (hssg:template (foo) (:foo (string-upcase foo)) (:baz "baz"))) (out (hssg:apply-template template data))) (hssg:let-metadata out ((foo :foo) (bar :bar) (baz :baz)) (is-every string-equal (foo "FOO") (bar "bar") (baz "baz"))))) (test template-chaining "Chaining two templates produces a new template" (let* ((data '((:foo . "foo"))) (t1 (hssg:template () (:bar "bar"))) (t2 (hssg:template (foo) (:foo (string-upcase foo)) (:baz "baz"))) (t3 (hssg:template (bar) (:bar (string-upcase bar)))) (template (hssg:chain-templates t1 t2 t3)) (out (hssg:apply-template template data))) (hssg:let-metadata out ((foo :foo) (bar :bar) (baz :baz)) (is-every string-equal (foo "FOO") (bar "BAR") (baz "baz"))))) (test initial-data "Providing a tamplate with initial data produces a new template" (let* ((data '((:foo . "foo"))) (template (hssg:template-with-data (hssg:template () (:baz "baz")) '((:bar . "bar")))) (out (hssg:apply-template template data))) (hssg:let-metadata out ((foo :foo) (bar :bar) (baz :baz)) (is-every string-equal (foo "foo") (bar "bar") (baz "baz")))))