Skip to content

Commit

Permalink
tests for remove() and delete()
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jun 6, 2011
1 parent 7010fe2 commit f5d429a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/circular.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ exports.circMapScrub = function () {
Object.keys(scrubbed).sort(),
[ 'a', 'b' ]
);
Traverse.deepEqual(scrubbed, { a : 1, b : 2 });
assert.ok(Traverse.deepEqual(scrubbed, { a : 1, b : 2 }));

assert.equal(obj.c, obj);
};
28 changes: 28 additions & 0 deletions test/mutability.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,31 @@ exports.removeMap = function () {
assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
assert.deepEqual(res, { a : 1, c : [ 3 ] });
};

exports.delete = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
Traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(Traverse.deepEqual(
obj,
{ a : 1, c : [ 3, undefined ] }
));
};

exports.deleteMap = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
var res = Traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});

assert.ok(Traverse.deepEqual(
res,
{ a : 1, b : 2, c : [ 3, 4 ] }
));
assert.ok(Traverse.deepEqual(
res,
{ a : 1, c : [ 3, undefined ] }
));
};

0 comments on commit f5d429a

Please sign in to comment.