diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-08-24 18:00:41 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-08-24 18:12:43 -0400 |
commit | 6fbc797d1ea42272ff929e295e872b0625b15d48 (patch) | |
tree | 12ebffaff1805758006627b629f7d8b20d8981d7 /test/test-async.js | |
parent | b2fded336afaef589eddb602b29a228faffcb21e (diff) | |
download | async-6fbc797d1ea42272ff929e295e872b0625b15d48.tar.gz |
Add async.transformtransform
Diffstat (limited to 'test/test-async.js')
-rwxr-xr-x | test/test-async.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js index 18894b0..a6af0e4 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2023,6 +2023,59 @@ exports['foldr alias'] = function(test){ test.done(); }; +exports['transform implictly determines memo if not provided'] = function(test){ + async.transform([1,2,3], function(memo, x, v, callback){ + memo.push(x + 1); + callback(); + }, function(err, result){ + test.same(result, [2, 3, 4]); + test.done(); + }); +}; + +exports['transform async with object memo'] = function(test){ + test.expect(2); + + async.transform([1,3,2], {}, function(memo, v, k, callback){ + setTimeout(function() { + memo[k] = v; + callback(); + }); + }, function(err, result) { + test.equals(err, null); + test.same(result, { + 0: 1, + 1: 3, + 2: 2 + }); + test.done(); + }); +}; + +exports['transform iterating object'] = function(test){ + test.expect(2); + + async.transform({a: 1, b: 3, c: 2}, function(memo, v, k, callback){ + setTimeout(function() { + memo[k] = v + 1; + callback(); + }); + }, function(err, result) { + test.equals(err, null); + test.same(result, {a: 2, b: 4, c: 3}); + test.done(); + }); +}; + +exports['transform error'] = function(test){ + async.transform([1,2,3], function(a, v, k, callback){ + callback('error'); + }, function(err){ + test.equals(err, 'error'); + test.done(); + }); +}; + exports['filter'] = function(test){ async.filter([3,1,2], filterIterator, function(results){ test.same(results, [3,1]); |