mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
wip: migrate to bun
This commit is contained in:
49
test/rest.spec.ts
Normal file
49
test/rest.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import assert from 'node:assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { slice, _ } from './utils';
|
||||
|
||||
describe('rest', () => {
|
||||
function fn(a, b, c) {
|
||||
return slice.call(arguments);
|
||||
}
|
||||
|
||||
it('should apply a rest parameter to `func`', () => {
|
||||
const rest = _.rest(fn);
|
||||
assert.deepStrictEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
|
||||
});
|
||||
|
||||
it('should work with `start`', () => {
|
||||
const rest = _.rest(fn, 1);
|
||||
assert.deepStrictEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
|
||||
});
|
||||
|
||||
it('should treat `start` as `0` for `NaN` or negative values', () => {
|
||||
const values = [-1, NaN, 'a'],
|
||||
expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
|
||||
|
||||
const actual = lodashStable.map(values, (value) => {
|
||||
const rest = _.rest(fn, value);
|
||||
return rest(1, 2, 3, 4);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should coerce `start` to an integer', () => {
|
||||
const rest = _.rest(fn, 1.6);
|
||||
assert.deepStrictEqual(rest(1, 2, 3), [1, [2, 3]]);
|
||||
});
|
||||
|
||||
it('should use an empty array when `start` is not reached', () => {
|
||||
const rest = _.rest(fn);
|
||||
assert.deepStrictEqual(rest(1), [1, undefined, []]);
|
||||
});
|
||||
|
||||
it('should work on functions with more than three parameters', () => {
|
||||
const rest = _.rest(function (a, b, c, d) {
|
||||
return slice.call(arguments);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user