chibi-scheme/tests/uri-tests.scm
Alex Shinn 8b5eb68238 File descriptors maintain a reference count of ports open on them
They can be close()d explicitly with close-file-descriptor, and
will close() on gc, but only explicitly closing the last port on
them will close the fileno.  Notably needed for network sockets
where we open separate input and output ports on the same socket.
2014-02-20 22:32:50 +09:00

65 lines
2.6 KiB
Scheme

(import (chibi) (chibi test) (chibi uri))
(test-begin "uri")
(test-assert (uri? (make-uri 'http)))
(test 'http (uri-scheme (make-uri 'http)))
(test "r" (uri-user (make-uri 'http "r")))
(test "google.com" (uri-host (make-uri 'http "r" "google.com")))
(test 80 (uri-port (make-uri 'http "r" "google.com" 80)))
(test "/search" (uri-path (make-uri 'http "r" "google.com" 80 "/search")))
(test "q=cats"
(uri-query (make-uri 'http "r" "google.com" 80 "/search" "q=cats")))
(test "recent"
(uri-fragment
(make-uri 'http "r" "google.com" 80 "/search" "q=cats" "recent")))
(let ((str "http://google.com"))
(test-assert (uri? (string->uri str)))
(test 'http (uri-scheme (string->uri str)))
(test "google.com" (uri-host (string->uri str)))
(test #f (uri-port (string->uri str)))
(test #f (uri-path (string->uri str)))
(test #f (uri-query (string->uri str)))
(test #f (uri-fragment (string->uri str))))
(let ((str "http://google.com/"))
(test-assert (uri? (string->uri str)))
(test 'http (uri-scheme (string->uri str)))
(test "google.com" (uri-host (string->uri str)))
(test #f (uri-port (string->uri str)))
(test "/" (uri-path (string->uri str)))
(test #f (uri-query (string->uri str)))
(test #f (uri-fragment (string->uri str))))
(let ((str "http://google.com:80/search?q=cats#recent"))
(test-assert (uri? (string->uri str)))
(test 'http (uri-scheme (string->uri str)))
(test "google.com" (uri-host (string->uri str)))
(test 80 (uri-port (string->uri str)))
(test "/search" (uri-path (string->uri str)))
(test "q=cats" (uri-query (string->uri str)))
(test "recent" (uri-fragment (string->uri str))))
(test "/%73" (uri-path (string->uri "http://google.com/%73")))
(test "/s" (uri-path (string->uri "http://google.com/%73" #t)))
(test "a=1&b=2;c=3"
(uri-query (string->uri "http://google.com/%73?a=1&b=2;c=3" #t)))
(test '(("a" . "1") ("b" . "2") ("c" . "3"))
(uri-query (string->uri "http://google.com/%73?a=1&b=2;c=3" #t #t)))
(test '(("a" . "1") ("b" . "2+2") ("c" . "3"))
(uri-query (string->uri "http://google.com/%73?a=1&b=2+2;c=%33" #f #t)))
(test '(("a" . "1") ("b" . "2 2") ("c" . "3"))
(uri-query (string->uri "http://google.com/%73?a=1&b=2+2;c=%33" #t #t)))
(let ((str "/"))
(test-assert (uri? (string->path-uri 'http str)))
(test 'http (uri-scheme (string->path-uri 'http str)))
(test #f (uri-host (string->path-uri 'http str)))
(test #f (uri-port (string->path-uri 'http str)))
(test "/" (uri-path (string->path-uri 'http str)))
(test #f (uri-query (string->path-uri 'http str)))
(test #f (uri-fragment (string->path-uri 'http str))))
(test-end)