hsx/tests/hsx.lisp

88 lines
2.3 KiB
Common Lisp
Raw Normal View History

2024-05-25 16:26:26 +00:00
(defpackage #:hsx-test/hsx
(:use #:cl
#:fiveam
2024-05-27 06:51:32 +00:00
#:hsx/hsx
#:hsx/builtin)
2024-05-26 03:26:09 +00:00
(:import-from #:hsx/element
#:create-element))
2024-05-25 16:26:26 +00:00
(in-package #:hsx-test/hsx)
2024-05-26 03:26:09 +00:00
(def-suite hsx-test)
(in-suite hsx-test)
2024-05-27 02:10:11 +00:00
2024-05-25 16:26:26 +00:00
(test empty-hsx
2024-05-26 03:26:09 +00:00
(is (equal (macroexpand-1
'(div))
'(create-element
"div"
2024-05-26 12:45:49 +00:00
(list)))))
2024-05-25 16:26:26 +00:00
(test hsx-with-props
2024-05-26 03:26:09 +00:00
(is (equal (macroexpand-1
'(div :prop1 "value1" :prop2 "value2"))
'(create-element
"div"
2024-05-26 12:45:49 +00:00
(list :prop1 "value1" :prop2 "value2")))))
2024-05-25 16:26:26 +00:00
(test hsx-with-children
2024-05-26 03:26:09 +00:00
(is (equal (macroexpand-1
'(div
"child1"
"child2"))
'(create-element
"div"
2024-05-26 12:45:49 +00:00
(list)
2024-05-26 03:26:09 +00:00
"child1"
"child2"))))
2024-05-25 16:26:26 +00:00
(test hsx-with-props-and-children
2024-05-26 03:26:09 +00:00
(is (equal (macroexpand-1
'(div :prop1 "value1" :prop2 "value2"
"child1"
"child2"))
'(create-element
"div"
2024-05-26 12:45:49 +00:00
(list :prop1 "value1" :prop2 "value2")
2024-05-26 03:26:09 +00:00
"child1"
"child2"))))
2024-05-27 02:10:11 +00:00
(defhsx custom "custom")
(test hsx-for-custom-tag-element
(is (equal (macroexpand-1
'(custom :prop1 "value1" :prop2 "value2"
"child1"
"child2"))
'(create-element
"custom"
(list :prop1 "value1" :prop2 "value2")
"child1"
"child2"))))
(defun %comp1 (&key prop1 prop2 children)
(declare (ignore prop1 prop2 children)))
(defhsx comp1 #'%comp1)
(defcomp comp2 (&key prop1 prop2 children)
2024-05-26 07:14:33 +00:00
(declare (ignore prop1 prop2 children)))
2024-05-26 03:26:09 +00:00
2024-05-27 02:10:11 +00:00
(test hsx-for-component-element
(is (equal (macroexpand-1
'(comp1 :prop1 "value1" :prop2 "value2"
"child1"
"child2"))
'(create-element
#'%comp1
(list :prop1 "value1" :prop2 "value2")
"child1"
"child2")))
2024-05-26 03:26:09 +00:00
(is (equal (macroexpand-1
2024-05-27 02:10:11 +00:00
'(comp2 :prop1 "value1" :prop2 "value2"
2024-05-26 03:26:09 +00:00
"child1"
"child2"))
'(create-element
2024-05-27 02:10:11 +00:00
(fdefinition '%comp2)
2024-05-26 12:45:49 +00:00
(list :prop1 "value1" :prop2 "value2")
2024-05-26 03:26:09 +00:00
"child1"
"child2"))))