|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2020 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 exists = require( './index' ); |
| 20 | + |
| 21 | +const done = ( error: Error, bool: boolean ) => { |
| 22 | + if ( error || ( bool !== true && bool !== false ) ) { |
| 23 | + throw error; |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | + |
| 28 | +// TESTS // |
| 29 | + |
| 30 | +// The function does not have a return value... |
| 31 | +{ |
| 32 | + exists( 'beepboop', done ); // $ExpectType void |
| 33 | + exists( '/var/www/html', done ); // $ExpectType void |
| 34 | +} |
| 35 | + |
| 36 | +// The compiler throws an error if the function is provided a first argument which is not a string... |
| 37 | +{ |
| 38 | + exists( 1, done ); // $ExpectError |
| 39 | + exists( false, done ); // $ExpectError |
| 40 | + exists( true, done ); // $ExpectError |
| 41 | + exists( null, done ); // $ExpectError |
| 42 | + exists( undefined, done ); // $ExpectError |
| 43 | + exists( [], done ); // $ExpectError |
| 44 | + exists( {}, done ); // $ExpectError |
| 45 | + exists( ( x: number ): number => x, done ); // $ExpectError |
| 46 | +} |
| 47 | + |
| 48 | +// The compiler throws an error if the function is provided a second argument which is not a function with the expected signature... |
| 49 | +{ |
| 50 | + exists( 'beepboop', 1 ); // $ExpectError |
| 51 | + exists( 'beepboop', false ); // $ExpectError |
| 52 | + exists( 'beepboop', true ); // $ExpectError |
| 53 | + exists( 'beepboop', null ); // $ExpectError |
| 54 | + exists( 'beepboop', undefined ); // $ExpectError |
| 55 | + exists( 'beepboop', [] ); // $ExpectError |
| 56 | + exists( 'beepboop', {} ); // $ExpectError |
| 57 | + exists( 'beepboop', ( x: number ): number => x ); // $ExpectError |
| 58 | +} |
| 59 | + |
| 60 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 61 | +{ |
| 62 | + exists(); // $ExpectError |
| 63 | + exists( 'C:\\foo\\bar\\baz' ); // $ExpectError |
| 64 | +} |
| 65 | + |
| 66 | +// Attached to main export is a `sync` method which returns a boolean... |
| 67 | +{ |
| 68 | + exists.sync( '/var/www/html' ); // $ExpectType boolean |
| 69 | + exists.sync( '/foo/bar/baz' ); // $ExpectType boolean |
| 70 | +} |
| 71 | + |
| 72 | +// The compiler throws an error if the `sync` method is provided a first argument which is not a string... |
| 73 | +{ |
| 74 | + exists.sync( 1 ); // $ExpectError |
| 75 | + exists.sync( false ); // $ExpectError |
| 76 | + exists.sync( true ); // $ExpectError |
| 77 | + exists.sync( null ); // $ExpectError |
| 78 | + exists.sync( undefined ); // $ExpectError |
| 79 | + exists.sync( [] ); // $ExpectError |
| 80 | + exists.sync( {} ); // $ExpectError |
| 81 | + exists.sync( ( x: number ): number => x ); // $ExpectError |
| 82 | +} |
| 83 | + |
| 84 | +// The compiler throws an error if the `sync` method is provided an unsupported number of arguments... |
| 85 | +{ |
| 86 | + exists.sync(); // $ExpectError |
| 87 | +} |
0 commit comments