|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2021 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +import circarray2iterator = require( './index' ); |
| 20 | + |
| 21 | +/** |
| 22 | +* Multiplies a value by 10. |
| 23 | +* |
| 24 | +* @param v - iterated value |
| 25 | +* @returns new value |
| 26 | +*/ |
| 27 | +function times10( v: number ): number { |
| 28 | + return v * 10.0; |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +// TESTS // |
| 33 | + |
| 34 | +// The function returns an iterator... |
| 35 | +{ |
| 36 | + circarray2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator |
| 37 | + circarray2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator |
| 38 | + circarray2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator |
| 39 | +} |
| 40 | + |
| 41 | +// The compiler throws an error if the function is provided a first argument which is not array-like... |
| 42 | +{ |
| 43 | + circarray2iterator( 123 ); // $ExpectError |
| 44 | + circarray2iterator( true ); // $ExpectError |
| 45 | + circarray2iterator( false ); // $ExpectError |
| 46 | + circarray2iterator( {} ); // $ExpectError |
| 47 | + circarray2iterator( null ); // $ExpectError |
| 48 | + circarray2iterator( undefined ); // $ExpectError |
| 49 | +} |
| 50 | + |
| 51 | +// The compiler throws an error if the function is provided a second argument which is not an options object or function... |
| 52 | +{ |
| 53 | + circarray2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError |
| 54 | + circarray2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError |
| 55 | + circarray2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError |
| 56 | + circarray2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError |
| 57 | + circarray2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError |
| 58 | + circarray2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError |
| 59 | +} |
| 60 | + |
| 61 | +// The compiler throws an error if the function is provided a `dir` option which is not a number... |
| 62 | +{ |
| 63 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': 'abc' } ); // $ExpectError |
| 64 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': true } ); // $ExpectError |
| 65 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': false } ); // $ExpectError |
| 66 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': null } ); // $ExpectError |
| 67 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': [] } ); // $ExpectError |
| 68 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': {} } ); // $ExpectError |
| 69 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': ( x: number ): number => x } ); // $ExpectError |
| 70 | +} |
| 71 | + |
| 72 | +// The compiler throws an error if the function is provided an `iter` option which is not a number... |
| 73 | +{ |
| 74 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': 'abc' } ); // $ExpectError |
| 75 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': true } ); // $ExpectError |
| 76 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': false } ); // $ExpectError |
| 77 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': null } ); // $ExpectError |
| 78 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': [] } ); // $ExpectError |
| 79 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': {} } ); // $ExpectError |
| 80 | + circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': ( x: number ): number => x } ); // $ExpectError |
| 81 | +} |
| 82 | + |
| 83 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 84 | +{ |
| 85 | + circarray2iterator(); // $ExpectError |
| 86 | + circarray2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError |
| 87 | +} |
0 commit comments