From f5d429a15a77e2a7ce33c2485a2b3ee43f41d341 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 5 Jun 2011 20:41:45 -0700 Subject: [PATCH] tests for remove() and delete() --- test/circular.js | 2 +- test/mutability.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/circular.js b/test/circular.js index 76363ff..e1eef3f 100644 --- a/test/circular.js +++ b/test/circular.js @@ -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); }; diff --git a/test/mutability.js b/test/mutability.js index ce85f1e..6f70210 100644 --- a/test/mutability.js +++ b/test/mutability.js @@ -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 ] } + )); +};