118 lines
5.7 KiB
Common Lisp
118 lines
5.7 KiB
Common Lisp
(in-package :cl-user)
|
|
(defpackage flute.test
|
|
(:use :cl :flute :fiveam))
|
|
(in-package :flute.test)
|
|
|
|
(def-suite simple-builtin-element)
|
|
(in-suite simple-builtin-element)
|
|
|
|
(test empty-attr
|
|
(let* ((div1 (div))
|
|
(div2 (div "the children text"))
|
|
(div3 (div "text 1" "text 2"))
|
|
(div4 (div (h1 "text 0") "text 01"
|
|
(list (list "text 3" div2) div3) "text 4")))
|
|
(is (eql nil (attrs-alist (element-attrs div1))))
|
|
(is (eql nil (element-children div1)))
|
|
(is (eql nil (attrs-alist (element-attrs div2))))
|
|
(is (equal (list "the children text") (element-children div2)))
|
|
(is (eql nil (attrs-alist (element-attrs div3))))
|
|
(is (equal (list "text 1" "text 2") (element-children div3)))
|
|
(is (eql nil (attrs-alist (element-attrs div4))))
|
|
(is (= 6 (length (element-children div4))))
|
|
(let ((child1 (first (element-children div4)))
|
|
(child2 (second (element-children div4)))
|
|
(child3 (third (element-children div4)))
|
|
(child4 (fourth (element-children div4)))
|
|
(child5 (fifth (element-children div4)))
|
|
(child6 (sixth (element-children div4))))
|
|
(is (equal "h1" (element-tag child1)))
|
|
(is (equal "text 01" child2))
|
|
(is (equal "text 3" child3))
|
|
(is (eql div2 child4))
|
|
(is (eql div3 child5))
|
|
(is (equal "text 4" child6)))))
|
|
|
|
(test attr-given-by-inline-args
|
|
(let* ((div1 (div :id "container"))
|
|
(div2 (div :id "cat" :class "happy"))
|
|
(div3 (div :id "container" "some children text" div1))
|
|
(div4 (div :id "dog" :class "happy" (list (list div1) div2) (list div3))))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div1))))
|
|
(is (eql nil (element-children div1)))
|
|
(is (equal '((:id . "cat") (:class . "happy")) (attrs-alist (element-attrs div2))))
|
|
(is (eql nil (element-children div2)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div3))))
|
|
(is (equal (list "some children text" div1) (element-children div3)))
|
|
(is (equal '((:id . "dog") (:class . "happy")) (attrs-alist (element-attrs div4))))
|
|
(is (equal (list div1 div2 div3) (element-children div4)))))
|
|
|
|
(test attr-given-by-attrs
|
|
(let* ((div00 (div (make-attrs)))
|
|
(div01 (div (make-attrs :alist nil) "some text"))
|
|
(div1 (div (make-attrs :alist '((:id . "container")))))
|
|
(div2 (div (make-attrs :alist '((:id . "cat") (:class . "happy")))))
|
|
(div3 (div (make-attrs :alist '((:id . "container"))) "some children text" div1))
|
|
(div4 (div (make-attrs :alist '((:id . "dog") (:class . "happy"))) (list (list div1) div2) (list div3))))
|
|
(is (eql nil (attrs-alist (element-attrs div00))))
|
|
(is (eql nil (element-children div00)))
|
|
(is (eql nil (attrs-alist (element-attrs div01))))
|
|
(is (equal (list "some text") (element-children div01)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div1))))
|
|
(is (eql nil (element-children div1)))
|
|
(is (equal '((:id . "cat") (:class . "happy")) (attrs-alist (element-attrs div2))))
|
|
(is (eql nil (element-children div2)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div3))))
|
|
(is (equal (list "some children text" div1) (element-children div3)))
|
|
(is (equal '((:id . "dog") (:class . "happy")) (attrs-alist (element-attrs div4))))
|
|
(is (equal (list div1 div2 div3) (element-children div4)))))
|
|
|
|
(test attr-given-by-alist
|
|
(let* ((div00 (div nil))
|
|
(div01 (div nil "some text"))
|
|
(div1 (div '((:id . "container"))))
|
|
(div2 (div '((:id . "cat") (:class . "happy"))))
|
|
(div3 (div '((:id . "container")) "some children text" div1))
|
|
(div4 (div '((:id . "dog") (:class . "happy")) (list (list div1) div2) (list div3))))
|
|
(is (eql nil (attrs-alist (element-attrs div00))))
|
|
(is (eql nil (element-children div00)))
|
|
(is (eql nil (attrs-alist (element-attrs div01))))
|
|
(is (equal (list "some text") (element-children div01)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div1))))
|
|
(is (eql nil (element-children div1)))
|
|
(is (equal '((:id . "cat") (:class . "happy")) (attrs-alist (element-attrs div2))))
|
|
(is (eql nil (element-children div2)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div3))))
|
|
(is (equal (list "some children text" div1) (element-children div3)))
|
|
(is (equal '((:id . "dog") (:class . "happy")) (attrs-alist (element-attrs div4))))
|
|
(is (equal (list div1 div2 div3) (element-children div4)))))
|
|
|
|
(test attr-given-by-plist
|
|
(let* ((div00 (div nil))
|
|
(div01 (div nil "some text"))
|
|
(div1 (div '(:id "container")))
|
|
(div2 (div '(:id "cat" :class "happy")))
|
|
(div3 (div '(:id "container") "some children text" div1))
|
|
(div4 (div '(:id "dog" :class "happy") (list (list div1) div2) (list div3))))
|
|
(is (eql nil (attrs-alist (element-attrs div00))))
|
|
(is (eql nil (element-children div00)))
|
|
(is (eql nil (attrs-alist (element-attrs div01))))
|
|
(is (equal (list "some text") (element-children div01)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div1))))
|
|
(is (eql nil (element-children div1)))
|
|
(is (equal '((:id . "cat") (:class . "happy")) (attrs-alist (element-attrs div2))))
|
|
(is (eql nil (element-children div2)))
|
|
(is (equal '((:id . "container")) (attrs-alist (element-attrs div3))))
|
|
(is (equal (list "some children text" div1) (element-children div3)))
|
|
(is (equal '((:id . "dog") (:class . "happy")) (attrs-alist (element-attrs div4))))
|
|
(is (equal (list div1 div2 div3) (element-children div4)))))
|
|
|
|
|
|
|
|
(run-all-tests)
|
|
|
|
;; (define-element clock (id size)
|
|
;; (div :id id
|
|
;; (h1 "clock")
|
|
;; (img "blabal" :size size)
|
|
;; children))
|