Skip to content

Commit

Permalink
hash test for map
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 27, 2010
1 parent 586124c commit 393444a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node
var sys = require('sys');
var Hash = require('traverse/hash');

exports['flat traversal with the hash lib'] = function (assert) {
var ref1 = { a : 1, b : 2 };
var hash1 = Hash(ref1).map(function (v) { return v + 1 }).end;
assert.equal(ref1.a, 1);
assert.equal(ref1.b, 2);
assert.equal(hash1.a, 2);
assert.equal(hash1.b, 3);

var ref2 = { foo : [1,2], bar : [4,5] };
var hash2 = Hash.map(ref2, function (v) { v.unshift(v[0] - 1); return v });
assert.equal(ref2.foo.join(' '), '1 2');
assert.equal(ref2.bar.join(' '), '4 5');
assert.equal(hash2.foo.join(' '), '0 1 2');
assert.equal(hash2.bar.join(' '), '3 4 5');
};

0 comments on commit 393444a

Please sign in to comment.