Skip to content

Commit 9417453

Browse files
committed
Add tests for new functions
1 parent 278720f commit 9417453

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

splitflap-tests/tests/construct-tests.rkt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
racket/file
77
racket/runtime-path
88
rackunit
9-
splitflap/private/validation
10-
splitflap/private/feed)
9+
splitflap)
1110

1211
;; ~~ DNS Domain validation (RFC 1035) ~~~~~~~~~~~
1312

@@ -75,6 +74,29 @@
7574
(check-false (valid-url-string? "ldap://[2001:db8::7]/c=GB?objectClass?one"))
7675
(check-false (valid-url-string? "telnet://192.0.2.16:80/"))
7776

77+
;; ~~ URL convenience functions ~~~~~~~~~~~~~~~~~~
78+
79+
(check-equal? (url-domain "http://example.com") "example.com")
80+
(check-equal? (url-domain "https://user:p@example.com:8080/path/to/file") "example.com")
81+
(check-exn exn:fail:contract? (lambda () (url-domain "x")))
82+
83+
;; ensure paths are tested accurately on all platforms
84+
(define rel-path (build-path "path" "to" "my file.html"))
85+
(check-true (relative-path? rel-path))
86+
(define abs-path (path->complete-path rel-path))
87+
(check-true (absolute-path? abs-path))
88+
89+
(check-equal? (url-join "http://example.com" rel-path) ; bare domain w/o trailing slash
90+
"http://example.com/path/to/my%20file.html")
91+
(check-equal? (url-join "http://example.com/" rel-path) ; bare domain w/trailing slash
92+
"http://example.com/path/to/my%20file.html")
93+
(check-equal? (url-join "http://example.com/dir/final" rel-path) ; final elem w/o trailing slash removed
94+
"http://example.com/dir/path/to/my%20file.html")
95+
(check-equal? (url-join "http://example.com/my dir/" rel-path) ; final element w/trailing slash kept
96+
"http://example.com/my%20dir/path/to/my%20file.html")
97+
(check-exn exn:fail:contract? (lambda () (url-join "x" "x"))) ; invalid URL string
98+
(check-exn exn:fail:contract? (lambda () (url-join "http://example.com" abs-path))) ; no absolute paths
99+
78100
;; ~~ Tag URIs (RFC 4151) ~~~~~~~~~~~~~~~~~~~~~~~~
79101
(check-true (tag-specific-string? "abcdefghijklmnopqrstuvwxyz0123456789"))
80102
(check-true (tag-specific-string? "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))

0 commit comments

Comments
 (0)