From 64a7503196868162abd3742e9cea04cec1c65aae Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 14 Nov 2015 18:09:59 -0800 Subject: [PATCH] Add lazy `at` tests to ensure it works with string index values. --- lodash.js | 2 +- test/test.js | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lodash.js b/lodash.js index e13b7e8cc..8733fbce7 100644 --- a/lodash.js +++ b/lodash.js @@ -13896,7 +13896,7 @@ LazyWrapper.prototype.at = rest(function(paths) { paths = baseFlatten(paths); return (paths.length == 1 && isIndex(paths[0])) - ? this.slice(paths[0], paths[0] + 1) + ? this.slice(paths[0], +paths[0] + 1) : new LazyWrapper(this); }); diff --git a/test/test.js b/test/test.js index 6456bffaf..c044b6d40 100644 --- a/test/test.js +++ b/test/test.js @@ -1248,13 +1248,13 @@ }); QUnit.test('should work in a lazy chain sequence', function(assert) { - assert.expect(4); + assert.expect(6); if (!isNpm) { var largeArray = lodashStable.range(LARGE_ARRAY_SIZE), smallArray = array; - lodashStable.each([[2], [2, 1]], function(paths) { + lodashStable.each([[2], ['2'], [2, 1]], function(paths) { lodashStable.times(2, function(index) { var array = index ? largeArray : smallArray, wrapped = _(array).map(identity).at(paths); @@ -1264,24 +1264,29 @@ }); } else { - skipTest(assert, 4); + skipTest(assert, 6); } }); QUnit.test('should support shortcut fusion', function(assert) { - assert.expect(2); + assert.expect(4); if (!isNpm) { - var count = 0, - array = lodashStable.range(LARGE_ARRAY_SIZE), + var array = lodashStable.range(LARGE_ARRAY_SIZE), + count = 0, iteratee = function(value) { count++; return square(value); }, - actual = _(array).map(iteratee).at(LARGE_ARRAY_SIZE - 1).value(); + lastIndex = LARGE_ARRAY_SIZE - 1; - assert.strictEqual(count, 1); - assert.deepEqual(actual, [square(LARGE_ARRAY_SIZE -1)]); + _.each([lastIndex, lastIndex + ''], function(index) { + count = 0; + var actual = _(array).map(iteratee).at(index).value(); + + assert.strictEqual(count, 1); + assert.deepEqual(actual, [square(lastIndex)]); + }); } else { - skipTest(assert, 2); + skipTest(assert, 4); } });