mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Move _#reverse tests into _.reverse tests.
This commit is contained in:
232
test/test.js
232
test/test.js
@@ -16634,6 +16634,9 @@
|
|||||||
QUnit.module('lodash.reverse');
|
QUnit.module('lodash.reverse');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
|
||||||
|
smallArray = [0, 1, 2, null];
|
||||||
|
|
||||||
QUnit.test('should reverse `array`', function(assert) {
|
QUnit.test('should reverse `array`', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
@@ -16643,6 +16646,116 @@
|
|||||||
assert.deepEqual(array, [3, 2, 1]);
|
assert.deepEqual(array, [3, 2, 1]);
|
||||||
assert.strictEqual(actual, array);
|
assert.strictEqual(actual, array);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should return the wrapped reversed `array`', function(assert) {
|
||||||
|
assert.expect(6);
|
||||||
|
|
||||||
|
if (!isNpm) {
|
||||||
|
lodashStable.times(2, function(index) {
|
||||||
|
var array = (index ? largeArray : smallArray).slice(),
|
||||||
|
clone = array.slice(),
|
||||||
|
wrapped = _(array).reverse(),
|
||||||
|
actual = wrapped.value();
|
||||||
|
|
||||||
|
assert.ok(wrapped instanceof _);
|
||||||
|
assert.strictEqual(actual, array);
|
||||||
|
assert.deepEqual(actual, clone.slice().reverse());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert, 6);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('should work in a lazy sequence', function(assert) {
|
||||||
|
assert.expect(4);
|
||||||
|
|
||||||
|
if (!isNpm) {
|
||||||
|
lodashStable.times(2, function(index) {
|
||||||
|
var array = (index ? largeArray : smallArray).slice(),
|
||||||
|
expected = array.slice(),
|
||||||
|
actual = _(array).slice(1).reverse().value();
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected.slice(1).reverse());
|
||||||
|
assert.deepEqual(array, expected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert, 4);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('should be lazy when in a lazy sequence', function(assert) {
|
||||||
|
assert.expect(3);
|
||||||
|
|
||||||
|
if (!isNpm) {
|
||||||
|
var spy = {
|
||||||
|
'toString': function() {
|
||||||
|
throw new Error('spy was revealed');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var array = largeArray.concat(spy),
|
||||||
|
expected = array.slice();
|
||||||
|
|
||||||
|
try {
|
||||||
|
var wrapped = _(array).slice(1).map(String).reverse(),
|
||||||
|
actual = wrapped.last();
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
assert.ok(wrapped instanceof _);
|
||||||
|
assert.strictEqual(actual, '1');
|
||||||
|
assert.deepEqual(array, expected);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert, 3);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('should work in a hybrid sequence', function(assert) {
|
||||||
|
assert.expect(8);
|
||||||
|
|
||||||
|
if (!isNpm) {
|
||||||
|
lodashStable.times(2, function(index) {
|
||||||
|
var clone = (index ? largeArray : smallArray).slice();
|
||||||
|
|
||||||
|
lodashStable.each(['map', 'filter'], function(methodName) {
|
||||||
|
var array = clone.slice(),
|
||||||
|
expected = clone.slice(1, -1).reverse(),
|
||||||
|
actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected);
|
||||||
|
|
||||||
|
array = clone.slice();
|
||||||
|
actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
|
||||||
|
|
||||||
|
assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert, 8);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
|
||||||
|
assert.expect(6);
|
||||||
|
|
||||||
|
if (!isNpm) {
|
||||||
|
lodashStable.times(2, function(index) {
|
||||||
|
var array = (index ? largeArray : smallArray).slice(),
|
||||||
|
expected = array.slice().reverse(),
|
||||||
|
wrapped = _(array).chain().reverse().head();
|
||||||
|
|
||||||
|
assert.ok(wrapped instanceof _);
|
||||||
|
assert.strictEqual(wrapped.value(), _.head(expected));
|
||||||
|
assert.deepEqual(array, expected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert, 6);
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -22128,125 +22241,6 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash(...).reverse');
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
|
|
||||||
smallArray = [0, 1, 2, null];
|
|
||||||
|
|
||||||
QUnit.test('should return the wrapped reversed `array`', function(assert) {
|
|
||||||
assert.expect(6);
|
|
||||||
|
|
||||||
if (!isNpm) {
|
|
||||||
lodashStable.times(2, function(index) {
|
|
||||||
var array = (index ? largeArray : smallArray).slice(),
|
|
||||||
clone = array.slice(),
|
|
||||||
wrapped = _(array).reverse(),
|
|
||||||
actual = wrapped.value();
|
|
||||||
|
|
||||||
assert.ok(wrapped instanceof _);
|
|
||||||
assert.strictEqual(actual, array);
|
|
||||||
assert.deepEqual(actual, clone.slice().reverse());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 6);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('should work in a lazy sequence', function(assert) {
|
|
||||||
assert.expect(4);
|
|
||||||
|
|
||||||
if (!isNpm) {
|
|
||||||
lodashStable.times(2, function(index) {
|
|
||||||
var array = (index ? largeArray : smallArray).slice(),
|
|
||||||
expected = array.slice(),
|
|
||||||
actual = _(array).slice(1).reverse().value();
|
|
||||||
|
|
||||||
assert.deepEqual(actual, expected.slice(1).reverse());
|
|
||||||
assert.deepEqual(array, expected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 4);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('should be lazy when in a lazy sequence', function(assert) {
|
|
||||||
assert.expect(3);
|
|
||||||
|
|
||||||
if (!isNpm) {
|
|
||||||
var spy = {
|
|
||||||
'toString': function() {
|
|
||||||
throw new Error('spy was revealed');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var array = largeArray.concat(spy),
|
|
||||||
expected = array.slice();
|
|
||||||
|
|
||||||
try {
|
|
||||||
var wrapped = _(array).slice(1).map(String).reverse(),
|
|
||||||
actual = wrapped.last();
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
assert.ok(wrapped instanceof _);
|
|
||||||
assert.strictEqual(actual, '1');
|
|
||||||
assert.deepEqual(array, expected);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('should work in a hybrid sequence', function(assert) {
|
|
||||||
assert.expect(8);
|
|
||||||
|
|
||||||
if (!isNpm) {
|
|
||||||
lodashStable.times(2, function(index) {
|
|
||||||
var clone = (index ? largeArray : smallArray).slice();
|
|
||||||
|
|
||||||
lodashStable.each(['map', 'filter'], function(methodName) {
|
|
||||||
var array = clone.slice(),
|
|
||||||
expected = clone.slice(1, -1).reverse(),
|
|
||||||
actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
|
|
||||||
|
|
||||||
assert.deepEqual(actual, expected);
|
|
||||||
|
|
||||||
array = clone.slice();
|
|
||||||
actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
|
|
||||||
|
|
||||||
assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 8);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
|
|
||||||
assert.expect(6);
|
|
||||||
|
|
||||||
if (!isNpm) {
|
|
||||||
lodashStable.times(2, function(index) {
|
|
||||||
var array = (index ? largeArray : smallArray).slice(),
|
|
||||||
expected = array.slice().reverse(),
|
|
||||||
wrapped = _(array).chain().reverse().head();
|
|
||||||
|
|
||||||
assert.ok(wrapped instanceof _);
|
|
||||||
assert.strictEqual(wrapped.value(), _.head(expected));
|
|
||||||
assert.deepEqual(array, expected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 6);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}());
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
QUnit.module('lodash(...).shift');
|
QUnit.module('lodash(...).shift');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user