Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (87 sloc) 5.67 KB
;; Copying and distribution of this file, with or without
;; modification, are permitted in any medium without royalty provided
;; this notice is preserved. This file is offered as-is, without any
;; warranty.
(in-package #:uri-template.test)
(in-readtable uri-template.test)
(eval-when (:compile-toplevel :load-toplevel :execute)
(def-suite uri-template))
(in-suite uri-template)
(defun run-tests ()
(run! 'uri-template))
(test interpolation3
(let ((bar "bar")
(baz 1))
(is (string= #U{bar}{baz}
(test interpolation2
(let ((bar "bar")
(baz 1))
(is (string= #U{bar}/{baz}
(test interpolation1
(let ((baz 1))
(is (string= #U{baz}
(test interpolation-encoding
(is (string= #U{"^BAZ !bar"}
(test destructuring1
(is (equal (uri-template-bind (#U{part}/{number})
(list part (parse-integer number) %uri-host))
'("widget" 1234 ""))))
(test destructuring2
(is (equal (uri-template-bind (#U{uri})
(list %uri-scheme %uri-host %uri-path %uri-directory %uri-file %uri-query %uri-fragment))
'("https" "" "/dir/1/2/search.html" "/dir/1/2/" "search.html" "arg=0-a&arg1=1-b&arg3-c" "hash"))))
(test destructuring3
(is (equal (uri-template:uri-template-bind (#U/apps/{app-name}/{table-template}/{table-id})
(list app-name table-template table-id %uri-path))
'("EVWeb" "Fixed Cost" "20" "/apps/EVWeb/Fixed Cost/20"))))
(test destructuring4
(is (equal (uri-template-bind (#U{uri})
(list %uri-scheme %uri-authority %uri-path %uri-directory %uri-file %uri-query %uri-fragment))
(test destructuring5
(is (equal (uri-template-bind (#U{uri})
(list %uri-scheme %uri-host %uri-path %uri-directory %uri-file %uri-query %uri-fragment %uri-head %uri-tail))
'("http" "" "/abc" "/" "abc" "bar=baz&xyz=1" "hash" "" "/abc?bar=baz&xyz=1#hash"))))
(test destructuring6
(is (equal (uri-template-bind (#U{uri})
(list %uri-scheme %uri-authority %uri-user %uri-host %uri-port %uri-path %uri-directory %uri-file %uri-query %uri-fragment %uri-head %uri-tail))
'("http" "" "user" "" "8080" "/dir/abc" "/dir/" "abc" "bar=baz&xyz=1" "hash" "" "/dir/abc?bar=baz&xyz=1#hash"))))
(test destructuring7
(is (equal (uri-template-bind (#U{uri})
(list %uri-scheme %uri-host %uri-path %uri-directory %uri-file %uri-query %uri-fragment))
'("http" "" "/" "/" nil "bar=baz&xyz=1" nil))))
(test destructuring8
(is (equal (uri-template-bind (#U{uri}) ""
(list %uri-scheme %uri-authority (list %uri-user %uri-host %uri-port)
%uri-path (list %uri-directory %uri-file) %uri-query %uri-fragment))
'("http" "" ("user" "" "8080") "/dir1/dir2/file"
("/dir1/dir2/" "file") "query=want&a=b" "hash"))))
(test destructuring9
(is (equal (uri-template-bind (#U{uri}) "/foo/bar"
(list %uri-head %uri-tail %uri-scheme
%uri-authority (list %uri-user %uri-host %uri-port)
%uri-path (list %uri-directory %uri-file) %uri-query %uri-fragment))
'(NIL "/foo/bar" NIL NIL (NIL NIL NIL) "/foo/bar" ("/foo/" "bar") NIL NIL))))
(test encoding1
(is (string= "abc123" (uri-encode "abc123"))))
(test encoding2
(is (string= "abc%20123" (uri-encode "abc 123"))))
(test encoding3
(is (string= "abc123" (uri-decode "abc123"))))
(test encoding4
(is (string= "abc 123" (uri-decode "abc%20123"))))
(test unicode-encoding1
(is (string= "%D1%84%D0%BE%D0%BE" (uri-encode "фоо"))))
(test unicode-encoding2
(is (string= "бар" (uri-decode "%D0%B1%D0%B0%D1%80"))))