aboutsummaryrefslogtreecommitdiff
path: root/tests/request.scm
blob: 0b68ea127c2120ff3631d8be887025da50ff5aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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