aboutsummaryrefslogtreecommitdiff
path: root/tests/request.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/request.scm')
-rw-r--r--tests/request.scm60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/request.scm b/tests/request.scm
new file mode 100644
index 0000000..0b68ea1
--- /dev/null
+++ b/tests/request.scm
@@ -0,0 +1,60 @@
+;;; 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 request))
+
+(test-runner-current (test-runner-simple))
+
+(test-begin "weeb-request")
+
+(test-group "urldecode"
+ (test-equal "hello" (urldecode "hello"))
+ (test-equal "hello world" (urldecode "hello+world"))
+ (test-equal "hello world" (urldecode "hello%20world"))
+ (test-equal "!@#$" (urldecode "%21%40%23%24"))
+ (test-equal "a b c" (urldecode "a+b+c"))
+ (test-equal "a b c" (urldecode "a%20b%20c"))
+ (test-equal "" (urldecode ""))
+ (test-equal "invalid%hex" (urldecode "invalid%hex"))
+ (test-equal "%" (urldecode "%"))
+ (test-equal "100%" (urldecode "100%25")))
+
+(test-group "parse-form-urlencoded"
+ (test-equal '(("key" . "value"))
+ (parse-form-urlencoded "key=value"))
+ (test-equal '(("a" . "1") ("b" . "2"))
+ (parse-form-urlencoded "a=1&b=2"))
+ (test-equal '(("name" . "John Doe"))
+ (parse-form-urlencoded "name=John+Doe"))
+ (test-equal '(("query" . "foo bar"))
+ (parse-form-urlencoded "query=foo%20bar"))
+ (test-equal '(("user_id" . "42") ("role" . "admin"))
+ (parse-form-urlencoded "user_id=42&role=admin"))
+ (test-equal '(("empty" . ""))
+ (parse-form-urlencoded "empty="))
+ (test-equal '(("foo-bar" . "baz"))
+ (parse-form-urlencoded "foo-bar=baz"))
+ (test-equal '(("a" . "1") ("b" . "2") ("c" . "3"))
+ (parse-form-urlencoded "a=1&b=2&c=3"))
+ (test-equal '(("foo" . "bar"))
+ (parse-form-urlencoded "foo=bar")) ; Verifies (string->symbol key)
+ (test-equal '()
+ (parse-form-urlencoded "")))
+
+(test-end)

© 2015 - 2026 Jakob L. Kreuze