1818
1919import doWhileEachRight = require( './index' ) ;
2020
21- const log = ( v : any , index : number ) : void => {
22- console . log ( `${ index } : ${ v } ` ) ;
23- } ;
21+ /**
22+ * Dummy function.
23+ */
24+ function fcn ( v : any , index : number ) : number {
25+ if ( v !== v ) {
26+ throw new Error ( 'beep' ) ;
27+ }
28+ return index ;
29+ }
2430
25- const isNotNaN = ( v : number ) : boolean => {
31+ /**
32+ * Dummy function.
33+ */
34+ function isNotNaN ( v : number ) : boolean {
2635 return ( v === v ) ;
27- } ;
36+ }
37+
2838
2939// TESTS //
3040
3141// The function returns the input collection...
3242{
33- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , isNotNaN ) ; // $ExpectType Collection
34- doWhileEachRight ( [ - 1 , 1 , 2 ] , log , isNotNaN , { } ) ; // $ExpectType Collection
43+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , isNotNaN ) ; // $ExpectType Collection<number>
44+ doWhileEachRight ( [ - 1 , 1 , 2 ] , fcn , isNotNaN , { } ) ; // $ExpectType Collection<number>
3545}
3646
3747// The compiler throws an error if the function is provided a first argument which is not a collection...
3848{
39- doWhileEachRight ( 2 , log , isNotNaN ) ; // $ExpectError
40- doWhileEachRight ( false , log , isNotNaN ) ; // $ExpectError
41- doWhileEachRight ( true , log , isNotNaN ) ; // $ExpectError
42- doWhileEachRight ( { } , log , isNotNaN ) ; // $ExpectError
49+ doWhileEachRight ( 2 , fcn , isNotNaN ) ; // $ExpectError
50+ doWhileEachRight ( false , fcn , isNotNaN ) ; // $ExpectError
51+ doWhileEachRight ( true , fcn , isNotNaN ) ; // $ExpectError
52+ doWhileEachRight ( { } , fcn , isNotNaN ) ; // $ExpectError
4353}
4454
4555// The compiler throws an error if the function is provided a second argument which is not a function...
@@ -54,18 +64,18 @@ const isNotNaN = ( v: number ): boolean => {
5464
5565// The compiler throws an error if the function is provided a third argument which is not a function...
5666{
57- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , 2 ) ; // $ExpectError
58- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , false ) ; // $ExpectError
59- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , true ) ; // $ExpectError
60- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , 'abc' ) ; // $ExpectError
61- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , { } ) ; // $ExpectError
62- doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , log , [ ] ) ; // $ExpectError
67+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , 2 ) ; // $ExpectError
68+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , false ) ; // $ExpectError
69+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , true ) ; // $ExpectError
70+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , 'abc' ) ; // $ExpectError
71+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , { } ) ; // $ExpectError
72+ doWhileEachRight ( [ 0 , 1 , 1 , NaN , 2 ] , fcn , [ ] ) ; // $ExpectError
6373}
6474
6575// The compiler throws an error if the function is provided an invalid number of arguments...
6676{
6777 doWhileEachRight ( ) ; // $ExpectError
6878 doWhileEachRight ( [ 1 , 2 , 3 ] ) ; // $ExpectError
69- doWhileEachRight ( [ 1 , 2 , 3 ] , log ) ; // $ExpectError
70- doWhileEachRight ( [ 1 , 2 , 3 ] , log , isNotNaN , { } , 3 ) ; // $ExpectError
79+ doWhileEachRight ( [ 1 , 2 , 3 ] , fcn ) ; // $ExpectError
80+ doWhileEachRight ( [ 1 , 2 , 3 ] , fcn , isNotNaN , { } , 3 ) ; // $ExpectError
7181}
0 commit comments