Change HSX parsing environment from compile-time to runtime
This commit is contained in:
parent
6471ee88d6
commit
8d3a2588d0
7 changed files with 109 additions and 128 deletions
tests
|
@ -7,72 +7,58 @@
|
|||
(def-suite element-test)
|
||||
(in-suite element-test)
|
||||
|
||||
(test tag
|
||||
(let ((elm (create-element :p
|
||||
'(:class "red")
|
||||
"Hello,"
|
||||
"World")))
|
||||
(is (eq :p (element-type elm)))
|
||||
(is (equal '(:class "red") (element-props elm)))
|
||||
(is (equal (list "Hello," "World") (element-children elm)))))
|
||||
(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
|
||||
"a"
|
||||
nil
|
||||
(list "b" (list nil "c"))
|
||||
(cons "d" "e"))))
|
||||
(list "a"
|
||||
nil
|
||||
(list "b" (list nil "c"))
|
||||
(cons "d" "e")))))
|
||||
(is (equal (list "a" "b" "c" "d" "e") (element-children elm)))))
|
||||
|
||||
(defun comp1 (&key title children)
|
||||
(defun comp1 (&key prop children)
|
||||
(create-element :div
|
||||
nil
|
||||
title
|
||||
children))
|
||||
(list prop
|
||||
children)))
|
||||
|
||||
(test component-accepting-keyword-args
|
||||
(let* ((elm (create-element #'comp1
|
||||
'(:title "foo")
|
||||
"bar"))
|
||||
(expanded (expand-component elm)))
|
||||
(is (eq #'comp1 (element-type elm)))
|
||||
(is (equal '(:title "foo") (element-props elm)))
|
||||
(is (equal (list "bar") (element-children elm)))
|
||||
(is (eq :div (element-type expanded)))
|
||||
(is (equal (list "foo" "bar") (element-children expanded)))))
|
||||
(let ((elm (expand-component (create-element #'comp1
|
||||
'(:prop "value")
|
||||
(list "child")))))
|
||||
(is (eq :div (element-type elm)))
|
||||
(is (equal (list "value" "child") (element-children elm)))))
|
||||
|
||||
(defun comp2 (&rest props)
|
||||
(create-element :div
|
||||
nil
|
||||
(getf props :title)
|
||||
(getf props :children)))
|
||||
(list (getf props :prop)
|
||||
(getf props :children))))
|
||||
|
||||
(test component-accepting-property-list
|
||||
(let* ((elm (create-element #'comp2
|
||||
'(:title "foo")
|
||||
"bar"))
|
||||
(expanded (expand-component elm)))
|
||||
(is (eq #'comp2 (element-type elm)))
|
||||
(is (equal '(:title "foo") (element-props elm)))
|
||||
(is (equal (list "bar") (element-children elm)))
|
||||
(is (eq :div (element-type expanded)))
|
||||
(is (equal (list "foo" "bar") (element-children expanded)))))
|
||||
(let ((elm (expand-component (create-element #'comp2
|
||||
'(:prop "value")
|
||||
(list "child")))))
|
||||
(is (eq :div (element-type elm)))
|
||||
(is (equal (list "value" "child") (element-children elm)))))
|
||||
|
||||
(defun comp3 (&rest props &key title children &allow-other-keys)
|
||||
(defun comp3 (&rest props &key prop children &allow-other-keys)
|
||||
(create-element :div
|
||||
nil
|
||||
title
|
||||
children
|
||||
(getf props :other-key)))
|
||||
(list prop
|
||||
children
|
||||
(getf props :other-key))))
|
||||
|
||||
(test component-accepting-keyword-args-and-property-list
|
||||
(let* ((elm (create-element #'comp3
|
||||
'(:title "foo" :other-key "baz")
|
||||
"bar"))
|
||||
(expanded (expand-component elm)))
|
||||
(is (eq #'comp3 (element-type elm)))
|
||||
(is (equal '(:title "foo" :other-key "baz") (element-props elm)))
|
||||
(is (equal (list "bar") (element-children elm)))
|
||||
(is (eq :div (element-type expanded)))
|
||||
(is (equal (list "foo" "bar" "baz") (element-children expanded)))))
|
||||
(let ((elm (expand-component (create-element #'comp3
|
||||
'(:prop "value" :other-key "other")
|
||||
(list "child")))))
|
||||
(is (eq :div (element-type elm)))
|
||||
(is (equal (list "value" "child" "other") (element-children elm)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue