Ensure _.fromPairs can consume results of _.toPairs. [closes #1790]

This commit is contained in:
John-David Dalton
2016-01-14 19:36:04 -08:00
parent 1a54e43a24
commit a5c1421c6b
2 changed files with 8 additions and 7 deletions

View File

@@ -5751,7 +5751,7 @@
while (++index < length) {
var pair = pairs[index];
baseSet(result, pair[0], pair[1]);
result[pair[0]] = pair[1];
}
return result;
}

View File

@@ -6326,13 +6326,13 @@
QUnit.module('lodash.fromPairs');
(function() {
var object = { 'barney': 36, 'fred': 40 },
array = [['barney', 36], ['fred', 40]];
QUnit.test('should accept a two dimensional array', function(assert) {
assert.expect(1);
var actual = _.fromPairs(array);
var array = [['a', 1], ['b', 2]],
object = { 'a': 1, 'b': 2 },
actual = _.fromPairs(array);
assert.deepEqual(actual, object);
});
@@ -6350,16 +6350,17 @@
assert.deepEqual(actual, expected);
});
QUnit.test('should support deep paths', function(assert) {
QUnit.test('should not support deep paths', function(assert) {
assert.expect(1);
var actual = _.fromPairs([['a.b.c', 1]]);
assert.deepEqual(actual, { 'a': { 'b': { 'c': 1 } } });
assert.deepEqual(actual, { 'a.b.c': 1 });
});
QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
assert.expect(1);
var object = { 'a.b.c': 1 };
assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
});