(in-package #:hssg/test) (def-suite hssg/template :description "Tests for the HTML template engine") (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")))))