;;; Weeb --- Web microframework for GNU Guile ;;; Copyright © 2026 Jakob Kreuze ;;; ;;; This file is part of Weeb. ;;; ;;; Weeb is free software: you can redistribute it and/or modify it ;;; under the terms of the GNU Affero General Public License as ;;; published by the Free Software Foundation, either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; Weeb is distributed in the hope that it will be useful, but WITHOUT ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General ;;; Public License for more details. ;;; ;;; You should have received a copy of the GNU Affero General Public ;;; License along with Weeb. If not, see . (use-modules (srfi srfi-64) (weeb sxml)) ;; Private imports for testing purposes. (define html-encode (@@ (weeb sxml) html-encode)) (test-runner-current (test-runner-simple)) (test-begin "weeb-sxml") (test-group "html-encode" (test-equal "encode simple text" "hello" (html-encode "hello")) (test-equal "encode special characters" "<b> & " '" (html-encode " & \" '"))) (test-group "sxml->html-document" (let ((doc '(html (body (p "Hello World"))))) (test-equal "render simple document" "

Hello World

" (sxml->html-document doc)))) (test-group "sxml->html" (test-equal "text node" "just text" (sxml->html "just text")) (test-equal "simple tag" "text" (sxml->html '(html "text"))) (test-equal "nested tags" "
nested
" (sxml->html '(div (span "nested")))) (test-equal "attributes" "

content

" (sxml->html '(p (@ (class "text") (id "main")) "content"))) (test-equal "multiple attributes" "link" (sxml->html '(a (@ (href "/") (rel "nofollow")) "link"))) (test-equal "self-closing tag" "" (sxml->html '(img (@ (src "logo.png"))))) (test-equal "html-encoded content" "

<script>alert("xss")</script>

" (sxml->html '(p ""))) (test-equal "no encoding for script" "" (sxml->html '(script "alert(\"1\" > \"2\");"))) (test-equal "deep nesting" "
    • item
" (sxml->html '(ul (li (ul (li "item")))))) (test-equal "empty non-self-closing tag" "
" (sxml->html '(div))) (test-equal "complex mix" "

Title

Text

" (sxml->html '(article (header (h1 "Title")) (p "Text"))))) (test-end)