-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
Aug 27, 2010
1 parent
586124c
commit 393444a
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; | ||
|