From a965836cf3420ae405e32a7f99b255cc4cc1bcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Fri, 16 Aug 2019 19:51:17 -0300 Subject: [PATCH] Enable indexOf tests (#4411) --- test/findIndex-and-indexOf.js | 63 ----------------------------------- test/indexOf.test.js | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 63 deletions(-) delete mode 100644 test/findIndex-and-indexOf.js create mode 100644 test/indexOf.test.js diff --git a/test/findIndex-and-indexOf.js b/test/findIndex-and-indexOf.js deleted file mode 100644 index 217e5503d..000000000 --- a/test/findIndex-and-indexOf.js +++ /dev/null @@ -1,63 +0,0 @@ -import assert from 'assert'; -import lodashStable from 'lodash'; -import { _, identity, stubZero, falsey } from './utils.js'; - -describe('findIndex and indexOf', function() { - lodashStable.each(['findIndex', 'indexOf'], function(methodName) { - var array = [1, 2, 3, 1, 2, 3], - func = _[methodName], - resolve = methodName == 'findIndex' ? lodashStable.curry(lodashStable.eq) : identity; - - it('`_.' + methodName + '` should return the index of the first matched value', function() { - assert.strictEqual(func(array, resolve(3)), 2); - }); - - it('`_.' + methodName + '` should work with a positive `fromIndex`', function() { - assert.strictEqual(func(array, resolve(1), 2), 3); - }); - - it('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function() { - var values = [6, 8, Math.pow(2, 32), Infinity], - expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1])); - - var actual = lodashStable.map(values, function(fromIndex) { - return [ - 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`', function() { - assert.strictEqual(func(array, resolve(2), -3), 4); - }); - - it('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function() { - var values = [-6, -8, -Infinity], - expected = lodashStable.map(values, stubZero); - - var actual = lodashStable.map(values, function(fromIndex) { - return func(array, resolve(1), fromIndex); - }); - - assert.deepStrictEqual(actual, expected); - }); - - it('`_.' + methodName + '` should treat falsey `fromIndex` values as `0`', function() { - var expected = lodashStable.map(falsey, stubZero); - - var actual = lodashStable.map(falsey, function(fromIndex) { - return func(array, resolve(1), fromIndex); - }); - - assert.deepStrictEqual(actual, expected); - }); - - it('`_.' + methodName + '` should coerce `fromIndex` to an integer', function() { - assert.strictEqual(func(array, resolve(2), 1.2), 1); - }); - }); -}); diff --git a/test/indexOf.test.js b/test/indexOf.test.js new file mode 100644 index 000000000..49fc80861 --- /dev/null +++ b/test/indexOf.test.js @@ -0,0 +1,60 @@ +import assert from 'assert'; +import lodashStable from 'lodash'; +import { stubZero, falsey } from './utils.js'; +import indexOf from '../indexOf.js'; + +describe('indexOf', function() { + var array = [1, 2, 3, 1, 2, 3]; + + it('`_.indexOf` should return the index of the first matched value', function() { + assert.strictEqual(indexOf(array, 3), 2); + }); + + it('`_.indexOf` should work with a positive `fromIndex`', function() { + assert.strictEqual(indexOf(array, 1, 2), 3); + }); + + it('`_.indexOf` should work with a `fromIndex` >= `length`', function() { + var values = [6, 8, Math.pow(2, 32), Infinity], + expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1])); + + var actual = lodashStable.map(values, function(fromIndex) { + return [ + indexOf(array, undefined, fromIndex), + indexOf(array, 1, fromIndex), + indexOf(array, '', fromIndex) + ]; + }); + + assert.deepStrictEqual(actual, expected); + }); + + it('`_.indexOf` should work with a negative `fromIndex`', function() { + assert.strictEqual(indexOf(array, 2, -3), 4); + }); + + it('`_.indexOf` should work with a negative `fromIndex` <= `-length`', function() { + var values = [-6, -8, -Infinity], + expected = lodashStable.map(values, stubZero); + + var actual = lodashStable.map(values, function(fromIndex) { + return indexOf(array, 1, fromIndex); + }); + + assert.deepStrictEqual(actual, expected); + }); + + it('`_.indexOf` should treat falsey `fromIndex` values as `0`', function() { + var expected = lodashStable.map(falsey, stubZero); + + var actual = lodashStable.map(falsey, function(fromIndex) { + return indexOf(array, 1, fromIndex); + }); + + assert.deepStrictEqual(actual, expected); + }); + + it('`_.indexOf` should coerce `fromIndex` to an integer', function() { + assert.strictEqual(indexOf(array, 2, 1.2), 1); + }); +});