From 15a4fb7adf497e94681c149c8e903aebfd41f5e7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 5 Sep 2015 10:00:21 -0700 Subject: [PATCH] Add `_.toPath` tests. --- test/test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test.js b/test/test.js index 44e162af9..89966bac9 100644 --- a/test/test.js +++ b/test/test.js @@ -15645,6 +15645,30 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.toPath'); + + (function() { + test('should convert a string to a path', 2, function() { + deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']); + deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']); + }); + + test('should shallow clone array path', 2, function() { + var array = ['a', 'b', 'c'], + actual = _.toPath(array); + + deepEqual(actual, array); + notStrictEqual(actual, array); + }); + + test('should handle complex paths', 1, function() { + var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g'); + deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.toPlainObject'); (function() {