Skip to content

Commit

Permalink
Add 3 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceColl committed Mar 5, 2024
1 parent 85142b7 commit 4d43f21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chobun.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ in the generated code, so it feels like using Lisp."
(cons *dynamic-html-gensym* (list res))))

(defun eval-html (tree)
(let ((html-gen (optimize-html-codegen (parse-html tree))))
(let ((html-gen (parse-html tree)))
(eval `(progn ,@html-gen))))

(defun maybe-eval-html (tree)
Expand Down
24 changes: 24 additions & 0 deletions t/chobun.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
(let ,vars
(is string= ,expected-output (html ,html-tree))))))

(defun component (val)
(html
(:div
(:h1 val))))

(defun dynamic-component (vals)
(with-dynamic-html
(loop for val in vals
collect `(:li (:div (:h1 ,val))))))

(html-test "Single tag" (:div "Hola") "<div>Hola</div>")
(html-test "Nested tags" (:div (:span "Hola")) "<div><span>Hola</span></div>")
(html-test "Same level tags" (:div (:span "Hola") (:h1 "Title")) "<div><span>Hola</span><h1>Title</h1></div>")
Expand Down Expand Up @@ -40,3 +50,17 @@
(:div (if (= (mod i 2) 0)
(:span (format nil "~a is EVEN" i))))))
"<div><div><span>0 is EVEN</span></div><div></div><div><span>2 is EVEN</span></div><div></div><div><span>4 is EVEN</span></div><div></div></div>")
(html-test "functions"
(:div (component "hola")
(component "adeu"))
"<div><div><h1>hola</h1></div><div><h1>adeu</h1></div></div>")

(html-test "functions and dolist"
(:ul
(dolist (val '("hola" "adeu" "wassup"))
(:li (component val))))
"<ul><li><div><h1>hola</h1></div></li><li><div><h1>adeu</h1></div></li><li><div><h1>wassup</h1></div></li></ul>")

(html-test "dynamic-html"
(:ul (dynamic-component '("hola" "adeu" "wassup")))
"<ul><li><div><h1>hola</h1></div></li><li><div><h1>adeu</h1></div></li><li><div><h1>wassup</h1></div></li></ul>")

0 comments on commit 4d43f21

Please sign in to comment.