diff --git a/hsx-test.asd b/hsx-test.asd index 1266328..e2f5324 100644 --- a/hsx-test.asd +++ b/hsx-test.asd @@ -7,12 +7,10 @@ "hsx-test/defhsx" "hsx-test/hsx" "hsx-test/escaper" - "hsx-test/renderer" "hsx-test/group") :test-names ((#:element-test . #:hsx-test/element) (#:defhsx-test . #:hsx-test/defhsx) (#:hsx-test . #:hsx-test/hsx) (#:escaper-test . #:hsx-test/escaper) - (#:renderer-test . #:hsx-test/renderer) (#:group-test . #:hsx-test/group)) :num-checks 42) diff --git a/tests/element.lisp b/tests/element.lisp index 71a04ae..1daf267 100644 --- a/tests/element.lisp +++ b/tests/element.lisp @@ -1,8 +1,13 @@ (defpackage #:hsx-test/element (:use #:cl - #:fiveam - #:hsx/element)) + #:fiveam + #:hsx/element) + (:import-from #:named-readtables + #:in-readtable) + (:import-from #:mstrings + #:mstring-syntax)) (in-package #:hsx-test/element) +(in-readtable mstring-syntax) (def-suite element-test) (in-suite element-test) @@ -23,6 +28,117 @@ (cons "d" "e"))))) (is (equal (list "a" "b" "c" "d" "e") (element-children elm))))) +(test empty-element + (is (string= "
" + (render-to-string (create-element :div nil nil))))) + +(test element-with-props + (is (string= "" + (render-to-string (create-element :div + (list :prop1 "value1" + :prop2 t + :prop3 nil) + nil))))) + +(test element-with-children + (is (string= "foo
" + (render-to-string (create-element :p + nil + (list "foo")) + :pretty t))) + (is (string= #M"+ \ foo + \
" + (render-to-string (create-element :p + nil + (list (create-element :span + nil + (list "foo")))) + :pretty t))) + (is (string= #M"+ \ foo + \ bar + \
" + (render-to-string (create-element :p + nil + (list "foo" + (create-element :span + nil + (list "bar")))) + :pretty t)))) + +(test element-with-props-and-children + (is (string= "foo
" + (render-to-string (create-element :p + (list :prop1 "value1" + :prop2 t + :prop3 nil) + (list "foo")) + :pretty t))) + (is (string= #M"+ \ foo + \ bar + \
" + (render-to-string (create-element :p + (list :prop1 "value1" + :prop2 t + :prop3 nil) + (list "foo" + (create-element :span + nil + "bar"))) + :pretty t)))) + +(test self-closing-tag + (is (string= "" + (render-to-string (create-element :img + (list :src "/background.png") + nil) + :pretty t)))) + +(test escaping-tag + (is (string= "foo
" - (render-to-string (p "foo") :pretty t))) - (is (string= #M"- \ foo - \
" - (render-to-string - (p - (span "foo")) - :pretty t))) - (is (string= #M"- \ foo - \ bar - \
" - (render-to-string - (p - "foo" - (span "bar")) - :pretty t)))) - -(test tag-with-props-and-children - (is (string= "foo
" - (render-to-string - (p :prop1 "value1" :prop2 t :prop3 nil - "foo") - :pretty t))) - (is (string= #M"- \ foo - \ bar - \
" - (render-to-string - (p :prop1 "value1" :prop2 t :prop3 nil - "foo" - (span "bar")) - :pretty t)))) - -(test self-closing-tag - (is (string= "" - (render-to-string - (img :src "/background.png") - :pretty t)))) - -(test escaping-tag - (is (string= "