Skip to content

Commit 661366c

Browse files
committed
add some regex match fixtures to illustrate ip address matching
1 parent 0e223b3 commit 661366c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/match-fixtures.coffee

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,39 @@ test 'match', (t) ->
161161
t.deepEqual pattern.match('/vvv1/resource'),
162162
_: 'resource'
163163
version: '1'
164-
t.equal null, pattern.match('/vvv1.1/resource'),
164+
t.equal null, pattern.match('/vvv1.1/resource')
165+
166+
167+
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]?)$/
168+
pattern = new UrlPattern regex
169+
t.equal null, pattern.match('10.10.10.10')
170+
t.equal null, pattern.match('ip/10.10.10.10')
171+
t.equal null, pattern.match('/ip/10.10.10.')
172+
t.equal null, pattern.match('/ip/10.')
173+
t.equal null, pattern.match('/ip/')
174+
t.deepEqual pattern.match('/ip/10.10.10.10'), ['10', '10', '10', '10']
175+
t.deepEqual pattern.match('/ip/127.0.0.1'), ['127', '0', '0', '1']
176+
177+
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]?))$/
178+
pattern = new UrlPattern regex
179+
t.equal null, pattern.match('10.10.10.10')
180+
t.equal null, pattern.match('ip/10.10.10.10')
181+
t.equal null, pattern.match('/ip/10.10.10.')
182+
t.equal null, pattern.match('/ip/10.')
183+
t.equal null, pattern.match('/ip/')
184+
t.deepEqual pattern.match('/ip/10.10.10.10'), ['10.10.10.10']
185+
t.deepEqual pattern.match('/ip/127.0.0.1'), ['127.0.0.1']
186+
187+
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]?))$/
188+
pattern = new UrlPattern regex, ['ip']
189+
t.equal null, pattern.match('10.10.10.10')
190+
t.equal null, pattern.match('ip/10.10.10.10')
191+
t.equal null, pattern.match('/ip/10.10.10.')
192+
t.equal null, pattern.match('/ip/10.')
193+
t.equal null, pattern.match('/ip/')
194+
t.deepEqual pattern.match('/ip/10.10.10.10'),
195+
ip: '10.10.10.10'
196+
t.deepEqual pattern.match('/ip/127.0.0.1'),
197+
ip: '127.0.0.1'
165198

166199
t.end()

0 commit comments

Comments
 (0)