mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Ensure complex paths work with _.get, _.result, & _.set.
This commit is contained in:
18
test/test.js
18
test/test.js
@@ -13139,6 +13139,14 @@
|
||||
});
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should handle complex paths', 2, function() {
|
||||
var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { 'e': 5 } } } } } };
|
||||
|
||||
_.each(['a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'].e', ['a', '-1.23', '["b"]', 'c', "['d']", 'e']], function(path) {
|
||||
strictEqual(func(object, path), 5);
|
||||
});
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return `undefined` when `object` is nullish', 4, function() {
|
||||
_.each(['constructor', ['constructor']], function(path) {
|
||||
strictEqual(func(null, path), undefined);
|
||||
@@ -13595,6 +13603,16 @@
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle complex paths', 2, function() {
|
||||
var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { 'e': 5 } } } } } };
|
||||
|
||||
_.each(['a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'].e', ['a', '-1.23', '["b"]', 'c', "['d']", 'e']], function(path) {
|
||||
_.set(object, path, 6);
|
||||
strictEqual(object.a[-1.23]['["b"]'].c["['d']"].e, 6);
|
||||
object.a[-1.23]['["b"]'].c["['d']"].e = 5;
|
||||
});
|
||||
});
|
||||
|
||||
test('should create parts of `path` that are missing', 6, function() {
|
||||
var object = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user