Skip to content

Commit c8e0a94

Browse files
committed
add more tests for scheme, domain, port, email, query string, etc
1 parent 661366c commit c8e0a94

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Diff for: test/match-fixtures.coffee

+50
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,56 @@ test 'match', (t) ->
163163
version: '1'
164164
t.equal null, pattern.match('/vvv1.1/resource')
165165

166+
pattern = new UrlPattern '/api/users/:id',
167+
segmentValueCharset: 'a-zA-Z0-9-_~ %.@'
168+
t.deepEqual pattern.match('/api/users/[email protected]'),
169+
170+
171+
pattern = new UrlPattern '/api/users?username=:username',
172+
segmentValueCharset: 'a-zA-Z0-9-_~ %.@'
173+
t.deepEqual pattern.match('/api/[email protected]'),
174+
username: '[email protected]'
175+
176+
pattern = new UrlPattern '/api/users?param1=:param1&param2=:param2'
177+
t.deepEqual pattern.match('/api/users?param1=foo&param2=bar'),
178+
param1: 'foo'
179+
param2: 'bar'
180+
181+
pattern = new UrlPattern ':scheme\\://:host(\\::port)',
182+
segmentValueCharset: 'a-zA-Z0-9-_~ %.'
183+
t.deepEqual pattern.match('ftp://ftp.example.com'),
184+
scheme: 'ftp'
185+
host: 'ftp.example.com'
186+
t.deepEqual pattern.match('ftp://ftp.example.com:8080'),
187+
scheme: 'ftp'
188+
host: 'ftp.example.com'
189+
port: '8080'
190+
t.deepEqual pattern.match('https://example.com:80'),
191+
scheme: 'https'
192+
host: 'example.com'
193+
port: '80'
194+
195+
pattern = new UrlPattern ':scheme\\://:host(\\::port)(/api(/:resource(/:id)))',
196+
segmentValueCharset: 'a-zA-Z0-9-_~ %.@'
197+
t.deepEqual pattern.match('https://sss.www.localhost.com'),
198+
scheme: 'https'
199+
host: 'sss.www.localhost.com'
200+
t.deepEqual pattern.match('https://sss.www.localhost.com:8080'),
201+
scheme: 'https'
202+
host: 'sss.www.localhost.com'
203+
port: '8080'
204+
t.deepEqual pattern.match('https://sss.www.localhost.com/api'),
205+
scheme: 'https'
206+
host: 'sss.www.localhost.com'
207+
t.deepEqual pattern.match('https://sss.www.localhost.com/api/security'),
208+
scheme: 'https'
209+
host: 'sss.www.localhost.com'
210+
resource: 'security'
211+
t.deepEqual pattern.match('https://sss.www.localhost.com/api/security/[email protected]'),
212+
scheme: 'https'
213+
host: 'sss.www.localhost.com'
214+
resource: 'security'
215+
166216

167217
regex = /\/ip\/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
168218
pattern = new UrlPattern regex

0 commit comments

Comments
 (0)