Skip to content

Commit

Permalink
Replace whitespace tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
akaspin committed Jul 14, 2010
1 parent 798fad1 commit b4484d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
58 changes: 29 additions & 29 deletions test/test-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});


0 comments on commit b4484d1

Please sign in to comment.