Skip to content

Commit

Permalink
stringify test for new modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 4, 2010
1 parent f0ee567 commit 6de18e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "traverse",
"version" : "0.1.1",
"version" : "0.1.2",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"author" : "James Halliday",
"license" : "MIT/X11",
Expand Down
38 changes: 38 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node
var Traverse = require('traverse');
var sys = require('sys');

exports.stringify = function (assert) {
//var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var obj = [ 5, 6, -3, [ 7, 8, -2, 11 ], { f : 10, g : -13 } ];

var s = '';
Traverse(obj).forEach(function (node) {
if (Array.isArray(node)) {
this.before(function () { s += '[' });
this.post(function (child) {
if (!child.isLast) s += ',';
});
this.after(function () { s += ']' });
}
else if (typeof node == 'object') {
this.before(function () { s += '{' });
this.pre(function (x, key) {
s += '"' + key + '"' + ':';
});
this.post(function (child) {
if (!child.isLast) s += ',';
});
this.after(function () { s += '}' });
}
else if (typeof node == 'function') {
s += 'null';
}
else {
s += node.toString();
}
});

assert.equal(s, JSON.stringify(obj));
}

0 comments on commit 6de18e5

Please sign in to comment.