-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now using expresso for test suite, json test written
- Loading branch information
James Halliday
committed
Jul 28, 2010
1 parent
fc5903b
commit 7d448da
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
}; | ||
|