fix set user element attr/children test

This commit is contained in:
Bo Yao 2018-06-30 17:39:20 -04:00
parent 24ace4da05
commit c5a1de8b23
2 changed files with 14 additions and 11 deletions

View file

@ -133,15 +133,17 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
`(defun ,name (&rest ,g!attrs-and-children)
(multiple-value-bind (,g!attrs ,g!children)
(split-attrs-and-children ,g!attrs-and-children)
(let ,(mapcar (lambda (arg)
(list arg `(cdr (assoc (make-keyword ',arg) (attrs-alist ,g!attrs)))))
args)
(make-user-element :tag (string-downcase ',name) :attrs ,g!attrs
:children ,g!children
:expander
(lambda (tag attrs children)
(declare (ignorable tag attrs children))
(progn ,@body)))))))
(let ((,g!element
(make-user-element :tag (string-downcase ',name) :attrs ,g!attrs
:children ,g!children)))
(setf (user-element-expander ,g!element)
(lambda (tag attrs children)
(declare (ignorable tag attrs children))
(let ,(mapcar (lambda (arg)
(list arg `(attr attrs (make-keyword ',arg))))
args)
(progn ,@body))))
,g!element))))
(defvar *expand-user-element* t)

View file

@ -234,7 +234,8 @@
(is (string= "woo" (second (element-children dog4))))
(setf (attr dog4 :size) 16)
(is (= 16 (attr dog4 :size)))
(is (string= "big-dog" (attr (user-element-expand-to dog4) :class)))))
(is (string= "big-dog" (attr (user-element-expand-to dog4) :class)))
(setf (element-children dog4) (list dog1 dog2 dog3))
(is (equal (list dog1 dog2 dog3 "dog") (element-children (user-element-expand-to dog4))))))
(run-all-tests)