Skip to content

Commit

Permalink
now using expresso for test suite, json test written
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 28, 2010
1 parent fc5903b commit 7d448da
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse');

exports['json test'] = function (assert) {
var id = 54;
var callbacks = {};
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };

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

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(
typeof obj.moo, 'function',
'Original obj.moo still a function'
);
assert.equal(
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'
);
};

0 comments on commit 7d448da

Please sign in to comment.