3 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
6 /** Used to detect when a function becomes hot. */
9 /** Used as the size to cover large array optimizations. */
10 var LARGE_ARRAY_SIZE = 200;
12 /** Used as the `TypeError` message for "Functions" methods. */
13 var FUNC_ERROR_TEXT = 'Expected a function';
15 /** Used as references for various `Number` constants. */
16 var MAX_SAFE_INTEGER = 9007199254740991,
17 MAX_INTEGER = 1.7976931348623157e+308;
19 /** Used as references for the maximum length and index of an array. */
20 var MAX_ARRAY_LENGTH = 4294967295,
21 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
23 /** `Object#toString` result references. */
24 var funcTag = '[object Function]',
25 numberTag = '[object Number]',
26 objectTag = '[object Object]';
28 /** Used as a reference to the global object. */
29 var root = (typeof global == 'object' && global) || this;
31 /** Used to store lodash to test for bad extensions/shims. */
32 var lodashBizarro = root.lodashBizarro;
34 /** Used for native method references. */
35 var arrayProto = Array.prototype,
36 errorProto = Error.prototype,
37 funcProto = Function.prototype,
38 objectProto = Object.prototype,
39 numberProto = Number.prototype,
40 stringProto = String.prototype;
42 /** Method and object shortcuts. */
43 var phantom = root.phantom,
44 amd = root.define && define.amd,
45 argv = root.process && process.argv,
46 ArrayBuffer = root.ArrayBuffer,
47 defineProperty = Object.defineProperty,
48 document = !phantom && root.document,
49 body = root.document && root.document.body,
50 create = Object.create,
51 fnToString = funcProto.toString,
52 freeze = Object.freeze,
53 identity = function(value) { return value; },
57 objToString = objectProto.toString,
59 push = arrayProto.push,
62 slice = arrayProto.slice,
64 symbol = Symbol ? Symbol('a') : undefined,
65 Uint8Array = root.Uint8Array,
66 WeakMap = root.WeakMap;
69 var add = function(x, y) { return x + y; },
70 doubled = function(n) { return n * 2; },
71 isEven = function(n) { return n % 2 == 0; },
72 square = function(n) { return n * n; };
74 /** Constant functions. */
75 var alwaysA = function() { return 'a'; },
76 alwaysB = function() { return 'b'; },
77 alwaysC = function() { return 'c'; };
79 var alwaysTrue = function() { return true; },
80 alwaysFalse = function() { return false; };
82 var alwaysNaN = function() { return NaN; },
83 alwaysNull = function() { return null; },
84 alwaysUndefined = function() { return undefined; };
86 var alwaysZero = function() { return 0; },
87 alwaysOne = function() { return 1; },
88 alwaysTwo = function() { return 2; },
89 alwaysThree = function() { return 3; },
90 alwaysFour = function() { return 4; };
92 var alwaysEmptyArray = function() { return []; },
93 alwaysEmptyObject = function() { return {}; },
94 alwaysEmptyString = function() { return ''; };
96 /** The file path of the lodash file to test. */
97 var filePath = (function() {
99 result = params || [];
103 result = params = phantom.args || require('system').args;
105 var last = result[result.length - 1];
106 result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js';
110 result = require('fs').realpathSync(result);
114 result = require.resolve(result);
120 /** The `ui` object. */
121 var ui = root.ui || (root.ui = {
122 'buildPath': filePath,
124 'isModularize': /\b(?:amd|commonjs|es6?|node|npm|(index|main)\.js)\b/.test(filePath),
125 'isStrict': /\bes6?\b/.test(filePath),
129 /** The basename of the lodash file to test. */
130 var basename = /[\w.-]+$/.exec(filePath)[0];
132 /** Used to indicate testing a modularized build. */
133 var isModularize = ui.isModularize;
135 /** Detect if testing `npm` modules. */
136 var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
138 /** Detect if running in PhantomJS. */
139 var isPhantom = phantom || (typeof callPhantom == 'function');
141 /** Detect if lodash is in strict mode. */
142 var isStrict = ui.isStrict;
144 /*--------------------------------------------------------------------------*/
146 // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
147 root.msWDfn = undefined;
149 // Exit early if going to run tests in a PhantomJS web page.
150 if (phantom && isModularize) {
151 var page = require('webpage').create();
153 page.onCallback = function(details) {
154 var coverage = details.coverage;
156 var fs = require('fs'),
157 cwd = fs.workingDirectory,
160 fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
162 phantom.exit(details.failed ? 1 : 0);
165 page.onConsoleMessage = function(message) {
166 console.log(message);
169 page.onInitialized = function() {
170 page.evaluate(function() {
171 document.addEventListener('DOMContentLoaded', function() {
172 QUnit.done(function(details) {
173 details.coverage = window.__coverage__;
174 callPhantom(details);
180 page.open(filePath, function(status) {
181 if (status != 'success') {
182 console.log('PhantomJS failed to load page: ' + filePath);
187 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
191 /*--------------------------------------------------------------------------*/
193 /** Used to test Web Workers. */
194 var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
195 (document && document.origin != 'null') && root.Worker;
197 /** Used to test host objects in IE. */
199 var xml = new ActiveXObject('Microsoft.XMLDOM');
202 /** Poison the free variable `root` in Node.js */
204 defineProperty(global.root, 'root', {
205 'configurable': false,
207 'get': function() { throw new ReferenceError; }
211 /** Use a single "load" function. */
212 var load = (!amd && typeof require == 'function')
216 /** The unit testing framework. */
217 var QUnit = root.QUnit || (root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js'));
219 /** Load stable Lodash and QUnit Extras. */
220 var lodashStable = root.lodashStable || load('../node_modules/lodash/index.js');
222 lodashStable = lodashStable.runInContext(root);
224 var QUnitExtras = load('../node_modules/qunit-extras/qunit-extras.js');
226 QUnitExtras.runInContext(root);
229 /** The `lodash` function to test. */
230 var _ = root._ || (root._ = (
232 _ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _,
233 (_.runInContext ? _.runInContext(root) : _)
236 /** Used to detect instrumented istanbul code coverage runs. */
237 var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) {
238 return /^(?:\$\$cov_\d+\$\$)$/.test(key);
241 /** Used to restore the `_` reference. */
242 var oldDash = root._;
244 /** Used to test generator functions. */
245 var generator = lodashStable.attempt(function() {
246 return Function('return function*(){}');
249 /** List of latin-1 supplementary letters to basic latin letters. */
250 var burredLetters = [
251 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce',
252 '\xcf', '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde',
253 '\xdf', '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee',
254 '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff'
257 /** List of combining diacritical marks. */
259 '\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305', '\u0306', '\u0307', '\u0308', '\u0309', '\u030a', '\u030b', '\u030c', '\u030d', '\u030e', '\u030f',
260 '\u0310', '\u0311', '\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317', '\u0318', '\u0319', '\u031a', '\u031b', '\u031c', '\u031d', '\u031e', '\u031f',
261 '\u0320', '\u0321', '\u0322', '\u0323', '\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329', '\u032a', '\u032b', '\u032c', '\u032d', '\u032e', '\u032f',
262 '\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339', '\u033a', '\u033b', '\u033c', '\u033d', '\u033e', '\u033f',
263 '\u0340', '\u0341', '\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347', '\u0348', '\u0349', '\u034a', '\u034b', '\u034c', '\u034d', '\u034e', '\u034f',
264 '\u0350', '\u0351', '\u0352', '\u0353', '\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359', '\u035a', '\u035b', '\u035c', '\u035d', '\u035e', '\u035f',
265 '\u0360', '\u0361', '\u0362', '\u0363', '\u0364', '\u0365', '\u0366', '\u0367', '\u0368', '\u0369', '\u036a', '\u036b', '\u036c', '\u036d', '\u036e', '\u036f',
266 '\ufe20', '\ufe21', '\ufe22', '\ufe23'
269 /** List of `burredLetters` translated to basic latin letters. */
270 var deburredLetters = [
271 'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
272 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th',
273 'ss', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
274 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y'
277 /** List of emoji modifiers. */
278 var emojiModifiers = [
286 /** Used to specify the emoji style glyph variant of characters. */
287 var emojiVar = '\ufe0f';
289 /** Used to provide falsey values to methods. */
290 var falsey = [, '', 0, false, NaN, null, undefined];
292 /** Used to provide empty values to methods. */
293 var empties = [[], {}].concat(falsey.slice(1));
295 /** Used to test error objects. */
306 /** Used to check whether methods support typed arrays. */
320 * Used to check for problems removing whitespace. For a whitespace reference,
321 * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
323 var whitespace = lodashStable.filter([
324 // Basic whitespace characters.
325 ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
328 '\n', '\r', '\u2028', '\u2029',
330 // Unicode category "Zs" space separators.
331 '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
332 '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
334 function(chr) { return /\s/.exec(chr); })
338 * Extracts the unwrapped value from its wrapper.
341 * @param {Object} wrapper The wrapper to unwrap.
342 * @returns {*} Returns the unwrapped value.
344 function getUnwrappedValue(wrapper) {
346 actions = wrapper.__actions__,
347 length = actions.length,
348 result = wrapper.__wrapped__;
350 while (++index < length) {
352 action = actions[index];
354 push.apply(args, action.args);
355 result = action.func.apply(action.thisArg, args);
361 * Removes all own enumerable properties from a given object.
364 * @param {Object} object The object to empty.
366 function emptyObject(object) {
367 lodashStable.forOwn(object, function(value, key, object) {
373 * Sets a non-enumerable property value on `object`.
375 * Note: This function is used to avoid a bug in older versions of V8 where
376 * overwriting non-enumerable built-ins makes them enumerable.
377 * See https://code.google.com/p/v8/issues/detail?id=1623
380 * @param {Object} object The object modify.
381 * @param {string} key The name of the property to set.
382 * @param {*} value The property value.
384 function setProperty(object, key, value) {
386 defineProperty(object, key, {
387 'configurable': true,
399 * Skips a given number of tests with a passing result.
402 * @param {Object} assert The QUnit assert object.
403 * @param {number} [count=1] The number of tests to skip.
405 function skipTest(assert, count) {
406 count || (count = 1);
408 assert.ok(true, 'test skipped');
412 /*--------------------------------------------------------------------------*/
414 // Add bizarro values.
416 if (document || (typeof require != 'function')) {
419 var nativeString = fnToString.call(toString),
420 reToString = /toString/g;
422 function createToString(funcName) {
423 return lodashStable.constant(nativeString.replace(reToString, funcName));
426 // Allow bypassing native checks.
427 setProperty(funcProto, 'toString', function wrapper() {
428 setProperty(funcProto, 'toString', fnToString);
429 var result = _.has(this, 'toString') ? this.toString() : fnToString.call(this);
430 setProperty(funcProto, 'toString', wrapper);
434 // Add prototype extensions.
435 funcProto._method = noop;
438 var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
439 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
440 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
444 setProperty(root, 'Map', (function() {
451 setProperty(root, 'Map', Map);
456 setProperty(root.Map, 'toString', createToString('Map'));
458 setProperty(Object, 'create', noop);
460 var _getOwnPropertySymbols = Object.getOwnPropertySymbols;
461 setProperty(Object, 'getOwnPropertySymbols', undefined);
463 setProperty(root, 'Set', noop);
464 setProperty(root, 'Symbol', undefined);
465 setProperty(root, 'WeakMap', noop);
467 // Fake `WinRTError`.
468 setProperty(root, 'WinRTError', Error);
470 // Clear cache so lodash can be reloaded.
471 emptyObject(require.cache);
473 // Load lodash and expose it to the bad extensions/shims.
474 lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
477 // Restore built-in methods.
478 if (_getOwnPropertySymbols) {
479 Object.getOwnPropertySymbols = _getOwnPropertySymbols;
481 delete Object.getOwnPropertySymbols;
484 setProperty(root, 'Map', Map);
489 setProperty(root, 'Set', Set);
494 setProperty(root, 'Symbol', Symbol);
499 setProperty(root, 'WeakMap', WeakMap);
503 setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
504 setProperty(Object, 'create', create);
506 delete root.WinRTError;
507 delete funcProto._method;
510 // Add other realm values from the `vm` module.
511 lodashStable.attempt(function() {
512 lodashStable.assign(realm, require('vm').runInNewContext([
514 ' var noop = function() {},',
518 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
519 " 'array': [1, 2, 3],",
520 " 'arrayBuffer': new (root.ArrayBuffer || noop),",
521 " 'boolean': Object(false),",
522 " 'date': new Date,",
523 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
524 " 'function': noop,",
525 " 'map': new (root.Map || noop),",
528 " 'number': Object(0),",
529 " 'object': { 'a': 1, 'b': 2, 'c': 3 },",
531 " 'set': new (root.Set || noop),",
532 " 'string': Object('a'),",
533 " 'symbol': Object((root.Symbol || noop)()),",
534 " 'undefined': undefined",
537 " ['" + typedArrays.join("', '") + "'].forEach(function(type) {",
538 " var Ctor = root[type]",
540 " object[type.toLowerCase()] = new Ctor(new ArrayBuffer(24));",
549 // Add other realm values from an iframe.
550 lodashStable.attempt(function() {
553 var iframe = document.createElement('iframe');
554 iframe.frameBorder = iframe.height = iframe.width = 0;
555 body.appendChild(iframe);
557 var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
562 ' var noop = function() {},',
566 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
567 " 'array': [1, 2, 3],",
568 " 'arrayBuffer': new (root.ArrayBuffer || noop),",
569 " 'boolean': Object(false),",
570 " 'date': new Date,",
571 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
572 " 'function': noop,",
573 " 'map': new (root.Map || noop),",
576 " 'number': Object(0),",
577 " 'object': { 'a': 1, 'b': 2, 'c': 3 },",
579 " 'set': new (root.Set || noop),",
580 " 'string': Object('a'),",
581 " 'symbol': Object((root.Symbol || noop)()),",
582 " 'undefined': undefined",
585 "_.each(['" + typedArrays.join("', '") + "'], function(type) {",
586 ' var Ctor = root[type];',
588 " object[type.toLowerCase()] = new Ctor(new ArrayBuffer(24));",
592 '_.assign(_._realm, object);',
601 lodashStable.attempt(function() {
602 var worker = new Worker('./asset/worker.js?t=' + (+new Date));
603 worker.addEventListener('message', function(e) {
604 _._VERSION = e.data || '';
607 worker.postMessage(ui.buildPath);
610 // Expose internal modules for better code coverage.
611 lodashStable.attempt(function() {
612 var path = require('path'),
613 basePath = path.dirname(filePath);
615 if (isModularize && !(amd || isNpm)) {
619 'internal/isIterateeCall'
620 ], function(relPath) {
621 var func = require(path.join(basePath, relPath)),
622 funcName = path.basename(relPath);
624 _['_' + funcName] = func[funcName] || func['default'] || func;
629 /*--------------------------------------------------------------------------*/
632 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
635 QUnit.module(basename);
638 QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
642 assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
649 QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
652 if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
653 assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
659 QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
663 assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
670 QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
673 var done = assert.async();
676 var limit = 30000 / QUnit.config.asyncRetries,
679 var attempt = function() {
680 var actual = _._VERSION;
681 if ((new Date - start) < limit && typeof actual != 'string') {
682 setTimeout(attempt, 16);
685 assert.strictEqual(actual, _.VERSION);
697 QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
701 assert.notOk('_method' in lodashBizarro);
708 QUnit.test('should avoid overwritten native methods', function(assert) {
711 function message(lodashMethod, nativeMethod) {
712 return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
715 function Foo() { this.a = 1; }
718 var object = { 'a': 1 },
719 otherObject = { 'b': 2 },
720 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
724 var actual = lodashBizarro.keysIn(new Foo).sort();
728 var label = message('_.keysIn', 'Object#propertyIsEnumerable');
729 assert.deepEqual(actual, ['a', 'b'], label);
733 lodashBizarro.difference([object, otherObject], largeArray),
734 lodashBizarro.intersection(largeArray, [object]),
735 lodashBizarro.uniq(largeArray)
740 label = message('_.difference`, `_.intersection`, and `_.uniq', 'Object.create` and `Map');
741 assert.deepEqual(actual, [[otherObject], [object], [object]], label);
748 lodashBizarro.clone(object),
749 lodashBizarro.cloneDeep(object)
754 label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
755 assert.deepEqual(actual, [object, object], label);
758 var symObject = Object(symbol);
759 symObject.constructor = Object;
761 Symbol ? lodashBizarro.clone(symObject) : {},
762 Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
763 Symbol ? lodashBizarro.toString(symObject) : ''
768 label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
769 assert.deepEqual(actual, [{}, false, ''], label);
772 var map = new lodashBizarro.memoize.Cache;
773 actual = map.set('a', 1).get('a');
777 label = message('_.memoize.Cache', 'Map');
778 assert.deepEqual(actual, 1, label);
781 map = new (Map || Object);
782 if (Symbol && Symbol.iterator) {
783 map[Symbol.iterator] = null;
785 actual = lodashBizarro.toArray(map);
789 label = message('_.toArray', 'Map');
790 assert.deepEqual(actual, [], label);
798 /*--------------------------------------------------------------------------*/
800 QUnit.module('isIndex');
803 var func = _._isIndex;
805 QUnit.test('should return `true` for indexes', function(assert) {
809 var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
810 expected = lodashStable.map(values, alwaysTrue);
812 var actual = lodashStable.map(values, function(args) {
813 return func.apply(undefined, args);
816 assert.deepEqual(actual, expected);
823 QUnit.test('should return `false` for non-indexes', function(assert) {
827 var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
828 expected = lodashStable.map(values, alwaysFalse);
830 var actual = lodashStable.map(values, function(args) {
831 return func.apply(undefined, args);
834 assert.deepEqual(actual, expected);
842 /*--------------------------------------------------------------------------*/
844 QUnit.module('isIterateeCall');
848 func = _._isIterateeCall,
851 QUnit.test('should return `true` for iteratee calls', function(assert) {
858 assert.strictEqual(func(1, 0, array), true);
859 assert.strictEqual(func(1, 'a', object), true);
860 assert.strictEqual(func(1, 'a', new Foo), true);
867 QUnit.test('should return `false` for non-iteratee calls', function(assert) {
871 assert.strictEqual(func(2, 0, array), false);
872 assert.strictEqual(func(1, 1.1, array), false);
873 assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
874 assert.strictEqual(func(1, 'b', object), false);
881 QUnit.test('should work with `NaN` values', function(assert) {
885 assert.strictEqual(func(NaN, 0, [NaN]), true);
886 assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
893 QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
898 var actual = func(1, { 'toString': null }, [1]);
900 var message = e.message;
902 assert.strictEqual(actual, false, message || '');
910 /*--------------------------------------------------------------------------*/
912 QUnit.module('lodash constructor');
915 var values = empties.concat(true, 1, 'a'),
916 expected = lodashStable.map(values, alwaysTrue);
918 QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
922 var actual = lodashStable.map(values, function(value) {
923 return _(value) instanceof _;
926 assert.deepEqual(actual, expected);
933 QUnit.test('should return provided `lodash` instances', function(assert) {
937 var actual = lodashStable.map(values, function(value) {
938 var wrapped = _(value);
939 return _(wrapped) === wrapped;
942 assert.deepEqual(actual, expected);
949 QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
952 if (!isNpm && lodashBizarro) {
953 var actual = lodashStable.map(values, function(value) {
954 var wrapped = _(lodashBizarro(value)),
955 unwrapped = wrapped.value();
957 return wrapped instanceof _ &&
958 ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
961 assert.deepEqual(actual, expected);
969 /*--------------------------------------------------------------------------*/
971 QUnit.module('lodash.add');
974 QUnit.test('should add two numbers', function(assert) {
977 assert.strictEqual(_.add(6, 4), 10);
978 assert.strictEqual(_.add(-6, 4), -2);
979 assert.strictEqual(_.add(-6, -4), -10);
982 QUnit.test('should not coerce arguments to numbers', function(assert) {
985 assert.strictEqual(_.add('6', '4'), '64');
986 assert.strictEqual(_.add('x', 'y'), 'xy');
989 QUnit.test('should work with only an `augend` or `addend`', function(assert) {
992 assert.strictEqual(_.add(6), 6);
993 assert.strictEqual(_.add(6, undefined), 6);
994 assert.strictEqual(_.add(undefined, 4), 4);
997 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1001 assert.strictEqual(_(1).add(2), 3);
1008 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1012 assert.ok(_(1).chain().add(2) instanceof _);
1020 /*--------------------------------------------------------------------------*/
1022 QUnit.module('lodash.after');
1025 function after(n, times) {
1027 lodashStable.times(times, _.after(n, function() { count++; }));
1031 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1034 assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
1035 assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
1036 assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
1037 assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
1040 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1043 assert.strictEqual(after(NaN, 1), 1);
1046 QUnit.test('should not set a `this` binding', function(assert) {
1049 var after = _.after(1, function(assert) { return ++this.count; }),
1050 object = { 'after': after, 'count': 0 };
1053 assert.strictEqual(object.after(), 2);
1054 assert.strictEqual(object.count, 2);
1058 /*--------------------------------------------------------------------------*/
1060 QUnit.module('lodash.ary');
1063 function fn(a, b, c) {
1064 return slice.call(arguments);
1067 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
1070 var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
1071 assert.deepEqual(actual, [6, 8, 10]);
1073 var capped = _.ary(fn, 2);
1074 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
1077 QUnit.test('should use `func.length` if `n` is not provided', function(assert) {
1080 var capped = _.ary(fn);
1081 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
1084 QUnit.test('should treat a negative `n` as `0`', function(assert) {
1087 var capped = _.ary(fn, -1);
1090 var actual = capped('a');
1093 assert.deepEqual(actual, []);
1096 QUnit.test('should coerce `n` to an integer', function(assert) {
1099 var values = ['1', 1.6, 'xyz'],
1100 expected = [['a'], ['a'], []];
1102 var actual = lodashStable.map(values, function(n) {
1103 var capped = _.ary(fn, n);
1104 return capped('a', 'b');
1107 assert.deepEqual(actual, expected);
1110 QUnit.test('should work when provided less than the capped number of arguments', function(assert) {
1113 var capped = _.ary(fn, 3);
1114 assert.deepEqual(capped('a'), ['a']);
1117 QUnit.test('should use the existing `ary` if smaller', function(assert) {
1120 var capped = _.ary(_.ary(fn, 1), 2);
1121 assert.deepEqual(capped('a', 'b', 'c'), ['a']);
1124 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
1127 var funcs = lodashStable.map([fn], _.ary),
1128 actual = funcs[0]('a', 'b', 'c');
1130 assert.deepEqual(actual, ['a', 'b', 'c']);
1133 QUnit.test('should work when combined with other methods that use metadata', function(assert) {
1136 var array = ['a', 'b', 'c'],
1137 includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
1139 assert.strictEqual(includes('b')(array, 2), true);
1142 includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
1143 assert.strictEqual(includes('b')(array, 2), true);
1151 /*--------------------------------------------------------------------------*/
1153 QUnit.module('lodash.assignIn');
1156 QUnit.test('should be aliased', function(assert) {
1159 assert.strictEqual(_.extend, _.assignIn);
1163 /*--------------------------------------------------------------------------*/
1165 QUnit.module('lodash.assign and lodash.assignIn');
1167 lodashStable.each(['assign', 'assignIn'], function(methodName) {
1168 var func = _[methodName];
1170 QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
1173 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
1176 QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
1179 var expected = { 'a': 1, 'b': 2, 'c': 3 };
1180 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
1181 assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
1184 QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
1187 var expected = { 'a': 3, 'b': 2, 'c': 1 };
1188 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1191 QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
1194 var expected = { 'a': null, 'b': undefined, 'c': null };
1195 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1198 QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
1204 'configurable': true,
1206 'set': function() { throw new Error; }
1214 'constructor': Object,
1215 'toString': lodashStable.constant('source')
1218 defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
1222 defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
1223 'get': alwaysUndefined
1226 defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
1230 defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
1231 'get': lodashStable.constant(Object)
1235 var actual = func(object, source);
1238 assert.deepEqual(actual, source);
1242 /*--------------------------------------------------------------------------*/
1244 QUnit.module('lodash.assignInWith');
1247 QUnit.test('should be aliased', function(assert) {
1250 assert.strictEqual(_.extendWith, _.assignInWith);
1254 /*--------------------------------------------------------------------------*/
1256 QUnit.module('lodash.assignWith and lodash.assignInWith');
1258 lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
1259 var func = _[methodName];
1261 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
1264 var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
1265 return a === undefined ? b : a;
1268 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
1271 QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
1274 var expected = { 'a': undefined };
1275 assert.deepEqual(func({}, expected, alwaysUndefined), expected);
1279 /*--------------------------------------------------------------------------*/
1281 QUnit.module('lodash.at');
1284 var args = arguments,
1285 array = ['a', 'b', 'c'],
1286 object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
1288 QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
1291 var actual = _.at(array, [0, 2]);
1292 assert.deepEqual(actual, ['a', 'c']);
1295 QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
1298 var actual = _.at(array, [2, 4, 0]);
1299 assert.deepEqual(actual, ['c', undefined, 'a']);
1302 QUnit.test('should work with non-index keys on array values', function(assert) {
1305 var values = lodashStable.reject(empties, function(value) {
1306 return (value === 0) || lodashStable.isArray(value);
1309 var array = lodashStable.transform(values, function(result, value) {
1313 var expected = lodashStable.map(values, alwaysOne),
1314 actual = _.at(array, values);
1316 assert.deepEqual(actual, expected);
1319 QUnit.test('should return an empty array when no keys are provided', function(assert) {
1322 assert.deepEqual(_.at(array), []);
1323 assert.deepEqual(_.at(array, [], []), []);
1326 QUnit.test('should accept multiple key arguments', function(assert) {
1329 var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
1330 assert.deepEqual(actual, ['d', 'a', 'c']);
1333 QUnit.test('should work with a falsey `object` argument when keys are provided', function(assert) {
1336 var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
1338 var actual = lodashStable.map(falsey, function(object) {
1340 return _.at(object, 0, 1, 'pop', 'push');
1344 assert.deepEqual(actual, expected);
1347 QUnit.test('should work with an `arguments` object for `object`', function(assert) {
1350 var actual = _.at(args, [2, 0]);
1351 assert.deepEqual(actual, [3, 1]);
1354 QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
1357 var actual = _.at([1, 2, 3, 4, 5], args);
1358 assert.deepEqual(actual, [2, 3, 4]);
1361 QUnit.test('should work with an object for `object`', function(assert) {
1364 var actual = _.at(object, ['a[0].b.c', 'a[1]']);
1365 assert.deepEqual(actual, [3, 4]);
1368 QUnit.test('should pluck inherited property values', function(assert) {
1371 function Foo() { this.a = 1; }
1372 Foo.prototype.b = 2;
1374 var actual = _.at(new Foo, 'b');
1375 assert.deepEqual(actual, [2]);
1378 QUnit.test('should work in a lazy sequence', function(assert) {
1382 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
1385 lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
1386 lodashStable.times(2, function(index) {
1387 var array = index ? largeArray : smallArray,
1388 wrapped = _(array).map(identity).at(paths);
1390 assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
1395 skipTest(assert, 6);
1399 QUnit.test('should support shortcut fusion', function(assert) {
1403 var array = lodashStable.range(LARGE_ARRAY_SIZE),
1405 iteratee = function(value) { count++; return square(value); },
1406 lastIndex = LARGE_ARRAY_SIZE - 1;
1408 lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
1410 var actual = _(array).map(iteratee).at(n).value(),
1411 expected = index < 2 ? 1 : 0;
1413 assert.strictEqual(count, expected);
1415 expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
1416 assert.deepEqual(actual, expected);
1420 skipTest(assert, 8);
1424 QUnit.test('work with an object for `object` when chaining', function(assert) {
1428 var paths = ['a[0].b.c', 'a[1]'],
1429 wrapped = _(object).map(identity).at(paths);
1431 assert.deepEqual(wrapped.value(), _.at(_.map(object, identity), paths));
1439 /*--------------------------------------------------------------------------*/
1441 QUnit.module('lodash.attempt');
1444 QUnit.test('should return the result of `func`', function(assert) {
1447 assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
1450 QUnit.test('should provide additional arguments to `func`', function(assert) {
1453 var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
1454 assert.deepEqual(actual, [1, 2]);
1457 QUnit.test('should return the caught error', function(assert) {
1460 var expected = lodashStable.map(errors, alwaysTrue);
1462 var actual = lodashStable.map(errors, function(error) {
1463 return _.attempt(function() { throw error; }) === error;
1466 assert.deepEqual(actual, expected);
1469 QUnit.test('should coerce errors to error objects', function(assert) {
1472 var actual = _.attempt(function() { throw 'x'; });
1473 assert.ok(lodashStable.isEqual(actual, Error('x')));
1476 QUnit.test('should work with an error object from another realm', function(assert) {
1480 var expected = lodashStable.map(realm.errors, alwaysTrue);
1482 var actual = lodashStable.map(realm.errors, function(error) {
1483 return _.attempt(function() { throw error; }) === error;
1486 assert.deepEqual(actual, expected);
1493 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1497 assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
1504 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1508 assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
1516 /*--------------------------------------------------------------------------*/
1518 QUnit.module('lodash.before');
1521 function before(n, times) {
1523 lodashStable.times(times, _.before(n, function() { count++; }));
1527 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1530 assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
1531 assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
1532 assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
1533 assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
1536 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1539 assert.strictEqual(before(NaN, 1), 0);
1542 QUnit.test('should not set a `this` binding', function(assert) {
1545 var before = _.before(2, function(assert) { return ++this.count; }),
1546 object = { 'before': before, 'count': 0 };
1549 assert.strictEqual(object.before(), 1);
1550 assert.strictEqual(object.count, 1);
1554 /*--------------------------------------------------------------------------*/
1556 QUnit.module('lodash.bind');
1560 var result = [this];
1561 push.apply(result, arguments);
1565 QUnit.test('should bind a function to an object', function(assert) {
1569 bound = _.bind(fn, object);
1571 assert.deepEqual(bound('a'), [object, 'a']);
1574 QUnit.test('should accept a falsey `thisArg` argument', function(assert) {
1577 var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
1578 expected = lodashStable.map(values, function(value) { return [value]; });
1580 var actual = lodashStable.map(values, function(value) {
1582 var bound = _.bind(fn, value);
1587 assert.ok(lodashStable.every(actual, function(value, index) {
1588 return lodashStable.isEqual(value, expected[index]);
1592 QUnit.test('should bind a function to nullish values', function(assert) {
1595 var bound = _.bind(fn, null),
1596 actual = bound('a');
1598 assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
1599 assert.strictEqual(actual[1], 'a');
1601 lodashStable.times(2, function(index) {
1602 bound = index ? _.bind(fn, undefined) : _.bind(fn);
1603 actual = bound('b');
1605 assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
1606 assert.strictEqual(actual[1], 'b');
1610 QUnit.test('should partially apply arguments ', function(assert) {
1614 bound = _.bind(fn, object, 'a');
1616 assert.deepEqual(bound(), [object, 'a']);
1618 bound = _.bind(fn, object, 'a');
1619 assert.deepEqual(bound('b'), [object, 'a', 'b']);
1621 bound = _.bind(fn, object, 'a', 'b');
1622 assert.deepEqual(bound(), [object, 'a', 'b']);
1623 assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
1626 QUnit.test('should support placeholders', function(assert) {
1630 ph = _.bind.placeholder,
1631 bound = _.bind(fn, object, ph, 'b', ph);
1633 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
1634 assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
1635 assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
1636 assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
1639 QUnit.test('should create a function with a `length` of `0`', function(assert) {
1642 var fn = function(a, b, c) {},
1643 bound = _.bind(fn, {});
1645 assert.strictEqual(bound.length, 0);
1647 bound = _.bind(fn, {}, 1);
1648 assert.strictEqual(bound.length, 0);
1651 QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
1658 var bound = _.bind(Foo, { 'a': 1 }),
1659 newBound = new bound;
1661 assert.strictEqual(bound().a, 1);
1662 assert.strictEqual(newBound.a, undefined);
1663 assert.ok(newBound instanceof Foo);
1666 QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
1675 var thisArg = { 'a': 1 },
1676 boundFoo = _.bind(Foo, thisArg),
1677 boundBar = _.bind(Bar, thisArg),
1679 expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
1681 var actual = lodashStable.times(count, function(index) {
1684 case 0: return [new boundFoo().a, new boundBar().a];
1685 case 1: return [new boundFoo(1).a, new boundBar(1).a];
1686 case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
1687 case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
1688 case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
1689 case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
1690 case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
1691 case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
1692 case 8: return [new boundFoo(1, 2, 3, 4, 5, 6, 7, 8).a, new boundBar(1, 2, 3, 4, 5, 6, 7, 8).a];
1697 assert.deepEqual(actual, expected);
1700 QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
1703 function Foo(value) {
1704 return value && object;
1707 var bound = _.bind(Foo),
1710 assert.ok(new bound instanceof Foo);
1711 assert.strictEqual(new bound(true), object);
1714 QUnit.test('should append array arguments to partially applied arguments', function(assert) {
1718 bound = _.bind(fn, object, 'a');
1720 assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
1723 QUnit.test('should not rebind functions', function(assert) {
1730 var bound1 = _.bind(fn, object1),
1731 bound2 = _.bind(bound1, object2, 'a'),
1732 bound3 = _.bind(bound1, object3, 'b');
1734 assert.deepEqual(bound1(), [object1]);
1735 assert.deepEqual(bound2(), [object1, 'a']);
1736 assert.deepEqual(bound3(), [object1, 'b']);
1739 QUnit.test('should not error when instantiating bound built-ins', function(assert) {
1742 var Ctor = _.bind(Date, null),
1743 expected = new Date(2012, 4, 23, 0, 0, 0, 0);
1746 var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
1749 assert.deepEqual(actual, expected);
1751 Ctor = _.bind(Date, null, 2012, 4, 23);
1754 actual = new Ctor(0, 0, 0, 0);
1757 assert.deepEqual(actual, expected);
1760 QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
1763 var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
1765 if (typeof createCtor == 'function') {
1766 var bound = _.bind(createCtor()),
1768 expected = lodashStable.times(count, alwaysTrue);
1770 var actual = lodashStable.times(count, function(index) {
1773 case 0: return !!(new bound);
1774 case 1: return !!(new bound(1));
1775 case 2: return !!(new bound(1, 2));
1776 case 3: return !!(new bound(1, 2, 3));
1777 case 4: return !!(new bound(1, 2, 3, 4));
1778 case 5: return !!(new bound(1, 2, 3, 4, 5));
1779 case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
1780 case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
1785 assert.deepEqual(actual, expected);
1792 QUnit.test('should return a wrapped value when chaining', function(assert) {
1797 bound = _(fn).bind({}, 'a', 'b');
1799 assert.ok(bound instanceof _);
1801 var actual = bound.value()('c');
1802 assert.deepEqual(actual, [object, 'a', 'b', 'c']);
1805 skipTest(assert, 2);
1810 /*--------------------------------------------------------------------------*/
1812 QUnit.module('lodash.bindAll');
1815 var args = arguments;
1822 'a': function() { return this._a; },
1823 'b': function() { return this._b; },
1824 'c': function() { return this._c; },
1825 'd': function() { return this._d; }
1828 QUnit.test('should accept individual method names', function(assert) {
1831 var object = lodashStable.cloneDeep(source);
1832 _.bindAll(object, 'a', 'b');
1834 var actual = lodashStable.map(['a', 'b', 'c'], function(methodName) {
1835 return object[methodName].call({});
1838 assert.deepEqual(actual, [1, 2, undefined]);
1841 QUnit.test('should accept arrays of method names', function(assert) {
1844 var object = lodashStable.cloneDeep(source);
1845 _.bindAll(object, ['a', 'b'], ['c']);
1847 var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(methodName) {
1848 return object[methodName].call({});
1851 assert.deepEqual(actual, [1, 2, 3, undefined]);
1854 QUnit.test('should work with an array `object` argument', function(assert) {
1857 var array = ['push', 'pop'];
1859 assert.strictEqual(array.pop, arrayProto.pop);
1862 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
1865 var object = lodashStable.cloneDeep(source);
1866 _.bindAll(object, args);
1868 var actual = lodashStable.map(args, function(methodName) {
1869 return object[methodName].call({});
1872 assert.deepEqual(actual, [1]);
1876 /*--------------------------------------------------------------------------*/
1878 QUnit.module('lodash.bindKey');
1881 QUnit.test('should work when the target function is overwritten', function(assert) {
1886 'greet': function(greeting) {
1887 return this.user + ' says: ' + greeting;
1891 var bound = _.bindKey(object, 'greet', 'hi');
1892 assert.strictEqual(bound(), 'fred says: hi');
1894 object.greet = function(greeting) {
1895 return this.user + ' says: ' + greeting + '!';
1898 assert.strictEqual(bound(), 'fred says: hi!');
1901 QUnit.test('should support placeholders', function(assert) {
1906 return slice.call(arguments);
1910 var ph = _.bindKey.placeholder,
1911 bound = _.bindKey(object, 'fn', ph, 'b', ph);
1913 assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
1914 assert.deepEqual(bound('a'), ['a', 'b', undefined]);
1915 assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
1916 assert.deepEqual(bound(), [undefined, 'b', undefined]);
1919 QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
1922 function Foo(value) {
1923 return value && object;
1926 var object = { 'Foo': Foo },
1927 bound = _.bindKey(object, 'Foo');
1929 assert.ok(new bound instanceof Foo);
1930 assert.strictEqual(new bound(true), object);
1934 /*--------------------------------------------------------------------------*/
1936 QUnit.module('case methods');
1938 lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
1939 var methodName = caseName + 'Case',
1940 func = _[methodName];
1943 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
1944 'FOO BAR', 'fooBar', '--foo-bar', '__foo_bar__'
1947 var converted = (function() {
1949 case 'camel': return 'fooBar';
1950 case 'kebab': return 'foo-bar';
1951 case 'lower': return 'foo bar';
1952 case 'snake': return 'foo_bar';
1953 case 'start': return 'Foo Bar';
1954 case 'upper': return 'FOO BAR';
1958 QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
1961 var actual = lodashStable.map(strings, function(string) {
1962 return func(string) === converted;
1965 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
1968 QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
1971 var actual = lodashStable.map(strings, function(string) {
1972 return func(func(string)) === converted;
1975 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
1978 QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
1981 var actual = lodashStable.map(burredLetters, function(burred, index) {
1982 var letter = deburredLetters[index];
1983 if (caseName == 'start') {
1984 letter = lodashStable.capitalize(letter);
1985 } else if (caseName == 'upper') {
1986 letter = letter.toUpperCase();
1988 letter = letter.toLowerCase();
1990 return func(burred) === letter;
1993 assert.deepEqual(actual, lodashStable.map(burredLetters, alwaysTrue));
1996 QUnit.test('`_.' + methodName + '` should trim latin-1 mathematical operators', function(assert) {
1999 var actual = lodashStable.map(['\xd7', '\xf7'], func);
2000 assert.deepEqual(actual, ['', '']);
2003 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
2006 var string = 'foo bar';
2007 assert.strictEqual(func(Object(string)), converted);
2008 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
2011 QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
2015 assert.strictEqual(_('foo bar')[methodName](), converted);
2022 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
2026 assert.ok(_('foo bar').chain()[methodName]() instanceof _);
2035 QUnit.test('should get the original value after cycling through all case methods', function(assert) {
2038 var funcs = [_.camelCase, _.kebabCase, _.snakeCase, _.startCase, _.camelCase];
2040 var actual = lodashStable.reduce(funcs, function(result, func) {
2041 return func(result);
2042 }, 'enable 24h format');
2044 assert.strictEqual(actual, 'enable24hFormat');
2048 /*--------------------------------------------------------------------------*/
2050 QUnit.module('lodash.camelCase');
2053 QUnit.test('should work with numbers', function(assert) {
2056 assert.strictEqual(_.camelCase('12 feet'), '12Feet');
2057 assert.strictEqual(_.camelCase('enable 24h format'), 'enable24hFormat');
2058 assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
2059 assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
2060 assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
2063 QUnit.test('should handle acronyms', function(assert) {
2066 lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
2067 assert.strictEqual(_.camelCase(string), 'safeHtml');
2070 lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
2071 assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
2074 lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
2075 assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
2080 /*--------------------------------------------------------------------------*/
2082 QUnit.module('lodash.capitalize');
2085 QUnit.test('should capitalize the first character of a string', function(assert) {
2088 assert.strictEqual(_.capitalize('fred'), 'Fred');
2089 assert.strictEqual(_.capitalize('Fred'), 'Fred');
2090 assert.strictEqual(_.capitalize(' fred'), ' fred');
2094 /*--------------------------------------------------------------------------*/
2096 QUnit.module('lodash.chain');
2099 QUnit.test('should return a wrapped value', function(assert) {
2103 var actual = _.chain({ 'a': 0 });
2104 assert.ok(actual instanceof _);
2111 QUnit.test('should return existing wrapped values', function(assert) {
2115 var wrapped = _({ 'a': 0 });
2116 assert.strictEqual(_.chain(wrapped), wrapped);
2117 assert.strictEqual(wrapped.chain(), wrapped);
2120 skipTest(assert, 2);
2124 QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
2128 var array = ['c', 'b', 'a'];
2130 assert.ok(_.chain(array).head() instanceof _);
2131 assert.ok(_(array).chain().head() instanceof _);
2133 assert.ok(_.chain(array).isArray() instanceof _);
2134 assert.ok(_(array).chain().isArray() instanceof _);
2136 assert.ok(_.chain(array).sortBy().head() instanceof _);
2137 assert.ok(_(array).chain().sortBy().head() instanceof _);
2140 skipTest(assert, 6);
2144 QUnit.test('should chain multiple methods', function(assert) {
2148 lodashStable.times(2, function(index) {
2149 var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
2150 expected = { ' ': 9, 'e': 14, 'f': 2, 'g': 1, 'h': 2, 'i': 4, 'l': 2, 'n': 6, 'o': 3, 'r': 2, 's': 2, 't': 5, 'u': 1, 'v': 4, 'w': 2, 'x': 1 },
2151 wrapped = index ? _(array).chain() : _.chain(array);
2153 var actual = wrapped
2155 .map(function(value) { return value.split(''); })
2157 .reduce(function(object, chr) {
2158 object[chr] || (object[chr] = 0);
2164 assert.deepEqual(actual, expected);
2166 array = [1, 2, 3, 4, 5, 6];
2167 wrapped = index ? _(array).chain() : _.chain(array);
2170 .filter(function(n) { return n % 2 != 0; })
2171 .reject(function(n) { return n % 3 == 0; })
2172 .sortBy(function(n) { return -n; })
2175 assert.deepEqual(actual, [5, 1]);
2178 wrapped = index ? _(array).chain() : _.chain(array);
2183 .tap(function(value) { value.pop(); })
2187 assert.deepEqual(actual, [25, 16, 9, 4]);
2191 skipTest(assert, 6);
2196 /*--------------------------------------------------------------------------*/
2198 QUnit.module('lodash.chunk');
2201 var array = [0, 1, 2, 3, 4, 5];
2203 QUnit.test('should return chunked arrays', function(assert) {
2206 var actual = _.chunk(array, 3);
2207 assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
2210 QUnit.test('should return the last chunk as remaining elements', function(assert) {
2213 var actual = _.chunk(array, 4);
2214 assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
2217 QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
2220 var values = falsey.concat(-1, -Infinity),
2221 expected = lodashStable.map(values, alwaysEmptyArray);
2223 var actual = lodashStable.map(values, function(value, index) {
2224 return index ? _.chunk(array, value) : _.chunk(array);
2227 assert.deepEqual(actual, expected);
2230 QUnit.test('should coerce `size` to an integer', function(assert) {
2233 assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
2237 /*--------------------------------------------------------------------------*/
2239 QUnit.module('lodash.clamp');
2242 QUnit.test('should work with a `max` argument', function(assert) {
2245 assert.strictEqual(_.clamp(5, 3), 3);
2246 assert.strictEqual(_.clamp(1, 3), 1);
2249 QUnit.test('should clamp negative numbers', function(assert) {
2252 assert.strictEqual(_.clamp(-10, -5, 5), -5);
2253 assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
2254 assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
2257 QUnit.test('should clamp positive numbers', function(assert) {
2260 assert.strictEqual(_.clamp(10, -5, 5), 5);
2261 assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
2262 assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
2265 QUnit.test('should not alter negative numbers in range', function(assert) {
2268 assert.strictEqual(_.clamp(-4, -5, 5), -4);
2269 assert.strictEqual(_.clamp(-5, -5, 5), -5);
2270 assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
2273 QUnit.test('should not alter positive numbers in range', function(assert) {
2276 assert.strictEqual(_.clamp(4, -5, 5), 4);
2277 assert.strictEqual(_.clamp(5, -5, 5), 5);
2278 assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
2281 QUnit.test('should not alter `0` in range', function(assert) {
2284 assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
2287 QUnit.test('should clamp to `0`', function(assert) {
2290 assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
2293 QUnit.test('should not alter `-0` in range', function(assert) {
2296 assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
2299 QUnit.test('should clamp to `-0`', function(assert) {
2302 assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
2305 QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
2308 assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
2311 QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
2314 assert.deepEqual(_.clamp(1, -5, NaN), 0);
2315 assert.deepEqual(_.clamp(-1, NaN, 5), 0);
2319 /*--------------------------------------------------------------------------*/
2321 QUnit.module('clone methods');
2324 function Foo() { this.a = 1; }
2325 Foo.prototype.b = 1;
2326 Foo.c = function() {};
2339 '`arguments` objects': arguments,
2340 'arrays': ['a', ''],
2341 'array-like-objects': { '0': 'a', '1': '', 'length': 3 },
2343 'boolean objects': Object(false),
2344 'date objects': new Date,
2345 'Foo instances': new Foo,
2346 'objects': { 'a': 0, 'b': 1, 'c': 2 },
2347 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
2348 'objects from another document': realm.object || {},
2350 'null values': null,
2352 'number objects': Object(0),
2356 'string objects': Object('a'),
2357 'undefined values': undefined
2360 objects['arrays'].length = 3;
2363 'DOM elements': body,
2365 'generators': generator
2368 lodashStable.each(errors, function(error) {
2369 uncloneable[error.name + 's'] = error;
2372 QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
2375 var array = [{ 'a': 0 }, { 'b': 1 }],
2376 actual = _.clone(array);
2378 assert.deepEqual(actual, array);
2379 assert.ok(actual !== array && actual[0] === array[0]);
2382 QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
2386 'foo': { 'b': { 'c': { 'd': {} } } },
2390 object.foo.b.c.d = object;
2391 object.bar.b = object.foo.b;
2393 var actual = _.cloneDeep(object);
2394 assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
2397 QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
2401 lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
2402 cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
2405 var clone = _.cloneDeep(cyclical),
2406 actual = clone['v' + LARGE_ARRAY_SIZE][0];
2408 assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
2409 assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
2412 QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
2416 keys = [true, false, 1, -Infinity, NaN, {}, null, 'a', symbol || {}, undefined];
2418 var pairs = lodashStable.map(keys, function(key, index) {
2419 var lastIndex = keys.length - 1;
2420 return [key, keys[lastIndex - index]];
2423 _.cloneDeepWith({ 'a': 1 }, function() {
2424 if (arguments.length > 1) {
2425 Stack || (Stack = _.last(arguments).constructor);
2429 var stacks = [new Stack(pairs), new Stack(pairs)];
2431 lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
2432 stacks[1].set({}, {});
2435 lodashStable.each(stacks, function(stack) {
2436 lodashStable.each(keys, function(key, index) {
2437 var value = pairs[index][1];
2439 assert.deepEqual(stack.get(key), value);
2440 assert.strictEqual(stack.has(key), true);
2441 assert.strictEqual(stack['delete'](key), true);
2442 assert.strictEqual(stack.has(key), false);
2443 assert.strictEqual(stack.get(key), undefined);
2444 assert.strictEqual(stack['delete'](key), false);
2445 assert.strictEqual(stack.set(key, value), stack);
2446 assert.strictEqual(stack.has(key), true);
2449 assert.strictEqual(stack.clear(), undefined);
2450 assert.ok(lodashStable.every(keys, function(key) {
2451 return !stack.has(key);
2456 lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
2457 var func = _[methodName],
2458 isDeep = methodName == 'cloneDeep';
2460 lodashStable.forOwn(objects, function(object, key) {
2461 QUnit.test('`_.' + methodName + '` should clone ' + key, function(assert) {
2464 var isEqual = (key == 'maps' || key == 'sets') ? _.isEqual : lodashStable.isEqual,
2465 actual = func(object);
2467 assert.ok(isEqual(actual, object));
2469 if (lodashStable.isObject(object)) {
2470 assert.notStrictEqual(actual, object);
2472 assert.strictEqual(actual, object);
2477 QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
2481 var buffer = new ArrayBuffer(10),
2482 actual = func(buffer);
2484 assert.strictEqual(actual.byteLength, buffer.byteLength);
2485 assert.notStrictEqual(actual, buffer);
2488 skipTest(assert, 2);
2492 QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
2495 var array = /x/.exec('vwxyz'),
2496 actual = func(array);
2498 assert.strictEqual(actual.index, 2);
2499 assert.strictEqual(actual.input, 'vwxyz');
2502 QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
2505 // Avoid a regexp literal for older Opera and use `exec` for older Safari.
2506 var regexp = RegExp('x', 'g');
2507 regexp.exec('vwxyz');
2509 var actual = func(regexp);
2510 assert.strictEqual(actual.lastIndex, 3);
2513 QUnit.test('`_.' + methodName + '` should create clone with the same `[[Prototype]]` as `value`', function(assert) {
2516 assert.ok(func(new Foo) instanceof Foo);
2519 QUnit.test('should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
2522 Foo.prototype.constructor = null;
2523 assert.notOk(func(new Foo) instanceof Foo);
2524 Foo.prototype.constructor = Foo;
2527 QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
2531 'constructor': objectProto.constructor,
2532 'hasOwnProperty': objectProto.hasOwnProperty,
2533 'isPrototypeOf': objectProto.isPrototypeOf,
2534 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
2535 'toLocaleString': objectProto.toLocaleString,
2536 'toString': objectProto.toString,
2537 'valueOf': objectProto.valueOf
2540 var actual = func(object);
2542 assert.deepEqual(actual, object);
2543 assert.notStrictEqual(actual, object);
2546 QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
2551 object[symbol] = {};
2552 assert.strictEqual(func(object)[symbol], object[symbol]);
2555 object = { 'a': { 'b': {} } };
2556 object.a.b[symbol] = {};
2557 assert.strictEqual(func(object).a.b[symbol], object.a.b[symbol]);
2564 skipTest(assert, 2);
2568 QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
2572 assert.strictEqual(func(symbol), symbol);
2574 var object = Object(symbol),
2575 actual = func(object);
2577 assert.strictEqual(typeof actual, 'object');
2578 assert.strictEqual(typeof actual.valueOf(), 'symbol');
2579 assert.notStrictEqual(actual, object);
2582 skipTest(assert, 4);
2586 QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
2590 assert.strictEqual(func(symbol), symbol);
2597 QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
2601 var element = document.createElement('div');
2604 assert.deepEqual(func(element), {});
2606 assert.ok(false, e.message);
2614 QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
2617 var expected = [{ 'a': [0] }, { 'b': [1] }],
2618 actual = lodashStable.map(expected, func);
2620 assert.deepEqual(actual, expected);
2623 assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
2625 assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
2629 QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
2634 var objects = lodashStable.transform(_, function(result, value, key) {
2635 if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) && !lodashStable.isArguments(value) && !lodashStable.isElement(value) && !lodashStable.isFunction(value)) {
2636 props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
2641 var expected = lodashStable.map(objects, alwaysTrue);
2643 var actual = lodashStable.map(objects, function(object) {
2644 var Ctor = object.constructor,
2645 result = func(object);
2647 return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
2650 assert.deepEqual(actual, expected, props.join(', '));
2653 QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
2657 var object = objects['objects'],
2658 actual = _(object)[methodName]();
2660 assert.deepEqual(actual, object);
2661 assert.notStrictEqual(actual, object);
2664 skipTest(assert, 2);
2668 lodashStable.each(typedArrays, function(type) {
2669 QUnit.test('`_.' + methodName + '` should clone ' + type + ' arrays', function(assert) {
2672 var Ctor = root[type];
2674 lodashStable.times(2, function(index) {
2676 var buffer = new ArrayBuffer(24),
2677 array = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
2678 actual = func(array);
2680 assert.deepEqual(actual, array);
2681 assert.notStrictEqual(actual, array);
2682 assert.strictEqual(actual.buffer === array.buffer, !isDeep);
2683 assert.strictEqual(actual.byteOffset, array.byteOffset);
2684 assert.strictEqual(actual.length, array.length);
2687 skipTest(assert, 5);
2693 lodashStable.forOwn(uncloneable, function(value, key) {
2694 QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
2698 var object = { 'a': value, 'b': { 'c': value } },
2699 actual = func(object),
2700 expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
2702 assert.deepEqual(actual, object);
2703 assert.notStrictEqual(actual, object);
2704 assert.deepEqual(func(value), expected);
2707 skipTest(assert, 3);
2713 lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
2714 var func = _[methodName],
2715 isDeep = methodName == 'cloneDeepWith';
2717 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
2723 func(foo, function() {
2724 var length = arguments.length,
2725 args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
2727 argsList.push(args);
2730 assert.deepEqual(argsList, isDeep ? [[foo], [1, 'a', foo]] : [[foo]]);
2733 QUnit.test('`_.' + methodName + '` should handle cloning if `customizer` returns `undefined`', function(assert) {
2736 var actual = func({ 'a': { 'b': 'c' } }, noop);
2737 assert.deepEqual(actual, { 'a': { 'b': 'c' } });
2740 lodashStable.forOwn(uncloneable, function(value, key) {
2741 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
2744 var customizer = function(value) {
2745 return lodashStable.isPlainObject(value) ? undefined : value;
2748 var actual = func(value, customizer);
2750 assert.deepEqual(actual, value);
2751 assert.strictEqual(actual, value);
2753 var object = { 'a': value, 'b': { 'c': value } };
2754 actual = func(object, customizer);
2756 assert.deepEqual(actual, object);
2757 assert.notStrictEqual(actual, object);
2763 /*--------------------------------------------------------------------------*/
2765 QUnit.module('lodash.compact');
2768 QUnit.test('should filter falsey values', function(assert) {
2771 var array = ['0', '1', '2'];
2772 assert.deepEqual(_.compact(falsey.concat(array)), array);
2775 QUnit.test('should work when in-between lazy operators', function(assert) {
2779 var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
2780 assert.deepEqual(actual, []);
2782 actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
2783 assert.deepEqual(actual, [true, 1, 'a']);
2786 skipTest(assert, 2);
2790 QUnit.test('should work in a lazy sequence', function(assert) {
2794 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
2795 actual = _(array).slice(1).compact().reverse().take().value();
2797 assert.deepEqual(actual, _.take(_.compact(_.slice(array, 1)).reverse()));
2805 /*--------------------------------------------------------------------------*/
2807 QUnit.module('lodash.concat');
2810 QUnit.test('should concat arrays and values', function(assert) {
2814 actual = _.concat(array, 2, [3], [[4]]);
2816 assert.deepEqual(actual, [1, 2, 3, [4]]);
2817 assert.deepEqual(array, [1]);
2820 QUnit.test('should treat sparse arrays as dense', function(assert) {
2824 actual = _.concat(Array(1), Array(1));
2826 expected.push(undefined, undefined);
2828 assert.ok('0'in actual);
2829 assert.ok('1' in actual);
2830 assert.deepEqual(actual, expected);
2833 QUnit.test('should return a new wrapped array', function(assert) {
2838 wrapped = _(array).concat([2, 3]),
2839 actual = wrapped.value();
2841 assert.deepEqual(array, [1]);
2842 assert.deepEqual(actual, [1, 2, 3]);
2845 skipTest(assert, 2);
2850 /*--------------------------------------------------------------------------*/
2852 QUnit.module('lodash.cond');
2855 QUnit.test('should create a conditional function', function(assert) {
2859 [lodashStable.matches({ 'a': 1 }), alwaysA],
2860 [lodashStable.matchesProperty('b', 1), alwaysB],
2861 [lodashStable.property('c'), alwaysC]
2864 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
2865 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
2866 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
2869 QUnit.test('should provide arguments to functions', function(assert) {
2874 expected = ['a', 'b', 'c'];
2876 var cond = _.cond([[
2877 function() { args1 || (args1 = slice.call(arguments)); return true; },
2878 function() { args2 || (args2 = slice.call(arguments)); }
2881 cond('a', 'b', 'c');
2883 assert.deepEqual(args1, expected);
2884 assert.deepEqual(args2, expected);
2887 QUnit.test('should work with predicate shorthands', function(assert) {
2891 [{ 'a': 1 }, alwaysA],
2892 [['b', 1], alwaysB],
2896 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
2897 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
2898 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
2901 QUnit.test('should return `undefined` when no condition is met', function(assert) {
2904 var cond = _.cond([[alwaysFalse, alwaysA]]);
2905 assert.strictEqual(cond({ 'a': 1 }), undefined);
2908 QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
2911 lodashStable.each([true, false], function(value) {
2912 assert.raises(function() { _.cond([[alwaysTrue, value]])(); }, TypeError);
2916 QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
2920 [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
2923 var object = { 'cond': cond, 'a': 1, 'b': 2 };
2924 assert.strictEqual(object.cond('a', 'b'), 2);
2928 /*--------------------------------------------------------------------------*/
2930 QUnit.module('lodash.conforms');
2939 QUnit.test('should create a function that checks if a given object conforms to `source`', function(assert) {
2942 var conforms = _.conforms({
2943 'b': function(value) { return value > 4; }
2946 var actual = lodashStable.filter(objects, conforms);
2947 assert.deepEqual(actual, [objects[0], objects[2]]);
2949 conforms = _.conforms({
2950 'b': function(value) { return value > 8; },
2951 'a': function(value) { return value > 1; }
2954 actual = lodashStable.filter(objects, conforms);
2955 assert.deepEqual(actual, [objects[2]]);
2958 QUnit.test('should not match by inherited `source` properties', function(assert) {
2962 this.a = function(value) {
2967 Foo.prototype.b = function(value) {
2971 var conforms = _.conforms(new Foo),
2972 actual = lodashStable.filter(objects, conforms);
2974 assert.deepEqual(actual, [objects[1], objects[2]]);
2977 QUnit.test('should not invoke `source` predicates for missing `object` properties', function(assert) {
2982 var conforms = _.conforms({
2983 'a': function() { count++; return true; }
2986 assert.strictEqual(conforms({}), false);
2987 assert.strictEqual(count, 0);
2990 QUnit.test('should work with a function for `object`', function(assert) {
2999 var conforms = _.conforms({
3000 'a': function(value) { return value > 1; }
3003 assert.strictEqual(conforms(Foo), false);
3004 assert.strictEqual(conforms(Bar), true);
3007 QUnit.test('should work with a function for `source`', function(assert) {
3011 Foo.a = function(value) { return value > 1; };
3013 var objects = [{ 'a': 1 }, { 'a': 2 }],
3014 actual = lodashStable.filter(objects, _.conforms(Foo));
3016 assert.deepEqual(actual, [objects[1]]);
3019 QUnit.test('should work with a non-plain `object`', function(assert) {
3025 Foo.prototype.b = 2;
3027 var conforms = _.conforms({
3028 'b': function(value) { return value > 1; }
3031 assert.strictEqual(conforms(new Foo), true);
3034 QUnit.test('should return `false` when `object` is nullish', function(assert) {
3037 var values = [, null, undefined],
3038 expected = lodashStable.map(values, alwaysFalse);
3040 var conforms = _.conforms({
3041 'a': function(value) { return value > 1; }
3044 var actual = lodashStable.map(values, function(value, index) {
3046 return index ? conforms(value) : conforms();
3050 assert.deepEqual(actual, expected);
3053 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
3056 var values = [, null, undefined],
3057 expected = lodashStable.map(values, alwaysTrue),
3058 conforms = _.conforms({});
3060 var actual = lodashStable.map(values, function(value, index) {
3062 return index ? conforms(value) : conforms();
3066 assert.deepEqual(actual, expected);
3069 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
3072 var object = { 'a': 1 },
3073 expected = lodashStable.map(empties, alwaysTrue);
3075 var actual = lodashStable.map(empties, function(value) {
3076 var conforms = _.conforms(value);
3077 return conforms(object);
3080 assert.deepEqual(actual, expected);
3083 QUnit.test('should not change behavior if `source` is modified', function(assert) {
3087 'a': function(value) { return value > 1; }
3090 var object = { 'a': 2 },
3091 conforms = _.conforms(source);
3093 assert.strictEqual(conforms(object), true);
3095 source.a = function(value) { return value < 2; };
3096 assert.strictEqual(conforms(object), true);
3100 /*--------------------------------------------------------------------------*/
3102 QUnit.module('lodash.constant');
3105 QUnit.test('should create a function that returns `value`', function(assert) {
3108 var object = { 'a': 1 },
3109 values = Array(2).concat(empties, true, 1, 'a'),
3110 constant = _.constant(object),
3111 expected = lodashStable.map(values, function() { return true; });
3113 var actual = lodashStable.map(values, function(value, index) {
3115 var result = constant();
3116 } else if (index == 1) {
3117 result = constant.call({});
3119 result = constant(value);
3121 return result === object;
3124 assert.deepEqual(actual, expected);
3127 QUnit.test('should work with falsey values', function(assert) {
3130 var expected = lodashStable.map(falsey, function() { return true; });
3132 var actual = lodashStable.map(falsey, function(value, index) {
3133 var constant = index ? _.constant(value) : _.constant(),
3134 result = constant();
3136 return (result === value) || (result !== result && value !== value);
3139 assert.deepEqual(actual, expected);
3142 QUnit.test('should return a wrapped value when chaining', function(assert) {
3146 var wrapped = _(true).constant();
3147 assert.ok(wrapped instanceof _);
3155 /*--------------------------------------------------------------------------*/
3157 QUnit.module('lodash.countBy');
3160 var array = [4.2, 6.1, 6.4];
3162 QUnit.test('should work with an iteratee', function(assert) {
3165 var actual = _.countBy(array, function(num) {
3166 return Math.floor(num);
3169 assert.deepEqual(actual, { '4': 1, '6': 2 });
3172 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
3175 var array = [4, 6, 6],
3176 values = [, null, undefined],
3177 expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
3179 var actual = lodashStable.map(values, function(value, index) {
3180 return index ? _.countBy(array, value) : _.countBy(array);
3183 assert.deepEqual(actual, expected);
3186 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
3189 var actual = _.countBy(['one', 'two', 'three'], 'length');
3190 assert.deepEqual(actual, { '3': 2, '5': 1 });
3193 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
3196 var actual = _.countBy([4.2, 6.1, 6.4], function(num) {
3197 return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor';
3200 assert.deepEqual(actual.constructor, 1);
3201 assert.deepEqual(actual.hasOwnProperty, 2);
3204 QUnit.test('should work with a number for `iteratee`', function(assert) {
3213 assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
3214 assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
3217 QUnit.test('should work with an object for `collection`', function(assert) {
3220 var actual = _.countBy({ 'a': 4.2, 'b': 6.1, 'c': 6.4 }, function(num) {
3221 return Math.floor(num);
3224 assert.deepEqual(actual, { '4': 1, '6': 2 });
3227 QUnit.test('should work in a lazy sequence', function(assert) {
3231 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
3232 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
3233 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
3236 var actual = _(array).countBy().map(square).filter(isEven).take().value();
3238 assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
3246 /*--------------------------------------------------------------------------*/
3248 QUnit.module('lodash.create');
3260 QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
3263 Circle.prototype = _.create(Shape.prototype);
3264 Circle.prototype.constructor = Circle;
3266 var actual = new Circle;
3268 assert.ok(actual instanceof Circle);
3269 assert.ok(actual instanceof Shape);
3270 assert.notStrictEqual(Circle.prototype, Shape.prototype);
3273 QUnit.test('should assign `properties` to the created object', function(assert) {
3276 var expected = { 'constructor': Circle, 'radius': 0 };
3277 Circle.prototype = _.create(Shape.prototype, expected);
3279 var actual = new Circle;
3281 assert.ok(actual instanceof Circle);
3282 assert.ok(actual instanceof Shape);
3283 assert.deepEqual(Circle.prototype, expected);
3286 QUnit.test('should assign own properties', function(assert) {
3293 Foo.prototype.b = 2;
3295 assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
3298 QUnit.test('should accept a falsey `prototype` argument', function(assert) {
3301 var expected = lodashStable.map(falsey, alwaysEmptyObject);
3303 var actual = lodashStable.map(falsey, function(prototype, index) {
3304 return index ? _.create(prototype) : _.create();
3307 assert.deepEqual(actual, expected);
3310 QUnit.test('should ignore primitive `prototype` arguments and use an empty object instead', function(assert) {
3313 var primitives = [true, null, 1, 'a', undefined],
3314 expected = lodashStable.map(primitives, alwaysTrue);
3316 var actual = lodashStable.map(primitives, function(value, index) {
3317 return lodashStable.isPlainObject(index ? _.create(value) : _.create());
3320 assert.deepEqual(actual, expected);
3323 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
3326 var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
3327 expected = lodashStable.map(array, alwaysTrue),
3328 objects = lodashStable.map(array, _.create);
3330 var actual = lodashStable.map(objects, function(object) {
3331 return object.a === 1 && !_.keys(object).length;
3334 assert.deepEqual(actual, expected);
3338 /*--------------------------------------------------------------------------*/
3340 QUnit.module('lodash.curry');
3343 function fn(a, b, c, d) {
3344 return slice.call(arguments);
3347 QUnit.test('should curry based on the number of arguments provided', function(assert) {
3350 var curried = _.curry(fn),
3351 expected = [1, 2, 3, 4];
3353 assert.deepEqual(curried(1)(2)(3)(4), expected);
3354 assert.deepEqual(curried(1, 2)(3, 4), expected);
3355 assert.deepEqual(curried(1, 2, 3, 4), expected);
3358 QUnit.test('should allow specifying `arity`', function(assert) {
3361 var curried = _.curry(fn, 3),
3362 expected = [1, 2, 3];
3364 assert.deepEqual(curried(1)(2, 3), expected);
3365 assert.deepEqual(curried(1, 2)(3), expected);
3366 assert.deepEqual(curried(1, 2, 3), expected);
3369 QUnit.test('should coerce `arity` to an integer', function(assert) {
3372 var values = ['0', 0.6, 'xyz'],
3373 expected = lodashStable.map(values, alwaysEmptyArray);
3375 var actual = lodashStable.map(values, function(arity) {
3376 return _.curry(fn, arity)();
3379 assert.deepEqual(actual, expected);
3380 assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
3383 QUnit.test('should support placeholders', function(assert) {
3386 var curried = _.curry(fn),
3387 ph = curried.placeholder;
3389 assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
3390 assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
3391 assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
3392 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
3395 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3398 var curried = _.curry(fn, 3);
3399 assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
3400 assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
3401 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3404 QUnit.test('should return a function with a `length` of `0`', function(assert) {
3407 lodashStable.times(2, function(index) {
3408 var curried = index ? _.curry(fn, 4) : _.curry(fn);
3409 assert.strictEqual(curried.length, 0);
3410 assert.strictEqual(curried(1).length, 0);
3411 assert.strictEqual(curried(1, 2).length, 0);
3415 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3418 var Foo = function(value) {
3419 return value && object;
3422 var curried = _.curry(Foo),
3425 assert.ok(new curried(false) instanceof Foo);
3426 assert.strictEqual(new curried(true), object);
3429 QUnit.test('should not set a `this` binding', function(assert) {
3432 var fn = function(a, b, c) {
3433 var value = this || {};
3434 return [value[a], value[b], value[c]];
3437 var object = { 'a': 1, 'b': 2, 'c': 3 },
3438 expected = [1, 2, 3];
3440 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
3441 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
3442 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3444 assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
3445 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
3446 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
3448 object.curried = _.curry(fn);
3449 assert.deepEqual(object.curried('a')('b')('c'), Array(3));
3450 assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
3451 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3454 QUnit.test('should work with partialed methods', function(assert) {
3457 var curried = _.curry(fn),
3458 expected = [1, 2, 3, 4];
3460 var a = _.partial(curried, 1),
3461 b = _.bind(a, null, 2),
3462 c = _.partialRight(b, 4),
3463 d = _.partialRight(b(3), 4);
3465 assert.deepEqual(c(3), expected);
3466 assert.deepEqual(d(), expected);
3470 /*--------------------------------------------------------------------------*/
3472 QUnit.module('lodash.curryRight');
3475 function fn(a, b, c, d) {
3476 return slice.call(arguments);
3479 QUnit.test('should curry based on the number of arguments provided', function(assert) {
3482 var curried = _.curryRight(fn),
3483 expected = [1, 2, 3, 4];
3485 assert.deepEqual(curried(4)(3)(2)(1), expected);
3486 assert.deepEqual(curried(3, 4)(1, 2), expected);
3487 assert.deepEqual(curried(1, 2, 3, 4), expected);
3490 QUnit.test('should allow specifying `arity`', function(assert) {
3493 var curried = _.curryRight(fn, 3),
3494 expected = [1, 2, 3];
3496 assert.deepEqual(curried(3)(1, 2), expected);
3497 assert.deepEqual(curried(2, 3)(1), expected);
3498 assert.deepEqual(curried(1, 2, 3), expected);
3501 QUnit.test('should coerce `arity` to an integer', function(assert) {
3504 var values = ['0', 0.6, 'xyz'],
3505 expected = lodashStable.map(values, alwaysEmptyArray);
3507 var actual = lodashStable.map(values, function(arity) {
3508 return _.curryRight(fn, arity)();
3511 assert.deepEqual(actual, expected);
3512 assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
3515 QUnit.test('should support placeholders', function(assert) {
3518 var curried = _.curryRight(fn),
3519 expected = [1, 2, 3, 4],
3520 ph = curried.placeholder;
3522 assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
3523 assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
3524 assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
3525 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
3528 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3531 var curried = _.curryRight(fn, 3);
3532 assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
3533 assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
3534 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3537 QUnit.test('should return a function with a `length` of `0`', function(assert) {
3540 lodashStable.times(2, function(index) {
3541 var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
3542 assert.strictEqual(curried.length, 0);
3543 assert.strictEqual(curried(4).length, 0);
3544 assert.strictEqual(curried(3, 4).length, 0);
3548 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3551 var Foo = function(value) {
3552 return value && object;
3555 var curried = _.curryRight(Foo),
3558 assert.ok(new curried(false) instanceof Foo);
3559 assert.strictEqual(new curried(true), object);
3562 QUnit.test('should not set a `this` binding', function(assert) {
3565 var fn = function(a, b, c) {
3566 var value = this || {};
3567 return [value[a], value[b], value[c]];
3570 var object = { 'a': 1, 'b': 2, 'c': 3 },
3571 expected = [1, 2, 3];
3573 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
3574 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
3575 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3577 assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
3578 assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
3579 assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
3581 object.curried = _.curryRight(fn);
3582 assert.deepEqual(object.curried('c')('b')('a'), Array(3));
3583 assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
3584 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3587 QUnit.test('should work with partialed methods', function(assert) {
3590 var curried = _.curryRight(fn),
3591 expected = [1, 2, 3, 4];
3593 var a = _.partialRight(curried, 4),
3594 b = _.partialRight(a, 3),
3595 c = _.bind(b, null, 1),
3596 d = _.partial(b(2), 1);
3598 assert.deepEqual(c(2), expected);
3599 assert.deepEqual(d(), expected);
3603 /*--------------------------------------------------------------------------*/
3605 QUnit.module('curry methods');
3607 lodashStable.each(['curry', 'curryRight'], function(methodName) {
3608 var func = _[methodName],
3609 fn = function(a, b) { return slice.call(arguments); },
3610 isCurry = methodName == 'curry';
3612 QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
3615 function run(a, b) {
3619 var curried = func(run);
3622 var actual = curried(1)(2);
3625 assert.strictEqual(actual, 3);
3628 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
3631 var array = [fn, fn, fn],
3632 object = { 'a': fn, 'b': fn, 'c': fn };
3634 lodashStable.each([array, object], function(collection) {
3635 var curries = lodashStable.map(collection, func),
3636 expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
3638 var actual = lodashStable.map(curries, function(curried) {
3639 return curried('a')('b');
3642 assert.deepEqual(actual, expected);
3647 /*--------------------------------------------------------------------------*/
3649 QUnit.module('lodash.debounce');
3652 QUnit.test('should debounce a function', function(assert) {
3655 var done = assert.async();
3658 debounced = _.debounce(function() { callCount++; }, 32);
3664 assert.strictEqual(callCount, 0);
3666 setTimeout(function() {
3667 assert.strictEqual(callCount, 1);
3672 QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
3675 var done = assert.async();
3677 var debounced = _.debounce(identity, 32);
3680 setTimeout(function() {
3681 assert.notEqual(debounced('y'), 'y');
3684 setTimeout(function() {
3685 assert.notEqual(debounced('z'), 'z');
3690 QUnit.test('subsequent "immediate" debounced calls return the last `func` result', function(assert) {
3693 var done = assert.async();
3695 var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
3696 result = [debounced('x'), debounced('y')];
3698 assert.deepEqual(result, ['x', 'x']);
3700 setTimeout(function() {
3701 var result = [debounced('a'), debounced('b')];
3702 assert.deepEqual(result, ['a', 'a']);
3707 QUnit.test('should apply default options', function(assert) {
3710 var done = assert.async();
3714 var debounced = _.debounce(function(value) {
3719 assert.strictEqual(debounced('a'), undefined);
3721 setTimeout(function() {
3722 assert.strictEqual(callCount, 1);
3727 QUnit.test('should support a `leading` option', function(assert) {
3730 var done = assert.async();
3732 var callCounts = [0, 0];
3734 var withLeading = _.debounce(function(value) {
3737 }, 32, { 'leading': true });
3739 assert.strictEqual(withLeading('a'), 'a');
3741 var withoutLeading = _.debounce(identity, 32, { 'leading': false });
3742 assert.strictEqual(withoutLeading('a'), undefined);
3744 var withLeadingAndTrailing = _.debounce(function() {
3746 }, 32, { 'leading': true });
3748 withLeadingAndTrailing();
3749 withLeadingAndTrailing();
3751 assert.strictEqual(callCounts[1], 1);
3753 setTimeout(function() {
3754 assert.deepEqual(callCounts, [1, 2]);
3757 assert.strictEqual(callCounts[0], 2);
3763 QUnit.test('should support a `trailing` option', function(assert) {
3766 var done = assert.async();
3771 var withTrailing = _.debounce(function(value) {
3774 }, 32, { 'trailing': true });
3776 var withoutTrailing = _.debounce(function(value) {
3779 }, 32, { 'trailing': false });
3781 assert.strictEqual(withTrailing('a'), undefined);
3782 assert.strictEqual(withoutTrailing('a'), undefined);
3784 setTimeout(function() {
3785 assert.strictEqual(withCount, 1);
3786 assert.strictEqual(withoutCount, 0);
3791 QUnit.test('should support a `maxWait` option', function(assert) {
3794 var done = assert.async();
3796 var limit = (argv || isPhantom) ? 1000 : 320,
3800 var withMaxWait = _.debounce(function() {
3802 }, 64, { 'maxWait': 128 });
3804 var withoutMaxWait = _.debounce(function() {
3808 var start = +new Date;
3809 while ((new Date - start) < limit) {
3813 var actual = [Boolean(withCount), Boolean(withoutCount)];
3815 setTimeout(function() {
3816 assert.deepEqual(actual, [true, false]);
3821 QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
3824 var done = assert.async();
3828 var debounced = _.debounce(function() {
3830 }, 32, { 'maxWait': 64 });
3834 setTimeout(function() {
3835 assert.strictEqual(callCount, 1);
3840 QUnit.test('should invoke the `trailing` call with the correct arguments and `this` binding', function(assert) {
3843 var done = assert.async();
3849 var debounced = _.debounce(function(value) {
3851 push.apply(actual, arguments);
3852 return ++callCount != 2;
3853 }, 32, { 'leading': true, 'maxWait': 64 });
3856 if (!debounced.call(object, 'a')) {
3860 setTimeout(function() {
3861 assert.strictEqual(callCount, 2);
3862 assert.deepEqual(actual, [object, 'a']);
3868 /*--------------------------------------------------------------------------*/
3870 QUnit.module('lodash.deburr');
3873 QUnit.test('should convert latin-1 supplementary letters to basic latin', function(assert) {
3876 var actual = lodashStable.map(burredLetters, _.deburr);
3877 assert.deepEqual(actual, deburredLetters);
3880 QUnit.test('should not deburr latin-1 mathematical operators', function(assert) {
3883 var operators = ['\xd7', '\xf7'],
3884 actual = lodashStable.map(operators, _.deburr);
3886 assert.deepEqual(actual, operators);
3889 QUnit.test('should deburr combining diacritical marks', function(assert) {
3892 var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
3894 var actual = lodashStable.map(comboMarks, function(chr) {
3895 return _.deburr('e' + chr + 'i');
3898 assert.deepEqual(actual, expected);
3902 /*--------------------------------------------------------------------------*/
3904 QUnit.module('lodash.defaults');
3907 QUnit.test('should assign source properties if missing on `object`', function(assert) {
3910 assert.deepEqual(_.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 }), { 'a': 1, 'b': 2 });
3913 QUnit.test('should accept multiple sources', function(assert) {
3916 var expected = { 'a': 1, 'b': 2, 'c': 3 };
3917 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 }), expected);
3918 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 }), expected);
3921 QUnit.test('should not overwrite `null` values', function(assert) {
3924 var actual = _.defaults({ 'a': null }, { 'a': 1 });
3925 assert.strictEqual(actual.a, null);
3928 QUnit.test('should overwrite `undefined` values', function(assert) {
3931 var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
3932 assert.strictEqual(actual.a, 1);
3935 QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
3939 'constructor': objectProto.constructor,
3940 'hasOwnProperty': objectProto.hasOwnProperty,
3941 'isPrototypeOf': objectProto.isPrototypeOf,
3942 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
3943 'toLocaleString': objectProto.toLocaleString,
3944 'toString': objectProto.toString,
3945 'valueOf': objectProto.valueOf
3950 'hasOwnProperty': 2,
3952 'propertyIsEnumerable': 4,
3953 'toLocaleString': 5,
3958 assert.deepEqual(_.defaults({}, source), source);
3959 assert.deepEqual(_.defaults({}, object, source), object);
3963 /*--------------------------------------------------------------------------*/
3965 QUnit.module('lodash.defaultsDeep');
3968 QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
3971 var object = { 'a': { 'b': 2 }, 'd': 4 },
3972 source = { 'a': { 'b': 1, 'c': 3 }, 'e': 5 },
3973 expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
3975 assert.deepEqual(_.defaultsDeep(object, source), expected);
3978 QUnit.test('should accept multiple sources', function(assert) {
3981 var source1 = { 'a': { 'b': 3 } },
3982 source2 = { 'a': { 'c': 3 } },
3983 source3 = { 'a': { 'b': 3, 'c': 3 } },
3984 source4 = { 'a': { 'c': 4 } },
3985 expected = { 'a': { 'b': 2, 'c': 3 } };
3987 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
3988 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
3991 QUnit.test('should not overwrite `null` values', function(assert) {
3994 var object = { 'a': { 'b': null } },
3995 source = { 'a': { 'b': 2 } },
3996 actual = _.defaultsDeep(object, source);
3998 assert.strictEqual(actual.a.b, null);
4001 QUnit.test('should overwrite `undefined` values', function(assert) {
4004 var object = { 'a': { 'b': undefined } },
4005 source = { 'a': { 'b': 2 } },
4006 actual = _.defaultsDeep(object, source);
4008 assert.strictEqual(actual.a.b, 2);
4011 QUnit.test('should merge sources containing circular references', function(assert) {
4015 'foo': { 'b': { 'c': { 'd': {} } } },
4020 'foo': { 'b': { 'c': { 'd': {} } } },
4024 object.foo.b.c.d = object;
4025 source.foo.b.c.d = source;
4026 source.bar.b = source.foo.b;
4028 var actual = _.defaultsDeep(object, source);
4029 assert.ok(actual.bar.b === actual.foo.b && actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
4032 QUnit.test('should not modify sources', function(assert) {
4035 var source1 = { 'a': 1, 'b': { 'c': 2 } },
4036 source2 = { 'b': { 'c': 3, 'd': 3 } },
4037 actual = _.defaultsDeep({}, source1, source2);
4039 assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
4040 assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
4041 assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
4044 QUnit.test('should not attempt a merge of a string into an array', function(assert) {
4047 var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
4048 assert.deepEqual(actual, { 'a': ['abc'] });
4052 /*--------------------------------------------------------------------------*/
4054 QUnit.module('lodash.defer');
4057 QUnit.test('should defer `func` execution', function(assert) {
4060 var done = assert.async();
4063 _.defer(function() { pass = true; });
4065 setTimeout(function() {
4071 QUnit.test('should provide additional arguments to `func`', function(assert) {
4074 var done = assert.async();
4078 _.defer(function() {
4079 args = slice.call(arguments);
4082 setTimeout(function() {
4083 assert.deepEqual(args, [1, 2]);
4088 QUnit.test('should be cancelable', function(assert) {
4091 var done = assert.async();
4095 var timerId = _.defer(function() {
4099 clearTimeout(timerId);
4101 setTimeout(function() {
4108 /*--------------------------------------------------------------------------*/
4110 QUnit.module('lodash.delay');
4113 QUnit.test('should delay `func` execution', function(assert) {
4116 var done = assert.async();
4119 _.delay(function() { pass = true; }, 32);
4121 setTimeout(function() {
4125 setTimeout(function() {
4131 QUnit.test('should provide additional arguments to `func`', function(assert) {
4134 var done = assert.async();
4138 _.delay(function() {
4139 args = slice.call(arguments);
4142 setTimeout(function() {
4143 assert.deepEqual(args, [1, 2]);
4148 QUnit.test('should use a default `wait` of `0`', function(assert) {
4151 var done = assert.async();
4155 _.delay(function() {
4161 setTimeout(function() {
4167 QUnit.test('should be cancelable', function(assert) {
4170 var done = assert.async();
4174 var timerId = _.delay(function() {
4178 clearTimeout(timerId);
4180 setTimeout(function() {
4187 /*--------------------------------------------------------------------------*/
4189 QUnit.module('difference methods');
4191 lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
4192 var args = (function() { return arguments; }(1, 2, 3)),
4193 func = _[methodName];
4195 QUnit.test('`_.' + methodName + '` should return the difference of the given arrays', function(assert) {
4198 var actual = func([1, 2, 3, 4, 5], [5, 2, 10]);
4199 assert.deepEqual(actual, [1, 3, 4]);
4201 actual = func([1, 2, 3, 4, 5], [5, 2, 10], [8, 4]);
4202 assert.deepEqual(actual, [1, 3]);
4205 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
4208 assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
4211 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
4214 var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
4215 array2 = lodashStable.range(LARGE_ARRAY_SIZE),
4220 array1.push(a, b, c);
4221 array2.push(b, c, a);
4223 assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
4226 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
4231 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
4233 assert.deepEqual(func([object1, object2], largeArray), [object2]);
4236 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
4239 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
4240 assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
4243 QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
4246 var array = [1, null, 3];
4247 assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
4248 assert.deepEqual(func(null, array, 1), []);
4249 assert.deepEqual(func(array, args, null), [null]);
4253 /*--------------------------------------------------------------------------*/
4255 QUnit.module('lodash.differenceBy');
4258 QUnit.test('should accept an `iteratee` argument', function(assert) {
4261 var actual = _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
4262 assert.deepEqual(actual, [3.1, 1.3]);
4264 actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
4265 assert.deepEqual(actual, [{ 'x': 2 }]);
4268 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
4273 _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], function() {
4274 args || (args = slice.call(arguments));
4277 assert.deepEqual(args, [4.4]);
4281 /*--------------------------------------------------------------------------*/
4283 QUnit.module('lodash.differenceWith');
4286 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
4288 QUnit.test('should work with a `comparator` argument', function(assert) {
4291 var actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
4292 assert.deepEqual(actual, [{ 'x': 2, 'y': 1 }]);
4296 /*--------------------------------------------------------------------------*/
4298 QUnit.module('lodash.drop');
4301 var array = [1, 2, 3];
4303 QUnit.test('should drop the first two elements', function(assert) {
4306 assert.deepEqual(_.drop(array, 2), [3]);
4309 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4312 var expected = lodashStable.map(falsey, function(value) {
4313 return value === undefined ? [2, 3] : array;
4316 var actual = lodashStable.map(falsey, function(n) {
4317 return _.drop(array, n);
4320 assert.deepEqual(actual, expected);
4323 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4326 lodashStable.each([0, -1, -Infinity], function(n) {
4327 assert.deepEqual(_.drop(array, n), array);
4331 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
4334 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4335 assert.deepEqual(_.drop(array, n), []);
4339 QUnit.test('should coerce `n` to an integer', function(assert) {
4342 assert.deepEqual(_.drop(array, 1.6), [2, 3]);
4345 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4348 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4349 actual = lodashStable.map(array, _.drop);
4351 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
4354 QUnit.test('should work in a lazy sequence', function(assert) {
4358 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4359 predicate = function(value) { values.push(value); return isEven(value); },
4361 actual = _(array).drop(2).drop().value();
4363 assert.deepEqual(actual, array.slice(3));
4365 actual = _(array).filter(predicate).drop(2).drop().value();
4366 assert.deepEqual(values, array);
4367 assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
4369 actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
4370 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
4374 actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
4375 assert.deepEqual(values, array.slice(1));
4376 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
4379 skipTest(assert, 6);
4384 /*--------------------------------------------------------------------------*/
4386 QUnit.module('lodash.dropRight');
4389 var array = [1, 2, 3];
4391 QUnit.test('should drop the last two elements', function(assert) {
4394 assert.deepEqual(_.dropRight(array, 2), [1]);
4397 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4400 var expected = lodashStable.map(falsey, function(value) {
4401 return value === undefined ? [1, 2] : array;
4404 var actual = lodashStable.map(falsey, function(n) {
4405 return _.dropRight(array, n);
4408 assert.deepEqual(actual, expected);
4411 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4414 lodashStable.each([0, -1, -Infinity], function(n) {
4415 assert.deepEqual(_.dropRight(array, n), array);
4419 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
4422 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4423 assert.deepEqual(_.dropRight(array, n), []);
4427 QUnit.test('should coerce `n` to an integer', function(assert) {
4430 assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
4433 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4436 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4437 actual = lodashStable.map(array, _.dropRight);
4439 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
4442 QUnit.test('should work in a lazy sequence', function(assert) {
4446 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4447 predicate = function(value) { values.push(value); return isEven(value); },
4449 actual = _(array).dropRight(2).dropRight().value();
4451 assert.deepEqual(actual, array.slice(0, -3));
4453 actual = _(array).filter(predicate).dropRight(2).dropRight().value();
4454 assert.deepEqual(values, array);
4455 assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
4457 actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
4458 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
4462 actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
4463 assert.deepEqual(values, array.slice(0, -1));
4464 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
4467 skipTest(assert, 6);
4472 /*--------------------------------------------------------------------------*/
4474 QUnit.module('lodash.dropRightWhile');
4477 var array = [1, 2, 3, 4];
4485 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
4488 var actual = _.dropRightWhile(array, function(num) {
4492 assert.deepEqual(actual, [1, 2]);
4495 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
4500 _.dropRightWhile(array, function() {
4501 args = slice.call(arguments);
4504 assert.deepEqual(args, [4, 3, array]);
4507 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
4510 assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
4513 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
4516 assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
4519 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
4522 assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
4525 QUnit.test('should return a wrapped value when chaining', function(assert) {
4529 var wrapped = _(array).dropRightWhile(function(num) {
4533 assert.ok(wrapped instanceof _);
4534 assert.deepEqual(wrapped.value(), [1, 2]);
4537 skipTest(assert, 2);
4542 /*--------------------------------------------------------------------------*/
4544 QUnit.module('lodash.dropWhile');
4547 var array = [1, 2, 3, 4];
4555 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
4558 var actual = _.dropWhile(array, function(num) {
4562 assert.deepEqual(actual, [3, 4]);
4565 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
4570 _.dropWhile(array, function() {
4571 args = slice.call(arguments);
4574 assert.deepEqual(args, [1, 0, array]);
4577 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
4580 assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
4583 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
4586 assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
4589 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
4592 assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
4595 QUnit.test('should work in a lazy sequence', function(assert) {
4599 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
4600 predicate = function(num) { return num < 3; },
4601 expected = _.dropWhile(array, predicate),
4602 wrapped = _(array).dropWhile(predicate);
4604 assert.deepEqual(wrapped.value(), expected);
4605 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
4606 assert.strictEqual(wrapped.last(), _.last(expected));
4609 skipTest(assert, 3);
4613 QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
4617 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
4619 var actual = _(array)
4620 .dropWhile(function(num) { return num == 1; })
4622 .dropWhile(function(num) { return num == 3; })
4625 assert.deepEqual(actual, array.slice(3));
4633 /*--------------------------------------------------------------------------*/
4635 QUnit.module('lodash.endsWith');
4640 QUnit.test('should return `true` if a string ends with `target`', function(assert) {
4643 assert.strictEqual(_.endsWith(string, 'c'), true);
4646 QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
4649 assert.strictEqual(_.endsWith(string, 'b'), false);
4652 QUnit.test('should work with a `position` argument', function(assert) {
4655 assert.strictEqual(_.endsWith(string, 'b', 2), true);
4658 QUnit.test('should work with `position` >= `string.length`', function(assert) {
4661 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
4662 assert.strictEqual(_.endsWith(string, 'c', position), true);
4666 QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
4669 var expected = lodashStable.map(falsey, alwaysTrue);
4671 var actual = lodashStable.map(falsey, function(position) {
4672 return _.endsWith(string, position === undefined ? 'c' : '', position);
4675 assert.deepEqual(actual, expected);
4678 QUnit.test('should treat a negative `position` as `0`', function(assert) {
4681 lodashStable.each([-1, -3, -Infinity], function(position) {
4682 assert.ok(lodashStable.every(string, function(chr) {
4683 return _.endsWith(string, chr, position) === false;
4685 assert.strictEqual(_.endsWith(string, '', position), true);
4689 QUnit.test('should coerce `position` to an integer', function(assert) {
4692 assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
4695 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
4698 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
4699 return _.endsWith(string, '', position, true);
4704 /*--------------------------------------------------------------------------*/
4706 QUnit.module('lodash.eq');
4709 QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
4712 assert.strictEqual(_.eq(), true);
4713 assert.strictEqual(_.eq(undefined), true);
4714 assert.strictEqual(_.eq(0, -0), true);
4715 assert.strictEqual(_.eq(NaN, NaN), true);
4716 assert.strictEqual(_.eq(1, 1), true);
4718 assert.strictEqual(_.eq(null, undefined), false);
4719 assert.strictEqual(_.eq(1, Object(1)), false);
4720 assert.strictEqual(_.eq(1, '1'), false);
4721 assert.strictEqual(_.eq(1, '1'), false);
4723 var object = { 'a': 1 };
4724 assert.strictEqual(_.eq(object, object), true);
4725 assert.strictEqual(_.eq(object, { 'a': 1 }), false);
4729 /*--------------------------------------------------------------------------*/
4731 QUnit.module('lodash.escape');
4734 var escaped = '&<>"'`\/',
4735 unescaped = '&<>"\'`\/';
4738 unescaped += unescaped;
4740 QUnit.test('should escape values', function(assert) {
4743 assert.strictEqual(_.escape(unescaped), escaped);
4746 QUnit.test('should not escape the "/" character', function(assert) {
4749 assert.strictEqual(_.escape('/'), '/');
4752 QUnit.test('should handle strings with nothing to escape', function(assert) {
4755 assert.strictEqual(_.escape('abc'), 'abc');
4758 QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
4761 assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
4765 /*--------------------------------------------------------------------------*/
4767 QUnit.module('lodash.escapeRegExp');
4770 var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
4771 unescaped = '^$.*+?()[]{}|\\';
4773 QUnit.test('should escape values', function(assert) {
4776 assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
4779 QUnit.test('should handle strings with nothing to escape', function(assert) {
4782 assert.strictEqual(_.escapeRegExp('ghi'), 'ghi');
4785 QUnit.test('should return an empty string for empty values', function(assert) {
4788 var values = [, null, undefined, ''],
4789 expected = lodashStable.map(values, alwaysEmptyString);
4791 var actual = lodashStable.map(values, function(value, index) {
4792 return index ? _.escapeRegExp(value) : _.escapeRegExp();
4795 assert.deepEqual(actual, expected);
4799 /*--------------------------------------------------------------------------*/
4801 QUnit.module('lodash.every');
4804 QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
4807 assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
4810 QUnit.test('should return `true` for empty collections', function(assert) {
4813 var expected = lodashStable.map(empties, alwaysTrue);
4815 var actual = lodashStable.map(empties, function(value) {
4817 return _.every(value, identity);
4821 assert.deepEqual(actual, expected);
4824 QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
4829 assert.strictEqual(_.every([true, null, true], function(value) {
4834 assert.strictEqual(count, 2);
4837 QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
4840 assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
4843 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
4846 var values = [, null, undefined],
4847 expected = lodashStable.map(values, alwaysFalse);
4849 var actual = lodashStable.map(values, function(value, index) {
4851 return index ? _.every(array, value) : _.every(array);
4854 assert.deepEqual(actual, expected);
4856 expected = lodashStable.map(values, alwaysTrue);
4857 actual = lodashStable.map(values, function(value, index) {
4859 return index ? _.every(array, value) : _.every(array);
4862 assert.deepEqual(actual, expected);
4865 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
4868 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
4869 assert.strictEqual(_.every(objects, 'a'), false);
4870 assert.strictEqual(_.every(objects, 'b'), true);
4873 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
4876 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
4877 assert.strictEqual(_.every(objects, { 'a': 0 }), true);
4878 assert.strictEqual(_.every(objects, { 'b': 1 }), false);
4881 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4884 var actual = lodashStable.map([[1]], _.every);
4885 assert.deepEqual(actual, [true]);
4889 /*--------------------------------------------------------------------------*/
4891 QUnit.module('strict mode checks');
4893 lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults'], function(methodName) {
4894 var func = _[methodName],
4895 isBindAll = methodName == 'bindAll';
4897 QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
4901 var object = freeze({ 'a': undefined, 'b': function() {} }),
4905 func(object, isBindAll ? 'b' : { 'a': 1 });
4917 /*--------------------------------------------------------------------------*/
4919 QUnit.module('lodash.fill');
4922 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
4925 var array = [1, 2, 3];
4926 assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
4929 QUnit.test('should use `undefined` for `value` if not provided', function(assert) {
4932 var array = [1, 2, 3],
4933 actual = _.fill(array);
4935 assert.deepEqual(actual, Array(3));
4936 assert.ok(lodashStable.every(actual, function(value, index) {
4937 return index in actual;
4941 QUnit.test('should work with a positive `start`', function(assert) {
4944 var array = [1, 2, 3];
4945 assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
4948 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
4951 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
4952 var array = [1, 2, 3];
4953 assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
4957 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
4960 var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
4962 var actual = lodashStable.map(falsey, function(start) {
4963 var array = [1, 2, 3];
4964 return _.fill(array, 'a', start);
4967 assert.deepEqual(actual, expected);
4970 QUnit.test('should work with a negative `start`', function(assert) {
4973 var array = [1, 2, 3];
4974 assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
4977 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
4980 lodashStable.each([-3, -4, -Infinity], function(start) {
4981 var array = [1, 2, 3];
4982 assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
4986 QUnit.test('should work with `start` >= `end`', function(assert) {
4989 lodashStable.each([2, 3], function(start) {
4990 var array = [1, 2, 3];
4991 assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
4995 QUnit.test('should work with a positive `end`', function(assert) {
4998 var array = [1, 2, 3];
4999 assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
5002 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
5005 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
5006 var array = [1, 2, 3];
5007 assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
5011 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
5014 var expected = lodashStable.map(falsey, function(value) {
5015 return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
5018 var actual = lodashStable.map(falsey, function(end) {
5019 var array = [1, 2, 3];
5020 return _.fill(array, 'a', 0, end);
5023 assert.deepEqual(actual, expected);
5026 QUnit.test('should work with a negative `end`', function(assert) {
5029 var array = [1, 2, 3];
5030 assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
5033 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
5036 lodashStable.each([-3, -4, -Infinity], function(end) {
5037 var array = [1, 2, 3];
5038 assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
5042 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
5045 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
5047 var actual = lodashStable.map(positions, function(pos) {
5048 var array = [1, 2, 3];
5049 return _.fill.apply(_, [array, 'a'].concat(pos));
5052 assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
5055 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5058 var array = [[1, 2], [3, 4]],
5059 actual = lodashStable.map(array, _.fill);
5061 assert.deepEqual(actual, [[0, 0], [1, 1]]);
5064 QUnit.test('should return a wrapped value when chaining', function(assert) {
5068 var array = [1, 2, 3],
5069 wrapped = _(array).fill('a'),
5070 actual = wrapped.value();
5072 assert.ok(wrapped instanceof _);
5073 assert.deepEqual(actual, ['a', 'a', 'a']);
5074 assert.strictEqual(actual, array);
5077 skipTest(assert, 3);
5082 /*--------------------------------------------------------------------------*/
5084 QUnit.module('lodash.filter');
5087 var array = [1, 2, 3];
5089 QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
5092 assert.deepEqual(_.filter(array, isEven), [2]);
5095 QUnit.test('should iterate over an object with numeric keys (test in Mobile Safari 8)', function(assert) {
5098 // Trigger a Mobile Safari 8 JIT bug.
5099 // See https://github.com/lodash/lodash/issues/799.
5101 object = { '1': 'foo', '8': 'bar', '50': 'baz' };
5103 lodashStable.times(1000, function(assert) {
5104 _.filter([], alwaysTrue);
5107 _.filter(object, function() {
5112 assert.strictEqual(counter, 3);
5116 /*--------------------------------------------------------------------------*/
5118 lodashStable.each(['find', 'findLast', 'findIndex', 'findLastIndex', 'findKey', 'findLastKey'], function(methodName) {
5119 QUnit.module('lodash.' + methodName);
5121 var func = _[methodName],
5122 isFindKey = /Key$/.test(methodName);
5132 'find': [objects[1], undefined, objects[2], objects[1]],
5133 'findLast': [objects[2], undefined, objects[2], objects[2]],
5134 'findIndex': [1, -1, 2, 1],
5135 'findLastIndex': [2, -1, 2, 2],
5136 'findKey': ['1', undefined, '2', '1'],
5137 'findLastKey': ['2', undefined, '2', '2']
5140 QUnit.test('should return the found value', function(assert) {
5143 assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
5146 QUnit.test('should return `' + expected[1] + '` if value is not found', function(assert) {
5149 assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
5152 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
5155 assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
5158 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
5161 assert.strictEqual(func(objects, ['b', 2]), expected[2]);
5164 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
5167 assert.strictEqual(func(objects, 'b'), expected[3]);
5170 QUnit.test('should return `' + expected[1] + '` for empty collections', function(assert) {
5173 var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
5174 expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
5176 var actual = lodashStable.map(emptyValues, function(value) {
5178 return func(value, { 'a': 3 });
5182 assert.deepEqual(actual, expecting);
5187 var array = [1, 2, 3, 4];
5198 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
5202 assert.strictEqual(_(array)[methodName](), expected);
5209 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
5213 assert.ok(_(array).chain()[methodName]() instanceof _);
5220 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
5224 var wrapped = _(array).chain()[methodName]();
5225 assert.strictEqual(wrapped.__wrapped__, array);
5232 QUnit.test('should work in a lazy sequence', function(assert) {
5236 var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5239 lodashStable.times(2, function(index) {
5240 var array = index ? largeArray : smallArray,
5241 wrapped = _(array).filter(isEven);
5243 assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
5247 skipTest(assert, 2);
5260 if (expected != null) {
5261 QUnit.test('should work with an object for `collection`', function(assert) {
5264 var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(num) {
5268 assert.strictEqual(actual, expected);
5274 /*--------------------------------------------------------------------------*/
5276 QUnit.module('lodash.find and lodash.findLast');
5278 lodashStable.each(['find', 'findLast'], function(methodName) {
5279 var isFind = methodName == 'find';
5281 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5287 array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5288 iteratee = function(value) { mapCount++; return square(value); },
5289 predicate = function(value) { findCount++; return isEven(value); },
5290 actual = _(array).map(iteratee)[methodName](predicate);
5292 assert.strictEqual(findCount, isFind ? 2 : 1);
5293 assert.strictEqual(mapCount, isFind ? 2 : 1);
5294 assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
5297 skipTest(assert, 3);
5302 /*--------------------------------------------------------------------------*/
5304 QUnit.module('lodash.flip');
5308 return slice.call(arguments);
5311 QUnit.test('should flip arguments provided to `func`', function(assert) {
5314 var flipped = _.flip(fn);
5315 assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
5319 /*--------------------------------------------------------------------------*/
5321 QUnit.module('lodash.flatMap');
5324 var array = [1, 2, 3, 4];
5326 function duplicate(n) {
5330 QUnit.test('should map values in `array` to a new flattened array', function(assert) {
5333 var actual = _.flatMap(array, duplicate),
5334 expected = lodashStable.flatten(lodashStable.map(array, duplicate));
5336 assert.deepEqual(actual, expected);
5339 QUnit.test('should work in a lazy sequence', function(assert) {
5343 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
5346 lodashStable.times(2, function(index) {
5347 var array = index ? largeArray : smallArray,
5348 actual = _(array).filter(isEven).flatMap(duplicate).take(2).value();
5350 assert.deepEqual(actual, _.take(_.flatMap(_.filter(array, isEven), duplicate), 2));
5354 skipTest(assert, 2);
5359 /*--------------------------------------------------------------------------*/
5361 QUnit.module('flatten methods');
5364 var args = arguments;
5366 QUnit.test('should perform a shallow flatten', function(assert) {
5369 var array = [[['a']], [['b']]];
5370 assert.deepEqual(_.flatten(array), [['a'], ['b']]);
5373 QUnit.test('should flatten `arguments` objects', function(assert) {
5376 var array = [args, [args]];
5378 assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
5379 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
5382 QUnit.test('should treat sparse arrays as dense', function(assert) {
5385 var array = [[1, 2, 3], Array(3)],
5386 expected = [1, 2, 3];
5388 expected.push(undefined, undefined, undefined);
5390 lodashStable.each([_.flatten(array), _.flatten(array, true), _.flattenDeep(array)], function(actual) {
5391 assert.deepEqual(actual, expected);
5392 assert.ok('4' in actual);
5396 QUnit.test('should work with extremely large arrays', function(assert) {
5399 // Test in modern browsers only to avoid browser hangs.
5400 lodashStable.times(3, function(index) {
5402 var expected = Array(5e5);
5406 var actual = actual == 1 ? _.flatten([expected], true) : _.flattenDeep([expected]);
5408 actual = _.flatten(expected);
5410 assert.deepEqual(actual, expected);
5412 assert.ok(false, e.message);
5421 QUnit.test('should work with empty arrays', function(assert) {
5424 var array = [[], [[]], [[], [[[]]]]];
5426 assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
5427 assert.deepEqual(_.flattenDeep(array), []);
5430 QUnit.test('should support flattening of nested arrays', function(assert) {
5433 var array = [1, [2, 3], 4, [[5]]];
5435 assert.deepEqual(_.flatten(array), [1, 2, 3, 4, [5]]);
5436 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
5439 QUnit.test('should return an empty array for non array-like objects', function(assert) {
5444 assert.deepEqual(_.flatten({ 'a': 1 }), expected);
5445 assert.deepEqual(_.flatten({ 'a': 1 }, true), expected);
5446 assert.deepEqual(_.flattenDeep({ 'a': 1 }), expected);
5449 QUnit.test('should return a wrapped value when chaining', function(assert) {
5453 var wrapped = _([1, [2], [3, [4]]]),
5454 actual = wrapped.flatten();
5456 assert.ok(actual instanceof _);
5457 assert.deepEqual(actual.value(), [1, 2, 3, [4]]);
5459 actual = wrapped.flattenDeep();
5461 assert.ok(actual instanceof _);
5462 assert.deepEqual(actual.value(), [1, 2, 3, 4]);
5465 skipTest(assert, 4);
5470 /*--------------------------------------------------------------------------*/
5472 QUnit.module('flow methods');
5474 lodashStable.each(['flow', 'flowRight'], function(methodName) {
5475 var func = _[methodName],
5476 isFlow = methodName == 'flow';
5478 QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
5481 var fixed = function(n) { return n.toFixed(1); },
5482 combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
5484 assert.strictEqual(combined(1, 2), '9.0');
5487 QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
5490 assert.notStrictEqual(func(noop), noop);
5493 QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are provided', function(assert) {
5496 var combined = func();
5499 assert.strictEqual(combined('a'), 'a');
5501 assert.ok(false, e.message);
5503 assert.strictEqual(combined.length, 0);
5504 assert.notStrictEqual(combined, identity);
5507 QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
5510 var curried = _.curry(identity);
5512 var combined = isFlow
5513 ? func(_.head, curried)
5514 : func(curried, _.head);
5516 assert.strictEqual(combined([1]), 1);
5519 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5524 array = lodashStable.range(LARGE_ARRAY_SIZE),
5525 iteratee = function(value) { mapCount++; return square(value); },
5526 predicate = function(value) { filterCount++; return isEven(value); };
5528 lodashStable.times(2, function(index) {
5529 var filter1 = _.filter,
5530 filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
5531 filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
5534 map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
5535 map3 = (_.map = index ? map2 : map1, map2(iteratee));
5538 take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
5539 take3 = (_.take = index ? take2 : take1, take2(2));
5541 var combined = isFlow
5542 ? func(map3, filter3, _.compact, take3)
5543 : func(take3, _.compact, filter3, map3);
5545 filterCount = mapCount = 0;
5546 assert.deepEqual(combined(array), [4, 16]);
5548 if (!isNpm && WeakMap && WeakMap.name) {
5549 assert.strictEqual(filterCount, 5, 'filterCount');
5550 assert.strictEqual(mapCount, 5, 'mapCount');
5553 skipTest(assert, 2);
5561 QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
5564 var curried = _.curry(_.ary(_.map, 2), 2),
5565 getProp = curried(curried.placeholder, 'a'),
5566 objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
5568 var combined = isFlow
5569 ? func(getProp, _.uniq)
5570 : func(_.uniq, getProp);
5572 assert.deepEqual(combined(objects), [1, 2]);
5575 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
5579 var wrapped = _(noop)[methodName]();
5580 assert.ok(wrapped instanceof _);
5588 /*--------------------------------------------------------------------------*/
5590 QUnit.module('lodash.forEach');
5593 QUnit.test('should be aliased', function(assert) {
5596 assert.strictEqual(_.each, _.forEach);
5600 /*--------------------------------------------------------------------------*/
5602 QUnit.module('lodash.forEachRight');
5605 QUnit.test('should be aliased', function(assert) {
5608 assert.strictEqual(_.eachRight, _.forEachRight);
5612 /*--------------------------------------------------------------------------*/
5614 QUnit.module('forIn methods');
5616 lodashStable.each(['forIn', 'forInRight'], function(methodName) {
5617 var func = _[methodName];
5619 QUnit.test('`_.' + methodName + '` iterates over inherited properties', function(assert) {
5622 function Foo() { this.a = 1; }
5623 Foo.prototype.b = 2;
5626 func(new Foo, function(value, key) { keys.push(key); });
5627 assert.deepEqual(keys.sort(), ['a', 'b']);
5631 /*--------------------------------------------------------------------------*/
5633 QUnit.module('forOwn methods');
5635 lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
5636 var func = _[methodName];
5638 QUnit.test('should iterate over `length` properties', function(assert) {
5641 var object = { '0': 'zero', '1': 'one', 'length': 2 },
5644 func(object, function(value, prop) { props.push(prop); });
5645 assert.deepEqual(props.sort(), ['0', '1', 'length']);
5649 /*--------------------------------------------------------------------------*/
5651 QUnit.module('iteration methods');
5685 var arrayMethods = [
5692 var collectionMethods = [
5711 var forInMethods = [
5718 var iterationMethods = [
5728 var objectMethods = [
5741 var rightMethods = [
5750 var unwrappedMethods = [
5771 lodashStable.each(methods, function(methodName) {
5772 var array = [1, 2, 3],
5773 func = _[methodName],
5774 isBy = /(^partition|By)$/.test(methodName),
5775 isFind = /^find/.test(methodName),
5776 isSome = methodName == 'some';
5778 QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
5783 expected = [1, 0, array];
5785 func(array, function() {
5786 args || (args = slice.call(arguments));
5789 if (lodashStable.includes(rightMethods, methodName)) {
5793 if (lodashStable.includes(objectMethods, methodName)) {
5797 expected.length = 1;
5799 assert.deepEqual(args, expected);
5806 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
5813 var expected = [[1, 0, array], [undefined, 1, array], [3, 2, array]];
5816 expected = lodashStable.map(expected, function(args) {
5817 return args.slice(0, 1);
5820 else if (lodashStable.includes(objectMethods, methodName)) {
5821 expected = lodashStable.map(expected, function(args) {
5826 if (lodashStable.includes(rightMethods, methodName)) {
5830 func(array, function() {
5831 argsList.push(slice.call(arguments));
5832 return !(isFind || isSome);
5835 assert.deepEqual(argsList, expected);
5843 lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
5844 var array = [1, 2, 3],
5845 func = _[methodName],
5846 isEvery = methodName == 'every';
5850 QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
5855 func(array, function(value, key) {
5860 assert.notOk(lodashStable.includes(keys, 'a'));
5868 lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
5869 var array = [1, 2, 3],
5870 func = _[methodName],
5871 isBaseEach = methodName == '_baseEach';
5873 QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
5876 if (!(isBaseEach || isNpm)) {
5877 var wrapped = _(array)[methodName](noop);
5878 assert.ok(wrapped instanceof _);
5886 lodashStable.each(unwrappedMethods, function(methodName) {
5887 var array = [1, 2, 3],
5888 func = _[methodName];
5890 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
5894 var actual = _(array)[methodName](noop);
5895 assert.notOk(actual instanceof _);
5902 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
5906 var wrapped = _(array).chain(),
5907 actual = wrapped[methodName](noop);
5909 assert.ok(actual instanceof _);
5910 assert.notStrictEqual(actual, wrapped);
5913 skipTest(assert, 2);
5918 lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
5919 var array = [1, 2, 3],
5920 func = _[methodName];
5922 QUnit.test('`_.' + methodName + '` iterates over own properties of objects', function(assert) {
5925 function Foo() { this.a = 1; }
5926 Foo.prototype.b = 2;
5930 func(new Foo, function(value) { values.push(value); });
5931 assert.deepEqual(values, [1]);
5939 lodashStable.each(iterationMethods, function(methodName) {
5940 var array = [1, 2, 3],
5941 func = _[methodName];
5943 QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
5947 assert.strictEqual(func(array, Boolean), array);
5955 lodashStable.each(collectionMethods, function(methodName) {
5956 var func = _[methodName];
5958 QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
5962 var isIteratedAsObject = function(object) {
5964 func(object, function() { result = true; }, 0);
5968 var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
5969 expected = lodashStable.map(values, alwaysTrue);
5971 var actual = lodashStable.map(values, function(length) {
5972 return isIteratedAsObject({ 'length': length });
5975 var Foo = function(a) {};
5978 assert.deepEqual(actual, expected);
5979 assert.ok(isIteratedAsObject(Foo));
5980 assert.notOk(isIteratedAsObject({ 'length': 0 }));
5983 skipTest(assert, 3);
5988 lodashStable.each(methods, function(methodName) {
5989 var array = [1, 2, 3],
5990 func = _[methodName],
5991 isFind = /^find/.test(methodName),
5992 isSome = methodName == 'some',
5993 isReduce = /^reduce/.test(methodName);
5995 QUnit.test('`_.' + methodName + '` should ignore changes to `array.length`', function(assert) {
6002 func(array, function() {
6006 return !(isFind || isSome);
6007 }, isReduce ? array : null);
6009 assert.strictEqual(count, 1);
6017 lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
6018 var func = _[methodName],
6019 isFind = /^find/.test(methodName),
6020 isSome = methodName == 'some',
6021 isReduce = /^reduce/.test(methodName);
6023 QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
6028 object = { 'a': 1 };
6030 func(object, function() {
6034 return !(isFind || isSome);
6035 }, isReduce ? object : null);
6037 assert.strictEqual(count, 1);
6046 /*--------------------------------------------------------------------------*/
6048 QUnit.module('object assignments');
6050 lodashStable.each(['assign', 'assignIn', 'defaults', 'merge'], function(methodName) {
6051 var func = _[methodName],
6052 isAssign = methodName == 'assign',
6053 isDefaults = methodName == 'defaults';
6055 QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
6058 var expected = lodashStable.map(falsey, alwaysTrue);
6060 var actual = lodashStable.map(falsey, function(object, index) {
6061 var result = index ? func(object) : func();
6062 return lodashStable.isEqual(result, Object(object));
6065 assert.deepEqual(actual, expected);
6068 QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'source properties', function(assert) {
6071 function Foo() { this.a = 1; }
6072 Foo.prototype.b = 2;
6074 var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
6075 assert.deepEqual(func({}, new Foo), expected);
6078 QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
6082 assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
6084 assert.ok(false, e.message);
6088 QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
6091 var source = { 'a': 1 },
6092 values = [null, undefined],
6093 expected = lodashStable.map(values, alwaysTrue);
6095 var actual = lodashStable.map(values, function(value) {
6096 var object = func(value, source);
6097 return object !== source && lodashStable.isEqual(object, source);
6100 assert.deepEqual(actual, expected);
6102 actual = lodashStable.map(values, function(value) {
6103 return lodashStable.isEqual(func(value), {});
6106 assert.deepEqual(actual, expected);
6109 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
6112 var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
6113 expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
6115 assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
6117 var fn = function() {};
6122 assert.deepEqual(_.reduce(fn, func, { 'a': 0 }), expected);
6125 QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
6129 var wrapped = _({ 'a': 1 }),
6130 actual = wrapped[methodName]({ 'b': 2 });
6132 assert.notStrictEqual(actual, wrapped);
6140 lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
6141 var func = _[methodName];
6143 QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
6147 Foo.prototype.a = 1;
6149 var actual = func(new Foo, { 'b': 2 });
6150 assert.notOk(_.has(actual, 'a'));
6154 lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'merge', 'mergeWith'], function(methodName) {
6155 var func = _[methodName];
6157 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
6160 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
6161 if (defineProperty) {
6165 defineProperty(object, 'a', {
6167 'configurable': true,
6168 'get': lodashStable.constant(value),
6169 'set': function() { pass = false; }
6172 func(object, { 'a': value });
6182 lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
6183 var func = _[methodName],
6184 isMergeWith = methodName == 'mergeWith';
6186 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
6190 object = { 'a': 1 },
6191 source = { 'a': 2 },
6192 expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
6194 func(object, source, function() {
6195 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6198 assert.deepEqual(args, expected, 'primitive property values');
6201 object = { 'a': 1 };
6202 source = { 'b': 2 };
6203 expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
6205 func(object, source, function() {
6206 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6209 assert.deepEqual(args, expected, 'missing destination property');
6212 objectValue = [1, 2],
6213 sourceValue = { 'b': 2 };
6215 object = { 'a': objectValue };
6216 source = { 'a': sourceValue };
6217 expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
6220 expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
6222 func(object, source, function() {
6223 argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6226 assert.deepEqual(argsList, expected, 'object property values');
6229 QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
6232 function callback() {}
6235 var actual = func({ 'a': 1 }, callback);
6236 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
6238 actual = func({ 'a': 1 }, callback, { 'c': 3 });
6239 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
6243 /*--------------------------------------------------------------------------*/
6245 QUnit.module('exit early');
6247 lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
6248 var func = _[methodName];
6250 QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
6254 var array = [1, 2, 3],
6257 func(array, function(value, other) {
6258 values.push(lodashStable.isArray(value) ? other : value);
6262 assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
6269 QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
6273 var object = { 'a': 1, 'b': 2, 'c': 3 },
6276 func(object, function(value, other) {
6277 values.push(lodashStable.isArray(value) ? other : value);
6281 assert.strictEqual(values.length, 1);
6289 /*--------------------------------------------------------------------------*/
6291 QUnit.module('`__proto__` property bugs');
6294 QUnit.test('internal data objects should work with the `__proto__` key', function(assert) {
6297 var stringLiteral = '__proto__',
6298 stringObject = Object(stringLiteral),
6299 expected = [stringLiteral, stringObject];
6301 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
6302 return isEven(count) ? stringLiteral : stringObject;
6305 assert.deepEqual(_.difference(largeArray, largeArray), []);
6306 assert.deepEqual(_.intersection(largeArray, largeArray), expected);
6307 assert.deepEqual(_.uniq(largeArray), expected);
6308 assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
6312 /*--------------------------------------------------------------------------*/
6314 QUnit.module('lodash.fromPairs');
6317 var object = { 'barney': 36, 'fred': 40 },
6318 array = [['barney', 36], ['fred', 40]];
6320 QUnit.test('should accept a two dimensional array', function(assert) {
6323 var actual = _.fromPairs(array);
6324 assert.deepEqual(actual, object);
6327 QUnit.test('should accept a falsey `array` argument', function(assert) {
6330 var expected = lodashStable.map(falsey, alwaysEmptyObject);
6332 var actual = lodashStable.map(falsey, function(array, index) {
6334 return index ? _.fromPairs(array) : _.fromPairs();
6338 assert.deepEqual(actual, expected);
6341 QUnit.test('should support deep paths', function(assert) {
6344 var actual = _.fromPairs([['a.b.c', 1]]);
6345 assert.deepEqual(actual, { 'a': { 'b': { 'c': 1 } } });
6348 QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
6351 assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
6354 QUnit.test('should work in a lazy sequence', function(assert) {
6358 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
6359 return ['key' + index, index];
6362 var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
6364 assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
6372 /*--------------------------------------------------------------------------*/
6374 QUnit.module('lodash.functions');
6377 QUnit.test('should return the function names of an object', function(assert) {
6380 var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': lodashStable.each };
6381 assert.deepEqual(_.functions(object).sort(), ['b', 'd']);
6384 QUnit.test('should not include inherited functions', function(assert) {
6391 Foo.prototype.c = noop;
6392 assert.deepEqual(_.functions(new Foo).sort(), ['a']);
6396 /*--------------------------------------------------------------------------*/
6398 QUnit.module('lodash.groupBy');
6401 var array = [4.2, 6.1, 6.4];
6403 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
6406 var array = [4, 6, 6],
6407 values = [, null, undefined],
6408 expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
6410 var actual = lodashStable.map(values, function(value, index) {
6411 return index ? _.groupBy(array, value) : _.groupBy(array);
6414 assert.deepEqual(actual, expected);
6417 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
6420 var actual = _.groupBy(['one', 'two', 'three'], 'length');
6421 assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
6424 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
6427 var actual = _.groupBy([4.2, 6.1, 6.4], function(num) {
6428 return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor';
6431 assert.deepEqual(actual.constructor, [4.2]);
6432 assert.deepEqual(actual.hasOwnProperty, [6.1, 6.4]);
6435 QUnit.test('should work with a number for `iteratee`', function(assert) {
6444 assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
6445 assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
6448 QUnit.test('should work with an object for `collection`', function(assert) {
6451 var actual = _.groupBy({ 'a': 4.2, 'b': 6.1, 'c': 6.4 }, function(num) {
6452 return Math.floor(num);
6455 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.4] });
6458 QUnit.test('should work in a lazy sequence', function(assert) {
6462 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
6463 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
6464 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
6467 var iteratee = function(value) { value.push(value[0]); return value; },
6468 predicate = function(value) { return isEven(value[0]); },
6469 actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
6471 assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
6479 /*--------------------------------------------------------------------------*/
6481 QUnit.module('lodash.gt');
6484 QUnit.test('should return `true` if `value` > `other`', function(assert) {
6487 assert.strictEqual(_.gt(3, 1), true);
6488 assert.strictEqual(_.gt('def', 'abc'), true);
6491 QUnit.test('should return `false` if `value` is less than or equal to `other`', function(assert) {
6494 assert.strictEqual(_.gt(1, 3), false);
6495 assert.strictEqual(_.gt(3, 3), false);
6496 assert.strictEqual(_.gt('abc', 'def'), false);
6497 assert.strictEqual(_.gt('def', 'def'), false);
6501 /*--------------------------------------------------------------------------*/
6503 QUnit.module('lodash.gte');
6506 QUnit.test('should return `true` if `value` >= `other`', function(assert) {
6509 assert.strictEqual(_.gte(3, 1), true);
6510 assert.strictEqual(_.gte(3, 3), true);
6511 assert.strictEqual(_.gte('def', 'abc'), true);
6512 assert.strictEqual(_.gte('def', 'def'), true);
6515 QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
6518 assert.strictEqual(_.gte(1, 3), false);
6519 assert.strictEqual(_.gte('abc', 'def'), false);
6523 /*--------------------------------------------------------------------------*/
6525 QUnit.module('has methods');
6527 lodashStable.each(['has', 'hasIn'], function(methodName) {
6528 var args = (function() { return arguments; }(1, 2, 3)),
6529 func = _[methodName],
6530 isHas = methodName == 'has';
6532 QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
6535 var object = { 'a': 1 };
6537 lodashStable.each(['a', ['a']], function(path) {
6538 assert.strictEqual(func(object, path), true);
6542 QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
6545 var object = { 'hasOwnProperty': null, 'a': 1 };
6546 assert.strictEqual(func(object, 'a'), true);
6549 QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
6552 var object = { 'a': { 'b': { 'c': 3 } } };
6554 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
6555 assert.strictEqual(func(object, path), true);
6559 QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
6563 fn.toString = lodashStable.constant('fn');
6565 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
6566 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
6567 values = [null, undefined, fn, {}];
6569 var actual = lodashStable.transform(objects, function(result, object, index) {
6570 var key = values[index];
6571 lodashStable.each([key, [key]], function(path) {
6572 var prop = _.property(key);
6573 result.push(prop(object));
6577 assert.deepEqual(actual, expected);
6580 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
6583 assert.strictEqual(func(args, 1), true);
6586 QUnit.test('`_.' + methodName + '` should work with non-string `path` arguments', function(assert) {
6589 var array = [1, 2, 3];
6591 lodashStable.each([1, [1]], function(path) {
6592 assert.strictEqual(func(array, path), true);
6596 QUnit.test('`_.' + methodName + '` should work for objects with a `[[Prototype]]` of `null`', function(assert) {
6600 var object = create(null);
6602 assert.strictEqual(func(object, 1), true);
6609 QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
6612 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
6614 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
6615 assert.strictEqual(func(object, path), true);
6619 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
6623 Foo.prototype.a = 1;
6625 lodashStable.each(['a', ['a']], function(path) {
6626 assert.strictEqual(func(new Foo, path), !isHas);
6630 QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
6633 var string = Object('abc');
6637 var values = [Array(3), args, string],
6638 expected = lodashStable.map(values, alwaysTrue);
6640 var actual = lodashStable.map(values, function(value) {
6641 return func(value, 0);
6644 assert.deepEqual(actual, expected);
6648 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
6651 var values = [null, undefined],
6652 expected = lodashStable.map(values, alwaysFalse);
6654 lodashStable.each(['constructor', ['constructor']], function(path) {
6655 var actual = lodashStable.map(values, function(value) {
6656 return func(value, path);
6659 assert.deepEqual(actual, expected);
6663 QUnit.test('`_.' + methodName + '` should return `false` with deep paths when `object` is nullish', function(assert) {
6666 var values = [null, undefined],
6667 expected = lodashStable.map(values, alwaysFalse);
6669 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
6670 var actual = lodashStable.map(values, function(value) {
6671 return func(value, path);
6674 assert.deepEqual(actual, expected);
6678 QUnit.test('`_.' + methodName + '` should return `false` if parts of `path` are missing', function(assert) {
6683 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
6684 assert.strictEqual(func(object, path), false);
6689 /*--------------------------------------------------------------------------*/
6691 QUnit.module('lodash.head');
6694 var array = [1, 2, 3, 4];
6696 QUnit.test('should return the first element', function(assert) {
6699 assert.strictEqual(_.head(array), 1);
6702 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
6708 assert.strictEqual(_.head(array), undefined);
6711 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
6714 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
6715 actual = lodashStable.map(array, _.head);
6717 assert.deepEqual(actual, [1, 4, 7]);
6720 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
6724 assert.strictEqual(_(array).head(), 1);
6731 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
6735 assert.ok(_(array).chain().head() instanceof _);
6742 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
6746 var wrapped = _(array).chain().head();
6747 assert.strictEqual(wrapped.__wrapped__, array);
6754 QUnit.test('should work in a lazy sequence', function(assert) {
6758 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
6761 lodashStable.times(2, function(index) {
6762 var array = index ? largeArray : smallArray,
6763 wrapped = _(array).filter(isEven);
6765 assert.strictEqual(wrapped.head(), _.head(_.filter(array, isEven)));
6769 skipTest(assert, 2);
6773 QUnit.test('should be aliased', function(assert) {
6776 assert.strictEqual(_.first, _.head);
6780 /*--------------------------------------------------------------------------*/
6782 QUnit.module('lodash.identity');
6785 QUnit.test('should return the first argument provided', function(assert) {
6788 var object = { 'name': 'fred' };
6789 assert.strictEqual(_.identity(object), object);
6793 /*--------------------------------------------------------------------------*/
6795 QUnit.module('lodash.includes');
6799 'an `arguments` object': arguments,
6800 'an array': [1, 2, 3, 4],
6801 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
6804 function(collection, key) {
6805 var isStr = typeof collection == 'string',
6806 values = _.toArray(collection),
6807 length = values.length;
6809 QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
6812 assert.strictEqual(_.includes(collection, 3), true);
6815 QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
6818 assert.strictEqual(_.includes(collection, 5), false);
6821 QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
6824 assert.strictEqual(_.includes(collection, values[2], 2), true);
6825 assert.strictEqual(_.includes(collection, values[1], 2), false);
6828 QUnit.test('should work with ' + key + ' and a `fromIndex` >= `collection.length`', function(assert) {
6831 lodashStable.each([4, 6, Math.pow(2, 32), Infinity], function(fromIndex) {
6832 assert.strictEqual(_.includes(collection, 1, fromIndex), false);
6833 assert.strictEqual(_.includes(collection, undefined, fromIndex), false);
6834 assert.strictEqual(_.includes(collection, '', fromIndex), (isStr && fromIndex == length));
6838 QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
6841 var expected = lodashStable.map(falsey, alwaysTrue);
6843 var actual = lodashStable.map(falsey, function(fromIndex) {
6844 return _.includes(collection, values[0], fromIndex);
6847 assert.deepEqual(actual, expected);
6850 QUnit.test('should work with ' + key + ' and coerce non-integer `fromIndex` values to integers', function(assert) {
6853 assert.strictEqual(_.includes(collection, values[0], '1'), false);
6854 assert.strictEqual(_.includes(collection, values[0], 0.1), true);
6855 assert.strictEqual(_.includes(collection, values[0], NaN), true);
6858 QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
6861 assert.strictEqual(_.includes(collection, values[2], -2), true);
6862 assert.strictEqual(_.includes(collection, values[1], -2), false);
6865 QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= negative `collection.length`', function(assert) {
6868 lodashStable.each([-4, -6, -Infinity], function(fromIndex) {
6869 assert.strictEqual(_.includes(collection, values[0], fromIndex), true);
6873 QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
6876 assert.strictEqual(_.includes(collection, 2, 1.2), true);
6879 QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
6883 assert.strictEqual(_(collection).includes(3), true);
6890 QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
6894 assert.ok(_(collection).chain().includes(3) instanceof _);
6904 'object': Object('abc')
6906 function(collection, key) {
6907 QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
6910 assert.strictEqual(_.includes(collection, 'bc'), true);
6911 assert.strictEqual(_.includes(collection, 'd'), false);
6915 QUnit.test('should return `false` for empty collections', function(assert) {
6918 var expected = lodashStable.map(empties, alwaysFalse);
6920 var actual = lodashStable.map(empties, function(value) {
6922 return _.includes(value);
6926 assert.deepEqual(actual, expected);
6929 QUnit.test('should match `NaN`', function(assert) {
6932 assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
6935 QUnit.test('should match `-0` as `0`', function(assert) {
6938 assert.strictEqual(_.includes([-0], 0), true);
6939 assert.strictEqual(_.includes([0], -0), true);
6942 QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
6945 var array1 = [1, 2, 3],
6948 assert.ok(lodashStable.every(array1, lodashStable.partial(_.includes, array2)));
6952 /*--------------------------------------------------------------------------*/
6954 QUnit.module('lodash.indexOf');
6957 var array = [1, 2, 3, 1, 2, 3];
6959 QUnit.test('should return the index of the first matched value', function(assert) {
6962 assert.strictEqual(_.indexOf(array, 3), 2);
6965 QUnit.test('should work with a positive `fromIndex`', function(assert) {
6968 assert.strictEqual(_.indexOf(array, 1, 2), 3);
6971 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
6974 var values = [6, 8, Math.pow(2, 32), Infinity],
6975 expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
6977 var actual = lodashStable.map(values, function(fromIndex) {
6979 _.indexOf(array, undefined, fromIndex),
6980 _.indexOf(array, 1, fromIndex),
6981 _.indexOf(array, '', fromIndex)
6985 assert.deepEqual(actual, expected);
6988 QUnit.test('should work with a negative `fromIndex`', function(assert) {
6991 assert.strictEqual(_.indexOf(array, 2, -3), 4);
6994 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
6997 var values = [-6, -8, -Infinity],
6998 expected = lodashStable.map(values, alwaysZero);
7000 var actual = lodashStable.map(values, function(fromIndex) {
7001 return _.indexOf(array, 1, fromIndex);
7004 assert.deepEqual(actual, expected);
7007 QUnit.test('should treat falsey `fromIndex` values as `0`', function(assert) {
7010 var expected = lodashStable.map(falsey, alwaysZero);
7012 var actual = lodashStable.map(falsey, function(fromIndex) {
7013 return _.indexOf(array, 1, fromIndex);
7016 assert.deepEqual(actual, expected);
7019 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
7022 assert.strictEqual(_.indexOf(array, 2, 1.2), 1);
7026 /*--------------------------------------------------------------------------*/
7028 QUnit.module('lodash.initial');
7031 var array = [1, 2, 3];
7033 QUnit.test('should accept a falsey `array` argument', function(assert) {
7036 var expected = lodashStable.map(falsey, alwaysEmptyArray);
7038 var actual = lodashStable.map(falsey, function(array, index) {
7040 return index ? _.initial(array) : _.initial();
7044 assert.deepEqual(actual, expected);
7047 QUnit.test('should exclude last element', function(assert) {
7050 assert.deepEqual(_.initial(array), [1, 2]);
7053 QUnit.test('should return an empty when querying empty arrays', function(assert) {
7056 assert.deepEqual(_.initial([]), []);
7059 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7062 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7063 actual = lodashStable.map(array, _.initial);
7065 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
7068 QUnit.test('should work in a lazy sequence', function(assert) {
7072 var array = lodashStable.range(LARGE_ARRAY_SIZE),
7075 var actual = _(array).initial().filter(function(value) {
7081 assert.deepEqual(actual, []);
7082 assert.deepEqual(values, _.initial(array));
7086 actual = _(array).filter(function(value) {
7088 return isEven(value);
7093 assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
7094 assert.deepEqual(values, array);
7097 skipTest(assert, 4);
7102 /*--------------------------------------------------------------------------*/
7104 QUnit.module('lodash.inRange');
7107 QUnit.test('should work with an `end` argument', function(assert) {
7110 assert.strictEqual(_.inRange(3, 5), true);
7111 assert.strictEqual(_.inRange(5, 5), false);
7112 assert.strictEqual(_.inRange(6, 5), false);
7115 QUnit.test('should work with `start` and `end` arguments', function(assert) {
7118 assert.strictEqual(_.inRange(1, 1, 5), true);
7119 assert.strictEqual(_.inRange(3, 1, 5), true);
7120 assert.strictEqual(_.inRange(0, 1, 5), false);
7121 assert.strictEqual(_.inRange(5, 1, 5), false);
7124 QUnit.test('should treat falsey `start` arguments as `0`', function(assert) {
7127 lodashStable.each(falsey, function(value, index) {
7129 assert.strictEqual(_.inRange(0, value), false);
7130 assert.strictEqual(_.inRange(0, value, 1), true);
7132 assert.strictEqual(_.inRange(0), false);
7137 QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
7140 assert.strictEqual(_.inRange(2, 5, 1), true);
7141 assert.strictEqual(_.inRange(-3, -2, -6), true);
7144 QUnit.test('should work with a floating point `n` value', function(assert) {
7147 assert.strictEqual(_.inRange(0.5, 5), true);
7148 assert.strictEqual(_.inRange(1.2, 1, 5), true);
7149 assert.strictEqual(_.inRange(5.2, 5), false);
7150 assert.strictEqual(_.inRange(0.5, 1, 5), false);
7153 QUnit.test('should coerce arguments to finite numbers', function(assert) {
7156 var actual = [_.inRange(0, '0', 1), _.inRange(0, '1'), _.inRange(0, 0, '1'), _.inRange(0, NaN, 1), _.inRange(-1, -1, NaN)],
7157 expected = lodashStable.map(actual, alwaysTrue);
7159 assert.deepEqual(actual, expected);
7163 /*--------------------------------------------------------------------------*/
7165 QUnit.module('intersection methods');
7167 lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
7168 var args = (function() { return arguments; }(1, 2, 3)),
7169 func = _[methodName];
7171 QUnit.test('`_.' + methodName + '` should return the intersection of the given arrays', function(assert) {
7174 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
7175 assert.deepEqual(actual, [1, 2]);
7178 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
7181 var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
7182 assert.deepEqual(actual, [1, 2]);
7185 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
7188 var actual = func([1, NaN, 3], [NaN, 5, NaN]);
7189 assert.deepEqual(actual, [NaN]);
7192 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
7196 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
7198 assert.deepEqual(func([object], largeArray), [object]);
7199 assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
7202 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
7205 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
7206 assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
7209 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7212 var array = [0, 1, null, 3],
7215 assert.deepEqual(func(array, args), expected);
7216 assert.deepEqual(func(args, array), expected);
7219 QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
7222 var actual = func([1, 1, 3, 2, 2]);
7223 assert.deepEqual(actual, [1, 3, 2]);
7226 QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
7229 var array = [0, 1, null, 3];
7230 assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
7231 assert.deepEqual(func(null, array, null, [2, 3]), []);
7232 assert.deepEqual(func(array, null, args, null), []);
7235 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
7239 var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
7240 assert.ok(wrapped instanceof _);
7241 assert.deepEqual(wrapped.value(), [1, 2]);
7244 skipTest(assert, 2);
7249 /*--------------------------------------------------------------------------*/
7251 QUnit.module('lodash.intersectionBy');
7254 QUnit.test('should accept an `iteratee` argument', function(assert) {
7257 var actual = _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
7258 assert.deepEqual(actual, [2.1]);
7260 actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7261 assert.deepEqual(actual, [{ 'x': 1 }]);
7264 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
7269 _.intersectionBy([2.1, 1.2], [4.3, 2.4], function() {
7270 args || (args = slice.call(arguments));
7273 assert.deepEqual(args, [4.3]);
7277 /*--------------------------------------------------------------------------*/
7279 QUnit.module('lodash.intersectionWith');
7282 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7284 QUnit.test('should work with a `comparator` argument', function(assert) {
7287 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
7288 actual = _.intersectionWith(objects, others, lodashStable.isEqual);
7290 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }]);
7294 /*--------------------------------------------------------------------------*/
7296 QUnit.module('lodash.invert');
7299 QUnit.test('should invert an object', function(assert) {
7302 var object = { 'a': 1, 'b': 2 },
7303 actual = _.invert(object);
7305 assert.deepEqual(actual, { '1': 'a', '2': 'b' });
7306 assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
7309 QUnit.test('should work with an object that has a `length` property', function(assert) {
7312 var object = { '0': 'a', '1': 'b', 'length': 2 };
7313 assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
7316 QUnit.test('should accept a `multiValue` flag', function(assert) {
7319 var object = { 'a': 1, 'b': 2, 'c': 1 };
7320 assert.deepEqual(_.invert(object, true), { '1': ['a', 'c'], '2': ['b'] });
7323 QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
7326 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
7328 assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
7329 assert.ok(lodashStable.isEqual(_.invert(object, true), { 'hasOwnProperty': ['a'], 'constructor': ['b'] }));
7332 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7335 var regular = { 'a': 1, 'b': 2, 'c': 1 },
7336 inverted = { '1': 'c', '2': 'b' };
7338 var array = [regular, regular, regular],
7339 object = { 'a': regular, 'b': regular, 'c': regular },
7340 expected = lodashStable.map(array, lodashStable.constant(inverted));
7342 lodashStable.each([array, object], function(collection) {
7343 var actual = lodashStable.map(collection, _.invert);
7344 assert.deepEqual(actual, expected);
7348 QUnit.test('should return a wrapped value when chaining', function(assert) {
7352 var object = { 'a': 1, 'b': 2 },
7353 wrapped = _(object).invert();
7355 assert.ok(wrapped instanceof _);
7356 assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
7359 skipTest(assert, 2);
7364 /*--------------------------------------------------------------------------*/
7366 QUnit.module('lodash.invoke');
7369 QUnit.test('should invoke a method on `object`', function(assert) {
7372 var object = { 'a': lodashStable.constant('A') },
7373 actual = _.invoke(object, 'a');
7375 assert.strictEqual(actual, 'A');
7378 QUnit.test('should support invoking with arguments', function(assert) {
7381 var object = { 'a': function(a, b) { return [a, b]; } },
7382 actual = _.invoke(object, 'a', 1, 2);
7384 assert.deepEqual(actual, [1, 2]);
7387 QUnit.test('should not error on nullish elements', function(assert) {
7390 var values = [null, undefined],
7391 expected = lodashStable.map(values, alwaysUndefined);
7393 var actual = lodashStable.map(values, function(value) {
7395 return _.invoke(value, 'a.b.c', 1, 2);
7399 assert.deepEqual(actual, expected);
7402 QUnit.test('should support deep paths', function(assert) {
7405 var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
7407 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7408 var actual = _.invoke(object, path, 1, 2);
7409 assert.deepEqual(actual, [1, 2]);
7413 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
7416 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
7418 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7419 assert.deepEqual(_.invoke(object, path), 1);
7423 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7427 var object = { 'a': alwaysOne };
7428 assert.strictEqual(_(object).invoke('a'), 1);
7435 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7439 var object = { 'a': alwaysOne };
7440 assert.ok(_(object).chain().invoke('a') instanceof _);
7448 /*--------------------------------------------------------------------------*/
7450 QUnit.module('lodash.invokeMap');
7453 QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
7456 var array = ['a', 'b', 'c'],
7457 actual = _.invokeMap(array, 'toUpperCase');
7459 assert.deepEqual(actual, ['A', 'B', 'C']);
7462 QUnit.test('should support invoking with arguments', function(assert) {
7465 var array = [function() { return slice.call(arguments); }],
7466 actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
7468 assert.deepEqual(actual, [['a', 'b', 'c']]);
7471 QUnit.test('should work with a function for `methodName`', function(assert) {
7474 var array = ['a', 'b', 'c'];
7476 var actual = _.invokeMap(array, function(left, right) {
7477 return left + this.toUpperCase() + right;
7480 assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
7483 QUnit.test('should work with an object for `collection`', function(assert) {
7486 var object = { 'a': 1, 'b': 2, 'c': 3 },
7487 actual = _.invokeMap(object, 'toFixed', 1);
7489 assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
7492 QUnit.test('should treat number values for `collection` as empty', function(assert) {
7495 assert.deepEqual(_.invokeMap(1), []);
7498 QUnit.test('should not error on nullish elements', function(assert) {
7501 var array = ['a', null, undefined, 'd'];
7504 var actual = _.invokeMap(array, 'toUpperCase');
7507 assert.deepEqual(_.invokeMap(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
7510 QUnit.test('should not error on elements with missing properties', function(assert) {
7513 var objects = lodashStable.map([null, undefined, alwaysOne], function(value) {
7514 return { 'a': value };
7517 var expected = lodashStable.map(objects, function(object) {
7518 return object.a ? object.a() : undefined;
7522 var actual = _.invokeMap(objects, 'a');
7525 assert.deepEqual(actual, expected);
7528 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
7531 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
7533 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7534 assert.deepEqual(_.invokeMap([object], path), [1]);
7538 QUnit.test('should return a wrapped value when chaining', function(assert) {
7542 var array = ['a', 'b', 'c'],
7544 actual = wrapped.invokeMap('toUpperCase');
7546 assert.ok(actual instanceof _);
7547 assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
7549 actual = wrapped.invokeMap(function(left, right) {
7550 return left + this.toUpperCase() + right;
7553 assert.ok(actual instanceof _);
7554 assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
7557 skipTest(assert, 4);
7561 QUnit.test('should support shortcut fusion', function(assert) {
7566 method = function() { count++; return this.index; };
7568 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
7569 return { 'index': index, 'method': method };
7572 var actual = _(array).invokeMap('method').take(1).value();
7574 assert.strictEqual(count, 1);
7575 assert.deepEqual(actual, [0]);
7578 skipTest(assert, 2);
7583 /*--------------------------------------------------------------------------*/
7585 QUnit.module('lodash.isArguments');
7588 var args = (function() { return arguments; }(1, 2, 3)),
7589 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
7591 QUnit.test('should return `true` for `arguments` objects', function(assert) {
7594 assert.strictEqual(_.isArguments(args), true);
7595 assert.strictEqual(_.isArguments(strictArgs), true);
7598 QUnit.test('should return `false` for non `arguments` objects', function(assert) {
7601 var expected = lodashStable.map(falsey, alwaysFalse);
7603 var actual = lodashStable.map(falsey, function(value, index) {
7604 return index ? _.isArguments(value) : _.isArguments();
7607 assert.deepEqual(actual, expected);
7609 assert.strictEqual(_.isArguments([1, 2, 3]), false);
7610 assert.strictEqual(_.isArguments(true), false);
7611 assert.strictEqual(_.isArguments(new Date), false);
7612 assert.strictEqual(_.isArguments(new Error), false);
7613 assert.strictEqual(_.isArguments(_), false);
7614 assert.strictEqual(_.isArguments(slice), false);
7615 assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
7616 assert.strictEqual(_.isArguments(1), false);
7617 assert.strictEqual(_.isArguments(/x/), false);
7618 assert.strictEqual(_.isArguments('a'), false);
7619 assert.strictEqual(_.isArguments(symbol), false);
7622 QUnit.test('should work with an `arguments` object from another realm', function(assert) {
7625 if (realm.arguments) {
7626 assert.strictEqual(_.isArguments(realm.arguments), true);
7634 /*--------------------------------------------------------------------------*/
7636 QUnit.module('lodash.isArray');
7639 var args = arguments;
7641 QUnit.test('should return `true` for arrays', function(assert) {
7644 assert.strictEqual(_.isArray([1, 2, 3]), true);
7647 QUnit.test('should return `false` for non-arrays', function(assert) {
7650 var expected = lodashStable.map(falsey, alwaysFalse);
7652 var actual = lodashStable.map(falsey, function(value, index) {
7653 return index ? _.isArray(value) : _.isArray();
7656 assert.deepEqual(actual, expected);
7658 assert.strictEqual(_.isArray(args), false);
7659 assert.strictEqual(_.isArray(true), false);
7660 assert.strictEqual(_.isArray(new Date), false);
7661 assert.strictEqual(_.isArray(new Error), false);
7662 assert.strictEqual(_.isArray(_), false);
7663 assert.strictEqual(_.isArray(slice), false);
7664 assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
7665 assert.strictEqual(_.isArray(1), false);
7666 assert.strictEqual(_.isArray(/x/), false);
7667 assert.strictEqual(_.isArray('a'), false);
7668 assert.strictEqual(_.isArray(symbol), false);
7671 QUnit.test('should work with an array from another realm', function(assert) {
7675 assert.strictEqual(_.isArray(realm.array), true);
7683 /*--------------------------------------------------------------------------*/
7685 QUnit.module('lodash.isArrayLike');
7688 var args = arguments;
7690 QUnit.test('should return `true` for array-like values', function(assert) {
7693 var values = [args, [1, 2, 3], { '0': 1, 'length': 1 }, 'a'],
7694 expected = lodashStable.map(values, alwaysTrue),
7695 actual = lodashStable.map(values, _.isArrayLike);
7697 assert.deepEqual(actual, expected);
7700 QUnit.test('should return `false` for non-arrays', function(assert) {
7703 var expected = lodashStable.map(falsey, function(value) {
7704 return value === '';
7707 var actual = lodashStable.map(falsey, function(value, index) {
7708 return index ? _.isArrayLike(value) : _.isArrayLike();
7711 assert.deepEqual(actual, expected);
7713 assert.strictEqual(_.isArrayLike(true), false);
7714 assert.strictEqual(_.isArrayLike(new Date), false);
7715 assert.strictEqual(_.isArrayLike(new Error), false);
7716 assert.strictEqual(_.isArrayLike(_), false);
7717 assert.strictEqual(_.isArrayLike(generator), false);
7718 assert.strictEqual(_.isArrayLike(slice), false);
7719 assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
7720 assert.strictEqual(_.isArrayLike(1), false);
7721 assert.strictEqual(_.isArrayLike(/x/), false);
7722 assert.strictEqual(_.isArrayLike(symbol), false);
7725 QUnit.test('should work with an array from another realm', function(assert) {
7729 var values = [realm.arguments, realm.array, realm.string],
7730 expected = lodashStable.map(values, alwaysTrue),
7731 actual = lodashStable.map(values, _.isArrayLike);
7733 assert.deepEqual(actual, expected);
7741 /*--------------------------------------------------------------------------*/
7743 QUnit.module('lodash.isBoolean');
7746 var args = arguments;
7748 QUnit.test('should return `true` for booleans', function(assert) {
7751 assert.strictEqual(_.isBoolean(true), true);
7752 assert.strictEqual(_.isBoolean(false), true);
7753 assert.strictEqual(_.isBoolean(Object(true)), true);
7754 assert.strictEqual(_.isBoolean(Object(false)), true);
7757 QUnit.test('should return `false` for non-booleans', function(assert) {
7760 var expected = lodashStable.map(falsey, function(value) {
7761 return value === false;
7764 var actual = lodashStable.map(falsey, function(value, index) {
7765 return index ? _.isBoolean(value) : _.isBoolean();
7768 assert.deepEqual(actual, expected);
7770 assert.strictEqual(_.isBoolean(args), false);
7771 assert.strictEqual(_.isBoolean([1, 2, 3]), false);
7772 assert.strictEqual(_.isBoolean(new Date), false);
7773 assert.strictEqual(_.isBoolean(new Error), false);
7774 assert.strictEqual(_.isBoolean(_), false);
7775 assert.strictEqual(_.isBoolean(slice), false);
7776 assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
7777 assert.strictEqual(_.isBoolean(1), false);
7778 assert.strictEqual(_.isBoolean(/x/), false);
7779 assert.strictEqual(_.isBoolean('a'), false);
7780 assert.strictEqual(_.isBoolean(symbol), false);
7783 QUnit.test('should work with a boolean from another realm', function(assert) {
7786 if (realm.boolean) {
7787 assert.strictEqual(_.isBoolean(realm.boolean), true);
7795 /*--------------------------------------------------------------------------*/
7797 QUnit.module('lodash.isDate');
7800 var args = arguments;
7802 QUnit.test('should return `true` for dates', function(assert) {
7805 assert.strictEqual(_.isDate(new Date), true);
7808 QUnit.test('should return `false` for non-dates', function(assert) {
7811 var expected = lodashStable.map(falsey, alwaysFalse);
7813 var actual = lodashStable.map(falsey, function(value, index) {
7814 return index ? _.isDate(value) : _.isDate();
7817 assert.deepEqual(actual, expected);
7819 assert.strictEqual(_.isDate(args), false);
7820 assert.strictEqual(_.isDate([1, 2, 3]), false);
7821 assert.strictEqual(_.isDate(true), false);
7822 assert.strictEqual(_.isDate(new Error), false);
7823 assert.strictEqual(_.isDate(_), false);
7824 assert.strictEqual(_.isDate(slice), false);
7825 assert.strictEqual(_.isDate({ 'a': 1 }), false);
7826 assert.strictEqual(_.isDate(1), false);
7827 assert.strictEqual(_.isDate(/x/), false);
7828 assert.strictEqual(_.isDate('a'), false);
7829 assert.strictEqual(_.isDate(symbol), false);
7832 QUnit.test('should work with a date object from another realm', function(assert) {
7836 assert.strictEqual(_.isDate(realm.date), true);
7844 /*--------------------------------------------------------------------------*/
7846 QUnit.module('lodash.isElement');
7849 var args = arguments;
7851 function Element() {
7855 QUnit.test('should return `false` for plain objects', function(assert) {
7858 var element = body || new Element;
7860 assert.strictEqual(_.isElement(element), true);
7861 assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
7862 assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
7863 assert.strictEqual(_.isElement({ 'nodeType': true }), false);
7864 assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
7865 assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
7866 assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
7869 QUnit.test('should return `false` for non DOM elements', function(assert) {
7872 var expected = lodashStable.map(falsey, alwaysFalse);
7874 var actual = lodashStable.map(falsey, function(value, index) {
7875 return index ? _.isElement(value) : _.isElement();
7878 assert.deepEqual(actual, expected);
7880 assert.strictEqual(_.isElement(args), false);
7881 assert.strictEqual(_.isElement([1, 2, 3]), false);
7882 assert.strictEqual(_.isElement(true), false);
7883 assert.strictEqual(_.isElement(new Date), false);
7884 assert.strictEqual(_.isElement(new Error), false);
7885 assert.strictEqual(_.isElement(_), false);
7886 assert.strictEqual(_.isElement(slice), false);
7887 assert.strictEqual(_.isElement({ 'a': 1 }), false);
7888 assert.strictEqual(_.isElement(1), false);
7889 assert.strictEqual(_.isElement(/x/), false);
7890 assert.strictEqual(_.isElement('a'), false);
7891 assert.strictEqual(_.isElement(symbol), false);
7894 QUnit.test('should work with a DOM element from another realm', function(assert) {
7897 if (realm.element) {
7898 assert.strictEqual(_.isElement(realm.element), true);
7906 /*--------------------------------------------------------------------------*/
7908 QUnit.module('lodash.isEmpty');
7911 var args = arguments;
7913 QUnit.test('should return `true` for empty values', function(assert) {
7916 var expected = lodashStable.map(empties, alwaysTrue),
7917 actual = lodashStable.map(empties, _.isEmpty);
7919 assert.deepEqual(actual, expected);
7921 assert.strictEqual(_.isEmpty(true), true);
7922 assert.strictEqual(_.isEmpty(slice), true);
7923 assert.strictEqual(_.isEmpty(1), true);
7924 assert.strictEqual(_.isEmpty(NaN), true);
7925 assert.strictEqual(_.isEmpty(/x/), true);
7926 assert.strictEqual(_.isEmpty(symbol), true);
7927 assert.strictEqual(_.isEmpty(), true);
7930 QUnit.test('should return `false` for non-empty values', function(assert) {
7933 assert.strictEqual(_.isEmpty([0]), false);
7934 assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
7935 assert.strictEqual(_.isEmpty('a'), false);
7938 QUnit.test('should work with an object that has a `length` property', function(assert) {
7941 assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
7944 QUnit.test('should work with `arguments` objects', function(assert) {
7947 assert.strictEqual(_.isEmpty(args), false);
7950 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
7953 function Foo(elements) { push.apply(this, elements); }
7954 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
7956 assert.strictEqual(_.isEmpty(new Foo([])), true);
7959 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
7963 Foo.prototype.length = -1;
7965 assert.strictEqual(_.isEmpty(new Foo), true);
7968 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
7972 Foo.prototype.length = MAX_SAFE_INTEGER + 1;
7974 assert.strictEqual(_.isEmpty(new Foo), true);
7977 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
7980 assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
7983 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7987 assert.strictEqual(_({}).isEmpty(), true);
7994 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7998 assert.ok(_({}).chain().isEmpty() instanceof _);
8006 /*--------------------------------------------------------------------------*/
8008 QUnit.module('lodash.isEqual');
8011 var symbol1 = Symbol ? Symbol('a') : true,
8012 symbol2 = Symbol ? Symbol('b') : false;
8014 QUnit.test('should compare primitives', function(assert) {
8018 [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
8019 [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
8020 [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
8021 ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
8022 [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
8023 [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
8024 [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
8025 [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
8026 [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
8029 var expected = lodashStable.map(pairs, function(pair) {
8033 var actual = lodashStable.map(pairs, function(pair) {
8034 return _.isEqual(pair[0], pair[1]);
8037 assert.deepEqual(actual, expected);
8040 QUnit.test('should compare arrays', function(assert) {
8043 var array1 = [true, null, 1, 'a', undefined],
8044 array2 = [true, null, 1, 'a', undefined];
8046 assert.strictEqual(_.isEqual(array1, array2), true);
8048 array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
8049 array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
8051 assert.strictEqual(_.isEqual(array1, array2), true);
8057 array2[1] = undefined;
8060 assert.strictEqual(_.isEqual(array1, array2), true);
8062 array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
8063 array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
8065 assert.strictEqual(_.isEqual(array1, array2), true);
8070 assert.strictEqual(_.isEqual(array1, array2), false);
8075 assert.strictEqual(_.isEqual(array1, array2), false);
8078 QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
8081 var array1 = [1, 2, 3],
8084 array1.every = array1.filter = array1.forEach =
8085 array1.indexOf = array1.lastIndexOf = array1.map =
8086 array1.some = array1.reduce = array1.reduceRight = null;
8088 array2.concat = array2.join = array2.pop =
8089 array2.reverse = array2.shift = array2.slice =
8090 array2.sort = array2.splice = array2.unshift = null;
8092 assert.strictEqual(_.isEqual(array1, array2), true);
8100 assert.strictEqual(_.isEqual(array1, array2), true);
8102 array1 = /x/.exec('vwxyz');
8105 assert.strictEqual(_.isEqual(array1, array2), true);
8108 QUnit.test('should compare sparse arrays', function(assert) {
8111 var array = Array(1);
8113 assert.strictEqual(_.isEqual(array, Array(1)), true);
8114 assert.strictEqual(_.isEqual(array, [undefined]), true);
8115 assert.strictEqual(_.isEqual(array, Array(2)), false);
8118 QUnit.test('should compare plain objects', function(assert) {
8121 var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
8122 object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
8124 assert.strictEqual(_.isEqual(object1, object2), true);
8126 object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
8127 object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
8129 assert.strictEqual(_.isEqual(object1, object2), true);
8131 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8132 object2 = { 'a': 3, 'b': 2, 'c': 1 };
8134 assert.strictEqual(_.isEqual(object1, object2), false);
8136 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8137 object2 = { 'd': 1, 'e': 2, 'f': 3 };
8139 assert.strictEqual(_.isEqual(object1, object2), false);
8141 object1 = { 'a': 1, 'b': 2 };
8142 object2 = { 'a': 1, 'b': 2, 'c': 3 };
8144 assert.strictEqual(_.isEqual(object1, object2), false);
8147 QUnit.test('should compare nested objects', function(assert) {
8156 'f': ['a', Object('b'), 'c'],
8158 'h': new Date(2012, 4, 23),
8165 'a': [1, Object(2), 3],
8170 'f': ['a', 'b', 'c'],
8172 'h': new Date(2012, 4, 23),
8178 assert.strictEqual(_.isEqual(object1, object2), true);
8181 QUnit.test('should compare object instances', function(assert) {
8184 function Foo() { this.a = 1; }
8185 Foo.prototype.a = 1;
8187 function Bar() { this.a = 1; }
8188 Bar.prototype.a = 2;
8190 assert.strictEqual(_.isEqual(new Foo, new Foo), true);
8191 assert.strictEqual(_.isEqual(new Foo, new Bar), false);
8192 assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
8193 assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
8196 QUnit.test('should compare objects with constructor properties', function(assert) {
8199 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
8200 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
8201 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
8202 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
8203 assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
8206 QUnit.test('should compare arrays with circular references', function(assert) {
8212 array1.push(array1);
8213 array2.push(array2);
8215 assert.strictEqual(_.isEqual(array1, array2), true);
8220 assert.strictEqual(_.isEqual(array1, array2), true);
8225 assert.strictEqual(_.isEqual(array1, array2), false);
8227 array1 = ['a', 'b', 'c'];
8229 array2 = ['a', ['a', 'b', 'c'], 'c'];
8231 assert.strictEqual(_.isEqual(array1, array2), false);
8234 QUnit.test('should compare objects with circular references', function(assert) {
8240 object1.a = object1;
8241 object2.a = object2;
8243 assert.strictEqual(_.isEqual(object1, object2), true);
8246 object2.b = Object(0);
8248 assert.strictEqual(_.isEqual(object1, object2), true);
8250 object1.c = Object(1);
8251 object2.c = Object(2);
8253 assert.strictEqual(_.isEqual(object1, object2), false);
8255 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8256 object1.b = object1;
8257 object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
8259 assert.strictEqual(_.isEqual(object1, object2), false);
8262 QUnit.test('should compare objects with multiple circular references', function(assert) {
8268 (array1[0].a = array1).push(array1);
8269 (array2[0].a = array2).push(array2);
8271 assert.strictEqual(_.isEqual(array1, array2), true);
8274 array2[0].b = Object(0);
8276 assert.strictEqual(_.isEqual(array1, array2), true);
8278 array1[0].c = Object(1);
8279 array2[0].c = Object(2);
8281 assert.strictEqual(_.isEqual(array1, array2), false);
8284 QUnit.test('should compare objects with complex circular references', function(assert) {
8288 'foo': { 'b': { 'c': { 'd': {} } } },
8293 'foo': { 'b': { 'c': { 'd': {} } } },
8297 object1.foo.b.c.d = object1;
8298 object1.bar.b = object1.foo.b;
8300 object2.foo.b.c.d = object2;
8301 object2.bar.b = object2.foo.b;
8303 assert.strictEqual(_.isEqual(object1, object2), true);
8306 QUnit.test('should compare objects with shared property values', function(assert) {
8318 object1.b = object1.a;
8320 assert.strictEqual(_.isEqual(object1, object2), true);
8323 QUnit.test('should treat objects created by `Object.create(null)` like a plain object', function(assert) {
8326 function Foo() { this.a = 1; }
8327 Foo.prototype.constructor = null;
8329 var object2 = { 'a': 1 };
8330 assert.strictEqual(_.isEqual(new Foo, object2), false);
8333 var object1 = create(null);
8335 assert.strictEqual(_.isEqual(object1, object2), true);
8342 QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
8346 object = { 'toString': function() { return primitive; } },
8347 values = [true, null, 1, 'a', undefined],
8348 expected = lodashStable.map(values, alwaysFalse);
8350 var actual = lodashStable.map(values, function(value) {
8352 return _.isEqual(object, value);
8355 assert.deepEqual(actual, expected);
8358 QUnit.test('should avoid common type coercions', function(assert) {
8361 assert.strictEqual(_.isEqual(true, Object(false)), false);
8362 assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
8363 assert.strictEqual(_.isEqual(false, Object('')), false);
8364 assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
8365 assert.strictEqual(_.isEqual(0, ''), false);
8366 assert.strictEqual(_.isEqual(1, true), false);
8367 assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
8368 assert.strictEqual(_.isEqual('36', 36), false);
8369 assert.strictEqual(_.isEqual(36, '36'), false);
8372 QUnit.test('should compare `arguments` objects', function(assert) {
8375 var args1 = (function() { return arguments; }(1, 2, 3)),
8376 args2 = (function() { return arguments; }(1, 2, 3)),
8377 args3 = (function() { return arguments; }(1, 2));
8379 assert.strictEqual(_.isEqual(args1, args2), true);
8380 assert.strictEqual(_.isEqual(args1, args3), false);
8383 QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
8386 var args = (function() { return arguments; }(1, 2, 3)),
8387 object = { '0': 1, '1': 2, '2': 3 };
8390 Foo.prototype = object;
8392 assert.strictEqual(_.isEqual(args, object), true);
8393 assert.strictEqual(_.isEqual(object, args), true);
8395 assert.strictEqual(_.isEqual(args, new Foo), false);
8396 assert.strictEqual(_.isEqual(new Foo, args), false);
8399 QUnit.test('should compare array buffers', function(assert) {
8403 var buffer1 = new ArrayBuffer(4),
8404 buffer2 = new ArrayBuffer(8);
8406 assert.strictEqual(_.isEqual(buffer1, buffer2), false);
8408 buffer1 = new Int8Array([-1]).buffer;
8409 buffer2 = new Uint8Array([255]).buffer;
8411 assert.strictEqual(_.isEqual(buffer1, buffer2), true);
8414 skipTest(assert, 2);
8418 QUnit.test('should compare date objects', function(assert) {
8421 assert.strictEqual(_.isEqual(new Date(2012, 4, 23), new Date(2012, 4, 23)), true);
8422 assert.strictEqual(_.isEqual(new Date(2012, 4, 23), new Date(2013, 3, 25)), false);
8423 assert.strictEqual(_.isEqual(new Date(2012, 4, 23), { 'getTime': lodashStable.constant(1337756400000) }), false);
8424 assert.strictEqual(_.isEqual(new Date('a'), new Date('a')), false);
8427 QUnit.test('should compare error objects', function(assert) {
8430 var pairs = lodashStable.map([
8438 ], function(type, index, errorTypes) {
8439 var otherType = errorTypes[++index % errorTypes.length],
8441 CtorB = root[otherType];
8443 return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
8446 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
8448 var actual = lodashStable.map(pairs, function(pair) {
8449 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
8452 assert.deepEqual(actual, expected);
8455 QUnit.test('should compare functions', function(assert) {
8458 function a() { return 1 + 2; }
8459 function b() { return 1 + 2; }
8461 assert.strictEqual(_.isEqual(a, a), true);
8462 assert.strictEqual(_.isEqual(a, b), false);
8465 QUnit.test('should compare maps', function(assert) {
8474 assert.strictEqual(_.isEqual(map1, map2), false);
8478 assert.strictEqual(_.isEqual(map1, map2), true);
8480 map1['delete']('a');
8482 assert.strictEqual(_.isEqual(map1, map2), true);
8484 map2['delete']('a');
8485 assert.strictEqual(_.isEqual(map1, map2), false);
8488 skipTest(assert, 4);
8492 QUnit.test('should compare regexes', function(assert) {
8495 assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
8496 assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
8497 assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
8498 assert.strictEqual(_.isEqual(/x/, /y/), false);
8499 assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
8502 QUnit.test('should compare sets', function(assert) {
8511 assert.strictEqual(_.isEqual(set1, set2), false);
8515 assert.strictEqual(_.isEqual(set1, set2), true);
8519 assert.strictEqual(_.isEqual(set1, set2), true);
8522 assert.strictEqual(_.isEqual(set1, set2), false);
8525 skipTest(assert, 4);
8529 QUnit.test('should compare typed arrays', function(assert) {
8532 var pairs = lodashStable.map(typedArrays, function(type, index) {
8533 var otherType = typedArrays[(index + 1) % typedArrays.length],
8534 CtorA = root[type] || function(n) { this.n = n; },
8535 CtorB = root[otherType] || function(n) { this.n = n; },
8536 bufferA = root[type] ? new ArrayBuffer(8) : 8,
8537 bufferB = root[otherType] ? new ArrayBuffer(8) : 8,
8538 bufferC = root[otherType] ? new ArrayBuffer(16) : 16;
8540 return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
8543 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
8545 var actual = lodashStable.map(pairs, function(pair) {
8546 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
8549 assert.deepEqual(actual, expected);
8552 QUnit.test('should work as an iteratee for `_.every`', function(assert) {
8555 var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
8559 QUnit.test('should return `true` for like-objects from different documents', function(assert) {
8563 assert.strictEqual(_.isEqual({ 'a': 1, 'b': 2, 'c': 3 }, realm.object), true);
8564 assert.strictEqual(_.isEqual({ 'a': 1, 'b': 2, 'c': 2 }, realm.object), false);
8565 assert.strictEqual(_.isEqual([1, 2, 3], realm.array), true);
8566 assert.strictEqual(_.isEqual([1, 2, 2], realm.array), false);
8569 skipTest(assert, 4);
8573 QUnit.test('should not error on DOM elements', function(assert) {
8577 var element1 = document.createElement('div'),
8578 element2 = element1.cloneNode(true);
8581 assert.strictEqual(_.isEqual(element1, element2), false);
8583 assert.ok(false, e.message);
8591 QUnit.test('should compare wrapped values', function(assert) {
8594 var stamp = +new Date;
8597 [[1, 2], [1, 2], [1, 2, 3]],
8598 [true, true, false],
8599 [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
8600 [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
8602 [NaN, NaN, Infinity],
8607 lodashStable.each(values, function(vals) {
8609 var wrapped1 = _(vals[0]),
8610 wrapped2 = _(vals[1]),
8611 actual = wrapped1.isEqual(wrapped2);
8613 assert.strictEqual(actual, true);
8614 assert.strictEqual(_.isEqual(_(actual), _(true)), true);
8616 wrapped1 = _(vals[0]);
8617 wrapped2 = _(vals[2]);
8619 actual = wrapped1.isEqual(wrapped2);
8620 assert.strictEqual(actual, false);
8621 assert.strictEqual(_.isEqual(_(actual), _(false)), true);
8624 skipTest(assert, 4);
8629 QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
8633 var object1 = _({ 'a': 1, 'b': 2 }),
8634 object2 = { 'a': 1, 'b': 2 };
8636 assert.strictEqual(object1.isEqual(object2), true);
8637 assert.strictEqual(_.isEqual(object1, object2), true);
8639 object1 = _({ 'a': 1, 'b': 2 });
8640 object2 = { 'a': 1, 'b': 1 };
8642 assert.strictEqual(object1.isEqual(object2), false);
8643 assert.strictEqual(_.isEqual(object1, object2), false);
8646 skipTest(assert, 4);
8650 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8654 assert.strictEqual(_('a').isEqual('a'), true);
8661 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8665 assert.ok(_('a').chain().isEqual('a') instanceof _);
8673 /*--------------------------------------------------------------------------*/
8675 QUnit.module('lodash.isEqualWith');
8678 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
8682 object1 = { 'a': [1, 2], 'b': null },
8683 object2 = { 'a': [1, 2], 'b': null };
8685 object1.b = object2;
8686 object2.b = object1;
8690 [object1.a, object2.a, 'a', object1, object2],
8691 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
8692 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
8693 [object1.b, object2.b, 'b', object1.b, object2.b],
8694 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
8695 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
8696 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
8697 [object1.b.b, object2.b.b, 'b', object1.b.b, object2.b.b]
8700 _.isEqualWith(object1, object2, function(assert) {
8701 var length = arguments.length,
8702 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
8704 argsList.push(args);
8707 assert.deepEqual(argsList, expected);
8710 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
8713 assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
8714 assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
8715 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
8718 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
8721 var customizer = function(value) {
8722 return _.isString(value) || undefined;
8725 assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
8726 assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
8727 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
8730 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
8733 var customizer = function(value) {
8734 return _.isString(value) ? false : undefined;
8737 assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
8738 assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
8739 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
8742 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
8745 var actual = _.isEqualWith('a', 'b', alwaysC);
8746 assert.strictEqual(actual, true);
8748 var values = _.without(falsey, undefined),
8749 expected = lodashStable.map(values, alwaysFalse);
8752 lodashStable.each(values, function(value) {
8753 actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
8756 assert.deepEqual(actual, expected);
8759 QUnit.test('should ensure `customizer` is a function', function(assert) {
8762 var array = [1, 2, 3],
8763 eq = _.partial(_.isEqualWith, array),
8764 actual = lodashStable.map([array, [1, 0, 3]], eq);
8766 assert.deepEqual(actual, [true, false]);
8769 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
8772 var value = { 'a': { 'b': 2 } };
8776 map1.set('a', value);
8779 map2.set('a', value);
8788 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
8791 array = _.toArray(pair[0]);
8795 [array[0], array[0], 0, array, array],
8796 [array[0][0], array[0][0], 0, array[0], array[0]],
8797 [array[0][1], array[0][1], 1, array[0], array[0]]
8801 expected.length = 2;
8803 _.isEqualWith(pair[0], pair[1], function() {
8804 var length = arguments.length,
8805 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
8807 argsList.push(args);
8810 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
8819 /*--------------------------------------------------------------------------*/
8821 QUnit.module('lodash.isError');
8824 var args = arguments;
8826 QUnit.test('should return `true` for error objects', function(assert) {
8829 var expected = lodashStable.map(errors, alwaysTrue);
8831 var actual = lodashStable.map(errors, function(error) {
8832 return _.isError(error) === true;
8835 assert.deepEqual(actual, expected);
8838 QUnit.test('should return `false` for non error objects', function(assert) {
8841 var expected = lodashStable.map(falsey, alwaysFalse);
8843 var actual = lodashStable.map(falsey, function(value, index) {
8844 return index ? _.isError(value) : _.isError();
8847 assert.deepEqual(actual, expected);
8849 assert.strictEqual(_.isError(args), false);
8850 assert.strictEqual(_.isError([1, 2, 3]), false);
8851 assert.strictEqual(_.isError(true), false);
8852 assert.strictEqual(_.isError(new Date), false);
8853 assert.strictEqual(_.isError(_), false);
8854 assert.strictEqual(_.isError(slice), false);
8855 assert.strictEqual(_.isError({ 'a': 1 }), false);
8856 assert.strictEqual(_.isError(1), false);
8857 assert.strictEqual(_.isError(/x/), false);
8858 assert.strictEqual(_.isError('a'), false);
8859 assert.strictEqual(_.isError(symbol), false);
8862 QUnit.test('should work with an error object from another realm', function(assert) {
8866 var expected = lodashStable.map(realm.errors, alwaysTrue);
8868 var actual = lodashStable.map(realm.errors, function(error) {
8869 return _.isError(error) === true;
8872 assert.deepEqual(actual, expected);
8880 /*--------------------------------------------------------------------------*/
8882 QUnit.module('lodash.isFinite');
8885 var args = arguments;
8887 QUnit.test('should return `true` for finite values', function(assert) {
8890 var values = [0, 1, 3.14, -1],
8891 expected = lodashStable.map(values, alwaysTrue),
8892 actual = lodashStable.map(values, _.isFinite);
8894 assert.deepEqual(actual, expected);
8897 QUnit.test('should return `false` for non-finite values', function(assert) {
8900 var values = [NaN, Infinity, -Infinity, Object(1)],
8901 expected = lodashStable.map(values, alwaysFalse),
8902 actual = lodashStable.map(values, _.isFinite);
8904 assert.deepEqual(actual, expected);
8907 QUnit.test('should return `false` for non-numeric values', function(assert) {
8910 var values = [undefined, [], true, '', ' ', '2px'],
8911 expected = lodashStable.map(values, alwaysFalse),
8912 actual = lodashStable.map(values, _.isFinite);
8914 assert.deepEqual(actual, expected);
8916 assert.strictEqual(_.isFinite(args), false);
8917 assert.strictEqual(_.isFinite([1, 2, 3]), false);
8918 assert.strictEqual(_.isFinite(true), false);
8919 assert.strictEqual(_.isFinite(new Date), false);
8920 assert.strictEqual(_.isFinite(new Error), false);
8921 assert.strictEqual(_.isFinite({ 'a': 1 }), false);
8922 assert.strictEqual(_.isFinite(/x/), false);
8923 assert.strictEqual(_.isFinite('a'), false);
8924 assert.strictEqual(_.isFinite(symbol), false);
8927 QUnit.test('should return `false` for numeric string values', function(assert) {
8930 var values = ['2', '0', '08'],
8931 expected = lodashStable.map(values, alwaysFalse),
8932 actual = lodashStable.map(values, _.isFinite);
8934 assert.deepEqual(actual, expected);
8938 /*--------------------------------------------------------------------------*/
8940 QUnit.module('lodash.isFunction');
8943 var args = arguments;
8945 QUnit.test('should return `true` for functions', function(assert) {
8948 assert.strictEqual(_.isFunction(_), true);
8949 assert.strictEqual(_.isFunction(slice), true);
8952 QUnit.test('should return `true` for generator functions', function(assert) {
8955 assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
8958 QUnit.test('should return `true` for typed array constructors', function(assert) {
8961 var expected = lodashStable.map(typedArrays, function(type) {
8962 return objToString.call(root[type]) == funcTag;
8965 var actual = lodashStable.map(typedArrays, function(type) {
8966 return _.isFunction(root[type]);
8969 assert.deepEqual(actual, expected);
8972 QUnit.test('should return `false` for non-functions', function(assert) {
8975 var expected = lodashStable.map(falsey, alwaysFalse);
8977 var actual = lodashStable.map(falsey, function(value, index) {
8978 return index ? _.isFunction(value) : _.isFunction();
8981 assert.deepEqual(actual, expected);
8983 assert.strictEqual(_.isFunction(args), false);
8984 assert.strictEqual(_.isFunction([1, 2, 3]), false);
8985 assert.strictEqual(_.isFunction(true), false);
8986 assert.strictEqual(_.isFunction(new Date), false);
8987 assert.strictEqual(_.isFunction(new Error), false);
8988 assert.strictEqual(_.isFunction({ 'a': 1 }), false);
8989 assert.strictEqual(_.isFunction(1), false);
8990 assert.strictEqual(_.isFunction(/x/), false);
8991 assert.strictEqual(_.isFunction('a'), false);
8992 assert.strictEqual(_.isFunction(symbol), false);
8995 assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
9001 QUnit.test('should work with host objects in IE 8 document mode (test in IE 11)', function(assert) {
9004 // Trigger a Chakra JIT bug.
9005 // See https://github.com/jashkenas/underscore/issues/1621.
9006 lodashStable.each([body, xml], function(object) {
9008 lodashStable.times(100, _.isFunction);
9009 assert.strictEqual(_.isFunction(object), false);
9017 QUnit.test('should work with a function from another realm', function(assert) {
9020 if (realm.function) {
9021 assert.strictEqual(_.isFunction(realm.function), true);
9029 /*--------------------------------------------------------------------------*/
9031 QUnit.module('isInteger methods');
9033 lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
9034 var args = arguments,
9035 func = _[methodName],
9036 isSafe = methodName == 'isSafeInteger';
9038 QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
9041 var values = [-1, 0, 1],
9042 expected = lodashStable.map(values, alwaysTrue);
9044 var actual = lodashStable.map(values, function(value) {
9048 assert.deepEqual(actual, expected);
9049 assert.strictEqual(func(MAX_INTEGER), !isSafe);
9052 QUnit.test('should return `false` for non-integer number values', function(assert) {
9055 var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
9056 expected = lodashStable.map(values, alwaysFalse);
9058 var actual = lodashStable.map(values, function(value) {
9062 assert.deepEqual(actual, expected);
9065 QUnit.test('should return `false` for non-numeric values', function(assert) {
9068 var expected = lodashStable.map(falsey, function(value) {
9072 var actual = lodashStable.map(falsey, function(value, index) {
9073 return index ? func(value) : func();
9076 assert.deepEqual(actual, expected);
9078 assert.strictEqual(func(args), false);
9079 assert.strictEqual(func([1, 2, 3]), false);
9080 assert.strictEqual(func(true), false);
9081 assert.strictEqual(func(new Date), false);
9082 assert.strictEqual(func(new Error), false);
9083 assert.strictEqual(func({ 'a': 1 }), false);
9084 assert.strictEqual(func(/x/), false);
9085 assert.strictEqual(func('a'), false);
9086 assert.strictEqual(func(symbol), false);
9090 /*--------------------------------------------------------------------------*/
9092 QUnit.module('lodash.isLength');
9095 QUnit.test('should return `true` for lengths', function(assert) {
9098 var values = [0, 3, MAX_SAFE_INTEGER],
9099 expected = lodashStable.map(values, alwaysTrue),
9100 actual = lodashStable.map(values, _.isLength);
9102 assert.deepEqual(actual, expected);
9105 QUnit.test('should return `false` for non-lengths', function(assert) {
9108 var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
9109 expected = lodashStable.map(values, alwaysFalse),
9110 actual = lodashStable.map(values, _.isLength);
9112 assert.deepEqual(actual, expected);
9116 /*--------------------------------------------------------------------------*/
9118 QUnit.module('lodash.isMatch');
9121 QUnit.test('should perform a deep comparison between `object` and `source`', function(assert) {
9124 var object = { 'a': 1, 'b': 2, 'c': 3 };
9125 assert.strictEqual(_.isMatch(object, { 'a': 1 }), true);
9126 assert.strictEqual(_.isMatch(object, { 'b': 1 }), false);
9127 assert.strictEqual(_.isMatch(object, { 'a': 1, 'c': 3 }), true);
9128 assert.strictEqual(_.isMatch(object, { 'c': 3, 'd': 4 }), false);
9130 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
9131 assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true);
9134 QUnit.test('should match inherited `object` properties', function(assert) {
9137 function Foo() { this.a = 1; }
9138 Foo.prototype.b = 2;
9140 assert.strictEqual(_.isMatch({ 'a': new Foo }, { 'a': { 'b': 2 } }), true);
9143 QUnit.test('should not match by inherited `source` properties', function(assert) {
9146 function Foo() { this.a = 1; }
9147 Foo.prototype.b = 2;
9149 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
9151 expected = lodashStable.map(objects, alwaysTrue);
9153 var actual = lodashStable.map(objects, function(object) {
9154 return _.isMatch(object, source);
9157 assert.deepEqual(actual, expected);
9160 QUnit.test('should compare a variety of `source` property values', function(assert) {
9163 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
9164 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } };
9166 assert.strictEqual(_.isMatch(object1, object1), true);
9167 assert.strictEqual(_.isMatch(object1, object2), false);
9170 QUnit.test('should match `-0` as `0`', function(assert) {
9173 var object1 = { 'a': -0 },
9174 object2 = { 'a': 0 };
9176 assert.strictEqual(_.isMatch(object1, object2), true);
9177 assert.strictEqual(_.isMatch(object2, object1), true);
9180 QUnit.test('should compare functions by reference', function(assert) {
9183 var object1 = { 'a': lodashStable.noop },
9184 object2 = { 'a': noop },
9185 object3 = { 'a': {} };
9187 assert.strictEqual(_.isMatch(object1, object1), true);
9188 assert.strictEqual(_.isMatch(object2, object1), false);
9189 assert.strictEqual(_.isMatch(object3, object1), false);
9192 QUnit.test('should work with a function for `object`', function(assert) {
9196 Foo.a = { 'b': 1, 'c': 2 };
9198 assert.strictEqual(_.isMatch(Foo, { 'a': { 'b': 1 } }), true);
9201 QUnit.test('should work with a function for `source`', function(assert) {
9206 Foo.b = function() {};
9209 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }];
9211 var actual = lodashStable.map(objects, function(object) {
9212 return _.isMatch(object, Foo);
9215 assert.deepEqual(actual, [false, true]);
9218 QUnit.test('should work with a non-plain `object`', function(assert) {
9221 function Foo(object) { lodashStable.assign(this, object); }
9223 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) });
9224 assert.strictEqual(_.isMatch(object, { 'a': { 'b': 1 } }), true);
9227 QUnit.test('should partial match arrays', function(assert) {
9230 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
9231 source = { 'a': ['d'] },
9232 predicate = function(object) { return _.isMatch(object, source); },
9233 actual = lodashStable.filter(objects, predicate);
9235 assert.deepEqual(actual, [objects[1]]);
9237 source = { 'a': ['b', 'd'] };
9238 actual = lodashStable.filter(objects, predicate);
9240 assert.deepEqual(actual, []);
9242 source = { 'a': ['d', 'b'] };
9243 actual = lodashStable.filter(objects, predicate);
9244 assert.deepEqual(actual, []);
9247 QUnit.test('should partial match arrays of objects', function(assert) {
9250 var source = { 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] };
9253 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
9254 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
9257 var actual = lodashStable.filter(objects, function(object) {
9258 return _.isMatch(object, source);
9261 assert.deepEqual(actual, [objects[0]]);
9264 QUnit.test('should partial match maps', function(assert) {
9268 var objects = [{ 'a': new Map }, { 'a': new Map }];
9269 objects[0].a.set('a', 1);
9270 objects[1].a.set('a', 1);
9271 objects[1].a.set('b', 2);
9276 var source = { 'a': map },
9277 predicate = function(object) { return _.isMatch(object, source); },
9278 actual = lodashStable.filter(objects, predicate);
9280 assert.deepEqual(actual, [objects[1]]);
9283 actual = lodashStable.filter(objects, predicate);
9285 assert.deepEqual(actual, objects);
9288 actual = lodashStable.filter(objects, predicate);
9290 assert.deepEqual(actual, []);
9293 skipTest(assert, 3);
9297 QUnit.test('should partial match sets', function(assert) {
9301 var objects = [{ 'a': new Set }, { 'a': new Set }];
9302 objects[0].a.add(1);
9303 objects[1].a.add(1);
9304 objects[1].a.add(2);
9309 var source = { 'a': set },
9310 predicate = function(object) { return _.isMatch(object, source); },
9311 actual = lodashStable.filter(objects, predicate);
9313 assert.deepEqual(actual, [objects[1]]);
9316 actual = lodashStable.filter(objects, predicate);
9318 assert.deepEqual(actual, objects);
9321 actual = lodashStable.filter(objects, predicate);
9323 assert.deepEqual(actual, []);
9326 skipTest(assert, 3);
9330 QUnit.test('should match `undefined` values', function(assert) {
9333 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
9334 source = { 'b': undefined },
9335 predicate = function(object) { return _.isMatch(object, source); },
9336 actual = lodashStable.map(objects, predicate),
9337 expected = [false, false, true];
9339 assert.deepEqual(actual, expected);
9341 source = { 'a': 1, 'b': undefined };
9342 actual = lodashStable.map(objects, predicate);
9344 assert.deepEqual(actual, expected);
9346 objects = [{ 'a': { 'b': 1 } }, { 'a':{ 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
9347 source = { 'a': { 'c': undefined } };
9348 actual = lodashStable.map(objects, predicate);
9350 assert.deepEqual(actual, expected);
9353 QUnit.test('should match `undefined` values on primitives', function(assert) {
9357 numberProto.b = undefined;
9360 assert.strictEqual(_.isMatch(1, { 'b': undefined }), true);
9362 assert.ok(false, e.message);
9365 assert.strictEqual(_.isMatch(1, { 'a': 1, 'b': undefined }), true);
9367 assert.ok(false, e.message);
9369 numberProto.a = { 'b': 1, 'c': undefined };
9371 assert.strictEqual(_.isMatch(1, { 'a': { 'c': undefined } }), true);
9373 assert.ok(false, e.message);
9375 delete numberProto.a;
9376 delete numberProto.b;
9379 QUnit.test('should return `false` when `object` is nullish', function(assert) {
9382 var values = [null, undefined],
9383 expected = lodashStable.map(values, alwaysFalse),
9384 source = { 'a': 1 };
9386 var actual = lodashStable.map(values, function(value) {
9388 return _.isMatch(value, source);
9392 assert.deepEqual(actual, expected);
9395 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
9398 var values = [null, undefined],
9399 expected = lodashStable.map(values, alwaysTrue),
9402 var actual = lodashStable.map(values, function(value) {
9404 return _.isMatch(value, source);
9408 assert.deepEqual(actual, expected);
9411 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
9414 var object = { 'a': 1 },
9415 expected = lodashStable.map(empties, alwaysTrue);
9417 var actual = lodashStable.map(empties, function(value) {
9418 return _.isMatch(object, value);
9421 assert.deepEqual(actual, expected);
9424 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
9427 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
9428 source = { 'a': [], 'b': {} };
9430 var actual = lodashStable.filter(objects, function(object) {
9431 return _.isMatch(object, source);
9434 assert.deepEqual(actual, objects);
9438 /*--------------------------------------------------------------------------*/
9440 QUnit.module('lodash.isMatchWith');
9443 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
9447 object1 = { 'a': [1, 2], 'b': null },
9448 object2 = { 'a': [1, 2], 'b': null };
9450 object1.b = object2;
9451 object2.b = object1;
9454 [object1.a, object2.a, 'a', object1, object2],
9455 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
9456 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
9457 [object1.b, object2.b, 'b', object1, object2],
9458 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
9459 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
9460 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
9461 [object1.b.b, object2.b.b, 'b', object1.b, object2.b],
9462 [object1.b.b.a, object2.b.b.a, 'a', object1.b.b, object2.b.b],
9463 [object1.b.b.a[0], object2.b.b.a[0], 0, object1.b.b.a, object2.b.b.a],
9464 [object1.b.b.a[1], object2.b.b.a[1], 1, object1.b.b.a, object2.b.b.a],
9465 [object1.b.b.b, object2.b.b.b, 'b', object1.b.b, object2.b.b]
9468 _.isMatchWith(object1, object2, function(assert) {
9469 argsList.push(slice.call(arguments, 0, -1));
9472 assert.deepEqual(argsList, expected);
9475 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
9478 assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
9481 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
9484 var customizer = function(value) {
9485 return _.isString(value) || undefined;
9488 assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
9489 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
9492 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
9495 var customizer = function(value) {
9496 return _.isString(value) ? false : undefined;
9499 assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
9500 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
9503 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
9506 var object = { 'a': 1 },
9507 actual = _.isMatchWith(object, { 'a': 1 }, alwaysA);
9509 assert.strictEqual(actual, true);
9511 var expected = lodashStable.map(falsey, alwaysFalse);
9514 lodashStable.each(falsey, function(value) {
9515 actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
9518 assert.deepEqual(actual, expected);
9521 QUnit.test('should ensure `customizer` is a function', function(assert) {
9524 var object = { 'a': 1 },
9525 matches = _.partial(_.isMatchWith, object),
9526 actual = lodashStable.map([object, { 'a': 2 }], matches);
9528 assert.deepEqual(actual, [true, false]);
9531 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
9534 var value = { 'a': { 'b': 2 } };
9538 map1.set('a', value);
9541 map2.set('a', value);
9550 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
9553 array = _.toArray(pair[0]),
9554 object1 = { 'a': pair[0] },
9555 object2 = { 'a': pair[1] };
9558 [pair[0], pair[1], 'a', object1, object2],
9559 [array[0], array[0], 0, array, array],
9560 [array[0][0], array[0][0], 0, array[0], array[0]],
9561 [array[0][1], array[0][1], 1, array[0], array[0]]
9565 expected.length = 2;
9567 _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
9568 argsList.push(slice.call(arguments, 0, -1));
9571 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
9580 /*--------------------------------------------------------------------------*/
9582 QUnit.module('lodash.isNaN');
9585 var args = arguments;
9587 QUnit.test('should return `true` for NaNs', function(assert) {
9590 assert.strictEqual(_.isNaN(NaN), true);
9591 assert.strictEqual(_.isNaN(Object(NaN)), true);
9594 QUnit.test('should return `false` for non-NaNs', function(assert) {
9597 var expected = lodashStable.map(falsey, function(value) {
9598 return value !== value;
9601 var actual = lodashStable.map(falsey, function(value, index) {
9602 return index ? _.isNaN(value) : _.isNaN();
9605 assert.deepEqual(actual, expected);
9607 assert.strictEqual(_.isNaN(args), false);
9608 assert.strictEqual(_.isNaN([1, 2, 3]), false);
9609 assert.strictEqual(_.isNaN(true), false);
9610 assert.strictEqual(_.isNaN(new Date), false);
9611 assert.strictEqual(_.isNaN(new Error), false);
9612 assert.strictEqual(_.isNaN(_), false);
9613 assert.strictEqual(_.isNaN(slice), false);
9614 assert.strictEqual(_.isNaN({ 'a': 1 }), false);
9615 assert.strictEqual(_.isNaN(1), false);
9616 assert.strictEqual(_.isNaN(Object(1)), false);
9617 assert.strictEqual(_.isNaN(/x/), false);
9618 assert.strictEqual(_.isNaN('a'), false);
9619 assert.strictEqual(_.isNaN(symbol), false);
9622 QUnit.test('should work with `NaN` from another realm', function(assert) {
9626 assert.strictEqual(_.isNaN(realm.nan), true);
9634 /*--------------------------------------------------------------------------*/
9636 QUnit.module('lodash.isNative');
9639 var args = arguments;
9641 QUnit.test('should return `true` for native methods', function(assert) {
9644 lodashStable.each([Array, create, root.encodeURI, slice, Uint8Array], function(func) {
9646 assert.strictEqual(_.isNative(func), true);
9654 assert.strictEqual(_.isNative(body.cloneNode), true);
9661 QUnit.test('should return `false` for non-native methods', function(assert) {
9664 var expected = lodashStable.map(falsey, alwaysFalse);
9666 var actual = lodashStable.map(falsey, function(value, index) {
9667 return index ? _.isNative(value) : _.isNative();
9670 assert.deepEqual(actual, expected);
9672 assert.strictEqual(_.isNative(args), false);
9673 assert.strictEqual(_.isNative([1, 2, 3]), false);
9674 assert.strictEqual(_.isNative(true), false);
9675 assert.strictEqual(_.isNative(new Date), false);
9676 assert.strictEqual(_.isNative(new Error), false);
9677 assert.strictEqual(_.isNative(_), false);
9678 assert.strictEqual(_.isNative({ 'a': 1 }), false);
9679 assert.strictEqual(_.isNative(1), false);
9680 assert.strictEqual(_.isNative(/x/), false);
9681 assert.strictEqual(_.isNative('a'), false);
9682 assert.strictEqual(_.isNative(symbol), false);
9685 QUnit.test('should work with native functions from another realm', function(assert) {
9688 if (realm.element) {
9689 assert.strictEqual(_.isNative(realm.element.cloneNode), true);
9695 assert.strictEqual(_.isNative(realm.object.valueOf), true);
9703 /*--------------------------------------------------------------------------*/
9705 QUnit.module('lodash.isNull');
9708 var args = arguments;
9710 QUnit.test('should return `true` for `null` values', function(assert) {
9713 assert.strictEqual(_.isNull(null), true);
9716 QUnit.test('should return `false` for non `null` values', function(assert) {
9719 var expected = lodashStable.map(falsey, function(value) {
9720 return value === null;
9723 var actual = lodashStable.map(falsey, function(value, index) {
9724 return index ? _.isNull(value) : _.isNull();
9727 assert.deepEqual(actual, expected);
9729 assert.strictEqual(_.isNull(args), false);
9730 assert.strictEqual(_.isNull([1, 2, 3]), false);
9731 assert.strictEqual(_.isNull(true), false);
9732 assert.strictEqual(_.isNull(new Date), false);
9733 assert.strictEqual(_.isNull(new Error), false);
9734 assert.strictEqual(_.isNull(_), false);
9735 assert.strictEqual(_.isNull(slice), false);
9736 assert.strictEqual(_.isNull({ 'a': 1 }), false);
9737 assert.strictEqual(_.isNull(1), false);
9738 assert.strictEqual(_.isNull(/x/), false);
9739 assert.strictEqual(_.isNull('a'), false);
9740 assert.strictEqual(_.isNull(symbol), false);
9743 QUnit.test('should work with nulls from another realm', function(assert) {
9747 assert.strictEqual(_.isNull(realm.null), true);
9755 /*--------------------------------------------------------------------------*/
9757 QUnit.module('lodash.isNil');
9760 var args = arguments;
9762 QUnit.test('should return `true` for nullish values', function(assert) {
9765 assert.strictEqual(_.isNil(null), true);
9766 assert.strictEqual(_.isNil(), true);
9767 assert.strictEqual(_.isNil(undefined), true);
9770 QUnit.test('should return `false` for non-nullish values', function(assert) {
9773 var expected = lodashStable.map(falsey, function(value) {
9774 return value == null;
9777 var actual = lodashStable.map(falsey, function(value, index) {
9778 return index ? _.isNil(value) : _.isNil();
9781 assert.deepEqual(actual, expected);
9783 assert.strictEqual(_.isNil(args), false);
9784 assert.strictEqual(_.isNil([1, 2, 3]), false);
9785 assert.strictEqual(_.isNil(true), false);
9786 assert.strictEqual(_.isNil(new Date), false);
9787 assert.strictEqual(_.isNil(new Error), false);
9788 assert.strictEqual(_.isNil(_), false);
9789 assert.strictEqual(_.isNil(slice), false);
9790 assert.strictEqual(_.isNil({ 'a': 1 }), false);
9791 assert.strictEqual(_.isNil(1), false);
9792 assert.strictEqual(_.isNil(/x/), false);
9793 assert.strictEqual(_.isNil('a'), false);
9796 assert.strictEqual(_.isNil(symbol), false);
9803 QUnit.test('should work with nulls from another realm', function(assert) {
9807 assert.strictEqual(_.isNil(realm.null), true);
9808 assert.strictEqual(_.isNil(realm.undefined), true);
9811 skipTest(assert, 2);
9816 /*--------------------------------------------------------------------------*/
9818 QUnit.module('lodash.isNumber');
9821 var args = arguments;
9823 QUnit.test('should return `true` for numbers', function(assert) {
9826 assert.strictEqual(_.isNumber(0), true);
9827 assert.strictEqual(_.isNumber(Object(0)), true);
9828 assert.strictEqual(_.isNumber(NaN), true);
9831 QUnit.test('should return `false` for non-numbers', function(assert) {
9834 var expected = lodashStable.map(falsey, function(value) {
9835 return typeof value == 'number';
9838 var actual = lodashStable.map(falsey, function(value, index) {
9839 return index ? _.isNumber(value) : _.isNumber();
9842 assert.deepEqual(actual, expected);
9844 assert.strictEqual(_.isNumber(args), false);
9845 assert.strictEqual(_.isNumber([1, 2, 3]), false);
9846 assert.strictEqual(_.isNumber(true), false);
9847 assert.strictEqual(_.isNumber(new Date), false);
9848 assert.strictEqual(_.isNumber(new Error), false);
9849 assert.strictEqual(_.isNumber(_), false);
9850 assert.strictEqual(_.isNumber(slice), false);
9851 assert.strictEqual(_.isNumber({ 'a': 1 }), false);
9852 assert.strictEqual(_.isNumber(/x/), false);
9853 assert.strictEqual(_.isNumber('a'), false);
9854 assert.strictEqual(_.isNumber(symbol), false);
9857 QUnit.test('should work with numbers from another realm', function(assert) {
9861 assert.strictEqual(_.isNumber(realm.number), true);
9868 QUnit.test('should avoid `[xpconnect wrapped native prototype]` in Firefox', function(assert) {
9871 assert.strictEqual(_.isNumber(+'2'), true);
9875 /*--------------------------------------------------------------------------*/
9877 QUnit.module('lodash.isObject');
9880 var args = arguments;
9882 QUnit.test('should return `true` for objects', function(assert) {
9885 assert.strictEqual(_.isObject(args), true);
9886 assert.strictEqual(_.isObject([1, 2, 3]), true);
9887 assert.strictEqual(_.isObject(Object(false)), true);
9888 assert.strictEqual(_.isObject(new Date), true);
9889 assert.strictEqual(_.isObject(new Error), true);
9890 assert.strictEqual(_.isObject(_), true);
9891 assert.strictEqual(_.isObject(slice), true);
9892 assert.strictEqual(_.isObject({ 'a': 1 }), true);
9893 assert.strictEqual(_.isObject(Object(0)), true);
9894 assert.strictEqual(_.isObject(/x/), true);
9895 assert.strictEqual(_.isObject(Object('a')), true);
9898 assert.strictEqual(_.isObject(body), true);
9904 assert.strictEqual(_.isObject(Object(symbol)), true);
9911 QUnit.test('should return `false` for non-objects', function(assert) {
9914 var values = falsey.concat(true, 1, 'a', symbol),
9915 expected = lodashStable.map(values, alwaysFalse);
9917 var actual = lodashStable.map(values, function(value, index) {
9918 return index ? _.isObject(value) : _.isObject();
9921 assert.deepEqual(actual, expected);
9924 QUnit.test('should work with objects from another realm', function(assert) {
9927 if (realm.element) {
9928 assert.strictEqual(_.isObject(realm.element), true);
9934 assert.strictEqual(_.isObject(realm.boolean), true);
9935 assert.strictEqual(_.isObject(realm.date), true);
9936 assert.strictEqual(_.isObject(realm.function), true);
9937 assert.strictEqual(_.isObject(realm.number), true);
9938 assert.strictEqual(_.isObject(realm.object), true);
9939 assert.strictEqual(_.isObject(realm.regexp), true);
9940 assert.strictEqual(_.isObject(realm.string), true);
9943 skipTest(assert, 7);
9947 QUnit.test('should avoid V8 bug #2291 (test in Chrome 19-20)', function(assert) {
9950 // Trigger a V8 JIT bug.
9951 // See https://code.google.com/p/v8/issues/detail?id=2291.
9954 // 1: Useless comparison statement, this is half the trigger.
9957 // 2: Initial check with object, this is the other half of the trigger.
9960 assert.strictEqual(_.isObject('a'), false);
9964 /*--------------------------------------------------------------------------*/
9966 QUnit.module('lodash.isObjectLike');
9969 var args = arguments;
9971 QUnit.test('should return `true` for objects', function(assert) {
9974 assert.strictEqual(_.isObjectLike(args), true);
9975 assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
9976 assert.strictEqual(_.isObjectLike(Object(false)), true);
9977 assert.strictEqual(_.isObjectLike(new Date), true);
9978 assert.strictEqual(_.isObjectLike(new Error), true);
9979 assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
9980 assert.strictEqual(_.isObjectLike(Object(0)), true);
9981 assert.strictEqual(_.isObjectLike(/x/), true);
9982 assert.strictEqual(_.isObjectLike(Object('a')), true);
9985 QUnit.test('should return `false` for non-objects', function(assert) {
9988 var values = falsey.concat(true, _, slice, 1, 'a', symbol),
9989 expected = lodashStable.map(values, alwaysFalse);
9991 var actual = lodashStable.map(values, function(value, index) {
9992 return index ? _.isObjectLike(value) : _.isObjectLike();
9995 assert.deepEqual(actual, expected);
9998 QUnit.test('should work with objects from another realm', function(assert) {
10001 if (realm.object) {
10002 assert.strictEqual(_.isObjectLike(realm.boolean), true);
10003 assert.strictEqual(_.isObjectLike(realm.date), true);
10004 assert.strictEqual(_.isObjectLike(realm.number), true);
10005 assert.strictEqual(_.isObjectLike(realm.object), true);
10006 assert.strictEqual(_.isObjectLike(realm.regexp), true);
10007 assert.strictEqual(_.isObjectLike(realm.string), true);
10010 skipTest(assert, 6);
10015 /*--------------------------------------------------------------------------*/
10017 QUnit.module('lodash.isPlainObject');
10020 var element = document && document.createElement('div');
10022 QUnit.test('should detect plain objects', function(assert) {
10029 assert.strictEqual(_.isPlainObject({}), true);
10030 assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
10031 assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
10032 assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
10033 assert.strictEqual(_.isPlainObject(new Foo(1)), false);
10036 QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
10040 var object = create(null);
10041 assert.strictEqual(_.isPlainObject(object), true);
10043 object.constructor = objectProto.constructor;
10044 assert.strictEqual(_.isPlainObject(object), true);
10047 skipTest(assert, 2);
10051 QUnit.test('should return `true` for plain objects with a custom `valueOf` property', function(assert) {
10054 assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
10057 var valueOf = element.valueOf;
10058 element.valueOf = 0;
10060 assert.strictEqual(_.isPlainObject(element), false);
10061 element.valueOf = valueOf;
10068 QUnit.test('should return `false` for DOM elements', function(assert) {
10072 assert.strictEqual(_.isPlainObject(element), false);
10078 QUnit.test('should return `false` for Object objects without a `toStringTag` of "Object"', function(assert) {
10081 assert.strictEqual(_.isPlainObject(arguments), false);
10082 assert.strictEqual(_.isPlainObject(Error), false);
10083 assert.strictEqual(_.isPlainObject(Math), false);
10086 QUnit.test('should return `false` for non-objects', function(assert) {
10089 var expected = lodashStable.map(falsey, alwaysFalse);
10091 var actual = lodashStable.map(falsey, function(value, index) {
10092 return index ? _.isPlainObject(value) : _.isPlainObject();
10095 assert.deepEqual(actual, expected);
10097 assert.strictEqual(_.isPlainObject(true), false);
10098 assert.strictEqual(_.isPlainObject('a'), false);
10099 assert.strictEqual(_.isPlainObject(symbol), false);
10102 QUnit.test('should work with objects from another realm', function(assert) {
10105 if (realm.object) {
10106 assert.strictEqual(_.isPlainObject(realm.object), true);
10114 /*--------------------------------------------------------------------------*/
10116 QUnit.module('lodash.isRegExp');
10119 var args = arguments;
10121 QUnit.test('should return `true` for regexes', function(assert) {
10124 assert.strictEqual(_.isRegExp(/x/), true);
10125 assert.strictEqual(_.isRegExp(RegExp('x')), true);
10128 QUnit.test('should return `false` for non-regexes', function(assert) {
10131 var expected = lodashStable.map(falsey, alwaysFalse);
10133 var actual = lodashStable.map(falsey, function(value, index) {
10134 return index ? _.isRegExp(value) : _.isRegExp();
10137 assert.deepEqual(actual, expected);
10139 assert.strictEqual(_.isRegExp(args), false);
10140 assert.strictEqual(_.isRegExp([1, 2, 3]), false);
10141 assert.strictEqual(_.isRegExp(true), false);
10142 assert.strictEqual(_.isRegExp(new Date), false);
10143 assert.strictEqual(_.isRegExp(new Error), false);
10144 assert.strictEqual(_.isRegExp(_), false);
10145 assert.strictEqual(_.isRegExp(slice), false);
10146 assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
10147 assert.strictEqual(_.isRegExp(1), false);
10148 assert.strictEqual(_.isRegExp('a'), false);
10149 assert.strictEqual(_.isRegExp(symbol), false);
10152 QUnit.test('should work with regexes from another realm', function(assert) {
10155 if (realm.regexp) {
10156 assert.strictEqual(_.isRegExp(realm.regexp), true);
10164 /*--------------------------------------------------------------------------*/
10166 QUnit.module('lodash.isString');
10169 var args = arguments;
10171 QUnit.test('should return `true` for strings', function(assert) {
10174 assert.strictEqual(_.isString('a'), true);
10175 assert.strictEqual(_.isString(Object('a')), true);
10178 QUnit.test('should return `false` for non-strings', function(assert) {
10181 var expected = lodashStable.map(falsey, function(value) {
10182 return value === '';
10185 var actual = lodashStable.map(falsey, function(value, index) {
10186 return index ? _.isString(value) : _.isString();
10189 assert.deepEqual(actual, expected);
10191 assert.strictEqual(_.isString(args), false);
10192 assert.strictEqual(_.isString([1, 2, 3]), false);
10193 assert.strictEqual(_.isString(true), false);
10194 assert.strictEqual(_.isString(new Date), false);
10195 assert.strictEqual(_.isString(new Error), false);
10196 assert.strictEqual(_.isString(_), false);
10197 assert.strictEqual(_.isString(slice), false);
10198 assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
10199 assert.strictEqual(_.isString(1), false);
10200 assert.strictEqual(_.isString(/x/), false);
10201 assert.strictEqual(_.isString(symbol), false);
10204 QUnit.test('should work with strings from another realm', function(assert) {
10207 if (realm.string) {
10208 assert.strictEqual(_.isString(realm.string), true);
10216 /*--------------------------------------------------------------------------*/
10218 QUnit.module('lodash.isSymbol');
10221 var args = arguments;
10223 QUnit.test('should return `true` for symbols', function(assert) {
10227 assert.strictEqual(_.isSymbol(symbol), true);
10228 assert.strictEqual(_.isSymbol(Object(symbol)), true);
10231 skipTest(assert, 2);
10235 QUnit.test('should return `false` for non-symbols', function(assert) {
10238 var expected = lodashStable.map(falsey, alwaysFalse);
10240 var actual = lodashStable.map(falsey, function(value, index) {
10241 return index ? _.isSymbol(value) : _.isSymbol();
10244 assert.deepEqual(actual, expected);
10246 assert.strictEqual(_.isSymbol(args), false);
10247 assert.strictEqual(_.isSymbol([1, 2, 3]), false);
10248 assert.strictEqual(_.isSymbol(true), false);
10249 assert.strictEqual(_.isSymbol(new Date), false);
10250 assert.strictEqual(_.isSymbol(new Error), false);
10251 assert.strictEqual(_.isSymbol(_), false);
10252 assert.strictEqual(_.isSymbol(slice), false);
10253 assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
10254 assert.strictEqual(_.isSymbol(1), false);
10255 assert.strictEqual(_.isSymbol(/x/), false);
10256 assert.strictEqual(_.isSymbol('a'), false);
10259 QUnit.test('should work with symbols from another realm', function(assert) {
10262 if (Symbol && realm.symbol) {
10263 assert.strictEqual(_.isSymbol(realm.symbol), true);
10271 /*--------------------------------------------------------------------------*/
10273 QUnit.module('lodash.isTypedArray');
10276 var args = arguments;
10278 QUnit.test('should return `true` for typed arrays', function(assert) {
10281 var expected = lodashStable.map(typedArrays, function(type) {
10282 return type in root;
10285 var actual = lodashStable.map(typedArrays, function(type) {
10286 var Ctor = root[type];
10287 return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
10290 assert.deepEqual(actual, expected);
10293 QUnit.test('should return `false` for non typed arrays', function(assert) {
10296 var expected = lodashStable.map(falsey, alwaysFalse);
10298 var actual = lodashStable.map(falsey, function(value, index) {
10299 return index ? _.isTypedArray(value) : _.isTypedArray();
10302 assert.deepEqual(actual, expected);
10304 assert.strictEqual(_.isTypedArray(args), false);
10305 assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
10306 assert.strictEqual(_.isTypedArray(true), false);
10307 assert.strictEqual(_.isTypedArray(new Date), false);
10308 assert.strictEqual(_.isTypedArray(new Error), false);
10309 assert.strictEqual(_.isTypedArray(_), false);
10310 assert.strictEqual(_.isTypedArray(slice), false);
10311 assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
10312 assert.strictEqual(_.isTypedArray(1), false);
10313 assert.strictEqual(_.isTypedArray(/x/), false);
10314 assert.strictEqual(_.isTypedArray('a'), false);
10315 assert.strictEqual(_.isTypedArray(symbol), false);
10318 QUnit.test('should work with typed arrays from another realm', function(assert) {
10321 if (realm.object) {
10322 var invoke = lodashStable.invokeMap || lodashStable.invoke,
10323 props = invoke(typedArrays, 'toLowerCase');
10325 var expected = lodashStable.map(props, function(key) {
10326 return key in realm;
10329 var actual = lodashStable.map(props, function(key) {
10330 var value = realm[key];
10331 return value ? _.isTypedArray(value) : false;
10334 assert.deepEqual(actual, expected);
10342 /*--------------------------------------------------------------------------*/
10344 QUnit.module('lodash.isUndefined');
10347 var args = arguments;
10349 QUnit.test('should return `true` for `undefined` values', function(assert) {
10352 assert.strictEqual(_.isUndefined(), true);
10353 assert.strictEqual(_.isUndefined(undefined), true);
10356 QUnit.test('should return `false` for non `undefined` values', function(assert) {
10359 var expected = lodashStable.map(falsey, function(value) {
10360 return value === undefined;
10363 var actual = lodashStable.map(falsey, function(value, index) {
10364 return index ? _.isUndefined(value) : _.isUndefined();
10367 assert.deepEqual(actual, expected);
10369 assert.strictEqual(_.isUndefined(args), false);
10370 assert.strictEqual(_.isUndefined([1, 2, 3]), false);
10371 assert.strictEqual(_.isUndefined(true), false);
10372 assert.strictEqual(_.isUndefined(new Date), false);
10373 assert.strictEqual(_.isUndefined(new Error), false);
10374 assert.strictEqual(_.isUndefined(_), false);
10375 assert.strictEqual(_.isUndefined(slice), false);
10376 assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
10377 assert.strictEqual(_.isUndefined(1), false);
10378 assert.strictEqual(_.isUndefined(/x/), false);
10379 assert.strictEqual(_.isUndefined('a'), false);
10382 assert.strictEqual(_.isUndefined(symbol), false);
10389 QUnit.test('should work with `undefined` from another realm', function(assert) {
10392 if (realm.object) {
10393 assert.strictEqual(_.isUndefined(realm.undefined), true);
10401 /*--------------------------------------------------------------------------*/
10403 QUnit.module('isType checks');
10406 QUnit.test('should return `false` for subclassed values', function(assert) {
10410 'isArray', 'isBoolean', 'isDate', 'isError',
10411 'isFunction', 'isNumber', 'isRegExp', 'isString'
10414 lodashStable.each(funcs, function(methodName) {
10416 Foo.prototype = root[methodName.slice(2)].prototype;
10418 var object = new Foo;
10419 if (objToString.call(object) == objectTag) {
10420 assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
10427 QUnit.test('should not error on host objects (test in IE)', function(assert) {
10431 'isArguments', 'isArray', 'isArrayLike', 'isBoolean', 'isDate',
10432 'isElement', 'isError', 'isFinite', 'isFunction', 'isInteger', 'isNaN',
10433 'isNil', 'isNull', 'isNumber', 'isObject', 'isObjectLike', 'isRegExp',
10434 'isSafeInteger', 'isString', 'isUndefined'
10437 lodashStable.each(funcs, function(methodName) {
10442 _[methodName](xml);
10446 assert.ok(pass, '`_.' + methodName + '` should not error');
10455 /*--------------------------------------------------------------------------*/
10457 QUnit.module('lodash.iteratee');
10460 QUnit.test('should provide arguments to `func`', function(assert) {
10463 var fn = function() { return slice.call(arguments); },
10464 iteratee = _.iteratee(fn),
10465 actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
10467 assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
10470 QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
10474 values = [, null, undefined],
10475 expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
10477 var actual = lodashStable.map(values, function(value, index) {
10478 var identity = index ? _.iteratee(value) : _.iteratee();
10479 return [!isNpm && identity, identity(object)];
10482 assert.deepEqual(actual, expected);
10485 QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
10488 var matches = _.iteratee({ 'a': 1, 'b': 2 });
10489 assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
10490 assert.strictEqual(matches({ 'b': 2 }), false);
10493 QUnit.test('should not change behavior if `source` is modified', function(assert) {
10497 { 'a': { 'b': 2, 'c': 3 } },
10498 { 'a': 1, 'b': 2 },
10502 lodashStable.each(sources, function(source, index) {
10503 var object = lodashStable.cloneDeep(source),
10504 matches = _.iteratee(source);
10506 assert.strictEqual(matches(object), true);
10517 assert.strictEqual(matches(object), true);
10518 assert.strictEqual(matches(source), false);
10522 QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is a number or string and a value is provided', function(assert) {
10525 var array = ['a', undefined],
10526 matches = _.iteratee([0, 'a']);
10528 assert.strictEqual(matches(array), true);
10530 matches = _.iteratee(['0', 'a']);
10531 assert.strictEqual(matches(array), true);
10533 matches = _.iteratee([1, undefined]);
10534 assert.strictEqual(matches(array), true);
10537 QUnit.test('should support deep paths for "_.matchesProperty" shorthands', function(assert) {
10540 var object = { 'a': { 'b': { 'c': { 'd': 1, 'e': 2 } } } },
10541 matches = _.iteratee(['a.b.c', { 'e': 2 }]);
10543 assert.strictEqual(matches(object), true);
10546 QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
10550 prop = _.iteratee(0);
10552 assert.strictEqual(prop(array), 'a');
10554 prop = _.iteratee('0');
10555 assert.strictEqual(prop(array), 'a');
10558 QUnit.test('should support deep paths for "_.property" shorthands', function(assert) {
10561 var object = { 'a': { 'b': { 'c': 3 } } },
10562 prop = _.iteratee('a.b.c');
10564 assert.strictEqual(prop(object), 3);
10567 QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
10570 var fn = function() {
10571 var result = [this.a];
10572 push.apply(result, arguments);
10576 var expected = [1, 2, 3],
10577 object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
10579 assert.deepEqual(object.iteratee(3), expected);
10581 object.iteratee = _.iteratee(_.partialRight(fn, 3));
10582 assert.deepEqual(object.iteratee(2), expected);
10585 QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
10588 var iteratee = _.iteratee;
10591 assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
10593 _.iteratee = iteratee;
10596 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
10599 var fn = function() { return this instanceof Number; },
10600 array = [fn, fn, fn],
10601 iteratees = lodashStable.map(array, _.iteratee),
10602 expected = lodashStable.map(array, alwaysFalse);
10604 var actual = lodashStable.map(iteratees, function(iteratee) {
10608 assert.deepEqual(actual, expected);
10612 /*--------------------------------------------------------------------------*/
10614 QUnit.module('custom `_.iteratee` methods');
10617 var array = ['one', 'two', 'three'],
10618 getPropA = _.partial(_.property, 'a'),
10619 getPropB = _.partial(_.property, 'b'),
10620 getLength = _.partial(_.property, 'length'),
10621 iteratee = _.iteratee;
10623 var getSum = function() {
10624 return function(result, object) {
10625 return result + object.a;
10630 { 'a': 0, 'b': 0 },
10631 { 'a': 1, 'b': 0 },
10635 QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
10638 if (!isModularize) {
10639 _.iteratee = getLength;
10640 assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
10641 _.iteratee = iteratee;
10648 QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
10651 if (!isModularize) {
10652 _.iteratee = getPropA;
10653 assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
10654 _.iteratee = iteratee;
10661 QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
10664 if (!isModularize) {
10665 _.iteratee = getPropB;
10666 assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
10667 _.iteratee = iteratee;
10674 QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
10677 if (!isModularize) {
10678 _.iteratee = getPropB;
10679 assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
10680 _.iteratee = iteratee;
10687 QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
10690 if (!isModularize) {
10691 _.iteratee = getPropA;
10692 assert.strictEqual(_.every(objects.slice(1)), true);
10693 _.iteratee = iteratee;
10700 QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
10703 if (!isModularize) {
10704 var objects = [{ 'a': 0 }, { 'a': 1 }];
10706 _.iteratee = getPropA;
10707 assert.deepEqual(_.filter(objects), [objects[1]]);
10708 _.iteratee = iteratee;
10715 QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
10718 if (!isModularize) {
10719 _.iteratee = getPropA;
10720 assert.strictEqual(_.find(objects), objects[1]);
10721 _.iteratee = iteratee;
10728 QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
10731 if (!isModularize) {
10732 _.iteratee = getPropA;
10733 assert.strictEqual(_.findIndex(objects), 1);
10734 _.iteratee = iteratee;
10741 QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
10744 if (!isModularize) {
10745 _.iteratee = getPropA;
10746 assert.strictEqual(_.findLast(objects), objects[2]);
10747 _.iteratee = iteratee;
10754 QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
10757 if (!isModularize) {
10758 _.iteratee = getPropA;
10759 assert.strictEqual(_.findLastIndex(objects), 2);
10760 _.iteratee = iteratee;
10767 QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
10770 if (!isModularize) {
10771 _.iteratee = getPropB;
10772 assert.strictEqual(_.findKey(objects), '2');
10773 _.iteratee = iteratee;
10780 QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
10783 if (!isModularize) {
10784 _.iteratee = getPropB;
10785 assert.strictEqual(_.findLastKey(objects), '2');
10786 _.iteratee = iteratee;
10793 QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
10796 if (!isModularize) {
10797 _.iteratee = getLength;
10798 assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
10799 _.iteratee = iteratee;
10806 QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
10809 if (!isModularize) {
10810 _.iteratee = getPropA;
10811 assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
10812 _.iteratee = iteratee;
10819 QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
10822 if (!isModularize) {
10823 _.iteratee = getLength;
10824 assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
10825 _.iteratee = iteratee;
10832 QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
10835 if (!isModularize) {
10836 _.iteratee = getPropA;
10837 assert.deepEqual(_.map(objects), [0, 1, 1]);
10838 _.iteratee = iteratee;
10845 QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
10848 if (!isModularize) {
10849 _.iteratee = getPropB;
10850 assert.deepEqual(_.mapKeys({ 'a': { 'b': 1 } }), { '1': { 'b': 1 } });
10851 _.iteratee = iteratee;
10858 QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
10861 if (!isModularize) {
10862 _.iteratee = getPropB;
10863 assert.deepEqual(_.mapValues({ 'a': { 'b': 1 } }), { 'a': 1 });
10864 _.iteratee = iteratee;
10871 QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
10874 if (!isModularize) {
10875 _.iteratee = getPropB;
10876 assert.deepEqual(_.maxBy(objects), objects[2]);
10877 _.iteratee = iteratee;
10884 QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
10887 if (!isModularize) {
10888 _.iteratee = getPropB;
10889 assert.deepEqual(_.minBy(objects), objects[0]);
10890 _.iteratee = iteratee;
10897 QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
10900 if (!isModularize) {
10901 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
10903 _.iteratee = getPropA;
10904 assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
10905 _.iteratee = iteratee;
10912 QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
10915 if (!isModularize) {
10916 _.iteratee = getPropA;
10917 assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
10918 _.iteratee = iteratee;
10925 QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
10928 if (!isModularize) {
10929 _.iteratee = getSum;
10930 assert.strictEqual(_.reduce(objects, undefined, 0), 2);
10931 _.iteratee = iteratee;
10938 QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
10941 if (!isModularize) {
10942 _.iteratee = getSum;
10943 assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
10944 _.iteratee = iteratee;
10951 QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
10954 if (!isModularize) {
10955 var objects = [{ 'a': 0 }, { 'a': 1 }];
10957 _.iteratee = getPropA;
10958 assert.deepEqual(_.reject(objects), [objects[0]]);
10959 _.iteratee = iteratee;
10966 QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
10969 if (!isModularize) {
10970 var objects = [{ 'a': 0 }, { 'a': 1 }];
10972 _.iteratee = getPropA;
10974 assert.deepEqual(objects, [{ 'a': 0 }]);
10975 _.iteratee = iteratee;
10982 QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
10985 if (!isModularize) {
10986 _.iteratee = getPropB;
10987 assert.strictEqual(_.some(objects), true);
10988 _.iteratee = iteratee;
10995 QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
10998 if (!isModularize) {
10999 _.iteratee = getPropA;
11000 assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
11001 _.iteratee = iteratee;
11008 QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
11011 if (!isModularize) {
11012 var objects = [{ 'a': 30 }, { 'a': 50 }];
11014 _.iteratee = getPropA;
11015 assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
11016 _.iteratee = iteratee;
11023 QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
11026 if (!isModularize) {
11027 var objects = [{ 'a': 30 }, { 'a': 50 }];
11029 _.iteratee = getPropA;
11030 assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
11031 _.iteratee = iteratee;
11038 QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
11041 if (!isModularize) {
11042 _.iteratee = getPropB;
11043 assert.strictEqual(_.sumBy(objects), 1);
11044 _.iteratee = iteratee;
11051 QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
11054 if (!isModularize) {
11055 _.iteratee = getPropB;
11056 assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
11057 _.iteratee = iteratee;
11064 QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
11067 if (!isModularize) {
11068 _.iteratee = getPropB;
11069 assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
11070 _.iteratee = iteratee;
11077 QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
11080 if (!isModularize) {
11081 _.iteratee = function() {
11082 return function(result, object) {
11083 result.sum += object.a;
11087 assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
11088 _.iteratee = iteratee;
11095 QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
11098 if (!isModularize) {
11099 _.iteratee = getPropB;
11100 assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
11101 _.iteratee = iteratee;
11108 QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
11111 if (!isModularize) {
11112 _.iteratee = getPropB;
11113 assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
11114 _.iteratee = iteratee;
11121 QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
11124 if (!isModularize) {
11125 _.iteratee = getPropA;
11126 assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
11127 _.iteratee = iteratee;
11135 /*--------------------------------------------------------------------------*/
11137 QUnit.module('lodash.join');
11140 var array = ['a', 'b', 'c'];
11142 QUnit.test('should return join all array elements into a string', function(assert) {
11145 assert.strictEqual(_.join(array, '~'), 'a~b~c');
11148 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
11152 var wrapped = _(array);
11153 assert.strictEqual(wrapped.join('~'), 'a~b~c');
11154 assert.strictEqual(wrapped.value(), array);
11157 skipTest(assert, 2);
11161 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
11165 assert.ok(_(array).chain().join('~') instanceof _);
11173 /*--------------------------------------------------------------------------*/
11175 QUnit.module('lodash.keyBy');
11178 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
11181 var array = [4, 6, 6],
11182 values = [, null, undefined],
11183 expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
11185 var actual = lodashStable.map(values, function(value, index) {
11186 return index ? _.keyBy(array, value) : _.keyBy(array);
11189 assert.deepEqual(actual, expected);
11192 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
11195 var actual = _.keyBy(['one', 'two', 'three'], 'length');
11196 assert.deepEqual(actual, { '3': 'two', '5': 'three' });
11199 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
11202 var actual = _.keyBy([4.2, 6.1, 6.4], function(num) {
11203 return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor';
11206 assert.deepEqual(actual.constructor, 4.2);
11207 assert.deepEqual(actual.hasOwnProperty, 6.4);
11210 QUnit.test('should work with a number for `iteratee`', function(assert) {
11219 assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
11220 assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
11223 QUnit.test('should work with an object for `collection`', function(assert) {
11226 var actual = _.keyBy({ 'a': 4.2, 'b': 6.1, 'c': 6.4 }, function(num) {
11227 return Math.floor(num);
11230 assert.deepEqual(actual, { '4': 4.2, '6': 6.4 });
11233 QUnit.test('should work in a lazy sequence', function(assert) {
11237 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
11238 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
11239 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
11242 var actual = _(array).keyBy().map(square).filter(isEven).take().value();
11244 assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
11252 /*--------------------------------------------------------------------------*/
11254 QUnit.module('keys methods');
11256 lodashStable.each(['keys', 'keysIn'], function(methodName) {
11257 var args = (function() { return arguments; }(1, 2, 3)),
11258 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
11259 func = _[methodName],
11260 isKeys = methodName == 'keys';
11262 QUnit.test('`_.' + methodName + '` should return the keys of an object', function(assert) {
11265 assert.deepEqual(func({ 'a': 1, 'b': 1 }).sort(), ['a', 'b']);
11268 QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
11271 assert.deepEqual(func('abc').sort(), ['0', '1', '2']);
11273 // IE 9 doesn't box numbers in for-in loops.
11275 assert.deepEqual(func(0), isKeys ? [] : ['a']);
11276 delete numberProto.a;
11279 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
11285 assert.deepEqual(func(array).sort(), ['0', '1', '2']);
11288 QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) {
11292 lodashStable.each([null, undefined], function(value) {
11293 assert.deepEqual(func(value), []);
11295 delete objectProto.a;
11298 QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
11304 assert.deepEqual(func(array).sort(), ['0', 'a']);
11307 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of arrays', function(assert) {
11310 var expected = isKeys ? ['0'] : ['0', 'a'];
11313 assert.deepEqual(func([1]).sort(), expected);
11314 delete arrayProto.a;
11317 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
11320 var values = [args, strictArgs],
11321 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2'])),
11322 actual = lodashStable.map(values, func);
11324 assert.deepEqual(actual, expected);
11327 QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
11330 var values = [args, strictArgs],
11331 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
11333 var actual = lodashStable.map(values, function(value) {
11335 var result = func(value).sort();
11340 assert.deepEqual(actual, expected);
11343 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of `arguments` objects', function(assert) {
11346 var values = [args, strictArgs],
11347 expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
11349 var actual = lodashStable.map(values, function(value) {
11351 var result = func(value).sort();
11352 delete objectProto.a;
11356 assert.deepEqual(actual, expected);
11359 QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
11362 assert.deepEqual(func(Object('abc')).sort(), ['0', '1', '2']);
11365 QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
11368 var object = Object('a');
11371 assert.deepEqual(func(object).sort(), ['0', 'a']);
11374 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of string objects', function(assert) {
11377 var expected = isKeys ? ['0'] : ['0', 'a'];
11380 assert.deepEqual(func(Object('a')).sort(), expected);
11381 delete stringProto.a;
11384 QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
11388 Foo.prototype.a = 1;
11390 var expected = ['a'];
11391 assert.deepEqual(func(Foo.prototype), expected);
11393 Foo.prototype = { 'constructor': Foo, 'a': 1 };
11394 assert.deepEqual(func(Foo.prototype), expected);
11396 var Fake = { 'prototype': {} };
11397 Fake.prototype.constructor = Fake;
11398 assert.deepEqual(func(Fake.prototype), ['constructor']);
11401 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties', function(assert) {
11404 function Foo() { this.a = 1; }
11405 Foo.prototype.b = 2;
11407 var expected = isKeys ? ['a'] : ['a', 'b'];
11408 assert.deepEqual(func(new Foo).sort(), expected);
11412 /*--------------------------------------------------------------------------*/
11414 QUnit.module('lodash.last');
11417 var array = [1, 2, 3, 4];
11419 QUnit.test('should return the last element', function(assert) {
11422 assert.strictEqual(_.last(array), 4);
11425 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
11431 assert.strictEqual(_.last([]), undefined);
11434 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
11437 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
11438 actual = lodashStable.map(array, _.last);
11440 assert.deepEqual(actual, [3, 6, 9]);
11443 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
11447 assert.strictEqual(_(array).last(), 4);
11454 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
11458 assert.ok(_(array).chain().last() instanceof _);
11465 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
11469 var wrapped = _(array).chain().last();
11470 assert.strictEqual(wrapped.__wrapped__, array);
11477 QUnit.test('should work in a lazy sequence', function(assert) {
11481 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
11482 smallArray = array;
11484 lodashStable.times(2, function(index) {
11485 var array = index ? largeArray : smallArray,
11486 wrapped = _(array).filter(isEven);
11488 assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
11492 skipTest(assert, 2);
11497 /*--------------------------------------------------------------------------*/
11499 QUnit.module('lodash.lowerCase');
11502 QUnit.test('should lowercase as space-separated words', function(assert) {
11505 assert.strictEqual(_.lowerCase('--Foo-Bar'), 'foo bar');
11506 assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
11507 assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
11511 /*--------------------------------------------------------------------------*/
11513 QUnit.module('lodash.lowerFirst');
11516 QUnit.test('should lowercase only the first character', function(assert) {
11519 assert.strictEqual(_.lowerFirst('fred'), 'fred');
11520 assert.strictEqual(_.lowerFirst('Fred'), 'fred');
11521 assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
11525 /*--------------------------------------------------------------------------*/
11527 QUnit.module('lodash.lt');
11530 QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
11533 assert.strictEqual(_.lt(1, 3), true);
11534 assert.strictEqual(_.lt('abc', 'def'), true);
11537 QUnit.test('should return `false` if `value` >= `other`', function(assert) {
11540 assert.strictEqual(_.lt(3, 1), false);
11541 assert.strictEqual(_.lt(3, 3), false);
11542 assert.strictEqual(_.lt('def', 'abc'), false);
11543 assert.strictEqual(_.lt('def', 'def'), false);
11547 /*--------------------------------------------------------------------------*/
11549 QUnit.module('lodash.lte');
11552 QUnit.test('should return `true` if `value` is less than or equal to `other`', function(assert) {
11555 assert.strictEqual(_.lte(1, 3), true);
11556 assert.strictEqual(_.lte(3, 3), true);
11557 assert.strictEqual(_.lte('abc', 'def'), true);
11558 assert.strictEqual(_.lte('def', 'def'), true);
11561 QUnit.test('should return `false` if `value` > `other`', function(assert) {
11564 assert.strictEqual(_.lt(3, 1), false);
11565 assert.strictEqual(_.lt('def', 'abc'), false);
11569 /*--------------------------------------------------------------------------*/
11571 QUnit.module('lodash.lastIndexOf');
11574 var array = [1, 2, 3, 1, 2, 3];
11576 QUnit.test('should return the index of the last matched value', function(assert) {
11579 assert.strictEqual(_.lastIndexOf(array, 3), 5);
11582 QUnit.test('should work with a positive `fromIndex`', function(assert) {
11585 assert.strictEqual(_.lastIndexOf(array, 1, 2), 0);
11588 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
11591 var values = [6, 8, Math.pow(2, 32), Infinity],
11592 expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
11594 var actual = lodashStable.map(values, function(fromIndex) {
11596 _.lastIndexOf(array, undefined, fromIndex),
11597 _.lastIndexOf(array, 1, fromIndex),
11598 _.lastIndexOf(array, '', fromIndex)
11602 assert.deepEqual(actual, expected);
11605 QUnit.test('should work with a negative `fromIndex`', function(assert) {
11608 assert.strictEqual(_.lastIndexOf(array, 2, -3), 1);
11611 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
11614 var values = [-6, -8, -Infinity],
11615 expected = lodashStable.map(values, alwaysZero);
11617 var actual = lodashStable.map(values, function(fromIndex) {
11618 return _.lastIndexOf(array, 1, fromIndex);
11621 assert.deepEqual(actual, expected);
11624 QUnit.test('should treat falsey `fromIndex` values correctly', function(assert) {
11627 var expected = lodashStable.map(falsey, function(value) {
11628 return value === undefined ? 5 : -1;
11631 var actual = lodashStable.map(falsey, function(fromIndex) {
11632 return _.lastIndexOf(array, 3, fromIndex);
11635 assert.deepEqual(actual, expected);
11638 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
11641 assert.strictEqual(_.lastIndexOf(array, 2, 4.2), 4);
11645 /*--------------------------------------------------------------------------*/
11647 QUnit.module('indexOf methods');
11649 lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
11650 var func = _[methodName],
11651 isIndexOf = !/last/i.test(methodName),
11652 isSorted = /^sorted/.test(methodName);
11654 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument', function(assert) {
11657 var expected = lodashStable.map(falsey, lodashStable.constant(-1));
11659 var actual = lodashStable.map(falsey, function(array, index) {
11661 return index ? func(array) : func();
11665 assert.deepEqual(actual, expected);
11668 QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
11671 var array = [1, 2, 3],
11674 assert.strictEqual(func(array, 4), -1);
11675 assert.strictEqual(func(array, 4, true), -1);
11676 assert.strictEqual(func(array, undefined, true), -1);
11678 assert.strictEqual(func(empty, undefined), -1);
11679 assert.strictEqual(func(empty, undefined, true), -1);
11682 QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
11688 assert.strictEqual(func(array, undefined), -1);
11689 assert.strictEqual(func(array, 0, true), -1);
11692 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
11695 var array = isSorted
11697 : [1, NaN, 3, NaN, 5, NaN];
11700 assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
11701 skipTest(assert, 3);
11704 assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
11705 assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
11706 assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
11711 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
11714 assert.strictEqual(func([-0], 0), 0);
11715 assert.strictEqual(func([0], -0), 0);
11719 /*--------------------------------------------------------------------------*/
11721 QUnit.module('lodash.map');
11724 var array = [1, 2, 3];
11726 QUnit.test('should map values in `collection` to a new array', function(assert) {
11729 var object = { 'a': 1, 'b': 2, 'c': 3 },
11730 expected = ['1', '2', '3'];
11732 assert.deepEqual(_.map(array, String), expected);
11733 assert.deepEqual(_.map(object, String), expected);
11736 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
11739 var objects = [{ 'a': 'x' }, { 'a': 'y' }];
11740 assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
11743 QUnit.test('should iterate over own properties of objects', function(assert) {
11746 function Foo() { this.a = 1; }
11747 Foo.prototype.b = 2;
11749 var actual = _.map(new Foo, function(value, key) { return key; });
11750 assert.deepEqual(actual, ['a']);
11753 QUnit.test('should work on an object with no `iteratee`', function(assert) {
11756 var actual = _.map({ 'a': 1, 'b': 2, 'c': 3 });
11757 assert.deepEqual(actual, array);
11760 QUnit.test('should handle object arguments with non-number length properties', function(assert) {
11763 var value = { 'value': 'x' },
11764 object = { 'length': { 'value': 'x' } };
11766 assert.deepEqual(_.map(object, identity), [value]);
11769 QUnit.test('should treat a nodelist as an array-like object', function(assert) {
11773 var actual = _.map(document.getElementsByTagName('body'), function(element) {
11774 return element.nodeName.toLowerCase();
11777 assert.deepEqual(actual, ['body']);
11784 QUnit.test('should accept a falsey `collection` argument', function(assert) {
11787 var expected = lodashStable.map(falsey, alwaysEmptyArray);
11789 var actual = lodashStable.map(falsey, function(collection, index) {
11791 return index ? _.map(collection) : _.map();
11795 assert.deepEqual(actual, expected);
11798 QUnit.test('should treat number values for `collection` as empty', function(assert) {
11801 assert.deepEqual(_.map(1), []);
11804 QUnit.test('should return a wrapped value when chaining', function(assert) {
11808 assert.ok(_(array).map(noop) instanceof _);
11815 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
11820 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
11821 expected = [1, 0, _.map(array.slice(1), square)];
11823 _(array).slice(1).map(function(value, index, array) {
11824 args || (args = slice.call(arguments));
11827 assert.deepEqual(args, [1, 0, array.slice(1)]);
11830 _(array).slice(1).map(square).map(function(value, index, array) {
11831 args || (args = slice.call(arguments));
11834 assert.deepEqual(args, expected);
11837 _(array).slice(1).map(square).map(function(value, index) {
11838 args || (args = slice.call(arguments));
11841 assert.deepEqual(args, expected);
11844 _(array).slice(1).map(square).map(function(value) {
11845 args || (args = slice.call(arguments));
11848 assert.deepEqual(args, [1]);
11851 _(array).slice(1).map(square).map(function() {
11852 args || (args = slice.call(arguments));
11855 assert.deepEqual(args, expected);
11858 skipTest(assert, 5);
11863 /*--------------------------------------------------------------------------*/
11865 QUnit.module('lodash.mapKeys');
11868 var array = [1, 2],
11869 object = { 'a': 1, 'b': 2, 'c': 3 };
11871 QUnit.test('should map keys in `object` to a new object', function(assert) {
11874 var actual = _.mapKeys(object, String);
11875 assert.deepEqual(actual, { '1': 1, '2': 2, '3': 3 });
11878 QUnit.test('should treat arrays like objects', function(assert) {
11881 var actual = _.mapKeys(array, String);
11882 assert.deepEqual(actual, { '1': 1, '2': 2 });
11885 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
11888 var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
11889 assert.deepEqual(actual, { 'c': { 'b': 'c' } });
11892 QUnit.test('should work on an object with no `iteratee`', function(assert) {
11895 var actual = _.mapKeys({ 'a': 1, 'b': 2, 'c': 3 });
11896 assert.deepEqual(actual, { '1': 1, '2': 2, '3': 3 });
11900 /*--------------------------------------------------------------------------*/
11902 QUnit.module('lodash.mapValues');
11905 var array = [1, 2],
11906 object = { 'a': 1, 'b': 2, 'c': 3 };
11908 QUnit.test('should map values in `object` to a new object', function(assert) {
11911 var actual = _.mapValues(object, String);
11912 assert.deepEqual(actual, { 'a': '1', 'b': '2', 'c': '3' });
11915 QUnit.test('should treat arrays like objects', function(assert) {
11918 var actual = _.mapValues(array, String);
11919 assert.deepEqual(actual, { '0': '1', '1': '2' });
11922 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
11925 var actual = _.mapValues({ 'a': { 'b': 1 } }, 'b');
11926 assert.deepEqual(actual, { 'a': 1 });
11929 QUnit.test('should work on an object with no `iteratee`', function(assert) {
11932 var actual = _.mapValues({ 'a': 1, 'b': 2, 'c': 3 });
11933 assert.deepEqual(actual, object);
11934 assert.notStrictEqual(actual, object);
11938 /*--------------------------------------------------------------------------*/
11940 QUnit.module('lodash.mapKeys and lodash.mapValues');
11942 lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
11943 var array = [1, 2],
11944 func = _[methodName],
11945 object = { 'a': 1, 'b': 2, 'c': 3 };
11947 QUnit.test('should iterate over own properties of objects', function(assert) {
11950 function Foo() { this.a = 'a'; }
11951 Foo.prototype.b = 'b';
11953 var actual = func(new Foo, function(value, key) { return key; });
11954 assert.deepEqual(actual, { 'a': 'a' });
11957 QUnit.test('should accept a falsey `object` argument', function(assert) {
11960 var expected = lodashStable.map(falsey, alwaysEmptyObject);
11962 var actual = lodashStable.map(falsey, function(object, index) {
11964 return index ? func(object) : func();
11968 assert.deepEqual(actual, expected);
11971 QUnit.test('should return a wrapped value when chaining', function(assert) {
11975 assert.ok(_(object)[methodName](noop) instanceof _);
11983 /*--------------------------------------------------------------------------*/
11985 QUnit.module('lodash.matches');
11988 QUnit.test('should create a function that performs a deep comparison between `source` and a given object', function(assert) {
11991 var object = { 'a': 1, 'b': 2, 'c': 3 },
11992 matches = _.matches({ 'a': 1 });
11994 assert.strictEqual(matches.length, 1);
11995 assert.strictEqual(matches(object), true);
11997 matches = _.matches({ 'b': 1 });
11998 assert.strictEqual(matches(object), false);
12000 matches = _.matches({ 'a': 1, 'c': 3 });
12001 assert.strictEqual(matches(object), true);
12003 matches = _.matches({ 'c': 3, 'd': 4 });
12004 assert.strictEqual(matches(object), false);
12006 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
12007 matches = _.matches({ 'a': { 'b': { 'c': 1 } } });
12009 assert.strictEqual(matches(object), true);
12012 QUnit.test('should match inherited `object` properties', function(assert) {
12015 function Foo() { this.a = 1; }
12016 Foo.prototype.b = 2;
12018 var object = { 'a': new Foo },
12019 matches = _.matches({ 'a': { 'b': 2 } });
12021 assert.strictEqual(matches(object), true);
12024 QUnit.test('should not match by inherited `source` properties', function(assert) {
12027 function Foo() { this.a = 1; }
12028 Foo.prototype.b = 2;
12030 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
12032 actual = lodashStable.map(objects, _.matches(source)),
12033 expected = lodashStable.map(objects, alwaysTrue);
12035 assert.deepEqual(actual, expected);
12038 QUnit.test('should compare a variety of `source` property values', function(assert) {
12041 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
12042 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
12043 matches = _.matches(object1);
12045 assert.strictEqual(matches(object1), true);
12046 assert.strictEqual(matches(object2), false);
12049 QUnit.test('should match `-0` as `0`', function(assert) {
12052 var object1 = { 'a': -0 },
12053 object2 = { 'a': 0 },
12054 matches = _.matches(object1);
12056 assert.strictEqual(matches(object2), true);
12058 matches = _.matches(object2);
12059 assert.strictEqual(matches(object1), true);
12062 QUnit.test('should compare functions by reference', function(assert) {
12065 var object1 = { 'a': lodashStable.noop },
12066 object2 = { 'a': noop },
12067 object3 = { 'a': {} },
12068 matches = _.matches(object1);
12070 assert.strictEqual(matches(object1), true);
12071 assert.strictEqual(matches(object2), false);
12072 assert.strictEqual(matches(object3), false);
12075 QUnit.test('should work with a function for `object`', function(assert) {
12079 Foo.a = { 'b': 1, 'c': 2 };
12081 var matches = _.matches({ 'a': { 'b': 1 } });
12082 assert.strictEqual(matches(Foo), true);
12085 QUnit.test('should work with a function for `source`', function(assert) {
12090 Foo.b = function() {};
12093 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
12094 actual = lodashStable.map(objects, _.matches(Foo));
12096 assert.deepEqual(actual, [false, true]);
12099 QUnit.test('should work with a non-plain `object`', function(assert) {
12102 function Foo(object) { lodashStable.assign(this, object); }
12104 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
12105 matches = _.matches({ 'a': { 'b': 1 } });
12107 assert.strictEqual(matches(object), true);
12110 QUnit.test('should partial match arrays', function(assert) {
12113 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
12114 actual = lodashStable.filter(objects, _.matches({ 'a': ['d'] }));
12116 assert.deepEqual(actual, [objects[1]]);
12118 actual = lodashStable.filter(objects, _.matches({ 'a': ['b', 'd'] }));
12119 assert.deepEqual(actual, []);
12121 actual = lodashStable.filter(objects, _.matches({ 'a': ['d', 'b'] }));
12122 assert.deepEqual(actual, []);
12125 QUnit.test('should partial match arrays of objects', function(assert) {
12129 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
12130 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
12133 var actual = lodashStable.filter(objects, _.matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
12134 assert.deepEqual(actual, [objects[0]]);
12137 QUnit.test('should partial match maps', function(assert) {
12141 var objects = [{ 'a': new Map }, { 'a': new Map }];
12142 objects[0].a.set('a', 1);
12143 objects[1].a.set('a', 1);
12144 objects[1].a.set('b', 2);
12148 var actual = lodashStable.filter(objects, _.matches({ 'a': map }));
12150 assert.deepEqual(actual, [objects[1]]);
12152 map['delete']('b');
12153 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
12155 assert.deepEqual(actual, objects);
12158 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
12160 assert.deepEqual(actual, []);
12163 skipTest(assert, 3);
12167 QUnit.test('should partial match sets', function(assert) {
12171 var objects = [{ 'a': new Set }, { 'a': new Set }];
12172 objects[0].a.add(1);
12173 objects[1].a.add(1);
12174 objects[1].a.add(2);
12178 var actual = lodashStable.filter(objects, _.matches({ 'a': set }));
12180 assert.deepEqual(actual, [objects[1]]);
12183 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
12185 assert.deepEqual(actual, objects);
12188 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
12190 assert.deepEqual(actual, []);
12193 skipTest(assert, 3);
12197 QUnit.test('should match `undefined` values', function(assert) {
12200 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
12201 actual = lodashStable.map(objects, _.matches({ 'b': undefined })),
12202 expected = [false, false, true];
12204 assert.deepEqual(actual, expected);
12206 actual = lodashStable.map(objects, _.matches({ 'a': 1, 'b': undefined }));
12208 assert.deepEqual(actual, expected);
12210 objects = [{ 'a': { 'b': 1 } }, { 'a': { 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
12211 actual = lodashStable.map(objects, _.matches({ 'a': { 'c': undefined } }));
12213 assert.deepEqual(actual, expected);
12216 QUnit.test('should match `undefined` values on primitives', function(assert) {
12220 numberProto.b = undefined;
12223 var matches = _.matches({ 'b': undefined });
12224 assert.strictEqual(matches(1), true);
12226 assert.ok(false, e.message);
12229 matches = _.matches({ 'a': 1, 'b': undefined });
12230 assert.strictEqual(matches(1), true);
12232 assert.ok(false, e.message);
12234 numberProto.a = { 'b': 1, 'c': undefined };
12236 matches = _.matches({ 'a': { 'c': undefined } });
12237 assert.strictEqual(matches(1), true);
12239 assert.ok(false, e.message);
12241 delete numberProto.a;
12242 delete numberProto.b;
12245 QUnit.test('should return `false` when `object` is nullish', function(assert) {
12248 var values = [, null, undefined],
12249 expected = lodashStable.map(values, alwaysFalse),
12250 matches = _.matches({ 'a': 1 });
12252 var actual = lodashStable.map(values, function(value, index) {
12254 return index ? matches(value) : matches();
12258 assert.deepEqual(actual, expected);
12261 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
12264 var values = [, null, undefined],
12265 expected = lodashStable.map(values, alwaysTrue),
12266 matches = _.matches({});
12268 var actual = lodashStable.map(values, function(value, index) {
12270 return index ? matches(value) : matches();
12274 assert.deepEqual(actual, expected);
12277 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
12280 var object = { 'a': 1 },
12281 expected = lodashStable.map(empties, alwaysTrue);
12283 var actual = lodashStable.map(empties, function(value) {
12284 var matches = _.matches(value);
12285 return matches(object);
12288 assert.deepEqual(actual, expected);
12291 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
12294 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
12295 actual = lodashStable.filter(objects, _.matches({ 'a': [], 'b': {} }));
12297 assert.deepEqual(actual, objects);
12300 QUnit.test('should not change behavior if `source` is modified', function(assert) {
12304 { 'a': { 'b': 2, 'c': 3 } },
12305 { 'a': 1, 'b': 2 },
12309 lodashStable.each(sources, function(source, index) {
12310 var object = lodashStable.cloneDeep(source),
12311 matches = _.matches(source);
12313 assert.strictEqual(matches(object), true);
12324 assert.strictEqual(matches(object), true);
12325 assert.strictEqual(matches(source), false);
12330 /*--------------------------------------------------------------------------*/
12332 QUnit.module('lodash.matchesProperty');
12335 QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
12338 var object = { 'a': 1, 'b': 2, 'c': 3 },
12339 matches = _.matchesProperty('a', 1);
12341 assert.strictEqual(matches.length, 1);
12342 assert.strictEqual(matches(object), true);
12344 matches = _.matchesProperty('b', 3);
12345 assert.strictEqual(matches(object), false);
12347 matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
12348 assert.strictEqual(matches({ 'a': object }), true);
12350 matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
12351 assert.strictEqual(matches(object), false);
12353 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
12354 matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
12356 assert.strictEqual(matches(object), true);
12359 QUnit.test('should support deep paths', function(assert) {
12362 var object = { 'a': { 'b': { 'c': 3 } } };
12364 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
12365 var matches = _.matchesProperty(path, 3);
12366 assert.strictEqual(matches(object), true);
12370 QUnit.test('should coerce key to a string', function(assert) {
12374 fn.toString = lodashStable.constant('fn');
12376 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
12377 values = [null, undefined, fn, {}];
12379 var expected = lodashStable.transform(values, function(result) {
12380 result.push(true, true);
12383 var actual = lodashStable.transform(objects, function(result, object, index) {
12384 var key = values[index];
12385 lodashStable.each([key, [key]], function(path) {
12386 var matches = _.matchesProperty(path, object[key]);
12387 result.push(matches(object));
12391 assert.deepEqual(actual, expected);
12394 QUnit.test('should match a key over a path', function(assert) {
12397 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
12399 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
12400 var matches = _.matchesProperty(path, 3);
12401 assert.strictEqual(matches(object), true);
12405 QUnit.test('should work with non-string `path` arguments', function(assert) {
12408 var array = [1, 2, 3];
12410 lodashStable.each([1, [1]], function(path) {
12411 var matches = _.matchesProperty(path, 2);
12412 assert.strictEqual(matches(array), true);
12416 QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
12421 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
12422 var matches = _.matchesProperty(path, 1);
12423 assert.strictEqual(matches(object), false);
12427 QUnit.test('should return `false` with deep paths when `object` is nullish', function(assert) {
12430 var values = [, null, undefined],
12431 expected = lodashStable.map(values, alwaysFalse);
12433 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
12434 var matches = _.matchesProperty(path, 1);
12436 var actual = lodashStable.map(values, function(value, index) {
12438 return index ? matches(value) : matches();
12442 assert.deepEqual(actual, expected);
12446 QUnit.test('should match inherited `srcValue` properties', function(assert) {
12450 Foo.prototype.b = 2;
12452 var object = { 'a': new Foo };
12454 lodashStable.each(['a', ['a']], function(path) {
12455 var matches = _.matchesProperty(path, { 'b': 2 });
12456 assert.strictEqual(matches(object), true);
12460 QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
12463 function Foo() { this.a = 1; }
12464 Foo.prototype.b = 2;
12466 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
12467 expected = lodashStable.map(objects, alwaysTrue);
12469 lodashStable.each(['a', ['a']], function(path) {
12470 assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
12474 QUnit.test('should compare a variety of values', function(assert) {
12477 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
12478 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
12479 matches = _.matchesProperty('a', object1);
12481 assert.strictEqual(matches({ 'a': object1 }), true);
12482 assert.strictEqual(matches({ 'a': object2 }), false);
12485 QUnit.test('should match `-0` as `0`', function(assert) {
12488 var matches = _.matchesProperty('a', -0);
12489 assert.strictEqual(matches({ 'a': 0 }), true);
12491 matches = _.matchesProperty('a', 0);
12492 assert.strictEqual(matches({ 'a': -0 }), true);
12495 QUnit.test('should compare functions by reference', function(assert) {
12498 var object1 = { 'a': lodashStable.noop },
12499 object2 = { 'a': noop },
12500 object3 = { 'a': {} },
12501 matches = _.matchesProperty('a', object1);
12503 assert.strictEqual(matches({ 'a': object1 }), true);
12504 assert.strictEqual(matches({ 'a': object2 }), false);
12505 assert.strictEqual(matches({ 'a': object3 }), false);
12508 QUnit.test('should work with a function for `srcValue`', function(assert) {
12513 Foo.b = function() {};
12516 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
12517 actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
12519 assert.deepEqual(actual, [false, true]);
12522 QUnit.test('should work with a non-plain `srcValue`', function(assert) {
12525 function Foo(object) { lodashStable.assign(this, object); }
12527 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
12528 matches = _.matchesProperty('a', { 'b': 1 });
12530 assert.strictEqual(matches(object), true);
12533 QUnit.test('should partial match arrays', function(assert) {
12536 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
12537 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
12539 assert.deepEqual(actual, [objects[1]]);
12541 actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
12542 assert.deepEqual(actual, []);
12544 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
12545 assert.deepEqual(actual, []);
12548 QUnit.test('should partial match arrays of objects', function(assert) {
12552 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
12553 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
12556 var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
12557 assert.deepEqual(actual, [objects[0]]);
12559 QUnit.test('should partial match maps', function(assert) {
12563 var objects = [{ 'a': new Map }, { 'a': new Map }];
12564 objects[0].a.set('a', 1);
12565 objects[1].a.set('a', 1);
12566 objects[1].a.set('b', 2);
12570 var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
12572 assert.deepEqual(actual, [objects[1]]);
12574 map['delete']('b');
12575 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
12577 assert.deepEqual(actual, objects);
12580 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
12582 assert.deepEqual(actual, []);
12585 skipTest(assert, 3);
12589 QUnit.test('should partial match sets', function(assert) {
12593 var objects = [{ 'a': new Set }, { 'a': new Set }];
12594 objects[0].a.add(1);
12595 objects[1].a.add(1);
12596 objects[1].a.add(2);
12600 var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
12602 assert.deepEqual(actual, [objects[1]]);
12605 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
12607 assert.deepEqual(actual, objects);
12610 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
12612 assert.deepEqual(actual, []);
12615 skipTest(assert, 3);
12619 QUnit.test('should match `undefined` values', function(assert) {
12622 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
12623 actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
12624 expected = [false, false, true];
12626 assert.deepEqual(actual, expected);
12628 objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
12629 actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
12631 assert.deepEqual(actual, expected);
12634 QUnit.test('should match `undefined` values on primitives', function(assert) {
12638 numberProto.b = undefined;
12641 var matches = _.matchesProperty('b', undefined);
12642 assert.strictEqual(matches(1), true);
12644 assert.ok(false, e.message);
12646 numberProto.a = { 'b': 1, 'c': undefined };
12648 matches = _.matchesProperty('a', { 'c': undefined });
12649 assert.strictEqual(matches(1), true);
12651 assert.ok(false, e.message);
12653 delete numberProto.a;
12654 delete numberProto.b;
12657 QUnit.test('should return `false` when `object` is nullish', function(assert) {
12660 var values = [, null, undefined],
12661 expected = lodashStable.map(values, alwaysFalse);
12663 lodashStable.each(['constructor', ['constructor']], function(path) {
12664 var matches = _.matchesProperty(path, 1);
12666 var actual = lodashStable.map(values, function(value, index) {
12668 return index ? matches(value) : matches();
12672 assert.deepEqual(actual, expected);
12676 QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
12679 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
12680 matches = _.matchesProperty('a', { 'a': [], 'b': {} });
12682 var actual = lodashStable.filter(objects, function(object) {
12683 return matches({ 'a': object });
12686 assert.deepEqual(actual, objects);
12689 QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
12692 lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
12693 var object = lodashStable.cloneDeep(source),
12694 matches = _.matchesProperty('a', source);
12696 assert.strictEqual(matches({ 'a': object }), true);
12707 assert.strictEqual(matches({ 'a': object }), true);
12708 assert.strictEqual(matches({ 'a': source }), false);
12713 /*--------------------------------------------------------------------------*/
12715 QUnit.module('lodash.max');
12718 QUnit.test('should return the largest value from a collection', function(assert) {
12721 assert.strictEqual(_.max([1, 2, 3]), 3);
12724 QUnit.test('should return `undefined` for empty collections', function(assert) {
12727 var values = falsey.concat([[]]),
12728 expected = lodashStable.map(values, alwaysUndefined);
12730 var actual = lodashStable.map(values, function(value, index) {
12732 return index ? _.max(value) : _.max();
12736 assert.deepEqual(actual, expected);
12739 QUnit.test('should work with non-numeric collection values', function(assert) {
12742 assert.strictEqual(_.max(['a', 'b']), 'b');
12746 /*--------------------------------------------------------------------------*/
12748 QUnit.module('lodash.mean');
12751 QUnit.test('should return the mean of an array of numbers', function(assert) {
12754 var array = [4, 2, 8, 6];
12755 assert.strictEqual(_.mean(array), 5);
12759 /*--------------------------------------------------------------------------*/
12761 QUnit.module('lodash.memoize');
12764 QUnit.test('should memoize results based on the first argument provided', function(assert) {
12767 var memoized = _.memoize(function(a, b, c) {
12771 assert.strictEqual(memoized(1, 2, 3), 6);
12772 assert.strictEqual(memoized(1, 3, 5), 6);
12775 QUnit.test('should support a `resolver` argument', function(assert) {
12778 var fn = function(a, b, c) { return a + b + c; },
12779 memoized = _.memoize(fn, fn);
12781 assert.strictEqual(memoized(1, 2, 3), 6);
12782 assert.strictEqual(memoized(1, 3, 5), 9);
12785 QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
12788 var fn = function(a, b, c) { return a + this.b + this.c; },
12789 memoized = _.memoize(fn, fn);
12791 var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
12792 assert.strictEqual(object.memoized(1), 6);
12796 assert.strictEqual(object.memoized(1), 9);
12799 QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
12802 assert.raises(function() { _.memoize(noop, true); }, TypeError);
12805 QUnit.test('should not error if `resolver` is falsey', function(assert) {
12808 var expected = lodashStable.map(falsey, alwaysTrue);
12810 var actual = lodashStable.map(falsey, function(resolver, index) {
12812 return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
12816 assert.deepEqual(actual, expected);
12819 QUnit.test('should check cache for own properties', function(assert) {
12826 'propertyIsEnumerable',
12832 var memoized = _.memoize(identity);
12834 var actual = lodashStable.map(props, function(value) {
12835 return memoized(value);
12838 assert.deepEqual(actual, props);
12841 QUnit.test('should cache the `__proto__` key', function(assert) {
12847 lodashStable.times(2, function(index) {
12849 resolver = index && identity;
12851 var memoized = _.memoize(function() {
12856 var cache = memoized.cache;
12861 assert.strictEqual(count, 1);
12862 assert.strictEqual(cache.get(key), array);
12863 assert.notOk(cache.__data__ instanceof Array);
12864 assert.strictEqual(cache['delete'](key), true);
12868 QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
12871 var oldCache = _.memoize.Cache;
12874 this.__data__ = [];
12877 Cache.prototype = {
12878 'get': function(key) {
12879 var entry = _.find(this.__data__, function(entry) {
12880 return key === entry.key;
12882 return entry && entry.value;
12884 'has': function(key) {
12885 return _.some(this.__data__, function(entry) {
12886 return key === entry.key;
12889 'set': function(key, value) {
12890 this.__data__.push({ 'key': key, 'value': value });
12895 _.memoize.Cache = Cache;
12897 var memoized = _.memoize(function(object) {
12898 return 'value:' + object.id;
12901 var cache = memoized.cache,
12902 key1 = { 'id': 'a' },
12903 key2 = { 'id': 'b' };
12905 assert.strictEqual(memoized(key1), 'value:a');
12906 assert.strictEqual(cache.has(key1), true);
12908 assert.strictEqual(memoized(key2), 'value:b');
12909 assert.strictEqual(cache.has(key2), true);
12911 _.memoize.Cache = oldCache;
12914 QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
12917 var oldCache = _.memoize.Cache;
12920 this.__data__ = [];
12923 Cache.prototype = {
12924 'get': function(key) {
12925 return _.find(this.__data__, function(entry) {
12926 return key === entry.key;
12929 'has': function(key) {
12930 return _.some(this.__data__, function(entry) {
12931 return key === entry.key;
12934 'set': function(key, value) {
12935 var result = new Cache;
12936 result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
12941 _.memoize.Cache = Cache;
12943 var memoized = _.memoize(function(object) {
12947 var key1 = { 'id': 'a' },
12948 key2 = { 'id': 'b' };
12953 var cache = memoized.cache;
12954 assert.strictEqual(cache.has(key1), true);
12955 assert.strictEqual(cache.has(key2), true);
12957 _.memoize.Cache = oldCache;
12960 QUnit.test('should implement a `Map` interface on the cache object', function(assert) {
12961 assert.expect(164);
12963 var keys = [true, false, 1, -Infinity, NaN, {}, null, 'a', symbol || {} , undefined];
12965 var pairs = lodashStable.map(keys, function(key, index) {
12966 var lastIndex = keys.length - 1;
12967 return [key, keys[lastIndex - index]];
12970 lodashStable.times(2, function(index) {
12971 var memoize = (index ? (lodashBizarro || {}) : _).memoize,
12972 Cache = memoize ? memoize.Cache : undefined,
12973 cache = Cache ? new Cache(pairs) : undefined;
12975 lodashStable.each(keys, function(key, index) {
12977 var value = pairs[index][1];
12979 assert.deepEqual(cache.get(key), value);
12980 assert.strictEqual(cache.has(key), true);
12981 assert.strictEqual(cache['delete'](key), true);
12982 assert.strictEqual(cache.has(key), false);
12983 assert.strictEqual(cache.get(key), undefined);
12984 assert.strictEqual(cache['delete'](key), false);
12985 assert.strictEqual(cache.set(key, value), cache);
12986 assert.strictEqual(cache.has(key), true);
12989 skipTest(assert, 8);
12994 assert.strictEqual(cache.clear(), undefined);
12995 assert.ok(lodashStable.every(keys, function(key) {
12996 return !cache.has(key);
13000 skipTest(assert, 2);
13006 /*--------------------------------------------------------------------------*/
13008 QUnit.module('lodash.merge');
13011 var args = arguments;
13013 QUnit.test('should merge `source` into `object`', function(assert) {
13018 { 'name': 'barney' },
13032 { 'height': '5\'4"' },
13033 { 'height': '5\'5"' }
13039 { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
13040 { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
13044 assert.deepEqual(_.merge(names, ages, heights), expected);
13047 QUnit.test('should merge sources containing circular references', function(assert) {
13056 'foo': { 'b': { 'c': { 'd': {} } } },
13060 source.foo.b.c.d = source;
13061 source.bar.b = source.foo.b;
13063 var actual = _.merge(object, source);
13064 assert.ok(actual.bar.b === actual.foo.b && actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
13067 QUnit.test('should work with four arguments', function(assert) {
13070 var expected = { 'a': 4 },
13071 actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
13073 assert.deepEqual(actual, expected);
13076 QUnit.test('should work with a function for `object`', function(assert) {
13081 var source = { 'a': 1 },
13082 actual = _.merge(Foo, source);
13084 assert.strictEqual(actual, Foo);
13085 assert.strictEqual(Foo.a, 1);
13088 QUnit.test('should work with a non-plain `object`', function(assert) {
13093 var object = new Foo,
13094 source = { 'a': 1 },
13095 actual = _.merge(object, source);
13097 assert.strictEqual(actual, object);
13098 assert.strictEqual(object.a, 1);
13101 QUnit.test('should pass thru primitive `object` values', function(assert) {
13104 var values = [true, 1, '1'];
13106 var actual = lodashStable.map(values, function(value) {
13107 return _.merge(value, { 'a': 1 });
13110 assert.deepEqual(actual, values);
13113 QUnit.test('should treat sparse array sources as dense', function(assert) {
13116 var array = Array(3);
13120 var actual = _.merge([], array),
13121 expected = array.slice();
13123 expected[1] = undefined;
13125 assert.ok('1' in actual);
13126 assert.deepEqual(actual, expected);
13129 QUnit.test('should merge `arguments` objects', function(assert) {
13132 var object1 = { 'value': args },
13133 object2 = { 'value': { '3': 4 } },
13134 expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
13135 actual = _.merge(object1, object2);
13137 assert.notOk('3' in args);
13138 assert.notOk(_.isArguments(actual.value));
13139 assert.deepEqual(actual.value, expected);
13140 object1.value = args;
13142 actual = _.merge(object2, object1);
13143 assert.notOk(_.isArguments(actual.value));
13144 assert.deepEqual(actual.value, expected);
13146 expected = { '0': 1, '1': 2, '2': 3 };
13148 actual = _.merge({}, object1);
13149 assert.notOk(_.isArguments(actual.value));
13150 assert.deepEqual(actual.value, expected);
13153 QUnit.test('should merge typed arrays', function(assert) {
13158 array3 = [0, 0, 0, 0],
13159 array4 = lodashStable.range(0, 8, 0);
13161 var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
13162 buffer = ArrayBuffer && new ArrayBuffer(8);
13164 // juggle for `Float64Array` shim
13165 if (root.Float64Array && (new Float64Array(buffer)).length == 8) {
13166 arrays[1] = array4;
13168 var expected = lodashStable.map(typedArrays, function(type, index) {
13169 var array = arrays[index].slice();
13171 return root[type] ? { 'value': array } : false;
13174 var actual = lodashStable.map(typedArrays, function(type) {
13175 var Ctor = root[type];
13176 return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
13179 assert.ok(lodashStable.isArray(actual));
13180 assert.deepEqual(actual, expected);
13182 expected = lodashStable.map(typedArrays, function(type, index) {
13183 var array = arrays[index].slice();
13185 return root[type] ? { 'value': array } : false;
13188 actual = lodashStable.map(typedArrays, function(type, index) {
13189 var Ctor = root[type],
13190 array = lodashStable.range(arrays[index].length);
13193 return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
13196 assert.ok(lodashStable.isArray(actual));
13197 assert.deepEqual(actual, expected);
13200 QUnit.test('should assign `null` values', function(assert) {
13203 var actual = _.merge({ 'a': 1 }, { 'a': null });
13204 assert.strictEqual(actual.a, null);
13207 QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) {
13212 var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
13213 expected = lodashStable.map(values, alwaysTrue);
13215 var actual = lodashStable.map(values, function(value) {
13216 var object = _.merge({}, { 'value': value });
13217 return object.value === value;
13220 assert.deepEqual(actual, expected);
13223 QUnit.test('should shallow clone array/typed-array/plain-object sources', function(assert) {
13226 var values = [[], new (Uint8Array || Object), {}],
13227 expected = lodashStable.map(values, alwaysTrue);
13229 var actual = lodashStable.map(values, function(value) {
13230 var object = _.merge({}, { 'value': value });
13231 return object.value !== value && lodashStable.isEqual(object.value, value);
13234 assert.deepEqual(actual, expected);
13237 QUnit.test('should merge plain-objects onto non plain-objects', function(assert) {
13240 function Foo(object) {
13241 lodashStable.assign(this, object);
13244 var object = { 'a': 1 },
13245 actual = _.merge(new Foo, object);
13247 assert.ok(actual instanceof Foo);
13248 assert.deepEqual(actual, new Foo(object));
13250 actual = _.merge([new Foo], [object]);
13251 assert.ok(actual[0] instanceof Foo);
13252 assert.deepEqual(actual, [new Foo(object)]);
13255 QUnit.test('should not assign `undefined` values', function(assert) {
13258 var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
13259 assert.deepEqual(actual, { 'a': 1 });
13262 QUnit.test('should skip `undefined` values in array sources if a destination value exists', function(assert) {
13265 var array = Array(3);
13269 var actual = _.merge([4, 5, 6], array),
13270 expected = [1, 5, 3];
13272 assert.deepEqual(actual, expected);
13275 array[1] = undefined;
13277 actual = _.merge([4, 5, 6], array);
13278 assert.deepEqual(actual, expected);
13281 QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
13284 if (defineProperty) {
13288 defineProperty(object, 'a', {
13289 'enumerable': true,
13290 'configurable': true,
13291 'get': function() { pass = false; },
13292 'set': function() { pass = false; }
13295 _.merge(object, object);
13303 QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
13306 var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
13307 actual = _.merge(object, { 'a': ['x'] });
13309 assert.deepEqual(actual, { 'a': ['x', 'y'] });
13311 actual = _.merge({ 'a': {} }, { 'a': [] });
13312 assert.deepEqual(actual, { 'a': [] });
13315 QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
13318 var object = { 'a': 'abcdef' },
13319 actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
13321 assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
13324 QUnit.test('should not error on DOM elements', function(assert) {
13327 var object1 = { 'el': document && document.createElement('div') },
13328 object2 = { 'el': document && document.createElement('div') },
13329 pairs = [[{}, object1], [object1, object2]],
13330 expected = lodashStable.map(pairs, alwaysTrue);
13332 var actual = lodashStable.map(pairs, function(pair) {
13334 return _.merge(pair[0], pair[1]).el === pair[1].el;
13338 assert.deepEqual(actual, expected);
13342 /*--------------------------------------------------------------------------*/
13344 QUnit.module('lodash.mergeWith');
13347 QUnit.test('should handle merging if `customizer` returns `undefined`', function(assert) {
13350 var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
13351 assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
13353 actual = _.mergeWith([], [undefined], identity);
13354 assert.deepEqual(actual, [undefined]);
13357 QUnit.test('should defer to `customizer` when it returns a value other than `undefined`', function(assert) {
13360 var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
13361 return lodashStable.isArray(a) ? a.concat(b) : undefined;
13364 assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
13368 /*--------------------------------------------------------------------------*/
13370 QUnit.module('lodash.method');
13373 QUnit.test('should create a function that calls a method of a given object', function(assert) {
13376 var object = { 'a': alwaysOne };
13378 lodashStable.each(['a', ['a']], function(path) {
13379 var method = _.method(path);
13380 assert.strictEqual(method.length, 1);
13381 assert.strictEqual(method(object), 1);
13385 QUnit.test('should work with deep property values', function(assert) {
13388 var object = { 'a': { 'b': { 'c': alwaysThree } } };
13390 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
13391 var method = _.method(path);
13392 assert.strictEqual(method(object), 3);
13396 QUnit.test('should work with non-string `path` arguments', function(assert) {
13399 var array = lodashStable.times(3, _.constant);
13401 lodashStable.each([1, [1]], function(path) {
13402 var method = _.method(path);
13403 assert.strictEqual(method(array), 1);
13407 QUnit.test('should coerce key to a string', function(assert) {
13411 fn.toString = lodashStable.constant('fn');
13413 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
13414 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
13415 values = [null, undefined, fn, {}];
13417 var actual = lodashStable.transform(objects, function(result, object, index) {
13418 var key = values[index];
13419 lodashStable.each([key, [key]], function(path) {
13420 var method = _.method(key);
13421 result.push(method(object));
13425 assert.deepEqual(actual, expected);
13428 QUnit.test('should work with inherited property values', function(assert) {
13432 Foo.prototype.a = alwaysOne;
13434 lodashStable.each(['a', ['a']], function(path) {
13435 var method = _.method(path);
13436 assert.strictEqual(method(new Foo), 1);
13440 QUnit.test('should use a key over a path', function(assert) {
13443 var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
13445 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
13446 var method = _.method(path);
13447 assert.strictEqual(method(object), 3);
13451 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
13454 var values = [, null, undefined],
13455 expected = lodashStable.map(values, alwaysUndefined);
13457 lodashStable.each(['constructor', ['constructor']], function(path) {
13458 var method = _.method(path);
13460 var actual = lodashStable.map(values, function(value, index) {
13461 return index ? method(value) : method();
13464 assert.deepEqual(actual, expected);
13468 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
13471 var values = [, null, undefined],
13472 expected = lodashStable.map(values, alwaysUndefined);
13474 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
13475 var method = _.method(path);
13477 var actual = lodashStable.map(values, function(value, index) {
13478 return index ? method(value) : method();
13481 assert.deepEqual(actual, expected);
13485 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
13490 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
13491 var method = _.method(path);
13492 assert.strictEqual(method(object), undefined);
13496 QUnit.test('should apply partial arguments to function', function(assert) {
13501 return slice.call(arguments);
13505 lodashStable.each(['fn', ['fn']], function(path) {
13506 var method = _.method(path, 1, 2, 3);
13507 assert.deepEqual(method(object), [1, 2, 3]);
13511 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
13514 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
13516 lodashStable.each(['a.b', ['a', 'b']], function(path) {
13517 var method = _.method(path);
13518 assert.strictEqual(method(object), 1);
13523 /*--------------------------------------------------------------------------*/
13525 QUnit.module('lodash.methodOf');
13528 QUnit.test('should create a function that calls a method of a given key', function(assert) {
13531 var object = { 'a': alwaysOne };
13533 lodashStable.each(['a', ['a']], function(path) {
13534 var methodOf = _.methodOf(object);
13535 assert.strictEqual(methodOf.length, 1);
13536 assert.strictEqual(methodOf(path), 1);
13540 QUnit.test('should work with deep property values', function(assert) {
13543 var object = { 'a': { 'b': { 'c': alwaysThree } } };
13545 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
13546 var methodOf = _.methodOf(object);
13547 assert.strictEqual(methodOf(path), 3);
13551 QUnit.test('should work with non-string `path` arguments', function(assert) {
13554 var array = lodashStable.times(3, _.constant);
13556 lodashStable.each([1, [1]], function(path) {
13557 var methodOf = _.methodOf(array);
13558 assert.strictEqual(methodOf(path), 1);
13562 QUnit.test('should coerce key to a string', function(assert) {
13566 fn.toString = lodashStable.constant('fn');
13568 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
13569 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
13570 values = [null, undefined, fn, {}];
13572 var actual = lodashStable.transform(objects, function(result, object, index) {
13573 var key = values[index];
13574 lodashStable.each([key, [key]], function(path) {
13575 var methodOf = _.methodOf(object);
13576 result.push(methodOf(key));
13580 assert.deepEqual(actual, expected);
13583 QUnit.test('should work with inherited property values', function(assert) {
13587 Foo.prototype.a = alwaysOne;
13589 lodashStable.each(['a', ['a']], function(path) {
13590 var methodOf = _.methodOf(new Foo);
13591 assert.strictEqual(methodOf(path), 1);
13595 QUnit.test('should use a key over a path', function(assert) {
13598 var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
13600 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
13601 var methodOf = _.methodOf(object);
13602 assert.strictEqual(methodOf(path), 3);
13606 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
13609 var values = [, null, undefined],
13610 expected = lodashStable.map(values, alwaysUndefined);
13612 lodashStable.each(['constructor', ['constructor']], function(path) {
13613 var actual = lodashStable.map(values, function(value, index) {
13614 var methodOf = index ? _.methodOf() : _.methodOf(value);
13615 return methodOf(path);
13618 assert.deepEqual(actual, expected);
13622 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
13625 var values = [, null, undefined],
13626 expected = lodashStable.map(values, alwaysUndefined);
13628 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
13629 var actual = lodashStable.map(values, function(value, index) {
13630 var methodOf = index ? _.methodOf() : _.methodOf(value);
13631 return methodOf(path);
13634 assert.deepEqual(actual, expected);
13638 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
13642 methodOf = _.methodOf(object);
13644 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
13645 assert.strictEqual(methodOf(path), undefined);
13649 QUnit.test('should apply partial arguments to function', function(assert) {
13654 return slice.call(arguments);
13658 var methodOf = _.methodOf(object, 1, 2, 3);
13660 lodashStable.each(['fn', ['fn']], function(path) {
13661 assert.deepEqual(methodOf(path), [1, 2, 3]);
13665 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
13668 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
13669 methodOf = _.methodOf(object);
13671 lodashStable.each(['a.b', ['a', 'b']], function(path) {
13672 assert.strictEqual(methodOf(path), 1);
13677 /*--------------------------------------------------------------------------*/
13679 QUnit.module('lodash.min');
13682 QUnit.test('should return the smallest value from a collection', function(assert) {
13685 assert.strictEqual(_.min([1, 2, 3]), 1);
13688 QUnit.test('should return `undefined` for empty collections', function(assert) {
13691 var values = falsey.concat([[]]),
13692 expected = lodashStable.map(values, alwaysUndefined);
13694 var actual = lodashStable.map(values, function(value, index) {
13696 return index ? _.min(value) : _.min();
13700 assert.deepEqual(actual, expected);
13703 QUnit.test('should work with non-numeric collection values', function(assert) {
13706 assert.strictEqual(_.min(['a', 'b']), 'a');
13710 /*--------------------------------------------------------------------------*/
13712 QUnit.module('extremum methods');
13714 lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
13715 var array = [1, 2, 3],
13716 func = _[methodName],
13717 isMax = /^max/.test(methodName);
13719 QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
13722 var curr = new Date,
13723 past = new Date(0);
13725 assert.strictEqual(func([curr, past]), isMax ? curr : past);
13728 QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
13731 var array = lodashStable.range(0, 5e5);
13732 assert.strictEqual(func(array), isMax ? 499999 : 0);
13735 QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
13739 var actual = _([40])[methodName]();
13740 assert.strictEqual(actual, 40);
13748 lodashStable.each(['maxBy', 'minBy'], function(methodName) {
13749 var array = [1, 2, 3],
13750 func = _[methodName],
13751 isMax = methodName == 'maxBy';
13753 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
13756 var actual = func(array, function(num) {
13760 assert.strictEqual(actual, isMax ? 1 : 3);
13763 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
13766 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
13767 actual = func(objects, 'a');
13769 assert.deepEqual(actual, objects[isMax ? 1 : 2]);
13771 var arrays = [[2], [3], [1]];
13772 actual = func(arrays, 0);
13774 assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
13777 QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
13780 var value = isMax ? -Infinity : Infinity,
13781 object = { 'a': value };
13783 var actual = func([object, { 'a': value }], function(object) {
13787 assert.strictEqual(actual, object);
13791 /*--------------------------------------------------------------------------*/
13793 QUnit.module('lodash.mixin');
13796 function Wrapper(value) {
13797 if (!(this instanceof Wrapper)) {
13798 return new Wrapper(value);
13800 if (_.has(value, '__wrapped__')) {
13801 var actions = slice.call(value.__actions__),
13802 chain = value.__chain__;
13804 value = value.__wrapped__;
13806 this.__wrapped__ = value;
13807 this.__actions__ = actions || [];
13808 this.__chain__ = chain || false;
13811 Wrapper.prototype.value = function() {
13812 return getUnwrappedValue(this);
13816 source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
13818 QUnit.test('should mixin `source` methods into lodash', function(assert) {
13824 assert.strictEqual(_.a(array), 'a');
13825 assert.strictEqual(_(array).a().value(), 'a');
13828 delete _.prototype.a;
13830 assert.notOk('b' in _);
13831 assert.notOk('b' in _.prototype);
13834 delete _.prototype.b;
13837 skipTest(assert, 4);
13841 QUnit.test('should mixin chaining methods by reference', function(assert) {
13848 assert.strictEqual(_.a(array), 'b');
13849 assert.strictEqual(_(array).a().value(), 'a');
13852 delete _.prototype.a;
13855 skipTest(assert, 2);
13859 QUnit.test('should use a default `object` of `this`', function(assert) {
13862 var object = lodashStable.create(_);
13863 object.mixin(source);
13865 assert.strictEqual(object.a(array), 'a');
13867 assert.notOk('a' in _);
13868 assert.notOk('a' in _.prototype);
13871 delete Wrapper.prototype.a;
13873 delete Wrapper.prototype.b;
13876 QUnit.test('should accept an `object` argument', function(assert) {
13880 _.mixin(object, source);
13881 assert.strictEqual(object.a(array), 'a');
13884 QUnit.test('should return `object`', function(assert) {
13888 assert.strictEqual(_.mixin(object, source), object);
13889 assert.strictEqual(_.mixin(), _);
13892 QUnit.test('should work with a function for `object`', function(assert) {
13895 _.mixin(Wrapper, source);
13897 var wrapped = Wrapper(array),
13898 actual = wrapped.a();
13900 assert.strictEqual(actual.value(), 'a');
13901 assert.ok(actual instanceof Wrapper);
13904 delete Wrapper.prototype.a;
13906 delete Wrapper.prototype.b;
13909 QUnit.test('should not assign inherited `source` methods', function(assert) {
13913 Foo.prototype.a = noop;
13916 assert.strictEqual(_.mixin(object, new Foo), object);
13919 QUnit.test('should accept an `options` argument', function(assert) {
13922 function message(func, chain) {
13923 return (func === _ ? 'lodash' : 'provided') + ' function should ' + (chain ? '' : 'not ') + 'chain';
13926 lodashStable.each([_, Wrapper], function(func) {
13927 lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
13930 _.mixin(source, options);
13932 _.mixin(func, source, options);
13934 var wrapped = func(array),
13935 actual = wrapped.a();
13937 if (options.chain) {
13938 assert.strictEqual(actual.value(), 'a', message(func, true));
13939 assert.ok(actual instanceof func, message(func, true));
13941 assert.strictEqual(actual, 'a', message(func, false));
13942 assert.notOk(actual instanceof func, message(func, false));
13945 delete func.prototype.a;
13947 delete func.prototype.b;
13950 skipTest(assert, 2);
13956 QUnit.test('should not extend lodash when an `object` is provided with an empty `options` object', function(assert) {
13959 _.mixin({ 'a': noop }, {});
13960 assert.notOk('a' in _);
13964 QUnit.test('should not error for non-object `options` values', function(assert) {
13970 _.mixin({}, source, 1);
13979 _.mixin(source, 1);
13984 delete _.prototype.a;
13986 delete _.prototype.b;
13991 QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
13994 lodashStable.each([_, Wrapper], function(func) {
13997 var wrapped = _(source),
13998 actual = wrapped.mixin();
14000 assert.strictEqual(actual.value(), _);
14004 actual = wrapped.mixin(source);
14005 assert.notStrictEqual(actual, wrapped);
14008 delete func.prototype.a;
14010 delete func.prototype.b;
14018 QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
14022 _.mixin({ 'a': _.countBy, 'b': _.filter });
14024 var array = lodashStable.range(LARGE_ARRAY_SIZE),
14025 actual = _(array).a().map(square).b(isEven).take().value();
14027 assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
14030 delete _.prototype.a;
14032 delete _.prototype.b;
14040 /*--------------------------------------------------------------------------*/
14042 QUnit.module('lodash.orderBy');
14046 { 'a': 'x', 'b': 3 },
14047 { 'a': 'y', 'b': 4 },
14048 { 'a': 'x', 'b': 1 },
14049 { 'a': 'y', 'b': 2 }
14052 QUnit.test('should sort by a single property by a specified order', function(assert) {
14055 var actual = _.orderBy(objects, 'a', 'desc');
14056 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
14059 QUnit.test('should sort by multiple properties by specified orders', function(assert) {
14062 var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
14063 assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
14066 QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
14069 var expected = [objects[2], objects[0], objects[3], objects[1]],
14070 actual = _.orderBy(objects, ['a', 'b']);
14072 assert.deepEqual(actual, expected);
14074 expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
14076 actual = lodashStable.map(falsey, function(order, index) {
14077 return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
14080 assert.deepEqual(actual, expected);
14083 QUnit.test('should work with `orders` specified as string objects', function(assert) {
14086 var actual = _.orderBy(objects, ['a'], [Object('desc')]);
14087 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
14091 /*--------------------------------------------------------------------------*/
14093 QUnit.module('lodash.overArgs');
14097 return slice.call(arguments);
14100 QUnit.test('should transform each argument', function(assert) {
14103 var over = _.overArgs(fn, doubled, square);
14104 assert.deepEqual(over(5, 10), [10, 100]);
14107 QUnit.test('should flatten `transforms`', function(assert) {
14110 var over = _.overArgs(fn, [doubled, square], String);
14111 assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
14114 QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
14117 var over = _.overArgs(fn, doubled, square);
14118 assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
14121 QUnit.test('should not transform any arguments if no transforms are provided', function(assert) {
14124 var over = _.overArgs(fn);
14125 assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
14128 QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
14131 var over = _.overArgs(fn, doubled, identity);
14132 assert.deepEqual(over(5), [10]);
14135 QUnit.test('should provide the correct argument to each transform', function(assert) {
14139 transform = function() { argsList.push(slice.call(arguments)); },
14140 over = _.overArgs(noop, transform, transform, transform);
14143 assert.deepEqual(argsList, [['a'], ['b']]);
14146 QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
14149 var over = _.overArgs(function(x) {
14155 var object = { 'over': over, 'true': 1 };
14156 assert.strictEqual(object.over(object), 1);
14160 /*--------------------------------------------------------------------------*/
14162 QUnit.module('lodash.negate');
14165 QUnit.test('should create a function that negates the result of `func`', function(assert) {
14168 var negate = _.negate(isEven);
14170 assert.strictEqual(negate(1), true);
14171 assert.strictEqual(negate(2), false);
14175 /*--------------------------------------------------------------------------*/
14177 QUnit.module('lodash.noop');
14180 QUnit.test('should return `undefined`', function(assert) {
14183 var values = empties.concat(true, new Date, _, 1, /x/, 'a'),
14184 expected = lodashStable.map(values, alwaysUndefined);
14186 var actual = lodashStable.map(values, function(value, index) {
14187 return index ? _.noop(value) : _.noop();
14190 assert.deepEqual(actual, expected);
14194 /*--------------------------------------------------------------------------*/
14196 QUnit.module('lodash.noConflict');
14199 QUnit.test('should return the `lodash` function', function(assert) {
14202 if (!isModularize) {
14203 assert.strictEqual(_.noConflict(), oldDash);
14204 assert.notStrictEqual(root._, oldDash);
14208 skipTest(assert, 2);
14212 QUnit.test('should work with a `root` of `this`', function(assert) {
14215 if (!isModularize && !coverage && (!document && realm.object)) {
14216 var fs = require('fs'),
14217 vm = require('vm'),
14219 context = vm.createContext({ '_': expected, 'console': console }),
14220 source = fs.readFileSync(filePath, 'utf8');
14222 vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
14224 assert.strictEqual(context._, expected);
14225 assert.ok(context.lodash);
14228 skipTest(assert, 2);
14233 /*--------------------------------------------------------------------------*/
14235 QUnit.module('lodash.now');
14238 QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
14241 var done = assert.async();
14243 var stamp = +new Date,
14246 assert.ok(actual >= stamp);
14248 setTimeout(function() {
14249 assert.ok(_.now() > actual);
14255 /*--------------------------------------------------------------------------*/
14257 QUnit.module('lodash.nthArg');
14260 QUnit.test('should create a function that returns its nth argument', function(assert) {
14263 var expected = ['a', 'b', 'c'];
14265 var actual = lodashStable.times(expected.length, function(n) {
14266 var func = _.nthArg(n);
14267 return func.apply(undefined, expected);
14270 assert.deepEqual(actual, expected);
14273 QUnit.test('should coerce `n` to an integer', function(assert) {
14276 var values = falsey,
14277 expected = lodashStable.map(values, alwaysA);
14279 var actual = lodashStable.map(values, function(n) {
14280 var func = n ? _.nthArg(n) : _.nthArg();
14281 return func('a', 'b', 'c');
14284 assert.deepEqual(actual, expected);
14286 values = ['1', 1.6];
14287 expected = lodashStable.map(values, alwaysB);
14289 actual = lodashStable.map(values, function(n) {
14290 var func = _.nthArg(n);
14291 return func('a', 'b', 'c');
14294 assert.deepEqual(actual, expected);
14298 /*--------------------------------------------------------------------------*/
14300 QUnit.module('lodash.omit');
14303 var args = arguments,
14304 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
14306 QUnit.test('should flatten `props`', function(assert) {
14309 assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
14310 assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
14313 QUnit.test('should work with a primitive `object` argument', function(assert) {
14319 assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
14321 delete stringProto.a;
14322 delete stringProto.b;
14325 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
14329 lodashStable.each([null, undefined], function(value) {
14330 assert.deepEqual(_.omit(value, 'valueOf'), {});
14332 delete objectProto.a;
14335 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
14338 assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
14341 QUnit.test('should coerce property names to strings', function(assert) {
14344 assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
14348 /*--------------------------------------------------------------------------*/
14350 QUnit.module('lodash.omitBy');
14353 QUnit.test('should work with a predicate argument', function(assert) {
14356 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
14358 var actual = _.omitBy(object, function(num) {
14359 return num != 2 && num != 4;
14362 assert.deepEqual(actual, { 'b': 2, 'd': 4 });
14366 /*--------------------------------------------------------------------------*/
14368 QUnit.module('omit methods');
14370 lodashStable.each(['omit', 'omitBy'], function(methodName) {
14371 var expected = { 'b': 2, 'd': 4 },
14372 func = _[methodName],
14373 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
14374 prop = function(object, props) { return props; };
14376 if (methodName == 'omitBy') {
14377 prop = function(object, props) {
14378 props = typeof props == 'string' ? [props] : props;
14379 return function(value) {
14380 return _.some(props, function(key) { return object[key] === value; });
14384 QUnit.test('`_.' + methodName + '` should create an object with omitted properties', function(assert) {
14387 assert.deepEqual(func(object, prop(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
14388 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
14391 QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) {
14395 Foo.prototype = object;
14398 assert.deepEqual(func(foo, prop(object, ['a', 'c'])), expected);
14401 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
14404 var array = [1, 2, 3];
14405 assert.deepEqual(func(array, prop(array, ['0', '2'])), { '1': 2 });
14409 /*--------------------------------------------------------------------------*/
14411 QUnit.module('lodash.once');
14414 QUnit.test('should invoke `func` once', function(assert) {
14418 once = _.once(function() { return ++count; });
14421 assert.strictEqual(once(), 1);
14422 assert.strictEqual(count, 1);
14425 QUnit.test('should ignore recursive calls', function(assert) {
14430 var once = _.once(function() {
14435 assert.strictEqual(once(), 1);
14436 assert.strictEqual(count, 1);
14439 QUnit.test('should not throw more than once', function(assert) {
14444 var once = _.once(function() {
14448 assert.raises(once);
14459 /*--------------------------------------------------------------------------*/
14461 QUnit.module('lodash.over');
14464 QUnit.test('should create a function that invokes `iteratees`', function(assert) {
14467 var over = _.over(Math.max, Math.min);
14468 assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
14471 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
14474 var over = _.over(undefined, null);
14475 assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
14478 QUnit.test('should work with a "_.property" style predicate', function(assert) {
14481 var object = { 'a': 1, 'b': 2 },
14482 over = _.over('b', 'a');
14484 assert.deepEqual(over(object), [2, 1]);
14487 QUnit.test('should work with a "_.matches" style predicate', function(assert) {
14490 var object = { 'a': 1, 'b': 2 },
14491 over = _.over({ 'c': 3 }, { 'a': 1 });
14493 assert.deepEqual(over(object), [false, true]);
14496 QUnit.test('should provide arguments to predicates', function(assert) {
14499 var over = _.over(function() {
14500 return slice.call(arguments);
14503 assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
14506 QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
14509 var over = _.over(function() { return this.b; }, function() { return this.a; }),
14510 object = { 'over': over, 'a': 1, 'b': 2 };
14512 assert.deepEqual(object.over(), [2, 1]);
14516 /*--------------------------------------------------------------------------*/
14518 QUnit.module('lodash.overEvery');
14521 QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
14524 var over = _.overEvery(alwaysTrue, alwaysOne, alwaysA);
14525 assert.strictEqual(over(), true);
14528 QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
14532 countFalse = function() { count++; return false; },
14533 countTrue = function() { count++; return true; },
14534 over = _.overEvery(countTrue, countFalse, countTrue);
14536 assert.strictEqual(over(), false);
14537 assert.strictEqual(count, 2);
14540 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
14543 var over = _.overEvery(undefined, null);
14544 assert.strictEqual(over(true), true);
14545 assert.strictEqual(over(false), false);
14548 QUnit.test('should work with a "_.property" style predicate', function(assert) {
14551 var object = { 'a': 1, 'b': 2 },
14552 over = _.overEvery('a', 'c');
14554 assert.strictEqual(over(object), false);
14556 over = _.overEvery('b', 'a');
14557 assert.strictEqual(over(object), true);
14560 QUnit.test('should work with a "_.matches" style predicate', function(assert) {
14563 var object = { 'a': 1, 'b': 2 },
14564 over = _.overEvery({ 'b': 2 }, { 'a': 1 });
14566 assert.strictEqual(over(object), true);
14568 over = _.overEvery({ 'a': 1 }, { 'c': 3 });
14569 assert.strictEqual(over(object), false);
14572 QUnit.test('should flatten `predicates`', function(assert) {
14575 var over = _.overEvery(alwaysTrue, [alwaysFalse]);
14576 assert.strictEqual(over(), false);
14579 QUnit.test('should provide arguments to predicates', function(assert) {
14584 var over = _.overEvery(function() {
14585 args = slice.call(arguments);
14588 over('a', 'b', 'c');
14589 assert.deepEqual(args, ['a', 'b', 'c']);
14592 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
14595 var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
14596 object = { 'over': over, 'a': 1, 'b': 2 };
14598 assert.strictEqual(object.over(), true);
14601 assert.strictEqual(object.over(), false);
14605 /*--------------------------------------------------------------------------*/
14607 QUnit.module('lodash.overSome');
14610 QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
14613 var over = _.overSome(alwaysFalse, alwaysOne, alwaysEmptyString);
14614 assert.strictEqual(over(), true);
14616 over = _.overSome(alwaysNull, alwaysA, alwaysZero);
14617 assert.strictEqual(over(), true);
14620 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
14624 countFalse = function() { count++; return false; },
14625 countTrue = function() { count++; return true; },
14626 over = _.overSome(countFalse, countTrue, countFalse);
14628 assert.strictEqual(over(), true);
14629 assert.strictEqual(count, 2);
14632 QUnit.test('should return `false` if all predicates return falsey', function(assert) {
14635 var over = _.overSome(alwaysFalse, alwaysFalse, alwaysFalse);
14636 assert.strictEqual(over(), false);
14638 over = _.overSome(alwaysNull, alwaysZero, alwaysEmptyString);
14639 assert.strictEqual(over(), false);
14642 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
14645 var over = _.overSome(undefined, null);
14646 assert.strictEqual(over(true), true);
14647 assert.strictEqual(over(false), false);
14650 QUnit.test('should work with a "_.property" style predicate', function(assert) {
14653 var object = { 'a': 1, 'b': 2 },
14654 over = _.overSome('c', 'a');
14656 assert.strictEqual(over(object), true);
14658 over = _.overSome('d', 'c');
14659 assert.strictEqual(over(object), false);
14662 QUnit.test('should work with a "_.matches" style predicate', function(assert) {
14665 var object = { 'a': 1, 'b': 2 },
14666 over = _.overSome({ 'c': 3 }, { 'a': 1 });
14668 assert.strictEqual(over(object), true);
14670 over = _.overSome({ 'b': 1 }, { 'a': 2 });
14671 assert.strictEqual(over(object), false);
14674 QUnit.test('should flatten `predicates`', function(assert) {
14677 var over = _.overSome(alwaysFalse, [alwaysTrue]);
14678 assert.strictEqual(over(), true);
14681 QUnit.test('should provide arguments to predicates', function(assert) {
14686 var over = _.overSome(function() {
14687 args = slice.call(arguments);
14690 over('a', 'b', 'c');
14691 assert.deepEqual(args, ['a', 'b', 'c']);
14694 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
14697 var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
14698 object = { 'over': over, 'a': 1, 'b': 2 };
14700 assert.strictEqual(object.over(), true);
14702 object.a = object.b = 0;
14703 assert.strictEqual(object.over(), false);
14707 /*--------------------------------------------------------------------------*/
14709 QUnit.module('lodash.pad');
14712 QUnit.test('should pad a string to a given length', function(assert) {
14715 assert.strictEqual(_.pad('abc', 9), ' abc ');
14718 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
14721 assert.strictEqual(_.pad('abc', 8), ' abc ');
14722 assert.strictEqual(_.pad('abc', 8, '_-'), '_-abc_-_');
14725 QUnit.test('should coerce `string` to a string', function(assert) {
14728 assert.strictEqual(_.pad(Object('abc'), 4), 'abc ');
14729 assert.strictEqual(_.pad({ 'toString': lodashStable.constant('abc') }, 5), ' abc ');
14733 /*--------------------------------------------------------------------------*/
14735 QUnit.module('lodash.padEnd');
14738 QUnit.test('should pad a string to a given length', function(assert) {
14741 assert.strictEqual(_.padEnd('abc', 6), 'abc ');
14744 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
14747 assert.strictEqual(_.padEnd('abc', 6, '_-'), 'abc_-_');
14750 QUnit.test('should coerce `string` to a string', function(assert) {
14753 assert.strictEqual(_.padEnd(Object('abc'), 4), 'abc ');
14754 assert.strictEqual(_.padEnd({ 'toString': lodashStable.constant('abc') }, 5), 'abc ');
14758 /*--------------------------------------------------------------------------*/
14760 QUnit.module('lodash.padStart');
14763 QUnit.test('should pad a string to a given length', function(assert) {
14766 assert.strictEqual(_.padStart('abc', 6), ' abc');
14769 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
14772 assert.strictEqual(_.padStart('abc', 6, '_-'), '_-_abc');
14775 QUnit.test('should coerce `string` to a string', function(assert) {
14778 assert.strictEqual(_.padStart(Object('abc'), 4), ' abc');
14779 assert.strictEqual(_.padStart({ 'toString': lodashStable.constant('abc') }, 5), ' abc');
14783 /*--------------------------------------------------------------------------*/
14785 QUnit.module('pad methods');
14787 lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
14788 var func = _[methodName],
14789 isPad = methodName == 'pad',
14790 isStart = methodName == 'padStart';
14792 QUnit.test('`_.' + methodName + '` should not pad is string is >= `length`', function(assert) {
14795 assert.strictEqual(func('abc', 2), 'abc');
14796 assert.strictEqual(func('abc', 3), 'abc');
14799 QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
14802 lodashStable.each([0, -2], function(length) {
14803 assert.strictEqual(func('abc', length), 'abc');
14807 QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
14810 lodashStable.each(['', '4'], function(length) {
14811 var actual = length ? (isStart ? ' abc' : 'abc ') : 'abc';
14812 assert.strictEqual(func('abc', length), actual);
14816 QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
14819 lodashStable.each([undefined, '_-'], function(chars) {
14820 var expected = chars ? (isPad ? '__' : chars) : ' ';
14821 assert.strictEqual(func(null, 2, chars), expected);
14822 assert.strictEqual(func(undefined, 2, chars), expected);
14823 assert.strictEqual(func('', 2, chars), expected);
14827 QUnit.test('`_.' + methodName + '` should work with nullish or empty string values for `chars`', function(assert) {
14830 assert.notStrictEqual(func('abc', 6, null), 'abc');
14831 assert.notStrictEqual(func('abc', 6, undefined), 'abc');
14832 assert.strictEqual(func('abc', 6, ''), 'abc');
14836 /*--------------------------------------------------------------------------*/
14838 QUnit.module('lodash.parseInt');
14841 QUnit.test('should accept a `radix` argument', function(assert) {
14844 var expected = lodashStable.range(2, 37);
14846 var actual = lodashStable.map(expected, function(radix) {
14847 return _.parseInt('10', radix);
14850 assert.deepEqual(actual, expected);
14853 QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
14856 assert.strictEqual(_.parseInt('10'), 10);
14857 assert.strictEqual(_.parseInt('10', 0), 10);
14858 assert.strictEqual(_.parseInt('10', 10), 10);
14859 assert.strictEqual(_.parseInt('10', undefined), 10);
14862 QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
14865 lodashStable.each(['0x20', '0X20'], function(string) {
14866 assert.strictEqual(_.parseInt(string), 32);
14867 assert.strictEqual(_.parseInt(string, 0), 32);
14868 assert.strictEqual(_.parseInt(string, 16), 32);
14869 assert.strictEqual(_.parseInt(string, undefined), 32);
14873 QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
14876 assert.strictEqual(_.parseInt('08'), 8);
14877 assert.strictEqual(_.parseInt('08', 10), 8);
14880 QUnit.test('should parse strings with leading whitespace (test in Chrome and Firefox)', function(assert) {
14883 var expected = [8, 8, 10, 10, 32, 32, 32, 32];
14885 lodashStable.times(2, function(index) {
14887 func = (index ? (lodashBizarro || {}) : _).parseInt;
14890 lodashStable.times(2, function(otherIndex) {
14891 var string = otherIndex ? '10' : '08';
14893 func(whitespace + string, 10),
14894 func(whitespace + string)
14898 lodashStable.each(['0x20', '0X20'], function(string) {
14900 func(whitespace + string),
14901 func(whitespace + string, 16)
14905 assert.deepEqual(actual, expected);
14913 QUnit.test('should coerce `radix` to a number', function(assert) {
14916 var object = { 'valueOf': alwaysZero };
14917 assert.strictEqual(_.parseInt('08', object), 8);
14918 assert.strictEqual(_.parseInt('0x20', object), 32);
14921 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
14924 var strings = lodashStable.map(['6', '08', '10'], Object),
14925 actual = lodashStable.map(strings, _.parseInt);
14927 assert.deepEqual(actual, [6, 8, 10]);
14929 actual = lodashStable.map('123', _.parseInt);
14930 assert.deepEqual(actual, [1, 2, 3]);
14934 /*--------------------------------------------------------------------------*/
14936 QUnit.module('partial methods');
14938 lodashStable.each(['partial', 'partialRight'], function(methodName) {
14939 var func = _[methodName],
14940 isPartial = methodName == 'partial',
14941 ph = func.placeholder;
14943 QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
14946 var par = func(identity, 'a');
14947 assert.strictEqual(par(), 'a');
14950 QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
14953 var fn = function(a, b) { return [a, b]; },
14954 par = func(fn, 'a'),
14955 expected = ['a', 'b'];
14957 assert.deepEqual(par('b'), isPartial ? expected : expected.reverse());
14960 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
14963 var fn = function() { return arguments.length; },
14966 assert.strictEqual(par(), 0);
14969 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
14972 var par = func(identity);
14973 assert.strictEqual(par('a'), 'a');
14976 QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
14979 var fn = function() { return slice.call(arguments); },
14980 par = func(fn, ph, 'b', ph);
14982 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
14983 assert.deepEqual(par('a'), ['a', 'b', undefined]);
14984 assert.deepEqual(par(), [undefined, 'b', undefined]);
14987 assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
14989 par = func(fn, ph, 'c', ph);
14990 assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
14994 QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
14997 var fn = function(a, b, c) {},
14998 par = func(fn, 'a');
15000 assert.strictEqual(par.length, 0);
15003 QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
15006 function Foo(value) {
15007 return value && object;
15013 assert.ok(new par instanceof Foo);
15014 assert.strictEqual(new par(true), object);
15017 QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
15020 function greet(greeting, name) {
15021 return greeting + ' ' + name;
15024 var par1 = func(greet, 'hi'),
15025 par2 = func(par1, 'barney'),
15026 par3 = func(par1, 'pebbles');
15028 assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
15029 assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
15030 assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
15033 QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
15036 var fn = function(a, b, c) { return a + b + c; },
15037 curried = _.curry(func(fn, 1), 2);
15039 assert.strictEqual(curried(2, 3), 6);
15040 assert.strictEqual(curried(2)(3), 6);
15043 QUnit.test('should work with placeholders and curried functions', function(assert) {
15046 var fn = function() { return slice.call(arguments); },
15047 curried = _.curry(fn),
15048 par = func(curried, ph, 'b', ph, 'd');
15050 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
15054 /*--------------------------------------------------------------------------*/
15056 QUnit.module('lodash.partialRight');
15059 QUnit.test('should work as a deep `_.defaults`', function(assert) {
15062 var object = { 'a': { 'b': 1 } },
15063 source = { 'a': { 'b': 2, 'c': 3 } },
15064 expected = { 'a': { 'b': 1, 'c': 3 } };
15066 var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
15067 return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
15070 assert.deepEqual(defaultsDeep(object, source), expected);
15074 /*--------------------------------------------------------------------------*/
15076 QUnit.module('methods using `createWrapper`');
15080 return slice.call(arguments);
15083 var ph1 = _.bind.placeholder,
15084 ph2 = _.bindKey.placeholder,
15085 ph3 = _.partial.placeholder,
15086 ph4 = _.partialRight.placeholder;
15088 QUnit.test('should work with combinations of partial functions', function(assert) {
15091 var a = _.partial(fn),
15092 b = _.partialRight(a, 3),
15093 c = _.partial(b, 1);
15095 assert.deepEqual(c(2), [1, 2, 3]);
15098 QUnit.test('should work with combinations of bound and partial functions', function(assert) {
15101 var fn = function() {
15102 var result = [this.a];
15103 push.apply(result, arguments);
15107 var expected = [1, 2, 3, 4],
15108 object = { 'a': 1, 'fn': fn };
15110 var a = _.bindKey(object, 'fn'),
15111 b = _.partialRight(a, 4),
15112 c = _.partial(b, 2);
15114 assert.deepEqual(c(3), expected);
15116 a = _.bind(fn, object);
15117 b = _.partialRight(a, 4);
15118 c = _.partial(b, 2);
15120 assert.deepEqual(c(3), expected);
15122 a = _.partial(fn, 2);
15123 b = _.bind(a, object);
15124 c = _.partialRight(b, 4);
15126 assert.deepEqual(c(3), expected);
15129 QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
15132 function Foo(a, b, c) {
15133 return b === 0 && object;
15136 var combo = _.partial(_.partialRight(Foo, 3), 1),
15139 assert.ok(new combo(2) instanceof Foo);
15140 assert.strictEqual(new combo(0), object);
15143 QUnit.test('should work with combinations of functions with placeholders', function(assert) {
15146 var expected = [1, 2, 3, 4, 5, 6],
15147 object = { 'fn': fn };
15149 var a = _.bindKey(object, 'fn', ph2, 2),
15150 b = _.partialRight(a, ph4, 6),
15151 c = _.partial(b, 1, ph3, 4);
15153 assert.deepEqual(c(3, 5), expected);
15155 a = _.bind(fn, object, ph1, 2);
15156 b = _.partialRight(a, ph4, 6);
15157 c = _.partial(b, 1, ph3, 4);
15159 assert.deepEqual(c(3, 5), expected);
15161 a = _.partial(fn, ph3, 2);
15162 b = _.bind(a, object, 1, ph1, 4);
15163 c = _.partialRight(b, ph4, 6);
15165 assert.deepEqual(c(3, 5), expected);
15168 QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
15171 var expected = [1, 2, 3, 4],
15172 object = { 'fn': fn };
15174 var a = _.bindKey(object, 'fn', ph2, 2),
15175 b = _.partialRight(a, ph4, 4),
15176 c = _.partial(b, ph3, 3);
15178 assert.deepEqual(c(1), expected);
15180 a = _.bind(fn, object, ph1, 2);
15181 b = _.partialRight(a, ph4, 4);
15182 c = _.partial(b, ph3, 3);
15184 assert.deepEqual(c(1), expected);
15186 a = _.partial(fn, ph3, 2);
15187 b = _.bind(a, object, ph1, 3);
15188 c = _.partialRight(b, ph4, 4);
15190 assert.deepEqual(c(1), expected);
15193 QUnit.test('should work with recursively bound functions', function(assert) {
15196 var fn = function() {
15200 var a = _.bind(fn, { 'a': 1 }),
15201 b = _.bind(a, { 'a': 2 }),
15202 c = _.bind(b, { 'a': 3 });
15204 assert.strictEqual(c(), 1);
15207 QUnit.test('should work when hot', function(assert) {
15210 lodashStable.times(2, function(index) {
15211 var fn = function() {
15212 var result = [this];
15213 push.apply(result, arguments);
15218 bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
15219 expected = [object, 1, 2, 3];
15221 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
15222 var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
15223 return index ? bound2(3) : bound2(1, 2, 3);
15226 assert.deepEqual(actual, expected);
15228 actual = _.last(lodashStable.times(HOT_COUNT, function() {
15229 var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
15230 bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
15232 return index ? bound2(3) : bound2(1, 2, 3);
15235 assert.deepEqual(actual, expected);
15238 lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
15239 var fn = function(a, b, c) { return [a, b, c]; },
15240 curried = _[methodName](fn),
15241 expected = index ? [3, 2, 1] : [1, 2, 3];
15243 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
15244 return curried(1)(2)(3);
15247 assert.deepEqual(actual, expected);
15249 actual = _.last(lodashStable.times(HOT_COUNT, function() {
15250 var curried = _[methodName](fn);
15251 return curried(1)(2)(3);
15254 assert.deepEqual(actual, expected);
15257 lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
15258 var func = _[methodName],
15259 fn = function() { return slice.call(arguments); },
15260 par1 = func(fn, 1),
15261 expected = index ? [3, 2, 1] : [1, 2, 3];
15263 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
15264 var par2 = func(par1, 2);
15268 assert.deepEqual(actual, expected);
15270 actual = _.last(lodashStable.times(HOT_COUNT, function() {
15271 var par1 = func(fn, 1),
15272 par2 = func(par1, 2);
15277 assert.deepEqual(actual, expected);
15282 /*--------------------------------------------------------------------------*/
15284 QUnit.module('lodash.partition');
15287 var array = [1, 0, 1];
15289 QUnit.test('should return two groups of elements', function(assert) {
15292 assert.deepEqual(_.partition([], identity), [[], []]);
15293 assert.deepEqual(_.partition(array, alwaysTrue), [array, []]);
15294 assert.deepEqual(_.partition(array, alwaysFalse), [[], array]);
15297 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
15300 var values = [, null, undefined],
15301 expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
15303 var actual = lodashStable.map(values, function(value, index) {
15304 return index ? _.partition(array, value) : _.partition(array);
15307 assert.deepEqual(actual, expected);
15310 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
15313 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
15314 actual = _.partition(objects, 'a');
15316 assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
15319 QUnit.test('should work with a number for `predicate`', function(assert) {
15328 assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
15329 assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
15332 QUnit.test('should work with an object for `collection`', function(assert) {
15335 var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, function(num) {
15336 return Math.floor(num);
15339 assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
15343 /*--------------------------------------------------------------------------*/
15345 QUnit.module('lodash.pick');
15348 var args = arguments,
15349 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
15351 QUnit.test('should flatten `props`', function(assert) {
15354 assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
15355 assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
15358 QUnit.test('should work with a primitive `object` argument', function(assert) {
15361 assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
15364 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
15367 lodashStable.each([null, undefined], function(value) {
15368 assert.deepEqual(_.pick(value, 'valueOf'), {});
15372 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
15375 assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
15378 QUnit.test('should coerce property names to strings', function(assert) {
15381 assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
15385 /*--------------------------------------------------------------------------*/
15387 QUnit.module('lodash.pickBy');
15390 QUnit.test('should work with a predicate argument', function(assert) {
15393 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
15395 var actual = _.pickBy(object, function(num) {
15396 return num == 1 || num == 3;
15399 assert.deepEqual(actual, { 'a': 1, 'c': 3 });
15403 /*--------------------------------------------------------------------------*/
15405 QUnit.module('pick methods');
15407 lodashStable.each(['pick', 'pickBy'], function(methodName) {
15408 var expected = { 'a': 1, 'c': 3 },
15409 func = _[methodName],
15410 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
15411 prop = function(object, props) { return props; };
15413 if (methodName == 'pickBy') {
15414 prop = function(object, props) {
15415 props = typeof props == 'string' ? [props] : props;
15416 return function(value) {
15417 return _.some(props, function(key) { return object[key] === value; });
15421 QUnit.test('`_.' + methodName + '` should create an object of picked properties', function(assert) {
15424 assert.deepEqual(func(object, prop(object, 'a')), { 'a': 1 });
15425 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
15428 QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) {
15432 Foo.prototype = object;
15435 assert.deepEqual(func(foo, prop(foo, ['a', 'c'])), expected);
15438 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
15441 var array = [1, 2, 3];
15442 assert.deepEqual(func(array, prop(array, '1')), { '1': 2 });
15446 /*--------------------------------------------------------------------------*/
15448 QUnit.module('lodash.property');
15451 QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
15454 var object = { 'a': 1 };
15456 lodashStable.each(['a', ['a']], function(path) {
15457 var prop = _.property(path);
15458 assert.strictEqual(prop.length, 1);
15459 assert.strictEqual(prop(object), 1);
15463 QUnit.test('should pluck deep property values', function(assert) {
15466 var object = { 'a': { 'b': { 'c': 3 } } };
15468 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
15469 var prop = _.property(path);
15470 assert.strictEqual(prop(object), 3);
15474 QUnit.test('should work with non-string `path` arguments', function(assert) {
15477 var array = [1, 2, 3];
15479 lodashStable.each([1, [1]], function(path) {
15480 var prop = _.property(path);
15481 assert.strictEqual(prop(array), 2);
15485 QUnit.test('should coerce key to a string', function(assert) {
15489 fn.toString = lodashStable.constant('fn');
15491 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15492 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
15493 values = [null, undefined, fn, {}];
15495 var actual = lodashStable.transform(objects, function(result, object, index) {
15496 var key = values[index];
15497 lodashStable.each([key, [key]], function(path) {
15498 var prop = _.property(key);
15499 result.push(prop(object));
15503 assert.deepEqual(actual, expected);
15506 QUnit.test('should pluck inherited property values', function(assert) {
15510 Foo.prototype.a = 1;
15512 lodashStable.each(['a', ['a']], function(path) {
15513 var prop = _.property(path);
15514 assert.strictEqual(prop(new Foo), 1);
15518 QUnit.test('should pluck a key over a path', function(assert) {
15521 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
15523 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
15524 var prop = _.property(path);
15525 assert.strictEqual(prop(object), 3);
15529 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15532 var values = [, null, undefined],
15533 expected = lodashStable.map(values, alwaysUndefined);
15535 lodashStable.each(['constructor', ['constructor']], function(path) {
15536 var prop = _.property(path);
15538 var actual = lodashStable.map(values, function(value, index) {
15539 return index ? prop(value) : prop();
15542 assert.deepEqual(actual, expected);
15546 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15549 var values = [, null, undefined],
15550 expected = lodashStable.map(values, alwaysUndefined);
15552 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15553 var prop = _.property(path);
15555 var actual = lodashStable.map(values, function(value, index) {
15556 return index ? prop(value) : prop();
15559 assert.deepEqual(actual, expected);
15563 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15568 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15569 var prop = _.property(path);
15570 assert.strictEqual(prop(object), undefined);
15575 /*--------------------------------------------------------------------------*/
15577 QUnit.module('lodash.propertyOf');
15580 QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
15583 var object = { 'a': 1 },
15584 propOf = _.propertyOf(object);
15586 assert.strictEqual(propOf.length, 1);
15587 lodashStable.each(['a', ['a']], function(path) {
15588 assert.strictEqual(propOf(path), 1);
15592 QUnit.test('should pluck deep property values', function(assert) {
15595 var object = { 'a': { 'b': { 'c': 3 } } },
15596 propOf = _.propertyOf(object);
15598 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
15599 assert.strictEqual(propOf(path), 3);
15603 QUnit.test('should work with non-string `path` arguments', function(assert) {
15606 var array = [1, 2, 3],
15607 propOf = _.propertyOf(array);
15609 lodashStable.each([1, [1]], function(path) {
15610 assert.strictEqual(propOf(path), 2);
15614 QUnit.test('should coerce key to a string', function(assert) {
15618 fn.toString = lodashStable.constant('fn');
15620 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15621 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
15622 values = [null, undefined, fn, {}];
15624 var actual = lodashStable.transform(objects, function(result, object, index) {
15625 var key = values[index];
15626 lodashStable.each([key, [key]], function(path) {
15627 var propOf = _.propertyOf(object);
15628 result.push(propOf(key));
15632 assert.deepEqual(actual, expected);
15635 QUnit.test('should pluck inherited property values', function(assert) {
15638 function Foo() { this.a = 1; }
15639 Foo.prototype.b = 2;
15641 var propOf = _.propertyOf(new Foo);
15643 lodashStable.each(['b', ['b']], function(path) {
15644 assert.strictEqual(propOf(path), 2);
15648 QUnit.test('should pluck a key over a path', function(assert) {
15651 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } },
15652 propOf = _.propertyOf(object);
15654 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
15655 assert.strictEqual(propOf(path), 3);
15659 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15662 var values = [, null, undefined],
15663 expected = lodashStable.map(values, alwaysUndefined);
15665 lodashStable.each(['constructor', ['constructor']], function(path) {
15666 var actual = lodashStable.map(values, function(value, index) {
15667 var propOf = index ? _.propertyOf(value) : _.propertyOf();
15668 return propOf(path);
15671 assert.deepEqual(actual, expected);
15675 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15678 var values = [, null, undefined],
15679 expected = lodashStable.map(values, alwaysUndefined);
15681 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15682 var actual = lodashStable.map(values, function(value, index) {
15683 var propOf = index ? _.propertyOf(value) : _.propertyOf();
15684 return propOf(path);
15687 assert.deepEqual(actual, expected);
15691 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15694 var propOf = _.propertyOf({});
15696 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15697 assert.strictEqual(propOf(path), undefined);
15702 /*--------------------------------------------------------------------------*/
15704 QUnit.module('pull methods');
15706 lodashStable.each(['pull', 'pullAll'], function(methodName) {
15707 var func = _[methodName],
15708 isPull = methodName == 'pull';
15710 function pull(array, values) {
15712 ? func.apply(undefined, [array].concat(values))
15713 : func(array, values);
15716 QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
15719 var array = [1, 2, 3],
15720 actual = pull(array, [1, 3]);
15722 assert.deepEqual(array, [2]);
15723 assert.ok(actual === array);
15726 QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
15729 var array = [1, 2, 3, 4];
15734 assert.notOk('0' in array);
15735 assert.notOk('2' in array);
15738 QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
15741 var array = [1, 2, 3];
15744 pull(array, [undefined]);
15745 assert.deepEqual(array, [1, 3]);
15748 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
15751 var array = [1, NaN, 3, NaN];
15753 pull(array, [NaN]);
15754 assert.deepEqual(array, [1, 3]);
15758 /*--------------------------------------------------------------------------*/
15760 QUnit.module('lodash.pullAllBy');
15763 QUnit.test('should accept an `iteratee` argument', function(assert) {
15766 var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
15768 var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
15772 assert.deepEqual(actual, [{ 'x': 2 }]);
15775 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
15779 array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
15781 _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
15782 args || (args = slice.call(arguments));
15785 assert.deepEqual(args, [{ 'x': 1 }]);
15789 /*--------------------------------------------------------------------------*/
15791 QUnit.module('lodash.pullAt');
15794 QUnit.test('should modify the array and return removed elements', function(assert) {
15797 var array = [1, 2, 3],
15798 actual = _.pullAt(array, [0, 1]);
15800 assert.deepEqual(array, [3]);
15801 assert.deepEqual(actual, [1, 2]);
15804 QUnit.test('should work with unsorted indexes', function(assert) {
15807 var array = [1, 2, 3, 4],
15808 actual = _.pullAt(array, [1, 3, 0]);
15810 assert.deepEqual(array, [3]);
15811 assert.deepEqual(actual, [2, 4, 1]);
15814 QUnit.test('should work with repeated indexes', function(assert) {
15817 var array = [1, 2, 3, 4],
15818 actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
15820 assert.deepEqual(array, [4]);
15821 assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
15824 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
15827 var array = ['a', 'b', 'c'],
15828 actual = _.pullAt(array, [2, 4, 0]);
15830 assert.deepEqual(array, ['b']);
15831 assert.deepEqual(actual, ['c', undefined, 'a']);
15834 QUnit.test('should flatten `indexes`', function(assert) {
15837 var array = ['a', 'b', 'c'];
15838 assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
15839 assert.deepEqual(array, ['b']);
15841 array = ['a', 'b', 'c', 'd'];
15842 assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
15843 assert.deepEqual(array, ['b']);
15846 QUnit.test('should return an empty array when no indexes are provided', function(assert) {
15849 var array = ['a', 'b', 'c'],
15850 actual = _.pullAt(array);
15852 assert.deepEqual(array, ['a', 'b', 'c']);
15853 assert.deepEqual(actual, []);
15855 actual = _.pullAt(array, [], []);
15857 assert.deepEqual(array, ['a', 'b', 'c']);
15858 assert.deepEqual(actual, []);
15861 QUnit.test('should work with non-index paths', function(assert) {
15864 var values = lodashStable.reject(empties, function(value) {
15865 return (value === 0) || lodashStable.isArray(value);
15866 }).concat(-1, 1.1);
15868 var array = lodashStable.transform(values, function(result, value) {
15872 var expected = lodashStable.map(values, alwaysOne),
15873 actual = _.pullAt(array, values);
15875 assert.deepEqual(actual, expected);
15877 expected = lodashStable.map(values, alwaysUndefined),
15878 actual = _.at(array, values);
15880 assert.deepEqual(actual, expected);
15883 QUnit.test('should work with deep paths', function(assert) {
15887 array.a = { 'b': { 'c': 3 } };
15889 var actual = _.pullAt(array, 'a.b.c');
15891 assert.deepEqual(actual, [3]);
15892 assert.deepEqual(array.a, { 'b': {} });
15895 actual = _.pullAt(array, 'a.b.c.d.e');
15898 assert.deepEqual(actual, [undefined]);
15901 QUnit.test('should work with a falsey `array` argument when keys are provided', function(assert) {
15904 var values = falsey.slice(),
15905 expected = lodashStable.map(values, lodashStable.constant(Array(4)));
15907 var actual = lodashStable.map(values, function(array) {
15909 return _.pullAt(array, 0, 1, 'pop', 'push');
15913 assert.deepEqual(actual, expected);
15917 /*--------------------------------------------------------------------------*/
15919 QUnit.module('lodash.random');
15922 var array = Array(1000);
15924 QUnit.test('should return `0` or `1` when arguments are not provided', function(assert) {
15927 var actual = lodashStable.map(array, function() {
15931 assert.deepEqual(_.uniq(actual).sort(), [0, 1]);
15934 QUnit.test('should support a `min` and `max` argument', function(assert) {
15940 assert.ok(_.some(array, function() {
15941 var result = _.random(min, max);
15942 return result >= min && result <= max;
15946 QUnit.test('should support not providing a `max` argument', function(assert) {
15952 assert.ok(_.some(array, function() {
15953 var result = _.random(max);
15954 return result >= min && result <= max;
15958 QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
15963 expected = [2, 3, 4];
15965 var actual = lodashStable.uniq(lodashStable.map(array, function() {
15966 return _.random(min, max);
15969 assert.deepEqual(actual, expected);
15972 QUnit.test('should support large integer values', function(assert) {
15975 var min = Math.pow(2, 31),
15976 max = Math.pow(2, 62);
15978 assert.ok(lodashStable.every(array, function() {
15979 var result = _.random(min, max);
15980 return result >= min && result <= max;
15983 assert.ok(_.some(array, function() {
15984 return _.random(MAX_INTEGER) > 0;
15988 QUnit.test('should coerce arguments to finite numbers', function(assert) {
15991 assert.strictEqual(_.random('1', '1'), 1);
15992 assert.strictEqual(_.random(NaN, NaN), 0);
15995 QUnit.test('should support floats', function(assert) {
16000 actual = _.random(min, max);
16002 assert.ok(actual % 1);
16003 assert.ok(actual >= min && actual <= max);
16006 QUnit.test('should support providing a `floating` argument', function(assert) {
16009 var actual = _.random(true);
16010 assert.ok(actual % 1 && actual >= 0 && actual <= 1);
16012 actual = _.random(2, true);
16013 assert.ok(actual % 1 && actual >= 0 && actual <= 2);
16015 actual = _.random(2, 4, true);
16016 assert.ok(actual % 1 && actual >= 2 && actual <= 4);
16019 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
16022 var array = [1, 2, 3],
16023 expected = lodashStable.map(array, alwaysTrue),
16024 randoms = lodashStable.map(array, _.random);
16026 var actual = lodashStable.map(randoms, function(result, index) {
16027 return result >= 0 && result <= array[index] && (result % 1) == 0;
16030 assert.deepEqual(actual, expected);
16034 /*--------------------------------------------------------------------------*/
16036 QUnit.module('range methods');
16038 lodashStable.each(['range', 'rangeRight'], function(methodName) {
16039 var func = _[methodName],
16040 isRange = methodName == 'range';
16042 function resolve(range) {
16043 return isRange ? range : range.reverse();
16046 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when provided only an `end` argument', function(assert) {
16049 assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
16050 assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
16053 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when provided only a `start` and `end` argument', function(assert) {
16056 assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
16057 assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
16060 QUnit.test('`_.' + methodName + '` should work with `start`, `end`, and `step` arguments', function(assert) {
16063 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
16064 assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
16065 assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
16068 QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
16071 assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
16074 QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
16077 assert.deepEqual(func(1, 5, 20), [1]);
16080 QUnit.test('`_.' + methodName + '` should work with a negative `step` argument', function(assert) {
16083 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
16084 assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
16087 QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
16090 var actual = func(-0, 1);
16091 assert.strictEqual(1 / actual[0], -Infinity);
16094 QUnit.test('`_.' + methodName + '` should treat falsey `start` arguments as `0`', function(assert) {
16097 lodashStable.each(falsey, function(value, index) {
16099 assert.deepEqual(func(value), []);
16100 assert.deepEqual(func(value, 1), [0]);
16102 assert.deepEqual(func(), []);
16107 QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
16110 var actual = [func('0', 1), func('1'), func(0, 1, '1'), func(NaN), func(NaN, NaN)];
16111 assert.deepEqual(actual, [[0], [0], [0], [], []]);
16114 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
16117 var array = [1, 2, 3],
16118 object = { 'a': 1, 'b': 2, 'c': 3 },
16119 expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
16121 lodashStable.each([array, object], function(collection) {
16122 var actual = lodashStable.map(collection, func);
16123 assert.deepEqual(actual, expected);
16128 /*--------------------------------------------------------------------------*/
16130 QUnit.module('lodash.rearg');
16134 return slice.call(arguments);
16137 QUnit.test('should reorder arguments provided to `func`', function(assert) {
16140 var rearged = _.rearg(fn, [2, 0, 1]);
16141 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
16144 QUnit.test('should work with repeated indexes', function(assert) {
16147 var rearged = _.rearg(fn, [1, 1, 1]);
16148 assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
16151 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
16154 var rearged = _.rearg(fn, [1, 4]);
16155 assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
16158 QUnit.test('should use `undefined` for non-index values', function(assert) {
16161 var values = lodashStable.reject(empties, function(value) {
16162 return (value === 0) || lodashStable.isArray(value);
16163 }).concat(-1, 1.1);
16165 var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
16167 var actual = lodashStable.map(values, function(value) {
16168 var rearged = _.rearg(fn, [value]);
16169 return rearged('a', 'b', 'c');
16172 assert.deepEqual(actual, expected);
16175 QUnit.test('should not rearrange arguments when no indexes are provided', function(assert) {
16178 var rearged = _.rearg(fn);
16179 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
16181 rearged = _.rearg(fn, [], []);
16182 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
16185 QUnit.test('should accept multiple index arguments', function(assert) {
16188 var rearged = _.rearg(fn, 2, 0, 1);
16189 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
16192 QUnit.test('should accept multiple arrays of indexes', function(assert) {
16195 var rearged = _.rearg(fn, [2], [0, 1]);
16196 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
16199 QUnit.test('should work with fewer indexes than arguments', function(assert) {
16202 var rearged = _.rearg(fn, [1, 0]);
16203 assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
16206 QUnit.test('should work on functions that have been rearged', function(assert) {
16209 var rearged1 = _.rearg(fn, 2, 1, 0),
16210 rearged2 = _.rearg(rearged1, 1, 0, 2);
16212 assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
16216 /*--------------------------------------------------------------------------*/
16218 QUnit.module('lodash.reduce');
16221 var array = [1, 2, 3];
16223 QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
16226 assert.strictEqual(_.reduce(array), 1);
16229 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
16234 _.reduce(array, function() {
16235 args || (args = slice.call(arguments));
16238 assert.deepEqual(args, [0, 1, 0, array]);
16241 _.reduce(array, function() {
16242 args || (args = slice.call(arguments));
16245 assert.deepEqual(args, [1, 2, 1, array]);
16248 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
16252 object = { 'a': 1, 'b': 2 },
16253 firstKey = _.head(_.keys(object));
16255 var expected = firstKey == 'a'
16256 ? [0, 1, 'a', object]
16257 : [0, 2, 'b', object];
16259 _.reduce(object, function() {
16260 args || (args = slice.call(arguments));
16263 assert.deepEqual(args, expected);
16266 expected = firstKey == 'a'
16267 ? [1, 2, 'b', object]
16268 : [2, 1, 'a', object];
16270 _.reduce(object, function() {
16271 args || (args = slice.call(arguments));
16274 assert.deepEqual(args, expected);
16278 /*--------------------------------------------------------------------------*/
16280 QUnit.module('lodash.reduceRight');
16283 var array = [1, 2, 3];
16285 QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
16288 assert.strictEqual(_.reduceRight(array), 3);
16291 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
16296 _.reduceRight(array, function() {
16297 args || (args = slice.call(arguments));
16300 assert.deepEqual(args, [0, 3, 2, array]);
16303 _.reduceRight(array, function() {
16304 args || (args = slice.call(arguments));
16307 assert.deepEqual(args, [3, 2, 1, array]);
16310 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
16314 object = { 'a': 1, 'b': 2 },
16315 isFIFO = lodashStable.keys(object)[0] == 'a';
16317 var expected = isFIFO
16318 ? [0, 2, 'b', object]
16319 : [0, 1, 'a', object];
16321 _.reduceRight(object, function() {
16322 args || (args = slice.call(arguments));
16325 assert.deepEqual(args, expected);
16329 ? [2, 1, 'a', object]
16330 : [1, 2, 'b', object];
16332 _.reduceRight(object, function() {
16333 args || (args = slice.call(arguments));
16336 assert.deepEqual(args, expected);
16340 /*--------------------------------------------------------------------------*/
16342 QUnit.module('reduce methods');
16344 lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
16345 var func = _[methodName],
16347 isReduce = methodName == 'reduce';
16349 QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
16352 var actual = func(['a', 'b', 'c'], function(accumulator, value) {
16353 return accumulator + value;
16356 assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
16359 QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
16363 expected = lodashStable.map(empties, alwaysUndefined);
16365 lodashStable.each(empties, function(value) {
16367 actual.push(func(value, noop));
16371 assert.deepEqual(actual, expected);
16374 QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
16377 var expected = lodashStable.map(empties, lodashStable.constant('x'));
16379 var actual = lodashStable.map(empties, function(value) {
16381 return func(value, noop, 'x');
16385 assert.deepEqual(actual, expected);
16388 QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
16391 var actual = func([], noop, undefined);
16392 assert.strictEqual(actual, undefined);
16395 QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is provided (test in IE > 9 and modern browsers)', function(assert) {
16399 object = { '0': 1, 'length': 0 };
16401 if ('__proto__' in array) {
16402 array.__proto__ = object;
16403 assert.strictEqual(func(array, noop), undefined);
16408 assert.strictEqual(func(object, noop), undefined);
16411 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
16415 assert.strictEqual(_(array)[methodName](add), 6);
16422 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
16426 assert.ok(_(array).chain()[methodName](add) instanceof _);
16434 /*--------------------------------------------------------------------------*/
16436 QUnit.module('lodash.reject');
16439 var array = [1, 2, 3];
16441 QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
16444 assert.deepEqual(_.reject(array, isEven), [1, 3]);
16448 /*--------------------------------------------------------------------------*/
16450 QUnit.module('filter methods');
16452 lodashStable.each(['filter', 'reject'], function(methodName) {
16453 var array = [1, 2, 3, 4],
16454 func = _[methodName],
16455 isFilter = methodName == 'filter',
16456 objects = [{ 'a': 0 }, { 'a': 1 }];
16458 QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
16461 var actual = func([0], function(num, index, array) {
16466 assert.deepEqual(actual, [0]);
16469 QUnit.test('`_.' + methodName + '` should work with a "_.property" style `predicate`', function(assert) {
16472 assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
16475 QUnit.test('`_.' + methodName + '` should work with a "_.matches" style `predicate`', function(assert) {
16478 assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
16481 QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
16485 var wrapped = _(array);
16487 var actual = wrapped[methodName](function(num) {
16491 assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
16493 actual = wrapped[methodName](function(num) {
16497 assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
16500 skipTest(assert, 2);
16504 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
16508 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
16509 predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); },
16510 actual = _(array).slice(1).map(square)[methodName](predicate).value();
16512 assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
16514 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
16515 return ['key' + index, index];
16518 actual = _(object).mapValues(square)[methodName](predicate).value();
16519 assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
16522 skipTest(assert, 2);
16526 QUnit.test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
16531 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
16532 expected = [1, 0, lodashStable.map(array.slice(1), square)];
16534 _(array).slice(1)[methodName](function(value, index, array) {
16535 args || (args = slice.call(arguments));
16538 assert.deepEqual(args, [1, 0, array.slice(1)]);
16541 _(array).slice(1).map(square)[methodName](function(value, index, array) {
16542 args || (args = slice.call(arguments));
16545 assert.deepEqual(args, expected);
16548 _(array).slice(1).map(square)[methodName](function(value, index) {
16549 args || (args = slice.call(arguments));
16552 assert.deepEqual(args, expected);
16555 _(array).slice(1).map(square)[methodName](function(value) {
16556 args || (args = slice.call(arguments));
16559 assert.deepEqual(args, [1]);
16562 _(array).slice(1).map(square)[methodName](function() {
16563 args || (args = slice.call(arguments));
16566 assert.deepEqual(args, expected);
16569 skipTest(assert, 5);
16574 /*--------------------------------------------------------------------------*/
16576 QUnit.module('lodash.remove');
16579 QUnit.test('should modify the array and return removed elements', function(assert) {
16582 var array = [1, 2, 3];
16584 var actual = _.remove(array, function(num) {
16588 assert.deepEqual(array, [3]);
16589 assert.deepEqual(actual, [1, 2]);
16592 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
16597 clone = array.slice();
16599 _.remove(array, function(value, index) {
16600 var args = slice.call(arguments);
16601 args[2] = args[2].slice();
16602 argsList.push(args);
16603 return isEven(index);
16606 assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
16609 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
16612 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
16613 _.remove(objects, { 'a': 1 });
16614 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
16617 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
16620 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
16621 _.remove(objects, ['a', 1]);
16622 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
16625 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
16628 var objects = [{ 'a': 0 }, { 'a': 1 }];
16629 _.remove(objects, 'a');
16630 assert.deepEqual(objects, [{ 'a': 0 }]);
16633 QUnit.test('should preserve holes in arrays', function(assert) {
16636 var array = [1, 2, 3, 4];
16640 _.remove(array, function(num) { return num === 1; });
16641 assert.notOk('0' in array);
16642 assert.notOk('2' in array);
16645 QUnit.test('should treat holes as `undefined`', function(assert) {
16648 var array = [1, 2, 3];
16651 _.remove(array, function(num) { return num == null; });
16652 assert.deepEqual(array, [1, 3]);
16655 QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
16658 var array = [1, 2, 3];
16659 _.remove(array, function(num, index) { return isEven(index); });
16660 assert.deepEqual(array, [2]);
16664 /*--------------------------------------------------------------------------*/
16666 QUnit.module('lodash.repeat');
16669 QUnit.test('should repeat a string `n` times', function(assert) {
16672 assert.strictEqual(_.repeat('*', 3), '***');
16673 assert.strictEqual(_.repeat('abc', 2), 'abcabc');
16676 QUnit.test('should return an empty string for negative `n` or `n` of `0`', function(assert) {
16679 assert.strictEqual(_.repeat('abc', 0), '');
16680 assert.strictEqual(_.repeat('abc', -2), '');
16683 QUnit.test('should coerce `n` to an integer', function(assert) {
16686 assert.strictEqual(_.repeat('abc'), '');
16687 assert.strictEqual(_.repeat('abc', '2'), 'abcabc');
16688 assert.strictEqual(_.repeat('abc', 2.6), 'abcabc');
16689 assert.strictEqual(_.repeat('*', { 'valueOf': alwaysThree }), '***');
16692 QUnit.test('should coerce `string` to a string', function(assert) {
16695 assert.strictEqual(_.repeat(Object('abc'), 2), 'abcabc');
16696 assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
16700 /*--------------------------------------------------------------------------*/
16702 QUnit.module('lodash.replace');
16705 QUnit.test('should replace the matched pattern', function(assert) {
16708 var string = 'abcdef';
16709 assert.strictEqual(_.replace(string, 'def', '123'), 'abc123');
16710 assert.strictEqual(_.replace(string, /[bdf]/g, '-'), 'a-c-e-');
16714 /*--------------------------------------------------------------------------*/
16716 QUnit.module('lodash.result');
16721 'b': function() { return this.a; }
16724 QUnit.test('should invoke function values', function(assert) {
16727 assert.strictEqual(_.result(object, 'b'), 1);
16730 QUnit.test('should invoke default function values', function(assert) {
16733 var actual = _.result(object, 'c', object.b);
16734 assert.strictEqual(actual, 1);
16737 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
16740 var value = { 'a': object };
16742 lodashStable.each(['a.b', ['a', 'b']], function(path) {
16743 assert.strictEqual(_.result(value, path), 1);
16748 /*--------------------------------------------------------------------------*/
16750 QUnit.module('lodash.get and lodash.result');
16752 lodashStable.each(['get', 'result'], function(methodName) {
16753 var func = _[methodName];
16755 QUnit.test('`_.' + methodName + '` should get property values', function(assert) {
16758 var object = { 'a': 1 };
16760 lodashStable.each(['a', ['a']], function(path) {
16761 assert.strictEqual(func(object, path), 1);
16765 QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
16768 var object = { 'a': { 'b': { 'c': 3 } } };
16770 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
16771 assert.strictEqual(func(object, path), 3);
16775 QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
16778 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
16780 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
16781 assert.strictEqual(func(object, path), 3);
16785 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
16788 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
16789 assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
16792 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
16795 var object = { 'a': 1 };
16796 assert.strictEqual(func(object, 'a[]'), 1);
16799 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
16802 lodashStable.each([['', ''], [[], ['']]], function(pair) {
16803 assert.strictEqual(func({}, pair[0]), undefined);
16804 assert.strictEqual(func({ '': 3 }, pair[1]), 3);
16808 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
16811 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
16814 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
16815 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
16818 lodashStable.each(paths, function(path) {
16819 assert.strictEqual(func(object, path), 8);
16823 QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
16826 lodashStable.each(['constructor', ['constructor']], function(path) {
16827 assert.strictEqual(func(null, path), undefined);
16828 assert.strictEqual(func(undefined, path), undefined);
16832 QUnit.test('`_.' + methodName + '` should return `undefined` with deep paths when `object` is nullish', function(assert) {
16835 var values = [null, undefined],
16836 expected = lodashStable.map(values, alwaysUndefined),
16837 paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
16839 lodashStable.each(paths, function(path) {
16840 var actual = lodashStable.map(values, function(value) {
16841 return func(value, path);
16844 assert.deepEqual(actual, expected);
16848 QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
16851 var object = { 'a': [, null] };
16853 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
16854 assert.strictEqual(func(object, path), undefined);
16858 QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
16861 var object = { 'a': { 'b': null } };
16863 lodashStable.each(['a.b', ['a', 'b']], function(path) {
16864 assert.strictEqual(func(object, path), null);
16868 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
16871 var object = { 'a': '' },
16872 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
16874 lodashStable.each(paths, function(path) {
16877 var actual = func(0, path);
16878 assert.strictEqual(actual, 1);
16880 delete numberProto.a;
16883 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
16884 stringProto.replace.b = 1;
16886 var actual = func(object, path);
16887 assert.strictEqual(actual, 1);
16889 delete stringProto.replace.b;
16893 QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
16896 var object = { 'a': {} },
16897 values = empties.concat(true, new Date, 1, /x/, 'a');
16899 var expected = lodashStable.transform(values, function(result, value) {
16900 result.push(value, value, value, value);
16903 var actual = lodashStable.transform(values, function(result, value) {
16904 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
16906 func(object, path, value),
16907 func(null, path, value)
16912 assert.deepEqual(actual, expected);
16916 /*--------------------------------------------------------------------------*/
16918 QUnit.module('lodash.rest');
16921 function fn(a, b, c) {
16922 return slice.call(arguments);
16925 QUnit.test('should apply a rest parameter to `func`', function(assert) {
16928 var rp = _.rest(fn);
16929 assert.deepEqual(rp(1, 2, 3, 4), [1, 2, [3, 4]]);
16932 QUnit.test('should work with `start`', function(assert) {
16935 var rp = _.rest(fn, 1);
16936 assert.deepEqual(rp(1, 2, 3, 4), [1, [2, 3, 4]]);
16939 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
16942 var values = [-1, NaN, 'a'],
16943 expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
16945 var actual = lodashStable.map(values, function(value) {
16946 var rp = _.rest(fn, value);
16947 return rp(1, 2, 3, 4);
16950 assert.deepEqual(actual, expected);
16953 QUnit.test('should coerce `start` to an integer', function(assert) {
16956 var rp = _.rest(fn, 1.6);
16957 assert.deepEqual(rp(1, 2, 3), [1, [2, 3]]);
16960 QUnit.test('should use an empty array when `start` is not reached', function(assert) {
16963 var rp = _.rest(fn);
16964 assert.deepEqual(rp(1), [1, undefined, []]);
16967 QUnit.test('should work on functions with more than three parameters', function(assert) {
16970 var rp = _.rest(function(a, b, c, d) {
16971 return slice.call(arguments);
16974 assert.deepEqual(rp(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
16978 /*--------------------------------------------------------------------------*/
16980 QUnit.module('lodash.reverse');
16983 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
16984 smallArray = [0, 1, 2, null];
16986 QUnit.test('should reverse `array`', function(assert) {
16989 var array = [1, 2, 3],
16990 actual = _.reverse(array);
16992 assert.deepEqual(array, [3, 2, 1]);
16993 assert.strictEqual(actual, array);
16996 QUnit.test('should return the wrapped reversed `array`', function(assert) {
17000 lodashStable.times(2, function(index) {
17001 var array = (index ? largeArray : smallArray).slice(),
17002 clone = array.slice(),
17003 wrapped = _(array).reverse(),
17004 actual = wrapped.value();
17006 assert.ok(wrapped instanceof _);
17007 assert.strictEqual(actual, array);
17008 assert.deepEqual(actual, clone.slice().reverse());
17012 skipTest(assert, 6);
17016 QUnit.test('should work in a lazy sequence', function(assert) {
17020 lodashStable.times(2, function(index) {
17021 var array = (index ? largeArray : smallArray).slice(),
17022 expected = array.slice(),
17023 actual = _(array).slice(1).reverse().value();
17025 assert.deepEqual(actual, expected.slice(1).reverse());
17026 assert.deepEqual(array, expected);
17030 skipTest(assert, 4);
17034 QUnit.test('should be lazy when in a lazy sequence', function(assert) {
17039 'toString': function() {
17040 throw new Error('spy was revealed');
17044 var array = largeArray.concat(spy),
17045 expected = array.slice();
17048 var wrapped = _(array).slice(1).map(String).reverse(),
17049 actual = wrapped.last();
17052 assert.ok(wrapped instanceof _);
17053 assert.strictEqual(actual, '1');
17054 assert.deepEqual(array, expected);
17057 skipTest(assert, 3);
17061 QUnit.test('should work in a hybrid sequence', function(assert) {
17065 lodashStable.times(2, function(index) {
17066 var clone = (index ? largeArray : smallArray).slice();
17068 lodashStable.each(['map', 'filter'], function(methodName) {
17069 var array = clone.slice(),
17070 expected = clone.slice(1, -1).reverse(),
17071 actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
17073 assert.deepEqual(actual, expected);
17075 array = clone.slice();
17076 actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
17078 assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
17083 skipTest(assert, 8);
17087 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
17091 lodashStable.times(2, function(index) {
17092 var array = (index ? largeArray : smallArray).slice(),
17093 expected = array.slice().reverse(),
17094 wrapped = _(array).chain().reverse().head();
17096 assert.ok(wrapped instanceof _);
17097 assert.strictEqual(wrapped.value(), _.head(expected));
17098 assert.deepEqual(array, expected);
17102 skipTest(assert, 6);
17107 /*--------------------------------------------------------------------------*/
17109 QUnit.module('round methods');
17111 lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
17112 var func = _[methodName],
17113 isCeil = methodName == 'ceil',
17114 isFloor = methodName == 'floor';
17116 QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
17119 var actual = func(4.006);
17120 assert.strictEqual(actual, isCeil ? 5 : 4);
17123 QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
17126 var actual = func(4.006, 0);
17127 assert.strictEqual(actual, isCeil ? 5 : 4);
17130 QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
17133 var actual = func(4.016, 2);
17134 assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
17136 actual = func(4.1, 2);
17137 assert.strictEqual(actual, 4.1);
17140 QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
17143 var actual = func(4160, -2);
17144 assert.strictEqual(actual, isFloor ? 4100 : 4200);
17147 QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
17150 var actual = func(4.006, NaN);
17151 assert.strictEqual(actual, isCeil ? 5 : 4);
17153 var expected = isFloor ? 4.01 : 4.02;
17155 actual = func(4.016, 2.6);
17156 assert.strictEqual(actual, expected);
17158 actual = func(4.016, '+2');
17159 assert.strictEqual(actual, expected);
17162 QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
17165 var actual = func(5e1, 2);
17166 assert.deepEqual(actual, 50);
17168 actual = func('5e', 1);
17169 assert.deepEqual(actual, NaN);
17171 actual = func('5e1e1', 1);
17172 assert.deepEqual(actual, NaN);
17175 QUnit.test('`_.' + methodName + '` should preserve sign of `0`', function(assert) {
17178 var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
17179 expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
17181 var actual = lodashStable.map(values, function(args) {
17182 return 1 / func.apply(undefined, args);
17185 assert.deepEqual(actual, expected);
17189 /*--------------------------------------------------------------------------*/
17191 QUnit.module('lodash.runInContext');
17194 QUnit.test('should not require a fully populated `context` object', function(assert) {
17197 if (!isModularize) {
17198 var lodash = _.runInContext({
17199 'setTimeout': function(callback) {
17205 lodash.delay(function() { pass = true; }, 32);
17213 QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
17216 if (!isModularize) {
17217 lodashStable.times(2, _.uniqueId);
17219 var oldId = Number(_.uniqueId()),
17220 lodash = _.runInContext();
17222 assert.ok(_.uniqueId() > oldId);
17224 var id = lodash.uniqueId();
17225 assert.strictEqual(id, '1');
17226 assert.ok(id < oldId);
17229 skipTest(assert, 3);
17234 /*--------------------------------------------------------------------------*/
17236 QUnit.module('lodash.sample');
17239 var array = [1, 2, 3];
17241 QUnit.test('should return a random element', function(assert) {
17244 var actual = _.sample(array);
17245 assert.ok(lodashStable.includes(array, actual));
17248 QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
17251 var expected = lodashStable.map(empties, alwaysUndefined);
17253 var actual = lodashStable.transform(empties, function(result, value) {
17255 result.push(_.sample(value));
17259 assert.deepEqual(actual, expected);
17262 QUnit.test('should sample an object', function(assert) {
17265 var object = { 'a': 1, 'b': 2, 'c': 3 },
17266 actual = _.sample(object);
17268 assert.ok(lodashStable.includes(array, actual));
17272 /*--------------------------------------------------------------------------*/
17274 QUnit.module('lodash.sampleSize');
17277 var array = [1, 2, 3];
17279 QUnit.test('should return an array of random elements', function(assert) {
17282 var actual = _.sampleSize(array, 2);
17283 assert.strictEqual(actual.length, 2);
17284 assert.deepEqual(lodashStable.difference(actual, array), []);
17287 QUnit.test('should contain elements of the collection', function(assert) {
17290 var actual = _.sampleSize(array, array.length);
17291 assert.deepEqual(actual.sort(), array);
17294 QUnit.test('should treat falsey `n` values as `0`', function(assert) {
17297 var expected = lodashStable.map(falsey, alwaysEmptyArray);
17299 var actual = lodashStable.map(falsey, function(n, index) {
17300 return index ? _.sampleSize([1], n) : _.sampleSize([1]);
17303 assert.deepEqual(actual, expected);
17306 QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
17309 lodashStable.each([0, -1, -Infinity], function(n) {
17310 assert.deepEqual(_.sampleSize(array, n), []);
17314 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
17317 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
17318 assert.deepEqual(_.sampleSize(array, n).sort(), array);
17322 QUnit.test('should coerce `n` to an integer', function(assert) {
17325 var actual = _.sampleSize(array, 1.6);
17326 assert.strictEqual(actual.length, 1);
17329 QUnit.test('should return an empty array for empty collections', function(assert) {
17332 var expected = lodashStable.map(empties, alwaysEmptyArray);
17334 var actual = lodashStable.transform(empties, function(result, value) {
17336 result.push(_.sampleSize(value, 1));
17340 assert.deepEqual(actual, expected);
17343 QUnit.test('should sample an object', function(assert) {
17346 var object = { 'a': 1, 'b': 2, 'c': 3 },
17347 actual = _.sampleSize(object, 2);
17349 assert.strictEqual(actual.length, 2);
17350 assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
17354 /*--------------------------------------------------------------------------*/
17356 QUnit.module('lodash.setWith');
17359 QUnit.test('should work with a `customizer` callback', function(assert) {
17362 var actual = _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, function(value) {
17363 if (!lodashStable.isObject(value)) {
17368 assert.deepEqual(actual, { '0': { '1': { '2': 3 }, 'length': 2 } });
17371 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
17374 var actual = _.setWith({}, 'a[0].b.c', 4, alwaysUndefined);
17375 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
17379 /*--------------------------------------------------------------------------*/
17381 QUnit.module('set methods');
17383 lodashStable.each(['set', 'setWith'], function(methodName) {
17384 var func = _[methodName];
17386 QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
17389 var object = { 'a': 1 };
17391 lodashStable.each(['a', ['a']], function(path) {
17392 var actual = func(object, path, 2);
17394 assert.strictEqual(actual, object);
17395 assert.strictEqual(object.a, 2);
17401 QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
17404 var object = { 'a': { 'b': { 'c': 3 } } };
17406 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
17407 var actual = func(object, path, 4);
17409 assert.strictEqual(actual, object);
17410 assert.strictEqual(object.a.b.c, 4);
17416 QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
17419 var object = { 'a.b.c': 3 };
17421 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
17422 var actual = func(object, path, 4);
17424 assert.strictEqual(actual, object);
17425 assert.deepEqual(object, { 'a.b.c': 4 });
17427 object['a.b.c'] = 3;
17431 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
17434 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 3 } } };
17435 func(object, ['a', 'b', 'c'], 4);
17436 assert.strictEqual(object.a.b.c, 4);
17439 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
17443 func(object, 'a[]', 1);
17444 assert.deepEqual(object, { 'a': 1 });
17447 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
17450 lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
17453 func(object, pair[0], 1);
17454 assert.deepEqual(object, index ? {} : { '': 1 });
17456 func(object, pair[1], 2);
17457 assert.deepEqual(object, { '': 2 });
17461 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
17464 var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
17467 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
17468 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
17471 lodashStable.each(paths, function(path) {
17472 func(object, path, 10);
17473 assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, 10);
17474 object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = 8;
17478 QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
17483 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
17484 var actual = func(object, path, 4);
17486 assert.strictEqual(actual, object);
17487 assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': 4 } }] });
17488 assert.notOk('0' in object.a);
17494 QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
17497 var values = [null, undefined],
17498 expected = [[null, null], [undefined, undefined]];
17500 var actual = lodashStable.map(values, function(value) {
17502 return [func(value, 'a.b', 1), func(value, ['a', 'b'], 1)];
17508 assert.deepEqual(actual, expected);
17511 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
17514 var object = { 'a': '' },
17515 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
17517 lodashStable.each(paths, function(path) {
17519 assert.strictEqual(0..a, 1);
17520 delete numberProto.a;
17523 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
17524 func(object, path, 1);
17525 assert.strictEqual(stringProto.replace.b, 1);
17526 delete stringProto.replace.b;
17530 QUnit.test('`_.' + methodName + '` should not error on paths over primitives in strict mode', function(assert) {
17537 lodashStable.each(['a', 'a.a.a'], function(path) {
17540 assert.strictEqual(0..a, 0);
17542 assert.ok(false, e.message);
17547 delete numberProto.a;
17550 QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
17555 func(object, ['1a', '2b', '3c'], 1);
17556 assert.deepEqual(object, { '1a': { '2b': { '3c': 1 } } });
17559 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
17562 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
17563 if (defineProperty) {
17567 defineProperty(object, 'a', {
17568 'enumerable': true,
17569 'configurable': true,
17570 'get': lodashStable.constant(value),
17571 'set': function() { pass = false; }
17574 func(object, 'a', value);
17584 /*--------------------------------------------------------------------------*/
17586 QUnit.module('lodash.shuffle');
17589 var array = [1, 2, 3],
17590 object = { 'a': 1, 'b': 2, 'c': 3 };
17592 QUnit.test('should return a new array', function(assert) {
17595 assert.notStrictEqual(_.shuffle(array), array);
17598 QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
17601 assert.deepEqual(_.shuffle(array).sort(), array);
17602 assert.deepEqual(_.shuffle(object).sort(), array);
17605 QUnit.test('should shuffle small collections', function(assert) {
17608 var uniqBy = lodashStable.uniqBy || lodashStable.uniq;
17610 var actual = lodashStable.times(1000, function(assert) {
17611 return _.shuffle([1, 2]);
17614 assert.deepEqual(lodashStable.sortBy(uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
17617 QUnit.test('should treat number values for `collection` as empty', function(assert) {
17620 assert.deepEqual(_.shuffle(1), []);
17624 /*--------------------------------------------------------------------------*/
17626 QUnit.module('lodash.size');
17629 var args = arguments,
17632 QUnit.test('should return the number of own enumerable properties of an object', function(assert) {
17635 assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
17638 QUnit.test('should return the length of an array', function(assert) {
17641 assert.strictEqual(_.size(array), 3);
17644 QUnit.test('should accept a falsey `object` argument', function(assert) {
17647 var expected = lodashStable.map(falsey, alwaysZero);
17649 var actual = lodashStable.map(falsey, function(object, index) {
17651 return index ? _.size(object) : _.size();
17655 assert.deepEqual(actual, expected);
17658 QUnit.test('should work with `arguments` objects', function(assert) {
17661 assert.strictEqual(_.size(args), 3);
17664 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
17667 function Foo(elements) { push.apply(this, elements); }
17668 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
17670 assert.strictEqual(_.size(new Foo(array)), 3);
17673 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
17676 assert.strictEqual(_.size({ 'length': -1 }), 1);
17679 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
17682 assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
17685 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
17688 assert.strictEqual(_.size({ 'length': '0' }), 1);
17692 /*--------------------------------------------------------------------------*/
17694 QUnit.module('lodash.slice');
17697 var array = [1, 2, 3];
17699 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
17702 var actual = _.slice(array);
17703 assert.deepEqual(actual, array);
17704 assert.notStrictEqual(actual, array);
17707 QUnit.test('should work with a positive `start`', function(assert) {
17710 assert.deepEqual(_.slice(array, 1), [2, 3]);
17711 assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
17714 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
17717 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
17718 assert.deepEqual(_.slice(array, start), []);
17722 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
17725 var expected = lodashStable.map(falsey, lodashStable.constant(array));
17727 var actual = lodashStable.map(falsey, function(start) {
17728 return _.slice(array, start);
17731 assert.deepEqual(actual, expected);
17734 QUnit.test('should work with a negative `start`', function(assert) {
17737 assert.deepEqual(_.slice(array, -1), [3]);
17740 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
17743 lodashStable.each([-3, -4, -Infinity], function(start) {
17744 assert.deepEqual(_.slice(array, start), array);
17748 QUnit.test('should work with `start` >= `end`', function(assert) {
17751 lodashStable.each([2, 3], function(start) {
17752 assert.deepEqual(_.slice(array, start, 2), []);
17756 QUnit.test('should work with a positive `end`', function(assert) {
17759 assert.deepEqual(_.slice(array, 0, 1), [1]);
17762 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
17765 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
17766 assert.deepEqual(_.slice(array, 0, end), array);
17770 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
17773 var expected = lodashStable.map(falsey, function(value) {
17774 return value === undefined ? array : [];
17777 var actual = lodashStable.map(falsey, function(end) {
17778 return _.slice(array, 0, end);
17781 assert.deepEqual(actual, expected);
17784 QUnit.test('should work with a negative `end`', function(assert) {
17787 assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
17790 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
17793 lodashStable.each([-3, -4, -Infinity], function(end) {
17794 assert.deepEqual(_.slice(array, 0, end), []);
17798 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
17801 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
17803 var actual = lodashStable.map(positions, function(pos) {
17804 return _.slice.apply(_, [array].concat(pos));
17807 assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
17810 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
17813 var array = [[1], [2, 3]],
17814 actual = lodashStable.map(array, _.slice);
17816 assert.deepEqual(actual, array);
17817 assert.notStrictEqual(actual, array);
17820 QUnit.test('should work in a lazy sequence', function(assert) {
17824 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
17825 length = array.length,
17826 wrapped = _(array);
17828 lodashStable.each(['map', 'filter'], function(methodName) {
17829 assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
17830 assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
17831 assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
17832 assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
17834 assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
17835 assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
17836 assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
17837 assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
17839 assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
17840 assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
17841 assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
17843 assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
17844 assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
17846 assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
17847 assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
17848 assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
17849 assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
17850 assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
17851 assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
17855 skipTest(assert, 38);
17860 /*--------------------------------------------------------------------------*/
17862 QUnit.module('lodash.some');
17865 QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
17868 assert.strictEqual(_.some([false, 1, ''], identity), true);
17869 assert.strictEqual(_.some([null, 'a', 0], identity), true);
17872 QUnit.test('should return `false` for empty collections', function(assert) {
17875 var expected = lodashStable.map(empties, alwaysFalse);
17877 var actual = lodashStable.map(empties, function(value) {
17879 return _.some(value, identity);
17883 assert.deepEqual(actual, expected);
17886 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
17891 assert.strictEqual(_.some([null, true, null], function(value) {
17896 assert.strictEqual(count, 2);
17899 QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
17902 assert.strictEqual(_.some([false, false, false], identity), false);
17903 assert.strictEqual(_.some([null, 0, ''], identity), false);
17906 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
17909 var values = [, null, undefined],
17910 expected = lodashStable.map(values, alwaysFalse);
17912 var actual = lodashStable.map(values, function(value, index) {
17913 var array = [0, 0];
17914 return index ? _.some(array, value) : _.some(array);
17917 assert.deepEqual(actual, expected);
17919 expected = lodashStable.map(values, alwaysTrue);
17920 actual = lodashStable.map(values, function(value, index) {
17921 var array = [0, 1];
17922 return index ? _.some(array, value) : _.some(array);
17925 assert.deepEqual(actual, expected);
17928 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
17931 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
17932 assert.strictEqual(_.some(objects, 'a'), false);
17933 assert.strictEqual(_.some(objects, 'b'), true);
17936 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
17939 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
17940 assert.strictEqual(_.some(objects, { 'a': 0 }), true);
17941 assert.strictEqual(_.some(objects, { 'b': 2 }), false);
17944 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
17947 var actual = lodashStable.map([[1]], _.some);
17948 assert.deepEqual(actual, [true]);
17952 /*--------------------------------------------------------------------------*/
17954 QUnit.module('lodash.sortBy');
17958 { 'a': 'x', 'b': 3 },
17959 { 'a': 'y', 'b': 4 },
17960 { 'a': 'x', 'b': 1 },
17961 { 'a': 'y', 'b': 2 }
17964 QUnit.test('should sort in ascending order', function(assert) {
17967 var actual = lodashStable.map(_.sortBy(objects, function(object) {
17971 assert.deepEqual(actual, [1, 2, 3, 4]);
17974 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
17977 var array = [3, 2, 1],
17978 values = [, null, undefined],
17979 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
17981 var actual = lodashStable.map(values, function(value, index) {
17982 return index ? _.sortBy(array, value) : _.sortBy(array);
17985 assert.deepEqual(actual, expected);
17988 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
17991 var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
17992 assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
17995 QUnit.test('should work with an object for `collection`', function(assert) {
17998 var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, function(num) {
17999 return Math.sin(num);
18002 assert.deepEqual(actual, [3, 1, 2]);
18005 QUnit.test('should move `null`, `undefined`, and `NaN` values to the end', function(assert) {
18008 var array = [NaN, undefined, null, 4, null, 1, undefined, 3, NaN, 2];
18009 assert.deepEqual(_.sortBy(array), [1, 2, 3, 4, null, null, undefined, undefined, NaN, NaN]);
18011 array = [NaN, undefined, null, 'd', null, 'a', undefined, 'c', NaN, 'b'];
18012 assert.deepEqual(_.sortBy(array), ['a', 'b', 'c', 'd', null, null, undefined, undefined, NaN, NaN]);
18015 QUnit.test('should treat number values for `collection` as empty', function(assert) {
18018 assert.deepEqual(_.sortBy(1), []);
18021 QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
18024 var actual = _.sortBy(objects, function(object) {
18025 var result = [object.a, object.b];
18026 result.toString = function() { return String(this[0]); };
18030 assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
18033 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18036 var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
18037 assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
18041 /*--------------------------------------------------------------------------*/
18043 QUnit.module('sortBy methods');
18045 lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
18046 var func = _[methodName];
18048 function Pair(a, b, c) {
18055 { 'a': 'x', 'b': 3 },
18056 { 'a': 'y', 'b': 4 },
18057 { 'a': 'x', 'b': 1 },
18058 { 'a': 'y', 'b': 2 }
18061 var stableArray = [
18062 new Pair(1, 1, 1), new Pair(1, 2, 1),
18063 new Pair(1, 1, 1), new Pair(1, 2, 1),
18064 new Pair(1, 3, 1), new Pair(1, 4, 1),
18065 new Pair(1, 5, 1), new Pair(1, 6, 1),
18066 new Pair(2, 1, 2), new Pair(2, 2, 2),
18067 new Pair(2, 3, 2), new Pair(2, 4, 2),
18068 new Pair(2, 5, 2), new Pair(2, 6, 2),
18069 new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
18070 new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
18071 new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
18074 var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
18076 QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
18079 var actual = func(objects, ['a', 'b']);
18080 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
18083 QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
18086 var actual = func(objects, ['a', function(object) { return object.b; }]);
18087 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
18090 QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
18093 lodashStable.each([stableArray, stableObject], function(value, index) {
18094 var actual = func(value, ['a', 'c']);
18095 assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
18099 QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
18103 var actual = func(objects.concat(null, undefined), ['a', 'b']);
18106 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
18109 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
18113 { 'a': 'x', '0': 3 },
18114 { 'a': 'y', '0': 4 },
18115 { 'a': 'x', '0': 1 },
18116 { 'a': 'y', '0': 2 }
18119 var funcs = [func, lodashStable.partialRight(func, 'bogus')];
18121 lodashStable.each(['a', 0, [0]], function(props, index) {
18122 var expected = lodashStable.map(funcs, lodashStable.constant(
18124 ? [objects[2], objects[3], objects[0], objects[1]]
18125 : [objects[0], objects[2], objects[1], objects[3]]
18128 var actual = lodashStable.map(funcs, function(func) {
18129 return lodashStable.reduce([props], func, objects);
18132 assert.deepEqual(actual, expected);
18137 /*--------------------------------------------------------------------------*/
18139 QUnit.module('sortedIndex methods');
18141 lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
18142 var func = _[methodName],
18143 isSortedIndex = methodName == 'sortedIndex';
18145 QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
18148 var array = [30, 50],
18149 values = [30, 40, 50],
18150 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
18152 var actual = lodashStable.map(values, function(value) {
18153 return func(array, value);
18156 assert.deepEqual(actual, expected);
18159 QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
18162 var array = ['a', 'c'],
18163 values = ['a', 'b', 'c'],
18164 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
18166 var actual = lodashStable.map(values, function(value) {
18167 return func(array, value);
18170 assert.deepEqual(actual, expected);
18173 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument and a `value`', function(assert) {
18176 var expected = lodashStable.map(falsey, lodashStable.constant([0, 0, 0]));
18178 var actual = lodashStable.map(falsey, function(array) {
18179 return [func(array, 1), func(array, undefined), func(array, NaN)];
18182 assert.deepEqual(actual, expected);
18185 QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
18188 var expected = [1, '2', {}, null, undefined, NaN, NaN];
18190 lodashStable.each([
18191 [NaN, null, 1, '2', {}, NaN, undefined],
18192 ['2', null, 1, NaN, {}, NaN, undefined]
18193 ], function(array) {
18194 assert.deepEqual(_.sortBy(array), expected);
18195 assert.strictEqual(func(expected, 3), 2);
18196 assert.strictEqual(func(expected, null), isSortedIndex ? 3 : 4);
18197 assert.strictEqual(func(expected, undefined), isSortedIndex ? 4 : 5);
18198 assert.strictEqual(func(expected, NaN), isSortedIndex ? 5 : 7);
18203 /*--------------------------------------------------------------------------*/
18205 QUnit.module('sortedIndexBy methods');
18207 lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
18208 var func = _[methodName],
18209 isSortedIndexBy = methodName == 'sortedIndexBy';
18211 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
18216 func([30, 50], 40, function(assert) {
18217 args || (args = slice.call(arguments));
18220 assert.deepEqual(args, [40]);
18223 QUnit.test('`_.' + methodName + '` should work with a "_.property" style `iteratee`', function(assert) {
18226 var objects = [{ 'x': 30 }, { 'x': 50 }],
18227 actual = func(objects, { 'x': 40 }, 'x');
18229 assert.strictEqual(actual, 1);
18232 QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
18235 lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
18237 values = [MAX_ARRAY_LENGTH, NaN, undefined];
18239 array.length = length;
18241 lodashStable.each(values, function(value) {
18244 var actual = func(array, value, function(value) {
18249 var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
18251 : Math.min(length, MAX_ARRAY_INDEX);
18253 // Avoid false fails in older Firefox.
18254 if (array.length == length) {
18255 assert.ok(steps == 32 || steps == 33);
18256 assert.strictEqual(actual, expected);
18259 skipTest(assert, 2);
18266 /*--------------------------------------------------------------------------*/
18268 QUnit.module('sortedIndexOf methods');
18270 lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
18271 var func = _[methodName],
18272 isSortedIndexOf = methodName == 'sortedIndexOf';
18274 QUnit.test('should perform a binary search', function(assert) {
18277 var sorted = [4, 4, 5, 5, 6, 6];
18278 assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
18282 /*--------------------------------------------------------------------------*/
18284 QUnit.module('lodash.sortedUniq');
18287 QUnit.test('should return unique values of a sorted array', function(assert) {
18290 var expected = [1, 2, 3];
18292 lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
18293 assert.deepEqual(_.sortedUniq(array), expected);
18298 /*--------------------------------------------------------------------------*/
18300 QUnit.module('lodash.split');
18303 QUnit.test('should support string split', function(assert) {
18306 var string = 'abcde';
18307 assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
18308 assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
18309 assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
18312 QUnit.test('should allow mixed string and array prototype methods', function(assert) {
18316 var wrapped = _('abc');
18317 assert.strictEqual(wrapped.split('b').join(','), 'a,c');
18325 /*--------------------------------------------------------------------------*/
18327 QUnit.module('lodash.spread');
18330 QUnit.test('should spread arguments to `func`', function(assert) {
18333 var spread = _.spread(add);
18334 assert.strictEqual(spread([4, 2]), 6);
18337 QUnit.test('should accept a falsey `array` argument', function(assert) {
18340 var spread = _.spread(alwaysTrue),
18341 expected = lodashStable.map(falsey, alwaysTrue);
18343 var actual = lodashStable.map(falsey, function(array, index) {
18345 return index ? spread(array) : spread();
18349 assert.deepEqual(actual, expected);
18352 QUnit.test('should provide the correct `func` arguments', function(assert) {
18357 var spread = _.spread(function() {
18358 args = slice.call(arguments);
18361 spread([4, 2], 'ignored');
18362 assert.deepEqual(args, [4, 2]);
18366 /*--------------------------------------------------------------------------*/
18368 QUnit.module('lodash.startsWith');
18371 var string = 'abc';
18373 QUnit.test('should return `true` if a string starts with `target`', function(assert) {
18376 assert.strictEqual(_.startsWith(string, 'a'), true);
18379 QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
18382 assert.strictEqual(_.startsWith(string, 'b'), false);
18385 QUnit.test('should work with a `position` argument', function(assert) {
18388 assert.strictEqual(_.startsWith(string, 'b', 1), true);
18391 QUnit.test('should work with `position` >= `string.length`', function(assert) {
18394 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
18395 assert.strictEqual(_.startsWith(string, 'a', position), false);
18399 QUnit.test('should treat falsey `position` values as `0`', function(assert) {
18402 var expected = lodashStable.map(falsey, alwaysTrue);
18404 var actual = lodashStable.map(falsey, function(position) {
18405 return _.startsWith(string, 'a', position);
18408 assert.deepEqual(actual, expected);
18411 QUnit.test('should treat a negative `position` as `0`', function(assert) {
18414 lodashStable.each([-1, -3, -Infinity], function(position) {
18415 assert.strictEqual(_.startsWith(string, 'a', position), true);
18416 assert.strictEqual(_.startsWith(string, 'b', position), false);
18420 QUnit.test('should coerce `position` to an integer', function(assert) {
18423 assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
18426 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
18429 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
18430 return _.startsWith(string, '', position, true);
18435 /*--------------------------------------------------------------------------*/
18437 QUnit.module('lodash.startsWith and lodash.endsWith');
18439 lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
18440 var func = _[methodName],
18441 isStartsWith = methodName == 'startsWith';
18443 var string = 'abc',
18444 chr = isStartsWith ? 'a' : 'c';
18446 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
18449 assert.strictEqual(func(Object(string), chr), true);
18450 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
18453 QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
18456 assert.strictEqual(func(string, Object(chr)), true);
18457 assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
18460 QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
18463 var position = isStartsWith ? 1 : 2;
18464 assert.strictEqual(func(string, 'b', Object(position)), true);
18465 assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
18469 /*--------------------------------------------------------------------------*/
18471 QUnit.module('lodash.subtract');
18474 QUnit.test('should subtract two numbers', function(assert) {
18477 assert.strictEqual(_.subtract(6, 4), 2);
18478 assert.strictEqual(_.subtract(-6, 4), -10);
18479 assert.strictEqual(_.subtract(-6, -4), -2);
18482 QUnit.test('should coerce arguments only numbers', function(assert) {
18485 assert.strictEqual(_.subtract('6', '4'), 2);
18486 assert.deepEqual(_.subtract('x', 'y'), NaN);
18489 QUnit.test('should work with only a `minuend` or `subtrahend`', function(assert) {
18492 assert.strictEqual(_.subtract(6), 6);
18493 assert.strictEqual(_.subtract(6, undefined), 6);
18494 assert.strictEqual(_.subtract(undefined, 4), 4);
18497 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
18501 assert.strictEqual(_(1).subtract(2), -1);
18508 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
18512 assert.ok(_(1).chain().subtract(2) instanceof _);
18520 /*--------------------------------------------------------------------------*/
18522 QUnit.module('lodash.sum');
18525 var array = [6, 4, 2];
18527 QUnit.test('should return the sum of an array of numbers', function(assert) {
18530 assert.strictEqual(_.sum(array), 12);
18533 QUnit.test('should return `undefined` when passing empty `array` values', function(assert) {
18536 var expected = lodashStable.map(empties, alwaysUndefined),
18537 actual = lodashStable.map(empties, _.sum);
18539 assert.deepEqual(actual, expected);
18542 QUnit.test('should skip `undefined` values', function(assert) {
18545 assert.strictEqual(_.sum([1, undefined]), 1);
18548 QUnit.test('should not skip `NaN` values', function(assert) {
18551 assert.deepEqual(_.sum([1, NaN]), NaN);
18554 QUnit.test('should not coerce values to numbers', function(assert) {
18557 assert.strictEqual(_.sum(['1', '2']), '12');
18561 /*--------------------------------------------------------------------------*/
18563 QUnit.module('lodash.sumBy');
18566 var array = [6, 4, 2],
18567 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
18569 QUnit.test('should work with an `iteratee` argument', function(assert) {
18572 var actual = _.sumBy(objects, function(object) {
18576 assert.deepEqual(actual, 6);
18579 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
18584 _.sumBy(array, function() {
18585 args || (args = slice.call(arguments));
18588 assert.deepEqual(args, [6]);
18591 QUnit.test('should work with a "_.property" style `iteratee`', function(assert) {
18594 var arrays = [[2], [3], [1]];
18595 assert.strictEqual(_.sumBy(arrays, 0), 6);
18596 assert.strictEqual(_.sumBy(objects, 'a'), 6);
18600 /*--------------------------------------------------------------------------*/
18602 QUnit.module('lodash.tail');
18605 var array = [1, 2, 3];
18607 QUnit.test('should accept a falsey `array` argument', function(assert) {
18610 var expected = lodashStable.map(falsey, alwaysEmptyArray);
18612 var actual = lodashStable.map(falsey, function(array, index) {
18614 return index ? _.tail(array) : _.tail();
18618 assert.deepEqual(actual, expected);
18621 QUnit.test('should exclude the first element', function(assert) {
18624 assert.deepEqual(_.tail(array), [2, 3]);
18627 QUnit.test('should return an empty when querying empty arrays', function(assert) {
18630 assert.deepEqual(_.tail([]), []);
18633 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18636 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
18637 actual = lodashStable.map(array, _.tail);
18639 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
18642 QUnit.test('should work in a lazy sequence', function(assert) {
18646 var array = lodashStable.range(LARGE_ARRAY_SIZE),
18649 var actual = _(array).tail().filter(function(value) {
18650 values.push(value);
18655 assert.deepEqual(actual, []);
18656 assert.deepEqual(values, array.slice(1));
18660 actual = _(array).filter(function(value) {
18661 values.push(value);
18662 return isEven(value);
18667 assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
18668 assert.deepEqual(values, array);
18671 skipTest(assert, 4);
18675 QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
18679 var array = lodashStable.range(LARGE_ARRAY_SIZE),
18680 iteratee = function() { pass = false; },
18682 actual = _(array).slice(0, 1).tail().map(iteratee).value();
18685 assert.deepEqual(actual, []);
18688 actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
18691 assert.deepEqual(actual, []);
18694 skipTest(assert, 4);
18699 /*--------------------------------------------------------------------------*/
18701 QUnit.module('lodash.take');
18704 var array = [1, 2, 3];
18706 QUnit.test('should take the first two elements', function(assert) {
18709 assert.deepEqual(_.take(array, 2), [1, 2]);
18712 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
18715 var expected = lodashStable.map(falsey, function(value) {
18716 return value === undefined ? [1] : [];
18719 var actual = lodashStable.map(falsey, function(n) {
18720 return _.take(array, n);
18723 assert.deepEqual(actual, expected);
18726 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
18729 lodashStable.each([0, -1, -Infinity], function(n) {
18730 assert.deepEqual(_.take(array, n), []);
18734 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
18737 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
18738 assert.deepEqual(_.take(array, n), array);
18742 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18745 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
18746 actual = lodashStable.map(array, _.take);
18748 assert.deepEqual(actual, [[1], [4], [7]]);
18751 QUnit.test('should work in a lazy sequence', function(assert) {
18755 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
18756 predicate = function(value) { values.push(value); return isEven(value); },
18758 actual = _(array).take(2).take().value();
18760 assert.deepEqual(actual, _.take(_.take(array, 2)));
18762 actual = _(array).filter(predicate).take(2).take().value();
18763 assert.deepEqual(values, [1, 2]);
18764 assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
18766 actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
18767 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
18771 actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
18772 assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
18773 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
18776 skipTest(assert, 6);
18781 /*--------------------------------------------------------------------------*/
18783 QUnit.module('lodash.takeRight');
18786 var array = [1, 2, 3];
18788 QUnit.test('should take the last two elements', function(assert) {
18791 assert.deepEqual(_.takeRight(array, 2), [2, 3]);
18794 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
18797 var expected = lodashStable.map(falsey, function(value) {
18798 return value === undefined ? [3] : [];
18801 var actual = lodashStable.map(falsey, function(n) {
18802 return _.takeRight(array, n);
18805 assert.deepEqual(actual, expected);
18808 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
18811 lodashStable.each([0, -1, -Infinity], function(n) {
18812 assert.deepEqual(_.takeRight(array, n), []);
18816 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
18819 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
18820 assert.deepEqual(_.takeRight(array, n), array);
18824 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18827 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
18828 actual = lodashStable.map(array, _.takeRight);
18830 assert.deepEqual(actual, [[3], [6], [9]]);
18833 QUnit.test('should work in a lazy sequence', function(assert) {
18837 var array = lodashStable.range(LARGE_ARRAY_SIZE),
18838 predicate = function(value) { values.push(value); return isEven(value); },
18840 actual = _(array).takeRight(2).takeRight().value();
18842 assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
18844 actual = _(array).filter(predicate).takeRight(2).takeRight().value();
18845 assert.deepEqual(values, array);
18846 assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
18848 actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
18849 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
18853 actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
18854 assert.deepEqual(values, array);
18855 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
18858 skipTest(assert, 6);
18863 /*--------------------------------------------------------------------------*/
18865 QUnit.module('lodash.takeRightWhile');
18868 var array = [1, 2, 3, 4];
18871 { 'a': 0, 'b': 0 },
18872 { 'a': 1, 'b': 1 },
18876 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
18879 var actual = _.takeRightWhile(array, function(num) {
18883 assert.deepEqual(actual, [3, 4]);
18886 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
18891 _.takeRightWhile(array, function() {
18892 args = slice.call(arguments);
18895 assert.deepEqual(args, [4, 3, array]);
18898 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
18901 assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
18904 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
18907 assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
18910 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
18913 assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
18916 QUnit.test('should work in a lazy sequence', function(assert) {
18920 var array = lodashStable.range(LARGE_ARRAY_SIZE),
18921 predicate = function(num) { return num > 2; },
18922 expected = _.takeRightWhile(array, predicate),
18923 wrapped = _(array).takeRightWhile(predicate);
18925 assert.deepEqual(wrapped.value(), expected);
18926 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
18927 assert.strictEqual(wrapped.last(), _.last(expected));
18930 skipTest(assert, 3);
18934 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
18939 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
18940 expected = [square(LARGE_ARRAY_SIZE), LARGE_ARRAY_SIZE - 1, lodashStable.map(array.slice(1), square)];
18942 _(array).slice(1).takeRightWhile(function(value, index, array) {
18943 args = slice.call(arguments);
18946 assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
18948 _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
18949 args = slice.call(arguments);
18952 assert.deepEqual(args, expected);
18954 _(array).slice(1).map(square).takeRightWhile(function(value, index) {
18955 args = slice.call(arguments);
18958 assert.deepEqual(args, expected);
18960 _(array).slice(1).map(square).takeRightWhile(function(index) {
18961 args = slice.call(arguments);
18964 assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
18966 _(array).slice(1).map(square).takeRightWhile(function() {
18967 args = slice.call(arguments);
18970 assert.deepEqual(args, expected);
18973 skipTest(assert, 5);
18978 /*--------------------------------------------------------------------------*/
18980 QUnit.module('lodash.takeWhile');
18983 var array = [1, 2, 3, 4];
18986 { 'a': 2, 'b': 2 },
18987 { 'a': 1, 'b': 1 },
18991 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
18994 var actual = _.takeWhile(array, function(num) {
18998 assert.deepEqual(actual, [1, 2]);
19001 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
19006 _.takeWhile(array, function() {
19007 args = slice.call(arguments);
19010 assert.deepEqual(args, [1, 0, array]);
19013 QUnit.test('should work with a "_.matches" style `predicate`', function(assert) {
19016 assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
19019 QUnit.test('should work with a "_.matchesProperty" style `predicate`', function(assert) {
19022 assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
19024 QUnit.test('should work with a "_.property" style `predicate`', function(assert) {
19027 assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
19030 QUnit.test('should work in a lazy sequence', function(assert) {
19034 var array = lodashStable.range(LARGE_ARRAY_SIZE),
19035 predicate = function(num) { return num < 3; },
19036 expected = _.takeWhile(array, predicate),
19037 wrapped = _(array).takeWhile(predicate);
19039 assert.deepEqual(wrapped.value(), expected);
19040 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
19041 assert.strictEqual(wrapped.last(), _.last(expected));
19044 skipTest(assert, 3);
19048 QUnit.test('should work in a lazy sequence with `take`', function(assert) {
19052 var array = lodashStable.range(LARGE_ARRAY_SIZE);
19054 var actual = _(array)
19055 .takeWhile(function(num) { return num < 4; })
19057 .takeWhile(function(num) { return num == 0; })
19060 assert.deepEqual(actual, [0]);
19067 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
19072 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
19073 expected = [1, 0, lodashStable.map(array.slice(1), square)];
19075 _(array).slice(1).takeWhile(function(value, index, array) {
19076 args = slice.call(arguments);
19079 assert.deepEqual(args, [1, 0, array.slice(1)]);
19081 _(array).slice(1).map(square).takeWhile(function(value, index, array) {
19082 args = slice.call(arguments);
19085 assert.deepEqual(args, expected);
19087 _(array).slice(1).map(square).takeWhile(function(value, index) {
19088 args = slice.call(arguments);
19091 assert.deepEqual(args, expected);
19093 _(array).slice(1).map(square).takeWhile(function(value) {
19094 args = slice.call(arguments);
19097 assert.deepEqual(args, [1]);
19099 _(array).slice(1).map(square).takeWhile(function() {
19100 args = slice.call(arguments);
19103 assert.deepEqual(args, expected);
19106 skipTest(assert, 5);
19111 /*--------------------------------------------------------------------------*/
19113 QUnit.module('lodash.tap');
19116 QUnit.test('should intercept and return the given value', function(assert) {
19123 var actual = _.tap(array, function(value) {
19124 intercepted = value;
19127 assert.strictEqual(actual, array);
19128 assert.strictEqual(intercepted, array);
19131 skipTest(assert, 2);
19135 QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
19142 var wrapped = _(array).tap(function(value) {
19143 intercepted = value;
19147 assert.ok(wrapped instanceof _);
19150 assert.strictEqual(intercepted, array);
19153 skipTest(assert, 2);
19158 /*--------------------------------------------------------------------------*/
19160 QUnit.module('lodash.template');
19163 QUnit.test('should escape values in "escape" delimiters', function(assert) {
19166 var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
19167 expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'`\/</p>')),
19168 data = { 'value': '&<>"\'`\/' };
19170 var actual = lodashStable.map(strings, function(string) {
19171 return _.template(string)(data);
19174 assert.deepEqual(actual, expected);
19177 QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
19180 var compiled = _.template('<%= typeof __e %>');
19181 assert.strictEqual(compiled({}), 'undefined');
19184 QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
19187 var compiled = _.template(
19189 for (var key in collection) {\
19190 %><li><%= collection[key] %></li><%\
19194 var data = { 'collection': { 'a': 'A', 'b': 'B' } },
19195 actual = compiled(data);
19197 assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
19200 QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
19203 var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
19204 data = { 'value': true };
19206 assert.strictEqual(compiled(data), 'yap');
19209 QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
19212 var compiled = _.template('<% var b = a; %><%= b.value %>'),
19213 data = { 'a': { 'value': 1 } };
19215 assert.strictEqual(compiled(data), '1');
19218 QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
19221 var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
19222 expected = lodashStable.map(strings, lodashStable.constant('ABC')),
19223 data = { 'a': 'A' };
19225 var actual = lodashStable.map(strings, function(string) {
19226 return _.template(string)(data);
19229 assert.deepEqual(actual, expected);
19232 QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
19235 var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
19236 data = { 'a': true };
19238 assert.strictEqual(compiled(data), 'a="A"');
19241 QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
19244 var compiled = _.template('<%= value ? value : "b" %>'),
19245 data = { 'value': 'a' };
19247 assert.strictEqual(compiled(data), 'a');
19250 QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
19253 var compiled = _.template('<%= typeof Math.abs %>');
19256 var actual = compiled();
19259 assert.strictEqual(actual, 'function');
19262 QUnit.test('should support complex "interpolate" delimiters', function(assert) {
19265 lodashStable.forOwn({
19266 '<%= a + b %>': '3',
19267 '<%= b - a %>': '1',
19268 '<%= a = b %>': '2',
19269 '<%= !a %>': 'false',
19271 '<%= a * b %>': '2',
19272 '<%= a / b %>': '0.5',
19273 '<%= a % b %>': '1',
19274 '<%= a >> b %>': '0',
19275 '<%= a << b %>': '4',
19276 '<%= a & b %>': '0',
19277 '<%= a ^ b %>': '3',
19278 '<%= a | b %>': '3',
19279 '<%= {}.toString.call(0) %>': numberTag,
19280 '<%= a.toFixed(2) %>': '1.00',
19281 '<%= obj["a"] %>': '1',
19282 '<%= delete a %>': 'true',
19283 '<%= "a" in obj %>': 'true',
19284 '<%= obj instanceof Object %>': 'true',
19285 '<%= new Boolean %>': 'false',
19286 '<%= typeof a %>': 'number',
19287 '<%= void a %>': ''
19289 function(value, key) {
19290 var compiled = _.template(key),
19291 data = { 'a': 1, 'b': 2 };
19293 assert.strictEqual(compiled(data), value, key);
19297 QUnit.test('should support ES6 template delimiters', function(assert) {
19300 var data = { 'value': 2 };
19301 assert.strictEqual(_.template('1${value}3')(data), '123');
19302 assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
19305 QUnit.test('should support the "imports" option', function(assert) {
19308 var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
19309 assert.strictEqual(compiled({}), '1');
19312 QUnit.test('should support the "variable" options', function(assert) {
19315 var compiled = _.template(
19316 '<% _.each( data.a, function( value ) { %>' +
19317 '<%= value.valueOf() %>' +
19318 '<% }) %>', { 'variable': 'data' }
19321 var data = { 'a': [1, 2, 3] };
19324 assert.strictEqual(compiled(data), '123');
19326 assert.ok(false, e.message);
19330 QUnit.test('should support custom delimiters', function(assert) {
19333 lodashStable.times(2, function(index) {
19334 var settingsClone = lodashStable.clone(_.templateSettings);
19336 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
19337 'escape': /\{\{-([\s\S]+?)\}\}/g,
19338 'evaluate': /\{\{([\s\S]+?)\}\}/g,
19339 'interpolate': /\{\{=([\s\S]+?)\}\}/g
19342 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
19343 compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
19344 data = { 'collection': ['a & A', 'b & B'] };
19346 assert.strictEqual(compiled(data), expected);
19347 lodashStable.assign(_.templateSettings, settingsClone);
19351 QUnit.test('should support custom delimiters containing special characters', function(assert) {
19354 lodashStable.times(2, function(index) {
19355 var settingsClone = lodashStable.clone(_.templateSettings);
19357 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
19358 'escape': /<\?-([\s\S]+?)\?>/g,
19359 'evaluate': /<\?([\s\S]+?)\?>/g,
19360 'interpolate': /<\?=([\s\S]+?)\?>/g
19363 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
19364 compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
19365 data = { 'collection': ['a & A', 'b & B'] };
19367 assert.strictEqual(compiled(data), expected);
19368 lodashStable.assign(_.templateSettings, settingsClone);
19372 QUnit.test('should use a `with` statement by default', function(assert) {
19375 var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
19376 actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
19378 assert.strictEqual(actual, '1b012');
19381 QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
19384 var lodash = _.templateSettings.imports._,
19385 settingsClone = lodashStable.clone(lodash.templateSettings);
19387 lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
19388 'interpolate': /\{\{=([\s\S]+?)\}\}/g
19391 var compiled = _.template('{{= a }}');
19392 assert.strictEqual(compiled({ 'a': 1 }), '1');
19394 if (settingsClone) {
19395 lodashStable.assign(lodash.templateSettings, settingsClone);
19397 delete lodash.templateSettings;
19401 QUnit.test('should fallback to `_.templateSettings`', function(assert) {
19404 var lodash = _.templateSettings.imports._,
19405 delimiter = _.templateSettings.interpolate;
19407 _.templateSettings.imports._ = { 'escape': lodashStable.escape };
19408 _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
19410 var compiled = _.template('{{= a }}');
19411 assert.strictEqual(compiled({ 'a': 1 }), '1');
19413 _.templateSettings.imports._ = lodash;
19414 _.templateSettings.interpolate = delimiter;
19417 QUnit.test('should ignore `null` delimiters', function(assert) {
19421 'escape': /\{\{-([\s\S]+?)\}\}/g,
19422 'evaluate': /\{\{([\s\S]+?)\}\}/g,
19423 'interpolate': /\{\{=([\s\S]+?)\}\}/g
19426 lodashStable.forOwn({
19427 'escape': '{{- a }}',
19428 'evaluate': '{{ print(a) }}',
19429 'interpolate': '{{= a }}'
19431 function(value, key) {
19432 var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
19433 settings[key] = delimiter[key];
19435 var expected = '1 <%- a %> <% print(a) %> <%= a %>',
19436 compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
19439 assert.strictEqual(compiled(data), expected);
19443 QUnit.test('should work without delimiters', function(assert) {
19446 var expected = 'abc';
19447 assert.strictEqual(_.template(expected)({}), expected);
19450 QUnit.test('should work with `this` references', function(assert) {
19453 var compiled = _.template('a<%= this.String("b") %>c');
19454 assert.strictEqual(compiled(), 'abc');
19456 var object = { 'b': 'B' };
19457 object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
19458 assert.strictEqual(object.compiled(), 'ABC');
19461 QUnit.test('should work with backslashes', function(assert) {
19464 var compiled = _.template('<%= a %> \\b'),
19465 data = { 'a': 'A' };
19467 assert.strictEqual(compiled(data), 'A \\b');
19470 QUnit.test('should work with escaped characters in string literals', function(assert) {
19473 var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
19474 assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
19476 var data = { 'a': 'A' };
19477 compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
19478 assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
19481 QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
19484 var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
19485 assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
19488 QUnit.test('should work with statements containing quotes', function(assert) {
19491 var compiled = _.template("<%\
19492 if (a == 'A' || a == \"a\") {\
19497 var data = { 'a': 'A' };
19498 assert.strictEqual(compiled(data), "'a',\"A\"");
19501 QUnit.test('should work with templates containing newlines and comments', function(assert) {
19504 var compiled = _.template('<%\n\
19505 // A code comment.\n\
19506 if (value) { value += 3; }\n\
19507 %><p><%= value %></p>'
19510 assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
19513 QUnit.test('should not error with IE conditional comments enabled (test with development build)', function(assert) {
19516 var compiled = _.template(''),
19528 QUnit.test('should tokenize delimiters', function(assert) {
19531 var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
19532 data = { 'type': 1 };
19534 assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
19537 QUnit.test('should evaluate delimiters once', function(assert) {
19541 compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
19542 data = { 'func': function(value) { actual.push(value); } };
19545 assert.deepEqual(actual, ['a', 'b', 'c']);
19548 QUnit.test('should match delimiters before escaping text', function(assert) {
19551 var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
19552 assert.strictEqual(compiled(), '<<\n a \n>>');
19555 QUnit.test('should resolve nullish values to an empty string', function(assert) {
19558 var compiled = _.template('<%= a %><%- a %>'),
19559 data = { 'a': null };
19561 assert.strictEqual(compiled(data), '');
19563 data = { 'a': undefined };
19564 assert.strictEqual(compiled(data), '');
19566 data = { 'a': {} };
19567 compiled = _.template('<%= a.b %><%- a.b %>');
19568 assert.strictEqual(compiled(data), '');
19571 QUnit.test('should return an empty string for empty values', function(assert) {
19574 var values = [, null, undefined, ''],
19575 expected = lodashStable.map(values, alwaysEmptyString),
19578 var actual = lodashStable.map(values, function(value, index) {
19579 var compiled = index ? _.template(value) : _.template();
19580 return compiled(data);
19583 assert.deepEqual(actual, expected);
19586 QUnit.test('should parse delimiters without newlines', function(assert) {
19589 var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
19590 compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
19591 data = { 'value': true };
19593 assert.strictEqual(compiled(data), expected);
19596 QUnit.test('should support recursive calls', function(assert) {
19599 var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
19600 data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
19602 assert.strictEqual(compiled(data), 'AB');
19605 QUnit.test('should coerce `text` argument to a string', function(assert) {
19608 var object = { 'toString': lodashStable.constant('<%= a %>') },
19611 assert.strictEqual(_.template(object)(data), '1');
19614 QUnit.test('should not modify the `options` object', function(assert) {
19618 _.template('', options);
19619 assert.deepEqual(options, {});
19622 QUnit.test('should not modify `_.templateSettings` when `options` are provided', function(assert) {
19625 var data = { 'a': 1 };
19627 assert.notOk('a' in _.templateSettings);
19628 _.template('', {}, data);
19629 assert.notOk('a' in _.templateSettings);
19631 delete _.templateSettings.a;
19634 QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
19644 assert.ok(pass, '`data` value');
19649 _.template('', 1)(1);
19653 assert.ok(pass, '`options` value');
19656 QUnit.test('should expose the source on compiled templates', function(assert) {
19659 var compiled = _.template('x'),
19660 values = [String(compiled), compiled.source],
19661 expected = lodashStable.map(values, alwaysTrue);
19663 var actual = lodashStable.map(values, function(value) {
19664 return lodashStable.includes(value, '__p');
19667 assert.deepEqual(actual, expected);
19670 QUnit.test('should expose the source on SyntaxErrors', function(assert) {
19674 _.template('<% if x %>');
19676 var source = e.source;
19678 assert.ok(lodashStable.includes(source, '__p'));
19681 QUnit.test('should not include sourceURLs in the source', function(assert) {
19684 var options = { 'sourceURL': '/a/b/c' },
19685 compiled = _.template('x', options),
19686 values = [compiled.source, undefined];
19689 _.template('<% if x %>', options);
19691 values[1] = e.source;
19693 var expected = lodashStable.map(values, alwaysFalse);
19695 var actual = lodashStable.map(values, function(value) {
19696 return lodashStable.includes(value, 'sourceURL');
19699 assert.deepEqual(actual, expected);
19702 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19705 var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
19706 compiles = lodashStable.map(array, _.template),
19707 data = { 'a': 'one', 'b': '`two`', 'c': 'three' };
19709 var actual = lodashStable.map(compiles, function(compiled) {
19710 return compiled(data);
19713 assert.deepEqual(actual, ['one', '`two`', 'three']);
19717 /*--------------------------------------------------------------------------*/
19719 QUnit.module('lodash.truncate');
19722 var string = 'hi-diddly-ho there, neighborino';
19724 QUnit.test('should use a default `length` of `30`', function(assert) {
19727 assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
19730 QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
19733 assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
19734 assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
19737 QUnit.test('should truncate string the given length', function(assert) {
19740 assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
19743 QUnit.test('should support a `omission` option', function(assert) {
19746 assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
19749 QUnit.test('should support a `length` option', function(assert) {
19752 assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
19755 QUnit.test('should support a `separator` option', function(assert) {
19758 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
19759 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
19760 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
19763 QUnit.test('should treat negative `length` as `0`', function(assert) {
19766 lodashStable.each([0, -2], function(length) {
19767 assert.strictEqual(_.truncate(string, { 'length': length }), '...');
19771 QUnit.test('should coerce `length` to an integer', function(assert) {
19774 lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
19775 var actual = index > 1 ? 'h...' : '...';
19776 assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
19780 QUnit.test('should coerce `string` to a string', function(assert) {
19783 assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
19784 assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
19787 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19790 var actual = lodashStable.map([string, string, string], _.truncate),
19791 truncated = 'hi-diddly-ho there, neighbo...';
19793 assert.deepEqual(actual, [truncated, truncated, truncated]);
19797 /*--------------------------------------------------------------------------*/
19799 QUnit.module('lodash.throttle');
19802 QUnit.test('should throttle a function', function(assert) {
19805 var done = assert.async();
19808 throttled = _.throttle(function() { callCount++; }, 32);
19814 var lastCount = callCount;
19815 assert.ok(callCount > 0);
19817 setTimeout(function() {
19818 assert.ok(callCount > lastCount);
19823 QUnit.test('subsequent calls should return the result of the first call', function(assert) {
19826 var done = assert.async();
19828 var throttled = _.throttle(identity, 32),
19829 result = [throttled('a'), throttled('b')];
19831 assert.deepEqual(result, ['a', 'a']);
19833 setTimeout(function() {
19834 var result = [throttled('x'), throttled('y')];
19835 assert.notEqual(result[0], 'a');
19836 assert.notStrictEqual(result[0], undefined);
19838 assert.notEqual(result[1], 'y');
19839 assert.notStrictEqual(result[1], undefined);
19844 QUnit.test('should clear timeout when `func` is called', function(assert) {
19847 var done = assert.async();
19849 if (!isModularize) {
19853 var getTime = function() {
19854 return ++dateCount == 5 ? Infinity : +new Date;
19857 var lodash = _.runInContext(lodashStable.assign({}, root, {
19858 'Date': lodashStable.assign(function() {
19859 return { 'getTime': getTime };
19865 var throttled = lodash.throttle(function() {
19873 setTimeout(function() {
19874 assert.strictEqual(callCount, 2);
19884 QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
19887 var done = assert.async();
19890 throttled = _.throttle(function() { callCount++; }, 32);
19893 assert.strictEqual(callCount, 1);
19895 setTimeout(function() {
19896 assert.strictEqual(callCount, 1);
19901 lodashStable.times(2, function(index) {
19902 QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
19905 var done = assert.async();
19908 limit = (argv || isPhantom) ? 1000 : 320,
19909 options = index ? { 'leading': false } : {};
19911 var throttled = _.throttle(function() {
19915 var start = +new Date;
19916 while ((new Date - start) < limit) {
19919 var actual = callCount > 1;
19921 setTimeout(function() {
19928 QUnit.test('should apply default options', function(assert) {
19931 var done = assert.async();
19935 var throttled = _.throttle(function(value) {
19940 assert.strictEqual(throttled('a'), 'a');
19941 assert.strictEqual(throttled('b'), 'a');
19943 setTimeout(function() {
19944 assert.strictEqual(callCount, 2);
19949 QUnit.test('should support a `leading` option', function(assert) {
19952 var withLeading = _.throttle(identity, 32, { 'leading': true });
19953 assert.strictEqual(withLeading('a'), 'a');
19955 var withoutLeading = _.throttle(identity, 32, { 'leading': false });
19956 assert.strictEqual(withoutLeading('a'), undefined);
19959 QUnit.test('should support a `trailing` option', function(assert) {
19962 var done = assert.async();
19967 var withTrailing = _.throttle(function(value) {
19970 }, 64, { 'trailing': true });
19972 var withoutTrailing = _.throttle(function(value) {
19975 }, 64, { 'trailing': false });
19977 assert.strictEqual(withTrailing('a'), 'a');
19978 assert.strictEqual(withTrailing('b'), 'a');
19980 assert.strictEqual(withoutTrailing('a'), 'a');
19981 assert.strictEqual(withoutTrailing('b'), 'a');
19983 setTimeout(function() {
19984 assert.strictEqual(withCount, 2);
19985 assert.strictEqual(withoutCount, 1);
19990 QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
19993 var done = assert.async();
19997 var throttled = _.throttle(function() {
19999 }, 64, { 'trailing': false });
20004 setTimeout(function() {
20009 setTimeout(function() {
20010 assert.ok(callCount > 1);
20016 /*--------------------------------------------------------------------------*/
20018 QUnit.module('lodash.debounce and lodash.throttle');
20020 lodashStable.each(['debounce', 'throttle'], function(methodName) {
20021 var func = _[methodName],
20022 isDebounce = methodName == 'debounce';
20024 QUnit.test('_.' + methodName + ' should not error for non-object `options` values', function(assert) {
20037 QUnit.test('_.' + methodName + ' should use a default `wait` of `0`', function(assert) {
20040 var done = assert.async();
20044 var funced = func(function() {
20050 setTimeout(function() {
20052 assert.strictEqual(callCount, isDebounce ? 1 : 2);
20057 QUnit.test('_.' + methodName + ' should invoke `func` with the correct `this` binding', function(assert) {
20060 var done = assert.async();
20063 'funced': func(function() { actual.push(this); }, 32)
20067 expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
20073 setTimeout(function() {
20074 assert.deepEqual(actual, expected);
20079 QUnit.test('_.' + methodName + ' supports recursive calls', function(assert) {
20082 var done = assert.async();
20085 args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
20086 expected = args.slice(),
20087 queue = args.slice();
20089 var funced = func(function() {
20090 var current = [this];
20091 push.apply(current, arguments);
20092 actual.push(current);
20094 var next = queue.shift();
20096 funced.call(next[0], next[1]);
20100 var next = queue.shift();
20101 funced.call(next[0], next[1]);
20102 assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
20104 setTimeout(function() {
20105 assert.deepEqual(actual, expected.slice(0, actual.length));
20110 QUnit.test('_.' + methodName + ' should work if the system time is set backwards', function(assert) {
20113 var done = assert.async();
20115 if (!isModularize) {
20119 var getTime = function() {
20120 return ++dateCount === 4 ? +new Date(2012, 3, 23, 23, 27, 18) : +new Date;
20123 var lodash = _.runInContext(lodashStable.assign({}, root, {
20124 'Date': lodashStable.assign(function() {
20125 return { 'getTime': getTime, 'valueOf': getTime };
20131 var funced = lodash[methodName](function() {
20137 setTimeout(function() {
20139 assert.strictEqual(callCount, isDebounce ? 1 : 2);
20149 QUnit.test('_.' + methodName + ' should support cancelling delayed calls', function(assert) {
20152 var done = assert.async();
20156 var funced = func(function() {
20158 }, 32, { 'leading': false });
20163 setTimeout(function() {
20164 assert.strictEqual(callCount, 0);
20169 QUnit.test('_.' + methodName + ' should reset `lastCalled` after cancelling', function(assert) {
20172 var done = assert.async();
20176 var funced = func(function() {
20177 return ++callCount;
20178 }, 32, { 'leading': true });
20180 assert.strictEqual(funced(), 1);
20182 assert.strictEqual(funced(), 2);
20184 setTimeout(function() {
20185 assert.strictEqual(callCount, 2);
20190 QUnit.test('_.' + methodName + ' should support flushing delayed calls', function(assert) {
20193 var done = assert.async();
20197 var funced = func(function() {
20198 return ++callCount;
20199 }, 32, { 'leading': false });
20202 var actual = funced.flush();
20204 setTimeout(function() {
20205 assert.strictEqual(actual, 1);
20206 assert.strictEqual(callCount, 1);
20212 /*--------------------------------------------------------------------------*/
20214 QUnit.module('lodash.times');
20217 QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
20220 lodashStable.each([-Infinity, NaN, Infinity], function(n) {
20221 assert.deepEqual(_.times(n), []);
20225 QUnit.test('should coerce `n` to an integer', function(assert) {
20228 var actual = _.times(2.6, _.indentify);
20229 assert.deepEqual(actual, [0, 1]);
20232 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
20237 _.times(1, function(assert) {
20238 args || (args = slice.call(arguments));
20241 assert.deepEqual(args, [0]);
20244 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
20247 var values = [, null, undefined],
20248 expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
20250 var actual = lodashStable.map(values, function(value, index) {
20251 return index ? _.times(3, value) : _.times(3);
20254 assert.deepEqual(actual, expected);
20257 QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
20260 assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
20263 QUnit.test('should return an empty array for falsey and negative `n` arguments', function(assert) {
20266 var values = falsey.concat(-1, -Infinity),
20267 expected = lodashStable.map(values, alwaysEmptyArray);
20269 var actual = lodashStable.map(values, function(value, index) {
20270 return index ? _.times(value) : _.times();
20273 assert.deepEqual(actual, expected);
20276 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
20280 assert.deepEqual(_(3).times(), [0, 1, 2]);
20287 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
20291 assert.ok(_(3).chain().times() instanceof _);
20299 /*--------------------------------------------------------------------------*/
20301 QUnit.module('lodash.toArray');
20304 QUnit.test('should convert objects to arrays', function(assert) {
20307 assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
20310 QUnit.test('should convert strings to arrays', function(assert) {
20313 assert.deepEqual(_.toArray(''), []);
20314 assert.deepEqual(_.toArray('ab'), ['a', 'b']);
20315 assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
20318 QUnit.test('should convert iterables to arrays', function(assert) {
20321 if (!isNpm && Symbol && Symbol.iterator) {
20322 var object = { '0': 'a', 'length': 1 };
20323 object[Symbol.iterator] = arrayProto[Symbol.iterator];
20325 assert.deepEqual(_.toArray(object), ['a']);
20332 QUnit.test('should work in a lazy sequence', function(assert) {
20336 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
20337 actual = _(array).slice(1).map(String).toArray().value();
20339 assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
20341 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
20342 return ['key' + index, index];
20345 actual = _(object).toArray().slice(1).map(String).value();
20346 assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
20349 skipTest(assert, 2);
20354 /*--------------------------------------------------------------------------*/
20356 QUnit.module('lodash.toLower');
20359 QUnit.test('should convert whole string to lower case', function(assert) {
20362 assert.deepEqual(_.toLower('--Foo-Bar'), '--foo-bar');
20363 assert.deepEqual(_.toLower('fooBar'), 'foobar');
20364 assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
20368 /*--------------------------------------------------------------------------*/
20370 QUnit.module('lodash.toUpper');
20373 QUnit.test('should convert whole string to upper case', function(assert) {
20376 assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
20377 assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
20378 assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
20382 /*--------------------------------------------------------------------------*/
20384 QUnit.module('lodash.slice and lodash.toArray');
20386 lodashStable.each(['slice', 'toArray'], function(methodName) {
20387 var args = (function() { return arguments; }(1, 2, 3)),
20389 func = _[methodName];
20391 QUnit.test('should return a dense array', function(assert) {
20394 var sparse = Array(3);
20397 var actual = func(sparse);
20399 assert.ok('0' in actual);
20400 assert.ok('2' in actual);
20401 assert.deepEqual(actual, sparse);
20404 QUnit.test('should treat array-like objects like arrays', function(assert) {
20407 var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 };
20408 assert.deepEqual(func(object), ['a', 'b', 'c']);
20409 assert.deepEqual(func(args), array);
20412 QUnit.test('should return a shallow clone of arrays', function(assert) {
20415 var actual = func(array);
20416 assert.deepEqual(actual, array);
20417 assert.notStrictEqual(actual, array);
20420 QUnit.test('should work with a node list for `collection`', function(assert) {
20425 var actual = func(document.getElementsByTagName('body'));
20428 assert.deepEqual(actual, [body]);
20436 /*--------------------------------------------------------------------------*/
20438 QUnit.module('toInteger methods');
20440 lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
20441 var func = _[methodName],
20442 isSafe = methodName == 'toSafeInteger';
20444 QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
20447 assert.strictEqual(func(-5.6), -5);
20448 assert.strictEqual(func('5.6'), 5);
20449 assert.strictEqual(func(), 0);
20450 assert.strictEqual(func(NaN), 0);
20452 var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
20453 assert.strictEqual(func(Infinity), expected);
20454 assert.strictEqual(func(-Infinity), -expected);
20457 QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
20460 assert.strictEqual(1 / func(-0), -Infinity);
20464 /*--------------------------------------------------------------------------*/
20466 QUnit.module('lodash.toLength');
20469 QUnit.test('should return a valid length', function(assert) {
20472 assert.strictEqual(_.toLength(-1), 0);
20473 assert.strictEqual(_.toLength('1'), 1);
20474 assert.strictEqual(_.toLength(1.1), 1);
20475 assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
20478 QUnit.test('should return `value` if a valid length', function(assert) {
20481 assert.strictEqual(_.toLength(0), 0);
20482 assert.strictEqual(_.toLength(3), 3);
20483 assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
20486 QUnit.test('should convert `-0` to `0`', function(assert) {
20489 assert.strictEqual(1 / _.toLength(-0), Infinity);
20493 /*--------------------------------------------------------------------------*/
20495 QUnit.module('lodash.toInteger and lodash.toNumber');
20497 lodashStable.each(['toInteger', 'toNumber'], function(methodName) {
20498 var func = _[methodName],
20499 isInt = methodName == 'toInteger';
20501 function negative(string) {
20502 return '-' + string;
20505 function pad(string) {
20506 return whitespace + string + whitespace;
20509 function positive(string) {
20510 return '+' + string;
20513 QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
20516 var values = falsey.concat(whitespace);
20518 var expected = lodashStable.map(values, function(value) {
20519 return (isInt || (value === whitespace)) ? 0 : Number(value);
20522 var actual = lodashStable.map(values, function(value, index) {
20523 return index ? func(value) : func();
20526 assert.deepEqual(actual, expected);
20529 QUnit.test('`_.' + methodName + '` should preserve sign of `0`', function(assert) {
20532 var values = [0, '0', -0, '-0'],
20533 expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
20535 var actual = lodashStable.map(values, function(value) {
20536 var result = func(value);
20537 return [result, 1 / result];
20540 assert.deepEqual(actual, expected);
20543 QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
20546 var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
20548 var expected = lodashStable.map(values, function(value) {
20550 if (value == 1.2) {
20553 else if (value == Infinity) {
20554 value = MAX_INTEGER;
20556 else if (value !== value) {
20560 return [value, value, -value, -value];
20563 var actual = lodashStable.map(values, function(value) {
20564 return lodashStable.flattenDeep(
20565 lodashStable.times(2, function(index) {
20566 var other = index ? -value : value;
20569 func(Object(other))
20575 assert.deepEqual(actual, expected);
20578 QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
20581 var transforms = [identity, pad, positive, negative];
20584 '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
20585 '1e+308', '1e308', '1E+308', '1E308',
20586 '5e-324', '5E-324',
20590 var expected = lodashStable.map(values, function(value) {
20593 if (n == 1.234567890) {
20596 else if (n == Infinity) {
20599 else if (n == Number.MIN_VALUE || n !== n) {
20603 return [n, n, n, n, n, n, -n, -n];
20606 var actual = lodashStable.map(values, function(value) {
20607 return lodashStable.flattenDeep(
20608 lodashStable.map(transforms, function(mod) {
20611 func(Object(mod(value)))
20617 assert.deepEqual(actual, expected);
20620 QUnit.test('`_.' + methodName + '` should convert binary and octal strings to numbers', function(assert) {
20623 var numbers = [42, 5349, 1715004],
20624 transforms = [identity, pad],
20625 values = ['0b101010', '0o12345', '0x1a2b3c'];
20627 var expected = lodashStable.map(numbers, function(n) {
20628 return lodashStable.times(8, lodashStable.constant(n));
20631 var actual = lodashStable.map(values, function(value) {
20632 return lodashStable.flattenDeep(
20633 lodashStable.times(2, function(index) {
20634 var other = index ? value.toUpperCase() : value;
20635 return lodashStable.map(transforms, function(mod) {
20638 func(Object(mod(other)))
20645 assert.deepEqual(actual, expected);
20648 QUnit.test('`_.' + methodName + '` should convert invalid binary and octal strings to `NaN`', function(assert) {
20651 var transforms = [identity, pad, positive, negative],
20652 values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
20654 var expected = lodashStable.map(values, function(n) {
20655 return lodashStable.times(16, lodashStable.constant(isInt ? 0 : NaN));
20658 var actual = lodashStable.map(values, function(value) {
20659 return lodashStable.flattenDeep(
20660 lodashStable.times(2, function(index) {
20661 var other = index ? value.toUpperCase() : value;
20662 return lodashStable.map(transforms, function(mod) {
20665 func(Object(mod(value)))
20672 assert.deepEqual(actual, expected);
20675 QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
20683 { 'valueOf': '1.1' },
20684 { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
20685 { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
20686 { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
20687 { 'valueOf': lodashStable.constant('-0x1a2b3c') },
20688 { 'toString': lodashStable.constant('-0x1a2b3c') },
20689 { 'valueOf': lodashStable.constant('0o12345') },
20690 { 'toString': lodashStable.constant('0o12345') },
20691 { 'valueOf': lodashStable.constant('0b101010') },
20692 { 'toString': lodashStable.constant('0b101010') }
20697 NaN, 2.2, 1.1, 1.1,
20712 var actual = lodashStable.map(values, func);
20714 assert.deepEqual(actual, expected);
20718 /*--------------------------------------------------------------------------*/
20720 QUnit.module('lodash.toPairs');
20723 QUnit.test('should create a two dimensional array of key-value pairs', function(assert) {
20726 var object = { 'a': 1, 'b': 2 };
20727 assert.deepEqual(_.toPairs(object), [['a', 1], ['b', 2]]);
20730 QUnit.test('should work with an object that has a `length` property', function(assert) {
20733 var object = { '0': 'a', '1': 'b', 'length': 2 };
20734 assert.deepEqual(_.toPairs(object), [['0', 'a'], ['1', 'b'], ['length', 2]]);
20737 QUnit.test('should work with strings', function(assert) {
20740 lodashStable.each(['xo', Object('xo')], function(string) {
20741 assert.deepEqual(_.toPairs(string), [['0', 'x'], ['1', 'o']]);
20746 /*--------------------------------------------------------------------------*/
20748 QUnit.module('lodash.toPath');
20751 QUnit.test('should convert a string to a path', function(assert) {
20754 assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
20755 assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
20758 QUnit.test('should coerce array elements to strings', function(assert) {
20761 var array = ['a', 'b', 'c'];
20763 lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
20764 var actual = _.toPath(value);
20765 assert.deepEqual(actual, array);
20766 assert.notStrictEqual(actual, array);
20770 QUnit.test('should handle complex paths', function(assert) {
20773 var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
20774 assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
20777 QUnit.test('should ignore consecutive brackets and dots', function(assert) {
20780 var expected = ['a'];
20781 assert.deepEqual(_.toPath('a.'), expected);
20782 assert.deepEqual(_.toPath('a[]'), expected);
20784 expected = ['a', 'b'];
20785 assert.deepEqual(_.toPath('a..b'), expected);
20786 assert.deepEqual(_.toPath('a[][]b'), expected);
20790 /*--------------------------------------------------------------------------*/
20792 QUnit.module('lodash.toPlainObject');
20795 var args = arguments;
20797 QUnit.test('should flatten inherited properties', function(assert) {
20800 function Foo() { this.b = 2; }
20801 Foo.prototype.c = 3;
20803 var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
20804 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
20807 QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
20810 var actual = _.toPlainObject(args),
20811 expected = { '0': 1, '1': 2, '2': 3 };
20813 assert.deepEqual(actual, expected);
20816 QUnit.test('should convert arrays to plain objects', function(assert) {
20819 var actual = _.toPlainObject(['a', 'b', 'c']),
20820 expected = { '0': 'a', '1': 'b', '2': 'c' };
20822 assert.deepEqual(actual, expected);
20826 /*--------------------------------------------------------------------------*/
20828 QUnit.module('lodash.toString');
20831 QUnit.test('should treat nullish values as empty strings', function(assert) {
20834 var values = [, null, undefined],
20835 expected = lodashStable.map(values, alwaysEmptyString);
20837 var actual = lodashStable.map(values, function(value, index) {
20838 return index ? _.toString(value) : _.toString();
20841 assert.deepEqual(actual, expected);
20844 QUnit.test('should preserve sign of `0`', function(assert) {
20847 var values = [0, Object(0), -0, Object(-0)],
20848 expected = ['0', '0', '-0', '-0'],
20849 actual = lodashStable.map(values, _.toString);
20851 assert.deepEqual(actual, expected);
20854 QUnit.test('should not error on symbols', function(assert) {
20859 assert.strictEqual(_.toString(symbol), 'Symbol(a)');
20861 assert.ok(false, e.message);
20869 QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
20873 var wrapped = _([1, 2, 3]);
20874 assert.strictEqual(wrapped.toString(), '1,2,3');
20882 /*--------------------------------------------------------------------------*/
20884 QUnit.module('lodash.transform');
20893 QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
20896 var accumulators = [, null, undefined],
20897 expected = lodashStable.map(accumulators, alwaysTrue),
20900 var iteratee = function(result, value, key) {
20901 result[key] = square(value);
20904 var mapper = function(accumulator, index) {
20905 return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
20908 var results = lodashStable.map(accumulators, mapper);
20910 var actual = lodashStable.map(results, function(result) {
20911 return result instanceof Foo;
20914 assert.deepEqual(actual, expected);
20916 expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
20917 actual = lodashStable.map(results, lodashStable.toPlainObject);
20919 assert.deepEqual(actual, expected);
20921 object = { 'a': 1, 'b': 2, 'c': 3 };
20922 actual = lodashStable.map(accumulators, mapper);
20924 assert.deepEqual(actual, expected);
20926 object = [1, 2, 3];
20927 expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
20928 actual = lodashStable.map(accumulators, mapper);
20930 assert.deepEqual(actual, expected);
20933 QUnit.test('should create regular arrays from typed arrays', function(assert) {
20936 var expected = lodashStable.map(typedArrays, alwaysTrue);
20938 var actual = lodashStable.map(typedArrays, function(type) {
20939 var Ctor = root[type],
20940 array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
20942 return lodashStable.isArray(_.transform(array, noop));
20945 assert.deepEqual(actual, expected);
20948 QUnit.test('should support an `accumulator` value', function(assert) {
20951 var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
20952 expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
20954 var actual = lodashStable.map(values, function(value) {
20955 return _.transform(value, function(result, value) {
20956 result.push(square(value));
20960 assert.deepEqual(actual, expected);
20962 var object = { 'a': 1, 'b': 4, 'c': 9 },
20963 expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
20965 actual = lodashStable.map(values, function(value) {
20966 return _.transform(value, function(result, value, key) {
20967 result[key] = square(value);
20971 assert.deepEqual(actual, expected);
20973 lodashStable.each([[], {}], function(accumulator) {
20974 var actual = lodashStable.map(values, function(value) {
20975 return _.transform(value, noop, accumulator);
20978 assert.ok(lodashStable.every(actual, function(result) {
20979 return result === accumulator;
20982 assert.strictEqual(_.transform(null, null, accumulator), accumulator);
20986 QUnit.test('should treat sparse arrays as dense', function(assert) {
20989 var actual = _.transform(Array(1), function(result, value, index) {
20990 result[index] = String(value);
20993 assert.deepEqual(actual, ['undefined']);
20996 QUnit.test('should work without an `iteratee` argument', function(assert) {
20999 assert.ok(_.transform(new Foo) instanceof Foo);
21002 QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
21005 var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
21006 values = [true, false, 0, 1, NaN, '', 'a'],
21007 expected = lodashStable.map(values, alwaysEmptyObject);
21009 var results = lodashStable.map(values, function(value) {
21010 return _.transform(value);
21013 assert.deepEqual(results, expected);
21015 expected = lodashStable.map(values, alwaysFalse);
21017 var actual = lodashStable.map(results, function(value, index) {
21018 return value instanceof Ctors[index];
21021 assert.deepEqual(actual, expected);
21024 QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
21027 Foo.prototype.constructor = null;
21028 assert.notOk(_.transform(new Foo) instanceof Foo);
21029 Foo.prototype.constructor = Foo;
21032 QUnit.test('should create an empty object when provided a falsey `object` argument', function(assert) {
21035 var expected = lodashStable.map(falsey, alwaysEmptyObject);
21037 var actual = lodashStable.map(falsey, function(object, index) {
21038 return index ? _.transform(object) : _.transform();
21041 assert.deepEqual(actual, expected);
21044 lodashStable.each({
21045 'array': [1, 2, 3],
21046 'object': { 'a': 1, 'b': 2, 'c': 3 }
21048 function(object, key) {
21049 QUnit.test('should provide the correct `iteratee` arguments when transforming an ' + key, function(assert) {
21054 _.transform(object, function() {
21055 args || (args = slice.call(arguments));
21058 var first = args[0];
21059 if (key == 'array') {
21060 assert.ok(first !== object && lodashStable.isArray(first));
21061 assert.deepEqual(args, [first, 1, 0, object]);
21063 assert.ok(first !== object && lodashStable.isPlainObject(first));
21064 assert.deepEqual(args, [first, 1, 'a', object]);
21069 QUnit.test('should create an object from the same realm as `object`', function(assert) {
21072 var objects = lodashStable.filter(realm, function(value) {
21073 return lodashStable.isObject(value) && !lodashStable.isElement(value);
21076 var expected = lodashStable.map(objects, alwaysTrue);
21078 var actual = lodashStable.map(objects, function(object) {
21079 var Ctor = object.constructor,
21080 result = _.transform(object);
21082 if (result === object) {
21085 if (lodashStable.isTypedArray(object)) {
21086 return result instanceof Array;
21088 return result instanceof Ctor || !(new Ctor instanceof Ctor);
21091 assert.deepEqual(actual, expected);
21095 /*--------------------------------------------------------------------------*/
21097 QUnit.module('trim methods');
21099 lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
21100 var func = _[methodName];
21104 parts.push('leading');
21107 parts.push('trailing');
21109 parts = parts.join(' and ');
21111 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
21114 var string = whitespace + 'a b c' + whitespace,
21115 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
21117 assert.strictEqual(func(string), expected);
21120 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
21123 var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
21124 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
21126 assert.strictEqual(func(object), expected);
21129 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
21132 var string = '-_-a-b-c-_-',
21133 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
21135 assert.strictEqual(func(string, '_-'), expected);
21138 QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
21141 var object = { 'toString': lodashStable.constant('_-') },
21142 string = '-_-a-b-c-_-',
21143 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
21145 assert.strictEqual(func(string, object), expected);
21148 QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
21151 lodashStable.each([null, '_-'], function(chars) {
21152 assert.strictEqual(func(null, chars), '');
21153 assert.strictEqual(func(undefined, chars), '');
21154 assert.strictEqual(func('', chars), '');
21158 QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
21161 var string = whitespace + 'a b c' + whitespace,
21162 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
21164 assert.strictEqual(func(string, undefined), expected);
21165 assert.strictEqual(func(string, ''), string);
21168 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
21171 var string = Object(whitespace + 'a b c' + whitespace),
21172 trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
21173 actual = lodashStable.map([string, string, string], func);
21175 assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
21178 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
21182 var string = whitespace + 'a b c' + whitespace,
21183 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
21185 assert.strictEqual(_(string)[methodName](), expected);
21192 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
21196 var string = whitespace + 'a b c' + whitespace;
21197 assert.ok(_(string).chain()[methodName]() instanceof _);
21205 /*--------------------------------------------------------------------------*/
21207 QUnit.module('uncommon symbols');
21210 var flag = '\ud83c\uddfa\ud83c\uddf8',
21211 heart = '\u2764' + emojiVar,
21212 hearts = '\ud83d\udc95',
21213 leafs = '\ud83c\udf42',
21214 raisedHand = '\u270B' + emojiVar,
21215 rocket = '\ud83d\ude80',
21216 thumbsUp = '\ud83d\udc4d',
21217 comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68';
21219 QUnit.test('should account for astral symbols', function(assert) {
21222 var allHearts = _.repeat(hearts, 10),
21223 chars = hearts + comboGlyph,
21224 string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
21225 trimChars = comboGlyph + hearts,
21226 trimString = trimChars + string + trimChars;
21228 assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
21229 assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
21230 assert.strictEqual(_.capitalize(rocket), rocket);
21232 assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
21233 assert.strictEqual(_.padStart(string, 16), ' ' + string);
21234 assert.strictEqual(_.padEnd(string, 16), string + ' ');
21236 assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
21237 assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
21238 assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
21240 assert.strictEqual(_.size(string), 13);
21241 assert.deepEqual(_.toArray(string), ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket]);
21243 assert.strictEqual(_.trim(trimString, chars), string);
21244 assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
21245 assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
21247 assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
21248 assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
21250 assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
21252 lodashStable.times(2, function(index) {
21253 var separator = index ? RegExp(hearts) : hearts,
21254 options = { 'length': 4, 'separator': separator },
21255 actual = _.truncate(string, options);
21257 assert.strictEqual(actual, 'A...');
21258 assert.strictEqual(actual.length, 4);
21260 actual = _.truncate(allHearts, options);
21261 assert.strictEqual(actual, hearts + '...');
21262 assert.strictEqual(actual.length, 5);
21266 QUnit.test('should match lone surrogates', function(assert) {
21269 var pair = hearts.split(''),
21270 surrogates = pair[0] + ' ' + pair[1];
21272 assert.strictEqual(_.size(surrogates), 3);
21273 assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
21274 assert.deepEqual(_.words(surrogates), []);
21277 QUnit.test('should account for regional symbols', function(assert) {
21280 var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
21281 regionals = pair.join(' ');
21283 assert.strictEqual(_.size(flag), 1);
21284 assert.strictEqual(_.size(regionals), 3);
21286 assert.deepEqual(_.toArray(flag), [flag]);
21287 assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
21289 assert.deepEqual(_.words(flag), [flag]);
21290 assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
21293 QUnit.test('should account for variation selectors', function(assert) {
21296 assert.strictEqual(_.size(heart), 1);
21297 assert.deepEqual(_.toArray(heart), [heart]);
21298 assert.deepEqual(_.words(heart), [heart]);
21301 QUnit.test('should account for modifiers', function(assert) {
21304 var values = lodashStable.map(emojiModifiers, function(modifier) {
21305 return thumbsUp + modifier;
21308 var expected = lodashStable.map(values, function(value) {
21309 return [1, [value], [value]];
21312 var actual = lodashStable.map(values, function(value) {
21313 return [_.size(value), _.toArray(value), _.words(value)];
21316 assert.deepEqual(actual, expected);
21319 QUnit.test('should account for variation selectors with modifiers', function(assert) {
21322 var values = lodashStable.map(emojiModifiers, function(modifier) {
21323 return raisedHand + modifier;
21326 var expected = lodashStable.map(values, function(value) {
21327 return [1, [value], [value]];
21330 var actual = lodashStable.map(values, function(value) {
21331 return [_.size(value), _.toArray(value), _.words(value)];
21334 assert.deepEqual(actual, expected);
21337 QUnit.test('should account for combining diacritical marks', function(assert) {
21340 var values = lodashStable.map(comboMarks, function(mark) {
21344 var expected = lodashStable.map(values, function(value) {
21345 return [1, [value], [value]];
21348 var actual = lodashStable.map(values, function(value) {
21349 return [_.size(value), _.toArray(value), _.words(value)];
21352 assert.deepEqual(actual, expected);
21356 /*--------------------------------------------------------------------------*/
21358 QUnit.module('lodash.unescape');
21361 var escaped = '&<>"'\/',
21362 unescaped = '&<>"\'\/';
21364 escaped += escaped;
21365 unescaped += unescaped;
21367 QUnit.test('should unescape entities in order', function(assert) {
21370 assert.strictEqual(_.unescape('&lt;'), '<');
21373 QUnit.test('should unescape the proper entities', function(assert) {
21376 assert.strictEqual(_.unescape(escaped), unescaped);
21379 QUnit.test('should not unescape the "/" entity', function(assert) {
21382 assert.strictEqual(_.unescape('/'), '/');
21385 QUnit.test('should handle strings with nothing to unescape', function(assert) {
21388 assert.strictEqual(_.unescape('abc'), 'abc');
21391 QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
21394 assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
21398 /*--------------------------------------------------------------------------*/
21400 QUnit.module('lodash.upperCase');
21403 QUnit.test('should uppercase as space-separated words', function(assert) {
21406 assert.strictEqual(_.upperCase('--foo-bar'), 'FOO BAR');
21407 assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
21408 assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
21412 /*--------------------------------------------------------------------------*/
21414 QUnit.module('lodash.upperFirst');
21417 QUnit.test('should uppercase only the first character', function(assert) {
21420 assert.strictEqual(_.upperFirst('fred'), 'Fred');
21421 assert.strictEqual(_.upperFirst('Fred'), 'Fred');
21422 assert.strictEqual(_.upperFirst('FRED'), 'FRED');
21426 /*--------------------------------------------------------------------------*/
21428 QUnit.module('lodash.unary');
21432 return slice.call(arguments);
21435 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
21438 var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
21439 assert.deepEqual(actual, [6, 8, 10]);
21442 QUnit.test('should work when provided less than the capped number of arguments', function(assert) {
21445 var capped = _.unary(fn);
21446 assert.deepEqual(capped(), []);
21450 /*--------------------------------------------------------------------------*/
21452 QUnit.module('union methods');
21454 lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
21455 var args = (function() { return arguments; }(1, 2, 3)),
21456 func = _[methodName];
21458 QUnit.test('`_.' + methodName + '` should return the union of the given arrays', function(assert) {
21461 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
21462 assert.deepEqual(actual, [1, 3, 2, 5, 4]);
21465 QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
21468 var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
21469 assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
21472 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
21476 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
21477 assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
21478 assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
21482 /*--------------------------------------------------------------------------*/
21484 QUnit.module('lodash.unionBy');
21487 QUnit.test('should accept an `iteratee` argument', function(assert) {
21490 var actual = _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
21491 assert.deepEqual(actual, [2.1, 1.2, 4.3]);
21493 actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
21494 assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
21497 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
21502 _.unionBy([2.1, 1.2], [4.3, 2.4], function() {
21503 args || (args = slice.call(arguments));
21506 assert.deepEqual(args, [2.1]);
21510 /*--------------------------------------------------------------------------*/
21512 QUnit.module('lodash.unionWith');
21515 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
21517 QUnit.test('should work with a `comparator` argument', function(assert) {
21520 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
21521 actual = _.unionWith(objects, others, lodashStable.isEqual);
21523 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]);
21527 /*--------------------------------------------------------------------------*/
21529 QUnit.module('lodash.uniq');
21532 QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
21535 var array = [[2, 1, 2], [1, 2, 1]],
21536 actual = lodashStable.map(array, lodashStable.uniq);
21538 assert.deepEqual(actual, [[2, 1], [1, 2]]);
21542 /*--------------------------------------------------------------------------*/
21544 QUnit.module('uniq methods');
21546 lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
21547 var func = _[methodName],
21548 isSorted = /^sorted/.test(methodName);
21549 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
21552 objects = _.sortBy(objects, 'a');
21555 QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
21558 var array = [2, 3, 1, 2, 3, 1];
21559 assert.deepEqual(func(array), [2, 3, 1]);
21562 QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
21565 var array = [1, 1, 2, 2, 3];
21566 assert.deepEqual(func(array), [1, 2, 3]);
21569 QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
21572 assert.deepEqual(func(objects), objects);
21575 QUnit.test('`_.' + methodName + '` should not treat `NaN` as unique', function(assert) {
21578 assert.deepEqual(func([1, 3, NaN, NaN]), [1, 3, NaN]);
21581 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
21584 var largeArray = [],
21585 expected = [0, {}, 'a'],
21586 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
21588 lodashStable.each(expected, function(value) {
21589 lodashStable.times(count, function() {
21590 largeArray.push(value);
21594 assert.deepEqual(func(largeArray), expected);
21597 QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
21600 var largeArray = [],
21601 expected = [false, true, null, undefined, NaN],
21602 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
21604 lodashStable.each(expected, function(value) {
21605 lodashStable.times(count, function() {
21606 largeArray.push(value);
21610 assert.deepEqual(func(largeArray), expected);
21613 QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
21617 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
21618 assert.deepEqual(func(largeArray), largeArray);
21625 QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
21628 // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
21631 Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
21632 Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
21633 Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
21636 var largeArray = [],
21637 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
21639 expected = lodashStable.map(expected, function(symbol) {
21640 return symbol || {};
21643 lodashStable.each(expected, function(value) {
21644 lodashStable.times(count, function() {
21645 largeArray.push(value);
21649 assert.deepEqual(func(largeArray), expected);
21656 QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
21659 var largeArray = [],
21660 expected = ['2', 2, Object('2'), Object(2)],
21661 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
21663 lodashStable.each(expected, function(value) {
21664 lodashStable.times(count, function() {
21665 largeArray.push(value);
21669 assert.deepEqual(func(largeArray), expected);
21673 /*--------------------------------------------------------------------------*/
21675 QUnit.module('uniqBy methods');
21677 lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
21678 var func = _[methodName],
21679 isSorted = methodName == 'sortedUniqBy',
21680 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
21683 objects = _.sortBy(objects, 'a');
21685 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
21688 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
21690 var actual = func(objects, function(object) {
21694 assert.deepEqual(actual, expected);
21697 QUnit.test('should work with large arrays', function(assert) {
21700 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
21704 var actual = func(largeArray, String);
21706 assert.deepEqual(actual, [[1, 2]]);
21707 assert.strictEqual(actual[0], largeArray[0]);
21710 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
21715 func(objects, function() {
21716 args || (args = slice.call(arguments));
21719 assert.deepEqual(args, [objects[0]]);
21722 QUnit.test('`_.' + methodName + '` should work with a "_.property" style `iteratee`', function(assert) {
21725 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
21726 actual = func(objects, 'a');
21728 assert.deepEqual(actual, expected);
21730 var arrays = [[2], [3], [1], [2], [3], [1]];
21732 arrays = lodashStable.sortBy(arrays, 0);
21734 expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
21735 actual = func(arrays, 0);
21737 assert.deepEqual(actual, expected);
21740 lodashStable.each({
21741 'an array': [0, 'a'],
21742 'an object': { '0': 'a' },
21746 function(iteratee, key) {
21747 QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
21750 var actual = func([['a'], ['a'], ['b']], iteratee);
21751 assert.deepEqual(actual, [['a'], ['b']]);
21756 /*--------------------------------------------------------------------------*/
21758 QUnit.module('lodash.uniqWith');
21761 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
21763 QUnit.test('should work with a `comparator` argument', function(assert) {
21766 var actual = _.uniqWith(objects, lodashStable.isEqual);
21767 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]);
21771 /*--------------------------------------------------------------------------*/
21773 QUnit.module('lodash.uniqueId');
21776 QUnit.test('should generate unique ids', function(assert) {
21779 var actual = lodashStable.times(1000, function(assert) {
21780 return _.uniqueId();
21783 assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
21786 QUnit.test('should return a string value when not providing a prefix argument', function(assert) {
21789 assert.strictEqual(typeof _.uniqueId(), 'string');
21792 QUnit.test('should coerce the prefix argument to a string', function(assert) {
21795 var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
21796 assert.ok(/3\d+,2\d+,1\d+/.test(actual));
21800 /*--------------------------------------------------------------------------*/
21802 QUnit.module('lodash.unset');
21805 QUnit.test('should unset property values', function(assert) {
21808 lodashStable.each(['a', ['a']], function(path) {
21809 var object = { 'a': 1, 'c': 2 };
21810 assert.strictEqual(_.unset(object, path), true);
21811 assert.deepEqual(object, { 'c': 2 });
21815 QUnit.test('should unset deep property values', function(assert) {
21818 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
21819 var object = { 'a': { 'b': { 'c': null } } };
21820 assert.strictEqual(_.unset(object, path), true);
21821 assert.deepEqual(object, { 'a': { 'b': {} } });
21825 QUnit.test('should handle complex paths', function(assert) {
21829 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
21830 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
21833 lodashStable.each(paths, function(path) {
21834 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
21835 assert.strictEqual(_.unset(object, path), true);
21836 assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
21840 QUnit.test('should return `true` for nonexistent paths', function(assert) {
21843 var object = { 'a': { 'b': { 'c': null } } };
21845 lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
21846 assert.strictEqual(_.unset(object, path), true);
21849 assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
21852 QUnit.test('should not error when `object` is nullish', function(assert) {
21855 var values = [null, undefined],
21856 expected = [[true, true], [true, true]];
21858 var actual = lodashStable.map(values, function(value) {
21860 return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
21866 assert.deepEqual(actual, expected);
21869 QUnit.test('should follow `path` over non-plain objects', function(assert) {
21872 var object = { 'a': '' },
21873 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
21875 lodashStable.each(paths, function(path) {
21878 var actual = _.unset(0, path);
21879 assert.strictEqual(actual, true);
21880 assert.notOk('a' in numberProto);
21882 delete numberProto.a;
21885 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
21886 stringProto.replace.b = 1;
21888 var actual = _.unset(object, path);
21889 assert.strictEqual(actual, true);
21890 assert.notOk('a' in stringProto.replace);
21892 delete stringProto.replace.b;
21896 QUnit.test('should return `false` for non-configurable properties', function(assert) {
21901 if (!isStrict && defineProperty) {
21902 defineProperty(object, 'a', {
21903 'configurable': false,
21904 'enumerable': true,
21908 assert.strictEqual(_.unset(object, 'a'), false);
21916 /*--------------------------------------------------------------------------*/
21918 QUnit.module('lodash.unzipWith');
21921 QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
21924 var array = [[1, 4], [2, 5], [3, 6]];
21926 var actual = _.unzipWith(array, function(a, b, c) {
21930 assert.deepEqual(actual, [6, 15]);
21933 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
21938 _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
21939 args || (args = slice.call(arguments));
21942 assert.deepEqual(args, [1, 2]);
21945 QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
21948 var array = [[1, 3], [2, 4]],
21949 values = [, null, undefined],
21950 expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
21952 var actual = lodashStable.map(values, function(value, index) {
21953 return index ? _.unzipWith(array, value) : _.unzipWith(array);
21956 assert.deepEqual(actual, expected);
21960 /*--------------------------------------------------------------------------*/
21962 QUnit.module('lodash.values');
21965 QUnit.test('should get the values of an object', function(assert) {
21968 var object = { 'a': 1, 'b': 2 };
21969 assert.deepEqual(_.values(object), [1, 2]);
21972 QUnit.test('should work with an object that has a `length` property', function(assert) {
21975 var object = { '0': 'a', '1': 'b', 'length': 2 };
21976 assert.deepEqual(_.values(object), ['a', 'b', 2]);
21980 /*--------------------------------------------------------------------------*/
21982 QUnit.module('lodash.without');
21985 QUnit.test('should use strict equality to determine the values to reject', function(assert) {
21988 var object1 = { 'a': 1 },
21989 object2 = { 'b': 2 },
21990 array = [object1, object2];
21992 assert.deepEqual(_.without(array, { 'a': 1 }), array);
21993 assert.deepEqual(_.without(array, object1), [object2]);
21996 QUnit.test('should remove all occurrences of each value from an array', function(assert) {
21999 var array = [1, 2, 3, 1, 2, 3];
22000 assert.deepEqual(_.without(array, 1, 2), [3, 3]);
22004 /*--------------------------------------------------------------------------*/
22006 QUnit.module('lodash.words');
22009 QUnit.test('should treat latin-1 supplementary letters as words', function(assert) {
22012 var expected = lodashStable.map(burredLetters, function(letter) {
22016 var actual = lodashStable.map(burredLetters, function(letter) {
22017 return _.words(letter);
22020 assert.deepEqual(actual, expected);
22023 QUnit.test('should not treat mathematical operators as words', function(assert) {
22026 var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
22027 expected = lodashStable.map(operators, alwaysEmptyArray),
22028 actual = lodashStable.map(operators, _.words);
22030 assert.deepEqual(actual, expected);
22033 QUnit.test('should support a `pattern` argument', function(assert) {
22036 assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
22037 assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
22040 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22043 var strings = lodashStable.map(['a', 'b', 'c'], Object),
22044 actual = lodashStable.map(strings, _.words);
22046 assert.deepEqual(actual, [['a'], ['b'], ['c']]);
22049 QUnit.test('should work with compound words', function(assert) {
22052 assert.deepEqual(_.words('12Feet'), ['12', 'Feet']);
22053 assert.deepEqual(_.words('enable 24h format'), ['enable', '24h', 'format']);
22054 assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
22055 assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
22056 assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
22057 assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
22058 assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
22061 QUnit.test('should work with compound words containing diacritical marks', function(assert) {
22064 assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
22065 assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
22066 assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
22070 /*--------------------------------------------------------------------------*/
22072 QUnit.module('lodash.wrap');
22075 QUnit.test('should create a wrapped function', function(assert) {
22078 var p = _.wrap(_.escape, function(func, text) {
22079 return '<p>' + func(text) + '</p>';
22082 assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
22085 QUnit.test('should provide the correct `wrapper` arguments', function(assert) {
22090 var wrapped = _.wrap(noop, function() {
22091 args || (args = slice.call(arguments));
22095 assert.deepEqual(args, [noop, 1, 2, 3]);
22098 QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
22101 var values = [, null, undefined],
22102 expected = lodashStable.map(values, alwaysA);
22104 var actual = lodashStable.map(values, function(value, index) {
22105 var wrapped = index ? _.wrap('a', value) : _.wrap('a');
22106 return wrapped('b', 'c');
22109 assert.deepEqual(actual, expected);
22112 QUnit.test('should not set a `this` binding', function(assert) {
22115 var p = _.wrap(_.escape, function(func) {
22116 return '<p>' + func(this.text) + '</p>';
22119 var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
22120 assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
22124 /*--------------------------------------------------------------------------*/
22126 QUnit.module('xor methods');
22128 lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
22129 var args = (function() { return arguments; }(1, 2, 3)),
22130 func = _[methodName];
22132 QUnit.test('`_.' + methodName + '` should return the symmetric difference of the given arrays', function(assert) {
22135 var actual = func([1, 2, 5], [2, 3, 5], [3, 4, 5]);
22136 assert.deepEqual(actual, [1, 4, 5]);
22139 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
22142 var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
22143 assert.deepEqual(actual, [1, 4, 5]);
22145 actual = func([1, 1]);
22146 assert.deepEqual(actual, [1]);
22149 QUnit.test('`_.' + methodName + '` should return a new array when a single array is provided', function(assert) {
22153 assert.notStrictEqual(func(array), array);
22156 QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
22160 assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
22163 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
22166 var array = [1, 2];
22167 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
22168 assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
22169 assert.deepEqual(func(array, null, args, null), [3]);
22172 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
22176 var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
22177 assert.ok(wrapped instanceof _);
22184 QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
22188 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
22189 wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
22191 var actual = lodashStable.map(['head', 'last'], function(methodName) {
22192 return wrapped[methodName]();
22195 assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
22203 /*--------------------------------------------------------------------------*/
22205 QUnit.module('lodash.xorBy');
22208 QUnit.test('should accept an `iteratee` argument', function(assert) {
22211 var actual = _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
22212 assert.deepEqual(actual, [1.2, 4.3]);
22214 actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
22215 assert.deepEqual(actual, [{ 'x': 2 }]);
22218 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
22223 _.xorBy([2.1, 1.2], [4.3, 2.4], function() {
22224 args || (args = slice.call(arguments));
22227 assert.deepEqual(args, [4.3]);
22231 /*--------------------------------------------------------------------------*/
22233 QUnit.module('lodash.xorWith');
22236 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
22238 QUnit.test('should work with a `comparator` argument', function(assert) {
22241 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
22242 actual = _.xorWith(objects, others, lodashStable.isEqual);
22244 assert.deepEqual(actual, [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]);
22248 /*--------------------------------------------------------------------------*/
22250 QUnit.module('lodash.zipObject');
22253 var object = { 'barney': 36, 'fred': 40 },
22254 array = [['barney', 36], ['fred', 40]];
22256 QUnit.test('should zip together key/value arrays into an object', function(assert) {
22259 var actual = _.zipObject(['barney', 'fred'], [36, 40]);
22260 assert.deepEqual(actual, object);
22263 QUnit.test('should ignore extra `values`', function(assert) {
22266 assert.deepEqual(_.zipObject(['a'], [1, 2]), { 'a': 1 });
22269 QUnit.test('should assign `undefined` values for extra `keys`', function(assert) {
22272 assert.deepEqual(_.zipObject(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
22275 QUnit.test('should support deep paths', function(assert) {
22278 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
22279 var actual = _.zipObject([path], [1]);
22280 assert.deepEqual(actual, { 'a': { 'b': { 'c': 1 } } });
22284 QUnit.test('should work in a lazy sequence', function(assert) {
22288 var values = lodashStable.range(LARGE_ARRAY_SIZE),
22289 props = lodashStable.map(values, function(value) { return 'key' + value; }),
22290 actual = _(props).zipObject(values).map(square).filter(isEven).take().value();
22292 assert.deepEqual(actual, _.take(_.filter(_.map(_.zipObject(props, values), square), isEven)));
22300 /*--------------------------------------------------------------------------*/
22302 QUnit.module('lodash.zipWith');
22305 QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
22308 var array1 = [1, 2, 3],
22309 array2 = [4, 5, 6],
22310 array3 = [7, 8, 9];
22312 var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
22316 assert.deepEqual(actual, [12, 15, 18]);
22318 var actual = _.zipWith(array1, [], function(a, b) {
22319 return a + (b || 0);
22322 assert.deepEqual(actual, [1, 2, 3]);
22325 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
22330 _.zipWith([1, 2], [3, 4], [5, 6], function() {
22331 args || (args = slice.call(arguments));
22334 assert.deepEqual(args, [1, 3, 5]);
22337 QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
22340 var array1 = [1, 2],
22342 values = [, null, undefined],
22343 expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
22345 var actual = lodashStable.map(values, function(value, index) {
22346 return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
22349 assert.deepEqual(actual, expected);
22353 /*--------------------------------------------------------------------------*/
22355 QUnit.module('lodash.unzip and lodash.zip');
22357 lodashStable.each(['unzip', 'zip'], function(methodName, index) {
22358 var func = _[methodName];
22359 func = _.bind(index ? func.apply : func.call, func, null);
22362 'an empty array': [
22371 [['barney', 'fred'], [36, 40]],
22372 [['barney', 36], ['fred', 40]]
22375 [['barney', 'fred'], [36, 40], [true, false]],
22376 [['barney', 36, true], ['fred', 40, false]]
22380 lodashStable.forOwn(object, function(pair, key) {
22381 QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
22384 var actual = func(pair[0]);
22385 assert.deepEqual(actual, pair[1]);
22386 assert.deepEqual(func(actual), actual.length ? pair[0] : []);
22390 QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
22394 [['barney', 36], ['fred', 40, false]],
22395 [['barney', 'fred'], [36, 40], [undefined, false]]
22398 var actual = func(pair[0]);
22399 assert.ok('0' in actual[2]);
22400 assert.deepEqual(actual, pair[1]);
22402 actual = func(actual);
22403 assert.ok('2' in actual[0]);
22404 assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
22407 QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
22410 var expected = lodashStable.map(falsey, alwaysEmptyArray);
22412 var actual = lodashStable.map(falsey, function(value) {
22413 return func([value, value, value]);
22416 assert.deepEqual(actual, expected);
22419 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
22422 var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
22423 assert.deepEqual(func(array), [[1, 3], [2, 4]]);
22426 QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
22429 var expected = [['barney', 'fred'], [36, 40]];
22430 assert.deepEqual(func(func(func(func(expected)))), expected);
22434 /*--------------------------------------------------------------------------*/
22436 QUnit.module('lodash(...).commit');
22439 QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
22444 wrapped = _(array).push(2).push(3);
22446 assert.deepEqual(array, [1]);
22448 var otherWrapper = wrapped.commit();
22449 assert.ok(otherWrapper instanceof _);
22450 assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
22451 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
22454 skipTest(assert, 4);
22458 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
22462 var wrapped = _([1]).chain().commit().head();
22463 assert.ok(wrapped instanceof _);
22464 assert.strictEqual(wrapped.value(), 1);
22467 skipTest(assert, 2);
22472 /*--------------------------------------------------------------------------*/
22474 QUnit.module('lodash(...).next');
22476 lodashStable.each([true, false], function(implict) {
22477 function chain(value) {
22478 return implict ? _(value) : _.chain(value);
22481 var chainType = 'in an ' + (implict ? 'implict' : 'explict') + ' chain';
22483 QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
22487 var wrapped = chain([1, 2]);
22489 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
22490 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
22491 assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
22494 skipTest(assert, 3);
22498 QUnit.test('should act as an iterable ' + chainType, function(assert) {
22501 if (!isNpm && Symbol && Symbol.iterator) {
22502 var array = [1, 2],
22503 wrapped = chain(array);
22505 assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
22506 assert.deepEqual(_.toArray(wrapped), array);
22509 skipTest(assert, 2);
22513 QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
22516 if (!isNpm && Array.from) {
22517 var hearts = '\ud83d\udc95',
22518 values = [[1], { 'a': 1 }, hearts];
22520 lodashStable.each(values, function(value) {
22521 var wrapped = chain(value);
22522 assert.deepEqual(Array.from(wrapped), _.toArray(value));
22526 skipTest(assert, 3);
22530 QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
22533 if (!isNpm && Symbol && Symbol.iterator) {
22534 var array = [1, 2],
22535 wrapped = chain(array);
22537 assert.deepEqual(_.toArray(wrapped), array);
22538 assert.deepEqual(_.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
22540 var other = wrapped.filter();
22541 assert.deepEqual(_.toArray(other), array, 'reset for new chain segments');
22542 assert.deepEqual(_.toArray(wrapped), [], 'iterator is still exhausted');
22545 skipTest(assert, 4);
22549 QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
22552 if (!isNpm && Symbol && Symbol.iterator) {
22553 var array = lodashStable.range(LARGE_ARRAY_SIZE),
22554 predicate = function(value) { values.push(value); return isEven(value); },
22556 wrapped = chain(array);
22558 assert.deepEqual(_.toArray(wrapped), array);
22560 wrapped = wrapped.filter(predicate);
22561 assert.deepEqual(_.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
22562 assert.deepEqual(values, array, 'memoizes iterator values');
22565 skipTest(assert, 3);
22570 /*--------------------------------------------------------------------------*/
22572 QUnit.module('lodash(...).plant');
22575 QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
22579 var array1 = [5, null, 3, null, 1],
22580 array2 = [10, null, 8, null, 6],
22581 wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
22582 wrapped2 = wrapped1.plant(array2);
22584 assert.deepEqual(wrapped2.value(), [36, 64]);
22585 assert.deepEqual(wrapped1.value(), [1, 9]);
22588 skipTest(assert, 2);
22592 QUnit.test('should clone `chainAll` settings', function(assert) {
22596 var array1 = [2, 4],
22598 wrapped1 = _(array1).chain().map(square),
22599 wrapped2 = wrapped1.plant(array2);
22601 assert.deepEqual(wrapped2.head().value(), 36);
22608 QUnit.test('should reset iterator data on cloned sequences', function(assert) {
22611 if (!isNpm && Symbol && Symbol.iterator) {
22612 var array1 = [2, 4],
22614 wrapped1 = _(array1).map(square);
22616 assert.deepEqual(_.toArray(wrapped1), [4, 16]);
22617 assert.deepEqual(_.toArray(wrapped1), []);
22619 var wrapped2 = wrapped1.plant(array2);
22620 assert.deepEqual(_.toArray(wrapped2), [36, 64]);
22623 skipTest(assert, 3);
22628 /*--------------------------------------------------------------------------*/
22630 QUnit.module('lodash(...).pop');
22633 QUnit.test('should remove elements from the end of `array`', function(assert) {
22637 var array = [1, 2],
22638 wrapped = _(array);
22640 assert.strictEqual(wrapped.pop(), 2);
22641 assert.deepEqual(wrapped.value(), [1]);
22642 assert.strictEqual(wrapped.pop(), 1);
22644 var actual = wrapped.value();
22645 assert.deepEqual(actual, []);
22646 assert.strictEqual(actual, array);
22649 skipTest(assert, 5);
22654 /*--------------------------------------------------------------------------*/
22656 QUnit.module('lodash(...).push');
22659 QUnit.test('should append elements to `array`', function(assert) {
22664 wrapped = _(array).push(2, 3),
22665 actual = wrapped.value();
22667 assert.strictEqual(actual, array);
22668 assert.deepEqual(actual, [1, 2, 3]);
22671 skipTest(assert, 2);
22676 /*--------------------------------------------------------------------------*/
22678 QUnit.module('lodash(...).shift');
22681 QUnit.test('should remove elements from the front of `array`', function(assert) {
22685 var array = [1, 2],
22686 wrapped = _(array);
22688 assert.strictEqual(wrapped.shift(), 1);
22689 assert.deepEqual(wrapped.value(), [2]);
22690 assert.strictEqual(wrapped.shift(), 2);
22692 var actual = wrapped.value();
22693 assert.deepEqual(actual, []);
22694 assert.strictEqual(actual, array);
22697 skipTest(assert, 5);
22702 /*--------------------------------------------------------------------------*/
22704 QUnit.module('lodash(...).sort');
22707 QUnit.test('should return the wrapped sorted `array`', function(assert) {
22711 var array = [3, 1, 2],
22712 wrapped = _(array).sort(),
22713 actual = wrapped.value();
22715 assert.strictEqual(actual, array);
22716 assert.deepEqual(actual, [1, 2, 3]);
22719 skipTest(assert, 2);
22724 /*--------------------------------------------------------------------------*/
22726 QUnit.module('lodash(...).splice');
22729 QUnit.test('should support removing and inserting elements', function(assert) {
22733 var array = [1, 2],
22734 wrapped = _(array);
22736 assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
22737 assert.deepEqual(wrapped.value(), [1, 3]);
22738 assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
22740 var actual = wrapped.value();
22741 assert.deepEqual(actual, []);
22742 assert.strictEqual(actual, array);
22745 skipTest(assert, 5);
22750 /*--------------------------------------------------------------------------*/
22752 QUnit.module('lodash(...).unshift');
22755 QUnit.test('should prepend elements to `array`', function(assert) {
22760 wrapped = _(array).unshift(1, 2),
22761 actual = wrapped.value();
22763 assert.strictEqual(actual, array);
22764 assert.deepEqual(actual, [1, 2, 3]);
22767 skipTest(assert, 2);
22772 /*--------------------------------------------------------------------------*/
22774 QUnit.module('lodash(...).value');
22777 QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
22782 wrapped = _(array).push(2).push(3);
22784 assert.deepEqual(array, [1]);
22785 assert.deepEqual(wrapped.value(), [1, 2, 3]);
22786 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
22787 assert.deepEqual(array, [1, 2, 3, 2, 3]);
22790 skipTest(assert, 4);
22794 QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
22798 var wrapped = _(123);
22799 assert.strictEqual(Number(wrapped), 123);
22806 QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
22809 if (!isNpm && JSON) {
22810 var wrapped = _([1, 2, 3]);
22811 assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
22818 QUnit.test('should be aliased', function(assert) {
22822 var expected = _.prototype.value;
22823 assert.strictEqual(_.prototype.toJSON, expected);
22824 assert.strictEqual(_.prototype.valueOf, expected);
22827 skipTest(assert, 2);
22832 /*--------------------------------------------------------------------------*/
22834 QUnit.module('lodash(...) methods that return the wrapped modified array');
22844 lodashStable.each(funcs, function(methodName) {
22845 QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
22849 var array = [1, 2, 3],
22850 wrapped = _(array),
22851 actual = wrapped[methodName]();
22853 assert.ok(actual instanceof _);
22854 assert.notStrictEqual(actual, wrapped);
22857 skipTest(assert, 2);
22863 /*--------------------------------------------------------------------------*/
22865 QUnit.module('lodash(...) methods that return new wrapped values');
22882 lodashStable.each(funcs, function(methodName) {
22883 QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
22887 var value = methodName == 'split' ? 'abc' : [1, 2, 3],
22888 wrapped = _(value),
22889 actual = wrapped[methodName]();
22891 assert.ok(actual instanceof _);
22892 assert.notStrictEqual(actual, wrapped);
22895 skipTest(assert, 2);
22901 /*--------------------------------------------------------------------------*/
22903 QUnit.module('lodash(...) methods that return unwrapped values');
22989 lodashStable.each(funcs, function(methodName) {
22990 QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
22994 var array = [1, 2, 3],
22995 actual = _(array)[methodName]();
22997 assert.notOk(actual instanceof _);
23004 QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
23008 var array = [1, 2, 3],
23009 actual = _(array).chain()[methodName]();
23011 assert.ok(actual instanceof _);
23020 /*--------------------------------------------------------------------------*/
23022 QUnit.module('"Arrays" category methods');
23025 var args = (function() { return arguments; }(1, null, [3], null, 5)),
23026 sortedArgs = (function() { return arguments; }(1, [3], 5, null, null)),
23027 array = [1, 2, 3, 4, 5, 6];
23029 QUnit.test('should work with `arguments` objects', function(assert) {
23032 function message(methodName) {
23033 return '`_.' + methodName + '` should work with `arguments` objects';
23036 assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
23037 assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
23039 assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
23040 assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
23042 assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
23043 assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
23044 assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
23045 assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
23046 assert.deepEqual(_.dropWhile(args,identity), [ null, [3], null, 5], message('dropWhile'));
23047 assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
23048 assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
23049 assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
23050 assert.deepEqual(_.head(args), 1, message('head'));
23051 assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
23052 assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
23053 assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
23054 assert.deepEqual(_.last(args), 5, message('last'));
23055 assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
23056 assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
23057 assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
23058 assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
23059 assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
23060 assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
23061 assert.deepEqual(_.take(args, 2), [1, null], message('take'));
23062 assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
23063 assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
23064 assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
23065 assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
23066 assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
23067 assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
23070 QUnit.test('should accept falsey primary arguments', function(assert) {
23073 function message(methodName) {
23074 return '`_.' + methodName + '` should accept falsey primary arguments';
23077 assert.deepEqual(_.difference(null, array), [], message('difference'));
23078 assert.deepEqual(_.intersection(null, array), [], message('intersection'));
23079 assert.deepEqual(_.union(null, array), array, message('union'));
23080 assert.deepEqual(_.xor(null, array), array, message('xor'));
23083 QUnit.test('should accept falsey secondary arguments', function(assert) {
23086 function message(methodName) {
23087 return '`_.' + methodName + '` should accept falsey secondary arguments';
23090 assert.deepEqual(_.difference(array, null), array, message('difference'));
23091 assert.deepEqual(_.intersection(array, null), [], message('intersection'));
23092 assert.deepEqual(_.union(array, null), array, message('union'));
23096 /*--------------------------------------------------------------------------*/
23098 QUnit.module('"Strings" category methods');
23101 var stringMethods = [
23124 lodashStable.each(stringMethods, function(methodName) {
23125 var func = _[methodName];
23127 QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
23130 var values = [, null, undefined, ''],
23131 expected = lodashStable.map(values, alwaysEmptyString);
23133 var actual = lodashStable.map(values, function(value, index) {
23134 return index ? func(value) : func();
23137 assert.deepEqual(actual, expected);
23142 /*--------------------------------------------------------------------------*/
23144 QUnit.module('lodash methods');
23147 var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
23148 return lodashStable.startsWith(methodName, '_');
23189 var rejectFalsey = [
23192 ].concat(checkFuncs);
23194 var returnArrays = [
23232 var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
23234 QUnit.test('should accept falsey arguments', function(assert) {
23235 assert.expect(287);
23237 var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
23239 lodashStable.each(acceptFalsey, function(methodName) {
23240 var expected = emptyArrays,
23241 func = _[methodName],
23244 var actual = lodashStable.map(falsey, function(value, index) {
23246 return index ? func(value) : func();
23252 if (methodName == 'noConflict') {
23255 else if (methodName == 'pull' || methodName == 'pullAll') {
23258 if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
23259 assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
23261 assert.ok(pass, '`_.' + methodName + '` accepts falsey arguments');
23264 // Skip tests for missing methods of modularized builds.
23265 lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
23266 if (!_[methodName]) {
23272 QUnit.test('should return an array', function(assert) {
23275 var array = [1, 2, 3];
23277 lodashStable.each(returnArrays, function(methodName) {
23279 func = _[methodName];
23281 switch (methodName) {
23283 actual = func(array, 'toFixed');
23286 actual = func(array, 1);
23289 actual = func(array);
23291 assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
23293 var isPull = methodName == 'pull' || methodName == 'pullAll';
23294 assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the provided array');
23298 QUnit.test('should throw an error for falsey arguments', function(assert) {
23301 lodashStable.each(rejectFalsey, function(methodName) {
23302 var expected = lodashStable.map(falsey, alwaysTrue),
23303 func = _[methodName];
23305 var actual = lodashStable.map(falsey, function(value, index) {
23306 var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
23309 index ? func(value) : func();
23311 pass = !pass && (e instanceof TypeError) &&
23312 (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
23317 assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
23321 QUnit.test('should not set a `this` binding', function(assert) {
23324 lodashStable.each(noBinding, function(methodName) {
23325 var fn = function() { return this.a; },
23326 func = _[methodName],
23327 isNegate = methodName == 'negate',
23328 object = { 'a': 1 },
23329 expected = isNegate ? false : 1;
23331 var wrapper = func(_.bind(fn, object));
23332 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
23334 wrapper = _.bind(func(fn), object);
23335 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
23337 object.wrapper = func(fn);
23338 assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
23342 QUnit.test('should not contain minified method names (test production builds)', function(assert) {
23345 var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
23346 assert.ok(lodashStable.every(_.functions(_), function(methodName) {
23347 return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
23352 /*--------------------------------------------------------------------------*/
23354 QUnit.config.asyncRetries = 10;
23355 QUnit.config.hidepassed = true;
23358 QUnit.config.noglobals = true;