diff options
author | Alexander Early <alexander.early@gmail.com> | 2016-02-27 14:57:13 -0800 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2016-02-27 14:58:00 -0800 |
commit | 9333133af2b1b7cc01c0c20500a404408517fdae (patch) | |
tree | 670c4fc2d7ad68212a7e96ff5b3a82e51dd9a45f /test | |
parent | 7ee15953293b5ca8e173ab281742c3dfdcc5df50 (diff) | |
download | async-9333133af2b1b7cc01c0c20500a404408517fdae.tar.gz |
moved tests to separate files
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-async.js | 435 |
1 files changed, 0 insertions, 435 deletions
diff --git a/test/test-async.js b/test/test-async.js index 20bf43f..c8a1c7c 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -37,19 +37,6 @@ function mapIterator(call_order, x, callback) { }, x*25); } -function filterIterator(x, callback) { - setTimeout(function(){ - callback(null, x % 2); - }, x*25); -} - -function detectIterator(call_order, x, callback) { - setTimeout(function(){ - call_order.push(x); - callback(null, x == 2); - }, x*25); -} - function eachNoCallbackIterator(test, x, callback) { test.equal(x, 1); callback(); @@ -2160,428 +2147,6 @@ exports['transform error'] = function(test){ }); }; -exports['filter'] = function(test){ - async.filter([3,1,2], filterIterator, function(err, results){ - test.equals(err, null); - test.same(results, [3,1]); - test.done(); - }); -}; - -exports['filter original untouched'] = function(test){ - var a = [3,1,2]; - async.filter(a, function(x, callback){ - callback(null, x % 2); - }, function(err, results){ - test.equals(err, null); - test.same(results, [3,1]); - test.same(a, [3,1,2]); - test.done(); - }); -}; - -exports['filter error'] = function(test){ - async.filter([3,1,2], function(x, callback){ - callback('error'); - } , function(err, results){ - test.equals(err, 'error'); - test.equals(results, null); - test.done(); - }); -}; - -exports['filterSeries'] = function(test){ - async.filterSeries([3,1,2], filterIterator, function(err, results){ - test.equals(err, null); - test.same(results, [3,1]); - test.done(); - }); -}; - -exports['select alias'] = function(test){ - test.equals(async.select, async.filter); - test.done(); -}; - -exports['selectSeries alias'] = function(test){ - test.equals(async.selectSeries, async.filterSeries); - test.done(); -}; - -exports['reject'] = function(test){ - test.expect(2); - async.reject([3,1,2], filterIterator, function(err, results){ - test.equals(err, null); - test.same(results, [2]); - test.done(); - }); -}; - -exports['reject original untouched'] = function(test){ - test.expect(3); - var a = [3,1,2]; - async.reject(a, function(x, callback){ - callback(null, x % 2); - }, function(err, results){ - test.equals(err, null); - test.same(results, [2]); - test.same(a, [3,1,2]); - test.done(); - }); -}; - -exports['reject error'] = function(test){ - test.expect(2); - async.reject([3,1,2], function(x, callback){ - callback('error'); - } , function(err, results){ - test.equals(err, 'error'); - test.equals(results, null); - test.done(); - }); -}; - -exports['rejectSeries'] = function(test){ - test.expect(2); - async.rejectSeries([3,1,2], filterIterator, function(err, results){ - test.equals(err, null); - test.same(results, [2]); - test.done(); - }); -}; - -function testLimit(test, arr, limitFunc, limit, iter, done) { - var args = []; - - limitFunc(arr, limit, function(x) { - args.push(x); - iter.apply(this, arguments); - }, function() { - test.same(args, arr); - if (done) done.apply(this, arguments); - else test.done(); - }); -} - -exports['rejectLimit'] = function(test) { - test.expect(3); - testLimit(test, [5, 4, 3, 2, 1], async.rejectLimit, 2, function(v, next) { - next(null, v % 2); - }, function(err, result){ - test.equals(err, null); - test.same(result, [4, 2]); - test.done(); - }); -}; - -exports['filterLimit'] = function(test) { - test.expect(3); - testLimit(test, [5, 4, 3, 2, 1], async.filterLimit, 2, function(v, next) { - next(null, v % 2); - }, function(err, result){ - test.equals(err, null); - test.same(result, [5, 3, 1]); - test.done(); - }); -}; - -exports['some true'] = function(test){ - test.expect(2); - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback(null, x === 1);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, true); - test.done(); - }); -}; - -exports['some false'] = function(test){ - test.expect(2); - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback(null, x === 10);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, false); - test.done(); - }); -}; - -exports['some early return'] = function(test){ - test.expect(1); - var call_order = []; - async.some([1,2,3], function(x, callback){ - setTimeout(function(){ - call_order.push(x); - callback(null, x === 1); - }, x*25); - }, function(){ - call_order.push('callback'); - }); - setTimeout(function(){ - test.same(call_order, [1,'callback',2,3]); - test.done(); - }, 100); -}; - -exports['some error'] = function(test){ - test.expect(2); - async.some([3,1,2], function(x, callback){ - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ - test.equals(err, 'error'); - test.equals(result, null); - test.done(); - }); -}; - -exports['someLimit true'] = function(test){ - async.someLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 2);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, true); - test.done(); - }); -}; - -exports['someLimit false'] = function(test){ - async.someLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 10);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, false); - test.done(); - }); -}; - -exports['every true'] = function(test){ - async.everyLimit([3,1,2], 1, function(x, callback){ - setTimeout(function(){callback(null, x > 1);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, true); - test.done(); - }); -}; - -exports['everyLimit false'] = function(test){ - async.everyLimit([3,1,2], 2, function(x, callback){ - setTimeout(function(){callback(null, x === 2);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, false); - test.done(); - }); -}; - -exports['everyLimit short-circuit'] = function(test){ - test.expect(3); - var calls = 0; - async.everyLimit([3,1,2], 1, function(x, callback){ - calls++; - callback(null, x === 1); - }, function(err, result){ - test.equals(err, null); - test.equals(result, false); - test.equals(calls, 1); - test.done(); - }); -}; - - -exports['someLimit short-circuit'] = function(test){ - test.expect(3); - var calls = 0; - async.someLimit([3,1,2], 1, function(x, callback){ - calls++; - callback(null, x === 1); - }, function(err, result){ - test.equals(err, null); - test.equals(result, true); - test.equals(calls, 2); - test.done(); - }); -}; - -exports['any alias'] = function(test){ - test.equals(async.any, async.some); - test.done(); -}; - -exports['every true'] = function(test){ - test.expect(2); - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback(null, true);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, true); - test.done(); - }); -}; - -exports['every false'] = function(test){ - test.expect(2); - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback(null, x % 2);}, 0); - }, function(err, result){ - test.equals(err, null); - test.equals(result, false); - test.done(); - }); -}; - -exports['every early return'] = function(test){ - test.expect(1); - var call_order = []; - async.every([1,2,3], function(x, callback){ - setTimeout(function(){ - call_order.push(x); - callback(null, x === 1); - }, x*25); - }, function(){ - call_order.push('callback'); - }); - setTimeout(function(){ - test.same(call_order, [1,2,'callback',3]); - test.done(); - }, 100); -}; - -exports['every error'] = function(test){ - async.every([1,2,3], function(x, callback){ - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ - test.equals(err, 'error'); - test.equals(result, null); - test.done(); - }); -}; - -exports['all alias'] = function(test){ - test.equals(async.all, async.every); - test.done(); -}; - -exports['detect'] = function(test){ - test.expect(3); - var call_order = []; - async.detect([3,2,1], detectIterator.bind(this, call_order), function(err, result){ - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function(){ - test.same(call_order, [1,2,'callback',3]); - test.done(); - }, 100); -}; - -exports['detect - mulitple matches'] = function(test){ - test.expect(3); - var call_order = []; - async.detect([3,2,2,1,2], detectIterator.bind(this, call_order), function(err, result){ - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function(){ - test.same(call_order, [1,2,'callback',2,2,3]); - test.done(); - }, 100); -}; - -exports['detect error'] = function(test){ - test.expect(2); - async.detect([3,2,1], function(x, callback) { - setTimeout(function(){callback('error');}, 0); - }, function(err, result){ - test.equals(err, 'error'); - test.equals(result, null); - test.done(); - }); -}; - -exports['detectSeries'] = function(test){ - test.expect(3); - var call_order = []; - async.detectSeries([3,2,1], detectIterator.bind(this, call_order), function(err, result){ - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function(){ - test.same(call_order, [3,2,'callback']); - test.done(); - }, 200); -}; - -exports['detectSeries - multiple matches'] = function(test){ - test.expect(3); - var call_order = []; - async.detectSeries([3,2,2,1,2], detectIterator.bind(this, call_order), function(err, result){ - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function(){ - test.same(call_order, [3,2,'callback']); - test.done(); - }, 200); -}; - -exports['detectSeries - ensure stop'] = function (test) { - test.expect(2); - async.detectSeries([1, 2, 3, 4, 5], function (num, cb) { - if (num > 3) throw new Error("detectSeries did not stop iterating"); - cb(null, num === 3); - }, function (err, result) { - test.equals(err, null); - test.equals(result, 3); - test.done(); - }); -}; - -exports['detectLimit'] = function(test){ - test.expect(3); - var call_order = []; - async.detectLimit([3, 2, 1], 2, detectIterator.bind(this, call_order), function(err, result) { - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function() { - test.same(call_order, [2, 'callback', 3]); - test.done(); - }, 100); -}; - -exports['detectLimit - multiple matches'] = function(test){ - test.expect(3); - var call_order = []; - async.detectLimit([3,2,2,1,2], 2, detectIterator.bind(this, call_order), function(err, result){ - call_order.push('callback'); - test.equals(err, null); - test.equals(result, 2); - }); - setTimeout(function(){ - test.same(call_order, [2, 'callback', 3]); - test.done(); - }, 100); -}; - -exports['detectLimit - ensure stop'] = function (test) { - test.expect(2); - async.detectLimit([1, 2, 3, 4, 5], 2, function (num, cb) { - if (num > 4) throw new Error("detectLimit did not stop iterating"); - cb(null, num === 3); - }, function (err, result) { - test.equals(err, null); - test.equals(result, 3); - test.done(); - }); -}; - exports['sortBy'] = function(test){ test.expect(2); |