diff --git a/hsx-test.asd b/hsx-test.asd index bd99f30..9ec115c 100644 --- a/hsx-test.asd +++ b/hsx-test.asd @@ -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))) diff --git a/qlfile b/qlfile index bf1c3a3..a16056b 100644 --- a/qlfile +++ b/qlfile @@ -1,2 +1,3 @@ ql fiveam ql alexandria +ql mstrings diff --git a/qlfile.lock b/qlfile.lock index 22f6050..2cef429 100644 --- a/qlfile.lock +++ b/qlfile.lock @@ -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")) diff --git a/src/builtin.lisp b/src/builtin.lisp index 931e8bb..7b02286 100644 --- a/src/builtin.lisp +++ b/src/builtin.lisp @@ -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 diff --git a/src/element.lisp b/src/element.lisp index e4b4958..cf43c93 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -26,7 +26,7 @@ (defclass html-tag (tag) ()) -(defclass fragment (element) ()) +(defclass fragment (tag) ()) (defclass component (element) ()) diff --git a/tests/renderer.lisp b/tests/renderer.lisp new file mode 100644 index 0000000..93b7c7a --- /dev/null +++ b/tests/renderer.lisp @@ -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= "
" + (render (hsx (div)))))) + +(test tag-with-props + (is (string= "
" + (render (hsx (div :prop1 "value1" :prop2 t :prop3 nil)))))) + +(test tag-with-children + (is (string= "

Hello, World!

" + (render (hsx (p "Hello, World!"))))) + (is (string= #M"

+ \ Hello, + \ World! + \

" + (render (hsx (p + "Hello," + (span "World!"))))))) + +(test tag-with-props-and-children + (is (string= "

Hello, World!

" + (render (hsx + (p :prop1 "value1" :prop2 t :prop3 nil + "Hello, World!"))))) + (is (string= #M"

+ \ Hello, + \ World! + \

" + (render (hsx + (p :prop1 "value1" :prop2 t :prop3 nil + "Hello," + (span "World!"))))))) + +(test fragment + (let ((frg (hsx + (<> + (li "bar") + (li "baz"))))) + (is (string= #M"
  • bar
  • +
  • baz
  • " + (render frg))) + (is (string= #M"" + (render (hsx + (ul + (li "foo") + frg + (li "brah")))))))) + +;; TODO: Add escaping test