mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 06:09:18 +02:00
By convention, a library meant for testing exports "run-tests". Also by convention, assume the test for (foo bar) is (foo bar-test), keeping the test in the same directory and avoiding confusion since (chibi test) is not a test for (chibi). - Avoids the hack of "load"ing test, with resulting namespace complications. - Allows keeping tests together with the libraries. - Allows setting up test hooks before running. - Allows implicit inference of test locations when using above conventions.
67 lines
3 KiB
Scheme
67 lines
3 KiB
Scheme
(define-library (chibi uri-test)
|
|
(export run-tests)
|
|
(import (chibi) (chibi test) (chibi uri))
|
|
(begin
|
|
(define (run-tests)
|
|
(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))))
|