|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 replaceAfterLast = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a string... |
| 25 | +{ |
| 26 | + replaceAfterLast( 'beep boop', ' ', 'foo', 10 ); // $ExpectType string |
| 27 | + replaceAfterLast( 'beep boop', 'xyz', 'foo', 10 ); // $ExpectType string |
| 28 | + replaceAfterLast( 'beep boop', '', 'foo', 10 ); // $ExpectType string |
| 29 | +} |
| 30 | + |
| 31 | +// The compiler throws an error if the function is provided arguments having invalid types... |
| 32 | +{ |
| 33 | + replaceAfterLast( true, 'd', 'foo', 100 ); // $ExpectError |
| 34 | + replaceAfterLast( false, 'd' , 'foo', 100 ); // $ExpectError |
| 35 | + replaceAfterLast( 3, 'd' , 'foo', 100 ); // $ExpectError |
| 36 | + replaceAfterLast( [], 'd' , 'foo', 100 ); // $ExpectError |
| 37 | + replaceAfterLast( {}, 'd' , 'foo', 100 ); // $ExpectError |
| 38 | + replaceAfterLast( ( x: number ): number => x, 'd', 'foo', 100 ); // $ExpectError |
| 39 | + |
| 40 | + replaceAfterLast( 'abc', true, 'foo', 10 ); // $ExpectError |
| 41 | + replaceAfterLast( 'abc', false, 'foo', 10 ); // $ExpectError |
| 42 | + replaceAfterLast( 'abc', 5 , 'foo', 10 ); // $ExpectError |
| 43 | + replaceAfterLast( 'abc', [], 'foo', 10 ); // $ExpectError |
| 44 | + replaceAfterLast( 'abc', {} , 'foo', 10 ); // $ExpectError |
| 45 | + replaceAfterLast( 'abc', ( x: number ): number => x , 'foo', 10 ); // $ExpectError |
| 46 | + |
| 47 | + replaceAfterLast( 'abc', 'd', true, 10 ); // $ExpectError |
| 48 | + replaceAfterLast( 'abc', 'd', false, 10 ); // $ExpectError |
| 49 | + replaceAfterLast( 'abc', 'd', 5, 10 ); // $ExpectError |
| 50 | + replaceAfterLast( 'abc', 'd', [], 10 ); // $ExpectError |
| 51 | + replaceAfterLast( 'abc', 'd', {}, 10 ); // $ExpectError |
| 52 | + replaceAfterLast( 'abc', 'd', ( x: number ): number => x, 10 ); // $ExpectError |
| 53 | + |
| 54 | + replaceAfterLast( 'abc', 'd', 'foo', true ); // $ExpectError |
| 55 | + replaceAfterLast( 'abc', 'd', 'foo', false ); // $ExpectError |
| 56 | + replaceAfterLast( 'abc', 'd', 'foo', '5' ); // $ExpectError |
| 57 | + replaceAfterLast( 'abc', 'd', 'foo', [] ); // $ExpectError |
| 58 | + replaceAfterLast( 'abc', 'd', 'foo', {} ); // $ExpectError |
| 59 | + replaceAfterLast( 'abc', 'd', 'foo', ( x: number ): number => x ); // $ExpectError |
| 60 | +} |
| 61 | + |
| 62 | +// The compiler throws an error if the function is provided insufficient arguments... |
| 63 | +{ |
| 64 | + replaceAfterLast(); // $ExpectError |
| 65 | + replaceAfterLast( 'abc' ); // $ExpectError |
| 66 | + replaceAfterLast( 'abc', 'd' ); // $ExpectError |
| 67 | + replaceAfterLast( 'abc', 'd', 'foo' ); // $ExpectError |
| 68 | + replaceAfterLast( 'abc', 'd', 'foo', 4, 4 ); // $ExpectError |
| 69 | +} |
0 commit comments