Skip to content

Commit

Permalink
more tests, all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 27, 2010
1 parent 0bd932b commit 2d9f7a2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var sys = require('sys');
var Hash = require('traverse/hash');

exports['flat traversal with the hash lib'] = function (assert) {
exports['hash traversal'] = function (assert) {
var ref1 = { a : 1, b : 2 };
var hash1 = Hash(ref1).map(function (v) { return v + 1 }).end;
assert.equal(ref1.a, 1);
Expand All @@ -16,5 +16,19 @@ exports['flat traversal with the hash lib'] = function (assert) {
assert.equal(ref2.bar.join(' '), '4 5');
assert.equal(hash2.foo.join(' '), '0 1 2');
assert.equal(hash2.bar.join(' '), '3 4 5');

var sum1 = Hash(ref2).reduce(function (acc, v) {
return acc + v.length
}, 0);
assert.equal(sum1, 4);

var sum2 = Hash.reduce(ref2, function (acc, v) {
return acc + v.length
}, 0);
assert.equal(sum2, 4);

var ref3 = { a : 5, b : 2, c : 7, 1337 : 'leet' };
var f1 = Hash.filter(ref3, function (v, k) { return v > 5 || k > 5 });
assert.equal(Object.keys(f1).sort().join(' '), '1337 c');
};

0 comments on commit 2d9f7a2

Please sign in to comment.