-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lisp
188 lines (168 loc) · 4.71 KB
/
test.lisp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
(defpackage :rerout-test
(:use :cl :parachute))
(in-package :rerout-test)
(defun test-route (router method url
expected-result
expected-parameters
expected-canonical)
(multiple-value-bind (result parameters canonical)
(rerout:route router method url)
(if expected-result
(is equal expected-result result)
(false result))
(if expected-parameters
(is equal expected-parameters parameters)
(false parameters))
(if expected-canonical
(is equal expected-canonical canonical)
(false canonical))))
(rerout:define-router simple-root ()
(:get "/" "get")
(:post "/" "post"))
(define-test "Simple root, GET"
(test-route 'simple-root :get "/"
"get"
nil
nil)
(test-route 'simple-root :get "/a"
nil
nil
nil))
(define-test "Simple root, POST"
(test-route 'simple-root :post "/"
"post"
nil
nil)
(test-route 'simple-root :post "/a"
nil
nil
nil))
(rerout:define-router simple-parts ()
(:get "/a/b/c" "a")
(:get "/b/c" "b")
(:get "/c" "c"))
(define-test "Simple parts, length 3"
(test-route 'simple-parts :get "/a/b/c"
"a"
nil
nil)
(test-route 'simple-parts :get "/a"
nil
nil
nil)
(test-route 'simple-parts :get "/a/b"
nil
nil
nil))
(define-test "Simple parts, length 2"
(test-route 'simple-parts :get "/b/c"
"b"
nil
nil)
(test-route 'simple-parts :get "/b"
nil
nil
nil))
(define-test "Simple parts, length 1"
(test-route 'simple-parts :get "/c"
"c"
nil
nil)
(test-route 'simple-parts :get "/"
nil
nil
nil))
(rerout:define-router simple-colons ()
(:get "/:a" "/:a")
(:get "/a/:a" "/a/:a")
(:get "/:a/a" "/:a/a"))
(define-test "Simple colons, length 1"
(test-route 'simple-colons :get "/"
nil
nil
nil)
(test-route 'simple-colons :get "/test"
"/:a"
'(:a "test")
nil))
(define-test "Simple colons, length 2"
(test-route 'simple-colons :get "/a/test"
"/a/:a"
'(:a "test")
nil)
(test-route 'simple-colons :get "/test/a"
"/:a/a"
'(:a "test")
nil))
(rerout:define-router simple-splat ()
(:get "/a/*a" "a")
(:get "/*b" "b"))
(define-test "Simple splat, length 2"
(test-route 'simple-splat :get "/a/foo"
"a"
'(:a "foo")
nil)
(test-route 'simple-splat :get "/a/foo/"
"a"
'(:a "foo/")
nil))
(define-test "Simple splat, length 1"
(test-route 'simple-splat :get "/b/foo"
"b"
'(:b "b/foo")
nil)
(test-route 'simple-splat :get "/foo/bar/baz/"
"b"
'(:b "foo/bar/baz/")
nil))
(rerout:define-router canonicalization ()
(:get "/a/a" "a without")
(:get "/b/b/" "b with")
(:get "/c/:c" "c without")
(:get "/d/:d/" "d with")
(:get "/e/*e" "e without"))
(define-test "Canonicalization, plain without final /"
(test-route 'canonicalization :get "/a/a"
"a without"
nil
nil)
(test-route 'canonicalization :get "/a/a/"
"a without"
nil
"/a/a"))
(define-test "Canonicalization, plain with final /"
(test-route 'canonicalization :get "/b/b/"
"b with"
nil
nil)
(test-route 'canonicalization :get "/b/b"
"b with"
nil
"/b/b/"))
(define-test "Canonicalization, colon without final /"
(test-route 'canonicalization :get "/c/foo"
"c without"
'(:c "foo")
nil)
(test-route 'canonicalization :get "/c/foo/"
"c without"
'(:c "foo")
"/c/foo"))
(define-test "Canonicalization, colon with final /"
(test-route 'canonicalization :get "/d/foo/"
"d with"
'(:d "foo")
nil)
(test-route 'canonicalization :get "/d/foo"
"d with"
'(:d "foo")
"/d/foo/"))
(define-test "Canonicalization, splat"
(test-route 'canonicalization :get "/e/foo"
"e without"
'(:e "foo")
nil)
(test-route 'canonicalization :get "/e/foo/"
"e without"
'(:e "foo/")
nil))