Skip to content

Commit

Permalink
updated tests to not use sys anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Feb 18, 2011
1 parent f0f76cc commit 7a0969f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
2 changes: 0 additions & 2 deletions test/instance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse');
var EventEmitter = require('events').EventEmitter;

Expand Down
30 changes: 15 additions & 15 deletions test/interface.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node
var sys = require('sys');
var assert = require('assert');
var Traverse = require('traverse');

exports['interface map'] = function (assert) {
exports['interface map'] = function () {
var obj = { a : [ 5,6,7 ], b : { c : [8] } };

assert.equal(
assert.eql(
Traverse.paths(obj)
.sort()
.map(function (path) { return path.join('/') })
Expand All @@ -15,28 +14,29 @@ exports['interface map'] = function (assert) {
'a a/0 a/1 a/2 b b/c b/c/0'
);

assert.equal(
Traverse.nodes(obj)
.map(function (node) { return sys.inspect(node) })
.join(' ')
,
'{ a: [ 5, 6, 7 ], b: { c: [ 8 ] } } [ 5, 6, 7 ] 5 6 7 { c: [ 8 ] } [ 8 ] 8'
assert.eql(
Traverse.nodes(obj),
[
{ a: [ 5, 6, 7 ], b: { c: [ 8 ] } },
[ 5, 6, 7 ], 5, 6, 7,
{ c: [ 8 ] }, [ 8 ], 8
]
);

assert.equal(
sys.inspect(Traverse.map(obj, function (node) {
assert.eql(
Traverse.map(obj, function (node) {
if (typeof node == 'number') {
return node + 1000;
}
else if (Array.isArray(node)) {
return node.join(' ');
}
})),
"{ a: '5 6 7', b: { c: '8' } }"
}),
{ a: '5 6 7', b: { c: '8' } }
);

var nodes = 0;
Traverse.forEach(obj, function (node) { nodes ++ });
assert.equal(nodes, 8);
assert.eql(nodes, 8);
};

2 changes: 0 additions & 2 deletions test/json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse');

exports['json test'] = function (assert) {
Expand Down
2 changes: 0 additions & 2 deletions test/leaves.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse');

exports['leaves test'] = function (assert) {
Expand Down
15 changes: 6 additions & 9 deletions test/negative.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#!/usr/bin/env node
var Traverse = require('traverse');
var sys = require('sys');
var assert = require('assert');

exports['negative update test'] = function (assert) {
exports['negative update test'] = function () {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var fixed = Traverse.map(obj, function (x) {
if (x < 0) this.update(x + 128);
});

assert.equal(
sys.inspect(fixed),
'[ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ]',
assert.eql(fixed,
[ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ],
'Negative values += 128'
);

assert.equal(
sys.inspect(obj),
'[ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ]',
assert.eql(obj,
[ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ],
'Original references not modified'
);
}
Expand Down
8 changes: 6 additions & 2 deletions test/obj.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env node
var sys = require('sys');
var assert = require('assert');
var Traverse = require('traverse');

exports['traverse an object with nested functions'] = function (assert) {
var to = setTimeout(function () {
assert.fail('never ran');
}, 1000);

function Cons (x) {
clearTimeout(to);
assert.equal(x, 10);
};
Traverse(new Cons(10));
Expand Down
5 changes: 2 additions & 3 deletions test/stringify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
var assert = require('assert');
var Traverse = require('traverse');
var sys = require('sys');

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

var s = '';
Expand Down

0 comments on commit 7a0969f

Please sign in to comment.