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