-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
double circular ref test failing, not aggressive enough
- Loading branch information
James Halliday
committed
Feb 18, 2011
1 parent
36df874
commit d190897
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var assert = require('assert'); | ||
var Traverse = require('traverse'); | ||
var util = require('util'); | ||
|
||
exports.circular = function (assert) { | ||
var obj = { x : 3 }; | ||
obj.y = obj; | ||
var foundY = false; | ||
Traverse(obj).forEach(function (x) { | ||
if (this.path.join('') == 'y') { | ||
assert.equal( | ||
util.inspect(this.circular.node), | ||
util.inspect(obj) | ||
); | ||
foundY = true; | ||
} | ||
}); | ||
assert.ok(foundY); | ||
}; | ||
|
||
exports.deepCirc = function () { | ||
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; | ||
obj.y[2] = obj; | ||
|
||
var times = 0; | ||
Traverse(obj).forEach(function (x) { | ||
if (this.circular) { | ||
assert.eql(this.circular.path, []); | ||
assert.eql(this.path, [ 'y', 2 ]); | ||
times ++; | ||
} | ||
}); | ||
|
||
assert.eql(times, 1); | ||
}; | ||
|
||
exports.doubleCirc = function () { | ||
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; | ||
obj.y[2] = obj; | ||
obj.x.push(obj.y); | ||
console.dir(obj); | ||
|
||
var circs = []; | ||
Traverse(obj).forEach(function (x) { | ||
if (this.circular) { | ||
circs.push({ circ : this.circular, self : this, node : x }); | ||
} | ||
}); | ||
|
||
assert.eql(circs[0].self.path, [ 'x', 3 ]); | ||
assert.eql(circs[0].circ.path, [ 'y' ]); | ||
|
||
assert.eql(circs[1].self.path, [ 'y', 2 ]); | ||
assert.eql(circs[1].circ.path, []); | ||
|
||
assert.eql(circs.length, 2); | ||
}; |