Add renderer test
This commit is contained in:
parent
5518ead174
commit
9d4d1aa9b6
6 changed files with 76 additions and 4 deletions
|
@ -4,5 +4,6 @@
|
||||||
:depends-on ("fiveam"
|
:depends-on ("fiveam"
|
||||||
"hsx-test/element"
|
"hsx-test/element"
|
||||||
"hsx-test/defhsx"
|
"hsx-test/defhsx"
|
||||||
"hsx-test/hsx")
|
"hsx-test/hsx"
|
||||||
|
"hsx-test/renderer")
|
||||||
:perform (test-op (op c) (symbol-call :fiveam :run-all-tests)))
|
:perform (test-op (op c) (symbol-call :fiveam :run-all-tests)))
|
||||||
|
|
1
qlfile
1
qlfile
|
@ -1,2 +1,3 @@
|
||||||
ql fiveam
|
ql fiveam
|
||||||
ql alexandria
|
ql alexandria
|
||||||
|
ql mstrings
|
||||||
|
|
|
@ -10,3 +10,7 @@
|
||||||
(:class qlot/source/ql:source-ql
|
(:class qlot/source/ql:source-ql
|
||||||
:initargs (:%version :latest)
|
:initargs (:%version :latest)
|
||||||
:version "ql-2023-10-21"))
|
:version "ql-2023-10-21"))
|
||||||
|
("mstrings" .
|
||||||
|
(:class qlot/source/ql:source-ql
|
||||||
|
:initargs (:%version :latest)
|
||||||
|
:version "ql-2023-10-21"))
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
(in-package #:hsx/builtin)
|
(in-package #:hsx/builtin)
|
||||||
|
|
||||||
|
|
||||||
(defmacro define-and-export-builtin-elements (&rest names)
|
(defmacro define-builtin-tags (&rest names)
|
||||||
`(progn
|
`(progn
|
||||||
,@(mapcan (lambda (name)
|
,@(mapcan (lambda (name)
|
||||||
(list `(deftag ,name)
|
(list `(deftag ,name)
|
||||||
`(export ',name)))
|
`(export ',name)))
|
||||||
names)))
|
names)))
|
||||||
|
|
||||||
(define-and-export-builtin-elements
|
(define-builtin-tags
|
||||||
; tags
|
; tags
|
||||||
a abbr address area article aside audio b base bdi bdo blockquote
|
a abbr address area article aside audio b base bdi bdo blockquote
|
||||||
body br button canvas caption cite code col colgroup data datalist
|
body br button canvas caption cite code col colgroup data datalist
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
(defclass html-tag (tag) ())
|
(defclass html-tag (tag) ())
|
||||||
|
|
||||||
(defclass fragment (element) ())
|
(defclass fragment (tag) ())
|
||||||
|
|
||||||
(defclass component (element) ())
|
(defclass component (element) ())
|
||||||
|
|
||||||
|
|
66
tests/renderer.lisp
Normal file
66
tests/renderer.lisp
Normal 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
|
Loading…
Reference in a new issue