@@ -437,6 +437,17 @@ exports['map'] = function(test){
437
437
} ) ;
438
438
} ;
439
439
440
+ exports [ 'map original untouched' ] = function ( test ) {
441
+ var a = [ 1 , 2 , 3 ] ;
442
+ async . map ( a , function ( x , callback ) {
443
+ callback ( null , x * 2 ) ;
444
+ } , function ( err , results ) {
445
+ test . same ( results , [ 2 , 4 , 6 ] ) ;
446
+ test . same ( a , [ 1 , 2 , 3 ] ) ;
447
+ test . done ( ) ;
448
+ } ) ;
449
+ } ;
450
+
440
451
exports [ 'map error' ] = function ( test ) {
441
452
test . expect ( 1 ) ;
442
453
async . map ( [ 1 , 2 , 3 ] , function ( x , callback ) {
@@ -472,10 +483,13 @@ exports['mapSeries error'] = function(test){
472
483
} ;
473
484
474
485
exports [ 'reduce' ] = function ( test ) {
475
- async . reduce ( [ 1 , 3 , 2 ] , 0 , function ( a , x , callback ) {
486
+ var call_order = [ ] ;
487
+ async . reduce ( [ 1 , 2 , 3 ] , 0 , function ( a , x , callback ) {
488
+ call_order . push ( x ) ;
476
489
callback ( null , a + x ) ;
477
490
} , function ( err , result ) {
478
491
test . equals ( result , 6 ) ;
492
+ test . same ( call_order , [ 1 , 2 , 3 ] ) ;
479
493
test . done ( ) ;
480
494
} ) ;
481
495
} ;
@@ -499,6 +513,35 @@ exports['reduce error'] = function(test){
499
513
setTimeout ( test . done , 50 ) ;
500
514
} ;
501
515
516
+ exports [ 'inject alias' ] = function ( test ) {
517
+ test . equals ( async . inject , async . reduce ) ;
518
+ test . done ( ) ;
519
+ } ;
520
+
521
+ exports [ 'foldl alias' ] = function ( test ) {
522
+ test . equals ( async . foldl , async . reduce ) ;
523
+ test . done ( ) ;
524
+ } ;
525
+
526
+ exports [ 'reduceRight' ] = function ( test ) {
527
+ var call_order = [ ] ;
528
+ var a = [ 1 , 2 , 3 ] ;
529
+ async . reduceRight ( a , 0 , function ( a , x , callback ) {
530
+ call_order . push ( x ) ;
531
+ callback ( null , a + x ) ;
532
+ } , function ( err , result ) {
533
+ test . equals ( result , 6 ) ;
534
+ test . same ( call_order , [ 3 , 2 , 1 ] ) ;
535
+ test . same ( a , [ 1 , 2 , 3 ] ) ;
536
+ test . done ( ) ;
537
+ } ) ;
538
+ } ;
539
+
540
+ exports [ 'foldr alias' ] = function ( test ) {
541
+ test . equals ( async . foldr , async . reduceRight ) ;
542
+ test . done ( ) ;
543
+ } ;
544
+
502
545
exports [ 'filter' ] = function ( test ) {
503
546
async . filter ( [ 3 , 1 , 2 ] , function ( x , callback ) {
504
547
setTimeout ( function ( ) { callback ( x % 2 ) ; } , x * 25 ) ;
@@ -508,6 +551,17 @@ exports['filter'] = function(test){
508
551
} ) ;
509
552
} ;
510
553
554
+ exports [ 'filter original untouched' ] = function ( test ) {
555
+ var a = [ 3 , 1 , 2 ] ;
556
+ async . filter ( a , function ( x , callback ) {
557
+ callback ( x % 2 ) ;
558
+ } , function ( results ) {
559
+ test . same ( results , [ 3 , 1 ] ) ;
560
+ test . same ( a , [ 3 , 1 , 2 ] ) ;
561
+ test . done ( ) ;
562
+ } ) ;
563
+ } ;
564
+
511
565
exports [ 'filterSeries' ] = function ( test ) {
512
566
async . filterSeries ( [ 3 , 1 , 2 ] , function ( x , callback ) {
513
567
setTimeout ( function ( ) { callback ( x % 2 ) ; } , x * 25 ) ;
@@ -517,6 +571,45 @@ exports['filterSeries'] = function(test){
517
571
} ) ;
518
572
} ;
519
573
574
+ exports [ 'select alias' ] = function ( test ) {
575
+ test . equals ( async . select , async . filter ) ;
576
+ test . done ( ) ;
577
+ } ;
578
+
579
+ exports [ 'selectSeries alias' ] = function ( test ) {
580
+ test . equals ( async . selectSeries , async . filterSeries ) ;
581
+ test . done ( ) ;
582
+ } ;
583
+
584
+ exports [ 'reject' ] = function ( test ) {
585
+ async . reject ( [ 3 , 1 , 2 ] , function ( x , callback ) {
586
+ setTimeout ( function ( ) { callback ( x % 2 ) ; } , x * 25 ) ;
587
+ } , function ( results ) {
588
+ test . same ( results , [ 2 ] ) ;
589
+ test . done ( ) ;
590
+ } ) ;
591
+ } ;
592
+
593
+ exports [ 'reject original untouched' ] = function ( test ) {
594
+ var a = [ 3 , 1 , 2 ] ;
595
+ async . reject ( a , function ( x , callback ) {
596
+ callback ( x % 2 ) ;
597
+ } , function ( results ) {
598
+ test . same ( results , [ 2 ] ) ;
599
+ test . same ( a , [ 3 , 1 , 2 ] ) ;
600
+ test . done ( ) ;
601
+ } ) ;
602
+ } ;
603
+
604
+ exports [ 'rejectSeries' ] = function ( test ) {
605
+ async . rejectSeries ( [ 3 , 1 , 2 ] , function ( x , callback ) {
606
+ setTimeout ( function ( ) { callback ( x % 2 ) ; } , x * 25 ) ;
607
+ } , function ( results ) {
608
+ test . same ( results , [ 2 ] ) ;
609
+ test . done ( ) ;
610
+ } ) ;
611
+ } ;
612
+
520
613
exports [ 'some true' ] = function ( test ) {
521
614
async . some ( [ 3 , 1 , 2 ] , function ( x , callback ) {
522
615
process . nextTick ( function ( ) {
@@ -555,6 +648,11 @@ exports['some early return'] = function(test){
555
648
} , 100 ) ;
556
649
} ;
557
650
651
+ exports [ 'any alias' ] = function ( test ) {
652
+ test . equals ( async . any , async . some ) ;
653
+ test . done ( ) ;
654
+ } ;
655
+
558
656
exports [ 'every true' ] = function ( test ) {
559
657
async . every ( [ 1 , 2 , 3 ] , function ( x , callback ) {
560
658
process . nextTick ( function ( ) { callback ( true ) ; } ) ;
@@ -588,3 +686,51 @@ exports['every early return'] = function(test){
588
686
test . done ( ) ;
589
687
} , 100 ) ;
590
688
} ;
689
+
690
+ exports [ 'all alias' ] = function ( test ) {
691
+ test . equals ( async . all , async . every ) ;
692
+ test . done ( ) ;
693
+ } ;
694
+
695
+ exports [ 'detect' ] = function ( test ) {
696
+ var call_order = [ ] ;
697
+ async . detect ( [ 3 , 2 , 1 ] , function ( x , callback ) {
698
+ setTimeout ( function ( ) {
699
+ call_order . push ( x ) ;
700
+ callback ( x == 2 ) ;
701
+ } , x * 25 ) ;
702
+ } , function ( result ) {
703
+ call_order . push ( 'callback' ) ;
704
+ test . equals ( result , 2 ) ;
705
+ } ) ;
706
+ setTimeout ( function ( ) {
707
+ test . same ( call_order , [ 1 , 2 , 'callback' , 3 ] ) ;
708
+ test . done ( ) ;
709
+ } , 100 ) ;
710
+ } ;
711
+
712
+ exports [ 'detectSeries' ] = function ( test ) {
713
+ var call_order = [ ] ;
714
+ async . detectSeries ( [ 3 , 2 , 1 ] , function ( x , callback ) {
715
+ setTimeout ( function ( ) {
716
+ call_order . push ( x ) ;
717
+ callback ( x == 2 ) ;
718
+ } , x * 25 ) ;
719
+ } , function ( result ) {
720
+ call_order . push ( 'callback' ) ;
721
+ test . equals ( result , 2 ) ;
722
+ } ) ;
723
+ setTimeout ( function ( ) {
724
+ test . same ( call_order , [ 3 , 2 , 'callback' ] ) ;
725
+ test . done ( ) ;
726
+ } , 200 ) ;
727
+ } ;
728
+
729
+ exports [ 'sortBy' ] = function ( test ) {
730
+ async . sortBy ( [ { a :1 } , { a :15 } , { a :6 } ] , function ( x , callback ) {
731
+ process . nextTick ( function ( ) { callback ( null , x . a ) ; } ) ;
732
+ } , function ( err , result ) {
733
+ test . same ( result , [ { a :1 } , { a :6 } , { a :15 } ] ) ;
734
+ test . done ( ) ;
735
+ } ) ;
736
+ } ;
0 commit comments