Add renderer test

This commit is contained in:
paku 2024-05-29 12:46:57 +09:00
parent 5518ead174
commit 9d4d1aa9b6
6 changed files with 76 additions and 4 deletions

View file

@ -4,5 +4,6 @@
:depends-on ("fiveam"
"hsx-test/element"
"hsx-test/defhsx"
"hsx-test/hsx")
"hsx-test/hsx"
"hsx-test/renderer")
:perform (test-op (op c) (symbol-call :fiveam :run-all-tests)))

1
qlfile
View file

@ -1,2 +1,3 @@
ql fiveam
ql alexandria
ql mstrings

View file

@ -10,3 +10,7 @@
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("mstrings" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))

View file

@ -5,14 +5,14 @@
(in-package #:hsx/builtin)
(defmacro define-and-export-builtin-elements (&rest names)
(defmacro define-builtin-tags (&rest names)
`(progn
,@(mapcan (lambda (name)
(list `(deftag ,name)
`(export ',name)))
names)))
(define-and-export-builtin-elements
(define-builtin-tags
; tags
a abbr address area article aside audio b base bdi bdo blockquote
body br button canvas caption cite code col colgroup data datalist

View file

@ -26,7 +26,7 @@
(defclass html-tag (tag) ())
(defclass fragment (element) ())
(defclass fragment (tag) ())
(defclass component (element) ())

66
tests/renderer.lisp Normal file
View file

@ -0,0 +1,66 @@
(defpackage #:hsx-test/renderer
(:use #:cl
#:fiveam
#:hsx
#:named-readtables)
(:import-from #:mstrings))
(in-package :hsx-test/renderer)
(in-readtable mstrings:mstring-syntax)
(def-suite renderer)
(in-suite renderer)
(test empty-tag
(is (string= "<div></div>"
(render (hsx (div))))))
(test tag-with-props
(is (string= "<div prop1=\"value1\" prop2></div>"
(render (hsx (div :prop1 "value1" :prop2 t :prop3 nil))))))
(test tag-with-children
(is (string= "<p>Hello, World!</p>"
(render (hsx (p "Hello, World!")))))
(is (string= #M"<p>
\ Hello,
\ <span>World!</span>
\</p>"
(render (hsx (p
"Hello,"
(span "World!")))))))
(test tag-with-props-and-children
(is (string= "<p prop1=\"value1\" prop2>Hello, World!</p>"
(render (hsx
(p :prop1 "value1" :prop2 t :prop3 nil
"Hello, World!")))))
(is (string= #M"<p prop1=\"value1\" prop2>
\ Hello,
\ <span>World!</span>
\</p>"
(render (hsx
(p :prop1 "value1" :prop2 t :prop3 nil
"Hello,"
(span "World!")))))))
(test fragment
(let ((frg (hsx
(<>
(li "bar")
(li "baz")))))
(is (string= #M"<li>bar</li>
<li>baz</li>"
(render frg)))
(is (string= #M"<ul>
\ <li>foo</li>
\ <li>bar</li>
\ <li>baz</li>
\ <li>brah</li>
\</ul>"
(render (hsx
(ul
(li "foo")
frg
(li "brah"))))))))
;; TODO: Add escaping test