2024-05-29 03:46:57 +00:00
|
|
|
(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
|
2024-05-30 00:22:18 +00:00
|
|
|
(is (string= "<p>foo</p>"
|
|
|
|
(render (hsx (p "foo")))))
|
2024-05-29 03:46:57 +00:00
|
|
|
(is (string= #M"<p>
|
2024-05-30 00:22:18 +00:00
|
|
|
\ <span>foo</span>
|
2024-05-29 03:46:57 +00:00
|
|
|
\</p>"
|
|
|
|
(render (hsx (p
|
2024-05-30 00:22:18 +00:00
|
|
|
(span "foo"))))))
|
|
|
|
(is (string= #M"<p>
|
|
|
|
\ foo
|
|
|
|
\ <span>bar</span>
|
|
|
|
\</p>"
|
|
|
|
(render (hsx (p
|
|
|
|
"foo"
|
|
|
|
(span "bar")))))))
|
2024-05-29 03:46:57 +00:00
|
|
|
|
|
|
|
(test tag-with-props-and-children
|
2024-05-30 00:22:18 +00:00
|
|
|
(is (string= "<p prop1=\"value1\" prop2>foo</p>"
|
2024-05-29 03:46:57 +00:00
|
|
|
(render (hsx
|
|
|
|
(p :prop1 "value1" :prop2 t :prop3 nil
|
2024-05-30 00:22:18 +00:00
|
|
|
"foo")))))
|
2024-05-29 03:46:57 +00:00
|
|
|
(is (string= #M"<p prop1=\"value1\" prop2>
|
2024-05-30 00:22:18 +00:00
|
|
|
\ foo
|
|
|
|
\ <span>bar</span>
|
2024-05-29 03:46:57 +00:00
|
|
|
\</p>"
|
|
|
|
(render (hsx
|
|
|
|
(p :prop1 "value1" :prop2 t :prop3 nil
|
2024-05-30 00:22:18 +00:00
|
|
|
"foo"
|
|
|
|
(span "bar")))))))
|
2024-05-29 03:46:57 +00:00
|
|
|
|
|
|
|
(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
|