18
18
19
19
import doWhileEachRight = require( './index' ) ;
20
20
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
+ }
24
30
25
- const isNotNaN = ( v : number ) : boolean => {
31
+ /**
32
+ * Dummy function.
33
+ */
34
+ function isNotNaN ( v : number ) : boolean {
26
35
return ( v === v ) ;
27
- } ;
36
+ }
37
+
28
38
29
39
// TESTS //
30
40
31
41
// The function returns the input collection...
32
42
{
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>
35
45
}
36
46
37
47
// The compiler throws an error if the function is provided a first argument which is not a collection...
38
48
{
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
43
53
}
44
54
45
55
// 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 => {
54
64
55
65
// The compiler throws an error if the function is provided a third argument which is not a function...
56
66
{
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
63
73
}
64
74
65
75
// The compiler throws an error if the function is provided an invalid number of arguments...
66
76
{
67
77
doWhileEachRight ( ) ; // $ExpectError
68
78
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
71
81
}
0 commit comments