Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
path-to-regexp PR54 tests.
// patch: "path-to-regexp": "git://github.com/pillarjs/path-to-regexp.git#asterisk-match"
var patch = require('./patch/node_modules/path-to-regexp');
// old: "path-to-regexp": "^0.1.3"
var old = require('./0.1.3/node_modules/path-to-regexp');
var assert = require('assert');
// routes: 0: route, 1: path, 2: param
var routes = [
['*', '/test/route/aA/bB/cC', '/test/route/aA/bB/cC'],
['/*', '/test/route/aA/bB/cC', 'test/route/aA/bB/cC'],
['/test*', '/test/route/aA/bB/cC', '/route/aA/bB/cC'],
['/test/*', '/test/route/aA/bB/cC', 'route/aA/bB/cC'],
['/test/route/*', '/test/route/aA/bB/cC', 'aA/bB/cC']
// -> fails with named parameters with wildcard on the old old: -> 'route'
//['/test/:path*', '/test/route/aA/bB/cC', 'route/aA/bB/cC']
];
var keys, result;
routes.forEach(function(route) {
keys = [];
result = patch(route[0], keys).exec(route[1]);
assert.equal(route[2], result[1]);
result = old(route[0], keys).exec(route[1]);
assert.equal(route[2], result[1]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment