(defpackage #:hsx-test/element (:use #:cl #:rove #:hsx/element) (:import-from #:named-readtables #:in-readtable) (:import-from #:mstrings #:mstring-syntax)) (in-package #:hsx-test/element) (in-readtable mstring-syntax) (deftest tag-test (testing "element-class" (ok (typep (create-element :div nil nil) 'tag)) (ok (typep (create-element :html nil nil) 'html-tag)) (ok (typep (create-element :img nil nil) 'self-closing-tag)) (ok (typep (create-element :style nil nil) 'non-escaping-tag)) (ok (typep (create-element :<> nil nil) 'fragment)) (ok (typep (create-element (lambda ()) nil nil) 'component)) (ok (signals (create-element "div" nil nil)))) (testing "flatten-children" (let* ((elm (create-element :p nil (list "a" nil (list "b" (list nil "c")) (cons "d" "e"))))) (ok (equal (list "a" "b" "c" "d" "e") (element-children elm))))) (testing "empty-element" (ok (string= "
" (render-to-string (create-element :div nil nil))))) (testing "element-with-props" (ok (string= "" (render-to-string (create-element :div (list :prop1 "value1" :prop2 t :prop3 nil) nil))))) (testing "element-with-children" (ok (string= "foo
" (render-to-string (create-element :p nil (list "foo")) :pretty t))) (ok (string= #M"\ foo
" (render-to-string (create-element :p nil (list (create-element :span nil (list "foo")))) :pretty t))) (ok (string= #M"\ foo \ bar
" (render-to-string (create-element :p nil (list "foo" (create-element :span nil (list "bar")))) :pretty t)))) (testing "element-with-props-and-children" (ok (string= "foo
" (render-to-string (create-element :p (list :prop1 "value1" :prop2 t :prop3 nil) (list "foo")) :pretty t))) (ok (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)))) (testing "self-closing-tag" (ok (string= "" (render-to-string (create-element :img (list :src "/background.png") nil) :pretty t)))) (testing "escaping-tag" (ok (string= "