Permalink
Browse files

tests

  • Loading branch information...
saambarati committed Jul 1, 2012
1 parent b8b74a4 commit 0790e4c39c7c59903c364065435b66a1baeeee5c
Showing with 24 additions and 26 deletions.
  1. +11 −10 tests/test-next.js
  2. +12 −15 tests/test-similar.js
  3. +1 −1 treeRouter.js
View
@@ -7,31 +7,32 @@ var maple = require('../treeRouter.js')
//note cbs.length is one less than matching routes, this is because the best match is placed in match.fn when '.match()' is invoked
//keep in mind, these functions can be defined in any order, because there are no conflicts between them
tree.define('/hello/', function () {
- console.log('/hello/')
+ //console.log('/hello/')
this.next()
})
tree.define('/hello/world', function () {
- console.log('/hello/world/')
+ //console.log('/hello/world/')
this.next()
})
tree.define('/hello/world/foo/', function () {
- console.log('/hello/world/foo/')
+ //console.log('/hello/world/foo/')
this.next()
})
tree.define('/hello/world/foo/bar/', function () {
- console.log('/hello/world/foo/bar')
+ //console.log('/hello/world/foo/bar')
this.next() //note, there is no next for this route, but make sure no crash
})
var match = tree.match('/hello/world/foo/bar')
-console.log('callbacks length before invocation => ' + match.cbs.length)
+assert(match.cbs.length === 3)
match.fn()
-console.log('callbacks length after invocation => ' + match.cbs.length)
+//console.log('callbacks length after invocation => ' + match.cbs.length)
+assert(match.cbs.length === 0)
console.log('\n\n')
match = tree.match('/hello/world/')
-console.log('callbacks length before invocation => ' + match.cbs.length)
+//console.log('callbacks length before invocation => ' + match.cbs.length)
+assert(match.cbs.length === 1)
match.fn()
-console.log('callbacks length after invocation => ' + match.cbs.length)
-
-
+//console.log('callbacks length after invocation => ' + match.cbs.length)
+assert(match.cbs.length === 0)
View
@@ -6,25 +6,22 @@ var maple = require('../treeRouter.js')
//the purpose of this test is to make sure similar routes don't interfere with one another. I made this because I had an early bug where routes differing by 1 letter would sometimes match
-tree.define('/trees.e/', function () {
- console.log('/trees.e')
-})
+function a(){}
+function b(){}
+function c(){}
-tree.define('/trees/', function () {
- console.log('/trees')
-})
-
-tree.define('/tree/', function () {
- console.log('/tree')
-})
+tree.define('/trees.e/', a)
+tree.define('/trees/', b)
+tree.define('/tree/', c)
var matcher
-matcher = tree.match('/tree')
-matcher.fn()
+matcher = tree.match('/trees.e')
+assert(matcher.fn === a)
matcher = tree.match('/trees')
-matcher.fn()
+assert(matcher.fn === b)
+
+matcher = tree.match('/tree')
+assert(matcher.fn === c)
-matcher = tree.match('/trees.e')
-matcher.fn()
View
@@ -158,7 +158,7 @@ RouteTree.prototype._matchRecursiveHelper = function (curNode, curPath, matcher)
}
curPath = curPath.slice(mPath.length + 1)
if (curPath.length && curPath !== '/') {
- if (mNode.callback) { matcher.cbs.push(mNode.callback) }
+ if (mNode.callback) { matcher.cbs.push(mNode.callback) } //TODO, should I add callbacks consecutively if they are the same function from ? mark routes
this._matchRecursiveHelper(mNode , curPath, matcher) //continute recursive search
} else {
if (mNode.callback) { //callback indicates this route was explicitly declared, not just a branch of another route, recursion ends

0 comments on commit 0790e4c

Please sign in to comment.