Skip to content

Commit

Permalink
tests pass again with the rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Feb 18, 2011
1 parent 414c726 commit f0f76cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 206 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"name" : "traverse",
"version" : "0.3.0",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"description" : "Traverse and transform objects by visiting every node on a recursive walk",
"author" : "James Halliday",
"license" : "MIT/X11",
"main" : "./index",
"modules" : {
"web" : "./lib/web",
"hash" : "./lib/hash"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/substack/js-traverse.git"
Expand Down
186 changes: 0 additions & 186 deletions test/hash.js

This file was deleted.

32 changes: 17 additions & 15 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,41 @@ exports['json test'] = function (assert) {
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };

var scrubbed = Traverse(obj).map(function (x) {
if (x instanceof Function) {
if (typeof x === 'function') {
callbacks[id] = { id : id, f : x, path : this.path };
this.update('[Function]');
id++;
}
}).value;
});

assert.equal(
scrubbed.moo, '[Function]',
'obj.moo replaced with "[Function]"'
);

assert.equal(
scrubbed.foo[3], '[Function]',
'obj.foo[3] replaced with "[Function]"'
)
assert.equal(
JSON.stringify(scrubbed),
'{"moo":"[Function]","foo":[2,3,4,"[Function]"]}',
'Full JSON string matches'
);
assert.equal(

assert.eql(scrubbed, {
moo : '[Function]',
foo : [ 2, 3, 4, "[Function]" ]
}, 'Full JSON string matches');

assert.eql(
typeof obj.moo, 'function',
'Original obj.moo still a function'
);
assert.equal(

assert.eql(
typeof obj.foo[3], 'function',
'Original obj.foo[3] still a function'
);
assert.equal(
sys.inspect(callbacks),
"{ '54': { id: 54, f: [Function], path: [ 'moo' ] }\n"
+ ", '55': { id: 55, f: [Function], path: [ 'foo', '3' ] }\n}",
'Check the generated callbacks list'
);

assert.eql(callbacks, {
54: { id: 54, f : obj.moo, path: [ 'moo' ] },
55: { id: 55, f : obj.foo[3], path: [ 'foo', '3' ] },
}, 'Check the generated callbacks list');
};

0 comments on commit f0f76cc

Please sign in to comment.