From 7a0969fbb39a7a66f4bd46ca8172edef15b675ea Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 18 Feb 2011 02:45:31 -0800 Subject: [PATCH] updated tests to not use sys anymore --- test/instance.js | 2 -- test/interface.js | 30 +++++++++++++++--------------- test/json.js | 2 -- test/leaves.js | 2 -- test/negative.js | 15 ++++++--------- test/obj.js | 8 ++++++-- test/stringify.js | 5 ++--- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/test/instance.js b/test/instance.js index 62c5c5b..4531ee0 100644 --- a/test/instance.js +++ b/test/instance.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node -var sys = require('sys'); var Traverse = require('traverse'); var EventEmitter = require('events').EventEmitter; diff --git a/test/interface.js b/test/interface.js index 2fe249a..f16fe53 100644 --- a/test/interface.js +++ b/test/interface.js @@ -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('/') }) @@ -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); }; diff --git a/test/json.js b/test/json.js index 9bb4875..de916e7 100644 --- a/test/json.js +++ b/test/json.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node -var sys = require('sys'); var Traverse = require('traverse'); exports['json test'] = function (assert) { diff --git a/test/leaves.js b/test/leaves.js index be9dbd5..de42407 100644 --- a/test/leaves.js +++ b/test/leaves.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node -var sys = require('sys'); var Traverse = require('traverse'); exports['leaves test'] = function (assert) { diff --git a/test/negative.js b/test/negative.js index 2e6119a..706332a 100644 --- a/test/negative.js +++ b/test/negative.js @@ -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' ); } diff --git a/test/obj.js b/test/obj.js index a1b1baf..6c3a19c 100644 --- a/test/obj.js +++ b/test/obj.js @@ -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)); diff --git a/test/stringify.js b/test/stringify.js index 80c97cb..bf36f63 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -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 = '';