Skip to content

Commit

Permalink
better test. git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
saambarati committed Jun 30, 2012
1 parent 1acac37 commit b8b74a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions tests/test-cblength.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ var assert = require('assert')
, mapleTree = require('../treeRouter.js')
, router = new mapleTree.RouteTree()

router.define('/foo/bar', function(){})
router.define('/bar', function(){})
router.define('/foo/bar/hello', function(){})
function a() {}
function b() {}
function c(){}
router.define('/foo/bar', a)
router.define('/bar', b)
router.define('/foo/bar/hello', c)

var route = router.match('/bar')
assert.ok(route.fn instanceof Function, 'Should match a route.')
assert.equal(route.fn, b)
assert.equal(route.cbs.length, 0, 'Should match one and only one route.')

var route = router.match('/foo/bar')
assert.ok(route.fn instanceof Function, 'Should match a route.')
assert.equal(route.fn, a)
assert.equal(route.cbs.length, 0, 'Should match one and only one route.') // This will throw

var route = router.match('/foo/bar/hello')
assert.ok(route.fn instanceof Function)
assert.equal(route.fn, c)
assert.equal(route.cbs[0], a)
assert.equal(route.cbs.length, 1) //should match two routes '/foo/bar callback && /foo/bar/hello callback'

2 changes: 1 addition & 1 deletion treeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ RouteTree.prototype._matchRecursiveHelper = function (curNode, curPath, matcher)
matcher.cbs.push(mNode.callback)
}
}
return
return //dive deeper into the tree, don't allow more matches at this level in the tree
}
}
}
Expand Down

0 comments on commit b8b74a4

Please sign in to comment.