|
| 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 open = require( './index' ); |
| 20 | + |
| 21 | +const done = ( error: Error, fd: number ) => { |
| 22 | + if ( error || !fd ) { |
| 23 | + throw error; |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | + |
| 28 | +// TESTS // |
| 29 | + |
| 30 | +// The function does not have a return value... |
| 31 | +{ |
| 32 | + open( '/path/to/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 | + open( 123, done ); // $ExpectError |
| 38 | + open( false, done ); // $ExpectError |
| 39 | + open( true, done ); // $ExpectError |
| 40 | + open( null, done ); // $ExpectError |
| 41 | + open( undefined, done ); // $ExpectError |
| 42 | + open( [], done ); // $ExpectError |
| 43 | + open( {}, done ); // $ExpectError |
| 44 | + open( ( x: number ): number => x, done ); // $ExpectError |
| 45 | +} |
| 46 | + |
| 47 | +// The compiler throws an error if the function is provided a last argument which is not a function with the expected signature... |
| 48 | +{ |
| 49 | + open( '/path/to/beepboop', 'abc' ); // $ExpectError |
| 50 | + open( '/path/to/beepboop', 123 ); // $ExpectError |
| 51 | + open( '/path/to/beepboop', false ); // $ExpectError |
| 52 | + open( '/path/to/beepboop', true ); // $ExpectError |
| 53 | + open( '/path/to/beepboop', null ); // $ExpectError |
| 54 | + open( '/path/to/beepboop', undefined ); // $ExpectError |
| 55 | + open( '/path/to/beepboop', [] ); // $ExpectError |
| 56 | + open( '/path/to/beepboop', {} ); // $ExpectError |
| 57 | + open( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError |
| 58 | +} |
| 59 | + |
| 60 | +// The compiler throws an error if the function is provided a `flags` argument which is not a string or number... |
| 61 | +{ |
| 62 | + open( '/path/to/beepboop', false, done ); // $ExpectError |
| 63 | + open( '/path/to/beepboop', true, done ); // $ExpectError |
| 64 | + open( '/path/to/beepboop', null, done ); // $ExpectError |
| 65 | + open( '/path/to/beepboop', undefined, done ); // $ExpectError |
| 66 | + open( '/path/to/beepboop', [], done ); // $ExpectError |
| 67 | + open( '/path/to/beepboop', {}, done ); // $ExpectError |
| 68 | + open( '/path/to/beepboop', ( x: number ): number => x, done ); // $ExpectError |
| 69 | +} |
| 70 | + |
| 71 | +// The compiler throws an error if the function is provided a `mode` argument which is not a number... |
| 72 | +{ |
| 73 | + open( '/path/to/beepboop', 'r+', 'abc', done ); // $ExpectError |
| 74 | + open( '/path/to/beepboop', 'r+', false, done ); // $ExpectError |
| 75 | + open( '/path/to/beepboop', 'r+', true, done ); // $ExpectError |
| 76 | + open( '/path/to/beepboop', 'r+', null, done ); // $ExpectError |
| 77 | + open( '/path/to/beepboop', 'r+', undefined, done ); // $ExpectError |
| 78 | + open( '/path/to/beepboop', 'r+', [], done ); // $ExpectError |
| 79 | + open( '/path/to/beepboop', 'r+', {}, done ); // $ExpectError |
| 80 | + open( '/path/to/beepboop', 'r+', ( x: number ): number => x, done ); // $ExpectError |
| 81 | +} |
| 82 | + |
| 83 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 84 | +{ |
| 85 | + open(); // $ExpectError |
| 86 | + open( 'C:\\foo\\bar\\baz' ); // $ExpectError |
| 87 | +} |
| 88 | + |
| 89 | +// Attached to main export is a `sync` method which returns a number or an error... |
| 90 | +{ |
| 91 | + open.sync( '/path/to/beepboop' ); // $ExpectType number | Error |
| 92 | +} |
| 93 | + |
| 94 | +// The compiler throws an error if the `sync` method is provided a first argument which is not a string... |
| 95 | +{ |
| 96 | + open.sync( 123 ); // $ExpectError |
| 97 | + open.sync( false ); // $ExpectError |
| 98 | + open.sync( true ); // $ExpectError |
| 99 | + open.sync( null ); // $ExpectError |
| 100 | + open.sync( undefined ); // $ExpectError |
| 101 | + open.sync( [] ); // $ExpectError |
| 102 | + open.sync( {} ); // $ExpectError |
| 103 | + open.sync( ( x: number ): number => x ); // $ExpectError |
| 104 | +} |
| 105 | + |
| 106 | +// The compiler throws an error if the `sync` method is provided a second argument which is not a string or number... |
| 107 | +{ |
| 108 | + open.sync( '/path/to/beepboop', false ); // $ExpectError |
| 109 | + open.sync( '/path/to/beepboop', true ); // $ExpectError |
| 110 | + open.sync( '/path/to/beepboop', null ); // $ExpectError |
| 111 | + open.sync( '/path/to/beepboop', [] ); // $ExpectError |
| 112 | + open.sync( '/path/to/beepboop', {} ); // $ExpectError |
| 113 | + open.sync( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError |
| 114 | +} |
| 115 | + |
| 116 | +// The compiler throws an error if the `sync` method is provided a third argument which is not a number... |
| 117 | +{ |
| 118 | + open.sync( '/path/to/beepboop', 'r+', false ); // $ExpectError |
| 119 | + open.sync( '/path/to/beepboop', 'r+', true ); // $ExpectError |
| 120 | + open.sync( '/path/to/beepboop', 'r+', null ); // $ExpectError |
| 121 | + open.sync( '/path/to/beepboop', 'r+', [] ); // $ExpectError |
| 122 | + open.sync( '/path/to/beepboop', 'r+', {} ); // $ExpectError |
| 123 | + open.sync( '/path/to/beepboop', 'r+', ( x: number ): number => x ); // $ExpectError |
| 124 | +} |
| 125 | + |
| 126 | +// The compiler throws an error if the `sync` method is provided an unsupported number of arguments... |
| 127 | +{ |
| 128 | + open.sync(); // $ExpectError |
| 129 | +} |
0 commit comments