mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Ensure _.fromPairs can consume results of _.toPairs. [closes #1790]
This commit is contained in:
@@ -5751,7 +5751,7 @@
|
||||
|
||||
while (++index < length) {
|
||||
var pair = pairs[index];
|
||||
baseSet(result, pair[0], pair[1]);
|
||||
result[pair[0]] = pair[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
13
test/test.js
13
test/test.js
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user