|
| 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 iterFill = 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 an iterator... |
| 48 | +{ |
| 49 | + iterFill( iterator(), 'beep' ); // $ExpectType Iterator |
| 50 | + iterFill( iterator(), 'beep', 2 ); // $ExpectType Iterator |
| 51 | + iterFill( iterator(), 'beep', 2, 5 ); // $ExpectType Iterator |
| 52 | +} |
| 53 | + |
| 54 | +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... |
| 55 | +{ |
| 56 | + iterFill( '5', 'beep' ); // $ExpectError |
| 57 | + iterFill( 5, 'beep' ); // $ExpectError |
| 58 | + iterFill( true, 'beep' ); // $ExpectError |
| 59 | + iterFill( false, 'beep' ); // $ExpectError |
| 60 | + iterFill( null, 'beep' ); // $ExpectError |
| 61 | + iterFill( undefined, 'beep' ); // $ExpectError |
| 62 | + iterFill( [], 'beep' ); // $ExpectError |
| 63 | + iterFill( {}, 'beep' ); // $ExpectError |
| 64 | + iterFill( ( x: number ): number => x, 'beep' ); // $ExpectError |
| 65 | +} |
| 66 | + |
| 67 | +// The compiler throws an error if the function is provided a third argument which is not is a number... |
| 68 | +{ |
| 69 | + iterFill( iterator(), 'beep', '5' ); // $ExpectError |
| 70 | + iterFill( iterator(), 'beep', true ); // $ExpectError |
| 71 | + iterFill( iterator(), 'beep', false ); // $ExpectError |
| 72 | + iterFill( iterator(), 'beep', null ); // $ExpectError |
| 73 | + iterFill( iterator(), 'beep', [] ); // $ExpectError |
| 74 | + iterFill( iterator(), 'beep', {} ); // $ExpectError |
| 75 | + iterFill( iterator(), 'beep', ( x: number ): number => x ); // $ExpectError |
| 76 | +} |
| 77 | + |
| 78 | +// The compiler throws an error if the function is provided a fourth argument which is not is a number... |
| 79 | +{ |
| 80 | + iterFill( iterator(), 'beep', 2, '5' ); // $ExpectError |
| 81 | + iterFill( iterator(), 'beep', 2, true ); // $ExpectError |
| 82 | + iterFill( iterator(), 'beep', 2, false ); // $ExpectError |
| 83 | + iterFill( iterator(), 'beep', 2, null ); // $ExpectError |
| 84 | + iterFill( iterator(), 'beep', 2, [] ); // $ExpectError |
| 85 | + iterFill( iterator(), 'beep', 2, {} ); // $ExpectError |
| 86 | + iterFill( iterator(), 'beep', 2, ( x: number ): number => x ); // $ExpectError |
| 87 | +} |
| 88 | + |
| 89 | +// The compiler throws an error if the function is provided insufficient arguments... |
| 90 | +{ |
| 91 | + iterFill(); // $ExpectError |
| 92 | + iterFill( iterator() ); // $ExpectError |
| 93 | +} |
0 commit comments