Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:akaspin/daleth

  • Loading branch information...
commit 2f541c86857c8e8790722585476260c0c8900e0f 2 parents 0654966 + b4484d1
@akaspin authored
Showing with 41 additions and 41 deletions.
  1. +12 −12 index.js
  2. +29 −29 test/test-basic.js
View
24 index.js
@@ -1,16 +1,16 @@
function daleth(){
- var routes = arguments;
- return function(path, callback) {
- path = path.split('?')[0]; //
- for (var i in routes) {
- var match = routes[i][0].exec(path);
- if (match){
- callback(routes[i][1],
- (match.length==1) ? [] : match.splice(1,1));
- return;
- }
- }
- };
+ var routes = arguments;
+ return function(path, callback) {
+ path = path.split('?')[0]; //
+ for (var i in routes) {
+ var match = routes[i][0].exec(path);
+ if (match){
+ callback(routes[i][1],
+ (match.length==1) ? [] : match.splice(1,1));
+ return;
+ }
+ }
+ };
};
module.exports = daleth;
View
58 test/test-basic.js
@@ -2,47 +2,47 @@ var sys = require('sys');
var assert = require('assert');
var tester = function(name, args, expect) {
- assert.equal(name, expect.name);
- assert.deepEqual(args, expect.args);
+ assert.equal(name, expect.name);
+ assert.deepEqual(args, expect.args);
};
var route = require("../")(
[/^\/user\/?$/, function(args, expect) {
- tester('#1', args, expect);
- }],
+ tester('#1', args, expect);
+ }],
[/^\/user\/([a-z]+)\/?$/, function(args, expect) {
- tester('#2', args, expect);
- }],
+ tester('#2', args, expect);
+ }],
[/^\/$/, function(args, expect) {
- tester('#3', args, expect);
- }],
+ tester('#3', args, expect);
+ }],
[/^\/.*$/, function(args, expect) {
- tester('Fallback', args, expect);
- }] // Fallback - catch all unhandled
+ tester('Fallback', args, expect);
+ }] // Fallback - catch all unhandled
);
[
- {path: "/fall", expect: {name:"Fallback", args:[]}},
- {path: "/fall/any", expect: {name:"Fallback", args:[]}},
- {path: "/Fall/any", expect: {name:"Fallback", args:[]}},
- {path: "/", expect: {name:"#3", args:[]}},
- {path: "/user", expect: {name:"#1", args:[]}},
- {path: "/user/", expect: {name:"#1", args:[]}},
- {path: "/User", expect: {name:"Fallback", args:[]}},
- {path: "/User/", expect: {name:"Fallback", args:[]}},
- {path: "/user/name", expect: {name:"#2", args:["name"]}},
- {path: "/user/name?slug=test", expect: {name:"#2", args:["name"]}},
- {path: "/user/name/?slug=test", expect: {name:"#2", args:["name"]}},
- {path: "/user/smith", expect: {name:"#2", args:["smith"]}},
- {path: "/user/name/any", expect: {name:"Fallback", args:[]}},
- {path: "/user/nam1", expect: {name:"Fallback", args:[]}},
+ {path: "/fall", expect: {name:"Fallback", args:[]}},
+ {path: "/fall/any", expect: {name:"Fallback", args:[]}},
+ {path: "/Fall/any", expect: {name:"Fallback", args:[]}},
+ {path: "/", expect: {name:"#3", args:[]}},
+ {path: "/user", expect: {name:"#1", args:[]}},
+ {path: "/user/", expect: {name:"#1", args:[]}},
+ {path: "/User", expect: {name:"Fallback", args:[]}},
+ {path: "/User/", expect: {name:"Fallback", args:[]}},
+ {path: "/user/name", expect: {name:"#2", args:["name"]}},
+ {path: "/user/name?slug=test", expect: {name:"#2", args:["name"]}},
+ {path: "/user/name/?slug=test", expect: {name:"#2", args:["name"]}},
+ {path: "/user/smith", expect: {name:"#2", args:["smith"]}},
+ {path: "/user/name/any", expect: {name:"Fallback", args:[]}},
+ {path: "/user/nam1", expect: {name:"Fallback", args:[]}},
]
.forEach(function(test){
- var req = test.path;
- var expect = test.expect;
- route(req, function(handler, args) {
- handler(args, expect);
- });
+ var req = test.path;
+ var expect = test.expect;
+ route(req, function(handler, args) {
+ handler(args, expect);
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.