hsx/tests/renderer.lisp

68 lines
1.9 KiB
Common Lisp
Raw Normal View History

2024-05-29 03:46:57 +00:00
(defpackage #:hsx-test/renderer
(:use #:cl
#:fiveam
2024-05-30 04:18:32 +00:00
#:named-readtables
#:hsx/builtin)
(:import-from #:mstrings)
(:import-from #:hsx/element
#:render))
2024-05-29 03:46:57 +00:00
(in-package :hsx-test/renderer)
(in-readtable mstrings:mstring-syntax)
(def-suite renderer-test)
(in-suite renderer-test)
2024-05-29 03:46:57 +00:00
(test empty-tag
(is (string= "<div></div>"
2024-05-30 04:18:32 +00:00
(render (div)))))
2024-05-29 03:46:57 +00:00
(test tag-with-props
(is (string= "<div prop1=\"value1\" prop2></div>"
2024-05-30 04:18:32 +00:00
(render (div :prop1 "value1" :prop2 t :prop3 nil)))))
2024-05-29 03:46:57 +00:00
(test tag-with-children
2024-05-30 00:22:18 +00:00
(is (string= "<p>foo</p>"
2024-05-30 04:18:32 +00:00
(render (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>"
2024-05-30 04:18:32 +00:00
(render (p
(span "foo")))))
2024-05-30 00:22:18 +00:00
(is (string= #M"<p>
\ foo
\ <span>bar</span>
\</p>"
2024-05-30 04:18:32 +00:00
(render (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-30 04:18:32 +00:00
(render (p :prop1 "value1" :prop2 t :prop3 nil
"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>"
2024-05-30 04:18:32 +00:00
(render (p :prop1 "value1" :prop2 t :prop3 nil
"foo"
(span "bar"))))))
2024-05-29 03:46:57 +00:00
(test fragment
2024-05-30 04:18:32 +00:00
(let ((frg (<>
(li "bar")
(li "baz"))))
2024-05-29 03:46:57 +00:00
(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>"
2024-05-30 04:18:32 +00:00
(render (ul
(li "foo")
frg
(li "brah")))))))