(defpackage #:hsx-test/element (:use #:cl #: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) (test element-class (is (typep (create-element :div nil nil) 'tag)) (is (typep (create-element :html nil nil) 'html-tag)) (is (typep (create-element :<> nil nil) 'fragment)) (is (typep (create-element (lambda ()) nil nil) 'component)) (signals error (create-element "div" nil nil))) (test flatten-children (let* ((elm (create-element :p nil (list "a" nil (list "b" (list nil "c")) (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= "