|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2019 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 iterSome = require( './index' ); |
| 20 | + |
| 21 | +/** |
| 22 | +* Returns an iterator protocol-compliant object. |
| 23 | +* |
| 24 | +* @returns iterator protocol-compliant object |
| 25 | +*/ |
| 26 | +function iterator() { |
| 27 | + return { |
| 28 | + 'next': next |
| 29 | + }; |
| 30 | + |
| 31 | + /** |
| 32 | + * Implements the iterator protocol `next` method. |
| 33 | + * |
| 34 | + * @returns iterator protocol-compliant object |
| 35 | + */ |
| 36 | + function next() { |
| 37 | + return { |
| 38 | + 'value': true, |
| 39 | + 'done': false |
| 40 | + }; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +// TESTS // |
| 46 | + |
| 47 | +// The function returns a boolean... |
| 48 | +{ |
| 49 | + iterSome( iterator(), 3 ); // $ExpectType boolean |
| 50 | +} |
| 51 | + |
| 52 | +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... |
| 53 | +{ |
| 54 | + iterSome( '5', 3 ); // $ExpectError |
| 55 | + iterSome( 5, 3 ); // $ExpectError |
| 56 | + iterSome( true, 3 ); // $ExpectError |
| 57 | + iterSome( false, 3 ); // $ExpectError |
| 58 | + iterSome( null, 3 ); // $ExpectError |
| 59 | + iterSome( undefined, 3 ); // $ExpectError |
| 60 | + iterSome( [], 3 ); // $ExpectError |
| 61 | + iterSome( {}, 3 ); // $ExpectError |
| 62 | + iterSome( ( x ) => x, 3 ); // $ExpectError |
| 63 | +} |
| 64 | + |
| 65 | +// The compiler throws an error if the function is provided a second argument which is not a number... |
| 66 | +{ |
| 67 | + iterSome( iterator(), '5' ); // $ExpectError |
| 68 | + iterSome( iterator(), true ); // $ExpectError |
| 69 | + iterSome( iterator(), false ); // $ExpectError |
| 70 | + iterSome( iterator(), null ); // $ExpectError |
| 71 | + iterSome( iterator(), undefined ); // $ExpectError |
| 72 | + iterSome( iterator(), [] ); // $ExpectError |
| 73 | + iterSome( iterator(), {} ); // $ExpectError |
| 74 | + iterSome( iterator(), ( x ) => x ); // $ExpectError |
| 75 | +} |
| 76 | + |
| 77 | +// The compiler throws an error if the function is provided insufficient arguments... |
| 78 | +{ |
| 79 | + iterSome(); // $ExpectError |
| 80 | + iterSome( iterator() ); // $ExpectError |
| 81 | +} |
0 commit comments