2024-10-03 02:00:19 +00:00
|
|
|
(defpackage #:hsx-test/dsl
|
2024-05-25 16:26:26 +00:00
|
|
|
(:use #:cl
|
2024-09-28 17:10:25 +00:00
|
|
|
#:rove
|
2024-12-12 03:57:05 +00:00
|
|
|
#:hsx/dsl)
|
|
|
|
(:import-from #:hsx/builtin)
|
2024-06-06 05:59:46 +00:00
|
|
|
(:import-from #:hsx/element
|
|
|
|
#:element-props
|
|
|
|
#:element-children))
|
2024-10-03 02:00:19 +00:00
|
|
|
(in-package #:hsx-test/dsl)
|
2024-05-25 16:26:26 +00:00
|
|
|
|
2024-12-12 03:57:05 +00:00
|
|
|
(deftest find-builtin-symbols-test
|
|
|
|
(testing "normal-cases"
|
|
|
|
(ok (expands '(hsx (div div div))
|
|
|
|
'(hsx/builtin:div div div)))
|
|
|
|
(ok (expands '(hsx (div (div div (div))))
|
|
|
|
'(hsx/builtin:div
|
|
|
|
(hsx/builtin:div
|
|
|
|
div
|
|
|
|
(hsx/builtin:div)))))
|
|
|
|
(ok (expands '(hsx (div
|
|
|
|
(labels ((div () "div"))
|
|
|
|
(hsx (div)))))
|
|
|
|
'(hsx/builtin:div
|
|
|
|
(labels ((div () "div"))
|
|
|
|
(hsx (div)))))))
|
|
|
|
|
|
|
|
(testing "ignore-cases"
|
|
|
|
(ok (expands '(hsx (div . div))
|
|
|
|
'(div . div)))
|
|
|
|
(ok (expands '(hsx ((div)))
|
|
|
|
'((div))))
|
|
|
|
(ok (expands '(hsx (div
|
|
|
|
(labels ((div () "div"))
|
|
|
|
(div))))
|
|
|
|
'(hsx/builtin:div
|
|
|
|
(labels ((div () "div"))
|
|
|
|
(div)))))))
|
|
|
|
|
2024-10-03 02:00:19 +00:00
|
|
|
(deftest dsl-test
|
2024-10-02 06:00:47 +00:00
|
|
|
(testing "empty-hsx"
|
2024-12-12 03:57:05 +00:00
|
|
|
(let ((elm (hsx (div))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (null (element-props elm)))
|
|
|
|
(ok (null (element-children elm)))))
|
|
|
|
|
|
|
|
(testing "hsx-with-static-props"
|
2024-12-12 03:57:05 +00:00
|
|
|
(let ((elm (hsx (div :prop1 "value1" :prop2 "value2"))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (equal '(:prop1 "value1" :prop2 "value2")
|
|
|
|
(element-props elm)))
|
|
|
|
(ok (null (element-children elm)))))
|
|
|
|
|
|
|
|
(testing "hsx-with-dynamic-props"
|
|
|
|
(let* ((props '(:prop1 "value1" :prop2 "value2"))
|
2024-12-12 03:57:05 +00:00
|
|
|
(elm (hsx (div props))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (equal props (element-props elm)))
|
|
|
|
(ok (null (element-children elm)))))
|
|
|
|
|
|
|
|
(testing "hsx-with-children"
|
2024-12-12 03:57:05 +00:00
|
|
|
(let ((elm (hsx (div
|
|
|
|
"child1"
|
|
|
|
"child2"))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (null (element-props elm)))
|
|
|
|
(ok (equal (list "child1" "child2") (element-children elm)))))
|
|
|
|
|
|
|
|
(testing "hsx-with-static-props-and-children"
|
2024-12-12 03:57:05 +00:00
|
|
|
(let ((elm (hsx (div :prop1 "value1" :prop2 "value2"
|
|
|
|
"child1"
|
|
|
|
"child2"))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (equal '(:prop1 "value1" :prop2 "value2")
|
|
|
|
(element-props elm)))
|
|
|
|
(ok (equal (list "child1" "child2") (element-children elm)))))
|
|
|
|
|
|
|
|
(testing "hsx-with-dynamic-props-and-children"
|
|
|
|
(let* ((props '(:prop1 "value1" :prop2 "value2"))
|
2024-12-12 03:57:05 +00:00
|
|
|
(elm (hsx (div props
|
|
|
|
"child1"
|
|
|
|
"child2"))))
|
2024-10-02 06:00:47 +00:00
|
|
|
(ok (equal props (element-props elm)))
|
|
|
|
(ok (equal (list "child1" "child2") (element-children elm))))))
|