Permalink
Browse files

using tap

  • Loading branch information...
1 parent 99a0a15 commit 4f4a3e504e702bffa88ea15b687a3712b56938dd @substack committed Jun 16, 2012
Showing with 387 additions and 331 deletions.
  1. +51 −49 test/circular.js
  2. +13 −11 test/date.js
  3. +78 −58 test/equal.js
  4. +8 −10 test/error.js
  5. +11 −9 test/has.js
  6. +8 −8 test/instance.js
  7. +14 −13 test/interface.js
  8. +13 −11 test/json.js
  9. +8 −6 test/keys.js
  10. +8 −7 test/leaves.js
  11. +115 −94 test/mutability.js
  12. +9 −8 test/negative.js
  13. +7 −11 test/obj.js
  14. +6 −4 test/siblings.js
  15. +13 −10 test/stop.js
  16. +7 −7 test/stringify.js
  17. +10 −8 test/subexpr.js
  18. +8 −7 test/super_deep.js
View
100 test/circular.js
@@ -1,115 +1,117 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
var deepEqual = require('./lib/deep_equal');
var util = require('util');
-exports.circular = function () {
+test('circular', function (t) {
+ t.plan(1);
+
var obj = { x : 3 };
obj.y = obj;
- var foundY = false;
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.path.join('') == 'y') {
- assert.equal(
+ t.equal(
util.inspect(this.circular.node),
util.inspect(obj)
);
- foundY = true;
}
});
- assert.ok(foundY);
-};
+});
-exports.deepCirc = function () {
+test('deepCirc', function (t) {
+ t.plan(2);
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
var times = 0;
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.circular) {
- assert.deepEqual(this.circular.path, []);
- assert.deepEqual(this.path, [ 'y', 2 ]);
- times ++;
+ t.same(this.circular.path, []);
+ t.same(this.path, [ 'y', 2 ]);
}
});
-
- assert.deepEqual(times, 1);
-};
+});
-exports.doubleCirc = function () {
+test('doubleCirc', function (t) {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);
var circs = [];
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.circular) {
circs.push({ circ : this.circular, self : this, node : x });
}
});
- assert.deepEqual(circs[0].self.path, [ 'x', 3, 2 ]);
- assert.deepEqual(circs[0].circ.path, []);
+ t.same(circs[0].self.path, [ 'x', 3, 2 ]);
+ t.same(circs[0].circ.path, []);
- assert.deepEqual(circs[1].self.path, [ 'y', 2 ]);
- assert.deepEqual(circs[1].circ.path, []);
+ t.same(circs[1].self.path, [ 'y', 2 ]);
+ t.same(circs[1].circ.path, []);
- assert.deepEqual(circs.length, 2);
-};
+ t.same(circs.length, 2);
+ t.end();
+});
-exports.circDubForEach = function () {
+test('circDubForEach', function (t) {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.circular) this.update('...');
});
- assert.deepEqual(obj, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
-};
+ t.same(obj, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
+ t.end();
+});
-exports.circDubMap = function () {
+test('circDubMap', function (t) {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);
- var c = Traverse(obj).map(function (x) {
+ var c = traverse(obj).map(function (x) {
if (this.circular) {
this.update('...');
}
});
- assert.deepEqual(c, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
-};
+ t.same(c, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
+ t.end();
+});
-exports.circClone = function () {
+test('circClone', function (t) {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);
- var clone = Traverse.clone(obj);
- assert.ok(obj !== clone);
+ var clone = traverse.clone(obj);
+ t.ok(obj !== clone);
- assert.ok(clone.y[2] === clone);
- assert.ok(clone.y[2] !== obj);
- assert.ok(clone.x[3][2] === clone);
- assert.ok(clone.x[3][2] !== obj);
- assert.deepEqual(clone.x.slice(0,3), [1,2,3]);
- assert.deepEqual(clone.y.slice(0,2), [4,5]);
-};
+ t.ok(clone.y[2] === clone);
+ t.ok(clone.y[2] !== obj);
+ t.ok(clone.x[3][2] === clone);
+ t.ok(clone.x[3][2] !== obj);
+ t.same(clone.x.slice(0,3), [1,2,3]);
+ t.same(clone.y.slice(0,2), [4,5]);
+ t.end();
+});
-exports.circMapScrub = function () {
+test('circMapScrub', function (t) {
var obj = { a : 1, b : 2 };
obj.c = obj;
- var scrubbed = Traverse(obj).map(function (node) {
+ var scrubbed = traverse(obj).map(function (node) {
if (this.circular) this.remove();
});
- assert.deepEqual(
+ t.same(
Object.keys(scrubbed).sort(),
[ 'a', 'b' ]
);
- assert.ok(deepEqual(scrubbed, { a : 1, b : 2 }));
+ t.ok(deepEqual(scrubbed, { a : 1, b : 2 }));
- assert.equal(obj.c, obj);
-};
+ t.equal(obj.c, obj);
+ t.end();
+});
View
24 test/date.js
@@ -1,35 +1,37 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports.dateEach = function () {
+test('dateEach', function (t) {
var obj = { x : new Date, y : 10, z : 5 };
var counts = {};
- Traverse(obj).forEach(function (node) {
+ traverse(obj).forEach(function (node) {
var t = (node instanceof Date && 'Date') || typeof node;
counts[t] = (counts[t] || 0) + 1;
});
- assert.deepEqual(counts, {
+ t.same(counts, {
object : 1,
Date : 1,
number : 2,
});
-};
+ t.end();
+});
-exports.dateMap = function () {
+test('dateMap', function (t) {
var obj = { x : new Date, y : 10, z : 5 };
- var res = Traverse(obj).map(function (node) {
+ var res = traverse(obj).map(function (node) {
if (typeof node === 'number') this.update(node + 100);
});
- assert.ok(obj.x !== res.x);
- assert.deepEqual(res, {
+ t.ok(obj.x !== res.x);
+ t.same(res, {
x : obj.x,
y : 110,
z : 105,
});
-};
+ t.end();
+});
View
136 test/equal.js
@@ -1,9 +1,11 @@
-var assert = require('assert');
+var test = require('tap').test;
var traverse = require('../');
var deepEqual = require('./lib/deep_equal');
-exports.deepDates = function () {
- assert.ok(
+test('deepDates', function (t) {
+ t.plan(2);
+
+ t.ok(
deepEqual(
{ d : new Date, x : [ 1, 2, 3 ] },
{ d : new Date, x : [ 1, 2, 3 ] }
@@ -13,70 +15,72 @@ exports.deepDates = function () {
var d0 = new Date;
setTimeout(function () {
- assert.ok(
+ t.ok(
!deepEqual(
{ d : d0, x : [ 1, 2, 3 ], },
{ d : new Date, x : [ 1, 2, 3 ] }
),
'microseconds should count in date equality'
);
}, 5);
-};
+});
-exports.deepCircular = function () {
+test('deepCircular', function (t) {
var a = [1];
a.push(a); // a = [ 1, *a ]
var b = [1];
b.push(a); // b = [ 1, [ 1, *a ] ]
- assert.ok(
+ t.ok(
!deepEqual(a, b),
'circular ref mount points count towards equality'
);
var c = [1];
c.push(c); // c = [ 1, *c ]
- assert.ok(
+ t.ok(
deepEqual(a, c),
'circular refs are structurally the same here'
);
var d = [1];
d.push(a); // c = [ 1, [ 1, *d ] ]
- assert.ok(
+ t.ok(
deepEqual(b, d),
'non-root circular ref structural comparison'
);
-};
+
+ t.end();
+});
-exports.deepInstances = function () {
- assert.ok(
+test('deepInstances', function (t) {
+ t.ok(
!deepEqual([ new Boolean(false) ], [ false ]),
'boolean instances are not real booleans'
);
- assert.ok(
+ t.ok(
!deepEqual([ new String('x') ], [ 'x' ]),
'string instances are not real strings'
);
- assert.ok(
+ t.ok(
!deepEqual([ new Number(4) ], [ 4 ]),
'number instances are not real numbers'
);
- assert.ok(
+ t.ok(
deepEqual([ new RegExp('x') ], [ /x/ ]),
'regexp instances are real regexps'
);
- assert.ok(
+ t.ok(
!deepEqual([ new RegExp(/./) ], [ /../ ]),
'these regexps aren\'t the same'
);
- assert.ok(
+ t.ok(
!deepEqual(
[ function (x) { return x * 2 } ],
[ function (x) { return x * 2 } ]
@@ -85,56 +89,61 @@ exports.deepInstances = function () {
);
var f = function (x) { return x * 2 };
- assert.ok(
+ t.ok(
deepEqual([ f ], [ f ]),
'these functions are actually equal'
);
-};
+
+ t.end();
+});
-exports.deepEqual = function () {
- assert.ok(
+test('deepEqual', function (t) {
+ t.ok(
!deepEqual([ 1, 2, 3 ], { 0 : 1, 1 : 2, 2 : 3 }),
'arrays are not objects'
);
-};
+ t.end();
+});
-exports.falsy = function () {
- assert.ok(
+test('falsy', function (t) {
+ t.ok(
!deepEqual([ undefined ], [ null ]),
'null is not undefined!'
);
- assert.ok(
+ t.ok(
!deepEqual([ null ], [ undefined ]),
'undefined is not null!'
);
- assert.ok(
+ t.ok(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
'undefined is not null, however deeply!'
);
- assert.ok(
+ t.ok(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
'null is not undefined, however deeply!'
);
- assert.ok(
+ t.ok(
!deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] }
),
'null is not undefined, however deeply!'
);
-};
+
+ t.end();
+});
-exports.deletedArrayEqual = function () {
+test('deletedArrayEqual', function (t) {
var xs = [ 1, 2, 3, 4 ];
delete xs[2];
@@ -143,78 +152,89 @@ exports.deletedArrayEqual = function () {
ys[1] = 2;
ys[3] = 4;
- assert.ok(
+ t.ok(
deepEqual(xs, ys),
'arrays with deleted elements are only equal to'
+ ' arrays with similarly deleted elements'
);
- assert.ok(
+ t.ok(
!deepEqual(xs, [ 1, 2, undefined, 4 ]),
'deleted array elements cannot be undefined'
);
- assert.ok(
+ t.ok(
!deepEqual(xs, [ 1, 2, null, 4 ]),
'deleted array elements cannot be null'
);
-};
+
+ t.end();
+});
-exports.deletedObjectEqual = function () {
+test('deletedObjectEqual', function (t) {
var obj = { a : 1, b : 2, c : 3 };
delete obj.c;
- assert.ok(
+ t.ok(
deepEqual(obj, { a : 1, b : 2 }),
'deleted object elements should not show up'
);
- assert.ok(
+ t.ok(
!deepEqual(obj, { a : 1, b : 2, c : undefined }),
'deleted object elements are not undefined'
);
- assert.ok(
+ t.ok(
!deepEqual(obj, { a : 1, b : 2, c : null }),
'deleted object elements are not null'
);
-};
+
+ t.end();
+});
-exports.emptyKeyEqual = function () {
- assert.ok(!deepEqual(
+test('emptyKeyEqual', function (t) {
+ t.ok(!deepEqual(
{ a : 1 }, { a : 1, '' : 55 }
));
-};
+
+ t.end();
+});
-exports.deepArguments = function () {
- assert.ok(
+test('deepArguments', function (t) {
+ t.ok(
!deepEqual(
[ 4, 5, 6 ],
(function () { return arguments })(4, 5, 6)
),
'arguments are not arrays'
);
- assert.ok(
+ t.ok(
deepEqual(
(function () { return arguments })(4, 5, 6),
(function () { return arguments })(4, 5, 6)
),
'arguments should equal'
);
-};
+
+ t.end();
+});
-exports.deepUn = function () {
- assert.ok(!deepEqual({ a : 1, b : 2 }, undefined));
- assert.ok(!deepEqual({ a : 1, b : 2 }, {}));
- assert.ok(!deepEqual(undefined, { a : 1, b : 2 }));
- assert.ok(!deepEqual({}, { a : 1, b : 2 }));
- assert.ok(deepEqual(undefined, undefined));
- assert.ok(deepEqual(null, null));
- assert.ok(!deepEqual(undefined, null));
-};
+test('deepUn', function (t) {
+ t.ok(!deepEqual({ a : 1, b : 2 }, undefined));
+ t.ok(!deepEqual({ a : 1, b : 2 }, {}));
+ t.ok(!deepEqual(undefined, { a : 1, b : 2 }));
+ t.ok(!deepEqual({}, { a : 1, b : 2 }));
+ t.ok(deepEqual(undefined, undefined));
+ t.ok(deepEqual(null, null));
+ t.ok(!deepEqual(undefined, null));
+
+ t.end();
+});
-exports.deepLevels = function () {
+test('deepLevels', function (t) {
var xs = [ 1, 2, [ 3, 4, [ 5, 6 ] ] ];
- assert.ok(!deepEqual(xs, []));
-};
+ t.ok(!deepEqual(xs, []));
+ t.end();
+});
View
18 test/error.js
@@ -1,13 +1,11 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['traverse an Error'] = function () {
+test('traverse an Error', function (t) {
var obj = new Error("test");
-
- var results = Traverse(obj).map(function (node) { });
-
- assert.deepEqual(results, {
- message: 'test'
- });
-};
+ var results = traverse(obj).map(function (node) {});
+ t.same(results, { message: 'test' });
+
+ t.end();
+});
View
20 test/has.js
@@ -1,13 +1,15 @@
-var assert = require('assert');
+var test = require('tap').test;
var traverse = require('../');
-exports.has = function () {
+test('has', function (t) {
var obj = { a : 2, b : [ 4, 5, { c : 6 } ] };
- assert.equal(traverse(obj).has([ 'b', 2, 'c' ]), true)
- assert.equal(traverse(obj).has([ 'b', 2, 'c', 0 ]), false)
- assert.equal(traverse(obj).has([ 'b', 2, 'd' ]), false)
- assert.equal(traverse(obj).has([]), true)
- assert.equal(traverse(obj).has([ 'a' ]), true)
- assert.equal(traverse(obj).has([ 'a', 2 ]), false)
-};
+ t.equal(traverse(obj).has([ 'b', 2, 'c' ]), true)
+ t.equal(traverse(obj).has([ 'b', 2, 'c', 0 ]), false)
+ t.equal(traverse(obj).has([ 'b', 2, 'd' ]), false)
+ t.equal(traverse(obj).has([]), true)
+ t.equal(traverse(obj).has([ 'a' ]), true)
+ t.equal(traverse(obj).has([ 'a', 2 ]), false)
+
+ t.end();
+});
View
16 test/instance.js
@@ -1,17 +1,17 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
var EventEmitter = require('events').EventEmitter;
-exports['check instanceof on node elems'] = function () {
-
+test('check instanceof on node elems', function (t) {
var counts = { emitter : 0 };
- Traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }])
+ traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }])
.forEach(function (node) {
if (node instanceof EventEmitter) counts.emitter ++;
})
;
- assert.equal(counts.emitter, 2);
-};
-
+ t.equal(counts.emitter, 2);
+
+ t.end();
+});
View
27 test/interface.js
@@ -1,11 +1,11 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['interface map'] = function () {
+test('interface map', function (t) {
var obj = { a : [ 5,6,7 ], b : { c : [8] } };
- assert.deepEqual(
- Traverse.paths(obj)
+ t.same(
+ traverse.paths(obj)
.sort()
.map(function (path) { return path.join('/') })
.slice(1)
@@ -14,17 +14,17 @@ exports['interface map'] = function () {
'a a/0 a/1 a/2 b b/c b/c/0'
);
- assert.deepEqual(
- Traverse.nodes(obj),
+ t.same(
+ traverse.nodes(obj),
[
{ a: [ 5, 6, 7 ], b: { c: [ 8 ] } },
[ 5, 6, 7 ], 5, 6, 7,
{ c: [ 8 ] }, [ 8 ], 8
]
);
- assert.deepEqual(
- Traverse.map(obj, function (node) {
+ t.same(
+ traverse.map(obj, function (node) {
if (typeof node == 'number') {
return node + 1000;
}
@@ -36,7 +36,8 @@ exports['interface map'] = function () {
);
var nodes = 0;
- Traverse.forEach(obj, function (node) { nodes ++ });
- assert.deepEqual(nodes, 8);
-};
-
+ traverse.forEach(obj, function (node) { nodes ++ });
+ t.same(nodes, 8);
+
+ t.end();
+});
View
24 test/json.js
@@ -1,47 +1,49 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['json test'] = function () {
+test('json test', function (t) {
var id = 54;
var callbacks = {};
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };
- var scrubbed = Traverse(obj).map(function (x) {
+ var scrubbed = traverse(obj).map(function (x) {
if (typeof x === 'function') {
callbacks[id] = { id : id, f : x, path : this.path };
this.update('[Function]');
id++;
}
});
- assert.equal(
+ t.equal(
scrubbed.moo, '[Function]',
'obj.moo replaced with "[Function]"'
);
- assert.equal(
+ t.equal(
scrubbed.foo[3], '[Function]',
'obj.foo[3] replaced with "[Function]"'
);
- assert.deepEqual(scrubbed, {
+ t.same(scrubbed, {
moo : '[Function]',
foo : [ 2, 3, 4, "[Function]" ]
}, 'Full JSON string matches');
- assert.deepEqual(
+ t.same(
typeof obj.moo, 'function',
'Original obj.moo still a function'
);
- assert.deepEqual(
+ t.same(
typeof obj.foo[3], 'function',
'Original obj.foo[3] still a function'
);
- assert.deepEqual(callbacks, {
+ t.same(callbacks, {
54: { id: 54, f : obj.moo, path: [ 'moo' ] },
55: { id: 55, f : obj.foo[3], path: [ 'foo', '3' ] },
}, 'Check the generated callbacks list');
-};
+
+ t.end();
+});
View
14 test/keys.js
@@ -1,9 +1,9 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['sort test'] = function () {
+test('sort test', function (t) {
var acc = [];
- Traverse({
+ traverse({
a: 30,
b: 22,
id: 9
@@ -21,9 +21,11 @@ exports['sort test'] = function () {
if (this.isLeaf) acc.push(node);
});
- assert.equal(
+ t.equal(
acc.join(' '),
'9 30 22',
'Traversal in a custom order'
);
-};
+
+ t.end();
+});
View
15 test/leaves.js
@@ -1,9 +1,9 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['leaves test'] = function () {
+test('leaves test', function (t) {
var acc = [];
- Traverse({
+ traverse({
a : [1,2,3],
b : 4,
c : [5,6],
@@ -12,10 +12,11 @@ exports['leaves test'] = function () {
if (this.isLeaf) acc.push(x);
});
- assert.equal(
+ t.equal(
acc.join(' '),
'1 2 3 4 5 6 7 8 9',
'Traversal in the right(?) order'
);
-};
-
+
+ t.end();
+});
View
209 test/mutability.js
@@ -1,252 +1,273 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
var deepEqual = require('./lib/deep_equal');
-exports.mutate = function () {
+test('mutate', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).forEach(function (x) {
+ var res = traverse(obj).forEach(function (x) {
if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
- assert.deepEqual(obj, res);
- assert.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
-};
+ t.same(obj, res);
+ t.same(obj, { a : 1, b : 20, c : [ 3, 40 ] });
+ t.end();
+});
-exports.mutateT = function () {
+test('mutateT', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse.forEach(obj, function (x) {
+ var res = traverse.forEach(obj, function (x) {
if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
- assert.deepEqual(obj, res);
- assert.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
-};
+ t.same(obj, res);
+ t.same(obj, { a : 1, b : 20, c : [ 3, 40 ] });
+ t.end();
+});
-exports.map = function () {
+test('map', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).map(function (x) {
+ var res = traverse(obj).map(function (x) {
if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
- assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
- assert.deepEqual(res, { a : 1, b : 20, c : [ 3, 40 ] });
-};
+ t.same(obj, { a : 1, b : 2, c : [ 3, 4 ] });
+ t.same(res, { a : 1, b : 20, c : [ 3, 40 ] });
+ t.end();
+});
-exports.mapT = function () {
+test('mapT', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse.map(obj, function (x) {
+ var res = traverse.map(obj, function (x) {
if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
- assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
- assert.deepEqual(res, { a : 1, b : 20, c : [ 3, 40 ] });
-};
+ t.same(obj, { a : 1, b : 2, c : [ 3, 4 ] });
+ t.same(res, { a : 1, b : 20, c : [ 3, 40 ] });
+ t.end();
+});
-exports.clone = function () {
+test('clone', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).clone();
- assert.deepEqual(obj, res);
- assert.ok(obj !== res);
+ var res = traverse(obj).clone();
+ t.same(obj, res);
+ t.ok(obj !== res);
obj.a ++;
- assert.deepEqual(res.a, 1);
+ t.same(res.a, 1);
obj.c.push(5);
- assert.deepEqual(res.c, [ 3, 4 ]);
-};
+ t.same(res.c, [ 3, 4 ]);
+ t.end();
+});
-exports.cloneT = function () {
+test('cloneT', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse.clone(obj);
- assert.deepEqual(obj, res);
- assert.ok(obj !== res);
+ var res = traverse.clone(obj);
+ t.same(obj, res);
+ t.ok(obj !== res);
obj.a ++;
- assert.deepEqual(res.a, 1);
+ t.same(res.a, 1);
obj.c.push(5);
- assert.deepEqual(res.c, [ 3, 4 ]);
-};
+ t.same(res.c, [ 3, 4 ]);
+ t.end();
+});
-exports.reduce = function () {
+test('reduce', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).reduce(function (acc, x) {
+ var res = traverse(obj).reduce(function (acc, x) {
if (this.isLeaf) acc.push(x);
return acc;
}, []);
- assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
- assert.deepEqual(res, [ 1, 2, 3, 4 ]);
-};
+ t.same(obj, { a : 1, b : 2, c : [ 3, 4 ] });
+ t.same(res, [ 1, 2, 3, 4 ]);
+ t.end();
+});
-exports.reduceInit = function () {
+test('reduceInit', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).reduce(function (acc, x) {
+ var res = traverse(obj).reduce(function (acc, x) {
if (this.isRoot) assert.fail('got root');
return acc;
});
- assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
- assert.deepEqual(res, obj);
-};
+ t.same(obj, { a : 1, b : 2, c : [ 3, 4 ] });
+ t.same(res, obj);
+ t.end();
+});
-exports.remove = function () {
+test('remove', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.remove();
});
- assert.deepEqual(obj, { a : 1, c : [ 3 ] });
-};
+ t.same(obj, { a : 1, c : [ 3 ] });
+ t.end();
+});
exports.removeNoStop = function() {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };
var keys = [];
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
keys.push(this.key)
if (this.key == 'c') this.remove();
});
- assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f'])
+ t.same(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f'])
+ t.end();
}
exports.removeStop = function() {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };
var keys = [];
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
keys.push(this.key)
if (this.key == 'c') this.remove(true);
});
- assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'f'])
+ t.same(keys, [undefined, 'a', 'b', 'c', 'f'])
+ t.end();
}
-exports.removeMap = function () {
+test('removeMap', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).map(function (x) {
+ var res = traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.remove();
});
- assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
- assert.deepEqual(res, { a : 1, c : [ 3 ] });
-};
+ t.same(obj, { a : 1, b : 2, c : [ 3, 4 ] });
+ t.same(res, { a : 1, c : [ 3 ] });
+ t.end();
+});
-exports.delete = function () {
+test('delete', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
obj, { a : 1, c : [ 3, undefined ] }
));
- assert.ok(deepEqual(
+ t.ok(deepEqual(
obj, { a : 1, c : [ 3 ] }
));
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
obj, { a : 1, c : [ 3, null ] }
));
-};
+ t.end();
+});
-exports.deleteNoStop = function() {
+test('deleteNoStop', function (t) {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
var keys = [];
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
keys.push(this.key)
if (this.key == 'c') this.delete();
});
- assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e'])
-}
+ t.same(keys, [undefined, 'a', 'b', 'c', 'd', 'e'])
+ t.end();
+});
-exports.deleteStop = function() {
+test('deleteStop', function (t) {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
var keys = [];
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
keys.push(this.key)
if (this.key == 'c') this.delete(true);
});
- assert.deepEqual(keys, [undefined, 'a', 'b', 'c'])
-}
+ t.same(keys, [undefined, 'a', 'b', 'c'])
+ t.end();
+});
-exports.deleteRedux = function () {
+test('deleteRedux', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
- Traverse(obj).forEach(function (x) {
+ traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
obj, { a : 1, c : [ 3, undefined, 5 ] }
));
- assert.ok(deepEqual(
+ t.ok(deepEqual(
obj, { a : 1, c : [ 3 ,, 5 ] }
));
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
obj, { a : 1, c : [ 3, null, 5 ] }
));
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
obj, { a : 1, c : [ 3, 5 ] }
));
-};
+
+ t.end();
+});
-exports.deleteMap = function () {
+test('deleteMap', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
- var res = Traverse(obj).map(function (x) {
+ var res = traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
- assert.ok(deepEqual(
+ t.ok(deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4 ] }
));
var xs = [ 3, 4 ];
delete xs[1];
- assert.ok(deepEqual(
+ t.ok(deepEqual(
res, { a : 1, c : xs }
));
- assert.ok(deepEqual(
+ t.ok(deepEqual(
res, { a : 1, c : [ 3, ] }
));
- assert.ok(deepEqual(
+ t.ok(deepEqual(
res, { a : 1, c : [ 3 ] }
));
-};
+
+ t.end();
+});
-exports.deleteMapRedux = function () {
+test('deleteMapRedux', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
- var res = Traverse(obj).map(function (x) {
+ var res = traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
- assert.ok(deepEqual(
+ t.ok(deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4, 5 ] }
));
var xs = [ 3, 4, 5 ];
delete xs[1];
- assert.ok(deepEqual(
+ t.ok(deepEqual(
res, { a : 1, c : xs }
));
- assert.ok(!deepEqual(
+ t.ok(!deepEqual(
res, { a : 1, c : [ 3, 5 ] }
));
- assert.ok(deepEqual(
+ t.ok(deepEqual(
res, { a : 1, c : [ 3 ,, 5 ] }
));
-};
+
+ t.end();
+});
View
17 test/negative.js
@@ -1,20 +1,21 @@
-var Traverse = require('../');
-var assert = require('assert');
+var traverse = require('../');
+var test = require('tap').test;
-exports['negative update test'] = function () {
+test('negative update test', function (t) {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
- var fixed = Traverse.map(obj, function (x) {
+ var fixed = traverse.map(obj, function (x) {
if (x < 0) this.update(x + 128);
});
- assert.deepEqual(fixed,
+ t.same(fixed,
[ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ],
'Negative values += 128'
);
- assert.deepEqual(obj,
+ t.same(obj,
[ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ],
'Original references not modified'
);
-}
-
+
+ t.end();
+});
View
18 test/obj.js
@@ -1,15 +1,11 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports['traverse an object with nested functions'] = function () {
- var to = setTimeout(function () {
- assert.fail('never ran');
- }, 1000);
+test('traverse an object with nested functions', function (t) {
+ t.plan(1);
function Cons (x) {
- clearTimeout(to);
- assert.equal(x, 10);
+ t.equal(x, 10)
};
- Traverse(new Cons(10));
-};
-
+ traverse(new Cons(10));
+});
View
10 test/siblings.js
@@ -1,7 +1,7 @@
-var assert = require('assert');
+var test = require('tap').test;
var traverse = require('../');
-exports.siblings = function () {
+test('siblings', function (t) {
var obj = { a : 1, b : 2, c : [ 4, 5, 6 ] };
var res = traverse(obj).reduce(function (acc, x) {
@@ -23,7 +23,7 @@ exports.siblings = function () {
return acc;
}, {});
- assert.deepEqual(res, {
+ t.same(res, {
'/' : { siblings : [], key : undefined, index : -1 },
'/a' : { siblings : [ 'a', 'b', 'c' ], key : 'a', index : 0 },
'/b' : { siblings : [ 'a', 'b', 'c' ], key : 'b', index : 1 },
@@ -32,4 +32,6 @@ exports.siblings = function () {
'/c/1' : { siblings : [ '0', '1', '2' ], key : '1', index : 1 },
'/c/2' : { siblings : [ '0', '1', '2' ], key : '2', index : 2 }
});
-};
+
+ t.end();
+});
View
23 test/stop.js
@@ -1,7 +1,7 @@
-var assert = require('assert');
+var test = require('tap').test;
var traverse = require('../');
-exports.stop = function () {
+test('stop', function (t) {
var visits = 0;
traverse('abcdefghij'.split('')).forEach(function (node) {
if (typeof node === 'string') {
@@ -10,21 +10,23 @@ exports.stop = function () {
}
});
- assert.equal(visits, 5);
-};
+ t.equal(visits, 5);
+ t.end();
+});
-exports.stopMap = function () {
+test('stopMap', function (t) {
var s = traverse('abcdefghij'.split('')).map(function (node) {
if (typeof node === 'string') {
if (node === 'e') this.stop()
return node.toUpperCase();
}
}).join('');
- assert.equal(s, 'ABCDEfghij');
-};
+ t.equal(s, 'ABCDEfghij');
+ t.end();
+});
-exports.stopReduce = function () {
+test('stopReduce', function (t) {
var obj = {
a : [ 4, 5 ],
b : [ 6, [ 7, 8, 9 ] ]
@@ -37,5 +39,6 @@ exports.stopReduce = function () {
return acc;
}, []);
- assert.deepEqual(xs, [ 4, 5, 6 ]);
-};
+ t.same(xs, [ 4, 5, 6 ]);
+ t.end();
+});
View
14 test/stringify.js
@@ -1,11 +1,11 @@
-var assert = require('assert');
-var Traverse = require('../');
+var test = require('tap').test;
+var traverse = require('../');
-exports.stringify = function () {
+test('stringify', function (t) {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var s = '';
- Traverse(obj).forEach(function (node) {
+ traverse(obj).forEach(function (node) {
if (Array.isArray(node)) {
this.before(function () { s += '[' });
this.post(function (child) {
@@ -31,6 +31,6 @@ exports.stringify = function () {
}
});
- assert.equal(s, JSON.stringify(obj));
-}
-
+ t.equal(s, JSON.stringify(obj));
+ t.end();
+});
View
18 test/subexpr.js
@@ -1,23 +1,24 @@
var traverse = require('../');
-var assert = require('assert');
+var test = require('tap').test;
-exports.subexpr = function () {
+test('subexpr', function (t) {
var obj = [ 'a', 4, 'b', 5, 'c', 6 ];
var r = traverse(obj).map(function (x) {
if (typeof x === 'number') {
this.update([ x - 0.1, x, x + 0.1 ], true);
}
});
- assert.deepEqual(obj, [ 'a', 4, 'b', 5, 'c', 6 ]);
- assert.deepEqual(r, [
+ t.same(obj, [ 'a', 4, 'b', 5, 'c', 6 ]);
+ t.same(r, [
'a', [ 3.9, 4, 4.1 ],
'b', [ 4.9, 5, 5.1 ],
'c', [ 5.9, 6, 6.1 ],
]);
-};
+ t.end();
+});
-exports.block = function () {
+test('block', function (t) {
var obj = [ [ 1 ], [ 2 ], [ 3 ] ];
var r = traverse(obj).map(function (x) {
if (Array.isArray(x) && !this.isRoot) {
@@ -26,9 +27,10 @@ exports.block = function () {
}
});
- assert.deepEqual(r, [
+ t.same(r, [
[ [ [ [ [ 5 ] ] ] ] ],
[ [ [ [ 5 ] ] ] ],
[ [ [ 5 ] ] ],
]);
-};
+ t.end();
+});
View
15 test/super_deep.js
@@ -1,23 +1,24 @@
-var assert = require('assert');
+var test = require('tap').test;
var traverse = require('../');
var deepEqual = require('./lib/deep_equal');
-exports.super_deep = function () {
+test('super_deep', function (t) {
var util = require('util');
var a0 = make();
var a1 = make();
- assert.ok(deepEqual(a0, a1));
+ t.ok(deepEqual(a0, a1));
a0.c.d.moo = true;
- assert.ok(!deepEqual(a0, a1));
+ t.ok(!deepEqual(a0, a1));
a1.c.d.moo = true;
- assert.ok(deepEqual(a0, a1));
+ t.ok(deepEqual(a0, a1));
// TODO: this one
//a0.c.a = a1;
- //assert.ok(!deepEqual(a0, a1));
-};
+ //t.ok(!deepEqual(a0, a1));
+ t.end();
+});
function make () {
var a = { self : 'a' };

0 comments on commit 4f4a3e5

Please sign in to comment.