|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 | + |
| 20 | +import cueveryByRight = require( './index' ); |
| 21 | + |
| 22 | +const isPositive = ( v: number ): boolean => { |
| 23 | + return ( v > 0 ); |
| 24 | +}; |
| 25 | + |
| 26 | +// TESTS // |
| 27 | + |
| 28 | +// The function returns an array... |
| 29 | +{ |
| 30 | + cueveryByRight( [ 0, 1, 1 ], isPositive ); // $ExpectType boolean[] |
| 31 | + cueveryByRight( [ -1, 0, 1, 2 ], isPositive ); // $ExpectType boolean[] |
| 32 | +} |
| 33 | + |
| 34 | +// The compiler throws an error if the function is provided a first argument which is not an array-like object... |
| 35 | +{ |
| 36 | + cueveryByRight( 1 ); // $ExpectError |
| 37 | + cueveryByRight( true ); // $ExpectError |
| 38 | + cueveryByRight( false ); // $ExpectError |
| 39 | + cueveryByRight( null ); // $ExpectError |
| 40 | + cueveryByRight( void 0 ); // $ExpectError |
| 41 | + cueveryByRight( {} ); // $ExpectError |
| 42 | +} |
| 43 | + |
| 44 | +// The compiler throws an error if the function is provided a second argument which is not a function... |
| 45 | +{ |
| 46 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 47 | + |
| 48 | + cueveryByRight( x, '1' ); // $ExpectError |
| 49 | + cueveryByRight( x, true ); // $ExpectError |
| 50 | + cueveryByRight( x, false ); // $ExpectError |
| 51 | + cueveryByRight( x, 'abc' ); // $ExpectError |
| 52 | + cueveryByRight( x, void 0 ); // $ExpectError |
| 53 | + cueveryByRight( x, {} ); // $ExpectError |
| 54 | + cueveryByRight( x, [] ); // $ExpectError |
| 55 | + |
| 56 | + cueveryByRight( x, '1', {} ); // $ExpectError |
| 57 | + cueveryByRight( x, true, {} ); // $ExpectError |
| 58 | + cueveryByRight( x, false, {} ); // $ExpectError |
| 59 | + cueveryByRight( x, 'abc', {} ); // $ExpectError |
| 60 | + cueveryByRight( x, void 0, {} ); // $ExpectError |
| 61 | + cueveryByRight( x, {}, {} ); // $ExpectError |
| 62 | + cueveryByRight( x, [], {} ); // $ExpectError |
| 63 | +} |
| 64 | + |
| 65 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 66 | +{ |
| 67 | + cueveryByRight(); // $ExpectError |
| 68 | + cueveryByRight( [] ); // $ExpectError |
| 69 | + cueveryByRight( [], [], [], [] ); // $ExpectError |
| 70 | +} |
| 71 | + |
| 72 | +// Attached to the main export is an `assign` method which returns a collection... |
| 73 | +{ |
| 74 | + const x = [ 1, 2, 3, 4 ]; |
| 75 | + cueveryByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive ); // $ExpectType (number | boolean)[] |
| 76 | + cueveryByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array |
| 77 | + cueveryByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array |
| 78 | + cueveryByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array |
| 79 | + cueveryByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array |
| 80 | + cueveryByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array |
| 81 | + cueveryByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array |
| 82 | + cueveryByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array |
| 83 | + cueveryByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array |
| 84 | + cueveryByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray |
| 85 | + |
| 86 | + cueveryByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] |
| 87 | + cueveryByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array |
| 88 | + cueveryByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array |
| 89 | + cueveryByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array |
| 90 | + cueveryByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array |
| 91 | + cueveryByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array |
| 92 | + cueveryByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array |
| 93 | + cueveryByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array |
| 94 | + cueveryByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array |
| 95 | + cueveryByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray |
| 96 | +} |
| 97 | + |
| 98 | +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... |
| 99 | +{ |
| 100 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 101 | + |
| 102 | + cueveryByRight.assign( 1, x, 2, 0, isPositive ); // $ExpectError |
| 103 | + cueveryByRight.assign( true, x, 2, 0, isPositive ); // $ExpectError |
| 104 | + cueveryByRight.assign( false, x, 2, 0, isPositive ); // $ExpectError |
| 105 | + cueveryByRight.assign( null, x, 2, 0, isPositive ); // $ExpectError |
| 106 | + cueveryByRight.assign( void 0, x, 2, 0, isPositive ); // $ExpectError |
| 107 | + cueveryByRight.assign( {}, x, 2, 0, isPositive ); // $ExpectError |
| 108 | + |
| 109 | + cueveryByRight.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError |
| 110 | + cueveryByRight.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError |
| 111 | + cueveryByRight.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError |
| 112 | + cueveryByRight.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError |
| 113 | + cueveryByRight.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError |
| 114 | + cueveryByRight.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError |
| 115 | +} |
| 116 | + |
| 117 | +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... |
| 118 | +{ |
| 119 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 120 | + |
| 121 | + cueveryByRight.assign( x, true, 1, 0, isPositive ); // $ExpectError |
| 122 | + cueveryByRight.assign( x, false, 1, 0, isPositive ); // $ExpectError |
| 123 | + cueveryByRight.assign( x, null, 1, 0, isPositive ); // $ExpectError |
| 124 | + cueveryByRight.assign( x, void 0, 1, 0, isPositive ); // $ExpectError |
| 125 | + cueveryByRight.assign( x, {}, 1, 0, isPositive ); // $ExpectError |
| 126 | + cueveryByRight.assign( x, 1, 1, 0, isPositive ); // $ExpectError |
| 127 | + |
| 128 | + cueveryByRight.assign( x, true, 1, 0, isPositive, {} ); // $ExpectError |
| 129 | + cueveryByRight.assign( x, false, 1, 0, isPositive, {} ); // $ExpectError |
| 130 | + cueveryByRight.assign( x, null, 1, 0, isPositive, {} ); // $ExpectError |
| 131 | + cueveryByRight.assign( x, void 0, 1, 0, isPositive, {} ); // $ExpectError |
| 132 | + cueveryByRight.assign( x, {}, 1, 0, isPositive, {} ); // $ExpectError |
| 133 | + cueveryByRight.assign( x, 1, 1, 0, isPositive, {} ); // $ExpectError |
| 134 | +} |
| 135 | + |
| 136 | +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... |
| 137 | +{ |
| 138 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 139 | + const y = [ false, null, false, null, false, null, false, null, false, null ]; |
| 140 | + |
| 141 | + cueveryByRight.assign( x, y, '1', 0, isPositive ); // $ExpectError |
| 142 | + cueveryByRight.assign( x, y, true, 0, isPositive ); // $ExpectError |
| 143 | + cueveryByRight.assign( x, y, false, 0, isPositive ); // $ExpectError |
| 144 | + cueveryByRight.assign( x, y, null, 0, isPositive ); // $ExpectError |
| 145 | + cueveryByRight.assign( x, y, void 0, 0, isPositive ); // $ExpectError |
| 146 | + cueveryByRight.assign( x, y, {}, 0, isPositive ); // $ExpectError |
| 147 | + cueveryByRight.assign( x, y, [], 0, isPositive ); // $ExpectError |
| 148 | + |
| 149 | + cueveryByRight.assign( x, y, '1', 0, isPositive, {} ); // $ExpectError |
| 150 | + cueveryByRight.assign( x, y, true, 0, isPositive, {} ); // $ExpectError |
| 151 | + cueveryByRight.assign( x, y, false, 0, isPositive, {} ); // $ExpectError |
| 152 | + cueveryByRight.assign( x, y, null, 0, isPositive, {} ); // $ExpectError |
| 153 | + cueveryByRight.assign( x, y, void 0, 0, isPositive, {} ); // $ExpectError |
| 154 | + cueveryByRight.assign( x, y, {}, 0, isPositive, {} ); // $ExpectError |
| 155 | + cueveryByRight.assign( x, y, [], 0, isPositive, {} ); // $ExpectError |
| 156 | +} |
| 157 | + |
| 158 | +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... |
| 159 | +{ |
| 160 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 161 | + const y = [ false, null, false, null, false, null, false, null, false, null ]; |
| 162 | + |
| 163 | + cueveryByRight.assign( x, y, 1, '1', isPositive ); // $ExpectError |
| 164 | + cueveryByRight.assign( x, y, 1, true, isPositive ); // $ExpectError |
| 165 | + cueveryByRight.assign( x, y, 1, false, isPositive ); // $ExpectError |
| 166 | + cueveryByRight.assign( x, y, 1, null, isPositive ); // $ExpectError |
| 167 | + cueveryByRight.assign( x, y, 1, void 0, isPositive ); // $ExpectError |
| 168 | + cueveryByRight.assign( x, y, 1, {}, isPositive ); // $ExpectError |
| 169 | + cueveryByRight.assign( x, y, 1, [], isPositive ); // $ExpectError |
| 170 | + |
| 171 | + cueveryByRight.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError |
| 172 | + cueveryByRight.assign( x, y, 1, true, isPositive, {} ); // $ExpectError |
| 173 | + cueveryByRight.assign( x, y, 1, false, isPositive, {} ); // $ExpectError |
| 174 | + cueveryByRight.assign( x, y, 1, null, isPositive, {} ); // $ExpectError |
| 175 | + cueveryByRight.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError |
| 176 | + cueveryByRight.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError |
| 177 | + cueveryByRight.assign( x, y, 1, [], isPositive, {} ); // $ExpectError |
| 178 | +} |
| 179 | + |
| 180 | +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function... |
| 181 | +{ |
| 182 | + const x = [ 0, 0, 1, 1, 1 ]; |
| 183 | + const y = [ false, null, false, null, false, null, false, null, false, null ]; |
| 184 | + |
| 185 | + cueveryByRight.assign( x, y, 1, 0, 2 ); // $ExpectError |
| 186 | + cueveryByRight.assign( x, y, 1, 0, false ); // $ExpectError |
| 187 | + cueveryByRight.assign( x, y, 1, 0, true ); // $ExpectError |
| 188 | + cueveryByRight.assign( x, y, 1, 0, 'abc' ); // $ExpectError |
| 189 | + cueveryByRight.assign( x, y, 1, 0, void 0 ); // $ExpectError |
| 190 | + cueveryByRight.assign( x, y, 1, 0, {} ); // $ExpectError |
| 191 | + cueveryByRight.assign( x, y, 1, 0, [] ); // $ExpectError |
| 192 | + |
| 193 | + cueveryByRight.assign( x, y, 1, 0, 2, {} ); // $ExpectError |
| 194 | + cueveryByRight.assign( x, y, 1, 0, false, {} ); // $ExpectError |
| 195 | + cueveryByRight.assign( x, y, 1, 0, true, {} ); // $ExpectError |
| 196 | + cueveryByRight.assign( x, y, 1, 0, 'abc', {} ); // $ExpectError |
| 197 | + cueveryByRight.assign( x, y, 1, 0, void 0, {} ); // $ExpectError |
| 198 | + cueveryByRight.assign( x, y, 1, 0, {}, {} ); // $ExpectError |
| 199 | + cueveryByRight.assign( x, y, 1, 0, [], {} ); // $ExpectError |
| 200 | +} |
| 201 | +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... |
| 202 | +{ |
| 203 | + cueveryByRight.assign(); // $ExpectError |
| 204 | + cueveryByRight.assign( [] ); // $ExpectError |
| 205 | + cueveryByRight.assign( [], [] ); // $ExpectError |
| 206 | + cueveryByRight.assign( [], [], 2 ); // $ExpectError |
| 207 | + cueveryByRight.assign( [], [], 2, {} ); // $ExpectError |
| 208 | + cueveryByRight.assign( [], [], 1, 1, {}, [], {} ); // $ExpectError |
| 209 | +} |
0 commit comments