|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2022 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 endsWith = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a boolean... |
| 25 | +{ |
| 26 | + endsWith( 'To be, or not to be, that is the question.', 'b', 19 ); // $ExpectType boolean |
| 27 | + endsWith( 'abd', 'ab', 2 ); // $ExpectType boolean |
| 28 | +} |
| 29 | + |
| 30 | +// The compiler throws an error if the function is provided arguments having invalid types... |
| 31 | +{ |
| 32 | + endsWith( true, 'd', 2 ); // $ExpectError |
| 33 | + endsWith( false, 'd', 2 ); // $ExpectError |
| 34 | + endsWith( 3, 'd', 3 ); // $ExpectError |
| 35 | + endsWith( [], 'd', 3 ); // $ExpectError |
| 36 | + endsWith( {}, 'd', 3 ); // $ExpectError |
| 37 | + endsWith( ( x: number ): number => x, 'd', 0 ); // $ExpectError |
| 38 | + |
| 39 | + endsWith( 'abd', true, 2 ); // $ExpectError |
| 40 | + endsWith( 'abd', false, 2 ); // $ExpectError |
| 41 | + endsWith( 'abd', 5, 2 ); // $ExpectError |
| 42 | + endsWith( 'abd', [], 3 ); // $ExpectError |
| 43 | + endsWith( 'abd', {}, 3 ); // $ExpectError |
| 44 | + endsWith( 'abd', ( x: number ): number => x, 0 ); // $ExpectError |
| 45 | + |
| 46 | + endsWith( 'abd', 'a', true ); // $ExpectError |
| 47 | + endsWith( 'abd', 'a', false ); // $ExpectError |
| 48 | + endsWith( 'abd', 'a', '5' ); // $ExpectError |
| 49 | + endsWith( 'abd', 'b', [] ); // $ExpectError |
| 50 | + endsWith( 'abd', 'b', {} ); // $ExpectError |
| 51 | + endsWith( 'abd', 'b', /[a-z]/ ); // $ExpectError |
| 52 | +} |
| 53 | + |
| 54 | +// The compiler throws an error if the function is provided insufficient arguments... |
| 55 | +{ |
| 56 | + endsWith(); // $ExpectError |
| 57 | + endsWith( 'abc' ); // $ExpectError |
| 58 | + endsWith( 'abc', 'a' ); // $ExpectError |
| 59 | +} |
0 commit comments