|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2026 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 resolveToken = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a string or number... |
| 25 | +{ |
| 26 | + resolveToken( [ 1, 2, 3 ], '0' ); // $ExpectType string | number |
| 27 | + resolveToken( { 'foo': 'bar' }, 'foo' ); // $ExpectType string | number |
| 28 | +} |
| 29 | + |
| 30 | +// The compiler throws an error if the function is provided a first argument which is neither an array nor an object... |
| 31 | +{ |
| 32 | + resolveToken( 'abc', '0' ); // $ExpectError |
| 33 | + resolveToken( 5, '0' ); // $ExpectError |
| 34 | + resolveToken( true, '0' ); // $ExpectError |
| 35 | + resolveToken( false, '0' ); // $ExpectError |
| 36 | + resolveToken( null, '0' ); // $ExpectError |
| 37 | + resolveToken( undefined, '0' ); // $ExpectError |
| 38 | +} |
| 39 | + |
| 40 | +// The compiler throws an error if the function is provided a second argument which is not a string... |
| 41 | +{ |
| 42 | + resolveToken( [ 1, 2, 3 ], true ); // $ExpectError |
| 43 | + resolveToken( [ 1, 2, 3 ], false ); // $ExpectError |
| 44 | + resolveToken( [ 1, 2, 3 ], null ); // $ExpectError |
| 45 | + resolveToken( [ 1, 2, 3 ], undefined ); // $ExpectError |
| 46 | + resolveToken( [ 1, 2, 3 ], 5 ); // $ExpectError |
| 47 | + resolveToken( [ 1, 2, 3 ], [] ); // $ExpectError |
| 48 | + resolveToken( [ 1, 2, 3 ], {} ); // $ExpectError |
| 49 | + resolveToken( [ 1, 2, 3 ], ( x: number ): number => x ); // $ExpectError |
| 50 | +} |
| 51 | + |
| 52 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 53 | +{ |
| 54 | + resolveToken(); // $ExpectError |
| 55 | + resolveToken( [ 1, 2, 3 ] ); // $ExpectError |
| 56 | + resolveToken( [ 1, 2, 3 ], '0', 123 ); // $ExpectError |
| 57 | +} |
0 commit comments