mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
129 lines
4.0 KiB
JavaScript
129 lines
4.0 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { falsey } from './utils.js';
|
|
import fill from '../fill.js';
|
|
|
|
describe('fill', function() {
|
|
it('should use a default `start` of `0` and a default `end` of `length`', function() {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a'), ['a', 'a', 'a']);
|
|
});
|
|
|
|
it('should use `undefined` for `value` if not given', function() {
|
|
var array = [1, 2, 3],
|
|
actual = fill(array);
|
|
|
|
assert.deepStrictEqual(actual, Array(3));
|
|
assert.ok(lodashStable.every(actual, function(value, index) {
|
|
return index in actual;
|
|
}));
|
|
});
|
|
|
|
it('should work with a positive `start`', function() {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', 1), [1, 'a', 'a']);
|
|
});
|
|
|
|
it('should work with a `start` >= `length`', function() {
|
|
lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', start), [1, 2, 3]);
|
|
});
|
|
});
|
|
|
|
it('should treat falsey `start` values as `0`', function() {
|
|
var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
|
|
|
|
var actual = lodashStable.map(falsey, function(start) {
|
|
var array = [1, 2, 3];
|
|
return fill(array, 'a', start);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should work with a negative `start`', function() {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', -1), [1, 2, 'a']);
|
|
});
|
|
|
|
it('should work with a negative `start` <= negative `length`', function() {
|
|
lodashStable.each([-3, -4, -Infinity], function(start) {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', start), ['a', 'a', 'a']);
|
|
});
|
|
});
|
|
|
|
it('should work with `start` >= `end`', function() {
|
|
lodashStable.each([2, 3], function(start) {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', start, 2), [1, 2, 3]);
|
|
});
|
|
});
|
|
|
|
it('should work with a positive `end`', function() {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', 0, 1), ['a', 2, 3]);
|
|
});
|
|
|
|
it('should work with a `end` >= `length`', function() {
|
|
lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', 0, end), ['a', 'a', 'a']);
|
|
});
|
|
});
|
|
|
|
it('should treat falsey `end` values, except `undefined`, as `0`', function() {
|
|
var expected = lodashStable.map(falsey, function(value) {
|
|
return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
|
|
});
|
|
|
|
var actual = lodashStable.map(falsey, function(end) {
|
|
var array = [1, 2, 3];
|
|
return fill(array, 'a', 0, end);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should work with a negative `end`', function() {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', 0, -1), ['a', 'a', 3]);
|
|
});
|
|
|
|
it('should work with a negative `end` <= negative `length`', function() {
|
|
lodashStable.each([-3, -4, -Infinity], function(end) {
|
|
var array = [1, 2, 3];
|
|
assert.deepStrictEqual(fill(array, 'a', 0, end), [1, 2, 3]);
|
|
});
|
|
});
|
|
|
|
it('should coerce `start` and `end` to integers', function() {
|
|
var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
|
|
|
|
var actual = lodashStable.map(positions, function(pos) {
|
|
var array = [1, 2, 3];
|
|
return fill.apply(_, [array, 'a'].concat(pos));
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
|
|
});
|
|
|
|
it('should work as an iteratee for methods like `_.map`', function() {
|
|
var array = [[1, 2], [3, 4]],
|
|
actual = lodashStable.map(array, fill);
|
|
|
|
assert.deepStrictEqual(actual, [[0, 0], [1, 1]]);
|
|
});
|
|
|
|
it('should return a wrapped value when chaining', function() {
|
|
var array = [1, 2, 3],
|
|
wrapped = _(array).fill('a'),
|
|
actual = wrapped.value();
|
|
|
|
assert.ok(wrapped instanceof _);
|
|
assert.strictEqual(actual, array);
|
|
assert.deepEqual(actual, ['a', 'a', 'a']);
|
|
});
|
|
});
|