aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/response.scm18
-rw-r--r--tests/router.scm18
-rw-r--r--tests/struct.scm18
-rw-r--r--tests/sxml.scm87
4 files changed, 141 insertions, 0 deletions
diff --git a/tests/response.scm b/tests/response.scm
index e382169..2e36ba3 100644
--- a/tests/response.scm
+++ b/tests/response.scm
@@ -1,3 +1,21 @@
+;;; Weeb --- Web microframework for GNU Guile
+;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; 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 <https://www.gnu.org/licenses/>.
+
(use-modules (srfi srfi-64)
(weeb response)
(weeb struct))
diff --git a/tests/router.scm b/tests/router.scm
index 6f1ddfb..59ec793 100644
--- a/tests/router.scm
+++ b/tests/router.scm
@@ -1,3 +1,21 @@
+;;; Weeb --- Web microframework for GNU Guile
+;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; 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 <https://www.gnu.org/licenses/>.
+
(use-modules (srfi srfi-11)
(srfi srfi-64)
(weeb router)
diff --git a/tests/struct.scm b/tests/struct.scm
index 7662fed..01c984d 100644
--- a/tests/struct.scm
+++ b/tests/struct.scm
@@ -1,3 +1,21 @@
+;;; Weeb --- Web microframework for GNU Guile
+;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; 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 <https://www.gnu.org/licenses/>.
+
(use-modules (srfi srfi-64)
(weeb struct))
diff --git a/tests/sxml.scm b/tests/sxml.scm
new file mode 100644
index 0000000..569fae1
--- /dev/null
+++ b/tests/sxml.scm
@@ -0,0 +1,87 @@
+;;; Weeb --- Web microframework for GNU Guile
+;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; 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 <https://www.gnu.org/licenses/>.
+
+(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"
+ "&lt;b&gt; &amp; &quot; &#39;"
+ (html-encode "<b> & \" '")))
+
+(test-group "sxml->html-document"
+ (let ((doc '(html (body (p "Hello World")))))
+ (test-equal "render simple document"
+ "<!DOCTYPE html><html><body><p>Hello World</p></body></html>"
+ (sxml->html-document doc))))
+
+(test-group "sxml->html"
+ (test-equal "text node"
+ "just text"
+ (sxml->html "just text"))
+
+ (test-equal "simple tag"
+ "<html>text</html>"
+ (sxml->html '(html "text")))
+
+ (test-equal "nested tags"
+ "<div><span>nested</span></div>"
+ (sxml->html '(div (span "nested"))))
+
+ (test-equal "attributes"
+ "<p class=\"text\" id=\"main\">content</p>"
+ (sxml->html '(p (@ (class "text") (id "main")) "content")))
+
+ (test-equal "multiple attributes"
+ "<a href=\"/\" rel=\"nofollow\">link</a>"
+ (sxml->html '(a (@ (href "/") (rel "nofollow")) "link")))
+
+ (test-equal "self-closing tag"
+ "<img src=\"logo.png\">"
+ (sxml->html '(img (@ (src "logo.png")))))
+
+ (test-equal "html-encoded content"
+ "<p>&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;</p>"
+ (sxml->html '(p "<script>alert(\"xss\")</script>")))
+
+ (test-equal "no encoding for script"
+ "<script>alert(\"1\" > \"2\");</script>"
+ (sxml->html '(script "alert(\"1\" > \"2\");")))
+
+ (test-equal "deep nesting"
+ "<ul><li><ul><li>item</li></ul></li></ul>"
+ (sxml->html '(ul (li (ul (li "item"))))))
+
+ (test-equal "empty non-self-closing tag"
+ "<div></div>"
+ (sxml->html '(div)))
+
+ (test-equal "complex mix"
+ "<article><header><h1>Title</h1></header><p>Text</p></article>"
+ (sxml->html '(article (header (h1 "Title")) (p "Text")))))
+
+(test-end)

© 2015 - 2026 Jakob L. Kreuze