Skip to content

Commit 43b8c48

Browse files
committed
Failing test case for index value
1 parent 66f8d3f commit 43b8c48

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,90 @@ describe('path-to-regexp', function () {
4646
assert.ok(!m);
4747
});
4848

49+
it('should match wildcards', function () {
50+
var params = [];
51+
var m = pathToRegExp('/*', params).exec('/pathname');
52+
53+
assert.equal(params.length, 0);
54+
55+
assert.equal(m.length, 2);
56+
assert.equal(m[0], '/pathname');
57+
assert.equal(m[1], 'pathname');
58+
});
59+
60+
it('should match wildcards without leading /', function () {
61+
var params = [];
62+
var m = pathToRegExp('*', params).exec('/pathname');
63+
64+
assert.equal(params.length, 0);
65+
66+
assert.equal(m.length, 2);
67+
assert.equal(m[0], '/pathname');
68+
assert.equal(m[1], '/pathname');
69+
});
70+
71+
it('should match wildcards with express params', function () {
72+
var params = [];
73+
var m = pathToRegExp('/:test/*', params).exec('/pathone/pathtwo');
74+
75+
assert.equal(params.length, 1);
76+
assert.equal(params[0].name, 'test');
77+
assert.equal(params[0].optional, false);
78+
assert.equal(params[0].index, 0);
79+
80+
assert.equal(m.length, 3);
81+
assert.equal(m[0], '/pathone/pathtwo');
82+
assert.equal(m[1], 'pathone');
83+
assert.equal(m[2], 'pathtwo');
84+
});
85+
86+
it('should match wildcards with express params (reverse order)', function () {
87+
var params = [];
88+
var m = pathToRegExp('/*/:test', params).exec('/pathone/pathtwo');
89+
90+
assert.equal(params.length, 1);
91+
assert.equal(params[0].name, 'test');
92+
assert.equal(params[0].optional, false);
93+
assert.equal(params[0].index, 1);
94+
95+
assert.equal(m.length, 3);
96+
assert.equal(m[0], '/pathone/pathtwo');
97+
assert.equal(m[1], 'pathone');
98+
assert.equal(m[2], 'pathtwo');
99+
});
100+
101+
it('should match wildcards with express params (reverse order, no leading /)', function () {
102+
var params = [];
103+
var m = pathToRegExp('*/:test', params).exec('/pathone/pathtwo');
104+
105+
assert.equal(params.length, 1);
106+
assert.equal(params[0].name, 'test');
107+
assert.equal(params[0].optional, false);
108+
assert.equal(params[0].index, 1);
109+
110+
assert.equal(m.length, 3);
111+
assert.equal(m[0], '/pathone/pathtwo');
112+
assert.equal(m[1], '/pathone');
113+
assert.equal(m[2], 'pathtwo');
114+
});
115+
116+
it('should have proper indexes when using multiple wildcards', function () {
117+
var params = [];
118+
var m = pathToRegExp('*/:test/*/:foo/*/:bar/*', params).exec('/a/b/c/d/e/f/g');
119+
120+
assert.equal(params.length, 3);
121+
assert.equal(params[0].name, 'test');
122+
assert.equal(params[0].optional, false);
123+
assert.equal(params[0].index, 1);
124+
125+
assert.equal(params[1].name, 'foo');
126+
assert.equal(params[1].index, 3);
127+
128+
assert.equal(params[2].name, 'bar');
129+
assert.equal(params[2].index, 5);
130+
131+
});
132+
49133
it('should do strict matches with trailing slashes', function () {
50134
var params = [];
51135
var re = pathToRegExp('/:test/', params, { strict: true });

0 commit comments

Comments
 (0)