mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add _.merge tests for arguments objectd and typed arrays.
This commit is contained in:
committed by
jdalton
parent
91d44147bb
commit
cccd43a16b
65
test/test.js
65
test/test.js
@@ -7794,7 +7794,7 @@
|
|||||||
|
|
||||||
test('should return `true` for typed arrays', 1, function() {
|
test('should return `true` for typed arrays', 1, function() {
|
||||||
var expected = _.map(typedArrays, function(type) {
|
var expected = _.map(typedArrays, function(type) {
|
||||||
return toString.call(root[type]) == funcTag;
|
return type in root;
|
||||||
});
|
});
|
||||||
|
|
||||||
var actual = _.map(typedArrays, function(type) {
|
var actual = _.map(typedArrays, function(type) {
|
||||||
@@ -7831,7 +7831,7 @@
|
|||||||
test('should work with typed arrays from another realm', 1, function() {
|
test('should work with typed arrays from another realm', 1, function() {
|
||||||
if (_._object) {
|
if (_._object) {
|
||||||
var expected = _.map(typedArrays, function(type) {
|
var expected = _.map(typedArrays, function(type) {
|
||||||
return toString.call(root[type]) == funcTag;
|
return type in root;
|
||||||
});
|
});
|
||||||
|
|
||||||
var actual = _.map(typedArrays, function(type) {
|
var actual = _.map(typedArrays, function(type) {
|
||||||
@@ -8920,17 +8920,58 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not treat `arguments` objects as plain objects', 1, function() {
|
test('should merge `arguments` objects', 3, function() {
|
||||||
var object = {
|
var object1 = { 'value': args },
|
||||||
'args': args
|
object2 = { 'value': { '3': 4 } },
|
||||||
};
|
expected = { '0': 1, '1': 2, '2': 3, '3': 4, 'length': 3 },
|
||||||
|
actual = _.merge(object1, object2);
|
||||||
|
|
||||||
var source = {
|
ok(!_.isArguments(actual.value));
|
||||||
'args': { '3': 4 }
|
deepEqual(actual.value, expected);
|
||||||
};
|
delete object1.value[3];
|
||||||
|
|
||||||
var actual = _.merge(object, source);
|
actual = _.merge(object2, object1);
|
||||||
strictEqual(_.isArguments(actual.args), false);
|
deepEqual(actual.value, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should merge typed arrays', 4, function() {
|
||||||
|
var array1 = [0, 0, 0]
|
||||||
|
array2 = _.range(0, 6, 0)
|
||||||
|
array3 = _.range(0, 12, 0),
|
||||||
|
array4 = _.range(0, 24, 0);
|
||||||
|
|
||||||
|
var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2];
|
||||||
|
|
||||||
|
var expected = _.map(typedArrays, function(type, index) {
|
||||||
|
var array = arrays[index].slice();
|
||||||
|
array[0] = 1;
|
||||||
|
return root[type] ? { 'value': array } : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
var actual = _.map(typedArrays, function(type) {
|
||||||
|
var Ctor = root[type];
|
||||||
|
return Ctor ? _.merge({ 'value': new Ctor(new ArrayBuffer(24)) }, { 'value': [1] }) : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
ok(_.isArray(actual));
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
|
||||||
|
expected = _.map(typedArrays, function(type, index) {
|
||||||
|
var array = arrays[index].slice();
|
||||||
|
array.push(1);
|
||||||
|
return root[type] ? { 'value': array } : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
actual = _.map(typedArrays, function(type, index) {
|
||||||
|
var Ctor = root[type],
|
||||||
|
array = _.range(arrays[index].length);
|
||||||
|
|
||||||
|
array.push(1);
|
||||||
|
return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(new ArrayBuffer(24)) }) : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
ok(_.isArray(actual));
|
||||||
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with four arguments', 1, function() {
|
test('should work with four arguments', 1, function() {
|
||||||
@@ -13184,7 +13225,7 @@
|
|||||||
var objects = [object2, object1, object4, object3, object2, object4, object4, object3, object2];
|
var objects = [object2, object1, object4, object3, object2, object4, object4, object3, object2];
|
||||||
|
|
||||||
var expected = _.map(typedArrays, function(type, index) {
|
var expected = _.map(typedArrays, function(type, index) {
|
||||||
return toString.call(root[type]) == funcTag && objects[index];
|
return root[type] ? objects[index] : false;
|
||||||
});
|
});
|
||||||
|
|
||||||
var actual = _.map(typedArrays, function(type) {
|
var actual = _.map(typedArrays, function(type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user