|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2023 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 truncateMiddle = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a string... |
| 25 | +{ |
| 26 | + truncateMiddle( 'abcdefghi', 3, '...' ); // $ExpectType string |
| 27 | +} |
| 28 | + |
| 29 | +// The compiler throws an error if the function is not provided a string as its first argument... |
| 30 | +{ |
| 31 | + truncateMiddle( true, 6, '...' ); // $ExpectError |
| 32 | + truncateMiddle( false, 6, '...' ); // $ExpectError |
| 33 | + truncateMiddle( 3, 6, '...' ); // $ExpectError |
| 34 | + truncateMiddle( [], 6, '...' ); // $ExpectError |
| 35 | + truncateMiddle( {}, 6, '...' ); // $ExpectError |
| 36 | + truncateMiddle( ( x: number ): number => x, 6, '...' ); // $ExpectError |
| 37 | +} |
| 38 | + |
| 39 | +// The compiler throws an error if the function is not provided a number as its second argument... |
| 40 | +{ |
| 41 | + truncateMiddle( 'abd', true, '...' ); // $ExpectError |
| 42 | + truncateMiddle( 'abd', false, '...' ); // $ExpectError |
| 43 | + truncateMiddle( 'abd', 'abc', '...' ); // $ExpectError |
| 44 | + truncateMiddle( 'abd', [], '...' ); // $ExpectError |
| 45 | + truncateMiddle( 'abd', {}, '...' ); // $ExpectError |
| 46 | + truncateMiddle( 'abd', ( x: number ): number => x, '...' ); // $ExpectError |
| 47 | +} |
| 48 | + |
| 49 | +// The compiler throws an error if the function is not provided a string as its third argument... |
| 50 | +{ |
| 51 | + truncateMiddle( 'beep boop', 4, true ); // $ExpectError |
| 52 | + truncateMiddle( 'beep boop', 4, false ); // $ExpectError |
| 53 | + truncateMiddle( 'beep boop', 4, 123 ); // $ExpectError |
| 54 | + truncateMiddle( 'beep boop', 4, [], 0 ); // $ExpectError |
| 55 | + truncateMiddle( 'beep boop', 4, {}, 0 ); // $ExpectError |
| 56 | + truncateMiddle( 'beep boop', 4, ( x: number ): number => x, 0 ); // $ExpectError |
| 57 | +} |
| 58 | + |
| 59 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 60 | +{ |
| 61 | + truncateMiddle(); // $ExpectError |
| 62 | + truncateMiddle( 'abc', 4, '|', true ); // $ExpectError |
| 63 | +} |
0 commit comments