Skip to content

Instantly share code, notes, and snippets.

@andineck
Created May 12, 2015 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andineck/f863a38d699976830de9 to your computer and use it in GitHub Desktop.
Save andineck/f863a38d699976830de9 to your computer and use it in GitHub Desktop.
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