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
|
2024-06-01 13:49:15 +00:00
|
|
|
#:render-to-string))
|
2024-05-29 03:46:57 +00:00
|
|
|
(in-package :hsx-test/renderer)
|
|
|
|
(in-readtable mstrings:mstring-syntax)
|
|
|
|
|
2024-05-30 03:55:13 +00:00
|
|
|
(def-suite renderer-test)
|
|
|
|
(in-suite renderer-test)
|
2024-05-29 03:46:57 +00:00
|
|
|
|
|
|
|
(test empty-tag
|
|
|
|
(is (string= "<div></div>"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string (div)))))
|
2024-05-29 03:46:57 +00:00
|
|
|
|
|
|
|
(test tag-with-props
|
|
|
|
(is (string= "<div prop1=\"value1\" prop2></div>"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(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-06-01 13:49:15 +00:00
|
|
|
(render-to-string (p "foo") :pretty t)))
|
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-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(p
|
|
|
|
(span "foo"))
|
|
|
|
:pretty t)))
|
2024-05-30 00:22:18 +00:00
|
|
|
(is (string= #M"<p>
|
|
|
|
\ foo
|
|
|
|
\ <span>bar</span>
|
|
|
|
\</p>"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(p
|
|
|
|
"foo"
|
|
|
|
(span "bar"))
|
|
|
|
:pretty t))))
|
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-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(p :prop1 "value1" :prop2 t :prop3 nil
|
|
|
|
"foo")
|
|
|
|
:pretty t)))
|
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-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(p :prop1 "value1" :prop2 t :prop3 nil
|
|
|
|
"foo"
|
|
|
|
(span "bar"))
|
|
|
|
:pretty t))))
|
2024-05-29 03:46:57 +00:00
|
|
|
|
2024-06-01 11:14:17 +00:00
|
|
|
(test self-closing-tag
|
|
|
|
(is (string= "<img src=\"/background.png\">"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(img :src "/background.png")
|
|
|
|
:pretty t))))
|
2024-06-01 11:14:17 +00:00
|
|
|
|
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>"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string frg :pretty t)))
|
2024-05-29 03:46:57 +00:00
|
|
|
(is (string= #M"<ul>
|
|
|
|
\ <li>foo</li>
|
|
|
|
\ <li>bar</li>
|
|
|
|
\ <li>baz</li>
|
|
|
|
\ <li>brah</li>
|
|
|
|
\</ul>"
|
2024-06-01 13:49:15 +00:00
|
|
|
(render-to-string
|
|
|
|
(ul
|
|
|
|
(li "foo")
|
|
|
|
frg
|
|
|
|
(li "brah"))
|
|
|
|
:pretty t)))))
|