mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
wip: migrate to bun
This commit is contained in:
69
test/findLastIndex-and-lastIndexOf.spec.ts
Normal file
69
test/findLastIndex-and-lastIndexOf.spec.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import assert from 'node:assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { identity, stubZero, falsey } from './utils';
|
||||
import findLastIndex from '../src/findLastIndex';
|
||||
import lastIndexOf from '../src/lastIndexOf';
|
||||
|
||||
const methods = {
|
||||
findLastIndex,
|
||||
lastIndexOf,
|
||||
};
|
||||
|
||||
describe('findLastIndex and lastIndexOf', () => {
|
||||
lodashStable.each(['findLastIndex', 'lastIndexOf'], (methodName) => {
|
||||
const array = [1, 2, 3, 1, 2, 3],
|
||||
func = methods[methodName],
|
||||
resolve =
|
||||
methodName == 'findLastIndex' ? lodashStable.curry(lodashStable.eq) : identity;
|
||||
|
||||
it(`\`_.${methodName}\` should return the index of the last matched value`, () => {
|
||||
assert.strictEqual(func(array, resolve(3)), 5);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should work with a positive \`fromIndex\``, () => {
|
||||
assert.strictEqual(func(array, resolve(1), 2), 0);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should work with a \`fromIndex\` >= \`length\``, () => {
|
||||
const values = [6, 8, 2 ** 32, Infinity],
|
||||
expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
|
||||
|
||||
const actual = lodashStable.map(values, (fromIndex) => [
|
||||
func(array, resolve(undefined), fromIndex),
|
||||
func(array, resolve(1), fromIndex),
|
||||
func(array, resolve(''), fromIndex),
|
||||
]);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should work with a negative \`fromIndex\``, () => {
|
||||
assert.strictEqual(func(array, resolve(2), -3), 1);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should work with a negative \`fromIndex\` <= \`-length\``, () => {
|
||||
const values = [-6, -8, -Infinity],
|
||||
expected = lodashStable.map(values, stubZero);
|
||||
|
||||
const actual = lodashStable.map(values, (fromIndex) =>
|
||||
func(array, resolve(1), fromIndex),
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should treat falsey \`fromIndex\` values correctly`, () => {
|
||||
const expected = lodashStable.map(falsey, (value) => (value === undefined ? 5 : -1));
|
||||
|
||||
const actual = lodashStable.map(falsey, (fromIndex) =>
|
||||
func(array, resolve(3), fromIndex),
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should coerce \`fromIndex\` to an integer`, () => {
|
||||
assert.strictEqual(func(array, resolve(2), 4.2), 4);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user