Skip to content

Commit

Permalink
Add test for replacing objects with strings and vice-versa
Browse files Browse the repository at this point in the history
  • Loading branch information
grncdr committed Jun 18, 2012
1 parent ee66cd1 commit 28d5fb6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/mutability.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,28 @@ exports.deleteMapRedux = function () {
res, { a : 1, c : [ 3 ,, 5 ] }
));
};

exports.objectToString = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
var res = Traverse(obj).forEach(function (x) {
if (typeof x === 'object' && !this.isRoot) {
this.update(JSON.stringify(x));
}
});
assert.deepEqual(obj, res);
assert.deepEqual(obj, { a : 1, b : 2, c : "[3,4]" });
};

exports.stringToObject = function () {
var obj = { a : 1, b : 2, c : "[3,4]" };
var res = Traverse(obj).forEach(function (x) {
if (typeof x === 'string') {
this.update(JSON.parse(x));
}
else if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
assert.deepEqual(obj, res);
assert.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
};

0 comments on commit 28d5fb6

Please sign in to comment.