|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2019 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 group = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns an object... |
| 25 | +{ |
| 26 | + group( [ 'beep', 'boop', 'foo', 'bar' ], [ 'b', 'b', 'f', 'b' ] ); // $ExpectType any |
| 27 | + const opts = { |
| 28 | + 'returns': 'indices' as 'indices' |
| 29 | + }; |
| 30 | + group( [ 'beep', 'boop', 'foo', 'bar' ], opts, [ 'b', 'b', 'f', 'b' ] ); // $ExpectType any |
| 31 | +} |
| 32 | + |
| 33 | +// The compiler throws an error if the function is provided a first argument which is not a collection... |
| 34 | +{ |
| 35 | + group( true, [ 'b', 'b', 'f', 'b' ] ); // $ExpectError |
| 36 | + group( false, [ 'b', 'b', 'f', 'b' ] ); // $ExpectError |
| 37 | + group( 5, [ 'b', 'b', 'f', 'b' ] ); // $ExpectError |
| 38 | +} |
| 39 | + |
| 40 | +// The compiler throws an error if the function is provided a last argument which is not a collection... |
| 41 | +{ |
| 42 | + const arr = [ 'beep', 'boop', 'foo', 'bar' ]; |
| 43 | + group( arr, false ); // $ExpectError |
| 44 | + group( arr, true ); // $ExpectError |
| 45 | + group( arr, 32 ); // $ExpectError |
| 46 | + group( arr, {} ); // $ExpectError |
| 47 | + |
| 48 | + group( arr, {}, false ); // $ExpectError |
| 49 | + group( arr, {}, true ); // $ExpectError |
| 50 | + group( arr, {}, 32 ); // $ExpectError |
| 51 | + group( arr, {}, {} ); // $ExpectError |
| 52 | +} |
| 53 | + |
| 54 | +// The compiler throws an error if the function is provided an options argument which is not an object... |
| 55 | +{ |
| 56 | + const arr = [ 'beep', 'boop', 'foo', 'bar' ]; |
| 57 | + const groups = [ 'b', 'b', 'f', 'b' ]; |
| 58 | + group( arr, null, groups ); // $ExpectError |
| 59 | +} |
| 60 | + |
| 61 | +// The compiler throws an error if the function is provided a `returns` option which is not one of 'indices', 'values', or '*'... |
| 62 | +{ |
| 63 | + const arr = [ 'beep', 'boop', 'foo', 'bar' ]; |
| 64 | + const groups = [ 'b', 'b', 'f', 'b' ]; |
| 65 | + group( arr, { 'returns': '5' }, groups ); // $ExpectError |
| 66 | + group( arr, { 'returns': 123 }, groups ); // $ExpectError |
| 67 | + group( arr, { 'returns': [] }, groups ); // $ExpectError |
| 68 | + group( arr, { 'returns': {} }, groups ); // $ExpectError |
| 69 | + group( arr, { 'returns': ( x: number ): number => x }, groups ); // $ExpectError |
| 70 | +} |
| 71 | + |
| 72 | +// The compiler throws an error if the function is provided an invalid number of arguments... |
| 73 | +{ |
| 74 | + const arr = [ 'beep', 'boop', 'foo', 'bar' ]; |
| 75 | + const groups = [ 'b', 'b', 'f', 'b' ]; |
| 76 | + group(); // $ExpectError |
| 77 | + group( arr ); // $ExpectError |
| 78 | + group( arr, {}, groups, 16 ); // $ExpectError |
| 79 | +} |
0 commit comments