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 funcProto = Function.prototype,
37 objectProto = Object.prototype,
38 numberProto = Number.prototype,
39 stringProto = String.prototype;
41 /** Method and object shortcuts. */
42 var phantom = root.phantom,
43 process = root.process,
44 amd = root.define && define.amd,
45 argv = process && process.argv,
46 defineProperty = Object.defineProperty,
47 document = !phantom && root.document,
48 body = root.document && root.document.body,
49 create = Object.create,
50 fnToString = funcProto.toString,
51 freeze = Object.freeze,
52 getSymbols = Object.getOwnPropertySymbols,
53 identity = function(value) { return value; },
56 objToString = objectProto.toString,
58 push = arrayProto.push,
60 slice = arrayProto.slice;
62 var ArrayBuffer = root.ArrayBuffer,
64 Promise = root.Promise,
68 Uint8Array = root.Uint8Array,
69 WeakMap = root.WeakMap,
70 WeakSet = root.WeakSet;
72 var arrayBuffer = ArrayBuffer ? new ArrayBuffer(2) : undefined,
73 map = Map ? new Map : undefined,
74 promise = Promise ? Promise.resolve(1) : undefined,
75 set = Set ? new Set : undefined,
76 symbol = Symbol ? Symbol('a') : undefined,
77 weakMap = WeakMap ? new WeakMap : undefined,
78 weakSet = WeakSet ? new WeakSet : undefined;
81 var add = function(x, y) { return x + y; },
82 doubled = function(n) { return n * 2; },
83 isEven = function(n) { return n % 2 == 0; },
84 square = function(n) { return n * n; };
86 /** Constant functions. */
87 var alwaysA = function() { return 'a'; },
88 alwaysB = function() { return 'b'; },
89 alwaysC = function() { return 'c'; };
91 var alwaysTrue = function() { return true; },
92 alwaysFalse = function() { return false; };
94 var alwaysNaN = function() { return NaN; },
95 alwaysNull = function() { return null; };
97 var alwaysZero = function() { return 0; },
98 alwaysOne = function() { return 1; },
99 alwaysTwo = function() { return 2; },
100 alwaysThree = function() { return 3; },
101 alwaysFour = function() { return 4; };
103 var alwaysEmptyArray = function() { return []; },
104 alwaysEmptyObject = function() { return {}; },
105 alwaysEmptyString = function() { return ''; };
107 /** List of latin-1 supplementary letters to basic latin letters. */
108 var burredLetters = [
109 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce',
110 '\xcf', '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde',
111 '\xdf', '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee',
112 '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff'
115 /** List of combining diacritical marks. */
117 '\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305', '\u0306', '\u0307', '\u0308', '\u0309', '\u030a', '\u030b', '\u030c', '\u030d', '\u030e', '\u030f',
118 '\u0310', '\u0311', '\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317', '\u0318', '\u0319', '\u031a', '\u031b', '\u031c', '\u031d', '\u031e', '\u031f',
119 '\u0320', '\u0321', '\u0322', '\u0323', '\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329', '\u032a', '\u032b', '\u032c', '\u032d', '\u032e', '\u032f',
120 '\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339', '\u033a', '\u033b', '\u033c', '\u033d', '\u033e', '\u033f',
121 '\u0340', '\u0341', '\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347', '\u0348', '\u0349', '\u034a', '\u034b', '\u034c', '\u034d', '\u034e', '\u034f',
122 '\u0350', '\u0351', '\u0352', '\u0353', '\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359', '\u035a', '\u035b', '\u035c', '\u035d', '\u035e', '\u035f',
123 '\u0360', '\u0361', '\u0362', '\u0363', '\u0364', '\u0365', '\u0366', '\u0367', '\u0368', '\u0369', '\u036a', '\u036b', '\u036c', '\u036d', '\u036e', '\u036f',
124 '\ufe20', '\ufe21', '\ufe22', '\ufe23'
127 /** List of `burredLetters` translated to basic latin letters. */
128 var deburredLetters = [
129 'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
130 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th',
131 'ss', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
132 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y'
135 /** Used to provide falsey values to methods. */
136 var falsey = [, null, undefined, false, 0, NaN, ''];
138 /** Used to specify the emoji style glyph variant of characters. */
139 var emojiVar = '\ufe0f';
141 /** Used to provide empty values to methods. */
142 var empties = [[], {}].concat(falsey.slice(1));
144 /** Used to test error objects. */
155 /** List of fitzpatrick modifiers. */
156 var fitzModifiers = [
164 /** Used to provide primitive values to methods. */
165 var primitives = [null, undefined, false, true, 1, NaN, 'a'];
167 /** Used to check whether methods support typed arrays. */
180 /** Used to check whether methods support array views. */
181 var arrayViews = typedArrays.concat('DataView');
183 /** The file path of the lodash file to test. */
184 var filePath = (function() {
186 result = params || [];
190 result = params = phantom.args || require('system').args;
192 var last = result[result.length - 1];
193 result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js';
197 result = require('fs').realpathSync(result);
201 result = require.resolve(result);
207 /** The `ui` object. */
208 var ui = root.ui || (root.ui = {
209 'buildPath': filePath,
211 'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
212 'isStrict': /\bes\b/.test(filePath),
216 /** The basename of the lodash file to test. */
217 var basename = /[\w.-]+$/.exec(filePath)[0];
219 /** Used to indicate testing a modularized build. */
220 var isModularize = ui.isModularize;
222 /** Detect if testing `npm` modules. */
223 var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
225 /** Detect if running in PhantomJS. */
226 var isPhantom = phantom || (typeof callPhantom == 'function');
228 /** Detect if lodash is in strict mode. */
229 var isStrict = ui.isStrict;
231 /*--------------------------------------------------------------------------*/
233 // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
234 root.msWDfn = undefined;
236 // Exit early if going to run tests in a PhantomJS web page.
237 if (phantom && isModularize) {
238 var page = require('webpage').create();
240 page.onCallback = function(details) {
241 var coverage = details.coverage;
243 var fs = require('fs'),
244 cwd = fs.workingDirectory,
247 fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
249 phantom.exit(details.failed ? 1 : 0);
252 page.onConsoleMessage = function(message) {
253 console.log(message);
256 page.onInitialized = function() {
257 page.evaluate(function() {
258 document.addEventListener('DOMContentLoaded', function() {
259 QUnit.done(function(details) {
260 details.coverage = window.__coverage__;
261 callPhantom(details);
267 page.open(filePath, function(status) {
268 if (status != 'success') {
269 console.log('PhantomJS failed to load page: ' + filePath);
274 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
278 /*--------------------------------------------------------------------------*/
280 /** Used to test Web Workers. */
281 var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
282 (document && document.origin != 'null') && root.Worker;
284 /** Used to test host objects in IE. */
286 var xml = new ActiveXObject('Microsoft.XMLDOM');
289 /** Poison the free variable `root` in Node.js */
291 defineProperty(global.root, 'root', {
292 'configurable': false,
294 'get': function() { throw new ReferenceError; }
298 /** Use a single "load" function. */
299 var load = (!amd && typeof require == 'function')
303 /** The unit testing framework. */
304 var QUnit = root.QUnit || (root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js'));
306 /** Load stable Lodash and QUnit Extras. */
307 var lodashStable = root.lodashStable;
310 lodashStable = load('../node_modules/lodash/lodash.js');
312 console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
315 lodashStable = lodashStable.noConflict();
317 lodashStable = lodashStable.runInContext(root);
319 var QUnitExtras = load('../node_modules/qunit-extras/qunit-extras.js');
321 QUnitExtras.runInContext(root);
324 /** The `lodash` function to test. */
325 var _ = root._ || (root._ = (
327 _ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _,
328 (_.runInContext ? _.runInContext(root) : _)
331 /** Used to detect instrumented istanbul code coverage runs. */
332 var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) {
333 return /^(?:\$\$cov_\d+\$\$)$/.test(key);
336 /** Used to test generator functions. */
337 var generator = lodashStable.attempt(function() {
338 return Function('return function*(){}');
341 /** Used to restore the `_` reference. */
342 var oldDash = root._;
345 * Used to check for problems removing whitespace. For a whitespace reference,
346 * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
348 var whitespace = lodashStable.filter([
349 // Basic whitespace characters.
350 ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
353 '\n', '\r', '\u2028', '\u2029',
355 // Unicode category "Zs" space separators.
356 '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
357 '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
359 function(chr) { return /\s/.exec(chr); })
363 * Creates a custom error object.
367 * @param {string} message The error message.
369 function CustomError(message) {
370 this.name = 'CustomError';
371 this.message = message;
374 CustomError.prototype = lodashStable.create(Error.prototype, {
375 'constructor': CustomError
379 * Removes all own enumerable string keyed properties from a given object.
382 * @param {Object} object The object to empty.
384 function emptyObject(object) {
385 lodashStable.forOwn(object, function(value, key, object) {
391 * Extracts the unwrapped value from its wrapper.
394 * @param {Object} wrapper The wrapper to unwrap.
395 * @returns {*} Returns the unwrapped value.
397 function getUnwrappedValue(wrapper) {
399 actions = wrapper.__actions__,
400 length = actions.length,
401 result = wrapper.__wrapped__;
403 while (++index < length) {
405 action = actions[index];
407 push.apply(args, action.args);
408 result = action.func.apply(action.thisArg, args);
414 * Sets a non-enumerable property value on `object`.
416 * Note: This function is used to avoid a bug in older versions of V8 where
417 * overwriting non-enumerable built-ins makes them enumerable.
418 * See https://code.google.com/p/v8/issues/detail?id=1623
421 * @param {Object} object The object modify.
422 * @param {string} key The name of the property to set.
423 * @param {*} value The property value.
425 function setProperty(object, key, value) {
427 defineProperty(object, key, {
428 'configurable': true,
440 * Skips a given number of tests with a passing result.
443 * @param {Object} assert The QUnit assert object.
444 * @param {number} [count=1] The number of tests to skip.
446 function skipAssert(assert, count) {
447 count || (count = 1);
449 assert.ok(true, 'test skipped');
453 /*--------------------------------------------------------------------------*/
455 // Add bizarro values.
457 if (document || (typeof require != 'function')) {
460 var nativeString = fnToString.call(toString),
461 reToString = /toString/g;
463 function createToString(funcName) {
464 return lodashStable.constant(nativeString.replace(reToString, funcName));
467 // Allow bypassing native checks.
468 setProperty(funcProto, 'toString', function wrapper() {
469 setProperty(funcProto, 'toString', fnToString);
470 var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
471 setProperty(funcProto, 'toString', wrapper);
475 // Add prototype extensions.
476 funcProto._method = noop;
479 setProperty(Object, 'create', (function() {
481 return function(prototype) {
482 if (lodashStable.isObject(prototype)) {
483 object.prototype = prototype;
484 var result = new object;
485 object.prototype = undefined;
491 setProperty(Object, 'getOwnPropertySymbols', undefined);
493 var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
494 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
495 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
499 defineProperty(root, 'Buffer', {
500 'configurable': true,
502 'get': function get() {
503 var caller = get.caller,
504 name = caller ? caller.name : '';
506 if (!(name == 'runInContext' || name.length == 1 || /\b_\.isBuffer\b/.test(caller))) {
513 setProperty(root, 'Map', (function() {
519 setProperty(root, 'Map', Map);
524 setProperty(root.Map, 'toString', createToString('Map'));
526 setProperty(root, 'Promise', noop);
527 setProperty(root, 'Set', noop);
528 setProperty(root, 'Symbol', undefined);
529 setProperty(root, 'WeakMap', noop);
531 // Fake `WinRTError`.
532 setProperty(root, 'WinRTError', Error);
534 // Clear cache so lodash can be reloaded.
535 emptyObject(require.cache);
537 // Load lodash and expose it to the bad extensions/shims.
538 lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
541 // Restore built-in methods.
542 setProperty(Object, 'create', create);
543 setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
544 setProperty(root, 'Buffer', Buffer);
547 Object.getOwnPropertySymbols = getSymbols;
549 delete Object.getOwnPropertySymbols;
552 setProperty(root, 'Map', Map);
557 setProperty(root, 'Promise', Promise);
562 setProperty(root, 'Set', Set);
567 setProperty(root, 'Symbol', Symbol);
572 setProperty(root, 'WeakMap', WeakMap);
576 delete root.WinRTError;
577 delete funcProto._method;
580 // Add other realm values from the `vm` module.
581 lodashStable.attempt(function() {
582 lodashStable.assign(realm, require('vm').runInNewContext([
584 ' var noop = function() {},',
588 " 'ArrayBuffer': root.ArrayBuffer,",
589 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
591 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
592 " 'boolean': Object(false),",
593 " 'date': new Date,",
594 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
595 " 'function': noop,",
596 " 'map': root.Map ? new root.Map : undefined,",
599 " 'number': Object(0),",
600 " 'object': { 'a': 1 },",
601 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
603 " 'set': root.Set ? new root.Set : undefined,",
604 " 'string': Object('a'),",
605 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
606 " 'undefined': undefined,",
607 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
608 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
611 " ['" + arrayViews.join("', '") + "'].forEach(function(type) {",
612 ' var Ctor = root[type]',
613 ' object[type] = Ctor;',
614 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
622 // Add other realm values from an iframe.
623 lodashStable.attempt(function() {
626 var iframe = document.createElement('iframe');
627 iframe.frameBorder = iframe.height = iframe.width = 0;
628 body.appendChild(iframe);
630 var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
635 ' var noop = function() {},',
639 " 'ArrayBuffer': root.ArrayBuffer,",
640 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
642 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
643 " 'boolean': Object(false),",
644 " 'date': new Date,",
645 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
646 " 'function': noop,",
647 " 'map': root.Map ? new root.Map : undefined,",
650 " 'number': Object(0),",
651 " 'object': { 'a': 1 },",
652 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
654 " 'set': root.Set ? new root.Set : undefined,",
655 " 'string': Object('a'),",
656 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
657 " 'undefined': undefined,",
658 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
659 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
662 "_.each(['" + arrayViews.join("', '") + "'], function(type) {",
663 ' var Ctor = root[type];',
664 ' object[type] = Ctor;',
665 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
668 '_.assign(_._realm, object);',
677 lodashStable.attempt(function() {
678 var worker = new Worker('./asset/worker.js?t=' + (+new Date));
679 worker.addEventListener('message', function(e) {
680 _._VERSION = e.data || '';
683 worker.postMessage(ui.buildPath);
686 // Expose internal modules for better code coverage.
687 lodashStable.attempt(function() {
688 var path = require('path'),
689 basePath = path.dirname(filePath);
691 if (isModularize && !(amd || isNpm)) {
696 ], function(relPath) {
697 var func = require(path.join(basePath, relPath)),
698 funcName = path.basename(relPath);
700 _['_' + funcName] = func[funcName] || func['default'] || func;
705 /*--------------------------------------------------------------------------*/
708 console.log('Running lodash tests.');
709 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
712 QUnit.module(basename);
715 QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
719 assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
726 QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
729 if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
730 assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
736 QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
740 assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
747 QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
750 var done = assert.async();
753 var limit = 30000 / QUnit.config.asyncRetries,
756 var attempt = function() {
757 var actual = _._VERSION;
758 if ((new Date - start) < limit && typeof actual != 'string') {
759 setTimeout(attempt, 16);
762 assert.strictEqual(actual, _.VERSION);
774 QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
778 assert.notOk('_method' in lodashBizarro);
785 QUnit.test('should avoid non-native built-ins', function(assert) {
788 function message(lodashMethod, nativeMethod) {
789 return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
797 var object = { 'a': 1 },
798 otherObject = { 'b': 2 },
799 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
803 var actual = lodashBizarro.keysIn(new Foo).sort();
807 var label = message('_.keysIn', 'Object#propertyIsEnumerable');
808 assert.deepEqual(actual, ['a', 'b'], label);
811 var actual = lodashBizarro.isEmpty({});
815 var label = message('_.isEmpty', 'Object#propertyIsEnumerable');
816 assert.strictEqual(actual, true, label);
820 lodashBizarro.difference([object, otherObject], largeArray),
821 lodashBizarro.intersection(largeArray, [object]),
822 lodashBizarro.uniq(largeArray)
827 label = message('_.difference`, `_.intersection`, and `_.uniq', 'Object.create` and `Map');
828 assert.deepEqual(actual, [[otherObject], [object], [object]], label);
835 lodashBizarro.clone(object),
836 lodashBizarro.cloneDeep(object)
841 label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
842 assert.deepEqual(actual, [object, object], label);
845 var symObject = Object(symbol);
847 // Avoid symbol detection in Babel's `typeof` helper.
848 symObject.constructor = Object;
851 Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
852 Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
853 Symbol ? lodashBizarro.toString(symObject) : ''
858 label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
859 assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
862 var map = new lodashBizarro.memoize.Cache;
863 actual = map.set('a', 1).get('a');
867 label = message('_.memoize.Cache', 'Map');
868 assert.deepEqual(actual, 1, label);
871 map = new (Map || Object);
872 if (Symbol && Symbol.iterator) {
873 map[Symbol.iterator] = null;
875 actual = lodashBizarro.toArray(map);
879 label = message('_.toArray', 'Map');
880 assert.deepEqual(actual, [], label);
883 skipAssert(assert, 7);
888 /*--------------------------------------------------------------------------*/
890 QUnit.module('isIndex');
893 var func = _._isIndex;
895 QUnit.test('should return `true` for indexes', function(assert) {
899 var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
900 expected = lodashStable.map(values, alwaysTrue);
902 var actual = lodashStable.map(values, function(args) {
903 return func.apply(undefined, args);
906 assert.deepEqual(actual, expected);
913 QUnit.test('should return `false` for non-indexes', function(assert) {
917 var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
918 expected = lodashStable.map(values, alwaysFalse);
920 var actual = lodashStable.map(values, function(args) {
921 return func.apply(undefined, args);
924 assert.deepEqual(actual, expected);
932 /*--------------------------------------------------------------------------*/
934 QUnit.module('isIterateeCall');
938 func = _._isIterateeCall,
941 QUnit.test('should return `true` for iteratee calls', function(assert) {
948 assert.strictEqual(func(1, 0, array), true);
949 assert.strictEqual(func(1, 'a', object), true);
950 assert.strictEqual(func(1, 'a', new Foo), true);
953 skipAssert(assert, 3);
957 QUnit.test('should return `false` for non-iteratee calls', function(assert) {
961 assert.strictEqual(func(2, 0, array), false);
962 assert.strictEqual(func(1, 1.1, array), false);
963 assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
964 assert.strictEqual(func(1, 'b', object), false);
967 skipAssert(assert, 4);
971 QUnit.test('should work with `NaN` values', function(assert) {
975 assert.strictEqual(func(NaN, 0, [NaN]), true);
976 assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
979 skipAssert(assert, 2);
983 QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
988 var actual = func(1, { 'toString': null }, [1]);
990 var message = e.message;
992 assert.strictEqual(actual, false, message || '');
1000 /*--------------------------------------------------------------------------*/
1002 QUnit.module('lodash constructor');
1005 var values = empties.concat(true, 1, 'a'),
1006 expected = lodashStable.map(values, alwaysTrue);
1008 QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
1012 var actual = lodashStable.map(values, function(value) {
1013 return _(value) instanceof _;
1016 assert.deepEqual(actual, expected);
1023 QUnit.test('should return the given `lodash` instances', function(assert) {
1027 var actual = lodashStable.map(values, function(value) {
1028 var wrapped = _(value);
1029 return _(wrapped) === wrapped;
1032 assert.deepEqual(actual, expected);
1039 QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
1042 if (!isNpm && lodashBizarro) {
1043 var actual = lodashStable.map(values, function(value) {
1044 var wrapped = _(lodashBizarro(value)),
1045 unwrapped = wrapped.value();
1047 return wrapped instanceof _ &&
1048 ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
1051 assert.deepEqual(actual, expected);
1059 /*--------------------------------------------------------------------------*/
1061 QUnit.module('lodash.add');
1064 QUnit.test('should add two numbers', function(assert) {
1067 assert.strictEqual(_.add(6, 4), 10);
1068 assert.strictEqual(_.add(-6, 4), -2);
1069 assert.strictEqual(_.add(-6, -4), -10);
1072 QUnit.test('should not coerce arguments to numbers', function(assert) {
1075 assert.strictEqual(_.add('6', '4'), '64');
1076 assert.strictEqual(_.add('x', 'y'), 'xy');
1080 /*--------------------------------------------------------------------------*/
1082 QUnit.module('lodash.after');
1085 function after(n, times) {
1087 lodashStable.times(times, _.after(n, function() { count++; }));
1091 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1094 assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
1095 assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
1096 assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
1097 assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
1100 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1103 assert.strictEqual(after(NaN, 1), 1);
1106 QUnit.test('should not set a `this` binding', function(assert) {
1109 var after = _.after(1, function(assert) { return ++this.count; }),
1110 object = { 'after': after, 'count': 0 };
1113 assert.strictEqual(object.after(), 2);
1114 assert.strictEqual(object.count, 2);
1118 /*--------------------------------------------------------------------------*/
1120 QUnit.module('lodash.ary');
1123 function fn(a, b, c) {
1124 return slice.call(arguments);
1127 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
1130 var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
1131 assert.deepEqual(actual, [6, 8, 10]);
1133 var capped = _.ary(fn, 2);
1134 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
1137 QUnit.test('should use `func.length` if `n` is not given', function(assert) {
1140 var capped = _.ary(fn);
1141 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
1144 QUnit.test('should treat a negative `n` as `0`', function(assert) {
1147 var capped = _.ary(fn, -1);
1150 var actual = capped('a');
1153 assert.deepEqual(actual, []);
1156 QUnit.test('should coerce `n` to an integer', function(assert) {
1159 var values = ['1', 1.6, 'xyz'],
1160 expected = [['a'], ['a'], []];
1162 var actual = lodashStable.map(values, function(n) {
1163 var capped = _.ary(fn, n);
1164 return capped('a', 'b');
1167 assert.deepEqual(actual, expected);
1170 QUnit.test('should work when given less than the capped number of arguments', function(assert) {
1173 var capped = _.ary(fn, 3);
1174 assert.deepEqual(capped('a'), ['a']);
1177 QUnit.test('should use the existing `ary` if smaller', function(assert) {
1180 var capped = _.ary(_.ary(fn, 1), 2);
1181 assert.deepEqual(capped('a', 'b', 'c'), ['a']);
1184 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
1187 var funcs = lodashStable.map([fn], _.ary),
1188 actual = funcs[0]('a', 'b', 'c');
1190 assert.deepEqual(actual, ['a', 'b', 'c']);
1193 QUnit.test('should work when combined with other methods that use metadata', function(assert) {
1196 var array = ['a', 'b', 'c'],
1197 includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
1199 assert.strictEqual(includes('b')(array, 2), true);
1202 includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
1203 assert.strictEqual(includes('b')(array, 2), true);
1211 /*--------------------------------------------------------------------------*/
1213 QUnit.module('lodash.assignIn');
1216 QUnit.test('should be aliased', function(assert) {
1219 assert.strictEqual(_.extend, _.assignIn);
1223 /*--------------------------------------------------------------------------*/
1225 QUnit.module('lodash.assign and lodash.assignIn');
1227 lodashStable.each(['assign', 'assignIn'], function(methodName) {
1228 var func = _[methodName];
1230 QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
1233 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
1236 QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
1239 var expected = { 'a': 1, 'b': 2, 'c': 3 };
1240 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
1241 assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
1244 QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
1247 var expected = { 'a': 3, 'b': 2, 'c': 1 };
1248 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1251 QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
1254 var expected = { 'a': null, 'b': undefined, 'c': null };
1255 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1258 QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
1264 'configurable': true,
1266 'set': function() { throw new Error; }
1274 'constructor': Object,
1275 'toString': lodashStable.constant('source')
1278 defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
1282 defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
1286 defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
1290 defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
1291 'get': lodashStable.constant(Object)
1295 var actual = func(object, source);
1298 assert.deepEqual(actual, source);
1301 QUnit.test('`_.' + methodName + '` should treat sparse array sources as dense', function(assert) {
1307 assert.deepEqual(func({}, array), { '0': 1, '1': undefined, '2': 3 });
1310 QUnit.test('`_.' + methodName + '` should assign values of prototype objects', function(assert) {
1314 Foo.prototype.a = 1;
1316 assert.deepEqual(func({}, Foo.prototype), { 'a': 1 });
1319 QUnit.test('`_.' + methodName + '` should coerce string sources to objects', function(assert) {
1322 assert.deepEqual(func({}, 'a'), { '0': 'a' });
1326 /*--------------------------------------------------------------------------*/
1328 QUnit.module('lodash.assignInWith');
1331 QUnit.test('should be aliased', function(assert) {
1334 assert.strictEqual(_.extendWith, _.assignInWith);
1338 /*--------------------------------------------------------------------------*/
1340 QUnit.module('lodash.assignWith and lodash.assignInWith');
1342 lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
1343 var func = _[methodName];
1345 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
1348 var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
1349 return a === undefined ? b : a;
1352 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
1355 QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
1358 var expected = { 'a': undefined };
1359 assert.deepEqual(func({}, expected, noop), expected);
1363 /*--------------------------------------------------------------------------*/
1365 QUnit.module('lodash.at');
1368 var args = arguments,
1369 array = ['a', 'b', 'c'],
1370 object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
1372 QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
1375 var actual = _.at(array, [0, 2]);
1376 assert.deepEqual(actual, ['a', 'c']);
1379 QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
1382 var actual = _.at(array, [2, 4, 0]);
1383 assert.deepEqual(actual, ['c', undefined, 'a']);
1386 QUnit.test('should work with non-index keys on array values', function(assert) {
1389 var values = lodashStable.reject(empties, function(value) {
1390 return (value === 0) || lodashStable.isArray(value);
1393 var array = lodashStable.transform(values, function(result, value) {
1397 var expected = lodashStable.map(values, alwaysOne),
1398 actual = _.at(array, values);
1400 assert.deepEqual(actual, expected);
1403 QUnit.test('should return an empty array when no keys are given', function(assert) {
1406 assert.deepEqual(_.at(array), []);
1407 assert.deepEqual(_.at(array, [], []), []);
1410 QUnit.test('should accept multiple key arguments', function(assert) {
1413 var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
1414 assert.deepEqual(actual, ['d', 'a', 'c']);
1417 QUnit.test('should work with a falsey `object` argument when keys are given', function(assert) {
1420 var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
1422 var actual = lodashStable.map(falsey, function(object) {
1424 return _.at(object, 0, 1, 'pop', 'push');
1428 assert.deepEqual(actual, expected);
1431 QUnit.test('should work with an `arguments` object for `object`', function(assert) {
1434 var actual = _.at(args, [2, 0]);
1435 assert.deepEqual(actual, [3, 1]);
1438 QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
1441 var actual = _.at([1, 2, 3, 4, 5], args);
1442 assert.deepEqual(actual, [2, 3, 4]);
1445 QUnit.test('should work with an object for `object`', function(assert) {
1448 var actual = _.at(object, ['a[0].b.c', 'a[1]']);
1449 assert.deepEqual(actual, [3, 4]);
1452 QUnit.test('should pluck inherited property values', function(assert) {
1458 Foo.prototype.b = 2;
1460 var actual = _.at(new Foo, 'b');
1461 assert.deepEqual(actual, [2]);
1464 QUnit.test('should work in a lazy sequence', function(assert) {
1468 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
1471 lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
1472 lodashStable.times(2, function(index) {
1473 var array = index ? largeArray : smallArray,
1474 wrapped = _(array).map(identity).at(paths);
1476 assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
1481 skipAssert(assert, 6);
1485 QUnit.test('should support shortcut fusion', function(assert) {
1489 var array = lodashStable.range(LARGE_ARRAY_SIZE),
1491 iteratee = function(value) { count++; return square(value); },
1492 lastIndex = LARGE_ARRAY_SIZE - 1;
1494 lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
1496 var actual = _(array).map(iteratee).at(n).value(),
1497 expected = index < 2 ? 1 : 0;
1499 assert.strictEqual(count, expected);
1501 expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
1502 assert.deepEqual(actual, expected);
1506 skipAssert(assert, 8);
1510 QUnit.test('work with an object for `object` when chaining', function(assert) {
1514 var paths = ['a[0].b.c', 'a[1]'],
1515 actual = _(object).map(identity).at(paths).value();
1517 assert.deepEqual(actual, _.at(_.map(object, identity), paths));
1519 var indexObject = { '0': 1 };
1520 actual = _(indexObject).at(0).value();
1521 assert.deepEqual(actual, _.at(indexObject, 0));
1524 skipAssert(assert, 2);
1529 /*--------------------------------------------------------------------------*/
1531 QUnit.module('lodash.attempt');
1534 QUnit.test('should return the result of `func`', function(assert) {
1537 assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
1540 QUnit.test('should provide additional arguments to `func`', function(assert) {
1543 var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
1544 assert.deepEqual(actual, [1, 2]);
1547 QUnit.test('should return the caught error', function(assert) {
1550 var expected = lodashStable.map(errors, alwaysTrue);
1552 var actual = lodashStable.map(errors, function(error) {
1553 return _.attempt(function() { throw error; }) === error;
1556 assert.deepEqual(actual, expected);
1559 QUnit.test('should coerce errors to error objects', function(assert) {
1562 var actual = _.attempt(function() { throw 'x'; });
1563 assert.ok(lodashStable.isEqual(actual, Error('x')));
1566 QUnit.test('should preserve custom errors', function(assert) {
1569 var actual = _.attempt(function() { throw new CustomError('x'); });
1570 assert.ok(actual instanceof CustomError);
1573 QUnit.test('should work with an error object from another realm', function(assert) {
1577 var expected = lodashStable.map(realm.errors, alwaysTrue);
1579 var actual = lodashStable.map(realm.errors, function(error) {
1580 return _.attempt(function() { throw error; }) === error;
1583 assert.deepEqual(actual, expected);
1590 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1594 assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
1601 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1605 assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
1613 /*--------------------------------------------------------------------------*/
1615 QUnit.module('lodash.before');
1618 function before(n, times) {
1620 lodashStable.times(times, _.before(n, function() { count++; }));
1624 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1627 assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
1628 assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
1629 assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
1630 assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
1633 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1636 assert.strictEqual(before(NaN, 1), 0);
1639 QUnit.test('should not set a `this` binding', function(assert) {
1642 var before = _.before(2, function(assert) { return ++this.count; }),
1643 object = { 'before': before, 'count': 0 };
1646 assert.strictEqual(object.before(), 1);
1647 assert.strictEqual(object.count, 1);
1651 /*--------------------------------------------------------------------------*/
1653 QUnit.module('lodash.bind');
1657 var result = [this];
1658 push.apply(result, arguments);
1662 QUnit.test('should bind a function to an object', function(assert) {
1666 bound = _.bind(fn, object);
1668 assert.deepEqual(bound('a'), [object, 'a']);
1671 QUnit.test('should accept a falsey `thisArg` argument', function(assert) {
1674 var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
1675 expected = lodashStable.map(values, function(value) { return [value]; });
1677 var actual = lodashStable.map(values, function(value) {
1679 var bound = _.bind(fn, value);
1684 assert.ok(lodashStable.every(actual, function(value, index) {
1685 return lodashStable.isEqual(value, expected[index]);
1689 QUnit.test('should bind a function to nullish values', function(assert) {
1692 var bound = _.bind(fn, null),
1693 actual = bound('a');
1695 assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
1696 assert.strictEqual(actual[1], 'a');
1698 lodashStable.times(2, function(index) {
1699 bound = index ? _.bind(fn, undefined) : _.bind(fn);
1700 actual = bound('b');
1702 assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
1703 assert.strictEqual(actual[1], 'b');
1707 QUnit.test('should partially apply arguments ', function(assert) {
1711 bound = _.bind(fn, object, 'a');
1713 assert.deepEqual(bound(), [object, 'a']);
1715 bound = _.bind(fn, object, 'a');
1716 assert.deepEqual(bound('b'), [object, 'a', 'b']);
1718 bound = _.bind(fn, object, 'a', 'b');
1719 assert.deepEqual(bound(), [object, 'a', 'b']);
1720 assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
1723 QUnit.test('should support placeholders', function(assert) {
1727 ph = _.bind.placeholder,
1728 bound = _.bind(fn, object, ph, 'b', ph);
1730 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
1731 assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
1732 assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
1733 assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
1736 QUnit.test('should use `_.placeholder` when set', function(assert) {
1739 if (!isModularize) {
1740 var _ph = _.placeholder = {},
1741 ph = _.bind.placeholder,
1743 bound = _.bind(fn, object, _ph, 'b', ph);
1745 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']);
1746 delete _.placeholder;
1753 QUnit.test('should create a function with a `length` of `0`', function(assert) {
1756 var fn = function(a, b, c) {},
1757 bound = _.bind(fn, {});
1759 assert.strictEqual(bound.length, 0);
1761 bound = _.bind(fn, {}, 1);
1762 assert.strictEqual(bound.length, 0);
1765 QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
1772 var bound = _.bind(Foo, { 'a': 1 }),
1773 newBound = new bound;
1775 assert.strictEqual(bound().a, 1);
1776 assert.strictEqual(newBound.a, undefined);
1777 assert.ok(newBound instanceof Foo);
1780 QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
1789 var thisArg = { 'a': 1 },
1790 boundFoo = _.bind(Foo, thisArg),
1791 boundBar = _.bind(Bar, thisArg),
1793 expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
1795 var actual = lodashStable.times(count, function(index) {
1798 case 0: return [new boundFoo().a, new boundBar().a];
1799 case 1: return [new boundFoo(1).a, new boundBar(1).a];
1800 case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
1801 case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
1802 case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
1803 case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
1804 case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
1805 case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
1806 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];
1811 assert.deepEqual(actual, expected);
1814 QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
1817 function Foo(value) {
1818 return value && object;
1821 var bound = _.bind(Foo),
1824 assert.ok(new bound instanceof Foo);
1825 assert.strictEqual(new bound(true), object);
1828 QUnit.test('should append array arguments to partially applied arguments', function(assert) {
1832 bound = _.bind(fn, object, 'a');
1834 assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
1837 QUnit.test('should not rebind functions', function(assert) {
1844 var bound1 = _.bind(fn, object1),
1845 bound2 = _.bind(bound1, object2, 'a'),
1846 bound3 = _.bind(bound1, object3, 'b');
1848 assert.deepEqual(bound1(), [object1]);
1849 assert.deepEqual(bound2(), [object1, 'a']);
1850 assert.deepEqual(bound3(), [object1, 'b']);
1853 QUnit.test('should not error when instantiating bound built-ins', function(assert) {
1856 var Ctor = _.bind(Date, null),
1857 expected = new Date(2012, 4, 23, 0, 0, 0, 0);
1860 var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
1863 assert.deepEqual(actual, expected);
1865 Ctor = _.bind(Date, null, 2012, 4, 23);
1868 actual = new Ctor(0, 0, 0, 0);
1871 assert.deepEqual(actual, expected);
1874 QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
1877 var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
1879 if (typeof createCtor == 'function') {
1880 var bound = _.bind(createCtor()),
1882 expected = lodashStable.times(count, alwaysTrue);
1884 var actual = lodashStable.times(count, function(index) {
1887 case 0: return !!(new bound);
1888 case 1: return !!(new bound(1));
1889 case 2: return !!(new bound(1, 2));
1890 case 3: return !!(new bound(1, 2, 3));
1891 case 4: return !!(new bound(1, 2, 3, 4));
1892 case 5: return !!(new bound(1, 2, 3, 4, 5));
1893 case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
1894 case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
1899 assert.deepEqual(actual, expected);
1906 QUnit.test('should return a wrapped value when chaining', function(assert) {
1911 bound = _(fn).bind({}, 'a', 'b');
1913 assert.ok(bound instanceof _);
1915 var actual = bound.value()('c');
1916 assert.deepEqual(actual, [object, 'a', 'b', 'c']);
1919 skipAssert(assert, 2);
1924 /*--------------------------------------------------------------------------*/
1926 QUnit.module('lodash.bindAll');
1929 var args = arguments;
1938 '-0': function() { return this._n0; },
1939 '0': function() { return this._p0; },
1940 'a': function() { return this._a; },
1941 'b': function() { return this._b; },
1942 'c': function() { return this._c; },
1943 'd': function() { return this._d; }
1946 QUnit.test('should accept individual method names', function(assert) {
1949 var object = lodashStable.cloneDeep(source);
1950 _.bindAll(object, 'a', 'b');
1952 var actual = lodashStable.map(['a', 'b', 'c'], function(key) {
1953 return object[key].call({});
1956 assert.deepEqual(actual, [1, 2, undefined]);
1959 QUnit.test('should accept arrays of method names', function(assert) {
1962 var object = lodashStable.cloneDeep(source);
1963 _.bindAll(object, ['a', 'b'], ['c']);
1965 var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(key) {
1966 return object[key].call({});
1969 assert.deepEqual(actual, [1, 2, 3, undefined]);
1972 QUnit.test('should preserve the sign of `0`', function(assert) {
1975 var props = [-0, Object(-0), 0, Object(0)];
1977 var actual = lodashStable.map(props, function(key) {
1978 var object = lodashStable.cloneDeep(source);
1979 _.bindAll(object, key);
1980 return object[lodashStable.toString(key)].call({});
1983 assert.deepEqual(actual, [-2, -2, -1, -1]);
1986 QUnit.test('should work with an array `object` argument', function(assert) {
1989 var array = ['push', 'pop'];
1991 assert.strictEqual(array.pop, arrayProto.pop);
1994 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
1997 var object = lodashStable.cloneDeep(source);
1998 _.bindAll(object, args);
2000 var actual = lodashStable.map(args, function(key) {
2001 return object[key].call({});
2004 assert.deepEqual(actual, [1]);
2008 /*--------------------------------------------------------------------------*/
2010 QUnit.module('lodash.bindKey');
2013 QUnit.test('should work when the target function is overwritten', function(assert) {
2018 'greet': function(greeting) {
2019 return this.user + ' says: ' + greeting;
2023 var bound = _.bindKey(object, 'greet', 'hi');
2024 assert.strictEqual(bound(), 'fred says: hi');
2026 object.greet = function(greeting) {
2027 return this.user + ' says: ' + greeting + '!';
2030 assert.strictEqual(bound(), 'fred says: hi!');
2033 QUnit.test('should support placeholders', function(assert) {
2038 return slice.call(arguments);
2042 var ph = _.bindKey.placeholder,
2043 bound = _.bindKey(object, 'fn', ph, 'b', ph);
2045 assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
2046 assert.deepEqual(bound('a'), ['a', 'b', undefined]);
2047 assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
2048 assert.deepEqual(bound(), [undefined, 'b', undefined]);
2051 QUnit.test('should use `_.placeholder` when set', function(assert) {
2054 if (!isModularize) {
2057 return slice.call(arguments);
2061 var _ph = _.placeholder = {},
2062 ph = _.bindKey.placeholder,
2063 bound = _.bindKey(object, 'fn', _ph, 'b', ph);
2065 assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']);
2066 delete _.placeholder;
2073 QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
2076 function Foo(value) {
2077 return value && object;
2080 var object = { 'Foo': Foo },
2081 bound = _.bindKey(object, 'Foo');
2083 assert.ok(new bound instanceof Foo);
2084 assert.strictEqual(new bound(true), object);
2088 /*--------------------------------------------------------------------------*/
2090 QUnit.module('case methods');
2092 lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
2093 var methodName = caseName + 'Case',
2094 func = _[methodName];
2097 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
2098 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__'
2101 var converted = (function() {
2103 case 'camel': return 'fooBar';
2104 case 'kebab': return 'foo-bar';
2105 case 'lower': return 'foo bar';
2106 case 'snake': return 'foo_bar';
2107 case 'start': return 'Foo Bar';
2108 case 'upper': return 'FOO BAR';
2112 QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
2115 var actual = lodashStable.map(strings, function(string) {
2116 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2117 return func(string) === expected;
2120 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
2123 QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
2126 var actual = lodashStable.map(strings, function(string) {
2127 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2128 return func(func(string)) === expected;
2131 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
2134 QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
2137 var actual = lodashStable.map(burredLetters, function(burred, index) {
2138 var letter = deburredLetters[index];
2139 if (caseName == 'start') {
2140 letter = lodashStable.capitalize(letter);
2141 } else if (caseName == 'upper') {
2142 letter = letter.toUpperCase();
2144 letter = letter.toLowerCase();
2146 return func(burred) === letter;
2149 assert.deepEqual(actual, lodashStable.map(burredLetters, alwaysTrue));
2152 QUnit.test('`_.' + methodName + '` should remove contraction apostrophes', function(assert) {
2155 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
2157 lodashStable.each(["'", '\u2019'], function(apos) {
2158 var actual = lodashStable.map(postfixes, function(postfix) {
2159 return func('a b' + apos + postfix + ' c');
2162 var expected = lodashStable.map(postfixes, function(postfix) {
2164 case 'camel': return 'aB' + postfix + 'C';
2165 case 'kebab': return 'a-b' + postfix + '-c';
2166 case 'lower': return 'a b' + postfix + ' c';
2167 case 'snake': return 'a_b' + postfix + '_c';
2168 case 'start': return 'A B' + postfix + ' C';
2169 case 'upper': return 'A B' + postfix.toUpperCase() + ' C';
2173 assert.deepEqual(actual, expected);
2177 QUnit.test('`_.' + methodName + '` should remove latin-1 mathematical operators', function(assert) {
2180 var actual = lodashStable.map(['\xd7', '\xf7'], func);
2181 assert.deepEqual(actual, ['', '']);
2184 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
2187 var string = 'foo bar';
2188 assert.strictEqual(func(Object(string)), converted);
2189 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
2192 QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
2196 assert.strictEqual(_('foo bar')[methodName](), converted);
2203 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
2207 assert.ok(_('foo bar').chain()[methodName]() instanceof _);
2216 QUnit.test('should get the original value after cycling through all case methods', function(assert) {
2219 var funcs = [_.camelCase, _.kebabCase, _.lowerCase, _.snakeCase, _.startCase, _.lowerCase, _.camelCase];
2221 var actual = lodashStable.reduce(funcs, function(result, func) {
2222 return func(result);
2223 }, 'enable 6h format');
2225 assert.strictEqual(actual, 'enable6HFormat');
2229 /*--------------------------------------------------------------------------*/
2231 QUnit.module('lodash.camelCase');
2234 QUnit.test('should work with numbers', function(assert) {
2237 assert.strictEqual(_.camelCase('12 feet'), '12Feet');
2238 assert.strictEqual(_.camelCase('enable 6h format'), 'enable6HFormat');
2239 assert.strictEqual(_.camelCase('enable 24H format'), 'enable24HFormat');
2240 assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
2241 assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
2242 assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
2245 QUnit.test('should handle acronyms', function(assert) {
2248 lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
2249 assert.strictEqual(_.camelCase(string), 'safeHtml');
2252 lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
2253 assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
2256 lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
2257 assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
2262 /*--------------------------------------------------------------------------*/
2264 QUnit.module('lodash.capitalize');
2267 QUnit.test('should capitalize the first character of a string', function(assert) {
2270 assert.strictEqual(_.capitalize('fred'), 'Fred');
2271 assert.strictEqual(_.capitalize('Fred'), 'Fred');
2272 assert.strictEqual(_.capitalize(' fred'), ' fred');
2276 /*--------------------------------------------------------------------------*/
2278 QUnit.module('lodash.castArray');
2281 QUnit.test('should wrap non-array items in an array', function(assert) {
2284 var values = falsey.concat(true, 1, 'a', { 'a': 1 }),
2285 expected = lodashStable.map(values, function(value) { return [value]; }),
2286 actual = lodashStable.map(values, _.castArray);
2288 assert.deepEqual(actual, expected);
2291 QUnit.test('should return array values by reference', function(assert) {
2295 assert.strictEqual(_.castArray(array), array);
2298 QUnit.test('should return an empty array when no arguments are given', function(assert) {
2301 assert.deepEqual(_.castArray(), []);
2305 /*--------------------------------------------------------------------------*/
2307 QUnit.module('lodash.chain');
2310 QUnit.test('should return a wrapped value', function(assert) {
2314 var actual = _.chain({ 'a': 0 });
2315 assert.ok(actual instanceof _);
2322 QUnit.test('should return existing wrapped values', function(assert) {
2326 var wrapped = _({ 'a': 0 });
2327 assert.strictEqual(_.chain(wrapped), wrapped);
2328 assert.strictEqual(wrapped.chain(), wrapped);
2331 skipAssert(assert, 2);
2335 QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
2339 var array = ['c', 'b', 'a'];
2341 assert.ok(_.chain(array).head() instanceof _);
2342 assert.ok(_(array).chain().head() instanceof _);
2344 assert.ok(_.chain(array).isArray() instanceof _);
2345 assert.ok(_(array).chain().isArray() instanceof _);
2347 assert.ok(_.chain(array).sortBy().head() instanceof _);
2348 assert.ok(_(array).chain().sortBy().head() instanceof _);
2351 skipAssert(assert, 6);
2355 QUnit.test('should chain multiple methods', function(assert) {
2359 lodashStable.times(2, function(index) {
2360 var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
2361 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 },
2362 wrapped = index ? _(array).chain() : _.chain(array);
2364 var actual = wrapped
2366 .map(function(value) { return value.split(''); })
2368 .reduce(function(object, chr) {
2369 object[chr] || (object[chr] = 0);
2375 assert.deepEqual(actual, expected);
2377 array = [1, 2, 3, 4, 5, 6];
2378 wrapped = index ? _(array).chain() : _.chain(array);
2381 .filter(function(n) { return n % 2 != 0; })
2382 .reject(function(n) { return n % 3 == 0; })
2383 .sortBy(function(n) { return -n; })
2386 assert.deepEqual(actual, [5, 1]);
2389 wrapped = index ? _(array).chain() : _.chain(array);
2394 .tap(function(value) { value.pop(); })
2398 assert.deepEqual(actual, [25, 16, 9, 4]);
2402 skipAssert(assert, 6);
2407 /*--------------------------------------------------------------------------*/
2409 QUnit.module('lodash.chunk');
2412 var array = [0, 1, 2, 3, 4, 5];
2414 QUnit.test('should return chunked arrays', function(assert) {
2417 var actual = _.chunk(array, 3);
2418 assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
2421 QUnit.test('should return the last chunk as remaining elements', function(assert) {
2424 var actual = _.chunk(array, 4);
2425 assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
2428 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
2431 var expected = lodashStable.map(falsey, function(value) {
2432 return value === undefined ? [[0], [1], [2], [3], [4], [5]] : [];
2435 var actual = lodashStable.map(falsey, function(size, index) {
2436 return index ? _.chunk(array, size) : _.chunk(array);
2439 assert.deepEqual(actual, expected);
2442 QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
2445 var values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity),
2446 expected = lodashStable.map(values, alwaysEmptyArray);
2448 var actual = lodashStable.map(values, function(n) {
2449 return _.chunk(array, n);
2452 assert.deepEqual(actual, expected);
2455 QUnit.test('should coerce `size` to an integer', function(assert) {
2458 assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
2461 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
2464 var actual = lodashStable.map([[1, 2], [3, 4]], _.chunk);
2465 assert.deepEqual(actual, [[[1], [2]], [[3], [4]]]);
2469 /*--------------------------------------------------------------------------*/
2471 QUnit.module('lodash.clamp');
2474 QUnit.test('should work with a `max` argument', function(assert) {
2477 assert.strictEqual(_.clamp(5, 3), 3);
2478 assert.strictEqual(_.clamp(1, 3), 1);
2481 QUnit.test('should clamp negative numbers', function(assert) {
2484 assert.strictEqual(_.clamp(-10, -5, 5), -5);
2485 assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
2486 assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
2489 QUnit.test('should clamp positive numbers', function(assert) {
2492 assert.strictEqual(_.clamp(10, -5, 5), 5);
2493 assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
2494 assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
2497 QUnit.test('should not alter negative numbers in range', function(assert) {
2500 assert.strictEqual(_.clamp(-4, -5, 5), -4);
2501 assert.strictEqual(_.clamp(-5, -5, 5), -5);
2502 assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
2505 QUnit.test('should not alter positive numbers in range', function(assert) {
2508 assert.strictEqual(_.clamp(4, -5, 5), 4);
2509 assert.strictEqual(_.clamp(5, -5, 5), 5);
2510 assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
2513 QUnit.test('should not alter `0` in range', function(assert) {
2516 assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
2519 QUnit.test('should clamp to `0`', function(assert) {
2522 assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
2525 QUnit.test('should not alter `-0` in range', function(assert) {
2528 assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
2531 QUnit.test('should clamp to `-0`', function(assert) {
2534 assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
2537 QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
2540 assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
2543 QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
2546 assert.deepEqual(_.clamp(1, -5, NaN), 0);
2547 assert.deepEqual(_.clamp(-1, NaN, 5), 0);
2551 /*--------------------------------------------------------------------------*/
2553 QUnit.module('clone methods');
2559 Foo.prototype.b = 1;
2560 Foo.c = function() {};
2573 '`arguments` objects': arguments,
2574 'arrays': ['a', ''],
2575 'array-like-objects': { '0': 'a', '1': '', 'length': 3 },
2577 'boolean objects': Object(false),
2578 'date objects': new Date,
2579 'Foo instances': new Foo,
2580 'objects': { 'a': 0, 'b': 1, 'c': 2 },
2581 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
2582 'objects from another document': realm.object || {},
2584 'null values': null,
2586 'number objects': Object(0),
2590 'string objects': Object('a'),
2591 'undefined values': undefined
2594 objects.arrays.length = 3;
2597 'DOM elements': body,
2599 'generators': generator
2602 lodashStable.each(errors, function(error) {
2603 uncloneable[error.name + 's'] = error;
2606 QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
2609 var array = [{ 'a': 0 }, { 'b': 1 }],
2610 actual = _.clone(array);
2612 assert.deepEqual(actual, array);
2613 assert.ok(actual !== array && actual[0] === array[0]);
2616 QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
2620 'foo': { 'b': { 'c': { 'd': {} } } },
2624 object.foo.b.c.d = object;
2625 object.bar.b = object.foo.b;
2627 var actual = _.cloneDeep(object);
2628 assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
2631 QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
2635 lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
2636 cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
2639 var clone = _.cloneDeep(cyclical),
2640 actual = clone['v' + LARGE_ARRAY_SIZE][0];
2642 assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
2643 assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
2646 QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
2650 keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || {}];
2652 var pairs = lodashStable.map(keys, function(key, index) {
2653 var lastIndex = keys.length - 1;
2654 return [key, keys[lastIndex - index]];
2657 _.cloneDeepWith({ 'a': 1 }, function() {
2658 if (arguments.length > 1) {
2659 Stack || (Stack = _.last(arguments).constructor);
2663 var stacks = [new Stack(pairs), new Stack(pairs)];
2665 lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
2666 stacks[1].set({}, {});
2669 lodashStable.each(stacks, function(stack) {
2670 lodashStable.each(keys, function(key, index) {
2671 var value = pairs[index][1];
2673 assert.deepEqual(stack.get(key), value);
2674 assert.strictEqual(stack.has(key), true);
2675 assert.strictEqual(stack['delete'](key), true);
2676 assert.strictEqual(stack.has(key), false);
2677 assert.strictEqual(stack.get(key), undefined);
2678 assert.strictEqual(stack['delete'](key), false);
2679 assert.strictEqual(stack.set(key, value), stack);
2680 assert.strictEqual(stack.has(key), true);
2683 assert.strictEqual(stack.clear(), undefined);
2684 assert.ok(lodashStable.every(keys, function(key) {
2685 return !stack.has(key);
2690 lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
2691 var func = _[methodName],
2692 isDeep = methodName == 'cloneDeep';
2694 lodashStable.forOwn(objects, function(object, key) {
2695 QUnit.test('`_.' + methodName + '` should clone ' + key, function(assert) {
2698 var isEqual = (key == 'maps' || key == 'sets') ? _.isEqual : lodashStable.isEqual,
2699 actual = func(object);
2701 assert.ok(isEqual(actual, object));
2703 if (lodashStable.isObject(object)) {
2704 assert.notStrictEqual(actual, object);
2706 assert.strictEqual(actual, object);
2711 QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
2715 var actual = func(arrayBuffer);
2716 assert.strictEqual(actual.byteLength, arrayBuffer.byteLength);
2717 assert.notStrictEqual(actual, arrayBuffer);
2720 skipAssert(assert, 2);
2724 QUnit.test('`_.' + methodName + '` should clone buffers', function(assert) {
2728 var buffer = new Buffer([1, 2]),
2729 actual = func(buffer);
2731 assert.strictEqual(actual.byteLength, buffer.byteLength);
2732 assert.strictEqual(actual.inspect(), buffer.inspect());
2733 assert.notStrictEqual(actual, buffer);
2736 assert.strictEqual(actual[0], isDeep ? 2 : 1);
2739 skipAssert(assert, 4);
2743 QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
2746 var array = /c/.exec('abcde'),
2747 actual = func(array);
2749 assert.strictEqual(actual.index, 2);
2750 assert.strictEqual(actual.input, 'abcde');
2753 QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
2757 regexp.exec('abcde');
2759 assert.strictEqual(func(regexp).lastIndex, 3);
2762 QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
2765 var values = lodashStable.map([false, true, 1, 'a'], function(value) {
2766 var object = Object(value);
2771 var expected = lodashStable.map(values, alwaysTrue);
2773 var actual = lodashStable.map(values, function(value) {
2774 return func(value).a === 1;
2777 assert.deepEqual(actual, expected);
2780 QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
2783 var actual = func(Foo.prototype);
2785 assert.notOk(actual instanceof Foo);
2786 assert.deepEqual(actual, { 'b': 1 });
2789 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone', function(assert) {
2792 assert.ok(func(new Foo) instanceof Foo);
2795 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone even when the `constructor` is incorrect', function(assert) {
2798 Foo.prototype.constructor = Object;
2799 assert.ok(func(new Foo) instanceof Foo);
2800 Foo.prototype.constructor = Foo;
2803 QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
2806 Foo.prototype.constructor = null;
2807 assert.notOk(func(new Foo) instanceof Foo);
2808 Foo.prototype.constructor = Foo;
2811 QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
2815 'constructor': objectProto.constructor,
2816 'hasOwnProperty': objectProto.hasOwnProperty,
2817 'isPrototypeOf': objectProto.isPrototypeOf,
2818 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
2819 'toLocaleString': objectProto.toLocaleString,
2820 'toString': objectProto.toString,
2821 'valueOf': objectProto.valueOf
2824 var actual = func(object);
2826 assert.deepEqual(actual, object);
2827 assert.notStrictEqual(actual, object);
2830 QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
2834 this[symbol] = { 'c': 1 };
2838 var symbol2 = Symbol('b');
2839 Foo.prototype[symbol2] = 2;
2841 var object = { 'a': { 'b': new Foo } };
2842 object[symbol] = { 'b': 1 };
2844 var actual = func(object);
2846 assert.deepEqual(getSymbols(actual.a.b), [symbol]);
2849 assert.deepEqual(actual[symbol], object[symbol]);
2850 assert.deepEqual(actual.a.b[symbol], object.a.b[symbol]);
2853 assert.strictEqual(actual[symbol], object[symbol]);
2854 assert.strictEqual(actual.a, object.a);
2858 skipAssert(assert, 3);
2862 QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
2866 assert.strictEqual(func(symbol), symbol);
2868 var object = Object(symbol),
2869 actual = func(object);
2871 assert.strictEqual(typeof actual, 'object');
2872 assert.strictEqual(typeof actual.valueOf(), 'symbol');
2873 assert.notStrictEqual(actual, object);
2876 skipAssert(assert, 4);
2880 QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
2884 assert.strictEqual(func(symbol), symbol);
2891 QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
2895 var element = document.createElement('div');
2898 assert.deepEqual(func(element), {});
2900 assert.ok(false, e.message);
2908 QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
2913 var objects = lodashStable.transform(_, function(result, value, key) {
2914 if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) &&
2915 !lodashStable.isArguments(value) && !lodashStable.isElement(value) &&
2916 !lodashStable.isFunction(value)) {
2917 props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
2922 var expected = lodashStable.map(objects, alwaysTrue);
2924 var actual = lodashStable.map(objects, function(object) {
2925 var Ctor = object.constructor,
2926 result = func(object);
2928 return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
2931 assert.deepEqual(actual, expected, props.join(', '));
2934 QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
2937 var expected = [{ 'a': [0] }, { 'b': [1] }],
2938 actual = lodashStable.map(expected, func);
2940 assert.deepEqual(actual, expected);
2943 assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
2945 assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
2949 QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
2953 var object = objects.objects,
2954 actual = _(object)[methodName]();
2956 assert.deepEqual(actual, object);
2957 assert.notStrictEqual(actual, object);
2960 skipAssert(assert, 2);
2964 lodashStable.each(arrayViews, function(type) {
2965 QUnit.test('`_.' + methodName + '` should clone ' + type + ' values', function(assert) {
2968 var Ctor = root[type];
2970 lodashStable.times(2, function(index) {
2972 var buffer = new ArrayBuffer(24),
2973 view = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
2974 actual = func(view);
2976 assert.deepEqual(actual, view);
2977 assert.notStrictEqual(actual, view);
2978 assert.strictEqual(actual.buffer === view.buffer, !isDeep);
2979 assert.strictEqual(actual.byteOffset, view.byteOffset);
2980 assert.strictEqual(actual.length, view.length);
2983 skipAssert(assert, 5);
2989 lodashStable.forOwn(uncloneable, function(value, key) {
2990 QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
2994 var object = { 'a': value, 'b': { 'c': value } },
2995 actual = func(object),
2996 expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
2998 assert.deepEqual(actual, object);
2999 assert.notStrictEqual(actual, object);
3000 assert.deepEqual(func(value), expected);
3003 skipAssert(assert, 3);
3009 lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
3010 var func = _[methodName],
3011 isDeep = methodName == 'cloneDeepWith';
3013 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
3019 func(object, function() {
3020 var length = arguments.length,
3021 args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
3023 argsList.push(args);
3026 assert.deepEqual(argsList, isDeep ? [[object], [1, 'a', object]] : [[object]]);
3029 QUnit.test('`_.' + methodName + '` should handle cloning if `customizer` returns `undefined`', function(assert) {
3032 var actual = func({ 'a': { 'b': 'c' } }, noop);
3033 assert.deepEqual(actual, { 'a': { 'b': 'c' } });
3036 lodashStable.forOwn(uncloneable, function(value, key) {
3037 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
3040 var customizer = function(value) {
3041 return lodashStable.isPlainObject(value) ? undefined : value;
3044 var actual = func(value, customizer);
3046 assert.deepEqual(actual, value);
3047 assert.strictEqual(actual, value);
3049 var object = { 'a': value, 'b': { 'c': value } };
3050 actual = func(object, customizer);
3052 assert.deepEqual(actual, object);
3053 assert.notStrictEqual(actual, object);
3059 /*--------------------------------------------------------------------------*/
3061 QUnit.module('lodash.compact');
3064 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
3066 QUnit.test('should filter falsey values', function(assert) {
3069 var array = ['0', '1', '2'];
3070 assert.deepEqual(_.compact(falsey.concat(array)), array);
3073 QUnit.test('should work when in-between lazy operators', function(assert) {
3077 var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
3078 assert.deepEqual(actual, []);
3080 actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
3081 assert.deepEqual(actual, [true, 1, 'a']);
3084 skipAssert(assert, 2);
3088 QUnit.test('should work in a lazy sequence', function(assert) {
3092 var actual = _(largeArray).slice(1).compact().reverse().take().value();
3093 assert.deepEqual(actual, _.take(_.compact(_.slice(largeArray, 1)).reverse()));
3100 QUnit.test('should work in a lazy sequence with a custom `_.iteratee`', function(assert) {
3103 if (!isModularize) {
3104 var iteratee = _.iteratee,
3107 _.iteratee = identity;
3110 var actual = _(largeArray).slice(1).compact().value();
3111 pass = lodashStable.isEqual(actual, _.compact(_.slice(largeArray, 1)));
3112 } catch (e) {console.log(e);}
3115 _.iteratee = iteratee;
3123 /*--------------------------------------------------------------------------*/
3125 QUnit.module('lodash.concat');
3128 QUnit.test('should shallow clone `array`', function(assert) {
3131 var array = [1, 2, 3],
3132 actual = _.concat(array);
3134 assert.deepEqual(actual, array);
3135 assert.notStrictEqual(actual, array);
3138 QUnit.test('should concat arrays and values', function(assert) {
3142 actual = _.concat(array, 2, [3], [[4]]);
3144 assert.deepEqual(actual, [1, 2, 3, [4]]);
3145 assert.deepEqual(array, [1]);
3148 QUnit.test('should cast non-array `array` values to arrays', function(assert) {
3151 var values = [, null, undefined, false, true, 1, NaN, 'a'];
3153 var expected = lodashStable.map(values, function(value, index) {
3154 return index ? [value] : [];
3157 var actual = lodashStable.map(values, function(value, index) {
3158 return index ? _.concat(value) : _.concat();
3161 assert.deepEqual(actual, expected);
3163 expected = lodashStable.map(values, function(value) {
3164 return [value, 2, [3]];
3167 actual = lodashStable.map(values, function(value) {
3168 return _.concat(value, [2], [[3]]);
3171 assert.deepEqual(actual, expected);
3174 QUnit.test('should treat sparse arrays as dense', function(assert) {
3178 actual = _.concat(Array(1), Array(1));
3180 expected.push(undefined, undefined);
3182 assert.ok('0'in actual);
3183 assert.ok('1' in actual);
3184 assert.deepEqual(actual, expected);
3187 QUnit.test('should return a new wrapped array', function(assert) {
3192 wrapped = _(array).concat([2, 3]),
3193 actual = wrapped.value();
3195 assert.deepEqual(array, [1]);
3196 assert.deepEqual(actual, [1, 2, 3]);
3199 skipAssert(assert, 2);
3204 /*--------------------------------------------------------------------------*/
3206 QUnit.module('lodash.cond');
3209 QUnit.test('should create a conditional function', function(assert) {
3213 [lodashStable.matches({ 'a': 1 }), alwaysA],
3214 [lodashStable.matchesProperty('b', 1), alwaysB],
3215 [lodashStable.property('c'), alwaysC]
3218 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3219 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3220 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3223 QUnit.test('should provide arguments to functions', function(assert) {
3228 expected = ['a', 'b', 'c'];
3230 var cond = _.cond([[
3231 function() { args1 || (args1 = slice.call(arguments)); return true; },
3232 function() { args2 || (args2 = slice.call(arguments)); }
3235 cond('a', 'b', 'c');
3237 assert.deepEqual(args1, expected);
3238 assert.deepEqual(args2, expected);
3241 QUnit.test('should work with predicate shorthands', function(assert) {
3245 [{ 'a': 1 }, alwaysA],
3246 [['b', 1], alwaysB],
3250 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3251 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3252 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3255 QUnit.test('should return `undefined` when no condition is met', function(assert) {
3258 var cond = _.cond([[alwaysFalse, alwaysA]]);
3259 assert.strictEqual(cond({ 'a': 1 }), undefined);
3262 QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
3265 lodashStable.each([false, true], function(value) {
3266 assert.raises(function() { _.cond([[alwaysTrue, value]])(); }, TypeError);
3270 QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
3274 [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
3277 var object = { 'cond': cond, 'a': 1, 'b': 2 };
3278 assert.strictEqual(object.cond('a', 'b'), 2);
3282 /*--------------------------------------------------------------------------*/
3284 QUnit.module('lodash.conforms');
3293 QUnit.test('should create a function that checks if a given object conforms to `source`', function(assert) {
3296 var conforms = _.conforms({
3297 'b': function(value) { return value > 4; }
3300 var actual = lodashStable.filter(objects, conforms);
3301 assert.deepEqual(actual, [objects[0], objects[2]]);
3303 conforms = _.conforms({
3304 'b': function(value) { return value > 8; },
3305 'a': function(value) { return value > 1; }
3308 actual = lodashStable.filter(objects, conforms);
3309 assert.deepEqual(actual, [objects[2]]);
3312 QUnit.test('should not match by inherited `source` properties', function(assert) {
3316 this.a = function(value) {
3320 Foo.prototype.b = function(value) {
3324 var conforms = _.conforms(new Foo),
3325 actual = lodashStable.filter(objects, conforms);
3327 assert.deepEqual(actual, [objects[1], objects[2]]);
3330 QUnit.test('should not invoke `source` predicates for missing `object` properties', function(assert) {
3335 var conforms = _.conforms({
3336 'a': function() { count++; return true; }
3339 assert.strictEqual(conforms({}), false);
3340 assert.strictEqual(count, 0);
3343 QUnit.test('should work with a function for `object`', function(assert) {
3352 var conforms = _.conforms({
3353 'a': function(value) { return value > 1; }
3356 assert.strictEqual(conforms(Foo), false);
3357 assert.strictEqual(conforms(Bar), true);
3360 QUnit.test('should work with a function for `source`', function(assert) {
3364 Foo.a = function(value) { return value > 1; };
3366 var objects = [{ 'a': 1 }, { 'a': 2 }],
3367 actual = lodashStable.filter(objects, _.conforms(Foo));
3369 assert.deepEqual(actual, [objects[1]]);
3372 QUnit.test('should work with a non-plain `object`', function(assert) {
3378 Foo.prototype.b = 2;
3380 var conforms = _.conforms({
3381 'b': function(value) { return value > 1; }
3384 assert.strictEqual(conforms(new Foo), true);
3387 QUnit.test('should return `false` when `object` is nullish', function(assert) {
3390 var values = [, null, undefined],
3391 expected = lodashStable.map(values, alwaysFalse);
3393 var conforms = _.conforms({
3394 'a': function(value) { return value > 1; }
3397 var actual = lodashStable.map(values, function(value, index) {
3399 return index ? conforms(value) : conforms();
3403 assert.deepEqual(actual, expected);
3406 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
3409 var values = [, null, undefined],
3410 expected = lodashStable.map(values, alwaysTrue),
3411 conforms = _.conforms({});
3413 var actual = lodashStable.map(values, function(value, index) {
3415 return index ? conforms(value) : conforms();
3419 assert.deepEqual(actual, expected);
3422 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
3425 var object = { 'a': 1 },
3426 expected = lodashStable.map(empties, alwaysTrue);
3428 var actual = lodashStable.map(empties, function(value) {
3429 var conforms = _.conforms(value);
3430 return conforms(object);
3433 assert.deepEqual(actual, expected);
3436 QUnit.test('should not change behavior if `source` is modified', function(assert) {
3440 'a': function(value) { return value > 1; }
3443 var object = { 'a': 2 },
3444 conforms = _.conforms(source);
3446 assert.strictEqual(conforms(object), true);
3448 source.a = function(value) { return value < 2; };
3449 assert.strictEqual(conforms(object), true);
3453 /*--------------------------------------------------------------------------*/
3455 QUnit.module('lodash.constant');
3458 QUnit.test('should create a function that returns `value`', function(assert) {
3461 var object = { 'a': 1 },
3462 values = Array(2).concat(empties, true, 1, 'a'),
3463 constant = _.constant(object),
3464 expected = lodashStable.map(values, function() { return true; });
3466 var actual = lodashStable.map(values, function(value, index) {
3468 var result = constant();
3469 } else if (index == 1) {
3470 result = constant.call({});
3472 result = constant(value);
3474 return result === object;
3477 assert.deepEqual(actual, expected);
3480 QUnit.test('should work with falsey values', function(assert) {
3483 var expected = lodashStable.map(falsey, function() { return true; });
3485 var actual = lodashStable.map(falsey, function(value, index) {
3486 var constant = index ? _.constant(value) : _.constant(),
3487 result = constant();
3489 return (result === value) || (result !== result && value !== value);
3492 assert.deepEqual(actual, expected);
3495 QUnit.test('should return a wrapped value when chaining', function(assert) {
3499 var wrapped = _(true).constant();
3500 assert.ok(wrapped instanceof _);
3508 /*--------------------------------------------------------------------------*/
3510 QUnit.module('lodash.countBy');
3513 var array = [6.1, 4.2, 6.3];
3515 QUnit.test('should transform keys by `iteratee`', function(assert) {
3518 var actual = _.countBy(array, Math.floor);
3519 assert.deepEqual(actual, { '4': 1, '6': 2 });
3522 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
3525 var array = [4, 6, 6],
3526 values = [, null, undefined],
3527 expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
3529 var actual = lodashStable.map(values, function(value, index) {
3530 return index ? _.countBy(array, value) : _.countBy(array);
3533 assert.deepEqual(actual, expected);
3536 QUnit.test('should work with `_.property` shorthands', function(assert) {
3539 var actual = _.countBy(['one', 'two', 'three'], 'length');
3540 assert.deepEqual(actual, { '3': 2, '5': 1 });
3543 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
3546 var actual = _.countBy(array, function(n) {
3547 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
3550 assert.deepEqual(actual.constructor, 1);
3551 assert.deepEqual(actual.hasOwnProperty, 2);
3554 QUnit.test('should work with a number for `iteratee`', function(assert) {
3563 assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
3564 assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
3567 QUnit.test('should work with an object for `collection`', function(assert) {
3570 var actual = _.countBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
3571 assert.deepEqual(actual, { '4': 1, '6': 2 });
3574 QUnit.test('should work in a lazy sequence', function(assert) {
3578 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
3579 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
3580 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
3583 var actual = _(array).countBy().map(square).filter(isEven).take().value();
3585 assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
3593 /*--------------------------------------------------------------------------*/
3595 QUnit.module('lodash.create');
3607 QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
3610 Circle.prototype = _.create(Shape.prototype);
3611 Circle.prototype.constructor = Circle;
3613 var actual = new Circle;
3615 assert.ok(actual instanceof Circle);
3616 assert.ok(actual instanceof Shape);
3617 assert.notStrictEqual(Circle.prototype, Shape.prototype);
3620 QUnit.test('should assign `properties` to the created object', function(assert) {
3623 var expected = { 'constructor': Circle, 'radius': 0 };
3624 Circle.prototype = _.create(Shape.prototype, expected);
3626 var actual = new Circle;
3628 assert.ok(actual instanceof Circle);
3629 assert.ok(actual instanceof Shape);
3630 assert.deepEqual(Circle.prototype, expected);
3633 QUnit.test('should assign own properties', function(assert) {
3640 Foo.prototype.b = 2;
3642 assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
3645 QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
3651 var object = _.create(new Foo, { 'a': 1 });
3652 assert.deepEqual(lodashStable.keys(object), ['a']);
3655 QUnit.test('should accept a falsey `prototype` argument', function(assert) {
3658 var expected = lodashStable.map(falsey, alwaysEmptyObject);
3660 var actual = lodashStable.map(falsey, function(prototype, index) {
3661 return index ? _.create(prototype) : _.create();
3664 assert.deepEqual(actual, expected);
3667 QUnit.test('should ignore primitive `prototype` arguments and use an empty object instead', function(assert) {
3670 var expected = lodashStable.map(primitives, alwaysTrue);
3672 var actual = lodashStable.map(primitives, function(value, index) {
3673 return lodashStable.isPlainObject(index ? _.create(value) : _.create());
3676 assert.deepEqual(actual, expected);
3679 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
3682 var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
3683 expected = lodashStable.map(array, alwaysTrue),
3684 objects = lodashStable.map(array, _.create);
3686 var actual = lodashStable.map(objects, function(object) {
3687 return object.a === 1 && !_.keys(object).length;
3690 assert.deepEqual(actual, expected);
3694 /*--------------------------------------------------------------------------*/
3696 QUnit.module('lodash.curry');
3699 function fn(a, b, c, d) {
3700 return slice.call(arguments);
3703 QUnit.test('should curry based on the number of arguments given', function(assert) {
3706 var curried = _.curry(fn),
3707 expected = [1, 2, 3, 4];
3709 assert.deepEqual(curried(1)(2)(3)(4), expected);
3710 assert.deepEqual(curried(1, 2)(3, 4), expected);
3711 assert.deepEqual(curried(1, 2, 3, 4), expected);
3714 QUnit.test('should allow specifying `arity`', function(assert) {
3717 var curried = _.curry(fn, 3),
3718 expected = [1, 2, 3];
3720 assert.deepEqual(curried(1)(2, 3), expected);
3721 assert.deepEqual(curried(1, 2)(3), expected);
3722 assert.deepEqual(curried(1, 2, 3), expected);
3725 QUnit.test('should coerce `arity` to an integer', function(assert) {
3728 var values = ['0', 0.6, 'xyz'],
3729 expected = lodashStable.map(values, alwaysEmptyArray);
3731 var actual = lodashStable.map(values, function(arity) {
3732 return _.curry(fn, arity)();
3735 assert.deepEqual(actual, expected);
3736 assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
3739 QUnit.test('should support placeholders', function(assert) {
3742 var curried = _.curry(fn),
3743 ph = curried.placeholder;
3745 assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
3746 assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
3747 assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
3748 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
3751 QUnit.test('should persist placeholders', function(assert) {
3754 var curried = _.curry(fn),
3755 ph = curried.placeholder,
3756 actual = curried(ph, ph, ph, 'd')('a')(ph)('b')('c');
3758 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3761 QUnit.test('should use `_.placeholder` when set', function(assert) {
3764 if (!isModularize) {
3765 var curried = _.curry(fn),
3766 _ph = _.placeholder = {},
3767 ph = curried.placeholder;
3769 assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]);
3770 delete _.placeholder;
3777 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3780 var curried = _.curry(fn, 3);
3781 assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
3782 assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
3783 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3786 QUnit.test('should create a function with a `length` of `0`', function(assert) {
3789 lodashStable.times(2, function(index) {
3790 var curried = index ? _.curry(fn, 4) : _.curry(fn);
3791 assert.strictEqual(curried.length, 0);
3792 assert.strictEqual(curried(1).length, 0);
3793 assert.strictEqual(curried(1, 2).length, 0);
3797 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3800 function Foo(value) {
3801 return value && object;
3804 var curried = _.curry(Foo),
3807 assert.ok(new curried(false) instanceof Foo);
3808 assert.strictEqual(new curried(true), object);
3811 QUnit.test('should not set a `this` binding', function(assert) {
3814 var fn = function(a, b, c) {
3815 var value = this || {};
3816 return [value[a], value[b], value[c]];
3819 var object = { 'a': 1, 'b': 2, 'c': 3 },
3820 expected = [1, 2, 3];
3822 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
3823 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
3824 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3826 assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
3827 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
3828 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
3830 object.curried = _.curry(fn);
3831 assert.deepEqual(object.curried('a')('b')('c'), Array(3));
3832 assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
3833 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3836 QUnit.test('should work with partialed methods', function(assert) {
3839 var curried = _.curry(fn),
3840 expected = [1, 2, 3, 4];
3842 var a = _.partial(curried, 1),
3843 b = _.bind(a, null, 2),
3844 c = _.partialRight(b, 4),
3845 d = _.partialRight(b(3), 4);
3847 assert.deepEqual(c(3), expected);
3848 assert.deepEqual(d(), expected);
3852 /*--------------------------------------------------------------------------*/
3854 QUnit.module('lodash.curryRight');
3857 function fn(a, b, c, d) {
3858 return slice.call(arguments);
3861 QUnit.test('should curry based on the number of arguments given', function(assert) {
3864 var curried = _.curryRight(fn),
3865 expected = [1, 2, 3, 4];
3867 assert.deepEqual(curried(4)(3)(2)(1), expected);
3868 assert.deepEqual(curried(3, 4)(1, 2), expected);
3869 assert.deepEqual(curried(1, 2, 3, 4), expected);
3872 QUnit.test('should allow specifying `arity`', function(assert) {
3875 var curried = _.curryRight(fn, 3),
3876 expected = [1, 2, 3];
3878 assert.deepEqual(curried(3)(1, 2), expected);
3879 assert.deepEqual(curried(2, 3)(1), expected);
3880 assert.deepEqual(curried(1, 2, 3), expected);
3883 QUnit.test('should coerce `arity` to an integer', function(assert) {
3886 var values = ['0', 0.6, 'xyz'],
3887 expected = lodashStable.map(values, alwaysEmptyArray);
3889 var actual = lodashStable.map(values, function(arity) {
3890 return _.curryRight(fn, arity)();
3893 assert.deepEqual(actual, expected);
3894 assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
3897 QUnit.test('should support placeholders', function(assert) {
3900 var curried = _.curryRight(fn),
3901 expected = [1, 2, 3, 4],
3902 ph = curried.placeholder;
3904 assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
3905 assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
3906 assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
3907 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
3910 QUnit.test('should persist placeholders', function(assert) {
3913 var curried = _.curryRight(fn),
3914 ph = curried.placeholder,
3915 actual = curried('a', ph, ph, ph)('b')(ph)('c')('d');
3917 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3920 QUnit.test('should use `_.placeholder` when set', function(assert) {
3923 if (!isModularize) {
3924 var curried = _.curryRight(fn),
3925 _ph = _.placeholder = {},
3926 ph = curried.placeholder;
3928 assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]);
3929 delete _.placeholder;
3936 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3939 var curried = _.curryRight(fn, 3);
3940 assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
3941 assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
3942 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3945 QUnit.test('should create a function with a `length` of `0`', function(assert) {
3948 lodashStable.times(2, function(index) {
3949 var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
3950 assert.strictEqual(curried.length, 0);
3951 assert.strictEqual(curried(4).length, 0);
3952 assert.strictEqual(curried(3, 4).length, 0);
3956 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3959 function Foo(value) {
3960 return value && object;
3963 var curried = _.curryRight(Foo),
3966 assert.ok(new curried(false) instanceof Foo);
3967 assert.strictEqual(new curried(true), object);
3970 QUnit.test('should not set a `this` binding', function(assert) {
3973 var fn = function(a, b, c) {
3974 var value = this || {};
3975 return [value[a], value[b], value[c]];
3978 var object = { 'a': 1, 'b': 2, 'c': 3 },
3979 expected = [1, 2, 3];
3981 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
3982 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
3983 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3985 assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
3986 assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
3987 assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
3989 object.curried = _.curryRight(fn);
3990 assert.deepEqual(object.curried('c')('b')('a'), Array(3));
3991 assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
3992 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3995 QUnit.test('should work with partialed methods', function(assert) {
3998 var curried = _.curryRight(fn),
3999 expected = [1, 2, 3, 4];
4001 var a = _.partialRight(curried, 4),
4002 b = _.partialRight(a, 3),
4003 c = _.bind(b, null, 1),
4004 d = _.partial(b(2), 1);
4006 assert.deepEqual(c(2), expected);
4007 assert.deepEqual(d(), expected);
4011 /*--------------------------------------------------------------------------*/
4013 QUnit.module('curry methods');
4015 lodashStable.each(['curry', 'curryRight'], function(methodName) {
4016 var func = _[methodName],
4017 fn = function(a, b) { return slice.call(arguments); },
4018 isCurry = methodName == 'curry';
4020 QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
4023 function run(a, b) {
4027 var curried = func(run);
4030 var actual = curried(1)(2);
4033 assert.strictEqual(actual, 3);
4036 QUnit.test('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function(assert) {
4039 var curried = _.curry(function hasOwnProperty(a, b, c) {
4043 var expected = [1, 2, 3];
4045 assert.deepEqual(curried(1)(2)(3), expected);
4048 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
4051 var array = [fn, fn, fn],
4052 object = { 'a': fn, 'b': fn, 'c': fn };
4054 lodashStable.each([array, object], function(collection) {
4055 var curries = lodashStable.map(collection, func),
4056 expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
4058 var actual = lodashStable.map(curries, function(curried) {
4059 return curried('a')('b');
4062 assert.deepEqual(actual, expected);
4067 /*--------------------------------------------------------------------------*/
4069 QUnit.module('lodash.debounce');
4072 QUnit.test('should debounce a function', function(assert) {
4075 var done = assert.async();
4079 var debounced = _.debounce(function(value) {
4084 var actual = [debounced(0), debounced(1), debounced(2)];
4085 assert.deepEqual(actual, [undefined, undefined, undefined]);
4086 assert.strictEqual(callCount, 0);
4088 setTimeout(function() {
4089 assert.strictEqual(callCount, 1);
4091 var actual = [debounced(3), debounced(4), debounced(5)];
4092 assert.deepEqual(actual, [2, 2, 2]);
4093 assert.strictEqual(callCount, 1);
4096 setTimeout(function() {
4097 assert.strictEqual(callCount, 2);
4102 QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
4105 var done = assert.async();
4107 var debounced = _.debounce(identity, 32);
4110 setTimeout(function() {
4111 assert.notEqual(debounced('y'), 'y');
4114 setTimeout(function() {
4115 assert.notEqual(debounced('z'), 'z');
4120 QUnit.test('should not immediately call `func` when `wait` is `0`', function(assert) {
4123 var done = assert.async();
4126 debounced = _.debounce(function() { ++callCount; }, 0);
4130 assert.strictEqual(callCount, 0);
4132 setTimeout(function() {
4133 assert.strictEqual(callCount, 1);
4138 QUnit.test('should apply default options', function(assert) {
4141 var done = assert.async();
4144 debounced = _.debounce(function() { callCount++; }, 32, {});
4147 assert.strictEqual(callCount, 0);
4149 setTimeout(function() {
4150 assert.strictEqual(callCount, 1);
4155 QUnit.test('should support a `leading` option', function(assert) {
4158 var done = assert.async();
4160 var callCounts = [0, 0];
4162 var withLeading = _.debounce(function() {
4164 }, 32, { 'leading': true });
4166 var withLeadingAndTrailing = _.debounce(function() {
4168 }, 32, { 'leading': true });
4171 assert.strictEqual(callCounts[0], 1);
4173 withLeadingAndTrailing();
4174 withLeadingAndTrailing();
4175 assert.strictEqual(callCounts[1], 1);
4177 setTimeout(function() {
4178 assert.deepEqual(callCounts, [1, 2]);
4181 assert.strictEqual(callCounts[0], 2);
4187 QUnit.test('subsequent leading debounced calls return the last `func` result', function(assert) {
4190 var done = assert.async();
4192 var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
4193 result = [debounced('x'), debounced('y')];
4195 assert.deepEqual(result, ['x', 'x']);
4197 setTimeout(function() {
4198 var result = [debounced('a'), debounced('b')];
4199 assert.deepEqual(result, ['a', 'a']);
4204 QUnit.test('should support a `trailing` option', function(assert) {
4207 var done = assert.async();
4212 var withTrailing = _.debounce(function() {
4214 }, 32, { 'trailing': true });
4216 var withoutTrailing = _.debounce(function() {
4218 }, 32, { 'trailing': false });
4221 assert.strictEqual(withCount, 0);
4224 assert.strictEqual(withoutCount, 0);
4226 setTimeout(function() {
4227 assert.strictEqual(withCount, 1);
4228 assert.strictEqual(withoutCount, 0);
4233 QUnit.test('should support a `maxWait` option', function(assert) {
4236 var done = assert.async();
4240 var debounced = _.debounce(function(value) {
4243 }, 32, { 'maxWait': 64 });
4247 assert.strictEqual(callCount, 0);
4249 setTimeout(function() {
4250 assert.strictEqual(callCount, 1);
4253 assert.strictEqual(callCount, 1);
4256 setTimeout(function() {
4257 assert.strictEqual(callCount, 2);
4262 QUnit.test('should support `maxWait` in a tight loop', function(assert) {
4265 var done = assert.async();
4267 var limit = (argv || isPhantom) ? 1000 : 320,
4271 var withMaxWait = _.debounce(function() {
4273 }, 64, { 'maxWait': 128 });
4275 var withoutMaxWait = _.debounce(function() {
4279 var start = +new Date;
4280 while ((new Date - start) < limit) {
4284 var actual = [Boolean(withoutCount), Boolean(withCount)];
4285 setTimeout(function() {
4286 assert.deepEqual(actual, [false, true]);
4291 QUnit.test('should queue a trailing call for subsequent debounced calls after `maxWait`', function(assert) {
4294 var done = assert.async();
4298 var debounced = _.debounce(function() {
4300 }, 64, { 'maxWait': 64 });
4304 lodashStable.times(20, function(index) {
4305 setTimeout(debounced, 54 + index);
4308 setTimeout(function() {
4309 assert.strictEqual(callCount, 2);
4314 QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
4317 var done = assert.async();
4321 var debounced = _.debounce(function() {
4323 }, 32, { 'maxWait': 64 });
4327 setTimeout(function() {
4329 assert.strictEqual(callCount, 1);
4332 setTimeout(function() {
4333 assert.strictEqual(callCount, 2);
4338 QUnit.test('should invoke the trailing call with the correct arguments and `this` binding', function(assert) {
4341 var done = assert.async();
4347 var debounced = _.debounce(function(value) {
4349 push.apply(actual, arguments);
4350 return ++callCount != 2;
4351 }, 32, { 'leading': true, 'maxWait': 64 });
4354 if (!debounced.call(object, 'a')) {
4358 setTimeout(function() {
4359 assert.strictEqual(callCount, 2);
4360 assert.deepEqual(actual, [object, 'a']);
4366 /*--------------------------------------------------------------------------*/
4368 QUnit.module('lodash.deburr');
4371 QUnit.test('should convert latin-1 supplementary letters to basic latin', function(assert) {
4374 var actual = lodashStable.map(burredLetters, _.deburr);
4375 assert.deepEqual(actual, deburredLetters);
4378 QUnit.test('should not deburr latin-1 mathematical operators', function(assert) {
4381 var operators = ['\xd7', '\xf7'],
4382 actual = lodashStable.map(operators, _.deburr);
4384 assert.deepEqual(actual, operators);
4387 QUnit.test('should deburr combining diacritical marks', function(assert) {
4390 var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
4392 var actual = lodashStable.map(comboMarks, function(chr) {
4393 return _.deburr('e' + chr + 'i');
4396 assert.deepEqual(actual, expected);
4400 /*--------------------------------------------------------------------------*/
4402 QUnit.module('lodash.defaults');
4405 QUnit.test('should assign source properties if missing on `object`', function(assert) {
4408 assert.deepEqual(_.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 }), { 'a': 1, 'b': 2 });
4411 QUnit.test('should accept multiple sources', function(assert) {
4414 var expected = { 'a': 1, 'b': 2, 'c': 3 };
4415 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 }), expected);
4416 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 }), expected);
4419 QUnit.test('should not overwrite `null` values', function(assert) {
4422 var actual = _.defaults({ 'a': null }, { 'a': 1 });
4423 assert.strictEqual(actual.a, null);
4426 QUnit.test('should overwrite `undefined` values', function(assert) {
4429 var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
4430 assert.strictEqual(actual.a, 1);
4433 QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
4437 'constructor': objectProto.constructor,
4438 'hasOwnProperty': objectProto.hasOwnProperty,
4439 'isPrototypeOf': objectProto.isPrototypeOf,
4440 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
4441 'toLocaleString': objectProto.toLocaleString,
4442 'toString': objectProto.toString,
4443 'valueOf': objectProto.valueOf
4448 'hasOwnProperty': 2,
4450 'propertyIsEnumerable': 4,
4451 'toLocaleString': 5,
4456 assert.deepEqual(_.defaults({}, source), source);
4457 assert.deepEqual(_.defaults({}, object, source), object);
4461 /*--------------------------------------------------------------------------*/
4463 QUnit.module('lodash.defaultsDeep');
4466 QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
4469 var object = { 'a': { 'b': 2 }, 'd': 4 },
4470 source = { 'a': { 'b': 1, 'c': 3 }, 'e': 5 },
4471 expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
4473 assert.deepEqual(_.defaultsDeep(object, source), expected);
4476 QUnit.test('should accept multiple sources', function(assert) {
4479 var source1 = { 'a': { 'b': 3 } },
4480 source2 = { 'a': { 'c': 3 } },
4481 source3 = { 'a': { 'b': 3, 'c': 3 } },
4482 source4 = { 'a': { 'c': 4 } },
4483 expected = { 'a': { 'b': 2, 'c': 3 } };
4485 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
4486 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
4489 QUnit.test('should not overwrite `null` values', function(assert) {
4492 var object = { 'a': { 'b': null } },
4493 source = { 'a': { 'b': 2 } },
4494 actual = _.defaultsDeep(object, source);
4496 assert.strictEqual(actual.a.b, null);
4499 QUnit.test('should not overwrite regexp values', function(assert) {
4502 var object = { 'a': { 'b': /x/ } },
4503 source = { 'a': { 'b': /y/ } },
4504 actual = _.defaultsDeep(object, source);
4506 assert.deepEqual(actual.a.b, /x/);
4509 QUnit.test('should not convert function properties to objects', function(assert) {
4512 var actual = _.defaultsDeep({}, { 'a': noop });
4513 assert.strictEqual(actual.a, noop);
4515 actual = _.defaultsDeep({}, { 'a': { 'b': noop } });
4516 assert.strictEqual(actual.a.b, noop);
4519 QUnit.test('should overwrite `undefined` values', function(assert) {
4522 var object = { 'a': { 'b': undefined } },
4523 source = { 'a': { 'b': 2 } },
4524 actual = _.defaultsDeep(object, source);
4526 assert.strictEqual(actual.a.b, 2);
4529 QUnit.test('should merge sources containing circular references', function(assert) {
4533 'foo': { 'b': { 'c': { 'd': {} } } },
4538 'foo': { 'b': { 'c': { 'd': {} } } },
4542 object.foo.b.c.d = object;
4543 source.foo.b.c.d = source;
4544 source.bar.b = source.foo.b;
4546 var actual = _.defaultsDeep(object, source);
4548 assert.strictEqual(actual.bar.b, actual.foo.b);
4549 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
4552 QUnit.test('should not modify sources', function(assert) {
4555 var source1 = { 'a': 1, 'b': { 'c': 2 } },
4556 source2 = { 'b': { 'c': 3, 'd': 3 } },
4557 actual = _.defaultsDeep({}, source1, source2);
4559 assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
4560 assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
4561 assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
4564 QUnit.test('should not attempt a merge of a string into an array', function(assert) {
4567 var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
4568 assert.deepEqual(actual, { 'a': ['abc'] });
4572 /*--------------------------------------------------------------------------*/
4574 QUnit.module('lodash.defer');
4577 QUnit.test('should defer `func` execution', function(assert) {
4580 var done = assert.async();
4583 _.defer(function() { pass = true; });
4585 setTimeout(function() {
4591 QUnit.test('should provide additional arguments to `func`', function(assert) {
4594 var done = assert.async();
4598 _.defer(function() {
4599 args = slice.call(arguments);
4602 setTimeout(function() {
4603 assert.deepEqual(args, [1, 2]);
4608 QUnit.test('should be cancelable', function(assert) {
4611 var done = assert.async();
4615 var timerId = _.defer(function() {
4619 clearTimeout(timerId);
4621 setTimeout(function() {
4628 /*--------------------------------------------------------------------------*/
4630 QUnit.module('lodash.delay');
4633 QUnit.test('should delay `func` execution', function(assert) {
4636 var done = assert.async();
4639 _.delay(function() { pass = true; }, 32);
4641 setTimeout(function() {
4645 setTimeout(function() {
4651 QUnit.test('should provide additional arguments to `func`', function(assert) {
4654 var done = assert.async();
4658 _.delay(function() {
4659 args = slice.call(arguments);
4662 setTimeout(function() {
4663 assert.deepEqual(args, [1, 2]);
4668 QUnit.test('should use a default `wait` of `0`', function(assert) {
4671 var done = assert.async();
4675 _.delay(function() {
4681 setTimeout(function() {
4687 QUnit.test('should be cancelable', function(assert) {
4690 var done = assert.async();
4694 var timerId = _.delay(function() {
4698 clearTimeout(timerId);
4700 setTimeout(function() {
4707 /*--------------------------------------------------------------------------*/
4709 QUnit.module('difference methods');
4711 lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
4712 var args = (function() { return arguments; }(1, 2, 3)),
4713 func = _[methodName];
4715 QUnit.test('`_.' + methodName + '` should return the difference of the given arrays', function(assert) {
4718 var actual = func([1, 2, 3, 4, 5], [5, 2, 10]);
4719 assert.deepEqual(actual, [1, 3, 4]);
4721 actual = func([1, 2, 3, 4, 5], [5, 2, 10], [8, 4]);
4722 assert.deepEqual(actual, [1, 3]);
4725 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
4728 var array = [-0, 0];
4730 var actual = lodashStable.map(array, function(value) {
4731 return func(array, [value]);
4734 assert.deepEqual(actual, [[], []]);
4736 actual = lodashStable.map(func([-0, 1], [1]), lodashStable.toString);
4737 assert.deepEqual(actual, ['0']);
4740 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
4743 assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
4746 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
4749 var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
4750 array2 = lodashStable.range(LARGE_ARRAY_SIZE),
4755 array1.push(a, b, c);
4756 array2.push(b, c, a);
4758 assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
4761 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
4764 var array = [-0, 0];
4766 var actual = lodashStable.map(array, function(value) {
4767 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
4768 return func(array, largeArray);
4771 assert.deepEqual(actual, [[], []]);
4773 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysOne);
4774 actual = lodashStable.map(func([-0, 1], largeArray), lodashStable.toString);
4775 assert.deepEqual(actual, ['0']);
4778 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
4781 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
4782 assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
4785 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
4790 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
4792 assert.deepEqual(func([object1, object2], largeArray), [object2]);
4795 QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
4798 var array = [1, null, 3];
4800 assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
4801 assert.deepEqual(func(null, array, 1), []);
4802 assert.deepEqual(func(array, args, null), [null]);
4806 /*--------------------------------------------------------------------------*/
4808 QUnit.module('lodash.differenceBy');
4811 QUnit.test('should accept an `iteratee` argument', function(assert) {
4814 var actual = _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
4815 assert.deepEqual(actual, [3.1, 1.3]);
4817 actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
4818 assert.deepEqual(actual, [{ 'x': 2 }]);
4821 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
4826 _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], function() {
4827 args || (args = slice.call(arguments));
4830 assert.deepEqual(args, [4.4]);
4834 /*--------------------------------------------------------------------------*/
4836 QUnit.module('lodash.differenceWith');
4839 QUnit.test('should work with a `comparator` argument', function(assert) {
4842 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
4843 actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
4845 assert.deepEqual(actual, [objects[1]]);
4848 QUnit.test('should preserve the sign of `0`', function(assert) {
4851 var array = [-0, 1],
4852 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysOne),
4853 others = [[1], largeArray],
4854 expected = lodashStable.map(others, lodashStable.constant(['-0']));
4856 var actual = lodashStable.map(others, function(other) {
4857 return lodashStable.map(_.differenceWith(array, other, lodashStable.eq), lodashStable.toString);
4860 assert.deepEqual(actual, expected);
4864 /*--------------------------------------------------------------------------*/
4866 QUnit.module('lodash.divide');
4869 QUnit.test('should divide two numbers', function(assert) {
4872 assert.strictEqual(_.divide(6, 4), 1.5);
4873 assert.strictEqual(_.divide(-6, 4), -1.5);
4874 assert.strictEqual(_.divide(-6, -4), 1.5);
4877 QUnit.test('should coerce arguments to numbers', function(assert) {
4880 assert.strictEqual(_.divide('6', '4'), 1.5);
4881 assert.deepEqual(_.divide('x', 'y'), NaN);
4885 /*--------------------------------------------------------------------------*/
4887 QUnit.module('lodash.drop');
4890 var array = [1, 2, 3];
4892 QUnit.test('should drop the first two elements', function(assert) {
4895 assert.deepEqual(_.drop(array, 2), [3]);
4898 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4901 var expected = lodashStable.map(falsey, function(value) {
4902 return value === undefined ? [2, 3] : array;
4905 var actual = lodashStable.map(falsey, function(n) {
4906 return _.drop(array, n);
4909 assert.deepEqual(actual, expected);
4912 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4915 lodashStable.each([0, -1, -Infinity], function(n) {
4916 assert.deepEqual(_.drop(array, n), array);
4920 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
4923 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4924 assert.deepEqual(_.drop(array, n), []);
4928 QUnit.test('should coerce `n` to an integer', function(assert) {
4931 assert.deepEqual(_.drop(array, 1.6), [2, 3]);
4934 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4937 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4938 actual = lodashStable.map(array, _.drop);
4940 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
4943 QUnit.test('should work in a lazy sequence', function(assert) {
4947 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4948 predicate = function(value) { values.push(value); return isEven(value); },
4950 actual = _(array).drop(2).drop().value();
4952 assert.deepEqual(actual, array.slice(3));
4954 actual = _(array).filter(predicate).drop(2).drop().value();
4955 assert.deepEqual(values, array);
4956 assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
4958 actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
4959 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
4963 actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
4964 assert.deepEqual(values, array.slice(1));
4965 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
4968 skipAssert(assert, 6);
4973 /*--------------------------------------------------------------------------*/
4975 QUnit.module('lodash.dropRight');
4978 var array = [1, 2, 3];
4980 QUnit.test('should drop the last two elements', function(assert) {
4983 assert.deepEqual(_.dropRight(array, 2), [1]);
4986 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4989 var expected = lodashStable.map(falsey, function(value) {
4990 return value === undefined ? [1, 2] : array;
4993 var actual = lodashStable.map(falsey, function(n) {
4994 return _.dropRight(array, n);
4997 assert.deepEqual(actual, expected);
5000 QUnit.test('should return all elements when `n` < `1`', function(assert) {
5003 lodashStable.each([0, -1, -Infinity], function(n) {
5004 assert.deepEqual(_.dropRight(array, n), array);
5008 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
5011 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
5012 assert.deepEqual(_.dropRight(array, n), []);
5016 QUnit.test('should coerce `n` to an integer', function(assert) {
5019 assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
5022 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5025 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
5026 actual = lodashStable.map(array, _.dropRight);
5028 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
5031 QUnit.test('should work in a lazy sequence', function(assert) {
5035 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5036 predicate = function(value) { values.push(value); return isEven(value); },
5038 actual = _(array).dropRight(2).dropRight().value();
5040 assert.deepEqual(actual, array.slice(0, -3));
5042 actual = _(array).filter(predicate).dropRight(2).dropRight().value();
5043 assert.deepEqual(values, array);
5044 assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
5046 actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
5047 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
5051 actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
5052 assert.deepEqual(values, array.slice(0, -1));
5053 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
5056 skipAssert(assert, 6);
5061 /*--------------------------------------------------------------------------*/
5063 QUnit.module('lodash.dropRightWhile');
5066 var array = [1, 2, 3, 4];
5074 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5077 var actual = _.dropRightWhile(array, function(n) {
5081 assert.deepEqual(actual, [1, 2]);
5084 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
5089 _.dropRightWhile(array, function() {
5090 args = slice.call(arguments);
5093 assert.deepEqual(args, [4, 3, array]);
5096 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5099 assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
5102 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5105 assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
5108 QUnit.test('should work with `_.property` shorthands', function(assert) {
5111 assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
5114 QUnit.test('should return a wrapped value when chaining', function(assert) {
5118 var wrapped = _(array).dropRightWhile(function(n) {
5122 assert.ok(wrapped instanceof _);
5123 assert.deepEqual(wrapped.value(), [1, 2]);
5126 skipAssert(assert, 2);
5131 /*--------------------------------------------------------------------------*/
5133 QUnit.module('lodash.dropWhile');
5136 var array = [1, 2, 3, 4];
5144 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5147 var actual = _.dropWhile(array, function(n) {
5151 assert.deepEqual(actual, [3, 4]);
5154 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
5159 _.dropWhile(array, function() {
5160 args = slice.call(arguments);
5163 assert.deepEqual(args, [1, 0, array]);
5166 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5169 assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
5172 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5175 assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
5178 QUnit.test('should work with `_.property` shorthands', function(assert) {
5181 assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
5184 QUnit.test('should work in a lazy sequence', function(assert) {
5188 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
5189 predicate = function(n) { return n < 3; },
5190 expected = _.dropWhile(array, predicate),
5191 wrapped = _(array).dropWhile(predicate);
5193 assert.deepEqual(wrapped.value(), expected);
5194 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
5195 assert.strictEqual(wrapped.last(), _.last(expected));
5198 skipAssert(assert, 3);
5202 QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
5206 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
5208 var actual = _(array)
5209 .dropWhile(function(n) { return n == 1; })
5211 .dropWhile(function(n) { return n == 3; })
5214 assert.deepEqual(actual, array.slice(3));
5222 /*--------------------------------------------------------------------------*/
5224 QUnit.module('lodash.endsWith');
5229 QUnit.test('should return `true` if a string ends with `target`', function(assert) {
5232 assert.strictEqual(_.endsWith(string, 'c'), true);
5235 QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
5238 assert.strictEqual(_.endsWith(string, 'b'), false);
5241 QUnit.test('should work with a `position` argument', function(assert) {
5244 assert.strictEqual(_.endsWith(string, 'b', 2), true);
5247 QUnit.test('should work with `position` >= `string.length`', function(assert) {
5250 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5251 assert.strictEqual(_.endsWith(string, 'c', position), true);
5255 QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
5258 var expected = lodashStable.map(falsey, alwaysTrue);
5260 var actual = lodashStable.map(falsey, function(position) {
5261 return _.endsWith(string, position === undefined ? 'c' : '', position);
5264 assert.deepEqual(actual, expected);
5267 QUnit.test('should treat a negative `position` as `0`', function(assert) {
5270 lodashStable.each([-1, -3, -Infinity], function(position) {
5271 assert.ok(lodashStable.every(string, function(chr) {
5272 return _.endsWith(string, chr, position) === false;
5274 assert.strictEqual(_.endsWith(string, '', position), true);
5278 QUnit.test('should coerce `position` to an integer', function(assert) {
5281 assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
5284 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
5287 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5288 return _.endsWith(string, '', position, true);
5293 /*--------------------------------------------------------------------------*/
5295 QUnit.module('lodash.eq');
5298 QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
5301 assert.strictEqual(_.eq(), true);
5302 assert.strictEqual(_.eq(undefined), true);
5303 assert.strictEqual(_.eq(0, -0), true);
5304 assert.strictEqual(_.eq(NaN, NaN), true);
5305 assert.strictEqual(_.eq(1, 1), true);
5307 assert.strictEqual(_.eq(null, undefined), false);
5308 assert.strictEqual(_.eq(1, Object(1)), false);
5309 assert.strictEqual(_.eq(1, '1'), false);
5310 assert.strictEqual(_.eq(1, '1'), false);
5312 var object = { 'a': 1 };
5313 assert.strictEqual(_.eq(object, object), true);
5314 assert.strictEqual(_.eq(object, { 'a': 1 }), false);
5318 /*--------------------------------------------------------------------------*/
5320 QUnit.module('lodash.escape');
5323 var escaped = '&<>"'`\/',
5324 unescaped = '&<>"\'`\/';
5327 unescaped += unescaped;
5329 QUnit.test('should escape values', function(assert) {
5332 assert.strictEqual(_.escape(unescaped), escaped);
5335 QUnit.test('should not escape the "/" character', function(assert) {
5338 assert.strictEqual(_.escape('/'), '/');
5341 QUnit.test('should handle strings with nothing to escape', function(assert) {
5344 assert.strictEqual(_.escape('abc'), 'abc');
5347 QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
5350 assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
5354 /*--------------------------------------------------------------------------*/
5356 QUnit.module('lodash.escapeRegExp');
5359 var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
5360 unescaped = '^$.*+?()[]{}|\\';
5362 QUnit.test('should escape values', function(assert) {
5365 assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
5368 QUnit.test('should handle strings with nothing to escape', function(assert) {
5371 assert.strictEqual(_.escapeRegExp('abc'), 'abc');
5374 QUnit.test('should return an empty string for empty values', function(assert) {
5377 var values = [, null, undefined, ''],
5378 expected = lodashStable.map(values, alwaysEmptyString);
5380 var actual = lodashStable.map(values, function(value, index) {
5381 return index ? _.escapeRegExp(value) : _.escapeRegExp();
5384 assert.deepEqual(actual, expected);
5388 /*--------------------------------------------------------------------------*/
5390 QUnit.module('lodash.every');
5393 QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
5396 assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
5399 QUnit.test('should return `true` for empty collections', function(assert) {
5402 var expected = lodashStable.map(empties, alwaysTrue);
5404 var actual = lodashStable.map(empties, function(value) {
5406 return _.every(value, identity);
5410 assert.deepEqual(actual, expected);
5413 QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
5418 assert.strictEqual(_.every([true, null, true], function(value) {
5423 assert.strictEqual(count, 2);
5426 QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
5429 assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
5432 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
5435 var values = [, null, undefined],
5436 expected = lodashStable.map(values, alwaysFalse);
5438 var actual = lodashStable.map(values, function(value, index) {
5440 return index ? _.every(array, value) : _.every(array);
5443 assert.deepEqual(actual, expected);
5445 expected = lodashStable.map(values, alwaysTrue);
5446 actual = lodashStable.map(values, function(value, index) {
5448 return index ? _.every(array, value) : _.every(array);
5451 assert.deepEqual(actual, expected);
5454 QUnit.test('should work with `_.property` shorthands', function(assert) {
5457 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
5458 assert.strictEqual(_.every(objects, 'a'), false);
5459 assert.strictEqual(_.every(objects, 'b'), true);
5462 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5465 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
5466 assert.strictEqual(_.every(objects, { 'a': 0 }), true);
5467 assert.strictEqual(_.every(objects, { 'b': 1 }), false);
5470 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5473 var actual = lodashStable.map([[1]], _.every);
5474 assert.deepEqual(actual, [true]);
5478 /*--------------------------------------------------------------------------*/
5480 QUnit.module('strict mode checks');
5482 lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults'], function(methodName) {
5483 var func = _[methodName],
5484 isBindAll = methodName == 'bindAll';
5486 QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
5490 var object = freeze({ 'a': undefined, 'b': function() {} }),
5494 func(object, isBindAll ? 'b' : { 'a': 1 });
5506 /*--------------------------------------------------------------------------*/
5508 QUnit.module('lodash.fill');
5511 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
5514 var array = [1, 2, 3];
5515 assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
5518 QUnit.test('should use `undefined` for `value` if not given', function(assert) {
5521 var array = [1, 2, 3],
5522 actual = _.fill(array);
5524 assert.deepEqual(actual, Array(3));
5525 assert.ok(lodashStable.every(actual, function(value, index) {
5526 return index in actual;
5530 QUnit.test('should work with a positive `start`', function(assert) {
5533 var array = [1, 2, 3];
5534 assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
5537 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
5540 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
5541 var array = [1, 2, 3];
5542 assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
5546 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
5549 var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
5551 var actual = lodashStable.map(falsey, function(start) {
5552 var array = [1, 2, 3];
5553 return _.fill(array, 'a', start);
5556 assert.deepEqual(actual, expected);
5559 QUnit.test('should work with a negative `start`', function(assert) {
5562 var array = [1, 2, 3];
5563 assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
5566 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
5569 lodashStable.each([-3, -4, -Infinity], function(start) {
5570 var array = [1, 2, 3];
5571 assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
5575 QUnit.test('should work with `start` >= `end`', function(assert) {
5578 lodashStable.each([2, 3], function(start) {
5579 var array = [1, 2, 3];
5580 assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
5584 QUnit.test('should work with a positive `end`', function(assert) {
5587 var array = [1, 2, 3];
5588 assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
5591 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
5594 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
5595 var array = [1, 2, 3];
5596 assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
5600 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
5603 var expected = lodashStable.map(falsey, function(value) {
5604 return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
5607 var actual = lodashStable.map(falsey, function(end) {
5608 var array = [1, 2, 3];
5609 return _.fill(array, 'a', 0, end);
5612 assert.deepEqual(actual, expected);
5615 QUnit.test('should work with a negative `end`', function(assert) {
5618 var array = [1, 2, 3];
5619 assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
5622 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
5625 lodashStable.each([-3, -4, -Infinity], function(end) {
5626 var array = [1, 2, 3];
5627 assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
5631 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
5634 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
5636 var actual = lodashStable.map(positions, function(pos) {
5637 var array = [1, 2, 3];
5638 return _.fill.apply(_, [array, 'a'].concat(pos));
5641 assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
5644 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5647 var array = [[1, 2], [3, 4]],
5648 actual = lodashStable.map(array, _.fill);
5650 assert.deepEqual(actual, [[0, 0], [1, 1]]);
5653 QUnit.test('should return a wrapped value when chaining', function(assert) {
5657 var array = [1, 2, 3],
5658 wrapped = _(array).fill('a'),
5659 actual = wrapped.value();
5661 assert.ok(wrapped instanceof _);
5662 assert.deepEqual(actual, ['a', 'a', 'a']);
5663 assert.strictEqual(actual, array);
5666 skipAssert(assert, 3);
5671 /*--------------------------------------------------------------------------*/
5673 QUnit.module('lodash.filter');
5676 var array = [1, 2, 3];
5678 QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
5681 assert.deepEqual(_.filter(array, isEven), [2]);
5684 QUnit.test('should iterate over an object with numeric keys (test in Mobile Safari 8)', function(assert) {
5687 // Trigger a mobile Safari 8 JIT bug.
5688 // See https://github.com/lodash/lodash/issues/799.
5690 object = { '1': 'foo', '8': 'bar', '50': 'baz' };
5692 lodashStable.times(1000, function(assert) {
5693 _.filter([], alwaysTrue);
5696 _.filter(object, function() {
5701 assert.strictEqual(counter, 3);
5705 /*--------------------------------------------------------------------------*/
5707 lodashStable.each(['find', 'findLast', 'findIndex', 'findLastIndex', 'findKey', 'findLastKey'], function(methodName) {
5708 QUnit.module('lodash.' + methodName);
5710 var func = _[methodName];
5720 'find': [objects[1], undefined, objects[2], objects[1]],
5721 'findLast': [objects[2], undefined, objects[2], objects[2]],
5722 'findIndex': [1, -1, 2, 1],
5723 'findLastIndex': [2, -1, 2, 2],
5724 'findKey': ['1', undefined, '2', '1'],
5725 'findLastKey': ['2', undefined, '2', '2']
5728 QUnit.test('`_.' + methodName + '` should return the found value', function(assert) {
5731 assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
5734 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` if value is not found', function(assert) {
5737 assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
5740 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
5743 assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
5746 QUnit.test('`_.' + methodName + '` should work with `_.matchesProperty` shorthands', function(assert) {
5749 assert.strictEqual(func(objects, ['b', 2]), expected[2]);
5752 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
5755 assert.strictEqual(func(objects, 'b'), expected[3]);
5758 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` for empty collections', function(assert) {
5761 var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
5762 expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
5764 var actual = lodashStable.map(emptyValues, function(value) {
5766 return func(value, { 'a': 3 });
5770 assert.deepEqual(actual, expecting);
5775 var array = [1, 2, 3, 4];
5786 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
5790 assert.strictEqual(_(array)[methodName](), expected);
5797 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
5801 assert.ok(_(array).chain()[methodName]() instanceof _);
5808 QUnit.test('`_.' + methodName + '` should not execute immediately when explicitly chaining', function(assert) {
5812 var wrapped = _(array).chain()[methodName]();
5813 assert.strictEqual(wrapped.__wrapped__, array);
5820 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
5824 var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5827 lodashStable.times(2, function(index) {
5828 var array = index ? largeArray : smallArray,
5829 wrapped = _(array).filter(isEven);
5831 assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
5835 skipAssert(assert, 2);
5848 if (expected != null) {
5849 QUnit.test('`_.' + methodName + '` should work with an object for `collection`', function(assert) {
5852 var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(n) {
5856 assert.strictEqual(actual, expected);
5862 /*--------------------------------------------------------------------------*/
5864 QUnit.module('lodash.find and lodash.findLast');
5866 lodashStable.each(['find', 'findLast'], function(methodName) {
5867 var isFind = methodName == 'find';
5869 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5875 array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5876 iteratee = function(value) { mapCount++; return square(value); },
5877 predicate = function(value) { findCount++; return isEven(value); },
5878 actual = _(array).map(iteratee)[methodName](predicate);
5880 assert.strictEqual(findCount, isFind ? 2 : 1);
5881 assert.strictEqual(mapCount, isFind ? 2 : 1);
5882 assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
5885 skipAssert(assert, 3);
5890 /*--------------------------------------------------------------------------*/
5892 QUnit.module('lodash.flip');
5896 return slice.call(arguments);
5899 QUnit.test('should flip arguments provided to `func`', function(assert) {
5902 var flipped = _.flip(fn);
5903 assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
5907 /*--------------------------------------------------------------------------*/
5909 QUnit.module('lodash.flatMapDepth');
5912 var array = [1, [2, [3, [4]], 5]];
5914 QUnit.test('should use a default `depth` of `1`', function(assert) {
5917 assert.deepEqual(_.flatMapDepth(array, identity), [1, 2, [3, [4]], 5]);
5920 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
5923 var values = [, null, undefined],
5924 expected = lodashStable.map(values, lodashStable.constant([1, 2, [3, [4]], 5]));
5926 var actual = lodashStable.map(values, function(value, index) {
5927 return index ? _.flatMapDepth(array, value) : _.flatMapDepth(array);
5930 assert.deepEqual(actual, expected);
5933 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
5936 lodashStable.each([-1, 0], function(depth) {
5937 assert.deepEqual(_.flatMapDepth(array, identity, depth), [1, [2, [3, [4]], 5]]);
5941 QUnit.test('should coerce `depth` to an integer', function(assert) {
5944 assert.deepEqual(_.flatMapDepth(array, identity, 2.2), [1, 2, 3, [4], 5]);
5948 /*--------------------------------------------------------------------------*/
5950 QUnit.module('flatMap methods');
5952 lodashStable.each(['flatMap', 'flatMapDeep', 'flatMapDepth'], function(methodName) {
5953 var func = _[methodName],
5954 array = [1, 2, 3, 4];
5956 function duplicate(n) {
5960 QUnit.test('`_.' + methodName + '` should map values in `array` to a new flattened array', function(assert) {
5963 var actual = func(array, duplicate),
5964 expected = lodashStable.flatten(lodashStable.map(array, duplicate));
5966 assert.deepEqual(actual, expected);
5969 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
5972 var objects = [{ 'a': [1, 2] }, { 'a': [3, 4] }];
5973 assert.deepEqual(func(objects, 'a'), array);
5976 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
5982 Foo.prototype.b = [3, 4];
5984 var actual = func(new Foo, identity);
5985 assert.deepEqual(actual, [1, 2]);
5988 QUnit.test('`_.' + methodName + '` should use `_.identity` when `iteratee` is nullish', function(assert) {
5991 var array = [[1, 2], [3, 4]],
5992 object = { 'a': [1, 2], 'b': [3, 4] },
5993 values = [, null, undefined],
5994 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
5996 lodashStable.each([array, object], function(collection) {
5997 var actual = lodashStable.map(values, function(value, index) {
5998 return index ? func(collection, value) : func(collection);
6001 assert.deepEqual(actual, expected);
6005 QUnit.test('`_.' + methodName + '` should accept a falsey `collection` argument', function(assert) {
6008 var expected = lodashStable.map(falsey, alwaysEmptyArray);
6010 var actual = lodashStable.map(falsey, function(collection, index) {
6012 return index ? func(collection) : func();
6016 assert.deepEqual(actual, expected);
6019 QUnit.test('`_.' + methodName + '` should treat number values for `collection` as empty', function(assert) {
6022 assert.deepEqual(func(1), []);
6025 QUnit.test('`_.' + methodName + '` should work with objects with non-number length properties', function(assert) {
6028 var object = { 'length': [1, 2] };
6029 assert.deepEqual(func(object, identity), [1, 2]);
6033 /*--------------------------------------------------------------------------*/
6035 QUnit.module('lodash.flattenDepth');
6038 var array = [1, [2, [3, [4]], 5]];
6040 QUnit.test('should use a default `depth` of `1`', function(assert) {
6043 assert.deepEqual(_.flattenDepth(array), [1, 2, [3, [4]], 5]);
6046 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
6049 lodashStable.each([-1, 0], function(depth) {
6050 assert.deepEqual(_.flattenDepth(array, depth), [1, [2, [3, [4]], 5]]);
6054 QUnit.test('should coerce `depth` to an integer', function(assert) {
6057 assert.deepEqual(_.flattenDepth(array, 2.2), [1, 2, 3, [4], 5]);
6061 /*--------------------------------------------------------------------------*/
6063 QUnit.module('flatten methods');
6066 var args = arguments,
6067 array = [1, [2, [3, [4]], 5]];
6069 QUnit.test('should flatten `arguments` objects', function(assert) {
6072 var array = [args, [args]];
6074 assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
6075 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
6076 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);
6079 QUnit.test('should treat sparse arrays as dense', function(assert) {
6082 var array = [[1, 2, 3], Array(3)],
6083 expected = [1, 2, 3];
6085 expected.push(undefined, undefined, undefined);
6087 lodashStable.each([_.flatten(array), _.flattenDeep(array), _.flattenDepth(array)], function(actual) {
6088 assert.deepEqual(actual, expected);
6089 assert.ok('4' in actual);
6093 QUnit.test('should work with extremely large arrays', function(assert) {
6096 lodashStable.times(3, function(index) {
6097 var expected = Array(5e5);
6099 var func = _.flatten;
6101 func = _.flattenDeep;
6102 } else if (index == 2) {
6103 func = _.flattenDepth;
6105 assert.deepEqual(func([expected]), expected);
6107 assert.ok(false, e.message);
6112 QUnit.test('should work with empty arrays', function(assert) {
6115 var array = [[], [[]], [[], [[[]]]]];
6117 assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
6118 assert.deepEqual(_.flattenDeep(array), []);
6119 assert.deepEqual(_.flattenDepth(array, 2), [[[]]]);
6122 QUnit.test('should support flattening of nested arrays', function(assert) {
6125 assert.deepEqual(_.flatten(array), [1, 2, [3, [4]], 5]);
6126 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
6127 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, [4], 5]);
6130 QUnit.test('should return an empty array for non array-like objects', function(assert) {
6134 nonArray = { 'a': 1 };
6136 assert.deepEqual(_.flatten(nonArray), expected);
6137 assert.deepEqual(_.flattenDeep(nonArray), expected);
6138 assert.deepEqual(_.flattenDepth(nonArray, 2), expected);
6141 QUnit.test('should return a wrapped value when chaining', function(assert) {
6145 var wrapped = _(array),
6146 actual = wrapped.flatten();
6148 assert.ok(actual instanceof _);
6149 assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);
6151 actual = wrapped.flattenDeep();
6153 assert.ok(actual instanceof _);
6154 assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);
6156 actual = wrapped.flattenDepth(2);
6158 assert.ok(actual instanceof _);
6159 assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);
6162 skipAssert(assert, 6);
6167 /*--------------------------------------------------------------------------*/
6169 QUnit.module('flow methods');
6171 lodashStable.each(['flow', 'flowRight'], function(methodName) {
6172 var func = _[methodName],
6173 isFlow = methodName == 'flow';
6175 QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
6178 var fixed = function(n) { return n.toFixed(1); },
6179 combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
6181 assert.strictEqual(combined(1, 2), '9.0');
6184 QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
6187 assert.notStrictEqual(func(noop), noop);
6190 QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are given', function(assert) {
6193 _.times(2, function(index) {
6195 var combined = index ? func([]) : func();
6196 assert.strictEqual(combined('a'), 'a');
6198 assert.ok(false, e.message);
6200 assert.strictEqual(combined.length, 0);
6201 assert.notStrictEqual(combined, identity);
6205 QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
6208 var curried = _.curry(identity);
6210 var combined = isFlow
6211 ? func(_.head, curried)
6212 : func(curried, _.head);
6214 assert.strictEqual(combined([1]), 1);
6217 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
6222 array = lodashStable.range(LARGE_ARRAY_SIZE),
6223 iteratee = function(value) { mapCount++; return square(value); },
6224 predicate = function(value) { filterCount++; return isEven(value); };
6226 lodashStable.times(2, function(index) {
6227 var filter1 = _.filter,
6228 filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
6229 filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
6232 map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
6233 map3 = (_.map = index ? map2 : map1, map2(iteratee));
6236 take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
6237 take3 = (_.take = index ? take2 : take1, take2(2));
6239 var combined = isFlow
6240 ? func(map3, filter3, _.compact, take3)
6241 : func(take3, _.compact, filter3, map3);
6243 filterCount = mapCount = 0;
6244 assert.deepEqual(combined(array), [4, 16]);
6246 if (!isNpm && WeakMap && WeakMap.name) {
6247 assert.strictEqual(filterCount, 5, 'filterCount');
6248 assert.strictEqual(mapCount, 5, 'mapCount');
6251 skipAssert(assert, 2);
6259 QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
6262 var curried = _.curry(_.ary(_.map, 2), 2),
6263 getProp = curried(curried.placeholder, 'a'),
6264 objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
6266 var combined = isFlow
6267 ? func(getProp, _.uniq)
6268 : func(_.uniq, getProp);
6270 assert.deepEqual(combined(objects), [1, 2]);
6273 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
6277 var wrapped = _(noop)[methodName]();
6278 assert.ok(wrapped instanceof _);
6286 /*--------------------------------------------------------------------------*/
6288 QUnit.module('lodash.forEach');
6291 QUnit.test('should be aliased', function(assert) {
6294 assert.strictEqual(_.each, _.forEach);
6298 /*--------------------------------------------------------------------------*/
6300 QUnit.module('lodash.forEachRight');
6303 QUnit.test('should be aliased', function(assert) {
6306 assert.strictEqual(_.eachRight, _.forEachRight);
6310 /*--------------------------------------------------------------------------*/
6312 QUnit.module('forIn methods');
6314 lodashStable.each(['forIn', 'forInRight'], function(methodName) {
6315 var func = _[methodName];
6317 QUnit.test('`_.' + methodName + '` iterates over inherited string keyed properties', function(assert) {
6323 Foo.prototype.b = 2;
6326 func(new Foo, function(value, key) { keys.push(key); });
6327 assert.deepEqual(keys.sort(), ['a', 'b']);
6331 /*--------------------------------------------------------------------------*/
6333 QUnit.module('forOwn methods');
6335 lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
6336 var func = _[methodName];
6338 QUnit.test('`_.' + methodName + '` should iterate over `length` properties', function(assert) {
6341 var object = { '0': 'zero', '1': 'one', 'length': 2 },
6344 func(object, function(value, prop) { props.push(prop); });
6345 assert.deepEqual(props.sort(), ['0', '1', 'length']);
6349 /*--------------------------------------------------------------------------*/
6351 QUnit.module('iteration methods');
6385 var arrayMethods = [
6392 var collectionMethods = [
6411 var forInMethods = [
6418 var iterationMethods = [
6428 var objectMethods = [
6441 var rightMethods = [
6450 var unwrappedMethods = [
6473 lodashStable.each(methods, function(methodName) {
6474 var array = [1, 2, 3],
6475 func = _[methodName],
6476 isBy = /(^partition|By)$/.test(methodName),
6477 isFind = /^find/.test(methodName),
6478 isOmitPick = /^(?:omit|pick)By$/.test(methodName),
6479 isSome = methodName == 'some';
6481 QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
6486 expected = [1, 0, array];
6488 func(array, function() {
6489 args || (args = slice.call(arguments));
6492 if (lodashStable.includes(rightMethods, methodName)) {
6496 if (lodashStable.includes(objectMethods, methodName)) {
6500 expected.length = isOmitPick ? 2 : 1;
6502 assert.deepEqual(args, expected);
6509 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
6516 var expected = lodashStable.includes(objectMethods, methodName)
6517 ? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
6518 : [[1, 0, array], [undefined, 1, array], [3, 2, array]];
6521 expected = lodashStable.map(expected, function(args) {
6522 return args.slice(0, isOmitPick ? 2 : 1);
6525 else if (lodashStable.includes(objectMethods, methodName)) {
6526 expected = lodashStable.map(expected, function(args) {
6531 if (lodashStable.includes(rightMethods, methodName)) {
6535 func(array, function() {
6536 argsList.push(slice.call(arguments));
6537 return !(isFind || isSome);
6540 assert.deepEqual(argsList, expected);
6548 lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
6549 var array = [1, 2, 3],
6550 func = _[methodName],
6551 isEvery = methodName == 'every';
6555 QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
6560 func(array, function(value, key) {
6565 assert.notOk(lodashStable.includes(keys, 'a'));
6573 lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
6574 var array = [1, 2, 3],
6575 isBaseEach = methodName == '_baseEach';
6577 QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
6580 if (!(isBaseEach || isNpm)) {
6581 var wrapped = _(array)[methodName](noop);
6582 assert.ok(wrapped instanceof _);
6590 lodashStable.each(unwrappedMethods, function(methodName) {
6591 var array = [1, 2, 3];
6593 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
6597 var actual = _(array)[methodName](noop);
6598 assert.notOk(actual instanceof _);
6605 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
6609 var wrapped = _(array).chain(),
6610 actual = wrapped[methodName](noop);
6612 assert.ok(actual instanceof _);
6613 assert.notStrictEqual(actual, wrapped);
6616 skipAssert(assert, 2);
6621 lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
6622 var func = _[methodName];
6624 QUnit.test('`_.' + methodName + '` iterates over own string keyed properties of objects', function(assert) {
6630 Foo.prototype.b = 2;
6634 func(new Foo, function(value) { values.push(value); });
6635 assert.deepEqual(values, [1]);
6643 lodashStable.each(iterationMethods, function(methodName) {
6644 var array = [1, 2, 3],
6645 func = _[methodName];
6647 QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
6651 assert.strictEqual(func(array, Boolean), array);
6659 lodashStable.each(collectionMethods, function(methodName) {
6660 var func = _[methodName];
6662 QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
6666 var isIteratedAsObject = function(object) {
6668 func(object, function() { result = true; }, 0);
6672 var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
6673 expected = lodashStable.map(values, alwaysTrue);
6675 var actual = lodashStable.map(values, function(length) {
6676 return isIteratedAsObject({ 'length': length });
6679 var Foo = function(a) {};
6682 assert.deepEqual(actual, expected);
6683 assert.ok(isIteratedAsObject(Foo));
6684 assert.notOk(isIteratedAsObject({ 'length': 0 }));
6687 skipAssert(assert, 3);
6692 lodashStable.each(methods, function(methodName) {
6693 var func = _[methodName],
6694 isFind = /^find/.test(methodName),
6695 isSome = methodName == 'some',
6696 isReduce = /^reduce/.test(methodName);
6698 QUnit.test('`_.' + methodName + '` should ignore changes to `array.length`', function(assert) {
6705 func(array, function() {
6709 return !(isFind || isSome);
6710 }, isReduce ? array : null);
6712 assert.strictEqual(count, 1);
6720 lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
6721 var func = _[methodName],
6722 isFind = /^find/.test(methodName),
6723 isSome = methodName == 'some',
6724 isReduce = /^reduce/.test(methodName);
6726 QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
6731 object = { 'a': 1 };
6733 func(object, function() {
6737 return !(isFind || isSome);
6738 }, isReduce ? object : null);
6740 assert.strictEqual(count, 1);
6749 /*--------------------------------------------------------------------------*/
6751 QUnit.module('object assignments');
6753 lodashStable.each(['assign', 'assignIn', 'defaults', 'merge'], function(methodName) {
6754 var func = _[methodName],
6755 isAssign = methodName == 'assign',
6756 isDefaults = methodName == 'defaults';
6758 QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
6761 var expected = lodashStable.map(primitives, function(value) {
6762 var object = Object(value);
6767 var actual = lodashStable.map(primitives, function(value) {
6768 return func(value, { 'a': 1 });
6771 assert.deepEqual(actual, expected);
6774 QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'string keyed source properties', function(assert) {
6780 Foo.prototype.b = 2;
6782 var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
6783 assert.deepEqual(func({}, new Foo), expected);
6786 QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
6790 assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
6792 assert.ok(false, e.message);
6796 QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
6799 var source = { 'a': 1 },
6800 values = [null, undefined],
6801 expected = lodashStable.map(values, alwaysTrue);
6803 var actual = lodashStable.map(values, function(value) {
6804 var object = func(value, source);
6805 return object !== source && lodashStable.isEqual(object, source);
6808 assert.deepEqual(actual, expected);
6810 actual = lodashStable.map(values, function(value) {
6811 return lodashStable.isEqual(func(value), {});
6814 assert.deepEqual(actual, expected);
6817 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
6820 var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
6821 expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
6823 assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
6825 var fn = function() {};
6830 assert.deepEqual(_.reduce(fn, func, { 'a': 0 }), expected);
6833 QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
6837 var wrapped = _({ 'a': 1 }),
6838 actual = wrapped[methodName]({ 'b': 2 });
6840 assert.notStrictEqual(actual, wrapped);
6848 lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
6849 var func = _[methodName];
6851 QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
6855 Foo.prototype.a = 1;
6857 var actual = func(new Foo, { 'b': 2 });
6858 assert.notOk(_.has(actual, 'a'));
6862 lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'merge', 'mergeWith'], function(methodName) {
6863 var func = _[methodName];
6865 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
6868 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
6869 if (defineProperty) {
6873 defineProperty(object, 'a', {
6875 'configurable': true,
6876 'get': lodashStable.constant(value),
6877 'set': function() { pass = false; }
6880 func(object, { 'a': value });
6890 lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
6891 var func = _[methodName],
6892 isMergeWith = methodName == 'mergeWith';
6894 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
6898 object = { 'a': 1 },
6899 source = { 'a': 2 },
6900 expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
6902 func(object, source, function() {
6903 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6906 assert.deepEqual(args, expected, 'primitive property values');
6909 object = { 'a': 1 };
6910 source = { 'b': 2 };
6911 expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
6913 func(object, source, function() {
6914 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6917 assert.deepEqual(args, expected, 'missing destination property');
6920 objectValue = [1, 2],
6921 sourceValue = { 'b': 2 };
6923 object = { 'a': objectValue };
6924 source = { 'a': sourceValue };
6925 expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
6928 expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
6930 func(object, source, function() {
6931 argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6934 assert.deepEqual(argsList, expected, 'object property values');
6937 QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
6940 function callback() {}
6943 var actual = func({ 'a': 1 }, callback);
6944 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
6946 actual = func({ 'a': 1 }, callback, { 'c': 3 });
6947 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
6951 /*--------------------------------------------------------------------------*/
6953 QUnit.module('exit early');
6955 lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
6956 var func = _[methodName];
6958 QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
6962 var array = [1, 2, 3],
6965 func(array, function(value, other) {
6966 values.push(lodashStable.isArray(value) ? other : value);
6970 assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
6977 QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
6981 var object = { 'a': 1, 'b': 2, 'c': 3 },
6984 func(object, function(value, other) {
6985 values.push(lodashStable.isArray(value) ? other : value);
6989 assert.strictEqual(values.length, 1);
6997 /*--------------------------------------------------------------------------*/
6999 QUnit.module('`__proto__` property bugs');
7002 QUnit.test('internal data objects should work with the `__proto__` key', function(assert) {
7005 var stringLiteral = '__proto__',
7006 stringObject = Object(stringLiteral),
7007 expected = [stringLiteral, stringObject];
7009 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
7010 return isEven(count) ? stringLiteral : stringObject;
7013 assert.deepEqual(_.difference(largeArray, largeArray), []);
7014 assert.deepEqual(_.intersection(largeArray, largeArray), expected);
7015 assert.deepEqual(_.uniq(largeArray), expected);
7016 assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
7020 /*--------------------------------------------------------------------------*/
7022 QUnit.module('lodash.fromPairs');
7025 QUnit.test('should accept a two dimensional array', function(assert) {
7028 var array = [['a', 1], ['b', 2]],
7029 object = { 'a': 1, 'b': 2 },
7030 actual = _.fromPairs(array);
7032 assert.deepEqual(actual, object);
7035 QUnit.test('should accept a falsey `array` argument', function(assert) {
7038 var expected = lodashStable.map(falsey, alwaysEmptyObject);
7040 var actual = lodashStable.map(falsey, function(array, index) {
7042 return index ? _.fromPairs(array) : _.fromPairs();
7046 assert.deepEqual(actual, expected);
7049 QUnit.test('should not support deep paths', function(assert) {
7052 var actual = _.fromPairs([['a.b', 1]]);
7053 assert.deepEqual(actual, { 'a.b': 1 });
7056 QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
7059 var object = { 'a.b': 1 };
7060 assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
7063 QUnit.test('should work in a lazy sequence', function(assert) {
7067 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
7068 return ['key' + index, index];
7071 var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
7073 assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
7081 /*--------------------------------------------------------------------------*/
7083 QUnit.module('lodash.functions');
7086 QUnit.test('should return the function names of an object', function(assert) {
7089 var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': noop },
7090 actual = _.functions(object).sort();
7092 assert.deepEqual(actual, ['b', 'd']);
7095 QUnit.test('should not include inherited functions', function(assert) {
7102 Foo.prototype.c = noop;
7104 assert.deepEqual(_.functions(new Foo), ['a']);
7108 /*--------------------------------------------------------------------------*/
7110 QUnit.module('lodash.groupBy');
7113 var array = [6.1, 4.2, 6.3];
7115 QUnit.test('should transform keys by `iteratee`', function(assert) {
7118 var actual = _.groupBy(array, Math.floor);
7119 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7122 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
7125 var array = [6, 4, 6],
7126 values = [, null, undefined],
7127 expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
7129 var actual = lodashStable.map(values, function(value, index) {
7130 return index ? _.groupBy(array, value) : _.groupBy(array);
7133 assert.deepEqual(actual, expected);
7136 QUnit.test('should work with `_.property` shorthands', function(assert) {
7139 var actual = _.groupBy(['one', 'two', 'three'], 'length');
7140 assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
7143 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
7146 var actual = _.groupBy(array, function(n) {
7147 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
7150 assert.deepEqual(actual.constructor, [4.2]);
7151 assert.deepEqual(actual.hasOwnProperty, [6.1, 6.3]);
7154 QUnit.test('should work with a number for `iteratee`', function(assert) {
7163 assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
7164 assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
7167 QUnit.test('should work with an object for `collection`', function(assert) {
7170 var actual = _.groupBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
7171 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7174 QUnit.test('should work in a lazy sequence', function(assert) {
7178 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
7179 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
7180 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
7183 var iteratee = function(value) { value.push(value[0]); return value; },
7184 predicate = function(value) { return isEven(value[0]); },
7185 actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
7187 assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
7195 /*--------------------------------------------------------------------------*/
7197 QUnit.module('lodash.gt');
7200 QUnit.test('should return `true` if `value` > `other`', function(assert) {
7203 assert.strictEqual(_.gt(3, 1), true);
7204 assert.strictEqual(_.gt('def', 'abc'), true);
7207 QUnit.test('should return `false` if `value` is <= `other`', function(assert) {
7210 assert.strictEqual(_.gt(1, 3), false);
7211 assert.strictEqual(_.gt(3, 3), false);
7212 assert.strictEqual(_.gt('abc', 'def'), false);
7213 assert.strictEqual(_.gt('def', 'def'), false);
7217 /*--------------------------------------------------------------------------*/
7219 QUnit.module('lodash.gte');
7222 QUnit.test('should return `true` if `value` >= `other`', function(assert) {
7225 assert.strictEqual(_.gte(3, 1), true);
7226 assert.strictEqual(_.gte(3, 3), true);
7227 assert.strictEqual(_.gte('def', 'abc'), true);
7228 assert.strictEqual(_.gte('def', 'def'), true);
7231 QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
7234 assert.strictEqual(_.gte(1, 3), false);
7235 assert.strictEqual(_.gte('abc', 'def'), false);
7239 /*--------------------------------------------------------------------------*/
7241 QUnit.module('has methods');
7243 lodashStable.each(['has', 'hasIn'], function(methodName) {
7244 var args = (function() { return arguments; }(1, 2, 3)),
7245 func = _[methodName],
7246 isHas = methodName == 'has';
7248 QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
7251 var object = { 'a': 1 };
7253 lodashStable.each(['a', ['a']], function(path) {
7254 assert.strictEqual(func(object, path), true);
7258 QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
7261 var object = { 'hasOwnProperty': null, 'a': 1 };
7262 assert.strictEqual(func(object, 'a'), true);
7265 QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
7268 var object = { 'a': { 'b': 2 } };
7270 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7271 assert.strictEqual(func(object, path), true);
7274 lodashStable.each(['a.a', ['a', 'a']], function(path) {
7275 assert.strictEqual(func(object, path), false);
7279 QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
7283 fn.toString = lodashStable.constant('fn');
7285 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
7286 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
7287 values = [null, undefined, fn, {}];
7289 var actual = lodashStable.transform(objects, function(result, object, index) {
7290 var key = values[index];
7291 lodashStable.each([key, [key]], function(path) {
7292 var prop = _.property(key);
7293 result.push(prop(object));
7297 assert.deepEqual(actual, expected);
7300 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7303 assert.strictEqual(func(args, 1), true);
7306 QUnit.test('`_.' + methodName + '` should work with a non-string `path`', function(assert) {
7309 var array = [1, 2, 3];
7311 lodashStable.each([1, [1]], function(path) {
7312 assert.strictEqual(func(array, path), true);
7316 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
7319 var object = { '-0': 'a', '0': 'b' },
7320 props = [-0, Object(-0), 0, Object(0)],
7321 expected = lodashStable.map(props, alwaysTrue);
7323 var actual = lodashStable.map(props, function(key) {
7324 return func(object, key);
7327 assert.deepEqual(actual, expected);
7330 QUnit.test('`_.' + methodName + '` should work with a symbol `path`', function(assert) {
7338 var symbol2 = Symbol('b');
7339 Foo.prototype[symbol2] = 2;
7340 var path = isHas ? symbol : symbol2;
7342 assert.strictEqual(func(new Foo, path), true);
7349 QUnit.test('`_.' + methodName + '` should work for objects with a `[[Prototype]]` of `null`', function(assert) {
7353 var object = create(null);
7355 assert.strictEqual(func(object, 1), true);
7362 QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
7365 var object = { 'a.b': 1 };
7367 lodashStable.each(['a.b', ['a.b']], function(path) {
7368 assert.strictEqual(func(object, path), true);
7372 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7376 Foo.prototype.a = 1;
7378 lodashStable.each(['a', ['a']], function(path) {
7379 assert.strictEqual(func(new Foo, path), !isHas);
7383 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
7387 Foo.prototype.a = { 'b': 1 };
7389 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7390 assert.strictEqual(func(new Foo, path), !isHas);
7394 QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
7397 var string = Object('abc');
7401 var values = [Array(3), args, string],
7402 expected = lodashStable.map(values, alwaysTrue);
7404 var actual = lodashStable.map(values, function(value) {
7405 return func(value, 0);
7408 assert.deepEqual(actual, expected);
7410 expected = lodashStable.map(values, lodashStable.constant([true, true]));
7412 actual = lodashStable.map(values, function(value) {
7413 return lodashStable.map(['a[0]', ['a', '0']], function(path) {
7414 return func({ 'a': value }, path);
7418 assert.deepEqual(actual, expected);
7422 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
7425 var values = [null, undefined],
7426 expected = lodashStable.map(values, alwaysFalse);
7428 lodashStable.each(['constructor', ['constructor']], function(path) {
7429 var actual = lodashStable.map(values, function(value) {
7430 return func(value, path);
7433 assert.deepEqual(actual, expected);
7437 QUnit.test('`_.' + methodName + '` should return `false` for deep paths when `object` is nullish', function(assert) {
7440 var values = [null, undefined],
7441 expected = lodashStable.map(values, alwaysFalse);
7443 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
7444 var actual = lodashStable.map(values, function(value) {
7445 return func(value, path);
7448 assert.deepEqual(actual, expected);
7452 QUnit.test('`_.' + methodName + '` should return `false` for nullish values of nested objects', function(assert) {
7455 var values = [, null, undefined],
7456 expected = lodashStable.map(values, alwaysFalse);
7458 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7459 var actual = lodashStable.map(values, function(value, index) {
7460 var object = index ? { 'a': value } : {};
7461 return func(object, path);
7464 assert.deepEqual(actual, expected);
7469 /*--------------------------------------------------------------------------*/
7471 QUnit.module('lodash.head');
7474 var array = [1, 2, 3, 4];
7476 QUnit.test('should return the first element', function(assert) {
7479 assert.strictEqual(_.head(array), 1);
7482 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
7486 assert.strictEqual(_.head([]), undefined);
7487 arrayProto.length = 0;
7490 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7493 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7494 actual = lodashStable.map(array, _.head);
7496 assert.deepEqual(actual, [1, 4, 7]);
7499 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7503 assert.strictEqual(_(array).head(), 1);
7510 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7514 assert.ok(_(array).chain().head() instanceof _);
7521 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
7525 var wrapped = _(array).chain().head();
7526 assert.strictEqual(wrapped.__wrapped__, array);
7533 QUnit.test('should work in a lazy sequence', function(assert) {
7537 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
7540 lodashStable.times(2, function(index) {
7541 var array = index ? largeArray : smallArray,
7542 wrapped = _(array).filter(isEven);
7544 assert.strictEqual(wrapped.head(), _.head(_.filter(array, isEven)));
7548 skipAssert(assert, 2);
7552 QUnit.test('should be aliased', function(assert) {
7555 assert.strictEqual(_.first, _.head);
7559 /*--------------------------------------------------------------------------*/
7561 QUnit.module('lodash.identity');
7564 QUnit.test('should return the first argument given', function(assert) {
7567 var object = { 'name': 'fred' };
7568 assert.strictEqual(_.identity(object), object);
7572 /*--------------------------------------------------------------------------*/
7574 QUnit.module('lodash.includes');
7578 'an `arguments` object': arguments,
7579 'an array': [1, 2, 3, 4],
7580 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
7583 function(collection, key) {
7584 var isStr = typeof collection == 'string',
7585 values = _.toArray(collection),
7586 length = values.length;
7588 QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
7591 assert.strictEqual(_.includes(collection, 3), true);
7594 QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
7597 assert.strictEqual(_.includes(collection, 5), false);
7600 QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
7603 assert.strictEqual(_.includes(collection, values[2], 2), true);
7604 assert.strictEqual(_.includes(collection, values[1], 2), false);
7607 QUnit.test('should work with ' + key + ' and a `fromIndex` >= `collection.length`', function(assert) {
7610 lodashStable.each([4, 6, Math.pow(2, 32), Infinity], function(fromIndex) {
7611 assert.strictEqual(_.includes(collection, 1, fromIndex), false);
7612 assert.strictEqual(_.includes(collection, undefined, fromIndex), false);
7613 assert.strictEqual(_.includes(collection, '', fromIndex), (isStr && fromIndex == length));
7617 QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
7620 var expected = lodashStable.map(falsey, alwaysTrue);
7622 var actual = lodashStable.map(falsey, function(fromIndex) {
7623 return _.includes(collection, values[0], fromIndex);
7626 assert.deepEqual(actual, expected);
7629 QUnit.test('should work with ' + key + ' and coerce non-integer `fromIndex` values to integers', function(assert) {
7632 assert.strictEqual(_.includes(collection, values[0], '1'), false);
7633 assert.strictEqual(_.includes(collection, values[0], 0.1), true);
7634 assert.strictEqual(_.includes(collection, values[0], NaN), true);
7637 QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
7640 assert.strictEqual(_.includes(collection, values[2], -2), true);
7641 assert.strictEqual(_.includes(collection, values[1], -2), false);
7644 QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= negative `collection.length`', function(assert) {
7647 lodashStable.each([-4, -6, -Infinity], function(fromIndex) {
7648 assert.strictEqual(_.includes(collection, values[0], fromIndex), true);
7652 QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
7655 assert.strictEqual(_.includes(collection, 2, 1.2), true);
7658 QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
7662 assert.strictEqual(_(collection).includes(3), true);
7669 QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
7673 assert.ok(_(collection).chain().includes(3) instanceof _);
7683 'object': Object('abc')
7685 function(collection, key) {
7686 QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
7689 assert.strictEqual(_.includes(collection, 'bc'), true);
7690 assert.strictEqual(_.includes(collection, 'd'), false);
7694 QUnit.test('should return `false` for empty collections', function(assert) {
7697 var expected = lodashStable.map(empties, alwaysFalse);
7699 var actual = lodashStable.map(empties, function(value) {
7701 return _.includes(value);
7705 assert.deepEqual(actual, expected);
7708 QUnit.test('should match `NaN`', function(assert) {
7711 assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
7714 QUnit.test('should match `-0` as `0`', function(assert) {
7717 assert.strictEqual(_.includes([-0], 0), true);
7718 assert.strictEqual(_.includes([0], -0), true);
7721 QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
7724 var array1 = [1, 2, 3],
7727 assert.ok(lodashStable.every(array1, lodashStable.partial(_.includes, array2)));
7731 /*--------------------------------------------------------------------------*/
7733 QUnit.module('lodash.indexOf');
7736 var array = [1, 2, 3, 1, 2, 3];
7738 QUnit.test('should return the index of the first matched value', function(assert) {
7741 assert.strictEqual(_.indexOf(array, 3), 2);
7744 QUnit.test('should work with a positive `fromIndex`', function(assert) {
7747 assert.strictEqual(_.indexOf(array, 1, 2), 3);
7750 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
7753 var values = [6, 8, Math.pow(2, 32), Infinity],
7754 expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
7756 var actual = lodashStable.map(values, function(fromIndex) {
7758 _.indexOf(array, undefined, fromIndex),
7759 _.indexOf(array, 1, fromIndex),
7760 _.indexOf(array, '', fromIndex)
7764 assert.deepEqual(actual, expected);
7767 QUnit.test('should work with a negative `fromIndex`', function(assert) {
7770 assert.strictEqual(_.indexOf(array, 2, -3), 4);
7773 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
7776 var values = [-6, -8, -Infinity],
7777 expected = lodashStable.map(values, alwaysZero);
7779 var actual = lodashStable.map(values, function(fromIndex) {
7780 return _.indexOf(array, 1, fromIndex);
7783 assert.deepEqual(actual, expected);
7786 QUnit.test('should treat falsey `fromIndex` values as `0`', function(assert) {
7789 var expected = lodashStable.map(falsey, alwaysZero);
7791 var actual = lodashStable.map(falsey, function(fromIndex) {
7792 return _.indexOf(array, 1, fromIndex);
7795 assert.deepEqual(actual, expected);
7798 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
7801 assert.strictEqual(_.indexOf(array, 2, 1.2), 1);
7805 /*--------------------------------------------------------------------------*/
7807 QUnit.module('lodash.initial');
7810 var array = [1, 2, 3];
7812 QUnit.test('should accept a falsey `array` argument', function(assert) {
7815 var expected = lodashStable.map(falsey, alwaysEmptyArray);
7817 var actual = lodashStable.map(falsey, function(array, index) {
7819 return index ? _.initial(array) : _.initial();
7823 assert.deepEqual(actual, expected);
7826 QUnit.test('should exclude last element', function(assert) {
7829 assert.deepEqual(_.initial(array), [1, 2]);
7832 QUnit.test('should return an empty when querying empty arrays', function(assert) {
7835 assert.deepEqual(_.initial([]), []);
7838 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7841 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7842 actual = lodashStable.map(array, _.initial);
7844 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
7847 QUnit.test('should work in a lazy sequence', function(assert) {
7851 var array = lodashStable.range(LARGE_ARRAY_SIZE),
7854 var actual = _(array).initial().filter(function(value) {
7860 assert.deepEqual(actual, []);
7861 assert.deepEqual(values, _.initial(array));
7865 actual = _(array).filter(function(value) {
7867 return isEven(value);
7872 assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
7873 assert.deepEqual(values, array);
7876 skipAssert(assert, 4);
7881 /*--------------------------------------------------------------------------*/
7883 QUnit.module('lodash.inRange');
7886 QUnit.test('should work with an `end` argument', function(assert) {
7889 assert.strictEqual(_.inRange(3, 5), true);
7890 assert.strictEqual(_.inRange(5, 5), false);
7891 assert.strictEqual(_.inRange(6, 5), false);
7894 QUnit.test('should work with `start` and `end` arguments', function(assert) {
7897 assert.strictEqual(_.inRange(1, 1, 5), true);
7898 assert.strictEqual(_.inRange(3, 1, 5), true);
7899 assert.strictEqual(_.inRange(0, 1, 5), false);
7900 assert.strictEqual(_.inRange(5, 1, 5), false);
7903 QUnit.test('should treat falsey `start` arguments as `0`', function(assert) {
7906 lodashStable.each(falsey, function(value, index) {
7908 assert.strictEqual(_.inRange(0, value), false);
7909 assert.strictEqual(_.inRange(0, value, 1), true);
7911 assert.strictEqual(_.inRange(0), false);
7916 QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
7919 assert.strictEqual(_.inRange(2, 5, 1), true);
7920 assert.strictEqual(_.inRange(-3, -2, -6), true);
7923 QUnit.test('should work with a floating point `n` value', function(assert) {
7926 assert.strictEqual(_.inRange(0.5, 5), true);
7927 assert.strictEqual(_.inRange(1.2, 1, 5), true);
7928 assert.strictEqual(_.inRange(5.2, 5), false);
7929 assert.strictEqual(_.inRange(0.5, 1, 5), false);
7932 QUnit.test('should coerce arguments to finite numbers', function(assert) {
7935 var actual = [_.inRange(0, '0', 1), _.inRange(0, '1'), _.inRange(0, 0, '1'), _.inRange(0, NaN, 1), _.inRange(-1, -1, NaN)],
7936 expected = lodashStable.map(actual, alwaysTrue);
7938 assert.deepEqual(actual, expected);
7942 /*--------------------------------------------------------------------------*/
7944 QUnit.module('intersection methods');
7946 lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
7947 var args = (function() { return arguments; }(1, 2, 3)),
7948 func = _[methodName];
7950 QUnit.test('`_.' + methodName + '` should return the intersection of two arrays', function(assert) {
7953 var actual = func([1, 3, 2], [5, 2, 1, 4]);
7954 assert.deepEqual(actual, [1, 2]);
7956 actual = func([5, 2, 1, 4], [1, 3, 2]);
7957 assert.deepEqual(actual, [2, 1]);
7960 QUnit.test('`_.' + methodName + '` should return the intersection of multiple arrays', function(assert) {
7963 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
7964 assert.deepEqual(actual, [1, 2]);
7966 actual = func([5, 2, 1, 4], [2, 1], [1, 3, 2]);
7967 assert.deepEqual(actual, [2, 1]);
7970 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
7973 var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
7974 assert.deepEqual(actual, [1, 2]);
7977 QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
7980 var actual = func([1, 1, 3, 2, 2]);
7981 assert.deepEqual(actual, [1, 3, 2]);
7984 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7987 var array = [0, 1, null, 3],
7990 assert.deepEqual(func(array, args), expected);
7991 assert.deepEqual(func(args, array), expected);
7994 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
7997 var values = [-0, 0],
7998 expected = lodashStable.map(values, lodashStable.constant(['0']));
8000 var actual = lodashStable.map(values, function(value) {
8001 return lodashStable.map(func(values, [value]), lodashStable.toString);
8004 assert.deepEqual(actual, expected);
8007 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
8010 var actual = func([1, NaN, 3], [NaN, 5, NaN]);
8011 assert.deepEqual(actual, [NaN]);
8014 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
8017 var values = [-0, 0],
8018 expected = lodashStable.map(values, lodashStable.constant(['0']));
8020 var actual = lodashStable.map(values, function(value) {
8021 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
8022 return lodashStable.map(func(values, largeArray), lodashStable.toString);
8025 assert.deepEqual(actual, expected);
8028 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
8031 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
8032 assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
8035 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
8039 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
8041 assert.deepEqual(func([object], largeArray), [object]);
8042 assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
8045 QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
8048 var array = [0, 1, null, 3];
8049 assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
8050 assert.deepEqual(func(null, array, null, [2, 3]), []);
8051 assert.deepEqual(func(array, null, args, null), []);
8054 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
8058 var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
8059 assert.ok(wrapped instanceof _);
8060 assert.deepEqual(wrapped.value(), [1, 2]);
8063 skipAssert(assert, 2);
8068 /*--------------------------------------------------------------------------*/
8070 QUnit.module('lodash.intersectionBy');
8073 QUnit.test('should accept an `iteratee` argument', function(assert) {
8076 var actual = _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
8077 assert.deepEqual(actual, [2.1]);
8079 actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8080 assert.deepEqual(actual, [{ 'x': 1 }]);
8083 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
8088 _.intersectionBy([2.1, 1.2], [4.3, 2.4], function() {
8089 args || (args = slice.call(arguments));
8092 assert.deepEqual(args, [4.3]);
8096 /*--------------------------------------------------------------------------*/
8098 QUnit.module('lodash.intersectionWith');
8101 QUnit.test('should work with a `comparator` argument', function(assert) {
8104 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
8105 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
8106 actual = _.intersectionWith(objects, others, lodashStable.isEqual);
8108 assert.deepEqual(actual, [objects[0]]);
8111 QUnit.test('should preserve the sign of `0`', function(assert) {
8115 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysZero),
8116 others = [[0], largeArray],
8117 expected = lodashStable.map(others, lodashStable.constant(['-0']));
8119 var actual = lodashStable.map(others, function(other) {
8120 return lodashStable.map(_.intersectionWith(array, other, lodashStable.eq), lodashStable.toString);
8123 assert.deepEqual(actual, expected);
8127 /*--------------------------------------------------------------------------*/
8129 QUnit.module('lodash.invert');
8132 QUnit.test('should invert an object', function(assert) {
8135 var object = { 'a': 1, 'b': 2 },
8136 actual = _.invert(object);
8138 assert.deepEqual(actual, { '1': 'a', '2': 'b' });
8139 assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
8142 QUnit.test('should work with values that shadow keys on `Object.prototype`', function(assert) {
8145 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
8146 assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
8149 QUnit.test('should work with an object that has a `length` property', function(assert) {
8152 var object = { '0': 'a', '1': 'b', 'length': 2 };
8153 assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
8156 QUnit.test('should return a wrapped value when chaining', function(assert) {
8160 var object = { 'a': 1, 'b': 2 },
8161 wrapped = _(object).invert();
8163 assert.ok(wrapped instanceof _);
8164 assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
8167 skipAssert(assert, 2);
8172 /*--------------------------------------------------------------------------*/
8174 QUnit.module('lodash.invertBy');
8177 var object = { 'a': 1, 'b': 2, 'c': 1 };
8179 QUnit.test('should transform keys by `iteratee`', function(assert) {
8182 var expected = { 'group1': ['a', 'c'], 'group2': ['b'] };
8184 var actual = _.invertBy(object, function(value) {
8185 return 'group' + value;
8188 assert.deepEqual(actual, expected);
8191 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
8194 var values = [, null, undefined],
8195 expected = lodashStable.map(values, lodashStable.constant({ '1': ['a', 'c'], '2': ['b'] }));
8197 var actual = lodashStable.map(values, function(value, index) {
8198 return index ? _.invertBy(object, value) : _.invertBy(object);
8201 assert.deepEqual(actual, expected);
8204 QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
8207 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' },
8208 expected = { 'hasOwnProperty': ['a'], 'constructor': ['b'] };
8210 assert.ok(lodashStable.isEqual(_.invertBy(object), expected));
8213 QUnit.test('should return a wrapped value when chaining', function(assert) {
8217 var wrapped = _(object).invertBy();
8219 assert.ok(wrapped instanceof _);
8220 assert.deepEqual(wrapped.value(), { '1': ['a', 'c'], '2': ['b'] });
8223 skipAssert(assert, 2);
8228 /*--------------------------------------------------------------------------*/
8230 QUnit.module('lodash.invoke');
8233 QUnit.test('should invoke a method on `object`', function(assert) {
8236 var object = { 'a': lodashStable.constant('A') },
8237 actual = _.invoke(object, 'a');
8239 assert.strictEqual(actual, 'A');
8242 QUnit.test('should support invoking with arguments', function(assert) {
8245 var object = { 'a': function(a, b) { return [a, b]; } },
8246 actual = _.invoke(object, 'a', 1, 2);
8248 assert.deepEqual(actual, [1, 2]);
8251 QUnit.test('should not error on nullish elements', function(assert) {
8254 var values = [null, undefined],
8255 expected = lodashStable.map(values, noop);
8257 var actual = lodashStable.map(values, function(value) {
8259 return _.invoke(value, 'a.b', 1, 2);
8263 assert.deepEqual(actual, expected);
8266 QUnit.test('should preserve the sign of `0`', function(assert) {
8269 var object = { '-0': alwaysA, '0': alwaysB },
8270 props = [-0, Object(-0), 0, Object(0)];
8272 var actual = lodashStable.map(props, function(key) {
8273 return _.invoke(object, key);
8276 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
8279 QUnit.test('should support deep paths', function(assert) {
8282 var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
8284 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8285 var actual = _.invoke(object, path, 1, 2);
8286 assert.deepEqual(actual, [1, 2]);
8290 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8293 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8295 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8296 assert.deepEqual(_.invoke(object, path), 1);
8300 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8304 var object = { 'a': alwaysOne };
8305 assert.strictEqual(_(object).invoke('a'), 1);
8312 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8316 var object = { 'a': alwaysOne };
8317 assert.ok(_(object).chain().invoke('a') instanceof _);
8325 /*--------------------------------------------------------------------------*/
8327 QUnit.module('lodash.invokeMap');
8330 QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
8333 var array = ['a', 'b', 'c'],
8334 actual = _.invokeMap(array, 'toUpperCase');
8336 assert.deepEqual(actual, ['A', 'B', 'C']);
8339 QUnit.test('should support invoking with arguments', function(assert) {
8342 var array = [function() { return slice.call(arguments); }],
8343 actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
8345 assert.deepEqual(actual, [['a', 'b', 'c']]);
8348 QUnit.test('should work with a function for `methodName`', function(assert) {
8351 var array = ['a', 'b', 'c'];
8353 var actual = _.invokeMap(array, function(left, right) {
8354 return left + this.toUpperCase() + right;
8357 assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
8360 QUnit.test('should work with an object for `collection`', function(assert) {
8363 var object = { 'a': 1, 'b': 2, 'c': 3 },
8364 actual = _.invokeMap(object, 'toFixed', 1);
8366 assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
8369 QUnit.test('should treat number values for `collection` as empty', function(assert) {
8372 assert.deepEqual(_.invokeMap(1), []);
8375 QUnit.test('should not error on nullish elements', function(assert) {
8378 var array = ['a', null, undefined, 'd'];
8381 var actual = _.invokeMap(array, 'toUpperCase');
8384 assert.deepEqual(actual, ['A', undefined, undefined, 'D']);
8387 QUnit.test('should not error on elements with missing properties', function(assert) {
8390 var objects = lodashStable.map([null, undefined, alwaysOne], function(value) {
8391 return { 'a': value };
8394 var expected = lodashStable.map(objects, function(object) {
8395 return object.a ? object.a() : undefined;
8399 var actual = _.invokeMap(objects, 'a');
8402 assert.deepEqual(actual, expected);
8405 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8408 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8410 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8411 assert.deepEqual(_.invokeMap([object], path), [1]);
8415 QUnit.test('should return a wrapped value when chaining', function(assert) {
8419 var array = ['a', 'b', 'c'],
8421 actual = wrapped.invokeMap('toUpperCase');
8423 assert.ok(actual instanceof _);
8424 assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
8426 actual = wrapped.invokeMap(function(left, right) {
8427 return left + this.toUpperCase() + right;
8430 assert.ok(actual instanceof _);
8431 assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
8434 skipAssert(assert, 4);
8438 QUnit.test('should support shortcut fusion', function(assert) {
8443 method = function() { count++; return this.index; };
8445 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
8446 return { 'index': index, 'method': method };
8449 var actual = _(array).invokeMap('method').take(1).value();
8451 assert.strictEqual(count, 1);
8452 assert.deepEqual(actual, [0]);
8455 skipAssert(assert, 2);
8460 /*--------------------------------------------------------------------------*/
8462 QUnit.module('lodash.isArguments');
8465 var args = (function() { return arguments; }(1, 2, 3)),
8466 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
8468 QUnit.test('should return `true` for `arguments` objects', function(assert) {
8471 assert.strictEqual(_.isArguments(args), true);
8472 assert.strictEqual(_.isArguments(strictArgs), true);
8475 QUnit.test('should return `false` for non `arguments` objects', function(assert) {
8478 var expected = lodashStable.map(falsey, alwaysFalse);
8480 var actual = lodashStable.map(falsey, function(value, index) {
8481 return index ? _.isArguments(value) : _.isArguments();
8484 assert.deepEqual(actual, expected);
8486 assert.strictEqual(_.isArguments([1, 2, 3]), false);
8487 assert.strictEqual(_.isArguments(true), false);
8488 assert.strictEqual(_.isArguments(new Date), false);
8489 assert.strictEqual(_.isArguments(new Error), false);
8490 assert.strictEqual(_.isArguments(_), false);
8491 assert.strictEqual(_.isArguments(slice), false);
8492 assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
8493 assert.strictEqual(_.isArguments(1), false);
8494 assert.strictEqual(_.isArguments(/x/), false);
8495 assert.strictEqual(_.isArguments('a'), false);
8496 assert.strictEqual(_.isArguments(symbol), false);
8499 QUnit.test('should work with an `arguments` object from another realm', function(assert) {
8502 if (realm.arguments) {
8503 assert.strictEqual(_.isArguments(realm.arguments), true);
8511 /*--------------------------------------------------------------------------*/
8513 QUnit.module('lodash.isArray');
8516 var args = arguments;
8518 QUnit.test('should return `true` for arrays', function(assert) {
8521 assert.strictEqual(_.isArray([1, 2, 3]), true);
8524 QUnit.test('should return `false` for non-arrays', function(assert) {
8527 var expected = lodashStable.map(falsey, alwaysFalse);
8529 var actual = lodashStable.map(falsey, function(value, index) {
8530 return index ? _.isArray(value) : _.isArray();
8533 assert.deepEqual(actual, expected);
8535 assert.strictEqual(_.isArray(args), false);
8536 assert.strictEqual(_.isArray(true), false);
8537 assert.strictEqual(_.isArray(new Date), false);
8538 assert.strictEqual(_.isArray(new Error), false);
8539 assert.strictEqual(_.isArray(_), false);
8540 assert.strictEqual(_.isArray(slice), false);
8541 assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
8542 assert.strictEqual(_.isArray(1), false);
8543 assert.strictEqual(_.isArray(/x/), false);
8544 assert.strictEqual(_.isArray('a'), false);
8545 assert.strictEqual(_.isArray(symbol), false);
8548 QUnit.test('should work with an array from another realm', function(assert) {
8552 assert.strictEqual(_.isArray(realm.array), true);
8560 /*--------------------------------------------------------------------------*/
8562 QUnit.module('lodash.isArrayBuffer');
8565 var args = arguments;
8567 QUnit.test('should return `true` for array buffers', function(assert) {
8571 assert.strictEqual(_.isArrayBuffer(arrayBuffer), true);
8578 QUnit.test('should return `false` for non array buffers', function(assert) {
8581 var expected = lodashStable.map(falsey, alwaysFalse);
8583 var actual = lodashStable.map(falsey, function(value, index) {
8584 return index ? _.isArrayBuffer(value) : _.isArrayBuffer();
8587 assert.deepEqual(actual, expected);
8589 assert.strictEqual(_.isArrayBuffer(args), false);
8590 assert.strictEqual(_.isArrayBuffer([1, 2, 3]), false);
8591 assert.strictEqual(_.isArrayBuffer(true), false);
8592 assert.strictEqual(_.isArrayBuffer(new Date), false);
8593 assert.strictEqual(_.isArrayBuffer(new Error), false);
8594 assert.strictEqual(_.isArrayBuffer(_), false);
8595 assert.strictEqual(_.isArrayBuffer(slice), false);
8596 assert.strictEqual(_.isArrayBuffer({ 'a': 1 }), false);
8597 assert.strictEqual(_.isArrayBuffer(1), false);
8598 assert.strictEqual(_.isArrayBuffer(/x/), false);
8599 assert.strictEqual(_.isArrayBuffer('a'), false);
8600 assert.strictEqual(_.isArrayBuffer(symbol), false);
8603 QUnit.test('should work with array buffers from another realm', function(assert) {
8606 if (realm.arrayBuffer) {
8607 assert.strictEqual(_.isArrayBuffer(realm.arrayBuffer), true);
8615 /*--------------------------------------------------------------------------*/
8617 QUnit.module('lodash.isArrayLike');
8620 var args = arguments;
8622 QUnit.test('should return `true` for array-like values', function(assert) {
8625 var values = [args, [1, 2, 3], { '0': 1, 'length': 1 }, 'a'],
8626 expected = lodashStable.map(values, alwaysTrue),
8627 actual = lodashStable.map(values, _.isArrayLike);
8629 assert.deepEqual(actual, expected);
8632 QUnit.test('should return `false` for non-arrays', function(assert) {
8635 var expected = lodashStable.map(falsey, function(value) {
8636 return value === '';
8639 var actual = lodashStable.map(falsey, function(value, index) {
8640 return index ? _.isArrayLike(value) : _.isArrayLike();
8643 assert.deepEqual(actual, expected);
8645 assert.strictEqual(_.isArrayLike(true), false);
8646 assert.strictEqual(_.isArrayLike(new Date), false);
8647 assert.strictEqual(_.isArrayLike(new Error), false);
8648 assert.strictEqual(_.isArrayLike(_), false);
8649 assert.strictEqual(_.isArrayLike(generator), false);
8650 assert.strictEqual(_.isArrayLike(slice), false);
8651 assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
8652 assert.strictEqual(_.isArrayLike(1), false);
8653 assert.strictEqual(_.isArrayLike(/x/), false);
8654 assert.strictEqual(_.isArrayLike(symbol), false);
8657 QUnit.test('should work with an array from another realm', function(assert) {
8661 var values = [realm.arguments, realm.array, realm.string],
8662 expected = lodashStable.map(values, alwaysTrue),
8663 actual = lodashStable.map(values, _.isArrayLike);
8665 assert.deepEqual(actual, expected);
8673 /*--------------------------------------------------------------------------*/
8675 QUnit.module('lodash.isBoolean');
8678 var args = arguments;
8680 QUnit.test('should return `true` for booleans', function(assert) {
8683 assert.strictEqual(_.isBoolean(true), true);
8684 assert.strictEqual(_.isBoolean(false), true);
8685 assert.strictEqual(_.isBoolean(Object(true)), true);
8686 assert.strictEqual(_.isBoolean(Object(false)), true);
8689 QUnit.test('should return `false` for non-booleans', function(assert) {
8692 var expected = lodashStable.map(falsey, function(value) {
8693 return value === false;
8696 var actual = lodashStable.map(falsey, function(value, index) {
8697 return index ? _.isBoolean(value) : _.isBoolean();
8700 assert.deepEqual(actual, expected);
8702 assert.strictEqual(_.isBoolean(args), false);
8703 assert.strictEqual(_.isBoolean([1, 2, 3]), false);
8704 assert.strictEqual(_.isBoolean(new Date), false);
8705 assert.strictEqual(_.isBoolean(new Error), false);
8706 assert.strictEqual(_.isBoolean(_), false);
8707 assert.strictEqual(_.isBoolean(slice), false);
8708 assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
8709 assert.strictEqual(_.isBoolean(1), false);
8710 assert.strictEqual(_.isBoolean(/x/), false);
8711 assert.strictEqual(_.isBoolean('a'), false);
8712 assert.strictEqual(_.isBoolean(symbol), false);
8715 QUnit.test('should work with a boolean from another realm', function(assert) {
8718 if (realm.boolean) {
8719 assert.strictEqual(_.isBoolean(realm.boolean), true);
8727 /*--------------------------------------------------------------------------*/
8729 QUnit.module('lodash.isBuffer');
8732 var args = arguments;
8734 QUnit.test('should return `true` for buffers', function(assert) {
8738 assert.strictEqual(_.isBuffer(new Buffer(2)), true);
8745 QUnit.test('should return `false` for non-buffers', function(assert) {
8748 var expected = lodashStable.map(falsey, alwaysFalse);
8750 var actual = lodashStable.map(falsey, function(value, index) {
8751 return index ? _.isBuffer(value) : _.isBuffer();
8754 assert.deepEqual(actual, expected);
8756 assert.strictEqual(_.isBuffer(args), false);
8757 assert.strictEqual(_.isBuffer([1, 2, 3]), false);
8758 assert.strictEqual(_.isBuffer(true), false);
8759 assert.strictEqual(_.isBuffer(new Date), false);
8760 assert.strictEqual(_.isBuffer(new Error), false);
8761 assert.strictEqual(_.isBuffer(_), false);
8762 assert.strictEqual(_.isBuffer(slice), false);
8763 assert.strictEqual(_.isBuffer({ 'a': 1 }), false);
8764 assert.strictEqual(_.isBuffer(1), false);
8765 assert.strictEqual(_.isBuffer(/x/), false);
8766 assert.strictEqual(_.isBuffer('a'), false);
8767 assert.strictEqual(_.isBuffer(symbol), false);
8770 QUnit.test('should return `false` if `Buffer` is not defined', function(assert) {
8773 if (!isStrict && Buffer && lodashBizarro) {
8774 assert.strictEqual(lodashBizarro.isBuffer(new Buffer(2)), false);
8782 /*--------------------------------------------------------------------------*/
8784 QUnit.module('lodash.isDate');
8787 var args = arguments;
8789 QUnit.test('should return `true` for dates', function(assert) {
8792 assert.strictEqual(_.isDate(new Date), true);
8795 QUnit.test('should return `false` for non-dates', function(assert) {
8798 var expected = lodashStable.map(falsey, alwaysFalse);
8800 var actual = lodashStable.map(falsey, function(value, index) {
8801 return index ? _.isDate(value) : _.isDate();
8804 assert.deepEqual(actual, expected);
8806 assert.strictEqual(_.isDate(args), false);
8807 assert.strictEqual(_.isDate([1, 2, 3]), false);
8808 assert.strictEqual(_.isDate(true), false);
8809 assert.strictEqual(_.isDate(new Error), false);
8810 assert.strictEqual(_.isDate(_), false);
8811 assert.strictEqual(_.isDate(slice), false);
8812 assert.strictEqual(_.isDate({ 'a': 1 }), false);
8813 assert.strictEqual(_.isDate(1), false);
8814 assert.strictEqual(_.isDate(/x/), false);
8815 assert.strictEqual(_.isDate('a'), false);
8816 assert.strictEqual(_.isDate(symbol), false);
8819 QUnit.test('should work with a date object from another realm', function(assert) {
8823 assert.strictEqual(_.isDate(realm.date), true);
8831 /*--------------------------------------------------------------------------*/
8833 QUnit.module('lodash.isElement');
8836 var args = arguments;
8838 function Element() {
8842 QUnit.test('should return `false` for plain objects', function(assert) {
8845 var element = body || new Element;
8847 assert.strictEqual(_.isElement(element), true);
8848 assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
8849 assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
8850 assert.strictEqual(_.isElement({ 'nodeType': true }), false);
8851 assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
8852 assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
8853 assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
8856 QUnit.test('should return `false` for non DOM elements', function(assert) {
8859 var expected = lodashStable.map(falsey, alwaysFalse);
8861 var actual = lodashStable.map(falsey, function(value, index) {
8862 return index ? _.isElement(value) : _.isElement();
8865 assert.deepEqual(actual, expected);
8867 assert.strictEqual(_.isElement(args), false);
8868 assert.strictEqual(_.isElement([1, 2, 3]), false);
8869 assert.strictEqual(_.isElement(true), false);
8870 assert.strictEqual(_.isElement(new Date), false);
8871 assert.strictEqual(_.isElement(new Error), false);
8872 assert.strictEqual(_.isElement(_), false);
8873 assert.strictEqual(_.isElement(slice), false);
8874 assert.strictEqual(_.isElement({ 'a': 1 }), false);
8875 assert.strictEqual(_.isElement(1), false);
8876 assert.strictEqual(_.isElement(/x/), false);
8877 assert.strictEqual(_.isElement('a'), false);
8878 assert.strictEqual(_.isElement(symbol), false);
8881 QUnit.test('should work with a DOM element from another realm', function(assert) {
8884 if (realm.element) {
8885 assert.strictEqual(_.isElement(realm.element), true);
8893 /*--------------------------------------------------------------------------*/
8895 QUnit.module('lodash.isEmpty');
8898 var args = arguments;
8900 QUnit.test('should return `true` for empty values', function(assert) {
8903 var expected = lodashStable.map(empties, alwaysTrue),
8904 actual = lodashStable.map(empties, _.isEmpty);
8906 assert.deepEqual(actual, expected);
8908 assert.strictEqual(_.isEmpty(true), true);
8909 assert.strictEqual(_.isEmpty(slice), true);
8910 assert.strictEqual(_.isEmpty(1), true);
8911 assert.strictEqual(_.isEmpty(NaN), true);
8912 assert.strictEqual(_.isEmpty(/x/), true);
8913 assert.strictEqual(_.isEmpty(symbol), true);
8914 assert.strictEqual(_.isEmpty(), true);
8917 assert.strictEqual(_.isEmpty(new Buffer(0)), true);
8918 assert.strictEqual(_.isEmpty(new Buffer(1)), false);
8921 skipAssert(assert, 2);
8925 QUnit.test('should return `false` for non-empty values', function(assert) {
8928 assert.strictEqual(_.isEmpty([0]), false);
8929 assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
8930 assert.strictEqual(_.isEmpty('a'), false);
8933 QUnit.test('should work with an object that has a `length` property', function(assert) {
8936 assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
8939 QUnit.test('should work with `arguments` objects', function(assert) {
8942 assert.strictEqual(_.isEmpty(args), false);
8945 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
8948 function Foo(elements) {
8949 push.apply(this, elements);
8951 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
8953 assert.strictEqual(_.isEmpty(new Foo([])), true);
8956 QUnit.test('should work with maps', function(assert) {
8960 lodashStable.each([new Map, realm.map], function(map) {
8961 assert.strictEqual(_.isEmpty(map), true);
8963 assert.strictEqual(_.isEmpty(map), false);
8968 skipAssert(assert, 4);
8972 QUnit.test('should work with sets', function(assert) {
8976 lodashStable.each([new Set, realm.set], function(set) {
8977 assert.strictEqual(_.isEmpty(set), true);
8979 assert.strictEqual(_.isEmpty(set), false);
8984 skipAssert(assert, 4);
8988 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
8992 Foo.prototype.length = -1;
8994 assert.strictEqual(_.isEmpty(new Foo), true);
8997 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
9001 Foo.prototype.length = MAX_SAFE_INTEGER + 1;
9003 assert.strictEqual(_.isEmpty(new Foo), true);
9006 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
9009 assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
9012 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
9016 assert.strictEqual(_({}).isEmpty(), true);
9023 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
9027 assert.ok(_({}).chain().isEmpty() instanceof _);
9035 /*--------------------------------------------------------------------------*/
9037 QUnit.module('lodash.isEqual');
9040 var symbol1 = Symbol ? Symbol('a') : true,
9041 symbol2 = Symbol ? Symbol('b') : false;
9043 QUnit.test('should compare primitives', function(assert) {
9047 [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
9048 [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
9049 [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
9050 ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
9051 [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
9052 [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
9053 [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
9054 [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
9055 [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
9058 var expected = lodashStable.map(pairs, function(pair) {
9062 var actual = lodashStable.map(pairs, function(pair) {
9063 return _.isEqual(pair[0], pair[1]);
9066 assert.deepEqual(actual, expected);
9069 QUnit.test('should compare arrays', function(assert) {
9072 var array1 = [true, null, 1, 'a', undefined],
9073 array2 = [true, null, 1, 'a', undefined];
9075 assert.strictEqual(_.isEqual(array1, array2), true);
9077 array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9078 array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9080 assert.strictEqual(_.isEqual(array1, array2), true);
9086 array2[1] = undefined;
9089 assert.strictEqual(_.isEqual(array1, array2), true);
9091 array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
9092 array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
9094 assert.strictEqual(_.isEqual(array1, array2), true);
9099 assert.strictEqual(_.isEqual(array1, array2), false);
9104 assert.strictEqual(_.isEqual(array1, array2), false);
9107 QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
9110 var array1 = [1, 2, 3],
9113 array1.every = array1.filter = array1.forEach =
9114 array1.indexOf = array1.lastIndexOf = array1.map =
9115 array1.some = array1.reduce = array1.reduceRight = null;
9117 array2.concat = array2.join = array2.pop =
9118 array2.reverse = array2.shift = array2.slice =
9119 array2.sort = array2.splice = array2.unshift = null;
9121 assert.strictEqual(_.isEqual(array1, array2), true);
9129 assert.strictEqual(_.isEqual(array1, array2), true);
9131 array1 = /c/.exec('abcde');
9134 assert.strictEqual(_.isEqual(array1, array2), true);
9137 QUnit.test('should compare sparse arrays', function(assert) {
9140 var array = Array(1);
9142 assert.strictEqual(_.isEqual(array, Array(1)), true);
9143 assert.strictEqual(_.isEqual(array, [undefined]), true);
9144 assert.strictEqual(_.isEqual(array, Array(2)), false);
9147 QUnit.test('should compare plain objects', function(assert) {
9150 var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
9151 object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
9153 assert.strictEqual(_.isEqual(object1, object2), true);
9155 object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9156 object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9158 assert.strictEqual(_.isEqual(object1, object2), true);
9160 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9161 object2 = { 'a': 3, 'b': 2, 'c': 1 };
9163 assert.strictEqual(_.isEqual(object1, object2), false);
9165 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9166 object2 = { 'd': 1, 'e': 2, 'f': 3 };
9168 assert.strictEqual(_.isEqual(object1, object2), false);
9170 object1 = { 'a': 1, 'b': 2 };
9171 object2 = { 'a': 1, 'b': 2, 'c': 3 };
9173 assert.strictEqual(_.isEqual(object1, object2), false);
9176 QUnit.test('should compare objects regardless of key order', function(assert) {
9179 var object1 = { 'a': 1, 'b': 2, 'c': 3 },
9180 object2 = { 'c': 3, 'a': 1, 'b': 2 };
9182 assert.strictEqual(_.isEqual(object1, object2), true);
9185 QUnit.test('should compare nested objects', function(assert) {
9194 'f': ['a', Object('b'), 'c'],
9196 'h': new Date(2012, 4, 23),
9203 'a': [1, Object(2), 3],
9208 'f': ['a', 'b', 'c'],
9210 'h': new Date(2012, 4, 23),
9216 assert.strictEqual(_.isEqual(object1, object2), true);
9219 QUnit.test('should compare object instances', function(assert) {
9225 Foo.prototype.a = 1;
9230 Bar.prototype.a = 2;
9232 assert.strictEqual(_.isEqual(new Foo, new Foo), true);
9233 assert.strictEqual(_.isEqual(new Foo, new Bar), false);
9234 assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
9235 assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
9238 QUnit.test('should compare objects with constructor properties', function(assert) {
9241 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
9242 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
9243 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
9244 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
9245 assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
9248 QUnit.test('should compare arrays with circular references', function(assert) {
9254 array1.push(array1);
9255 array2.push(array2);
9257 assert.strictEqual(_.isEqual(array1, array2), true);
9262 assert.strictEqual(_.isEqual(array1, array2), true);
9267 assert.strictEqual(_.isEqual(array1, array2), false);
9269 array1 = ['a', 'b', 'c'];
9271 array2 = ['a', ['a', 'b', 'c'], 'c'];
9273 assert.strictEqual(_.isEqual(array1, array2), false);
9276 QUnit.test('should compare objects with circular references', function(assert) {
9282 object1.a = object1;
9283 object2.a = object2;
9285 assert.strictEqual(_.isEqual(object1, object2), true);
9288 object2.b = Object(0);
9290 assert.strictEqual(_.isEqual(object1, object2), true);
9292 object1.c = Object(1);
9293 object2.c = Object(2);
9295 assert.strictEqual(_.isEqual(object1, object2), false);
9297 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9298 object1.b = object1;
9299 object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
9301 assert.strictEqual(_.isEqual(object1, object2), false);
9304 QUnit.test('should compare objects with multiple circular references', function(assert) {
9310 (array1[0].a = array1).push(array1);
9311 (array2[0].a = array2).push(array2);
9313 assert.strictEqual(_.isEqual(array1, array2), true);
9316 array2[0].b = Object(0);
9318 assert.strictEqual(_.isEqual(array1, array2), true);
9320 array1[0].c = Object(1);
9321 array2[0].c = Object(2);
9323 assert.strictEqual(_.isEqual(array1, array2), false);
9326 QUnit.test('should compare objects with complex circular references', function(assert) {
9330 'foo': { 'b': { 'c': { 'd': {} } } },
9335 'foo': { 'b': { 'c': { 'd': {} } } },
9339 object1.foo.b.c.d = object1;
9340 object1.bar.b = object1.foo.b;
9342 object2.foo.b.c.d = object2;
9343 object2.bar.b = object2.foo.b;
9345 assert.strictEqual(_.isEqual(object1, object2), true);
9348 QUnit.test('should compare objects with shared property values', function(assert) {
9360 object1.b = object1.a;
9362 assert.strictEqual(_.isEqual(object1, object2), true);
9365 QUnit.test('should treat objects created by `Object.create(null)` like a plain object', function(assert) {
9371 Foo.prototype.constructor = null;
9373 var object2 = { 'a': 1 };
9374 assert.strictEqual(_.isEqual(new Foo, object2), false);
9377 var object1 = create(null);
9379 assert.strictEqual(_.isEqual(object1, object2), true);
9386 QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
9390 object = { 'toString': function() { return primitive; } },
9391 values = [true, null, 1, 'a', undefined],
9392 expected = lodashStable.map(values, alwaysFalse);
9394 var actual = lodashStable.map(values, function(value) {
9396 return _.isEqual(object, value);
9399 assert.deepEqual(actual, expected);
9402 QUnit.test('should avoid common type coercions', function(assert) {
9405 assert.strictEqual(_.isEqual(true, Object(false)), false);
9406 assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
9407 assert.strictEqual(_.isEqual(false, Object('')), false);
9408 assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
9409 assert.strictEqual(_.isEqual(0, ''), false);
9410 assert.strictEqual(_.isEqual(1, true), false);
9411 assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
9412 assert.strictEqual(_.isEqual('36', 36), false);
9413 assert.strictEqual(_.isEqual(36, '36'), false);
9416 QUnit.test('should compare `arguments` objects', function(assert) {
9419 var args1 = (function() { return arguments; }(1, 2, 3)),
9420 args2 = (function() { return arguments; }(1, 2, 3)),
9421 args3 = (function() { return arguments; }(1, 2));
9423 assert.strictEqual(_.isEqual(args1, args2), true);
9424 assert.strictEqual(_.isEqual(args1, args3), false);
9427 QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
9430 var args = (function() { return arguments; }(1, 2, 3)),
9431 object = { '0': 1, '1': 2, '2': 3 };
9434 Foo.prototype = object;
9436 assert.strictEqual(_.isEqual(args, object), true);
9437 assert.strictEqual(_.isEqual(object, args), true);
9439 assert.strictEqual(_.isEqual(args, new Foo), false);
9440 assert.strictEqual(_.isEqual(new Foo, args), false);
9443 QUnit.test('should compare array buffers', function(assert) {
9447 var buffer1 = new ArrayBuffer(4),
9448 buffer2 = new ArrayBuffer(8);
9450 assert.strictEqual(_.isEqual(buffer1, buffer2), false);
9452 buffer1 = new Int8Array([-1]).buffer;
9453 buffer2 = new Uint8Array([255]).buffer;
9455 assert.strictEqual(_.isEqual(buffer1, buffer2), true);
9458 skipAssert(assert, 2);
9462 QUnit.test('should compare array views', function(assert) {
9465 lodashStable.times(2, function(index) {
9466 var ns = index ? realm : root;
9468 var pairs = lodashStable.map(arrayViews, function(type, viewIndex) {
9469 var otherType = arrayViews[(viewIndex + 1) % arrayViews.length],
9470 CtorA = ns[type] || function(n) { this.n = n; },
9471 CtorB = ns[otherType] || function(n) { this.n = n; },
9472 bufferA = ns[type] ? new ns.ArrayBuffer(8) : 8,
9473 bufferB = ns[otherType] ? new ns.ArrayBuffer(8) : 8,
9474 bufferC = ns[otherType] ? new ns.ArrayBuffer(16) : 16;
9476 return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
9479 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9481 var actual = lodashStable.map(pairs, function(pair) {
9482 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9485 assert.deepEqual(actual, expected);
9489 QUnit.test('should compare date objects', function(assert) {
9492 var date = new Date(2012, 4, 23);
9494 assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
9495 assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false);
9496 assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false);
9497 assert.strictEqual(_.isEqual(new Date('a'), new Date('a')), false);
9500 QUnit.test('should compare error objects', function(assert) {
9503 var pairs = lodashStable.map([
9511 ], function(type, index, errorTypes) {
9512 var otherType = errorTypes[++index % errorTypes.length],
9514 CtorB = root[otherType];
9516 return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
9519 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9521 var actual = lodashStable.map(pairs, function(pair) {
9522 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9525 assert.deepEqual(actual, expected);
9528 QUnit.test('should compare functions', function(assert) {
9531 function a() { return 1 + 2; }
9532 function b() { return 1 + 2; }
9534 assert.strictEqual(_.isEqual(a, a), true);
9535 assert.strictEqual(_.isEqual(a, b), false);
9538 QUnit.test('should compare maps', function(assert) {
9542 lodashStable.each([[map, new Map], [map, realm.map]], function(maps) {
9548 assert.strictEqual(_.isEqual(map1, map2), false);
9552 assert.strictEqual(_.isEqual(map1, map2), true);
9554 map1['delete']('a');
9556 assert.strictEqual(_.isEqual(map1, map2), true);
9558 map2['delete']('a');
9559 assert.strictEqual(_.isEqual(map1, map2), false);
9566 skipAssert(assert, 8);
9570 QUnit.test('should compare maps with circular references', function(assert) {
9577 map1.set('a', map1);
9578 map2.set('a', map2);
9579 assert.strictEqual(_.isEqual(map1, map2), true);
9583 assert.strictEqual(_.isEqual(map1, map2), false);
9586 skipAssert(assert, 2);
9590 QUnit.test('should compare promises by reference', function(assert) {
9594 lodashStable.each([[promise, Promise.resolve(1)], [promise, realm.promise]], function(promises) {
9595 var promise1 = promises[0],
9596 promise2 = promises[1];
9598 assert.strictEqual(_.isEqual(promise1, promise2), false);
9599 assert.strictEqual(_.isEqual(promise1, promise1), true);
9603 skipAssert(assert, 4);
9607 QUnit.test('should compare regexes', function(assert) {
9610 assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
9611 assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
9612 assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
9613 assert.strictEqual(_.isEqual(/x/, /y/), false);
9614 assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
9617 QUnit.test('should compare sets', function(assert) {
9621 lodashStable.each([[set, new Set], [set, realm.set]], function(sets) {
9627 assert.strictEqual(_.isEqual(set1, set2), false);
9631 assert.strictEqual(_.isEqual(set1, set2), true);
9635 assert.strictEqual(_.isEqual(set1, set2), true);
9638 assert.strictEqual(_.isEqual(set1, set2), false);
9645 skipAssert(assert, 8);
9649 QUnit.test('should compare sets with circular references', function(assert) {
9658 assert.strictEqual(_.isEqual(set1, set2), true);
9662 assert.strictEqual(_.isEqual(set1, set2), false);
9665 skipAssert(assert, 2);
9669 QUnit.test('should work as an iteratee for `_.every`', function(assert) {
9672 var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
9676 QUnit.test('should return `true` for like-objects from different documents', function(assert) {
9680 assert.strictEqual(_.isEqual([1], realm.array), true);
9681 assert.strictEqual(_.isEqual([2], realm.array), false);
9682 assert.strictEqual(_.isEqual({ 'a': 1 }, realm.object), true);
9683 assert.strictEqual(_.isEqual({ 'a': 2 }, realm.object), false);
9686 skipAssert(assert, 4);
9690 QUnit.test('should not error on DOM elements', function(assert) {
9694 var element1 = document.createElement('div'),
9695 element2 = element1.cloneNode(true);
9698 assert.strictEqual(_.isEqual(element1, element2), false);
9700 assert.ok(false, e.message);
9708 QUnit.test('should compare wrapped values', function(assert) {
9711 var stamp = +new Date;
9714 [[1, 2], [1, 2], [1, 2, 3]],
9715 [true, true, false],
9716 [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
9717 [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
9719 [NaN, NaN, Infinity],
9724 lodashStable.each(values, function(vals) {
9726 var wrapped1 = _(vals[0]),
9727 wrapped2 = _(vals[1]),
9728 actual = wrapped1.isEqual(wrapped2);
9730 assert.strictEqual(actual, true);
9731 assert.strictEqual(_.isEqual(_(actual), _(true)), true);
9733 wrapped1 = _(vals[0]);
9734 wrapped2 = _(vals[2]);
9736 actual = wrapped1.isEqual(wrapped2);
9737 assert.strictEqual(actual, false);
9738 assert.strictEqual(_.isEqual(_(actual), _(false)), true);
9741 skipAssert(assert, 4);
9746 QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
9750 var object1 = _({ 'a': 1, 'b': 2 }),
9751 object2 = { 'a': 1, 'b': 2 };
9753 assert.strictEqual(object1.isEqual(object2), true);
9754 assert.strictEqual(_.isEqual(object1, object2), true);
9756 object1 = _({ 'a': 1, 'b': 2 });
9757 object2 = { 'a': 1, 'b': 1 };
9759 assert.strictEqual(object1.isEqual(object2), false);
9760 assert.strictEqual(_.isEqual(object1, object2), false);
9763 skipAssert(assert, 4);
9767 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
9771 assert.strictEqual(_('a').isEqual('a'), true);
9778 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
9782 assert.ok(_('a').chain().isEqual('a') instanceof _);
9790 /*--------------------------------------------------------------------------*/
9792 QUnit.module('lodash.isEqualWith');
9795 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
9799 object1 = { 'a': [1, 2], 'b': null },
9800 object2 = { 'a': [1, 2], 'b': null };
9802 object1.b = object2;
9803 object2.b = object1;
9807 [object1.a, object2.a, 'a', object1, object2],
9808 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
9809 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
9810 [object1.b, object2.b, 'b', object1.b, object2.b],
9811 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
9812 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
9813 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
9814 [object1.b.b, object2.b.b, 'b', object1.b.b, object2.b.b]
9817 _.isEqualWith(object1, object2, function(assert) {
9818 var length = arguments.length,
9819 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
9821 argsList.push(args);
9824 assert.deepEqual(argsList, expected);
9827 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
9830 assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
9831 assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
9832 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
9835 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
9838 var customizer = function(value) {
9839 return _.isString(value) || undefined;
9842 assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
9843 assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
9844 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
9847 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
9850 var customizer = function(value) {
9851 return _.isString(value) ? false : undefined;
9854 assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
9855 assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
9856 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
9859 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
9862 var actual = _.isEqualWith('a', 'b', alwaysC);
9863 assert.strictEqual(actual, true);
9865 var values = _.without(falsey, undefined),
9866 expected = lodashStable.map(values, alwaysFalse);
9869 lodashStable.each(values, function(value) {
9870 actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
9873 assert.deepEqual(actual, expected);
9876 QUnit.test('should ensure `customizer` is a function', function(assert) {
9879 var array = [1, 2, 3],
9880 eq = _.partial(_.isEqualWith, array),
9881 actual = lodashStable.map([array, [1, 0, 3]], eq);
9883 assert.deepEqual(actual, [true, false]);
9886 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
9889 var value = { 'a': { 'b': 2 } };
9893 map1.set('a', value);
9896 map2.set('a', value);
9905 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
9908 array = _.toArray(pair[0]);
9912 [array[0], array[0], 0, array, array],
9913 [array[0][0], array[0][0], 0, array[0], array[0]],
9914 [array[0][1], array[0][1], 1, array[0], array[0]]
9918 expected.length = 2;
9920 _.isEqualWith(pair[0], pair[1], function() {
9921 var length = arguments.length,
9922 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
9924 argsList.push(args);
9927 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
9936 /*--------------------------------------------------------------------------*/
9938 QUnit.module('lodash.isError');
9941 var args = arguments;
9943 QUnit.test('should return `true` for error objects', function(assert) {
9946 var expected = lodashStable.map(errors, alwaysTrue);
9948 var actual = lodashStable.map(errors, function(error) {
9949 return _.isError(error) === true;
9952 assert.deepEqual(actual, expected);
9955 QUnit.test('should return `true` for subclassed values', function(assert) {
9958 assert.strictEqual(_.isError(new CustomError('x')), true);
9961 QUnit.test('should return `false` for non error objects', function(assert) {
9964 var expected = lodashStable.map(falsey, alwaysFalse);
9966 var actual = lodashStable.map(falsey, function(value, index) {
9967 return index ? _.isError(value) : _.isError();
9970 assert.deepEqual(actual, expected);
9972 assert.strictEqual(_.isError(args), false);
9973 assert.strictEqual(_.isError([1, 2, 3]), false);
9974 assert.strictEqual(_.isError(true), false);
9975 assert.strictEqual(_.isError(new Date), false);
9976 assert.strictEqual(_.isError(_), false);
9977 assert.strictEqual(_.isError(slice), false);
9978 assert.strictEqual(_.isError({ 'a': 1 }), false);
9979 assert.strictEqual(_.isError(1), false);
9980 assert.strictEqual(_.isError(/x/), false);
9981 assert.strictEqual(_.isError('a'), false);
9982 assert.strictEqual(_.isError(symbol), false);
9985 QUnit.test('should work with an error object from another realm', function(assert) {
9989 var expected = lodashStable.map(realm.errors, alwaysTrue);
9991 var actual = lodashStable.map(realm.errors, function(error) {
9992 return _.isError(error) === true;
9995 assert.deepEqual(actual, expected);
10003 /*--------------------------------------------------------------------------*/
10005 QUnit.module('lodash.isFinite');
10008 var args = arguments;
10010 QUnit.test('should return `true` for finite values', function(assert) {
10013 var values = [0, 1, 3.14, -1],
10014 expected = lodashStable.map(values, alwaysTrue),
10015 actual = lodashStable.map(values, _.isFinite);
10017 assert.deepEqual(actual, expected);
10020 QUnit.test('should return `false` for non-finite values', function(assert) {
10023 var values = [NaN, Infinity, -Infinity, Object(1)],
10024 expected = lodashStable.map(values, alwaysFalse),
10025 actual = lodashStable.map(values, _.isFinite);
10027 assert.deepEqual(actual, expected);
10030 QUnit.test('should return `false` for non-numeric values', function(assert) {
10033 var values = [undefined, [], true, '', ' ', '2px'],
10034 expected = lodashStable.map(values, alwaysFalse),
10035 actual = lodashStable.map(values, _.isFinite);
10037 assert.deepEqual(actual, expected);
10039 assert.strictEqual(_.isFinite(args), false);
10040 assert.strictEqual(_.isFinite([1, 2, 3]), false);
10041 assert.strictEqual(_.isFinite(true), false);
10042 assert.strictEqual(_.isFinite(new Date), false);
10043 assert.strictEqual(_.isFinite(new Error), false);
10044 assert.strictEqual(_.isFinite({ 'a': 1 }), false);
10045 assert.strictEqual(_.isFinite(/x/), false);
10046 assert.strictEqual(_.isFinite('a'), false);
10047 assert.strictEqual(_.isFinite(symbol), false);
10050 QUnit.test('should return `false` for numeric string values', function(assert) {
10053 var values = ['2', '0', '08'],
10054 expected = lodashStable.map(values, alwaysFalse),
10055 actual = lodashStable.map(values, _.isFinite);
10057 assert.deepEqual(actual, expected);
10061 /*--------------------------------------------------------------------------*/
10063 QUnit.module('lodash.isFunction');
10066 var args = arguments;
10068 QUnit.test('should return `true` for functions', function(assert) {
10071 assert.strictEqual(_.isFunction(_), true);
10072 assert.strictEqual(_.isFunction(slice), true);
10075 QUnit.test('should return `true` for generator functions', function(assert) {
10078 assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
10081 QUnit.test('should return `true` for array view constructors', function(assert) {
10084 var expected = lodashStable.map(arrayViews, function(type) {
10085 return objToString.call(root[type]) == funcTag;
10088 var actual = lodashStable.map(arrayViews, function(type) {
10089 return _.isFunction(root[type]);
10092 assert.deepEqual(actual, expected);
10095 QUnit.test('should return `false` for non-functions', function(assert) {
10098 var expected = lodashStable.map(falsey, alwaysFalse);
10100 var actual = lodashStable.map(falsey, function(value, index) {
10101 return index ? _.isFunction(value) : _.isFunction();
10104 assert.deepEqual(actual, expected);
10106 assert.strictEqual(_.isFunction(args), false);
10107 assert.strictEqual(_.isFunction([1, 2, 3]), false);
10108 assert.strictEqual(_.isFunction(true), false);
10109 assert.strictEqual(_.isFunction(new Date), false);
10110 assert.strictEqual(_.isFunction(new Error), false);
10111 assert.strictEqual(_.isFunction({ 'a': 1 }), false);
10112 assert.strictEqual(_.isFunction(1), false);
10113 assert.strictEqual(_.isFunction(/x/), false);
10114 assert.strictEqual(_.isFunction('a'), false);
10115 assert.strictEqual(_.isFunction(symbol), false);
10118 assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
10120 skipAssert(assert);
10124 QUnit.test('should work with host objects in IE 8 document mode (test in IE 11)', function(assert) {
10127 // Trigger a Chakra JIT bug.
10128 // See https://github.com/jashkenas/underscore/issues/1621.
10129 lodashStable.each([body, xml], function(object) {
10131 lodashStable.times(100, _.isFunction);
10132 assert.strictEqual(_.isFunction(object), false);
10135 skipAssert(assert);
10140 QUnit.test('should work with a function from another realm', function(assert) {
10143 if (realm.function) {
10144 assert.strictEqual(_.isFunction(realm.function), true);
10147 skipAssert(assert);
10152 /*--------------------------------------------------------------------------*/
10154 QUnit.module('isInteger methods');
10156 lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
10157 var args = arguments,
10158 func = _[methodName],
10159 isSafe = methodName == 'isSafeInteger';
10161 QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
10164 var values = [-1, 0, 1],
10165 expected = lodashStable.map(values, alwaysTrue);
10167 var actual = lodashStable.map(values, function(value) {
10168 return func(value);
10171 assert.deepEqual(actual, expected);
10172 assert.strictEqual(func(MAX_INTEGER), !isSafe);
10175 QUnit.test('should return `false` for non-integer number values', function(assert) {
10178 var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
10179 expected = lodashStable.map(values, alwaysFalse);
10181 var actual = lodashStable.map(values, function(value) {
10182 return func(value);
10185 assert.deepEqual(actual, expected);
10188 QUnit.test('should return `false` for non-numeric values', function(assert) {
10191 var expected = lodashStable.map(falsey, function(value) {
10192 return value === 0;
10195 var actual = lodashStable.map(falsey, function(value, index) {
10196 return index ? func(value) : func();
10199 assert.deepEqual(actual, expected);
10201 assert.strictEqual(func(args), false);
10202 assert.strictEqual(func([1, 2, 3]), false);
10203 assert.strictEqual(func(true), false);
10204 assert.strictEqual(func(new Date), false);
10205 assert.strictEqual(func(new Error), false);
10206 assert.strictEqual(func({ 'a': 1 }), false);
10207 assert.strictEqual(func(/x/), false);
10208 assert.strictEqual(func('a'), false);
10209 assert.strictEqual(func(symbol), false);
10213 /*--------------------------------------------------------------------------*/
10215 QUnit.module('lodash.isLength');
10218 QUnit.test('should return `true` for lengths', function(assert) {
10221 var values = [0, 3, MAX_SAFE_INTEGER],
10222 expected = lodashStable.map(values, alwaysTrue),
10223 actual = lodashStable.map(values, _.isLength);
10225 assert.deepEqual(actual, expected);
10228 QUnit.test('should return `false` for non-lengths', function(assert) {
10231 var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
10232 expected = lodashStable.map(values, alwaysFalse),
10233 actual = lodashStable.map(values, _.isLength);
10235 assert.deepEqual(actual, expected);
10239 /*--------------------------------------------------------------------------*/
10241 QUnit.module('lodash.isMap');
10244 var args = arguments;
10246 QUnit.test('should return `true` for maps', function(assert) {
10250 assert.strictEqual(_.isMap(map), true);
10253 skipAssert(assert);
10257 QUnit.test('should return `false` for non-maps', function(assert) {
10260 var expected = lodashStable.map(falsey, alwaysFalse);
10262 var actual = lodashStable.map(falsey, function(value, index) {
10263 return index ? _.isMap(value) : _.isMap();
10266 assert.deepEqual(actual, expected);
10268 assert.strictEqual(_.isMap(args), false);
10269 assert.strictEqual(_.isMap([1, 2, 3]), false);
10270 assert.strictEqual(_.isMap(true), false);
10271 assert.strictEqual(_.isMap(new Date), false);
10272 assert.strictEqual(_.isMap(new Error), false);
10273 assert.strictEqual(_.isMap(_), false);
10274 assert.strictEqual(_.isMap(slice), false);
10275 assert.strictEqual(_.isMap({ 'a': 1 }), false);
10276 assert.strictEqual(_.isMap(1), false);
10277 assert.strictEqual(_.isMap(/x/), false);
10278 assert.strictEqual(_.isMap('a'), false);
10279 assert.strictEqual(_.isMap(symbol), false);
10280 assert.strictEqual(_.isMap(weakMap), false);
10283 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
10286 var values = [false, true],
10287 expected = lodashStable.map(values, alwaysFalse);
10289 var actual = lodashStable.map(values, function(value) {
10290 return _.isMap({ 'constructor': value });
10293 assert.deepEqual(actual, expected);
10296 QUnit.test('should work with maps from another realm', function(assert) {
10300 assert.strictEqual(_.isMap(realm.map), true);
10303 skipAssert(assert);
10308 /*--------------------------------------------------------------------------*/
10310 QUnit.module('lodash.isMatch');
10313 QUnit.test('should perform a deep comparison between `object` and `source`', function(assert) {
10316 var object = { 'a': 1, 'b': 2, 'c': 3 };
10317 assert.strictEqual(_.isMatch(object, { 'a': 1 }), true);
10318 assert.strictEqual(_.isMatch(object, { 'b': 1 }), false);
10319 assert.strictEqual(_.isMatch(object, { 'a': 1, 'c': 3 }), true);
10320 assert.strictEqual(_.isMatch(object, { 'c': 3, 'd': 4 }), false);
10322 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
10323 assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true);
10326 QUnit.test('should match inherited string keyed `object` properties', function(assert) {
10332 Foo.prototype.b = 2;
10334 assert.strictEqual(_.isMatch({ 'a': new Foo }, { 'a': { 'b': 2 } }), true);
10337 QUnit.test('should not match by inherited `source` properties', function(assert) {
10343 Foo.prototype.b = 2;
10345 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
10347 expected = lodashStable.map(objects, alwaysTrue);
10349 var actual = lodashStable.map(objects, function(object) {
10350 return _.isMatch(object, source);
10353 assert.deepEqual(actual, expected);
10356 QUnit.test('should compare a variety of `source` property values', function(assert) {
10359 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
10360 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } };
10362 assert.strictEqual(_.isMatch(object1, object1), true);
10363 assert.strictEqual(_.isMatch(object1, object2), false);
10366 QUnit.test('should match `-0` as `0`', function(assert) {
10369 var object1 = { 'a': -0 },
10370 object2 = { 'a': 0 };
10372 assert.strictEqual(_.isMatch(object1, object2), true);
10373 assert.strictEqual(_.isMatch(object2, object1), true);
10376 QUnit.test('should compare functions by reference', function(assert) {
10379 var object1 = { 'a': lodashStable.noop },
10380 object2 = { 'a': noop },
10381 object3 = { 'a': {} };
10383 assert.strictEqual(_.isMatch(object1, object1), true);
10384 assert.strictEqual(_.isMatch(object2, object1), false);
10385 assert.strictEqual(_.isMatch(object3, object1), false);
10388 QUnit.test('should work with a function for `object`', function(assert) {
10392 Foo.a = { 'b': 1, 'c': 2 };
10394 assert.strictEqual(_.isMatch(Foo, { 'a': { 'b': 1 } }), true);
10397 QUnit.test('should work with a function for `source`', function(assert) {
10402 Foo.b = function() {};
10405 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }];
10407 var actual = lodashStable.map(objects, function(object) {
10408 return _.isMatch(object, Foo);
10411 assert.deepEqual(actual, [false, true]);
10414 QUnit.test('should work with a non-plain `object`', function(assert) {
10417 function Foo(object) { lodashStable.assign(this, object); }
10419 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) });
10420 assert.strictEqual(_.isMatch(object, { 'a': { 'b': 1 } }), true);
10423 QUnit.test('should partial match arrays', function(assert) {
10426 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
10427 source = { 'a': ['d'] },
10428 predicate = function(object) { return _.isMatch(object, source); },
10429 actual = lodashStable.filter(objects, predicate);
10431 assert.deepEqual(actual, [objects[1]]);
10433 source = { 'a': ['b', 'd'] };
10434 actual = lodashStable.filter(objects, predicate);
10436 assert.deepEqual(actual, []);
10438 source = { 'a': ['d', 'b'] };
10439 actual = lodashStable.filter(objects, predicate);
10440 assert.deepEqual(actual, []);
10443 QUnit.test('should partial match arrays of objects', function(assert) {
10446 var source = { 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] };
10449 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
10450 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
10453 var actual = lodashStable.filter(objects, function(object) {
10454 return _.isMatch(object, source);
10457 assert.deepEqual(actual, [objects[0]]);
10460 QUnit.test('should partial match maps', function(assert) {
10464 var objects = [{ 'a': new Map }, { 'a': new Map }];
10465 objects[0].a.set('a', 1);
10466 objects[1].a.set('a', 1);
10467 objects[1].a.set('b', 2);
10472 var source = { 'a': map },
10473 predicate = function(object) { return _.isMatch(object, source); },
10474 actual = lodashStable.filter(objects, predicate);
10476 assert.deepEqual(actual, [objects[1]]);
10478 map['delete']('b');
10479 actual = lodashStable.filter(objects, predicate);
10481 assert.deepEqual(actual, objects);
10484 actual = lodashStable.filter(objects, predicate);
10486 assert.deepEqual(actual, []);
10489 skipAssert(assert, 3);
10493 QUnit.test('should partial match sets', function(assert) {
10497 var objects = [{ 'a': new Set }, { 'a': new Set }];
10498 objects[0].a.add(1);
10499 objects[1].a.add(1);
10500 objects[1].a.add(2);
10505 var source = { 'a': set },
10506 predicate = function(object) { return _.isMatch(object, source); },
10507 actual = lodashStable.filter(objects, predicate);
10509 assert.deepEqual(actual, [objects[1]]);
10512 actual = lodashStable.filter(objects, predicate);
10514 assert.deepEqual(actual, objects);
10517 actual = lodashStable.filter(objects, predicate);
10519 assert.deepEqual(actual, []);
10522 skipAssert(assert, 3);
10526 QUnit.test('should match `undefined` values', function(assert) {
10529 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
10530 source = { 'b': undefined },
10531 predicate = function(object) { return _.isMatch(object, source); },
10532 actual = lodashStable.map(objects, predicate),
10533 expected = [false, false, true];
10535 assert.deepEqual(actual, expected);
10537 source = { 'a': 1, 'b': undefined };
10538 actual = lodashStable.map(objects, predicate);
10540 assert.deepEqual(actual, expected);
10542 objects = [{ 'a': { 'b': 1 } }, { 'a': { 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
10543 source = { 'a': { 'c': undefined } };
10544 actual = lodashStable.map(objects, predicate);
10546 assert.deepEqual(actual, expected);
10549 QUnit.test('should match `undefined` values on primitives', function(assert) {
10553 numberProto.b = undefined;
10556 assert.strictEqual(_.isMatch(1, { 'b': undefined }), true);
10558 assert.ok(false, e.message);
10561 assert.strictEqual(_.isMatch(1, { 'a': 1, 'b': undefined }), true);
10563 assert.ok(false, e.message);
10565 numberProto.a = { 'b': 1, 'c': undefined };
10567 assert.strictEqual(_.isMatch(1, { 'a': { 'c': undefined } }), true);
10569 assert.ok(false, e.message);
10571 delete numberProto.a;
10572 delete numberProto.b;
10575 QUnit.test('should return `false` when `object` is nullish', function(assert) {
10578 var values = [null, undefined],
10579 expected = lodashStable.map(values, alwaysFalse),
10580 source = { 'a': 1 };
10582 var actual = lodashStable.map(values, function(value) {
10584 return _.isMatch(value, source);
10588 assert.deepEqual(actual, expected);
10591 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
10594 var values = [null, undefined],
10595 expected = lodashStable.map(values, alwaysTrue),
10598 var actual = lodashStable.map(values, function(value) {
10600 return _.isMatch(value, source);
10604 assert.deepEqual(actual, expected);
10607 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
10610 var object = { 'a': 1 },
10611 expected = lodashStable.map(empties, alwaysTrue);
10613 var actual = lodashStable.map(empties, function(value) {
10614 return _.isMatch(object, value);
10617 assert.deepEqual(actual, expected);
10620 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
10623 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
10624 source = { 'a': [], 'b': {} };
10626 var actual = lodashStable.filter(objects, function(object) {
10627 return _.isMatch(object, source);
10630 assert.deepEqual(actual, objects);
10634 /*--------------------------------------------------------------------------*/
10636 QUnit.module('lodash.isMatchWith');
10639 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
10643 object1 = { 'a': [1, 2], 'b': null },
10644 object2 = { 'a': [1, 2], 'b': null };
10646 object1.b = object2;
10647 object2.b = object1;
10650 [object1.a, object2.a, 'a', object1, object2],
10651 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10652 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10653 [object1.b, object2.b, 'b', object1, object2],
10654 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
10655 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
10656 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
10657 [object1.b.b, object2.b.b, 'b', object1.b, object2.b],
10658 [object1.b.b.a, object2.b.b.a, 'a', object1.b.b, object2.b.b],
10659 [object1.b.b.a[0], object2.b.b.a[0], 0, object1.b.b.a, object2.b.b.a],
10660 [object1.b.b.a[1], object2.b.b.a[1], 1, object1.b.b.a, object2.b.b.a],
10661 [object1.b.b.b, object2.b.b.b, 'b', object1.b.b, object2.b.b]
10664 _.isMatchWith(object1, object2, function(assert) {
10665 argsList.push(slice.call(arguments, 0, -1));
10668 assert.deepEqual(argsList, expected);
10671 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
10674 assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
10677 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
10680 var customizer = function(value) {
10681 return _.isString(value) || undefined;
10684 assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
10685 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10688 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
10691 var customizer = function(value) {
10692 return _.isString(value) ? false : undefined;
10695 assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
10696 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10699 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
10702 var object = { 'a': 1 },
10703 actual = _.isMatchWith(object, { 'a': 1 }, alwaysA);
10705 assert.strictEqual(actual, true);
10707 var expected = lodashStable.map(falsey, alwaysFalse);
10710 lodashStable.each(falsey, function(value) {
10711 actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
10714 assert.deepEqual(actual, expected);
10717 QUnit.test('should ensure `customizer` is a function', function(assert) {
10720 var object = { 'a': 1 },
10721 matches = _.partial(_.isMatchWith, object),
10722 actual = lodashStable.map([object, { 'a': 2 }], matches);
10724 assert.deepEqual(actual, [true, false]);
10727 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
10730 var value = { 'a': { 'b': 2 } };
10733 var map1 = new Map;
10734 map1.set('a', value);
10736 var map2 = new Map;
10737 map2.set('a', value);
10740 var set1 = new Set;
10743 var set2 = new Set;
10746 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
10749 array = _.toArray(pair[0]),
10750 object1 = { 'a': pair[0] },
10751 object2 = { 'a': pair[1] };
10754 [pair[0], pair[1], 'a', object1, object2],
10755 [array[0], array[0], 0, array, array],
10756 [array[0][0], array[0][0], 0, array[0], array[0]],
10757 [array[0][1], array[0][1], 1, array[0], array[0]]
10761 expected.length = 2;
10763 _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
10764 argsList.push(slice.call(arguments, 0, -1));
10767 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
10770 skipAssert(assert);
10776 /*--------------------------------------------------------------------------*/
10778 QUnit.module('lodash.isNaN');
10781 var args = arguments;
10783 QUnit.test('should return `true` for NaNs', function(assert) {
10786 assert.strictEqual(_.isNaN(NaN), true);
10787 assert.strictEqual(_.isNaN(Object(NaN)), true);
10790 QUnit.test('should return `false` for non-NaNs', function(assert) {
10793 var expected = lodashStable.map(falsey, function(value) {
10794 return value !== value;
10797 var actual = lodashStable.map(falsey, function(value, index) {
10798 return index ? _.isNaN(value) : _.isNaN();
10801 assert.deepEqual(actual, expected);
10803 assert.strictEqual(_.isNaN(args), false);
10804 assert.strictEqual(_.isNaN([1, 2, 3]), false);
10805 assert.strictEqual(_.isNaN(true), false);
10806 assert.strictEqual(_.isNaN(new Date), false);
10807 assert.strictEqual(_.isNaN(new Error), false);
10808 assert.strictEqual(_.isNaN(_), false);
10809 assert.strictEqual(_.isNaN(slice), false);
10810 assert.strictEqual(_.isNaN({ 'a': 1 }), false);
10811 assert.strictEqual(_.isNaN(1), false);
10812 assert.strictEqual(_.isNaN(Object(1)), false);
10813 assert.strictEqual(_.isNaN(/x/), false);
10814 assert.strictEqual(_.isNaN('a'), false);
10815 assert.strictEqual(_.isNaN(symbol), false);
10818 QUnit.test('should work with `NaN` from another realm', function(assert) {
10821 if (realm.object) {
10822 assert.strictEqual(_.isNaN(realm.nan), true);
10825 skipAssert(assert);
10830 /*--------------------------------------------------------------------------*/
10832 QUnit.module('lodash.isNative');
10835 var args = arguments;
10837 QUnit.test('should return `true` for native methods', function(assert) {
10840 var values = [Array, body && body.cloneNode, create, root.encodeURI, Promise, slice, Uint8Array],
10841 expected = lodashStable.map(values, Boolean),
10842 actual = lodashStable.map(values, _.isNative);
10844 assert.deepEqual(actual, expected);
10847 QUnit.test('should return `false` for non-native methods', function(assert) {
10850 var expected = lodashStable.map(falsey, alwaysFalse);
10852 var actual = lodashStable.map(falsey, function(value, index) {
10853 return index ? _.isNative(value) : _.isNative();
10856 assert.deepEqual(actual, expected);
10858 assert.strictEqual(_.isNative(args), false);
10859 assert.strictEqual(_.isNative([1, 2, 3]), false);
10860 assert.strictEqual(_.isNative(true), false);
10861 assert.strictEqual(_.isNative(new Date), false);
10862 assert.strictEqual(_.isNative(new Error), false);
10863 assert.strictEqual(_.isNative(_), false);
10864 assert.strictEqual(_.isNative({ 'a': 1 }), false);
10865 assert.strictEqual(_.isNative(1), false);
10866 assert.strictEqual(_.isNative(/x/), false);
10867 assert.strictEqual(_.isNative('a'), false);
10868 assert.strictEqual(_.isNative(symbol), false);
10871 QUnit.test('should work with native functions from another realm', function(assert) {
10874 if (realm.element) {
10875 assert.strictEqual(_.isNative(realm.element.cloneNode), true);
10878 skipAssert(assert);
10880 if (realm.object) {
10881 assert.strictEqual(_.isNative(realm.object.valueOf), true);
10884 skipAssert(assert);
10889 /*--------------------------------------------------------------------------*/
10891 QUnit.module('lodash.isNil');
10894 var args = arguments;
10896 QUnit.test('should return `true` for nullish values', function(assert) {
10899 assert.strictEqual(_.isNil(null), true);
10900 assert.strictEqual(_.isNil(), true);
10901 assert.strictEqual(_.isNil(undefined), true);
10904 QUnit.test('should return `false` for non-nullish values', function(assert) {
10907 var expected = lodashStable.map(falsey, function(value) {
10908 return value == null;
10911 var actual = lodashStable.map(falsey, function(value, index) {
10912 return index ? _.isNil(value) : _.isNil();
10915 assert.deepEqual(actual, expected);
10917 assert.strictEqual(_.isNil(args), false);
10918 assert.strictEqual(_.isNil([1, 2, 3]), false);
10919 assert.strictEqual(_.isNil(true), false);
10920 assert.strictEqual(_.isNil(new Date), false);
10921 assert.strictEqual(_.isNil(new Error), false);
10922 assert.strictEqual(_.isNil(_), false);
10923 assert.strictEqual(_.isNil(slice), false);
10924 assert.strictEqual(_.isNil({ 'a': 1 }), false);
10925 assert.strictEqual(_.isNil(1), false);
10926 assert.strictEqual(_.isNil(/x/), false);
10927 assert.strictEqual(_.isNil('a'), false);
10930 assert.strictEqual(_.isNil(symbol), false);
10933 skipAssert(assert);
10937 QUnit.test('should work with nulls from another realm', function(assert) {
10940 if (realm.object) {
10941 assert.strictEqual(_.isNil(realm.null), true);
10942 assert.strictEqual(_.isNil(realm.undefined), true);
10945 skipAssert(assert, 2);
10950 /*--------------------------------------------------------------------------*/
10952 QUnit.module('lodash.isNull');
10955 var args = arguments;
10957 QUnit.test('should return `true` for `null` values', function(assert) {
10960 assert.strictEqual(_.isNull(null), true);
10963 QUnit.test('should return `false` for non `null` values', function(assert) {
10966 var expected = lodashStable.map(falsey, function(value) {
10967 return value === null;
10970 var actual = lodashStable.map(falsey, function(value, index) {
10971 return index ? _.isNull(value) : _.isNull();
10974 assert.deepEqual(actual, expected);
10976 assert.strictEqual(_.isNull(args), false);
10977 assert.strictEqual(_.isNull([1, 2, 3]), false);
10978 assert.strictEqual(_.isNull(true), false);
10979 assert.strictEqual(_.isNull(new Date), false);
10980 assert.strictEqual(_.isNull(new Error), false);
10981 assert.strictEqual(_.isNull(_), false);
10982 assert.strictEqual(_.isNull(slice), false);
10983 assert.strictEqual(_.isNull({ 'a': 1 }), false);
10984 assert.strictEqual(_.isNull(1), false);
10985 assert.strictEqual(_.isNull(/x/), false);
10986 assert.strictEqual(_.isNull('a'), false);
10987 assert.strictEqual(_.isNull(symbol), false);
10990 QUnit.test('should work with nulls from another realm', function(assert) {
10993 if (realm.object) {
10994 assert.strictEqual(_.isNull(realm.null), true);
10997 skipAssert(assert);
11002 /*--------------------------------------------------------------------------*/
11004 QUnit.module('lodash.isNumber');
11007 var args = arguments;
11009 QUnit.test('should return `true` for numbers', function(assert) {
11012 assert.strictEqual(_.isNumber(0), true);
11013 assert.strictEqual(_.isNumber(Object(0)), true);
11014 assert.strictEqual(_.isNumber(NaN), true);
11017 QUnit.test('should return `false` for non-numbers', function(assert) {
11020 var expected = lodashStable.map(falsey, function(value) {
11021 return typeof value == 'number';
11024 var actual = lodashStable.map(falsey, function(value, index) {
11025 return index ? _.isNumber(value) : _.isNumber();
11028 assert.deepEqual(actual, expected);
11030 assert.strictEqual(_.isNumber(args), false);
11031 assert.strictEqual(_.isNumber([1, 2, 3]), false);
11032 assert.strictEqual(_.isNumber(true), false);
11033 assert.strictEqual(_.isNumber(new Date), false);
11034 assert.strictEqual(_.isNumber(new Error), false);
11035 assert.strictEqual(_.isNumber(_), false);
11036 assert.strictEqual(_.isNumber(slice), false);
11037 assert.strictEqual(_.isNumber({ 'a': 1 }), false);
11038 assert.strictEqual(_.isNumber(/x/), false);
11039 assert.strictEqual(_.isNumber('a'), false);
11040 assert.strictEqual(_.isNumber(symbol), false);
11043 QUnit.test('should work with numbers from another realm', function(assert) {
11046 if (realm.number) {
11047 assert.strictEqual(_.isNumber(realm.number), true);
11050 skipAssert(assert);
11054 QUnit.test('should avoid `[xpconnect wrapped native prototype]` in Firefox', function(assert) {
11057 assert.strictEqual(_.isNumber(+'2'), true);
11061 /*--------------------------------------------------------------------------*/
11063 QUnit.module('lodash.isObject');
11066 var args = arguments;
11068 QUnit.test('should return `true` for objects', function(assert) {
11071 assert.strictEqual(_.isObject(args), true);
11072 assert.strictEqual(_.isObject([1, 2, 3]), true);
11073 assert.strictEqual(_.isObject(Object(false)), true);
11074 assert.strictEqual(_.isObject(new Date), true);
11075 assert.strictEqual(_.isObject(new Error), true);
11076 assert.strictEqual(_.isObject(_), true);
11077 assert.strictEqual(_.isObject(slice), true);
11078 assert.strictEqual(_.isObject({ 'a': 1 }), true);
11079 assert.strictEqual(_.isObject(Object(0)), true);
11080 assert.strictEqual(_.isObject(/x/), true);
11081 assert.strictEqual(_.isObject(Object('a')), true);
11084 assert.strictEqual(_.isObject(body), true);
11087 skipAssert(assert);
11090 assert.strictEqual(_.isObject(Object(symbol)), true);
11093 skipAssert(assert);
11097 QUnit.test('should return `false` for non-objects', function(assert) {
11100 var values = falsey.concat(true, 1, 'a', symbol),
11101 expected = lodashStable.map(values, alwaysFalse);
11103 var actual = lodashStable.map(values, function(value, index) {
11104 return index ? _.isObject(value) : _.isObject();
11107 assert.deepEqual(actual, expected);
11110 QUnit.test('should work with objects from another realm', function(assert) {
11113 if (realm.element) {
11114 assert.strictEqual(_.isObject(realm.element), true);
11117 skipAssert(assert);
11119 if (realm.object) {
11120 assert.strictEqual(_.isObject(realm.boolean), true);
11121 assert.strictEqual(_.isObject(realm.date), true);
11122 assert.strictEqual(_.isObject(realm.function), true);
11123 assert.strictEqual(_.isObject(realm.number), true);
11124 assert.strictEqual(_.isObject(realm.object), true);
11125 assert.strictEqual(_.isObject(realm.regexp), true);
11126 assert.strictEqual(_.isObject(realm.string), true);
11129 skipAssert(assert, 7);
11133 QUnit.test('should avoid V8 bug #2291 (test in Chrome 19-20)', function(assert) {
11136 // Trigger a V8 JIT bug.
11137 // See https://code.google.com/p/v8/issues/detail?id=2291.
11140 // First, have a comparison statement.
11143 // Then perform the check with `object`.
11144 _.isObject(object);
11146 assert.strictEqual(_.isObject('a'), false);
11150 /*--------------------------------------------------------------------------*/
11152 QUnit.module('lodash.isObjectLike');
11155 var args = arguments;
11157 QUnit.test('should return `true` for objects', function(assert) {
11160 assert.strictEqual(_.isObjectLike(args), true);
11161 assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
11162 assert.strictEqual(_.isObjectLike(Object(false)), true);
11163 assert.strictEqual(_.isObjectLike(new Date), true);
11164 assert.strictEqual(_.isObjectLike(new Error), true);
11165 assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
11166 assert.strictEqual(_.isObjectLike(Object(0)), true);
11167 assert.strictEqual(_.isObjectLike(/x/), true);
11168 assert.strictEqual(_.isObjectLike(Object('a')), true);
11171 QUnit.test('should return `false` for non-objects', function(assert) {
11174 var values = falsey.concat(true, _, slice, 1, 'a', symbol),
11175 expected = lodashStable.map(values, alwaysFalse);
11177 var actual = lodashStable.map(values, function(value, index) {
11178 return index ? _.isObjectLike(value) : _.isObjectLike();
11181 assert.deepEqual(actual, expected);
11184 QUnit.test('should work with objects from another realm', function(assert) {
11187 if (realm.object) {
11188 assert.strictEqual(_.isObjectLike(realm.boolean), true);
11189 assert.strictEqual(_.isObjectLike(realm.date), true);
11190 assert.strictEqual(_.isObjectLike(realm.number), true);
11191 assert.strictEqual(_.isObjectLike(realm.object), true);
11192 assert.strictEqual(_.isObjectLike(realm.regexp), true);
11193 assert.strictEqual(_.isObjectLike(realm.string), true);
11196 skipAssert(assert, 6);
11201 /*--------------------------------------------------------------------------*/
11203 QUnit.module('lodash.isPlainObject');
11206 var element = document && document.createElement('div');
11208 QUnit.test('should detect plain objects', function(assert) {
11215 assert.strictEqual(_.isPlainObject({}), true);
11216 assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
11217 assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
11218 assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
11219 assert.strictEqual(_.isPlainObject(new Foo(1)), false);
11222 QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
11226 var object = create(null);
11227 assert.strictEqual(_.isPlainObject(object), true);
11229 object.constructor = objectProto.constructor;
11230 assert.strictEqual(_.isPlainObject(object), true);
11233 skipAssert(assert, 2);
11237 QUnit.test('should return `true` for plain objects with a custom `valueOf` property', function(assert) {
11240 assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
11243 var valueOf = element.valueOf;
11244 element.valueOf = 0;
11246 assert.strictEqual(_.isPlainObject(element), false);
11247 element.valueOf = valueOf;
11250 skipAssert(assert);
11254 QUnit.test('should return `false` for objects with a custom `[[Prototype]]`', function(assert) {
11258 var object = create({ 'a': 1 });
11259 assert.strictEqual(_.isPlainObject(object), false);
11262 skipAssert(assert);
11266 QUnit.test('should return `false` for DOM elements', function(assert) {
11270 assert.strictEqual(_.isPlainObject(element), false);
11272 skipAssert(assert);
11276 QUnit.test('should return `false` for Object objects without a `toStringTag` of "Object"', function(assert) {
11279 assert.strictEqual(_.isPlainObject(arguments), false);
11280 assert.strictEqual(_.isPlainObject(Error), false);
11281 assert.strictEqual(_.isPlainObject(Math), false);
11284 QUnit.test('should return `false` for non-objects', function(assert) {
11287 var expected = lodashStable.map(falsey, alwaysFalse);
11289 var actual = lodashStable.map(falsey, function(value, index) {
11290 return index ? _.isPlainObject(value) : _.isPlainObject();
11293 assert.deepEqual(actual, expected);
11295 assert.strictEqual(_.isPlainObject(true), false);
11296 assert.strictEqual(_.isPlainObject('a'), false);
11297 assert.strictEqual(_.isPlainObject(symbol), false);
11300 QUnit.test('should work with objects from another realm', function(assert) {
11303 if (realm.object) {
11304 assert.strictEqual(_.isPlainObject(realm.object), true);
11307 skipAssert(assert);
11312 /*--------------------------------------------------------------------------*/
11314 QUnit.module('lodash.isRegExp');
11317 var args = arguments;
11319 QUnit.test('should return `true` for regexes', function(assert) {
11322 assert.strictEqual(_.isRegExp(/x/), true);
11323 assert.strictEqual(_.isRegExp(RegExp('x')), true);
11326 QUnit.test('should return `false` for non-regexes', function(assert) {
11329 var expected = lodashStable.map(falsey, alwaysFalse);
11331 var actual = lodashStable.map(falsey, function(value, index) {
11332 return index ? _.isRegExp(value) : _.isRegExp();
11335 assert.deepEqual(actual, expected);
11337 assert.strictEqual(_.isRegExp(args), false);
11338 assert.strictEqual(_.isRegExp([1, 2, 3]), false);
11339 assert.strictEqual(_.isRegExp(true), false);
11340 assert.strictEqual(_.isRegExp(new Date), false);
11341 assert.strictEqual(_.isRegExp(new Error), false);
11342 assert.strictEqual(_.isRegExp(_), false);
11343 assert.strictEqual(_.isRegExp(slice), false);
11344 assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
11345 assert.strictEqual(_.isRegExp(1), false);
11346 assert.strictEqual(_.isRegExp('a'), false);
11347 assert.strictEqual(_.isRegExp(symbol), false);
11350 QUnit.test('should work with regexes from another realm', function(assert) {
11353 if (realm.regexp) {
11354 assert.strictEqual(_.isRegExp(realm.regexp), true);
11357 skipAssert(assert);
11362 /*--------------------------------------------------------------------------*/
11364 QUnit.module('lodash.isSet');
11367 var args = arguments;
11369 QUnit.test('should return `true` for sets', function(assert) {
11373 assert.strictEqual(_.isSet(set), true);
11376 skipAssert(assert);
11380 QUnit.test('should return `false` for non-sets', function(assert) {
11383 var expected = lodashStable.map(falsey, alwaysFalse);
11385 var actual = lodashStable.map(falsey, function(value, index) {
11386 return index ? _.isSet(value) : _.isSet();
11389 assert.deepEqual(actual, expected);
11391 assert.strictEqual(_.isSet(args), false);
11392 assert.strictEqual(_.isSet([1, 2, 3]), false);
11393 assert.strictEqual(_.isSet(true), false);
11394 assert.strictEqual(_.isSet(new Date), false);
11395 assert.strictEqual(_.isSet(new Error), false);
11396 assert.strictEqual(_.isSet(_), false);
11397 assert.strictEqual(_.isSet(slice), false);
11398 assert.strictEqual(_.isSet({ 'a': 1 }), false);
11399 assert.strictEqual(_.isSet(1), false);
11400 assert.strictEqual(_.isSet(/x/), false);
11401 assert.strictEqual(_.isSet('a'), false);
11402 assert.strictEqual(_.isSet(symbol), false);
11403 assert.strictEqual(_.isSet(weakSet), false);
11406 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
11409 var values = [false, true],
11410 expected = lodashStable.map(values, alwaysFalse);
11412 var actual = lodashStable.map(values, function(value) {
11413 return _.isSet({ 'constructor': value });
11416 assert.deepEqual(actual, expected);
11419 QUnit.test('should work with weak sets from another realm', function(assert) {
11423 assert.strictEqual(_.isSet(realm.set), true);
11426 skipAssert(assert);
11431 /*--------------------------------------------------------------------------*/
11433 QUnit.module('lodash.isString');
11436 var args = arguments;
11438 QUnit.test('should return `true` for strings', function(assert) {
11441 assert.strictEqual(_.isString('a'), true);
11442 assert.strictEqual(_.isString(Object('a')), true);
11445 QUnit.test('should return `false` for non-strings', function(assert) {
11448 var expected = lodashStable.map(falsey, function(value) {
11449 return value === '';
11452 var actual = lodashStable.map(falsey, function(value, index) {
11453 return index ? _.isString(value) : _.isString();
11456 assert.deepEqual(actual, expected);
11458 assert.strictEqual(_.isString(args), false);
11459 assert.strictEqual(_.isString([1, 2, 3]), false);
11460 assert.strictEqual(_.isString(true), false);
11461 assert.strictEqual(_.isString(new Date), false);
11462 assert.strictEqual(_.isString(new Error), false);
11463 assert.strictEqual(_.isString(_), false);
11464 assert.strictEqual(_.isString(slice), false);
11465 assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
11466 assert.strictEqual(_.isString(1), false);
11467 assert.strictEqual(_.isString(/x/), false);
11468 assert.strictEqual(_.isString(symbol), false);
11471 QUnit.test('should work with strings from another realm', function(assert) {
11474 if (realm.string) {
11475 assert.strictEqual(_.isString(realm.string), true);
11478 skipAssert(assert);
11483 /*--------------------------------------------------------------------------*/
11485 QUnit.module('lodash.isSymbol');
11488 var args = arguments;
11490 QUnit.test('should return `true` for symbols', function(assert) {
11494 assert.strictEqual(_.isSymbol(symbol), true);
11495 assert.strictEqual(_.isSymbol(Object(symbol)), true);
11498 skipAssert(assert, 2);
11502 QUnit.test('should return `false` for non-symbols', function(assert) {
11505 var expected = lodashStable.map(falsey, alwaysFalse);
11507 var actual = lodashStable.map(falsey, function(value, index) {
11508 return index ? _.isSymbol(value) : _.isSymbol();
11511 assert.deepEqual(actual, expected);
11513 assert.strictEqual(_.isSymbol(args), false);
11514 assert.strictEqual(_.isSymbol([1, 2, 3]), false);
11515 assert.strictEqual(_.isSymbol(true), false);
11516 assert.strictEqual(_.isSymbol(new Date), false);
11517 assert.strictEqual(_.isSymbol(new Error), false);
11518 assert.strictEqual(_.isSymbol(_), false);
11519 assert.strictEqual(_.isSymbol(slice), false);
11520 assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
11521 assert.strictEqual(_.isSymbol(1), false);
11522 assert.strictEqual(_.isSymbol(/x/), false);
11523 assert.strictEqual(_.isSymbol('a'), false);
11526 QUnit.test('should work with symbols from another realm', function(assert) {
11529 if (Symbol && realm.symbol) {
11530 assert.strictEqual(_.isSymbol(realm.symbol), true);
11533 skipAssert(assert);
11538 /*--------------------------------------------------------------------------*/
11540 QUnit.module('lodash.isTypedArray');
11543 var args = arguments;
11545 QUnit.test('should return `true` for typed arrays', function(assert) {
11548 var expected = lodashStable.map(typedArrays, function(type) {
11549 return type in root;
11552 var actual = lodashStable.map(typedArrays, function(type) {
11553 var Ctor = root[type];
11554 return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
11557 assert.deepEqual(actual, expected);
11560 QUnit.test('should return `false` for non typed arrays', function(assert) {
11563 var expected = lodashStable.map(falsey, alwaysFalse);
11565 var actual = lodashStable.map(falsey, function(value, index) {
11566 return index ? _.isTypedArray(value) : _.isTypedArray();
11569 assert.deepEqual(actual, expected);
11571 assert.strictEqual(_.isTypedArray(args), false);
11572 assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
11573 assert.strictEqual(_.isTypedArray(true), false);
11574 assert.strictEqual(_.isTypedArray(new Date), false);
11575 assert.strictEqual(_.isTypedArray(new Error), false);
11576 assert.strictEqual(_.isTypedArray(_), false);
11577 assert.strictEqual(_.isTypedArray(slice), false);
11578 assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
11579 assert.strictEqual(_.isTypedArray(1), false);
11580 assert.strictEqual(_.isTypedArray(/x/), false);
11581 assert.strictEqual(_.isTypedArray('a'), false);
11582 assert.strictEqual(_.isTypedArray(symbol), false);
11585 QUnit.test('should work with typed arrays from another realm', function(assert) {
11588 if (realm.object) {
11589 var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
11591 var expected = lodashStable.map(props, function(key) {
11592 return realm[key] !== undefined;
11595 var actual = lodashStable.map(props, function(key) {
11596 var value = realm[key];
11597 return value ? _.isTypedArray(value) : false;
11600 assert.deepEqual(actual, expected);
11603 skipAssert(assert);
11608 /*--------------------------------------------------------------------------*/
11610 QUnit.module('lodash.isUndefined');
11613 var args = arguments;
11615 QUnit.test('should return `true` for `undefined` values', function(assert) {
11618 assert.strictEqual(_.isUndefined(), true);
11619 assert.strictEqual(_.isUndefined(undefined), true);
11622 QUnit.test('should return `false` for non `undefined` values', function(assert) {
11625 var expected = lodashStable.map(falsey, function(value) {
11626 return value === undefined;
11629 var actual = lodashStable.map(falsey, function(value, index) {
11630 return index ? _.isUndefined(value) : _.isUndefined();
11633 assert.deepEqual(actual, expected);
11635 assert.strictEqual(_.isUndefined(args), false);
11636 assert.strictEqual(_.isUndefined([1, 2, 3]), false);
11637 assert.strictEqual(_.isUndefined(true), false);
11638 assert.strictEqual(_.isUndefined(new Date), false);
11639 assert.strictEqual(_.isUndefined(new Error), false);
11640 assert.strictEqual(_.isUndefined(_), false);
11641 assert.strictEqual(_.isUndefined(slice), false);
11642 assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
11643 assert.strictEqual(_.isUndefined(1), false);
11644 assert.strictEqual(_.isUndefined(/x/), false);
11645 assert.strictEqual(_.isUndefined('a'), false);
11648 assert.strictEqual(_.isUndefined(symbol), false);
11651 skipAssert(assert);
11655 QUnit.test('should work with `undefined` from another realm', function(assert) {
11658 if (realm.object) {
11659 assert.strictEqual(_.isUndefined(realm.undefined), true);
11662 skipAssert(assert);
11667 /*--------------------------------------------------------------------------*/
11669 QUnit.module('lodash.isWeakMap');
11672 var args = arguments;
11674 QUnit.test('should return `true` for weak maps', function(assert) {
11678 assert.strictEqual(_.isWeakMap(weakMap), true);
11681 skipAssert(assert);
11685 QUnit.test('should return `false` for non weak maps', function(assert) {
11688 var expected = lodashStable.map(falsey, alwaysFalse);
11690 var actual = lodashStable.map(falsey, function(value, index) {
11691 return index ? _.isWeakMap(value) : _.isWeakMap();
11694 assert.deepEqual(actual, expected);
11696 assert.strictEqual(_.isWeakMap(args), false);
11697 assert.strictEqual(_.isWeakMap([1, 2, 3]), false);
11698 assert.strictEqual(_.isWeakMap(true), false);
11699 assert.strictEqual(_.isWeakMap(new Date), false);
11700 assert.strictEqual(_.isWeakMap(new Error), false);
11701 assert.strictEqual(_.isWeakMap(_), false);
11702 assert.strictEqual(_.isWeakMap(slice), false);
11703 assert.strictEqual(_.isWeakMap({ 'a': 1 }), false);
11704 assert.strictEqual(_.isWeakMap(map), false);
11705 assert.strictEqual(_.isWeakMap(1), false);
11706 assert.strictEqual(_.isWeakMap(/x/), false);
11707 assert.strictEqual(_.isWeakMap('a'), false);
11708 assert.strictEqual(_.isWeakMap(symbol), false);
11711 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
11714 var values = [false, true],
11715 expected = lodashStable.map(values, alwaysFalse);
11717 var actual = lodashStable.map(values, function(value) {
11718 return _.isWeakMap({ 'constructor': value });
11721 assert.deepEqual(actual, expected);
11724 QUnit.test('should work with weak maps from another realm', function(assert) {
11727 if (realm.weakMap) {
11728 assert.strictEqual(_.isWeakMap(realm.weakMap), true);
11731 skipAssert(assert);
11736 /*--------------------------------------------------------------------------*/
11738 QUnit.module('lodash.isWeakSet');
11741 var args = arguments;
11743 QUnit.test('should return `true` for weak sets', function(assert) {
11747 assert.strictEqual(_.isWeakSet(weakSet), true);
11750 skipAssert(assert);
11754 QUnit.test('should return `false` for non weak sets', function(assert) {
11757 var expected = lodashStable.map(falsey, alwaysFalse);
11759 var actual = lodashStable.map(falsey, function(value, index) {
11760 return index ? _.isWeakSet(value) : _.isWeakSet();
11763 assert.deepEqual(actual, expected);
11765 assert.strictEqual(_.isWeakSet(args), false);
11766 assert.strictEqual(_.isWeakSet([1, 2, 3]), false);
11767 assert.strictEqual(_.isWeakSet(true), false);
11768 assert.strictEqual(_.isWeakSet(new Date), false);
11769 assert.strictEqual(_.isWeakSet(new Error), false);
11770 assert.strictEqual(_.isWeakSet(_), false);
11771 assert.strictEqual(_.isWeakSet(slice), false);
11772 assert.strictEqual(_.isWeakSet({ 'a': 1 }), false);
11773 assert.strictEqual(_.isWeakSet(1), false);
11774 assert.strictEqual(_.isWeakSet(/x/), false);
11775 assert.strictEqual(_.isWeakSet('a'), false);
11776 assert.strictEqual(_.isWeakSet(set), false);
11777 assert.strictEqual(_.isWeakSet(symbol), false);
11780 QUnit.test('should work with weak sets from another realm', function(assert) {
11783 if (realm.weakSet) {
11784 assert.strictEqual(_.isWeakSet(realm.weakSet), true);
11787 skipAssert(assert);
11792 /*--------------------------------------------------------------------------*/
11794 QUnit.module('isType checks');
11797 QUnit.test('should return `false` for subclassed values', function(assert) {
11801 'isArray', 'isBoolean', 'isDate', 'isFunction',
11802 'isNumber', 'isRegExp', 'isString'
11805 lodashStable.each(funcs, function(methodName) {
11807 Foo.prototype = root[methodName.slice(2)].prototype;
11809 var object = new Foo;
11810 if (objToString.call(object) == objectTag) {
11811 assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
11814 skipAssert(assert);
11819 QUnit.test('should not error on host objects (test in IE)', function(assert) {
11823 'isArguments', 'isArray', 'isArrayBuffer', 'isArrayLike', 'isBoolean',
11824 'isBuffer', 'isDate', 'isElement', 'isError', 'isFinite', 'isFunction',
11825 'isInteger', 'isMap', 'isNaN', 'isNil', 'isNull', 'isNumber', 'isObject',
11826 'isObjectLike', 'isRegExp', 'isSet', 'isSafeInteger', 'isString',
11827 'isUndefined', 'isWeakMap', 'isWeakSet'
11830 lodashStable.each(funcs, function(methodName) {
11835 _[methodName](xml);
11839 assert.ok(pass, '`_.' + methodName + '` should not error');
11842 skipAssert(assert);
11848 /*--------------------------------------------------------------------------*/
11850 QUnit.module('lodash.iteratee');
11853 QUnit.test('should provide arguments to `func`', function(assert) {
11856 var fn = function() { return slice.call(arguments); },
11857 iteratee = _.iteratee(fn),
11858 actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
11860 assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
11863 QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
11867 values = [, null, undefined],
11868 expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
11870 var actual = lodashStable.map(values, function(value, index) {
11871 var identity = index ? _.iteratee(value) : _.iteratee();
11872 return [!isNpm && identity, identity(object)];
11875 assert.deepEqual(actual, expected);
11878 QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
11881 var matches = _.iteratee({ 'a': 1, 'b': 2 });
11882 assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
11883 assert.strictEqual(matches({ 'b': 2 }), false);
11886 QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
11890 { 'a': { 'b': 2, 'c': 3 } },
11891 { 'a': 1, 'b': 2 },
11895 lodashStable.each(sources, function(source, index) {
11896 var object = lodashStable.cloneDeep(source),
11897 matches = _.iteratee(source);
11899 assert.strictEqual(matches(object), true);
11910 assert.strictEqual(matches(object), true);
11911 assert.strictEqual(matches(source), false);
11915 QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
11918 var array = ['a', undefined],
11919 matches = _.iteratee([0, 'a']);
11921 assert.strictEqual(matches(array), true);
11923 matches = _.iteratee(['0', 'a']);
11924 assert.strictEqual(matches(array), true);
11926 matches = _.iteratee([1, undefined]);
11927 assert.strictEqual(matches(array), true);
11930 QUnit.test('should support deep paths for `_.matchesProperty` shorthands', function(assert) {
11933 var object = { 'a': { 'b': { 'c': 1, 'd': 2 } } },
11934 matches = _.iteratee(['a.b', { 'c': 1 }]);
11936 assert.strictEqual(matches(object), true);
11939 QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
11943 { 'a': { 'b': 2, 'c': 3 } },
11944 { 'a': 1, 'b': 2 },
11948 lodashStable.each(sources, function(source, index) {
11949 var object = { 'a': lodashStable.cloneDeep(source) },
11950 matches = _.iteratee(['a', source]);
11952 assert.strictEqual(matches(object), true);
11963 assert.strictEqual(matches(object), true);
11964 assert.strictEqual(matches({ 'a': source }), false);
11968 QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
11972 prop = _.iteratee(0);
11974 assert.strictEqual(prop(array), 'a');
11976 prop = _.iteratee('0');
11977 assert.strictEqual(prop(array), 'a');
11980 QUnit.test('should support deep paths for `_.property` shorthands', function(assert) {
11983 var object = { 'a': { 'b': 2 } },
11984 prop = _.iteratee('a.b');
11986 assert.strictEqual(prop(object), 2);
11989 QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
11992 var fn = function() {
11993 var result = [this.a];
11994 push.apply(result, arguments);
11998 var expected = [1, 2, 3],
11999 object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
12001 assert.deepEqual(object.iteratee(3), expected);
12003 object.iteratee = _.iteratee(_.partialRight(fn, 3));
12004 assert.deepEqual(object.iteratee(2), expected);
12007 QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
12010 var iteratee = _.iteratee;
12013 assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
12015 _.iteratee = iteratee;
12018 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
12021 var fn = function() { return this instanceof Number; },
12022 array = [fn, fn, fn],
12023 iteratees = lodashStable.map(array, _.iteratee),
12024 expected = lodashStable.map(array, alwaysFalse);
12026 var actual = lodashStable.map(iteratees, function(iteratee) {
12030 assert.deepEqual(actual, expected);
12034 /*--------------------------------------------------------------------------*/
12036 QUnit.module('custom `_.iteratee` methods');
12039 var array = ['one', 'two', 'three'],
12040 getPropA = _.partial(_.property, 'a'),
12041 getPropB = _.partial(_.property, 'b'),
12042 getLength = _.partial(_.property, 'length'),
12043 iteratee = _.iteratee;
12045 var getSum = function() {
12046 return function(result, object) {
12047 return result + object.a;
12052 { 'a': 0, 'b': 0 },
12053 { 'a': 1, 'b': 0 },
12057 QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
12060 if (!isModularize) {
12061 _.iteratee = getLength;
12062 assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
12063 _.iteratee = iteratee;
12066 skipAssert(assert);
12070 QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
12073 if (!isModularize) {
12074 _.iteratee = getPropA;
12075 assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
12076 _.iteratee = iteratee;
12079 skipAssert(assert);
12083 QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
12086 if (!isModularize) {
12087 _.iteratee = getPropB;
12088 assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
12089 _.iteratee = iteratee;
12092 skipAssert(assert);
12096 QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
12099 if (!isModularize) {
12100 _.iteratee = getPropB;
12101 assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
12102 _.iteratee = iteratee;
12105 skipAssert(assert);
12109 QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
12112 if (!isModularize) {
12113 _.iteratee = getPropA;
12114 assert.strictEqual(_.every(objects.slice(1)), true);
12115 _.iteratee = iteratee;
12118 skipAssert(assert);
12122 QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
12125 if (!isModularize) {
12126 var objects = [{ 'a': 0 }, { 'a': 1 }];
12128 _.iteratee = getPropA;
12129 assert.deepEqual(_.filter(objects), [objects[1]]);
12130 _.iteratee = iteratee;
12133 skipAssert(assert);
12137 QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
12140 if (!isModularize) {
12141 _.iteratee = getPropA;
12142 assert.strictEqual(_.find(objects), objects[1]);
12143 _.iteratee = iteratee;
12146 skipAssert(assert);
12150 QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
12153 if (!isModularize) {
12154 _.iteratee = getPropA;
12155 assert.strictEqual(_.findIndex(objects), 1);
12156 _.iteratee = iteratee;
12159 skipAssert(assert);
12163 QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
12166 if (!isModularize) {
12167 _.iteratee = getPropA;
12168 assert.strictEqual(_.findLast(objects), objects[2]);
12169 _.iteratee = iteratee;
12172 skipAssert(assert);
12176 QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
12179 if (!isModularize) {
12180 _.iteratee = getPropA;
12181 assert.strictEqual(_.findLastIndex(objects), 2);
12182 _.iteratee = iteratee;
12185 skipAssert(assert);
12189 QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
12192 if (!isModularize) {
12193 _.iteratee = getPropB;
12194 assert.strictEqual(_.findKey(objects), '2');
12195 _.iteratee = iteratee;
12198 skipAssert(assert);
12202 QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
12205 if (!isModularize) {
12206 _.iteratee = getPropB;
12207 assert.strictEqual(_.findLastKey(objects), '2');
12208 _.iteratee = iteratee;
12211 skipAssert(assert);
12215 QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
12218 if (!isModularize) {
12219 _.iteratee = getLength;
12220 assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
12221 _.iteratee = iteratee;
12224 skipAssert(assert);
12228 QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
12231 if (!isModularize) {
12232 _.iteratee = getPropA;
12233 assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
12234 _.iteratee = iteratee;
12237 skipAssert(assert);
12241 QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
12244 if (!isModularize) {
12245 _.iteratee = getLength;
12246 assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
12247 _.iteratee = iteratee;
12250 skipAssert(assert);
12254 QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
12257 if (!isModularize) {
12258 _.iteratee = getPropA;
12259 assert.deepEqual(_.map(objects), [0, 1, 1]);
12260 _.iteratee = iteratee;
12263 skipAssert(assert);
12267 QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
12270 if (!isModularize) {
12271 _.iteratee = getPropB;
12272 assert.deepEqual(_.mapKeys({ 'a': { 'b': 1 } }), { '1': { 'b': 1 } });
12273 _.iteratee = iteratee;
12276 skipAssert(assert);
12280 QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
12283 if (!isModularize) {
12284 _.iteratee = getPropB;
12285 assert.deepEqual(_.mapValues({ 'a': { 'b': 1 } }), { 'a': 1 });
12286 _.iteratee = iteratee;
12289 skipAssert(assert);
12293 QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
12296 if (!isModularize) {
12297 _.iteratee = getPropB;
12298 assert.deepEqual(_.maxBy(objects), objects[2]);
12299 _.iteratee = iteratee;
12302 skipAssert(assert);
12306 QUnit.test('`_.meanBy` should use `_.iteratee` internally', function(assert) {
12309 if (!isModularize) {
12310 _.iteratee = getPropA;
12311 assert.strictEqual(_.meanBy(objects), 2 / 3);
12312 _.iteratee = iteratee;
12315 skipAssert(assert);
12319 QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
12322 if (!isModularize) {
12323 _.iteratee = getPropB;
12324 assert.deepEqual(_.minBy(objects), objects[0]);
12325 _.iteratee = iteratee;
12328 skipAssert(assert);
12332 QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
12335 if (!isModularize) {
12336 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
12338 _.iteratee = getPropA;
12339 assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
12340 _.iteratee = iteratee;
12343 skipAssert(assert);
12347 QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
12350 if (!isModularize) {
12351 _.iteratee = getPropA;
12352 assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
12353 _.iteratee = iteratee;
12356 skipAssert(assert);
12360 QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
12363 if (!isModularize) {
12364 _.iteratee = getSum;
12365 assert.strictEqual(_.reduce(objects, undefined, 0), 2);
12366 _.iteratee = iteratee;
12369 skipAssert(assert);
12373 QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
12376 if (!isModularize) {
12377 _.iteratee = getSum;
12378 assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
12379 _.iteratee = iteratee;
12382 skipAssert(assert);
12386 QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
12389 if (!isModularize) {
12390 var objects = [{ 'a': 0 }, { 'a': 1 }];
12392 _.iteratee = getPropA;
12393 assert.deepEqual(_.reject(objects), [objects[0]]);
12394 _.iteratee = iteratee;
12397 skipAssert(assert);
12401 QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
12404 if (!isModularize) {
12405 var objects = [{ 'a': 0 }, { 'a': 1 }];
12407 _.iteratee = getPropA;
12409 assert.deepEqual(objects, [{ 'a': 0 }]);
12410 _.iteratee = iteratee;
12413 skipAssert(assert);
12417 QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
12420 if (!isModularize) {
12421 _.iteratee = getPropB;
12422 assert.strictEqual(_.some(objects), true);
12423 _.iteratee = iteratee;
12426 skipAssert(assert);
12430 QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
12433 if (!isModularize) {
12434 _.iteratee = getPropA;
12435 assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
12436 _.iteratee = iteratee;
12439 skipAssert(assert);
12443 QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
12446 if (!isModularize) {
12447 var objects = [{ 'a': 30 }, { 'a': 50 }];
12449 _.iteratee = getPropA;
12450 assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
12451 _.iteratee = iteratee;
12454 skipAssert(assert);
12458 QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
12461 if (!isModularize) {
12462 var objects = [{ 'a': 30 }, { 'a': 50 }];
12464 _.iteratee = getPropA;
12465 assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
12466 _.iteratee = iteratee;
12469 skipAssert(assert);
12473 QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
12476 if (!isModularize) {
12477 _.iteratee = getPropB;
12478 assert.strictEqual(_.sumBy(objects), 1);
12479 _.iteratee = iteratee;
12482 skipAssert(assert);
12486 QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
12489 if (!isModularize) {
12490 _.iteratee = getPropB;
12491 assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
12492 _.iteratee = iteratee;
12495 skipAssert(assert);
12499 QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
12502 if (!isModularize) {
12503 _.iteratee = getPropB;
12504 assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
12505 _.iteratee = iteratee;
12508 skipAssert(assert);
12512 QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
12515 if (!isModularize) {
12516 _.iteratee = function() {
12517 return function(result, object) {
12518 result.sum += object.a;
12522 assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
12523 _.iteratee = iteratee;
12526 skipAssert(assert);
12530 QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
12533 if (!isModularize) {
12534 _.iteratee = getPropB;
12535 assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
12536 _.iteratee = iteratee;
12539 skipAssert(assert);
12543 QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
12546 if (!isModularize) {
12547 _.iteratee = getPropB;
12548 assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
12549 _.iteratee = iteratee;
12552 skipAssert(assert);
12556 QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
12559 if (!isModularize) {
12560 _.iteratee = getPropA;
12561 assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
12562 _.iteratee = iteratee;
12565 skipAssert(assert);
12570 /*--------------------------------------------------------------------------*/
12572 QUnit.module('lodash.join');
12575 var array = ['a', 'b', 'c'];
12577 QUnit.test('should return join all array elements into a string', function(assert) {
12580 assert.strictEqual(_.join(array, '~'), 'a~b~c');
12583 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12587 var wrapped = _(array);
12588 assert.strictEqual(wrapped.join('~'), 'a~b~c');
12589 assert.strictEqual(wrapped.value(), array);
12592 skipAssert(assert, 2);
12596 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12600 assert.ok(_(array).chain().join('~') instanceof _);
12603 skipAssert(assert);
12608 /*--------------------------------------------------------------------------*/
12610 QUnit.module('lodash.keyBy');
12614 { 'dir': 'left', 'code': 97 },
12615 { 'dir': 'right', 'code': 100 }
12618 QUnit.test('should transform keys by `iteratee`', function(assert) {
12621 var expected = { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } };
12623 var actual = _.keyBy(array, function(object) {
12624 return String.fromCharCode(object.code);
12627 assert.deepEqual(actual, expected);
12630 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
12633 var array = [4, 6, 6],
12634 values = [, null, undefined],
12635 expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
12637 var actual = lodashStable.map(values, function(value, index) {
12638 return index ? _.keyBy(array, value) : _.keyBy(array);
12641 assert.deepEqual(actual, expected);
12644 QUnit.test('should work with `_.property` shorthands', function(assert) {
12647 var expected = { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } },
12648 actual = _.keyBy(array, 'dir');
12650 assert.deepEqual(actual, expected);
12653 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
12656 var actual = _.keyBy([6.1, 4.2, 6.3], function(n) {
12657 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
12660 assert.deepEqual(actual.constructor, 4.2);
12661 assert.deepEqual(actual.hasOwnProperty, 6.3);
12664 QUnit.test('should work with a number for `iteratee`', function(assert) {
12673 assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
12674 assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
12677 QUnit.test('should work with an object for `collection`', function(assert) {
12680 var actual = _.keyBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
12681 assert.deepEqual(actual, { '4': 4.2, '6': 6.3 });
12684 QUnit.test('should work in a lazy sequence', function(assert) {
12688 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
12689 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
12690 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
12693 var actual = _(array).keyBy().map(square).filter(isEven).take().value();
12695 assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
12698 skipAssert(assert);
12703 /*--------------------------------------------------------------------------*/
12705 QUnit.module('keys methods');
12707 lodashStable.each(['keys', 'keysIn'], function(methodName) {
12708 var args = (function() { return arguments; }(1, 2, 3)),
12709 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
12710 func = _[methodName],
12711 isKeys = methodName == 'keys';
12713 QUnit.test('`_.' + methodName + '` should return the string keyed property names of `object`', function(assert) {
12716 var actual = func({ 'a': 1, 'b': 1 }).sort();
12718 assert.deepEqual(actual, ['a', 'b']);
12721 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties', function(assert) {
12727 Foo.prototype.b = 2;
12729 var expected = isKeys ? ['a'] : ['a', 'b'],
12730 actual = func(new Foo).sort();
12732 assert.deepEqual(actual, expected);
12735 QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
12738 var expected = lodashStable.map(primitives, function(value) {
12739 return typeof value == 'string' ? ['0'] : [];
12742 var actual = lodashStable.map(primitives, func);
12743 assert.deepEqual(actual, expected);
12745 // IE 9 doesn't box numbers in for-in loops.
12747 assert.deepEqual(func(0), isKeys ? [] : ['a']);
12748 delete numberProto.a;
12751 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
12757 var actual = func(array).sort();
12759 assert.deepEqual(actual, ['0', '1', '2']);
12762 QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) {
12766 lodashStable.each([null, undefined], function(value) {
12767 assert.deepEqual(func(value), []);
12769 delete objectProto.a;
12772 QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
12778 var actual = func(array).sort();
12780 assert.deepEqual(actual, ['0', 'a']);
12783 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of arrays', function(assert) {
12788 var expected = isKeys ? ['0'] : ['0', 'a'],
12789 actual = func([1]).sort();
12791 assert.deepEqual(actual, expected);
12793 delete arrayProto.a;
12796 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
12799 var values = [args, strictArgs],
12800 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2']));
12802 var actual = lodashStable.map(values, function(value) {
12803 return func(value).sort();
12806 assert.deepEqual(actual, expected);
12809 QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
12812 var values = [args, strictArgs],
12813 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
12815 var actual = lodashStable.map(values, function(value) {
12817 var result = func(value).sort();
12822 assert.deepEqual(actual, expected);
12825 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of `arguments` objects', function(assert) {
12828 var values = [args, strictArgs],
12829 expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
12831 var actual = lodashStable.map(values, function(value) {
12833 var result = func(value).sort();
12834 delete objectProto.a;
12838 assert.deepEqual(actual, expected);
12841 QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
12844 var actual = func(Object('abc')).sort();
12846 assert.deepEqual(actual, ['0', '1', '2']);
12849 QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
12852 var object = Object('a');
12855 var actual = func(object).sort();
12857 assert.deepEqual(actual, ['0', 'a']);
12860 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of string objects', function(assert) {
12865 var expected = isKeys ? ['0'] : ['0', 'a'],
12866 actual = func(Object('a')).sort();
12868 assert.deepEqual(actual, expected);
12870 delete stringProto.a;
12873 QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
12877 Foo.prototype.a = 1;
12879 var expected = ['a'];
12880 assert.deepEqual(func(Foo.prototype), expected);
12882 Foo.prototype = { 'constructor': Foo, 'a': 1 };
12883 assert.deepEqual(func(Foo.prototype), expected);
12885 var Fake = { 'prototype': {} };
12886 Fake.prototype.constructor = Fake;
12887 assert.deepEqual(func(Fake.prototype), ['constructor']);
12891 /*--------------------------------------------------------------------------*/
12893 QUnit.module('lodash.last');
12896 var array = [1, 2, 3, 4];
12898 QUnit.test('should return the last element', function(assert) {
12901 assert.strictEqual(_.last(array), 4);
12904 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
12910 assert.strictEqual(_.last([]), undefined);
12913 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
12916 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
12917 actual = lodashStable.map(array, _.last);
12919 assert.deepEqual(actual, [3, 6, 9]);
12922 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12926 assert.strictEqual(_(array).last(), 4);
12929 skipAssert(assert);
12933 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12937 assert.ok(_(array).chain().last() instanceof _);
12940 skipAssert(assert);
12944 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
12948 var wrapped = _(array).chain().last();
12949 assert.strictEqual(wrapped.__wrapped__, array);
12952 skipAssert(assert);
12956 QUnit.test('should work in a lazy sequence', function(assert) {
12960 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
12961 smallArray = array;
12963 lodashStable.times(2, function(index) {
12964 var array = index ? largeArray : smallArray,
12965 wrapped = _(array).filter(isEven);
12967 assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
12971 skipAssert(assert, 2);
12976 /*--------------------------------------------------------------------------*/
12978 QUnit.module('lodash.lowerCase');
12981 QUnit.test('should lowercase as space-separated words', function(assert) {
12984 assert.strictEqual(_.lowerCase('--Foo-Bar--'), 'foo bar');
12985 assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
12986 assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
12990 /*--------------------------------------------------------------------------*/
12992 QUnit.module('lodash.lowerFirst');
12995 QUnit.test('should lowercase only the first character', function(assert) {
12998 assert.strictEqual(_.lowerFirst('fred'), 'fred');
12999 assert.strictEqual(_.lowerFirst('Fred'), 'fred');
13000 assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
13004 /*--------------------------------------------------------------------------*/
13006 QUnit.module('lodash.lt');
13009 QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
13012 assert.strictEqual(_.lt(1, 3), true);
13013 assert.strictEqual(_.lt('abc', 'def'), true);
13016 QUnit.test('should return `false` if `value` >= `other`', function(assert) {
13019 assert.strictEqual(_.lt(3, 1), false);
13020 assert.strictEqual(_.lt(3, 3), false);
13021 assert.strictEqual(_.lt('def', 'abc'), false);
13022 assert.strictEqual(_.lt('def', 'def'), false);
13026 /*--------------------------------------------------------------------------*/
13028 QUnit.module('lodash.lte');
13031 QUnit.test('should return `true` if `value` is <= `other`', function(assert) {
13034 assert.strictEqual(_.lte(1, 3), true);
13035 assert.strictEqual(_.lte(3, 3), true);
13036 assert.strictEqual(_.lte('abc', 'def'), true);
13037 assert.strictEqual(_.lte('def', 'def'), true);
13040 QUnit.test('should return `false` if `value` > `other`', function(assert) {
13043 assert.strictEqual(_.lt(3, 1), false);
13044 assert.strictEqual(_.lt('def', 'abc'), false);
13048 /*--------------------------------------------------------------------------*/
13050 QUnit.module('lodash.lastIndexOf');
13053 var array = [1, 2, 3, 1, 2, 3];
13055 QUnit.test('should return the index of the last matched value', function(assert) {
13058 assert.strictEqual(_.lastIndexOf(array, 3), 5);
13061 QUnit.test('should work with a positive `fromIndex`', function(assert) {
13064 assert.strictEqual(_.lastIndexOf(array, 1, 2), 0);
13067 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
13070 var values = [6, 8, Math.pow(2, 32), Infinity],
13071 expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
13073 var actual = lodashStable.map(values, function(fromIndex) {
13075 _.lastIndexOf(array, undefined, fromIndex),
13076 _.lastIndexOf(array, 1, fromIndex),
13077 _.lastIndexOf(array, '', fromIndex)
13081 assert.deepEqual(actual, expected);
13084 QUnit.test('should work with a negative `fromIndex`', function(assert) {
13087 assert.strictEqual(_.lastIndexOf(array, 2, -3), 1);
13090 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
13093 var values = [-6, -8, -Infinity],
13094 expected = lodashStable.map(values, alwaysZero);
13096 var actual = lodashStable.map(values, function(fromIndex) {
13097 return _.lastIndexOf(array, 1, fromIndex);
13100 assert.deepEqual(actual, expected);
13103 QUnit.test('should treat falsey `fromIndex` values correctly', function(assert) {
13106 var expected = lodashStable.map(falsey, function(value) {
13107 return value === undefined ? 5 : -1;
13110 var actual = lodashStable.map(falsey, function(fromIndex) {
13111 return _.lastIndexOf(array, 3, fromIndex);
13114 assert.deepEqual(actual, expected);
13117 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
13120 assert.strictEqual(_.lastIndexOf(array, 2, 4.2), 4);
13124 /*--------------------------------------------------------------------------*/
13126 QUnit.module('indexOf methods');
13128 lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
13129 var func = _[methodName],
13130 isIndexOf = !/last/i.test(methodName),
13131 isSorted = /^sorted/.test(methodName);
13133 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument', function(assert) {
13136 var expected = lodashStable.map(falsey, lodashStable.constant(-1));
13138 var actual = lodashStable.map(falsey, function(array, index) {
13140 return index ? func(array) : func();
13144 assert.deepEqual(actual, expected);
13147 QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
13150 var array = [1, 2, 3],
13153 assert.strictEqual(func(array, 4), -1);
13154 assert.strictEqual(func(array, 4, true), -1);
13155 assert.strictEqual(func(array, undefined, true), -1);
13157 assert.strictEqual(func(empty, undefined), -1);
13158 assert.strictEqual(func(empty, undefined, true), -1);
13161 QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
13167 assert.strictEqual(func(array, undefined), -1);
13168 assert.strictEqual(func(array, 0, true), -1);
13171 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
13174 var array = isSorted
13176 : [1, NaN, 3, NaN, 5, NaN];
13179 assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
13180 skipAssert(assert, 2);
13183 assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
13184 assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
13185 assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
13189 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
13192 assert.strictEqual(func([-0], 0), 0);
13193 assert.strictEqual(func([0], -0), 0);
13197 /*--------------------------------------------------------------------------*/
13199 QUnit.module('lodash.map');
13202 var array = [1, 2];
13204 QUnit.test('should map values in `collection` to a new array', function(assert) {
13207 var object = { 'a': 1, 'b': 2 },
13208 expected = ['1', '2'];
13210 assert.deepEqual(_.map(array, String), expected);
13211 assert.deepEqual(_.map(object, String), expected);
13214 QUnit.test('should work with `_.property` shorthands', function(assert) {
13217 var objects = [{ 'a': 'x' }, { 'a': 'y' }];
13218 assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
13221 QUnit.test('should iterate over own string keyed properties of objects', function(assert) {
13227 Foo.prototype.b = 2;
13229 var actual = _.map(new Foo, identity);
13230 assert.deepEqual(actual, [1]);
13233 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13236 var object = { 'a': 1, 'b': 2 },
13237 values = [, null, undefined],
13238 expected = lodashStable.map(values, lodashStable.constant([1, 2]));
13240 lodashStable.each([array, object], function(collection) {
13241 var actual = lodashStable.map(values, function(value, index) {
13242 return index ? _.map(collection, value) : _.map(collection);
13245 assert.deepEqual(actual, expected);
13249 QUnit.test('should accept a falsey `collection` argument', function(assert) {
13252 var expected = lodashStable.map(falsey, alwaysEmptyArray);
13254 var actual = lodashStable.map(falsey, function(collection, index) {
13256 return index ? _.map(collection) : _.map();
13260 assert.deepEqual(actual, expected);
13263 QUnit.test('should treat number values for `collection` as empty', function(assert) {
13266 assert.deepEqual(_.map(1), []);
13269 QUnit.test('should treat a nodelist as an array-like object', function(assert) {
13273 var actual = _.map(document.getElementsByTagName('body'), function(element) {
13274 return element.nodeName.toLowerCase();
13277 assert.deepEqual(actual, ['body']);
13280 skipAssert(assert);
13284 QUnit.test('should work with objects with non-number length properties', function(assert) {
13287 var value = { 'value': 'x' },
13288 object = { 'length': { 'value': 'x' } };
13290 assert.deepEqual(_.map(object, identity), [value]);
13293 QUnit.test('should return a wrapped value when chaining', function(assert) {
13297 assert.ok(_(array).map(noop) instanceof _);
13300 skipAssert(assert);
13304 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
13309 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
13310 expected = [1, 0, _.map(array.slice(1), square)];
13312 _(array).slice(1).map(function(value, index, array) {
13313 args || (args = slice.call(arguments));
13316 assert.deepEqual(args, [1, 0, array.slice(1)]);
13319 _(array).slice(1).map(square).map(function(value, index, array) {
13320 args || (args = slice.call(arguments));
13323 assert.deepEqual(args, expected);
13326 _(array).slice(1).map(square).map(function(value, index) {
13327 args || (args = slice.call(arguments));
13330 assert.deepEqual(args, expected);
13333 _(array).slice(1).map(square).map(function(value) {
13334 args || (args = slice.call(arguments));
13337 assert.deepEqual(args, [1]);
13340 _(array).slice(1).map(square).map(function() {
13341 args || (args = slice.call(arguments));
13344 assert.deepEqual(args, expected);
13347 skipAssert(assert, 5);
13352 /*--------------------------------------------------------------------------*/
13354 QUnit.module('lodash.mapKeys');
13357 var array = [1, 2],
13358 object = { 'a': 1, 'b': 2 };
13360 QUnit.test('should map keys in `object` to a new object', function(assert) {
13363 var actual = _.mapKeys(object, String);
13364 assert.deepEqual(actual, { '1': 1, '2': 2 });
13367 QUnit.test('should treat arrays like objects', function(assert) {
13370 var actual = _.mapKeys(array, String);
13371 assert.deepEqual(actual, { '1': 1, '2': 2 });
13374 QUnit.test('should work with `_.property` shorthands', function(assert) {
13377 var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
13378 assert.deepEqual(actual, { 'c': { 'b': 'c' } });
13381 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13384 var object = { 'a': 1, 'b': 2 },
13385 values = [, null, undefined],
13386 expected = lodashStable.map(values, lodashStable.constant({ '1': 1, '2': 2 }));
13388 var actual = lodashStable.map(values, function(value, index) {
13389 return index ? _.mapKeys(object, value) : _.mapKeys(object);
13392 assert.deepEqual(actual, expected);
13396 /*--------------------------------------------------------------------------*/
13398 QUnit.module('lodash.mapValues');
13401 var array = [1, 2],
13402 object = { 'a': 1, 'b': 2 };
13404 QUnit.test('should map values in `object` to a new object', function(assert) {
13407 var actual = _.mapValues(object, String);
13408 assert.deepEqual(actual, { 'a': '1', 'b': '2' });
13411 QUnit.test('should treat arrays like objects', function(assert) {
13414 var actual = _.mapValues(array, String);
13415 assert.deepEqual(actual, { '0': '1', '1': '2' });
13418 QUnit.test('should work with `_.property` shorthands', function(assert) {
13421 var actual = _.mapValues({ 'a': { 'b': 1 } }, 'b');
13422 assert.deepEqual(actual, { 'a': 1 });
13425 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13428 var object = { 'a': 1, 'b': 2 },
13429 values = [, null, undefined],
13430 expected = lodashStable.map(values, lodashStable.constant([true, false]));
13432 var actual = lodashStable.map(values, function(value, index) {
13433 var result = index ? _.mapValues(object, value) : _.mapValues(object);
13434 return [lodashStable.isEqual(result, object), result === object];
13437 assert.deepEqual(actual, expected);
13441 /*--------------------------------------------------------------------------*/
13443 QUnit.module('lodash.mapKeys and lodash.mapValues');
13445 lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
13446 var func = _[methodName],
13447 object = { 'a': 1, 'b': 2 };
13449 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
13455 Foo.prototype.b = 'b';
13457 var actual = func(new Foo, function(value, key) { return key; });
13458 assert.deepEqual(actual, { 'a': 'a' });
13461 QUnit.test('`_.' + methodName + '` should accept a falsey `object` argument', function(assert) {
13464 var expected = lodashStable.map(falsey, alwaysEmptyObject);
13466 var actual = lodashStable.map(falsey, function(object, index) {
13468 return index ? func(object) : func();
13472 assert.deepEqual(actual, expected);
13475 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
13479 assert.ok(_(object)[methodName](noop) instanceof _);
13482 skipAssert(assert);
13487 /*--------------------------------------------------------------------------*/
13489 QUnit.module('lodash.matches');
13492 QUnit.test('should create a function that performs a deep comparison between `source` and a given object', function(assert) {
13495 var object = { 'a': 1, 'b': 2, 'c': 3 },
13496 matches = _.matches({ 'a': 1 });
13498 assert.strictEqual(matches.length, 1);
13499 assert.strictEqual(matches(object), true);
13501 matches = _.matches({ 'b': 1 });
13502 assert.strictEqual(matches(object), false);
13504 matches = _.matches({ 'a': 1, 'c': 3 });
13505 assert.strictEqual(matches(object), true);
13507 matches = _.matches({ 'c': 3, 'd': 4 });
13508 assert.strictEqual(matches(object), false);
13510 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
13511 matches = _.matches({ 'a': { 'b': { 'c': 1 } } });
13513 assert.strictEqual(matches(object), true);
13516 QUnit.test('should match inherited string keyed `object` properties', function(assert) {
13522 Foo.prototype.b = 2;
13524 var object = { 'a': new Foo },
13525 matches = _.matches({ 'a': { 'b': 2 } });
13527 assert.strictEqual(matches(object), true);
13530 QUnit.test('should not match by inherited `source` properties', function(assert) {
13536 Foo.prototype.b = 2;
13538 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
13540 actual = lodashStable.map(objects, _.matches(source)),
13541 expected = lodashStable.map(objects, alwaysTrue);
13543 assert.deepEqual(actual, expected);
13546 QUnit.test('should compare a variety of `source` property values', function(assert) {
13549 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
13550 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
13551 matches = _.matches(object1);
13553 assert.strictEqual(matches(object1), true);
13554 assert.strictEqual(matches(object2), false);
13557 QUnit.test('should match `-0` as `0`', function(assert) {
13560 var object1 = { 'a': -0 },
13561 object2 = { 'a': 0 },
13562 matches = _.matches(object1);
13564 assert.strictEqual(matches(object2), true);
13566 matches = _.matches(object2);
13567 assert.strictEqual(matches(object1), true);
13570 QUnit.test('should compare functions by reference', function(assert) {
13573 var object1 = { 'a': lodashStable.noop },
13574 object2 = { 'a': noop },
13575 object3 = { 'a': {} },
13576 matches = _.matches(object1);
13578 assert.strictEqual(matches(object1), true);
13579 assert.strictEqual(matches(object2), false);
13580 assert.strictEqual(matches(object3), false);
13583 QUnit.test('should work with a function for `object`', function(assert) {
13587 Foo.a = { 'b': 1, 'c': 2 };
13589 var matches = _.matches({ 'a': { 'b': 1 } });
13590 assert.strictEqual(matches(Foo), true);
13593 QUnit.test('should work with a function for `source`', function(assert) {
13598 Foo.b = function() {};
13601 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
13602 actual = lodashStable.map(objects, _.matches(Foo));
13604 assert.deepEqual(actual, [false, true]);
13607 QUnit.test('should work with a non-plain `object`', function(assert) {
13610 function Foo(object) { lodashStable.assign(this, object); }
13612 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
13613 matches = _.matches({ 'a': { 'b': 1 } });
13615 assert.strictEqual(matches(object), true);
13618 QUnit.test('should partial match arrays', function(assert) {
13621 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
13622 actual = lodashStable.filter(objects, _.matches({ 'a': ['d'] }));
13624 assert.deepEqual(actual, [objects[1]]);
13626 actual = lodashStable.filter(objects, _.matches({ 'a': ['b', 'd'] }));
13627 assert.deepEqual(actual, []);
13629 actual = lodashStable.filter(objects, _.matches({ 'a': ['d', 'b'] }));
13630 assert.deepEqual(actual, []);
13633 QUnit.test('should partial match arrays of objects', function(assert) {
13637 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
13638 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
13641 var actual = lodashStable.filter(objects, _.matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
13642 assert.deepEqual(actual, [objects[0]]);
13645 QUnit.test('should partial match maps', function(assert) {
13649 var objects = [{ 'a': new Map }, { 'a': new Map }];
13650 objects[0].a.set('a', 1);
13651 objects[1].a.set('a', 1);
13652 objects[1].a.set('b', 2);
13656 var actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13658 assert.deepEqual(actual, [objects[1]]);
13660 map['delete']('b');
13661 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13663 assert.deepEqual(actual, objects);
13666 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13668 assert.deepEqual(actual, []);
13671 skipAssert(assert, 3);
13675 QUnit.test('should partial match sets', function(assert) {
13679 var objects = [{ 'a': new Set }, { 'a': new Set }];
13680 objects[0].a.add(1);
13681 objects[1].a.add(1);
13682 objects[1].a.add(2);
13686 var actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13688 assert.deepEqual(actual, [objects[1]]);
13691 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13693 assert.deepEqual(actual, objects);
13696 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13698 assert.deepEqual(actual, []);
13701 skipAssert(assert, 3);
13705 QUnit.test('should match `undefined` values', function(assert) {
13708 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
13709 actual = lodashStable.map(objects, _.matches({ 'b': undefined })),
13710 expected = [false, false, true];
13712 assert.deepEqual(actual, expected);
13714 actual = lodashStable.map(objects, _.matches({ 'a': 1, 'b': undefined }));
13716 assert.deepEqual(actual, expected);
13718 objects = [{ 'a': { 'b': 1 } }, { 'a': { 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
13719 actual = lodashStable.map(objects, _.matches({ 'a': { 'c': undefined } }));
13721 assert.deepEqual(actual, expected);
13724 QUnit.test('should match `undefined` values on primitives', function(assert) {
13728 numberProto.b = undefined;
13731 var matches = _.matches({ 'b': undefined });
13732 assert.strictEqual(matches(1), true);
13734 assert.ok(false, e.message);
13737 matches = _.matches({ 'a': 1, 'b': undefined });
13738 assert.strictEqual(matches(1), true);
13740 assert.ok(false, e.message);
13742 numberProto.a = { 'b': 1, 'c': undefined };
13744 matches = _.matches({ 'a': { 'c': undefined } });
13745 assert.strictEqual(matches(1), true);
13747 assert.ok(false, e.message);
13749 delete numberProto.a;
13750 delete numberProto.b;
13753 QUnit.test('should return `false` when `object` is nullish', function(assert) {
13756 var values = [, null, undefined],
13757 expected = lodashStable.map(values, alwaysFalse),
13758 matches = _.matches({ 'a': 1 });
13760 var actual = lodashStable.map(values, function(value, index) {
13762 return index ? matches(value) : matches();
13766 assert.deepEqual(actual, expected);
13769 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
13772 var values = [, null, undefined],
13773 expected = lodashStable.map(values, alwaysTrue),
13774 matches = _.matches({});
13776 var actual = lodashStable.map(values, function(value, index) {
13778 return index ? matches(value) : matches();
13782 assert.deepEqual(actual, expected);
13785 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
13788 var object = { 'a': 1 },
13789 expected = lodashStable.map(empties, alwaysTrue);
13791 var actual = lodashStable.map(empties, function(value) {
13792 var matches = _.matches(value);
13793 return matches(object);
13796 assert.deepEqual(actual, expected);
13799 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
13802 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
13803 actual = lodashStable.filter(objects, _.matches({ 'a': [], 'b': {} }));
13805 assert.deepEqual(actual, objects);
13808 QUnit.test('should not change behavior if `source` is modified', function(assert) {
13812 { 'a': { 'b': 2, 'c': 3 } },
13813 { 'a': 1, 'b': 2 },
13817 lodashStable.each(sources, function(source, index) {
13818 var object = lodashStable.cloneDeep(source),
13819 matches = _.matches(source);
13821 assert.strictEqual(matches(object), true);
13832 assert.strictEqual(matches(object), true);
13833 assert.strictEqual(matches(source), false);
13838 /*--------------------------------------------------------------------------*/
13840 QUnit.module('lodash.matchesProperty');
13843 QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
13846 var object = { 'a': 1, 'b': 2, 'c': 3 },
13847 matches = _.matchesProperty('a', 1);
13849 assert.strictEqual(matches.length, 1);
13850 assert.strictEqual(matches(object), true);
13852 matches = _.matchesProperty('b', 3);
13853 assert.strictEqual(matches(object), false);
13855 matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
13856 assert.strictEqual(matches({ 'a': object }), true);
13858 matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
13859 assert.strictEqual(matches(object), false);
13861 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
13862 matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
13864 assert.strictEqual(matches(object), true);
13867 QUnit.test('should support deep paths', function(assert) {
13870 var object = { 'a': { 'b': 2 } };
13872 lodashStable.each(['a.b', ['a', 'b']], function(path) {
13873 var matches = _.matchesProperty(path, 2);
13874 assert.strictEqual(matches(object), true);
13878 QUnit.test('should work with a non-string `path`', function(assert) {
13881 var array = [1, 2, 3];
13883 lodashStable.each([1, [1]], function(path) {
13884 var matches = _.matchesProperty(path, 2);
13885 assert.strictEqual(matches(array), true);
13889 QUnit.test('should preserve the sign of `0`', function(assert) {
13892 var object1 = { '-0': 'a' },
13893 object2 = { '0': 'b' },
13894 pairs = [[object1, object2], [object1, object2], [object2, object1], [object2, object1]],
13895 props = [-0, Object(-0), 0, Object(0)],
13896 values = ['a', 'a', 'b', 'b'],
13897 expected = lodashStable.map(props, lodashStable.constant([true, false]));
13899 var actual = lodashStable.map(props, function(key, index) {
13900 var matches = _.matchesProperty(key, values[index]),
13901 pair = pairs[index];
13903 return [matches(pair[0]), matches(pair[1])];
13906 assert.deepEqual(actual, expected);
13909 QUnit.test('should coerce key to a string', function(assert) {
13913 fn.toString = lodashStable.constant('fn');
13915 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
13916 values = [null, undefined, fn, {}];
13918 var expected = lodashStable.transform(values, function(result) {
13919 result.push(true, true);
13922 var actual = lodashStable.transform(objects, function(result, object, index) {
13923 var key = values[index];
13924 lodashStable.each([key, [key]], function(path) {
13925 var matches = _.matchesProperty(path, object[key]);
13926 result.push(matches(object));
13930 assert.deepEqual(actual, expected);
13933 QUnit.test('should match a key over a path', function(assert) {
13936 var object = { 'a.b': 1, 'a': { 'b': 2 } };
13938 lodashStable.each(['a.b', ['a.b']], function(path) {
13939 var matches = _.matchesProperty(path, 1);
13940 assert.strictEqual(matches(object), true);
13944 QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
13949 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
13950 var matches = _.matchesProperty(path, 1);
13951 assert.strictEqual(matches(object), false);
13955 QUnit.test('should return `false` for deep paths when `object` is nullish', function(assert) {
13958 var values = [, null, undefined],
13959 expected = lodashStable.map(values, alwaysFalse);
13961 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
13962 var matches = _.matchesProperty(path, 1);
13964 var actual = lodashStable.map(values, function(value, index) {
13966 return index ? matches(value) : matches();
13970 assert.deepEqual(actual, expected);
13974 QUnit.test('should match inherited string keyed `srcValue` properties', function(assert) {
13978 Foo.prototype.b = 2;
13980 var object = { 'a': new Foo };
13982 lodashStable.each(['a', ['a']], function(path) {
13983 var matches = _.matchesProperty(path, { 'b': 2 });
13984 assert.strictEqual(matches(object), true);
13988 QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
13994 Foo.prototype.b = 2;
13996 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
13997 expected = lodashStable.map(objects, alwaysTrue);
13999 lodashStable.each(['a', ['a']], function(path) {
14000 assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
14004 QUnit.test('should compare a variety of values', function(assert) {
14007 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
14008 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
14009 matches = _.matchesProperty('a', object1);
14011 assert.strictEqual(matches({ 'a': object1 }), true);
14012 assert.strictEqual(matches({ 'a': object2 }), false);
14015 QUnit.test('should match `-0` as `0`', function(assert) {
14018 var matches = _.matchesProperty('a', -0);
14019 assert.strictEqual(matches({ 'a': 0 }), true);
14021 matches = _.matchesProperty('a', 0);
14022 assert.strictEqual(matches({ 'a': -0 }), true);
14025 QUnit.test('should compare functions by reference', function(assert) {
14028 var object1 = { 'a': lodashStable.noop },
14029 object2 = { 'a': noop },
14030 object3 = { 'a': {} },
14031 matches = _.matchesProperty('a', object1);
14033 assert.strictEqual(matches({ 'a': object1 }), true);
14034 assert.strictEqual(matches({ 'a': object2 }), false);
14035 assert.strictEqual(matches({ 'a': object3 }), false);
14038 QUnit.test('should work with a function for `srcValue`', function(assert) {
14043 Foo.b = function() {};
14046 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
14047 actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
14049 assert.deepEqual(actual, [false, true]);
14052 QUnit.test('should work with a non-plain `srcValue`', function(assert) {
14055 function Foo(object) { lodashStable.assign(this, object); }
14057 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
14058 matches = _.matchesProperty('a', { 'b': 1 });
14060 assert.strictEqual(matches(object), true);
14063 QUnit.test('should partial match arrays', function(assert) {
14066 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
14067 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
14069 assert.deepEqual(actual, [objects[1]]);
14071 actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
14072 assert.deepEqual(actual, []);
14074 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
14075 assert.deepEqual(actual, []);
14078 QUnit.test('should partial match arrays of objects', function(assert) {
14082 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
14083 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
14086 var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
14087 assert.deepEqual(actual, [objects[0]]);
14089 QUnit.test('should partial match maps', function(assert) {
14093 var objects = [{ 'a': new Map }, { 'a': new Map }];
14094 objects[0].a.set('a', 1);
14095 objects[1].a.set('a', 1);
14096 objects[1].a.set('b', 2);
14100 var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14102 assert.deepEqual(actual, [objects[1]]);
14104 map['delete']('b');
14105 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14107 assert.deepEqual(actual, objects);
14110 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14112 assert.deepEqual(actual, []);
14115 skipAssert(assert, 3);
14119 QUnit.test('should partial match sets', function(assert) {
14123 var objects = [{ 'a': new Set }, { 'a': new Set }];
14124 objects[0].a.add(1);
14125 objects[1].a.add(1);
14126 objects[1].a.add(2);
14130 var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14132 assert.deepEqual(actual, [objects[1]]);
14135 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14137 assert.deepEqual(actual, objects);
14140 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14142 assert.deepEqual(actual, []);
14145 skipAssert(assert, 3);
14149 QUnit.test('should match `undefined` values', function(assert) {
14152 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
14153 actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
14154 expected = [false, false, true];
14156 assert.deepEqual(actual, expected);
14158 objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
14159 actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
14161 assert.deepEqual(actual, expected);
14164 QUnit.test('should match `undefined` values of nested objects', function(assert) {
14167 var object = { 'a': { 'b': undefined } };
14169 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14170 var matches = _.matchesProperty(path, undefined);
14171 assert.strictEqual(matches(object), true);
14174 lodashStable.each(['a.a', ['a', 'a']], function(path) {
14175 var matches = _.matchesProperty(path, undefined);
14176 assert.strictEqual(matches(object), false);
14180 QUnit.test('should match `undefined` values on primitives', function(assert) {
14184 numberProto.b = undefined;
14187 var matches = _.matchesProperty('b', undefined);
14188 assert.strictEqual(matches(1), true);
14190 assert.ok(false, e.message);
14192 numberProto.a = { 'b': 1, 'c': undefined };
14194 matches = _.matchesProperty('a', { 'c': undefined });
14195 assert.strictEqual(matches(1), true);
14197 assert.ok(false, e.message);
14199 delete numberProto.a;
14200 delete numberProto.b;
14203 QUnit.test('should return `false` when `object` is nullish', function(assert) {
14206 var values = [, null, undefined],
14207 expected = lodashStable.map(values, alwaysFalse);
14209 lodashStable.each(['constructor', ['constructor']], function(path) {
14210 var matches = _.matchesProperty(path, 1);
14212 var actual = lodashStable.map(values, function(value, index) {
14214 return index ? matches(value) : matches();
14218 assert.deepEqual(actual, expected);
14222 QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
14225 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
14226 matches = _.matchesProperty('a', { 'a': [], 'b': {} });
14228 var actual = lodashStable.filter(objects, function(object) {
14229 return matches({ 'a': object });
14232 assert.deepEqual(actual, objects);
14235 QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
14238 lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
14239 var object = lodashStable.cloneDeep(source),
14240 matches = _.matchesProperty('a', source);
14242 assert.strictEqual(matches({ 'a': object }), true);
14253 assert.strictEqual(matches({ 'a': object }), true);
14254 assert.strictEqual(matches({ 'a': source }), false);
14259 /*--------------------------------------------------------------------------*/
14261 QUnit.module('lodash.max');
14264 QUnit.test('should return the largest value from a collection', function(assert) {
14267 assert.strictEqual(_.max([1, 2, 3]), 3);
14270 QUnit.test('should return `undefined` for empty collections', function(assert) {
14273 var values = falsey.concat([[]]),
14274 expected = lodashStable.map(values, noop);
14276 var actual = lodashStable.map(values, function(value, index) {
14278 return index ? _.max(value) : _.max();
14282 assert.deepEqual(actual, expected);
14285 QUnit.test('should work with non-numeric collection values', function(assert) {
14288 assert.strictEqual(_.max(['a', 'b']), 'b');
14292 /*--------------------------------------------------------------------------*/
14294 QUnit.module('lodash.mean');
14297 QUnit.test('should return the mean of an array of numbers', function(assert) {
14300 var array = [4, 2, 8, 6];
14301 assert.strictEqual(_.mean(array), 5);
14304 QUnit.test('should return `NaN` when passing empty `array` values', function(assert) {
14307 var expected = lodashStable.map(empties, alwaysNaN),
14308 actual = lodashStable.map(empties, _.mean);
14310 assert.deepEqual(actual, expected);
14314 /*--------------------------------------------------------------------------*/
14316 QUnit.module('lodash.meanBy');
14319 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
14321 QUnit.test('should work with an `iteratee` argument', function(assert) {
14324 var actual = _.meanBy(objects, function(object) {
14328 assert.deepEqual(actual, 2);
14331 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
14336 _.meanBy(objects, function() {
14337 args || (args = slice.call(arguments));
14340 assert.deepEqual(args, [{ 'a': 2 }]);
14343 QUnit.test('should work with `_.property` shorthands', function(assert) {
14346 var arrays = [[2], [3], [1]];
14347 assert.strictEqual(_.meanBy(arrays, 0), 2);
14348 assert.strictEqual(_.meanBy(objects, 'a'), 2);
14352 /*--------------------------------------------------------------------------*/
14354 QUnit.module('lodash.memoize');
14357 QUnit.test('should memoize results based on the first argument given', function(assert) {
14360 var memoized = _.memoize(function(a, b, c) {
14364 assert.strictEqual(memoized(1, 2, 3), 6);
14365 assert.strictEqual(memoized(1, 3, 5), 6);
14368 QUnit.test('should support a `resolver` argument', function(assert) {
14371 var fn = function(a, b, c) { return a + b + c; },
14372 memoized = _.memoize(fn, fn);
14374 assert.strictEqual(memoized(1, 2, 3), 6);
14375 assert.strictEqual(memoized(1, 3, 5), 9);
14378 QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
14381 var fn = function(a, b, c) { return a + this.b + this.c; },
14382 memoized = _.memoize(fn, fn);
14384 var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
14385 assert.strictEqual(object.memoized(1), 6);
14389 assert.strictEqual(object.memoized(1), 9);
14392 QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
14395 assert.raises(function() { _.memoize(noop, true); }, TypeError);
14398 QUnit.test('should not error if `resolver` is falsey', function(assert) {
14401 var expected = lodashStable.map(falsey, alwaysTrue);
14403 var actual = lodashStable.map(falsey, function(resolver, index) {
14405 return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
14409 assert.deepEqual(actual, expected);
14412 QUnit.test('should check cache for own properties', function(assert) {
14419 'propertyIsEnumerable',
14425 var memoized = _.memoize(identity);
14427 var actual = lodashStable.map(props, function(value) {
14428 return memoized(value);
14431 assert.deepEqual(actual, props);
14434 QUnit.test('should cache the `__proto__` key', function(assert) {
14440 lodashStable.times(2, function(index) {
14442 resolver = index && identity;
14444 var memoized = _.memoize(function() {
14449 var cache = memoized.cache;
14454 assert.strictEqual(count, 1);
14455 assert.strictEqual(cache.get(key), array);
14456 assert.notOk(cache.__data__ instanceof Array);
14457 assert.strictEqual(cache['delete'](key), true);
14461 QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
14464 var oldCache = _.memoize.Cache;
14467 this.__data__ = [];
14470 Cache.prototype = {
14471 'get': function(key) {
14472 var entry = _.find(this.__data__, function(entry) {
14473 return key === entry.key;
14475 return entry && entry.value;
14477 'has': function(key) {
14478 return _.some(this.__data__, function(entry) {
14479 return key === entry.key;
14482 'set': function(key, value) {
14483 this.__data__.push({ 'key': key, 'value': value });
14488 _.memoize.Cache = Cache;
14490 var memoized = _.memoize(function(object) {
14491 return 'value:' + object.id;
14494 var cache = memoized.cache,
14495 key1 = { 'id': 'a' },
14496 key2 = { 'id': 'b' };
14498 assert.strictEqual(memoized(key1), 'value:a');
14499 assert.strictEqual(cache.has(key1), true);
14501 assert.strictEqual(memoized(key2), 'value:b');
14502 assert.strictEqual(cache.has(key2), true);
14504 _.memoize.Cache = oldCache;
14507 QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
14510 var oldCache = _.memoize.Cache;
14513 this.__data__ = [];
14516 Cache.prototype = {
14517 'get': function(key) {
14518 return _.find(this.__data__, function(entry) {
14519 return key === entry.key;
14522 'has': function(key) {
14523 return _.some(this.__data__, function(entry) {
14524 return key === entry.key;
14527 'set': function(key, value) {
14528 var result = new Cache;
14529 result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
14534 _.memoize.Cache = Cache;
14536 var memoized = _.memoize(function(object) {
14540 var key1 = { 'id': 'a' },
14541 key2 = { 'id': 'b' };
14546 var cache = memoized.cache;
14547 assert.strictEqual(cache.has(key1), true);
14548 assert.strictEqual(cache.has(key2), true);
14550 _.memoize.Cache = oldCache;
14553 QUnit.test('should implement a `Map` interface on the cache object', function(assert) {
14554 assert.expect(164);
14556 var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || {}];
14558 var pairs = lodashStable.map(keys, function(key, index) {
14559 var lastIndex = keys.length - 1;
14560 return [key, keys[lastIndex - index]];
14563 lodashStable.times(2, function(index) {
14564 var memoize = (index ? (lodashBizarro || {}) : _).memoize,
14565 Cache = memoize ? memoize.Cache : undefined,
14566 cache = Cache ? new Cache(pairs) : undefined;
14568 lodashStable.each(keys, function(key, index) {
14570 var value = pairs[index][1];
14572 assert.deepEqual(cache.get(key), value);
14573 assert.strictEqual(cache.has(key), true);
14574 assert.strictEqual(cache['delete'](key), true);
14575 assert.strictEqual(cache.has(key), false);
14576 assert.strictEqual(cache.get(key), undefined);
14577 assert.strictEqual(cache['delete'](key), false);
14578 assert.strictEqual(cache.set(key, value), cache);
14579 assert.strictEqual(cache.has(key), true);
14582 skipAssert(assert, 8);
14587 assert.strictEqual(cache.clear(), undefined);
14588 assert.ok(lodashStable.every(keys, function(key) {
14589 return !cache.has(key);
14593 skipAssert(assert, 2);
14599 /*--------------------------------------------------------------------------*/
14601 QUnit.module('lodash.merge');
14604 var args = arguments;
14606 QUnit.test('should merge `source` into `object`', function(assert) {
14611 { 'name': 'barney' },
14625 { 'height': '5\'4"' },
14626 { 'height': '5\'5"' }
14632 { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
14633 { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
14637 assert.deepEqual(_.merge(names, ages, heights), expected);
14640 QUnit.test('should merge sources containing circular references', function(assert) {
14649 'foo': { 'b': { 'c': { 'd': {} } } },
14653 source.foo.b.c.d = source;
14654 source.bar.b = source.foo.b;
14656 var actual = _.merge(object, source);
14658 assert.notStrictEqual(actual.bar.b, actual.foo.b);
14659 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
14662 QUnit.test('should work with four arguments', function(assert) {
14665 var expected = { 'a': 4 },
14666 actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
14668 assert.deepEqual(actual, expected);
14671 QUnit.test('should merge onto function `object` values', function(assert) {
14676 var source = { 'a': 1 },
14677 actual = _.merge(Foo, source);
14679 assert.strictEqual(actual, Foo);
14680 assert.strictEqual(Foo.a, 1);
14683 QUnit.test('should not merge onto nested function values', function(assert) {
14686 var source1 = { 'a': function() {} },
14687 source2 = { 'a': { 'b': 1 } },
14688 actual = _.merge({}, source1, source2),
14689 expected = { 'a': { 'b': 1 } };
14691 assert.deepEqual(actual, expected);
14693 source1 = { 'a': function() {} };
14694 source2 = { 'a': { 'b': 1 } };
14696 expected = { 'a': function() {} };
14699 actual = _.merge(source1, source2);
14700 assert.strictEqual(typeof actual.a, 'function');
14701 assert.strictEqual(actual.a.b, 1);
14704 QUnit.test('should merge onto non-plain `object` values', function(assert) {
14709 var object = new Foo,
14710 actual = _.merge(object, { 'a': 1 });
14712 assert.strictEqual(actual, object);
14713 assert.strictEqual(object.a, 1);
14716 QUnit.test('should treat sparse array sources as dense', function(assert) {
14722 var actual = _.merge([], array),
14723 expected = array.slice();
14725 expected[1] = undefined;
14727 assert.ok('1' in actual);
14728 assert.deepEqual(actual, expected);
14731 QUnit.test('should merge `arguments` objects', function(assert) {
14734 var object1 = { 'value': args },
14735 object2 = { 'value': { '3': 4 } },
14736 expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
14737 actual = _.merge(object1, object2);
14739 assert.notOk('3' in args);
14740 assert.notOk(_.isArguments(actual.value));
14741 assert.deepEqual(actual.value, expected);
14742 object1.value = args;
14744 actual = _.merge(object2, object1);
14745 assert.notOk(_.isArguments(actual.value));
14746 assert.deepEqual(actual.value, expected);
14748 expected = { '0': 1, '1': 2, '2': 3 };
14750 actual = _.merge({}, object1);
14751 assert.notOk(_.isArguments(actual.value));
14752 assert.deepEqual(actual.value, expected);
14755 QUnit.test('should merge typed arrays', function(assert) {
14760 array3 = [0, 0, 0, 0],
14761 array4 = [0, 0, 0, 0, 0, 0, 0, 0];
14763 var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
14764 buffer = ArrayBuffer && new ArrayBuffer(8);
14766 // Juggle for `Float64Array` shim.
14767 if (root.Float64Array && (new Float64Array(buffer)).length == 8) {
14768 arrays[1] = array4;
14770 var expected = lodashStable.map(typedArrays, function(type, index) {
14771 var array = arrays[index].slice();
14773 return root[type] ? { 'value': array } : false;
14776 var actual = lodashStable.map(typedArrays, function(type) {
14777 var Ctor = root[type];
14778 return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
14781 assert.ok(lodashStable.isArray(actual));
14782 assert.deepEqual(actual, expected);
14784 expected = lodashStable.map(typedArrays, function(type, index) {
14785 var array = arrays[index].slice();
14787 return root[type] ? { 'value': array } : false;
14790 actual = lodashStable.map(typedArrays, function(type, index) {
14791 var Ctor = root[type],
14792 array = lodashStable.range(arrays[index].length);
14795 return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
14798 assert.ok(lodashStable.isArray(actual));
14799 assert.deepEqual(actual, expected);
14802 QUnit.test('should assign `null` values', function(assert) {
14805 var actual = _.merge({ 'a': 1 }, { 'a': null });
14806 assert.strictEqual(actual.a, null);
14809 QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) {
14814 var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
14815 expected = lodashStable.map(values, alwaysTrue);
14817 var actual = lodashStable.map(values, function(value) {
14818 var object = _.merge({}, { 'value': value });
14819 return object.value === value;
14822 assert.deepEqual(actual, expected);
14825 QUnit.test('should deep clone array/typed-array/plain-object sources', function(assert) {
14828 var typedArray = Uint8Array
14829 ? new Uint8Array(new ArrayBuffer(2))
14830 : { 'buffer': [0, 0] };
14832 var props = ['0', 'a', 'buffer'],
14833 values = [[{ 'a': 1 }], { 'a': [1] }, typedArray],
14834 expected = lodashStable.map(values, alwaysTrue);
14836 var actual = lodashStable.map(values, function(value, index) {
14837 var key = props[index],
14838 object = _.merge({}, { 'value': value }),
14839 newValue = object.value;
14842 newValue !== value &&
14843 newValue[key] !== value[key] &&
14844 lodashStable.isEqual(newValue, value)
14848 assert.deepEqual(actual, expected);
14851 QUnit.test('should not augment source objects', function(assert) {
14854 var source1 = { 'a': [{ 'a': 1 }] },
14855 source2 = { 'a': [{ 'b': 2 }] },
14856 actual = _.merge({}, source1, source2);
14858 assert.deepEqual(source1.a, [{ 'a': 1 }]);
14859 assert.deepEqual(source2.a, [{ 'b': 2 }]);
14860 assert.deepEqual(actual.a, [{ 'a': 1, 'b': 2 }]);
14862 var source1 = { 'a': [[1, 2, 3]] },
14863 source2 = { 'a': [[3, 4]] },
14864 actual = _.merge({}, source1, source2);
14866 assert.deepEqual(source1.a, [[1, 2, 3]]);
14867 assert.deepEqual(source2.a, [[3, 4]]);
14868 assert.deepEqual(actual.a, [[3, 4, 3]]);
14871 QUnit.test('should merge plain-objects onto non plain-objects', function(assert) {
14874 function Foo(object) {
14875 lodashStable.assign(this, object);
14878 var object = { 'a': 1 },
14879 actual = _.merge(new Foo, object);
14881 assert.ok(actual instanceof Foo);
14882 assert.deepEqual(actual, new Foo(object));
14884 actual = _.merge([new Foo], [object]);
14885 assert.ok(actual[0] instanceof Foo);
14886 assert.deepEqual(actual, [new Foo(object)]);
14889 QUnit.test('should not assign `undefined` values', function(assert) {
14892 var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
14893 assert.deepEqual(actual, { 'a': 1 });
14896 QUnit.test('should skip `undefined` values in array sources if a destination value exists', function(assert) {
14902 var actual = _.merge([4, 5, 6], array),
14903 expected = [1, 5, 3];
14905 assert.deepEqual(actual, expected);
14908 array[1] = undefined;
14910 actual = _.merge([4, 5, 6], array);
14911 assert.deepEqual(actual, expected);
14914 QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
14917 if (defineProperty) {
14921 defineProperty(object, 'a', {
14922 'enumerable': true,
14923 'configurable': true,
14924 'get': function() { pass = false; },
14925 'set': function() { pass = false; }
14928 _.merge(object, object);
14932 skipAssert(assert);
14936 QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
14939 var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
14940 actual = _.merge(object, { 'a': ['x'] });
14942 assert.deepEqual(actual, { 'a': ['x', 'y'] });
14944 actual = _.merge({ 'a': {} }, { 'a': [] });
14945 assert.deepEqual(actual, { 'a': [] });
14948 QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
14951 var object = { 'a': 'abcde' },
14952 actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
14954 assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
14957 QUnit.test('should not error on DOM elements', function(assert) {
14960 var object1 = { 'el': document && document.createElement('div') },
14961 object2 = { 'el': document && document.createElement('div') },
14962 pairs = [[{}, object1], [object1, object2]],
14963 expected = lodashStable.map(pairs, alwaysTrue);
14965 var actual = lodashStable.map(pairs, function(pair) {
14967 return _.merge(pair[0], pair[1]).el === pair[1].el;
14971 assert.deepEqual(actual, expected);
14975 /*--------------------------------------------------------------------------*/
14977 QUnit.module('lodash.mergeWith');
14980 QUnit.test('should handle merging if `customizer` returns `undefined`', function(assert) {
14983 var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
14984 assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
14986 actual = _.mergeWith([], [undefined], identity);
14987 assert.deepEqual(actual, [undefined]);
14990 QUnit.test('should defer to `customizer` when it returns a non `undefined` value', function(assert) {
14993 var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
14994 return lodashStable.isArray(a) ? a.concat(b) : undefined;
14997 assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
15000 QUnit.test('should overwrite primitives with source object clones', function(assert) {
15003 var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) {
15004 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15007 assert.deepEqual(actual, { 'a': { 'b': ['c'] } });
15010 QUnit.test('should clone sources when `customizer` result is `undefined`', function(assert) {
15013 var source1 = { 'a': { 'b': { 'c': 1 } } },
15014 source2 = { 'a': { 'b': { 'd': 2 } } };
15016 _.mergeWith({}, source1, source2, noop);
15017 assert.deepEqual(source1.a.b, { 'c': 1 });
15020 QUnit.test('should pop the stack of sources for each sibling property', function(assert) {
15023 var array = ['b', 'c'],
15024 object = { 'a': ['a'] },
15025 source = { 'a': array, 'b': array };
15027 var actual = _.mergeWith(object, source, function(a, b) {
15028 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15031 assert.deepEqual(actual, { 'a': ['a', 'b', 'c'], 'b': ['b', 'c'] });
15035 /*--------------------------------------------------------------------------*/
15037 QUnit.module('lodash.method');
15040 QUnit.test('should create a function that calls a method of a given object', function(assert) {
15043 var object = { 'a': alwaysOne };
15045 lodashStable.each(['a', ['a']], function(path) {
15046 var method = _.method(path);
15047 assert.strictEqual(method.length, 1);
15048 assert.strictEqual(method(object), 1);
15052 QUnit.test('should work with deep property values', function(assert) {
15055 var object = { 'a': { 'b': alwaysTwo } };
15057 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15058 var method = _.method(path);
15059 assert.strictEqual(method(object), 2);
15063 QUnit.test('should work with a non-string `path`', function(assert) {
15066 var array = lodashStable.times(3, _.constant);
15068 lodashStable.each([1, [1]], function(path) {
15069 var method = _.method(path);
15070 assert.strictEqual(method(array), 1);
15074 QUnit.test('should coerce key to a string', function(assert) {
15078 fn.toString = lodashStable.constant('fn');
15080 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15081 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
15082 values = [null, undefined, fn, {}];
15084 var actual = lodashStable.transform(objects, function(result, object, index) {
15085 var key = values[index];
15086 lodashStable.each([key, [key]], function(path) {
15087 var method = _.method(key);
15088 result.push(method(object));
15092 assert.deepEqual(actual, expected);
15095 QUnit.test('should work with inherited property values', function(assert) {
15099 Foo.prototype.a = alwaysOne;
15101 lodashStable.each(['a', ['a']], function(path) {
15102 var method = _.method(path);
15103 assert.strictEqual(method(new Foo), 1);
15107 QUnit.test('should use a key over a path', function(assert) {
15110 var object = { 'a.b': alwaysOne, 'a': { 'b': alwaysTwo } };
15112 lodashStable.each(['a.b', ['a.b']], function(path) {
15113 var method = _.method(path);
15114 assert.strictEqual(method(object), 1);
15118 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15121 var values = [, null, undefined],
15122 expected = lodashStable.map(values, noop);
15124 lodashStable.each(['constructor', ['constructor']], function(path) {
15125 var method = _.method(path);
15127 var actual = lodashStable.map(values, function(value, index) {
15128 return index ? method(value) : method();
15131 assert.deepEqual(actual, expected);
15135 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15138 var values = [, null, undefined],
15139 expected = lodashStable.map(values, noop);
15141 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15142 var method = _.method(path);
15144 var actual = lodashStable.map(values, function(value, index) {
15145 return index ? method(value) : method();
15148 assert.deepEqual(actual, expected);
15152 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15157 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15158 var method = _.method(path);
15159 assert.strictEqual(method(object), undefined);
15163 QUnit.test('should apply partial arguments to function', function(assert) {
15168 return slice.call(arguments);
15172 lodashStable.each(['fn', ['fn']], function(path) {
15173 var method = _.method(path, 1, 2, 3);
15174 assert.deepEqual(method(object), [1, 2, 3]);
15178 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15181 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
15183 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15184 var method = _.method(path);
15185 assert.strictEqual(method(object), 1);
15190 /*--------------------------------------------------------------------------*/
15192 QUnit.module('lodash.methodOf');
15195 QUnit.test('should create a function that calls a method of a given key', function(assert) {
15198 var object = { 'a': alwaysOne };
15200 lodashStable.each(['a', ['a']], function(path) {
15201 var methodOf = _.methodOf(object);
15202 assert.strictEqual(methodOf.length, 1);
15203 assert.strictEqual(methodOf(path), 1);
15207 QUnit.test('should work with deep property values', function(assert) {
15210 var object = { 'a': { 'b': alwaysTwo } };
15212 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15213 var methodOf = _.methodOf(object);
15214 assert.strictEqual(methodOf(path), 2);
15218 QUnit.test('should work with a non-string `path`', function(assert) {
15221 var array = lodashStable.times(3, _.constant);
15223 lodashStable.each([1, [1]], function(path) {
15224 var methodOf = _.methodOf(array);
15225 assert.strictEqual(methodOf(path), 1);
15229 QUnit.test('should coerce key to a string', function(assert) {
15233 fn.toString = lodashStable.constant('fn');
15235 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15236 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
15237 values = [null, undefined, fn, {}];
15239 var actual = lodashStable.transform(objects, function(result, object, index) {
15240 var key = values[index];
15241 lodashStable.each([key, [key]], function(path) {
15242 var methodOf = _.methodOf(object);
15243 result.push(methodOf(key));
15247 assert.deepEqual(actual, expected);
15250 QUnit.test('should work with inherited property values', function(assert) {
15254 Foo.prototype.a = alwaysOne;
15256 lodashStable.each(['a', ['a']], function(path) {
15257 var methodOf = _.methodOf(new Foo);
15258 assert.strictEqual(methodOf(path), 1);
15262 QUnit.test('should use a key over a path', function(assert) {
15265 var object = { 'a.b': alwaysOne, 'a': { 'b': alwaysTwo } };
15267 lodashStable.each(['a.b', ['a.b']], function(path) {
15268 var methodOf = _.methodOf(object);
15269 assert.strictEqual(methodOf(path), 1);
15273 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15276 var values = [, null, undefined],
15277 expected = lodashStable.map(values, noop);
15279 lodashStable.each(['constructor', ['constructor']], function(path) {
15280 var actual = lodashStable.map(values, function(value, index) {
15281 var methodOf = index ? _.methodOf() : _.methodOf(value);
15282 return methodOf(path);
15285 assert.deepEqual(actual, expected);
15289 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15292 var values = [, null, undefined],
15293 expected = lodashStable.map(values, noop);
15295 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15296 var actual = lodashStable.map(values, function(value, index) {
15297 var methodOf = index ? _.methodOf() : _.methodOf(value);
15298 return methodOf(path);
15301 assert.deepEqual(actual, expected);
15305 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15309 methodOf = _.methodOf(object);
15311 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15312 assert.strictEqual(methodOf(path), undefined);
15316 QUnit.test('should apply partial arguments to function', function(assert) {
15321 return slice.call(arguments);
15325 var methodOf = _.methodOf(object, 1, 2, 3);
15327 lodashStable.each(['fn', ['fn']], function(path) {
15328 assert.deepEqual(methodOf(path), [1, 2, 3]);
15332 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15335 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
15336 methodOf = _.methodOf(object);
15338 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15339 assert.strictEqual(methodOf(path), 1);
15344 /*--------------------------------------------------------------------------*/
15346 QUnit.module('lodash.min');
15349 QUnit.test('should return the smallest value from a collection', function(assert) {
15352 assert.strictEqual(_.min([1, 2, 3]), 1);
15355 QUnit.test('should return `undefined` for empty collections', function(assert) {
15358 var values = falsey.concat([[]]),
15359 expected = lodashStable.map(values, noop);
15361 var actual = lodashStable.map(values, function(value, index) {
15363 return index ? _.min(value) : _.min();
15367 assert.deepEqual(actual, expected);
15370 QUnit.test('should work with non-numeric collection values', function(assert) {
15373 assert.strictEqual(_.min(['a', 'b']), 'a');
15377 /*--------------------------------------------------------------------------*/
15379 QUnit.module('extremum methods');
15381 lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
15382 var func = _[methodName],
15383 isMax = /^max/.test(methodName);
15385 QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
15388 var curr = new Date,
15389 past = new Date(0);
15391 assert.strictEqual(func([curr, past]), isMax ? curr : past);
15394 QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
15397 var array = lodashStable.range(0, 5e5);
15398 assert.strictEqual(func(array), isMax ? 499999 : 0);
15401 QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
15405 var actual = _([40])[methodName]();
15406 assert.strictEqual(actual, 40);
15409 skipAssert(assert);
15414 lodashStable.each(['maxBy', 'minBy'], function(methodName) {
15415 var array = [1, 2, 3],
15416 func = _[methodName],
15417 isMax = methodName == 'maxBy';
15419 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
15422 var actual = func(array, function(n) {
15426 assert.strictEqual(actual, isMax ? 1 : 3);
15429 QUnit.test('should work with `_.property` shorthands', function(assert) {
15432 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
15433 actual = func(objects, 'a');
15435 assert.deepEqual(actual, objects[isMax ? 1 : 2]);
15437 var arrays = [[2], [3], [1]];
15438 actual = func(arrays, 0);
15440 assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
15443 QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
15446 var value = isMax ? -Infinity : Infinity,
15447 object = { 'a': value };
15449 var actual = func([object, { 'a': value }], function(object) {
15453 assert.strictEqual(actual, object);
15457 /*--------------------------------------------------------------------------*/
15459 QUnit.module('lodash.mixin');
15462 function reset(wrapper) {
15464 delete wrapper.prototype.a;
15466 delete wrapper.prototype.b;
15469 function Wrapper(value) {
15470 if (!(this instanceof Wrapper)) {
15471 return new Wrapper(value);
15473 if (_.has(value, '__wrapped__')) {
15474 var actions = slice.call(value.__actions__),
15475 chain = value.__chain__;
15477 value = value.__wrapped__;
15479 this.__wrapped__ = value;
15480 this.__actions__ = actions || [];
15481 this.__chain__ = chain || false;
15484 Wrapper.prototype.value = function() {
15485 return getUnwrappedValue(this);
15489 source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
15491 QUnit.test('should mixin `source` methods into lodash', function(assert) {
15497 assert.strictEqual(_.a(array), 'a');
15498 assert.strictEqual(_(array).a().value(), 'a');
15499 assert.notOk('b' in _);
15500 assert.notOk('b' in _.prototype);
15505 skipAssert(assert, 4);
15509 QUnit.test('should mixin chaining methods by reference', function(assert) {
15516 assert.strictEqual(_.a(array), 'b');
15517 assert.strictEqual(_(array).a().value(), 'a');
15522 skipAssert(assert, 2);
15526 QUnit.test('should use a default `object` of `this`', function(assert) {
15529 var object = lodashStable.create(_);
15530 object.mixin(source);
15532 assert.strictEqual(object.a(array), 'a');
15533 assert.notOk('a' in _);
15534 assert.notOk('a' in _.prototype);
15539 QUnit.test('should accept an `object` argument', function(assert) {
15543 _.mixin(object, source);
15544 assert.strictEqual(object.a(array), 'a');
15547 QUnit.test('should accept a function `object`', function(assert) {
15550 _.mixin(Wrapper, source);
15552 var wrapped = Wrapper(array),
15553 actual = wrapped.a();
15555 assert.strictEqual(actual.value(), 'a');
15556 assert.ok(actual instanceof Wrapper);
15561 QUnit.test('should return `object`', function(assert) {
15565 assert.strictEqual(_.mixin(object, source), object);
15566 assert.strictEqual(_.mixin(Wrapper, source), Wrapper);
15567 assert.strictEqual(_.mixin(), _);
15572 QUnit.test('should not assign inherited `source` methods', function(assert) {
15576 Foo.prototype.a = noop;
15579 assert.strictEqual(_.mixin(object, new Foo), object);
15582 QUnit.test('should accept an `options` argument', function(assert) {
15585 function message(func, chain) {
15586 return (func === _ ? 'lodash' : 'given') + ' function should ' + (chain ? '' : 'not ') + 'chain';
15589 lodashStable.each([_, Wrapper], function(func) {
15590 lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
15593 _.mixin(source, options);
15595 _.mixin(func, source, options);
15597 var wrapped = func(array),
15598 actual = wrapped.a();
15600 if (options.chain) {
15601 assert.strictEqual(actual.value(), 'a', message(func, true));
15602 assert.ok(actual instanceof func, message(func, true));
15604 assert.strictEqual(actual, 'a', message(func, false));
15605 assert.notOk(actual instanceof func, message(func, false));
15610 skipAssert(assert, 2);
15616 QUnit.test('should not extend lodash when an `object` is given with an empty `options` object', function(assert) {
15619 _.mixin({ 'a': noop }, {});
15620 assert.notOk('a' in _);
15624 QUnit.test('should not error for non-object `options` values', function(assert) {
15630 _.mixin({}, source, 1);
15639 _.mixin(source, 1);
15648 QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
15651 lodashStable.each([_, Wrapper], function(func) {
15654 var wrapped = _(source),
15655 actual = wrapped.mixin();
15657 assert.strictEqual(actual.value(), _);
15661 actual = wrapped.mixin(source);
15662 assert.notStrictEqual(actual, wrapped);
15667 skipAssert(assert);
15672 QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
15676 _.mixin({ 'a': _.countBy, 'b': _.filter });
15678 var array = lodashStable.range(LARGE_ARRAY_SIZE),
15679 actual = _(array).a().map(square).b(isEven).take().value();
15681 assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
15686 skipAssert(assert);
15691 /*--------------------------------------------------------------------------*/
15693 QUnit.module('lodash.multiply');
15696 QUnit.test('should multiply two numbers', function(assert) {
15699 assert.strictEqual(_.multiply(6, 4), 24);
15700 assert.strictEqual(_.multiply(-6, 4), -24);
15701 assert.strictEqual(_.multiply(-6, -4), 24);
15704 QUnit.test('should coerce arguments to numbers', function(assert) {
15707 assert.strictEqual(_.multiply('6', '4'), 24);
15708 assert.deepEqual(_.multiply('x', 'y'), NaN);
15712 /*--------------------------------------------------------------------------*/
15714 QUnit.module('lodash.orderBy');
15718 { 'a': 'x', 'b': 3 },
15719 { 'a': 'y', 'b': 4 },
15720 { 'a': 'x', 'b': 1 },
15721 { 'a': 'y', 'b': 2 }
15724 QUnit.test('should sort by a single property by a specified order', function(assert) {
15727 var actual = _.orderBy(objects, 'a', 'desc');
15728 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15731 QUnit.test('should sort by multiple properties by specified orders', function(assert) {
15734 var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
15735 assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
15738 QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
15741 var expected = [objects[2], objects[0], objects[3], objects[1]],
15742 actual = _.orderBy(objects, ['a', 'b']);
15744 assert.deepEqual(actual, expected);
15746 expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
15748 actual = lodashStable.map(falsey, function(order, index) {
15749 return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
15752 assert.deepEqual(actual, expected);
15755 QUnit.test('should work with `orders` specified as string objects', function(assert) {
15758 var actual = _.orderBy(objects, ['a'], [Object('desc')]);
15759 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15763 /*--------------------------------------------------------------------------*/
15765 QUnit.module('lodash.overArgs');
15769 return slice.call(arguments);
15772 QUnit.test('should transform each argument', function(assert) {
15775 var over = _.overArgs(fn, doubled, square);
15776 assert.deepEqual(over(5, 10), [10, 100]);
15779 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
15782 var over = _.overArgs(fn, undefined, null);
15783 assert.deepEqual(over('a', 'b'), ['a', 'b']);
15786 QUnit.test('should work with `_.property` shorthands', function(assert) {
15789 var over = _.overArgs(fn, 'b', 'a');
15790 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [2, 1]);
15793 QUnit.test('should work with `_.matches` shorthands', function(assert) {
15796 var over = _.overArgs(fn, { 'b': 1 }, { 'a': 1 });
15797 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
15800 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
15803 var over = _.overArgs(fn, ['b', 1], [['a', 1]]);
15804 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
15807 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
15810 var over = _.overArgs(fn, ['a', 1]);
15811 assert.deepEqual(over({ 'a': 1 }, { '1': 2 }), [1, 2]);
15813 over = _.overArgs(fn, [['a', 1]]);
15814 assert.deepEqual(over({ 'a': 1 }), [true]);
15817 QUnit.test('should flatten `transforms`', function(assert) {
15820 var over = _.overArgs(fn, [doubled, square], String);
15821 assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
15824 QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
15827 var over = _.overArgs(fn, doubled, square);
15828 assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
15831 QUnit.test('should not transform any arguments if no transforms are given', function(assert) {
15834 var over = _.overArgs(fn);
15835 assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
15838 QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
15841 var over = _.overArgs(fn, doubled, identity);
15842 assert.deepEqual(over(5), [10]);
15845 QUnit.test('should provide the correct argument to each transform', function(assert) {
15849 transform = function() { argsList.push(slice.call(arguments)); },
15850 over = _.overArgs(noop, transform, transform, transform);
15853 assert.deepEqual(argsList, [['a'], ['b']]);
15856 QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
15859 var over = _.overArgs(function(x) {
15865 var object = { 'over': over, 'true': 1 };
15866 assert.strictEqual(object.over(object), 1);
15870 /*--------------------------------------------------------------------------*/
15872 QUnit.module('lodash.negate');
15875 QUnit.test('should create a function that negates the result of `func`', function(assert) {
15878 var negate = _.negate(isEven);
15880 assert.strictEqual(negate(1), true);
15881 assert.strictEqual(negate(2), false);
15885 /*--------------------------------------------------------------------------*/
15887 QUnit.module('lodash.noop');
15890 QUnit.test('should return `undefined`', function(assert) {
15893 var values = empties.concat(true, new Date, _, 1, /x/, 'a'),
15894 expected = lodashStable.map(values, noop);
15896 var actual = lodashStable.map(values, function(value, index) {
15897 return index ? _.noop(value) : _.noop();
15900 assert.deepEqual(actual, expected);
15904 /*--------------------------------------------------------------------------*/
15906 QUnit.module('lodash.noConflict');
15909 QUnit.test('should return the `lodash` function', function(assert) {
15912 if (!isModularize) {
15913 assert.strictEqual(_.noConflict(), oldDash);
15914 assert.notStrictEqual(root._, oldDash);
15918 skipAssert(assert, 2);
15922 QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) {
15925 if (!isModularize) {
15926 var object = root._ = {};
15927 assert.strictEqual(_.noConflict(), oldDash);
15928 assert.strictEqual(root._, object);
15932 skipAssert(assert, 2);
15936 QUnit.test('should work with a `root` of `this`', function(assert) {
15939 if (!isModularize && !coverage && (!document && realm.object)) {
15940 var fs = require('fs'),
15941 vm = require('vm'),
15943 context = vm.createContext({ '_': expected, 'console': console }),
15944 source = fs.readFileSync(filePath, 'utf8');
15946 vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
15948 assert.strictEqual(context._, expected);
15949 assert.ok(context.lodash);
15952 skipAssert(assert, 2);
15957 /*--------------------------------------------------------------------------*/
15959 QUnit.module('lodash.now');
15962 QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
15965 var done = assert.async();
15967 var stamp = +new Date,
15970 assert.ok(actual >= stamp);
15972 setTimeout(function() {
15973 assert.ok(_.now() > actual);
15979 /*--------------------------------------------------------------------------*/
15981 QUnit.module('lodash.nth');
15984 var array = ['a', 'b', 'c', 'd'];
15986 QUnit.test('should get the nth element of `array`', function(assert) {
15989 var actual = lodashStable.map(array, function(value, index) {
15990 return _.nth(array, index);
15993 assert.deepEqual(actual, array);
15996 QUnit.test('should work with a negative `n`', function(assert) {
15999 var actual = lodashStable.map(lodashStable.range(1, array.length + 1), function(n) {
16000 return _.nth(array, -n);
16003 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16006 QUnit.test('should coerce `n` to an integer', function(assert) {
16009 var values = falsey,
16010 expected = lodashStable.map(values, alwaysA);
16012 var actual = lodashStable.map(values, function(n) {
16013 return n ? _.nth(array, n) : _.nth(array);
16016 assert.deepEqual(actual, expected);
16018 values = ['1', 1.6];
16019 expected = lodashStable.map(values, alwaysB);
16021 actual = lodashStable.map(values, function(n) {
16022 return _.nth(array, n);
16025 assert.deepEqual(actual, expected);
16028 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16031 var values = [null, undefined, []],
16032 expected = lodashStable.map(values, noop);
16034 var actual = lodashStable.map(values, function(array) {
16035 return _.nth(array, 1);
16038 assert.deepEqual(actual, expected);
16041 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16044 var array = [1, 2],
16045 values = [Infinity, array.length],
16046 expected = lodashStable.map(values, noop);
16050 var actual = lodashStable.map(values, function(n) {
16051 return _.nth(array, n);
16054 assert.deepEqual(actual, expected);
16058 /*--------------------------------------------------------------------------*/
16060 QUnit.module('lodash.nthArg');
16063 var args = ['a', 'b', 'c', 'd'];
16065 QUnit.test('should create a function that returns its nth argument', function(assert) {
16068 var actual = lodashStable.map(args, function(value, index) {
16069 var func = _.nthArg(index);
16070 return func.apply(undefined, args);
16073 assert.deepEqual(actual, args);
16076 QUnit.test('should work with a negative `n`', function(assert) {
16079 var actual = lodashStable.map(lodashStable.range(1, args.length + 1), function(n) {
16080 var func = _.nthArg(-n);
16081 return func.apply(undefined, args);
16084 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16087 QUnit.test('should coerce `n` to an integer', function(assert) {
16090 var values = falsey,
16091 expected = lodashStable.map(values, alwaysA);
16093 var actual = lodashStable.map(values, function(n) {
16094 var func = n ? _.nthArg(n) : _.nthArg();
16095 return func.apply(undefined, args);
16098 assert.deepEqual(actual, expected);
16100 values = ['1', 1.6];
16101 expected = lodashStable.map(values, alwaysB);
16103 actual = lodashStable.map(values, function(n) {
16104 var func = _.nthArg(n);
16105 return func.apply(undefined, args);
16108 assert.deepEqual(actual, expected);
16111 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16114 var func = _.nthArg(1);
16115 assert.strictEqual(func(), undefined);
16118 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16121 var values = [Infinity, args.length],
16122 expected = lodashStable.map(values, noop);
16124 var actual = lodashStable.map(values, function(n) {
16125 var func = _.nthArg(n);
16126 return func.apply(undefined, args);
16129 assert.deepEqual(actual, expected);
16133 /*--------------------------------------------------------------------------*/
16135 QUnit.module('lodash.omit');
16138 var args = arguments,
16139 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16141 QUnit.test('should flatten `props`', function(assert) {
16144 assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
16145 assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
16148 QUnit.test('should work with a primitive `object` argument', function(assert) {
16154 assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
16156 delete stringProto.a;
16157 delete stringProto.b;
16160 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
16164 lodashStable.each([null, undefined], function(value) {
16165 assert.deepEqual(_.omit(value, 'valueOf'), {});
16167 delete objectProto.a;
16170 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
16173 assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
16176 QUnit.test('should coerce property names to strings', function(assert) {
16179 assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
16183 /*--------------------------------------------------------------------------*/
16185 QUnit.module('lodash.omitBy');
16188 QUnit.test('should work with a predicate argument', function(assert) {
16191 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16193 var actual = _.omitBy(object, function(n) {
16194 return n != 2 && n != 4;
16197 assert.deepEqual(actual, { 'b': 2, 'd': 4 });
16201 /*--------------------------------------------------------------------------*/
16203 QUnit.module('omit methods');
16205 lodashStable.each(['omit', 'omitBy'], function(methodName) {
16206 var expected = { 'b': 2, 'd': 4 },
16207 func = _[methodName],
16208 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
16209 prop = lodashStable.nthArg(1);
16211 if (methodName == 'omitBy') {
16212 prop = function(object, props) {
16213 props = lodashStable.castArray(props);
16214 return function(value) {
16215 return lodashStable.some(props, function(key) {
16216 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
16217 return object[key] === value;
16222 QUnit.test('`_.' + methodName + '` should create an object with omitted string keyed properties', function(assert) {
16225 assert.deepEqual(func(object, prop(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
16226 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
16229 QUnit.test('`_.' + methodName + '` should include inherited string keyed properties', function(assert) {
16233 Foo.prototype = object;
16235 assert.deepEqual(func(new Foo, prop(object, ['a', 'c'])), expected);
16238 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
16241 var object = { '-0': 'a', '0': 'b' },
16242 props = [-0, Object(-0), 0, Object(0)],
16243 expected = [{ '0': 'b' }, { '0': 'b' }, { '-0': 'a' }, { '-0': 'a' }];
16245 var actual = lodashStable.map(props, function(key) {
16246 return func(object, prop(object, key));
16249 assert.deepEqual(actual, expected);
16252 QUnit.test('`_.' + methodName + '` should include symbol properties', function(assert) {
16261 var symbol2 = Symbol('b');
16262 Foo.prototype[symbol2] = 2;
16265 actual = func(foo, prop(foo, 'a'));
16267 assert.strictEqual(actual[symbol], 1);
16268 assert.strictEqual(actual[symbol2], 2);
16271 skipAssert(assert, 2);
16275 QUnit.test('`_.' + methodName + '` should create an object with omitted symbol properties', function(assert) {
16284 var symbol2 = Symbol('b');
16285 Foo.prototype[symbol2] = 2;
16288 actual = func(foo, prop(foo, symbol));
16290 assert.strictEqual(actual.a, 0);
16291 assert.strictEqual(actual[symbol], undefined);
16292 assert.strictEqual(actual[symbol2], 2);
16294 actual = func(foo, prop(foo, symbol2));
16296 assert.strictEqual(actual.a, 0);
16297 assert.strictEqual(actual[symbol], 1);
16298 assert.strictEqual(actual[symbol2], undefined);
16301 skipAssert(assert, 6);
16305 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
16308 var array = [1, 2, 3];
16309 assert.deepEqual(func(array, prop(array, ['0', '2'])), { '1': 2 });
16313 /*--------------------------------------------------------------------------*/
16315 QUnit.module('lodash.once');
16318 QUnit.test('should invoke `func` once', function(assert) {
16322 once = _.once(function() { return ++count; });
16325 assert.strictEqual(once(), 1);
16326 assert.strictEqual(count, 1);
16329 QUnit.test('should ignore recursive calls', function(assert) {
16334 var once = _.once(function() {
16339 assert.strictEqual(once(), 1);
16340 assert.strictEqual(count, 1);
16343 QUnit.test('should not throw more than once', function(assert) {
16348 var once = _.once(function() {
16352 assert.raises(once);
16363 /*--------------------------------------------------------------------------*/
16365 QUnit.module('lodash.over');
16368 QUnit.test('should create a function that invokes `iteratees`', function(assert) {
16371 var over = _.over(Math.max, Math.min);
16372 assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
16375 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16378 var over = _.over(undefined, null);
16379 assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
16382 QUnit.test('should work with `_.property` shorthands', function(assert) {
16385 var over = _.over('b', 'a');
16386 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [2, 1]);
16389 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16392 var over = _.over({ 'b': 1 }, { 'a': 1 });
16393 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [false, true]);
16396 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16399 var over = _.over(['b', 2], [['a', 2]]);
16401 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [true, false]);
16402 assert.deepEqual(over({ 'a': 2, 'b': 1 }), [false, true]);
16405 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16408 var over = _.over(['a', 1]);
16410 assert.deepEqual(over({ 'a': 1, '1': 2 }), [1, 2]);
16411 assert.deepEqual(over({ 'a': 2, '1': 1 }), [2, 1]);
16413 over = _.over([['a', 1]]);
16415 assert.deepEqual(over({ 'a': 1 }), [true]);
16416 assert.deepEqual(over({ 'a': 2 }), [false]);
16419 QUnit.test('should provide arguments to predicates', function(assert) {
16422 var over = _.over(function() {
16423 return slice.call(arguments);
16426 assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
16429 QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
16432 var over = _.over(function() { return this.b; }, function() { return this.a; }),
16433 object = { 'over': over, 'a': 1, 'b': 2 };
16435 assert.deepEqual(object.over(), [2, 1]);
16439 /*--------------------------------------------------------------------------*/
16441 QUnit.module('lodash.overEvery');
16444 QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
16447 var over = _.overEvery(alwaysTrue, alwaysOne, alwaysA);
16448 assert.strictEqual(over(), true);
16451 QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
16455 countFalse = function() { count++; return false; },
16456 countTrue = function() { count++; return true; },
16457 over = _.overEvery(countTrue, countFalse, countTrue);
16459 assert.strictEqual(over(), false);
16460 assert.strictEqual(count, 2);
16463 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16466 var over = _.overEvery(undefined, null);
16468 assert.strictEqual(over(true), true);
16469 assert.strictEqual(over(false), false);
16472 QUnit.test('should work with `_.property` shorthands', function(assert) {
16475 var over = _.overEvery('b', 'a');
16477 assert.strictEqual(over({ 'a': 1, 'b': 1 }), true);
16478 assert.strictEqual(over({ 'a': 0, 'b': 1 }), false);
16481 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16484 var over = _.overEvery({ 'b': 2 }, { 'a': 1 });
16486 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16487 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16490 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16493 var over = _.overEvery(['b', 2], [['a', 1]]);
16495 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16496 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16499 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16502 var over = _.overEvery(['a', 1]);
16504 assert.strictEqual(over({ 'a': 1, '1': 1 }), true);
16505 assert.strictEqual(over({ 'a': 1, '1': 0 }), false);
16506 assert.strictEqual(over({ 'a': 0, '1': 1 }), false);
16508 over = _.overEvery([['a', 1]]);
16510 assert.strictEqual(over({ 'a': 1 }), true);
16511 assert.strictEqual(over({ 'a': 2 }), false);
16514 QUnit.test('should flatten `predicates`', function(assert) {
16517 var over = _.overEvery(alwaysTrue, [alwaysFalse]);
16518 assert.strictEqual(over(), false);
16521 QUnit.test('should provide arguments to predicates', function(assert) {
16526 var over = _.overEvery(function() {
16527 args = slice.call(arguments);
16530 over('a', 'b', 'c');
16531 assert.deepEqual(args, ['a', 'b', 'c']);
16534 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16537 var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
16538 object = { 'over': over, 'a': 1, 'b': 2 };
16540 assert.strictEqual(object.over(), true);
16543 assert.strictEqual(object.over(), false);
16547 /*--------------------------------------------------------------------------*/
16549 QUnit.module('lodash.overSome');
16552 QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
16555 var over = _.overSome(alwaysFalse, alwaysOne, alwaysEmptyString);
16556 assert.strictEqual(over(), true);
16558 over = _.overSome(alwaysNull, alwaysA, alwaysZero);
16559 assert.strictEqual(over(), true);
16562 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
16566 countFalse = function() { count++; return false; },
16567 countTrue = function() { count++; return true; },
16568 over = _.overSome(countFalse, countTrue, countFalse);
16570 assert.strictEqual(over(), true);
16571 assert.strictEqual(count, 2);
16574 QUnit.test('should return `false` if all predicates return falsey', function(assert) {
16577 var over = _.overSome(alwaysFalse, alwaysFalse, alwaysFalse);
16578 assert.strictEqual(over(), false);
16580 over = _.overSome(alwaysNull, alwaysZero, alwaysEmptyString);
16581 assert.strictEqual(over(), false);
16584 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16587 var over = _.overSome(undefined, null);
16589 assert.strictEqual(over(true), true);
16590 assert.strictEqual(over(false), false);
16593 QUnit.test('should work with `_.property` shorthands', function(assert) {
16596 var over = _.overSome('b', 'a');
16598 assert.strictEqual(over({ 'a': 1, 'b': 0 }), true);
16599 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16602 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16605 var over = _.overSome({ 'b': 2 }, { 'a': 1 });
16607 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16608 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16611 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16614 var over = _.overSome(['a', 1], [['b', 2]]);
16616 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16617 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16620 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16623 var over = _.overSome(['a', 1]);
16625 assert.strictEqual(over({ 'a': 0, '1': 0 }), false);
16626 assert.strictEqual(over({ 'a': 1, '1': 0 }), true);
16627 assert.strictEqual(over({ 'a': 0, '1': 1 }), true);
16629 over = _.overSome([['a', 1]]);
16631 assert.strictEqual(over({ 'a': 1 }), true);
16632 assert.strictEqual(over({ 'a': 2 }), false);
16635 QUnit.test('should flatten `predicates`', function(assert) {
16638 var over = _.overSome(alwaysFalse, [alwaysTrue]);
16639 assert.strictEqual(over(), true);
16642 QUnit.test('should provide arguments to predicates', function(assert) {
16647 var over = _.overSome(function() {
16648 args = slice.call(arguments);
16651 over('a', 'b', 'c');
16652 assert.deepEqual(args, ['a', 'b', 'c']);
16655 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16658 var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
16659 object = { 'over': over, 'a': 1, 'b': 2 };
16661 assert.strictEqual(object.over(), true);
16663 object.a = object.b = 0;
16664 assert.strictEqual(object.over(), false);
16668 /*--------------------------------------------------------------------------*/
16670 QUnit.module('lodash.pad');
16673 var string = 'abc';
16675 QUnit.test('should pad a string to a given length', function(assert) {
16678 var values = [, undefined],
16679 expected = lodashStable.map(values, lodashStable.constant(' abc '));
16681 var actual = lodashStable.map(values, function(value, index) {
16682 return index ? _.pad(string, 6, value) : _.pad(string, 6);
16685 assert.deepEqual(actual, expected);
16688 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
16691 assert.strictEqual(_.pad(string, 8), ' abc ');
16692 assert.strictEqual(_.pad(string, 8, '_-'), '_-abc_-_');
16695 QUnit.test('should coerce `string` to a string', function(assert) {
16698 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
16699 expected = lodashStable.map(values, alwaysTrue);
16701 var actual = lodashStable.map(values, function(value) {
16702 return _.pad(value, 6) === ' abc ';
16705 assert.deepEqual(actual, expected);
16709 /*--------------------------------------------------------------------------*/
16711 QUnit.module('lodash.padEnd');
16714 var string = 'abc';
16716 QUnit.test('should pad a string to a given length', function(assert) {
16719 var values = [, undefined],
16720 expected = lodashStable.map(values, lodashStable.constant('abc '));
16722 var actual = lodashStable.map(values, function(value, index) {
16723 return index ? _.padEnd(string, 6, value) : _.padEnd(string, 6);
16726 assert.deepEqual(actual, expected);
16729 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
16732 assert.strictEqual(_.padEnd(string, 6, '_-'), 'abc_-_');
16735 QUnit.test('should coerce `string` to a string', function(assert) {
16738 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
16739 expected = lodashStable.map(values, alwaysTrue);
16741 var actual = lodashStable.map(values, function(value) {
16742 return _.padEnd(value, 6) === 'abc ';
16745 assert.deepEqual(actual, expected);
16749 /*--------------------------------------------------------------------------*/
16751 QUnit.module('lodash.padStart');
16754 var string = 'abc';
16756 QUnit.test('should pad a string to a given length', function(assert) {
16759 var values = [, undefined],
16760 expected = lodashStable.map(values, lodashStable.constant(' abc'));
16762 var actual = lodashStable.map(values, function(value, index) {
16763 return index ? _.padStart(string, 6, value) : _.padStart(string, 6);
16766 assert.deepEqual(actual, expected);
16769 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
16772 assert.strictEqual(_.padStart(string, 6, '_-'), '_-_abc');
16775 QUnit.test('should coerce `string` to a string', function(assert) {
16778 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
16779 expected = lodashStable.map(values, alwaysTrue);
16781 var actual = lodashStable.map(values, function(value) {
16782 return _.padStart(value, 6) === ' abc';
16785 assert.deepEqual(actual, expected);
16789 /*--------------------------------------------------------------------------*/
16791 QUnit.module('pad methods');
16793 lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
16794 var func = _[methodName],
16795 isPad = methodName == 'pad',
16796 isStart = methodName == 'padStart',
16799 QUnit.test('`_.' + methodName + '` should not pad if string is >= `length`', function(assert) {
16802 assert.strictEqual(func(string, 2), string);
16803 assert.strictEqual(func(string, 3), string);
16806 QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
16809 lodashStable.each([0, -2], function(length) {
16810 assert.strictEqual(func(string, length), string);
16814 QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
16817 lodashStable.each(['', '4'], function(length) {
16818 var actual = length ? (isStart ? ' abc' : 'abc ') : string;
16819 assert.strictEqual(func(string, length), actual);
16823 QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
16826 lodashStable.each([undefined, '_-'], function(chars) {
16827 var expected = chars ? (isPad ? '__' : chars) : ' ';
16828 assert.strictEqual(func(null, 2, chars), expected);
16829 assert.strictEqual(func(undefined, 2, chars), expected);
16830 assert.strictEqual(func('', 2, chars), expected);
16834 QUnit.test('`_.' + methodName + '` should return `string` when `chars` coerces to an empty string', function(assert) {
16837 var values = ['', Object('')],
16838 expected = lodashStable.map(values, lodashStable.constant(string));
16840 var actual = lodashStable.map(values, function(value) {
16841 return _.pad(string, 6, value);
16844 assert.deepEqual(actual, expected);
16848 /*--------------------------------------------------------------------------*/
16850 QUnit.module('lodash.parseInt');
16853 QUnit.test('should accept a `radix` argument', function(assert) {
16856 var expected = lodashStable.range(2, 37);
16858 var actual = lodashStable.map(expected, function(radix) {
16859 return _.parseInt('10', radix);
16862 assert.deepEqual(actual, expected);
16865 QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
16868 assert.strictEqual(_.parseInt('10'), 10);
16869 assert.strictEqual(_.parseInt('10', 0), 10);
16870 assert.strictEqual(_.parseInt('10', 10), 10);
16871 assert.strictEqual(_.parseInt('10', undefined), 10);
16874 QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
16877 lodashStable.each(['0x20', '0X20'], function(string) {
16878 assert.strictEqual(_.parseInt(string), 32);
16879 assert.strictEqual(_.parseInt(string, 0), 32);
16880 assert.strictEqual(_.parseInt(string, 16), 32);
16881 assert.strictEqual(_.parseInt(string, undefined), 32);
16885 QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
16888 assert.strictEqual(_.parseInt('08'), 8);
16889 assert.strictEqual(_.parseInt('08', 10), 8);
16892 QUnit.test('should parse strings with leading whitespace (test in Chrome and Firefox)', function(assert) {
16895 var expected = [8, 8, 10, 10, 32, 32, 32, 32];
16897 lodashStable.times(2, function(index) {
16899 func = (index ? (lodashBizarro || {}) : _).parseInt;
16902 lodashStable.times(2, function(otherIndex) {
16903 var string = otherIndex ? '10' : '08';
16905 func(whitespace + string, 10),
16906 func(whitespace + string)
16910 lodashStable.each(['0x20', '0X20'], function(string) {
16912 func(whitespace + string),
16913 func(whitespace + string, 16)
16917 assert.deepEqual(actual, expected);
16920 skipAssert(assert);
16925 QUnit.test('should coerce `radix` to a number', function(assert) {
16928 var object = { 'valueOf': alwaysZero };
16929 assert.strictEqual(_.parseInt('08', object), 8);
16930 assert.strictEqual(_.parseInt('0x20', object), 32);
16933 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
16936 var strings = lodashStable.map(['6', '08', '10'], Object),
16937 actual = lodashStable.map(strings, _.parseInt);
16939 assert.deepEqual(actual, [6, 8, 10]);
16941 actual = lodashStable.map('123', _.parseInt);
16942 assert.deepEqual(actual, [1, 2, 3]);
16946 /*--------------------------------------------------------------------------*/
16948 QUnit.module('partial methods');
16950 lodashStable.each(['partial', 'partialRight'], function(methodName) {
16951 var func = _[methodName],
16952 isPartial = methodName == 'partial',
16953 ph = func.placeholder;
16955 QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
16958 var par = func(identity, 'a');
16959 assert.strictEqual(par(), 'a');
16962 QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
16965 var fn = function(a, b) { return [a, b]; },
16966 par = func(fn, 'a'),
16967 expected = isPartial ? ['a', 'b'] : ['b', 'a'];
16969 assert.deepEqual(par('b'), expected);
16972 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
16975 var fn = function() { return arguments.length; },
16978 assert.strictEqual(par(), 0);
16981 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
16984 var par = func(identity);
16985 assert.strictEqual(par('a'), 'a');
16988 QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
16991 var fn = function() { return slice.call(arguments); },
16992 par = func(fn, ph, 'b', ph);
16994 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
16995 assert.deepEqual(par('a'), ['a', 'b', undefined]);
16996 assert.deepEqual(par(), [undefined, 'b', undefined]);
16999 assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
17001 par = func(fn, ph, 'c', ph);
17002 assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
17006 QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) {
17009 if (!isModularize) {
17010 var _ph = _.placeholder = {},
17011 fn = function() { return slice.call(arguments); },
17012 par = func(fn, _ph, 'b', ph),
17013 expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph];
17015 assert.deepEqual(par('a', 'c'), expected);
17016 delete _.placeholder;
17019 skipAssert(assert);
17023 QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
17026 var fn = function(a, b, c) {},
17027 par = func(fn, 'a');
17029 assert.strictEqual(par.length, 0);
17032 QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
17035 function Foo(value) {
17036 return value && object;
17042 assert.ok(new par instanceof Foo);
17043 assert.strictEqual(new par(true), object);
17046 QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
17049 function greet(greeting, name) {
17050 return greeting + ' ' + name;
17053 var par1 = func(greet, 'hi'),
17054 par2 = func(par1, 'barney'),
17055 par3 = func(par1, 'pebbles');
17057 assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
17058 assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
17059 assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
17062 QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
17065 var fn = function(a, b, c) { return a + b + c; },
17066 curried = _.curry(func(fn, 1), 2);
17068 assert.strictEqual(curried(2, 3), 6);
17069 assert.strictEqual(curried(2)(3), 6);
17072 QUnit.test('should work with placeholders and curried functions', function(assert) {
17075 var fn = function() { return slice.call(arguments); },
17076 curried = _.curry(fn),
17077 par = func(curried, ph, 'b', ph, 'd');
17079 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
17083 /*--------------------------------------------------------------------------*/
17085 QUnit.module('lodash.partialRight');
17088 QUnit.test('should work as a deep `_.defaults`', function(assert) {
17091 var object = { 'a': { 'b': 1 } },
17092 source = { 'a': { 'b': 2, 'c': 3 } },
17093 expected = { 'a': { 'b': 1, 'c': 3 } };
17095 var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
17096 return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
17099 assert.deepEqual(defaultsDeep(object, source), expected);
17103 /*--------------------------------------------------------------------------*/
17105 QUnit.module('methods using `createWrapper`');
17109 return slice.call(arguments);
17112 var ph1 = _.bind.placeholder,
17113 ph2 = _.bindKey.placeholder,
17114 ph3 = _.partial.placeholder,
17115 ph4 = _.partialRight.placeholder;
17117 QUnit.test('should work with combinations of partial functions', function(assert) {
17120 var a = _.partial(fn),
17121 b = _.partialRight(a, 3),
17122 c = _.partial(b, 1);
17124 assert.deepEqual(c(2), [1, 2, 3]);
17127 QUnit.test('should work with combinations of bound and partial functions', function(assert) {
17130 var fn = function() {
17131 var result = [this.a];
17132 push.apply(result, arguments);
17136 var expected = [1, 2, 3, 4],
17137 object = { 'a': 1, 'fn': fn };
17139 var a = _.bindKey(object, 'fn'),
17140 b = _.partialRight(a, 4),
17141 c = _.partial(b, 2);
17143 assert.deepEqual(c(3), expected);
17145 a = _.bind(fn, object);
17146 b = _.partialRight(a, 4);
17147 c = _.partial(b, 2);
17149 assert.deepEqual(c(3), expected);
17151 a = _.partial(fn, 2);
17152 b = _.bind(a, object);
17153 c = _.partialRight(b, 4);
17155 assert.deepEqual(c(3), expected);
17158 QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
17161 function Foo(a, b, c) {
17162 return b === 0 && object;
17165 var combo = _.partial(_.partialRight(Foo, 3), 1),
17168 assert.ok(new combo(2) instanceof Foo);
17169 assert.strictEqual(new combo(0), object);
17172 QUnit.test('should work with combinations of functions with placeholders', function(assert) {
17175 var expected = [1, 2, 3, 4, 5, 6],
17176 object = { 'fn': fn };
17178 var a = _.bindKey(object, 'fn', ph2, 2),
17179 b = _.partialRight(a, ph4, 6),
17180 c = _.partial(b, 1, ph3, 4);
17182 assert.deepEqual(c(3, 5), expected);
17184 a = _.bind(fn, object, ph1, 2);
17185 b = _.partialRight(a, ph4, 6);
17186 c = _.partial(b, 1, ph3, 4);
17188 assert.deepEqual(c(3, 5), expected);
17190 a = _.partial(fn, ph3, 2);
17191 b = _.bind(a, object, 1, ph1, 4);
17192 c = _.partialRight(b, ph4, 6);
17194 assert.deepEqual(c(3, 5), expected);
17197 QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
17200 var expected = [1, 2, 3, 4],
17201 object = { 'fn': fn };
17203 var a = _.bindKey(object, 'fn', ph2, 2),
17204 b = _.partialRight(a, ph4, 4),
17205 c = _.partial(b, ph3, 3);
17207 assert.deepEqual(c(1), expected);
17209 a = _.bind(fn, object, ph1, 2);
17210 b = _.partialRight(a, ph4, 4);
17211 c = _.partial(b, ph3, 3);
17213 assert.deepEqual(c(1), expected);
17215 a = _.partial(fn, ph3, 2);
17216 b = _.bind(a, object, ph1, 3);
17217 c = _.partialRight(b, ph4, 4);
17219 assert.deepEqual(c(1), expected);
17222 QUnit.test('should work with recursively bound functions', function(assert) {
17225 var fn = function() {
17229 var a = _.bind(fn, { 'a': 1 }),
17230 b = _.bind(a, { 'a': 2 }),
17231 c = _.bind(b, { 'a': 3 });
17233 assert.strictEqual(c(), 1);
17236 QUnit.test('should work when hot', function(assert) {
17239 lodashStable.times(2, function(index) {
17240 var fn = function() {
17241 var result = [this];
17242 push.apply(result, arguments);
17247 bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17248 expected = [object, 1, 2, 3];
17250 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17251 var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17252 return index ? bound2(3) : bound2(1, 2, 3);
17255 assert.deepEqual(actual, expected);
17257 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17258 var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17259 bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17261 return index ? bound2(3) : bound2(1, 2, 3);
17264 assert.deepEqual(actual, expected);
17267 lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
17268 var fn = function(a, b, c) { return [a, b, c]; },
17269 curried = _[methodName](fn),
17270 expected = index ? [3, 2, 1] : [1, 2, 3];
17272 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17273 return curried(1)(2)(3);
17276 assert.deepEqual(actual, expected);
17278 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17279 var curried = _[methodName](fn);
17280 return curried(1)(2)(3);
17283 assert.deepEqual(actual, expected);
17286 lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
17287 var func = _[methodName],
17288 fn = function() { return slice.call(arguments); },
17289 par1 = func(fn, 1),
17290 expected = index ? [3, 2, 1] : [1, 2, 3];
17292 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17293 var par2 = func(par1, 2);
17297 assert.deepEqual(actual, expected);
17299 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17300 var par1 = func(fn, 1),
17301 par2 = func(par1, 2);
17306 assert.deepEqual(actual, expected);
17311 /*--------------------------------------------------------------------------*/
17313 QUnit.module('lodash.partition');
17316 var array = [1, 0, 1];
17318 QUnit.test('should split elements into two groups by `predicate`', function(assert) {
17321 assert.deepEqual(_.partition([], identity), [[], []]);
17322 assert.deepEqual(_.partition(array, alwaysTrue), [array, []]);
17323 assert.deepEqual(_.partition(array, alwaysFalse), [[], array]);
17326 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
17329 var values = [, null, undefined],
17330 expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
17332 var actual = lodashStable.map(values, function(value, index) {
17333 return index ? _.partition(array, value) : _.partition(array);
17336 assert.deepEqual(actual, expected);
17339 QUnit.test('should work with `_.property` shorthands', function(assert) {
17342 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
17343 actual = _.partition(objects, 'a');
17345 assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
17348 QUnit.test('should work with a number for `predicate`', function(assert) {
17357 assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
17358 assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
17361 QUnit.test('should work with an object for `collection`', function(assert) {
17364 var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
17365 assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
17369 /*--------------------------------------------------------------------------*/
17371 QUnit.module('lodash.pick');
17374 var args = arguments,
17375 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
17377 QUnit.test('should flatten `props`', function(assert) {
17380 assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
17381 assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
17384 QUnit.test('should work with a primitive `object` argument', function(assert) {
17387 assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
17390 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
17393 lodashStable.each([null, undefined], function(value) {
17394 assert.deepEqual(_.pick(value, 'valueOf'), {});
17398 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
17401 assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
17404 QUnit.test('should coerce property names to strings', function(assert) {
17407 assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
17411 /*--------------------------------------------------------------------------*/
17413 QUnit.module('lodash.pickBy');
17416 QUnit.test('should work with a predicate argument', function(assert) {
17419 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
17421 var actual = _.pickBy(object, function(n) {
17422 return n == 1 || n == 3;
17425 assert.deepEqual(actual, { 'a': 1, 'c': 3 });
17429 /*--------------------------------------------------------------------------*/
17431 QUnit.module('pick methods');
17433 lodashStable.each(['pick', 'pickBy'], function(methodName) {
17434 var expected = { 'a': 1, 'c': 3 },
17435 func = _[methodName],
17436 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
17437 prop = lodashStable.nthArg(1);
17439 if (methodName == 'pickBy') {
17440 prop = function(object, props) {
17441 props = lodashStable.castArray(props);
17442 return function(value) {
17443 return lodashStable.some(props, function(key) {
17444 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
17445 return object[key] === value;
17450 QUnit.test('`_.' + methodName + '` should create an object of picked string keyed properties', function(assert) {
17453 assert.deepEqual(func(object, prop(object, 'a')), { 'a': 1 });
17454 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
17457 QUnit.test('`_.' + methodName + '` should pick inherited string keyed properties', function(assert) {
17461 Foo.prototype = object;
17464 assert.deepEqual(func(foo, prop(foo, ['a', 'c'])), expected);
17467 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
17470 var object = { '-0': 'a', '0': 'b' },
17471 props = [-0, Object(-0), 0, Object(0)],
17472 expected = [{ '-0': 'a' }, { '-0': 'a' }, { '0': 'b' }, { '0': 'b' }];
17474 var actual = lodashStable.map(props, function(key) {
17475 return func(object, prop(object, key));
17478 assert.deepEqual(actual, expected);
17481 QUnit.test('`_.' + methodName + '` should pick symbol properties', function(assert) {
17489 var symbol2 = Symbol('b');
17490 Foo.prototype[symbol2] = 2;
17493 actual = func(foo, prop(foo, [symbol, symbol2]));
17495 assert.strictEqual(actual[symbol], 1);
17496 assert.strictEqual(actual[symbol2], 2);
17499 skipAssert(assert, 2);
17503 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
17506 var array = [1, 2, 3];
17507 assert.deepEqual(func(array, prop(array, '1')), { '1': 2 });
17511 /*--------------------------------------------------------------------------*/
17513 QUnit.module('lodash.property');
17516 QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
17519 var object = { 'a': 1 };
17521 lodashStable.each(['a', ['a']], function(path) {
17522 var prop = _.property(path);
17523 assert.strictEqual(prop.length, 1);
17524 assert.strictEqual(prop(object), 1);
17528 QUnit.test('should pluck deep property values', function(assert) {
17531 var object = { 'a': { 'b': 2 } };
17533 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17534 var prop = _.property(path);
17535 assert.strictEqual(prop(object), 2);
17539 QUnit.test('should pluck inherited property values', function(assert) {
17543 Foo.prototype.a = 1;
17545 lodashStable.each(['a', ['a']], function(path) {
17546 var prop = _.property(path);
17547 assert.strictEqual(prop(new Foo), 1);
17551 QUnit.test('should work with a non-string `path`', function(assert) {
17554 var array = [1, 2, 3];
17556 lodashStable.each([1, [1]], function(path) {
17557 var prop = _.property(path);
17558 assert.strictEqual(prop(array), 2);
17562 QUnit.test('should preserve the sign of `0`', function(assert) {
17565 var object = { '-0': 'a', '0': 'b' },
17566 props = [-0, Object(-0), 0, Object(0)];
17568 var actual = lodashStable.map(props, function(key) {
17569 var prop = _.property(key);
17570 return prop(object);
17573 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
17576 QUnit.test('should coerce key to a string', function(assert) {
17580 fn.toString = lodashStable.constant('fn');
17582 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
17583 values = [null, undefined, fn, {}];
17585 var actual = lodashStable.transform(objects, function(result, object, index) {
17586 var key = values[index];
17587 lodashStable.each([key, [key]], function(path) {
17588 var prop = _.property(key);
17589 result.push(prop(object));
17593 assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
17596 QUnit.test('should pluck a key over a path', function(assert) {
17599 var object = { 'a.b': 1, 'a': { 'b': 2 } };
17601 lodashStable.each(['a.b', ['a.b']], function(path) {
17602 var prop = _.property(path);
17603 assert.strictEqual(prop(object), 1);
17607 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
17610 var values = [, null, undefined],
17611 expected = lodashStable.map(values, noop);
17613 lodashStable.each(['constructor', ['constructor']], function(path) {
17614 var prop = _.property(path);
17616 var actual = lodashStable.map(values, function(value, index) {
17617 return index ? prop(value) : prop();
17620 assert.deepEqual(actual, expected);
17624 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
17627 var values = [, null, undefined],
17628 expected = lodashStable.map(values, noop);
17630 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
17631 var prop = _.property(path);
17633 var actual = lodashStable.map(values, function(value, index) {
17634 return index ? prop(value) : prop();
17637 assert.deepEqual(actual, expected);
17641 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
17646 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
17647 var prop = _.property(path);
17648 assert.strictEqual(prop(object), undefined);
17653 /*--------------------------------------------------------------------------*/
17655 QUnit.module('lodash.propertyOf');
17658 QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
17661 var object = { 'a': 1 },
17662 propOf = _.propertyOf(object);
17664 assert.strictEqual(propOf.length, 1);
17665 lodashStable.each(['a', ['a']], function(path) {
17666 assert.strictEqual(propOf(path), 1);
17670 QUnit.test('should pluck deep property values', function(assert) {
17673 var object = { 'a': { 'b': 2 } },
17674 propOf = _.propertyOf(object);
17676 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17677 assert.strictEqual(propOf(path), 2);
17681 QUnit.test('should pluck inherited property values', function(assert) {
17687 Foo.prototype.b = 2;
17689 var propOf = _.propertyOf(new Foo);
17691 lodashStable.each(['b', ['b']], function(path) {
17692 assert.strictEqual(propOf(path), 2);
17696 QUnit.test('should work with a non-string `path`', function(assert) {
17699 var array = [1, 2, 3],
17700 propOf = _.propertyOf(array);
17702 lodashStable.each([1, [1]], function(path) {
17703 assert.strictEqual(propOf(path), 2);
17707 QUnit.test('should preserve the sign of `0`', function(assert) {
17710 var object = { '-0': 'a', '0': 'b' },
17711 props = [-0, Object(-0), 0, Object(0)];
17713 var actual = lodashStable.map(props, function(key) {
17714 var propOf = _.propertyOf(object);
17715 return propOf(key);
17718 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
17721 QUnit.test('should coerce key to a string', function(assert) {
17725 fn.toString = lodashStable.constant('fn');
17727 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
17728 values = [null, undefined, fn, {}];
17730 var actual = lodashStable.transform(objects, function(result, object, index) {
17731 var key = values[index];
17732 lodashStable.each([key, [key]], function(path) {
17733 var propOf = _.propertyOf(object);
17734 result.push(propOf(key));
17738 assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
17741 QUnit.test('should pluck a key over a path', function(assert) {
17744 var object = { 'a.b': 1, 'a': { 'b': 2 } },
17745 propOf = _.propertyOf(object);
17747 lodashStable.each(['a.b', ['a.b']], function(path) {
17748 assert.strictEqual(propOf(path), 1);
17752 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
17755 var values = [, null, undefined],
17756 expected = lodashStable.map(values, noop);
17758 lodashStable.each(['constructor', ['constructor']], function(path) {
17759 var actual = lodashStable.map(values, function(value, index) {
17760 var propOf = index ? _.propertyOf(value) : _.propertyOf();
17761 return propOf(path);
17764 assert.deepEqual(actual, expected);
17768 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
17771 var values = [, null, undefined],
17772 expected = lodashStable.map(values, noop);
17774 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
17775 var actual = lodashStable.map(values, function(value, index) {
17776 var propOf = index ? _.propertyOf(value) : _.propertyOf();
17777 return propOf(path);
17780 assert.deepEqual(actual, expected);
17784 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
17787 var propOf = _.propertyOf({});
17789 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
17790 assert.strictEqual(propOf(path), undefined);
17795 /*--------------------------------------------------------------------------*/
17797 QUnit.module('lodash.pullAllBy');
17800 QUnit.test('should accept an `iteratee` argument', function(assert) {
17803 var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
17805 var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
17809 assert.deepEqual(actual, [{ 'x': 2 }]);
17812 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
17816 array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
17818 _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
17819 args || (args = slice.call(arguments));
17822 assert.deepEqual(args, [{ 'x': 1 }]);
17826 /*--------------------------------------------------------------------------*/
17828 QUnit.module('lodash.pullAllWith');
17831 QUnit.test('should work with a `comparator` argument', function(assert) {
17834 var objects = [{ 'x': 1, 'y': 1 }, { 'x': 2, 'y': 2 }, { 'x': 3, 'y': 3 }],
17835 expected = [objects[0], objects[2]],
17836 actual = _.pullAllWith(objects, [{ 'x': 2, 'y': 2 }], lodashStable.isEqual);
17838 assert.deepEqual(actual, expected);
17842 /*--------------------------------------------------------------------------*/
17844 QUnit.module('pull methods');
17846 lodashStable.each(['pull', 'pullAll', 'pullAllWith'], function(methodName) {
17847 var func = _[methodName],
17848 isPull = methodName == 'pull';
17850 function pull(array, values) {
17852 ? func.apply(undefined, [array].concat(values))
17853 : func(array, values);
17856 QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
17859 var array = [1, 2, 3],
17860 actual = pull(array, [1, 3]);
17862 assert.deepEqual(array, [2]);
17863 assert.ok(actual === array);
17866 QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
17869 var array = [1, 2, 3, 4];
17874 assert.notOk('0' in array);
17875 assert.notOk('2' in array);
17878 QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
17881 var array = [1, 2, 3];
17884 pull(array, [undefined]);
17885 assert.deepEqual(array, [1, 3]);
17888 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
17891 var array = [1, NaN, 3, NaN];
17893 pull(array, [NaN]);
17894 assert.deepEqual(array, [1, 3]);
17898 /*--------------------------------------------------------------------------*/
17900 QUnit.module('lodash.pullAt');
17903 QUnit.test('should modify the array and return removed elements', function(assert) {
17906 var array = [1, 2, 3],
17907 actual = _.pullAt(array, [0, 1]);
17909 assert.deepEqual(array, [3]);
17910 assert.deepEqual(actual, [1, 2]);
17913 QUnit.test('should work with unsorted indexes', function(assert) {
17916 var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
17917 actual = _.pullAt(array, [1, 3, 11, 7, 5, 9]);
17919 assert.deepEqual(array, [1, 3, 5, 7, 9, 11]);
17920 assert.deepEqual(actual, [2, 4, 12, 8, 6, 10]);
17923 QUnit.test('should work with repeated indexes', function(assert) {
17926 var array = [1, 2, 3, 4],
17927 actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
17929 assert.deepEqual(array, [4]);
17930 assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
17933 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
17936 var array = ['a', 'b', 'c'],
17937 actual = _.pullAt(array, [2, 4, 0]);
17939 assert.deepEqual(array, ['b']);
17940 assert.deepEqual(actual, ['c', undefined, 'a']);
17943 QUnit.test('should flatten `indexes`', function(assert) {
17946 var array = ['a', 'b', 'c'];
17947 assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
17948 assert.deepEqual(array, ['b']);
17950 array = ['a', 'b', 'c', 'd'];
17951 assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
17952 assert.deepEqual(array, ['b']);
17955 QUnit.test('should return an empty array when no indexes are given', function(assert) {
17958 var array = ['a', 'b', 'c'],
17959 actual = _.pullAt(array);
17961 assert.deepEqual(array, ['a', 'b', 'c']);
17962 assert.deepEqual(actual, []);
17964 actual = _.pullAt(array, [], []);
17966 assert.deepEqual(array, ['a', 'b', 'c']);
17967 assert.deepEqual(actual, []);
17970 QUnit.test('should work with non-index paths', function(assert) {
17973 var values = lodashStable.reject(empties, function(value) {
17974 return (value === 0) || lodashStable.isArray(value);
17975 }).concat(-1, 1.1);
17977 var array = lodashStable.transform(values, function(result, value) {
17981 var expected = lodashStable.map(values, alwaysOne),
17982 actual = _.pullAt(array, values);
17984 assert.deepEqual(actual, expected);
17986 expected = lodashStable.map(values, noop),
17987 actual = lodashStable.at(array, values);
17989 assert.deepEqual(actual, expected);
17992 QUnit.test('should preserve the sign of `0`', function(assert) {
17995 var props = [-0, Object(-0), 0, Object(0)];
17997 var actual = lodashStable.map(props, function(key) {
18000 return _.pullAt(array, key);
18003 assert.deepEqual(actual, [[-2], [-2], [-1], [-1]]);
18006 QUnit.test('should work with deep paths', function(assert) {
18010 array.a = { 'b': 2 };
18012 var actual = _.pullAt(array, 'a.b');
18014 assert.deepEqual(actual, [2]);
18015 assert.deepEqual(array.a, {});
18018 actual = _.pullAt(array, 'a.b.c');
18021 assert.deepEqual(actual, [undefined]);
18024 QUnit.test('should work with a falsey `array` argument when keys are given', function(assert) {
18027 var values = falsey.slice(),
18028 expected = lodashStable.map(values, lodashStable.constant(Array(4)));
18030 var actual = lodashStable.map(values, function(array) {
18032 return _.pullAt(array, 0, 1, 'pop', 'push');
18036 assert.deepEqual(actual, expected);
18040 /*--------------------------------------------------------------------------*/
18042 QUnit.module('lodash.random');
18045 var array = Array(1000);
18047 QUnit.test('should return `0` or `1` when no arguments are given', function(assert) {
18050 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18054 assert.deepEqual(actual, [0, 1]);
18057 QUnit.test('should support a `min` and `max` argument', function(assert) {
18063 assert.ok(_.some(array, function() {
18064 var result = _.random(min, max);
18065 return result >= min && result <= max;
18069 QUnit.test('should support not providing a `max` argument', function(assert) {
18075 assert.ok(_.some(array, function() {
18076 var result = _.random(max);
18077 return result >= min && result <= max;
18081 QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
18086 expected = [2, 3, 4];
18088 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18089 return _.random(min, max);
18092 assert.deepEqual(actual, expected);
18095 QUnit.test('should support large integer values', function(assert) {
18098 var min = Math.pow(2, 31),
18099 max = Math.pow(2, 62);
18101 assert.ok(lodashStable.every(array, function() {
18102 var result = _.random(min, max);
18103 return result >= min && result <= max;
18106 assert.ok(_.some(array, function() {
18107 return _.random(MAX_INTEGER) > 0;
18111 QUnit.test('should coerce arguments to finite numbers', function(assert) {
18114 assert.strictEqual(_.random('1', '1'), 1);
18115 assert.strictEqual(_.random(NaN, NaN), 0);
18118 QUnit.test('should support floats', function(assert) {
18123 actual = _.random(min, max);
18125 assert.ok(actual % 1);
18126 assert.ok(actual >= min && actual <= max);
18129 QUnit.test('should support providing a `floating` argument', function(assert) {
18132 var actual = _.random(true);
18133 assert.ok(actual % 1 && actual >= 0 && actual <= 1);
18135 actual = _.random(2, true);
18136 assert.ok(actual % 1 && actual >= 0 && actual <= 2);
18138 actual = _.random(2, 4, true);
18139 assert.ok(actual % 1 && actual >= 2 && actual <= 4);
18142 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18145 var array = [1, 2, 3],
18146 expected = lodashStable.map(array, alwaysTrue),
18147 randoms = lodashStable.map(array, _.random);
18149 var actual = lodashStable.map(randoms, function(result, index) {
18150 return result >= 0 && result <= array[index] && (result % 1) == 0;
18153 assert.deepEqual(actual, expected);
18157 /*--------------------------------------------------------------------------*/
18159 QUnit.module('range methods');
18161 lodashStable.each(['range', 'rangeRight'], function(methodName) {
18162 var func = _[methodName],
18163 isRange = methodName == 'range';
18165 function resolve(range) {
18166 return isRange ? range : range.reverse();
18169 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `end` is given', function(assert) {
18172 assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
18173 assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
18176 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `start` and `end` are given', function(assert) {
18179 assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
18180 assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
18183 QUnit.test('`_.' + methodName + '` should work with `start`, `end`, and `step` arguments', function(assert) {
18186 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18187 assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
18188 assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
18191 QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
18194 assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
18197 QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
18200 assert.deepEqual(func(1, 5, 20), [1]);
18203 QUnit.test('`_.' + methodName + '` should work with a negative `step`', function(assert) {
18206 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18207 assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
18210 QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
18213 var actual = func(-0, 1);
18214 assert.strictEqual(1 / actual[0], -Infinity);
18217 QUnit.test('`_.' + methodName + '` should treat falsey `start` arguments as `0`', function(assert) {
18220 lodashStable.each(falsey, function(value, index) {
18222 assert.deepEqual(func(value), []);
18223 assert.deepEqual(func(value, 1), [0]);
18225 assert.deepEqual(func(), []);
18230 QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
18233 var actual = [func('0', 1), func('1'), func(0, 1, '1'), func(NaN), func(NaN, NaN)];
18234 assert.deepEqual(actual, [[0], [0], [0], [], []]);
18237 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
18240 var array = [1, 2, 3],
18241 object = { 'a': 1, 'b': 2, 'c': 3 },
18242 expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
18244 lodashStable.each([array, object], function(collection) {
18245 var actual = lodashStable.map(collection, func);
18246 assert.deepEqual(actual, expected);
18251 /*--------------------------------------------------------------------------*/
18253 QUnit.module('lodash.rearg');
18257 return slice.call(arguments);
18260 QUnit.test('should reorder arguments provided to `func`', function(assert) {
18263 var rearged = _.rearg(fn, [2, 0, 1]);
18264 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18267 QUnit.test('should work with repeated indexes', function(assert) {
18270 var rearged = _.rearg(fn, [1, 1, 1]);
18271 assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
18274 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
18277 var rearged = _.rearg(fn, [1, 4]);
18278 assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
18281 QUnit.test('should use `undefined` for non-index values', function(assert) {
18284 var values = lodashStable.reject(empties, function(value) {
18285 return (value === 0) || lodashStable.isArray(value);
18286 }).concat(-1, 1.1);
18288 var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
18290 var actual = lodashStable.map(values, function(value) {
18291 var rearged = _.rearg(fn, [value]);
18292 return rearged('a', 'b', 'c');
18295 assert.deepEqual(actual, expected);
18298 QUnit.test('should not rearrange arguments when no indexes are given', function(assert) {
18301 var rearged = _.rearg(fn);
18302 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18304 rearged = _.rearg(fn, [], []);
18305 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18308 QUnit.test('should accept multiple index arguments', function(assert) {
18311 var rearged = _.rearg(fn, 2, 0, 1);
18312 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18315 QUnit.test('should accept multiple arrays of indexes', function(assert) {
18318 var rearged = _.rearg(fn, [2], [0, 1]);
18319 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18322 QUnit.test('should work with fewer indexes than arguments', function(assert) {
18325 var rearged = _.rearg(fn, [1, 0]);
18326 assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
18329 QUnit.test('should work on functions that have been rearged', function(assert) {
18332 var rearged1 = _.rearg(fn, 2, 1, 0),
18333 rearged2 = _.rearg(rearged1, 1, 0, 2);
18335 assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
18339 /*--------------------------------------------------------------------------*/
18341 QUnit.module('lodash.reduce');
18344 var array = [1, 2, 3];
18346 QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
18349 assert.strictEqual(_.reduce(array), 1);
18352 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
18357 _.reduce(array, function() {
18358 args || (args = slice.call(arguments));
18361 assert.deepEqual(args, [0, 1, 0, array]);
18364 _.reduce(array, function() {
18365 args || (args = slice.call(arguments));
18368 assert.deepEqual(args, [1, 2, 1, array]);
18371 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
18375 object = { 'a': 1, 'b': 2 },
18376 firstKey = _.head(_.keys(object));
18378 var expected = firstKey == 'a'
18379 ? [0, 1, 'a', object]
18380 : [0, 2, 'b', object];
18382 _.reduce(object, function() {
18383 args || (args = slice.call(arguments));
18386 assert.deepEqual(args, expected);
18389 expected = firstKey == 'a'
18390 ? [1, 2, 'b', object]
18391 : [2, 1, 'a', object];
18393 _.reduce(object, function() {
18394 args || (args = slice.call(arguments));
18397 assert.deepEqual(args, expected);
18401 /*--------------------------------------------------------------------------*/
18403 QUnit.module('lodash.reduceRight');
18406 var array = [1, 2, 3];
18408 QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
18411 assert.strictEqual(_.reduceRight(array), 3);
18414 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
18419 _.reduceRight(array, function() {
18420 args || (args = slice.call(arguments));
18423 assert.deepEqual(args, [0, 3, 2, array]);
18426 _.reduceRight(array, function() {
18427 args || (args = slice.call(arguments));
18430 assert.deepEqual(args, [3, 2, 1, array]);
18433 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
18437 object = { 'a': 1, 'b': 2 },
18438 isFIFO = lodashStable.keys(object)[0] == 'a';
18440 var expected = isFIFO
18441 ? [0, 2, 'b', object]
18442 : [0, 1, 'a', object];
18444 _.reduceRight(object, function() {
18445 args || (args = slice.call(arguments));
18448 assert.deepEqual(args, expected);
18452 ? [2, 1, 'a', object]
18453 : [1, 2, 'b', object];
18455 _.reduceRight(object, function() {
18456 args || (args = slice.call(arguments));
18459 assert.deepEqual(args, expected);
18463 /*--------------------------------------------------------------------------*/
18465 QUnit.module('reduce methods');
18467 lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
18468 var func = _[methodName],
18470 isReduce = methodName == 'reduce';
18472 QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
18475 var actual = func(['a', 'b', 'c'], function(accumulator, value) {
18476 return accumulator + value;
18479 assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
18482 QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
18486 expected = lodashStable.map(empties, noop);
18488 lodashStable.each(empties, function(value) {
18490 actual.push(func(value, noop));
18494 assert.deepEqual(actual, expected);
18497 QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
18500 var expected = lodashStable.map(empties, lodashStable.constant('x'));
18502 var actual = lodashStable.map(empties, function(value) {
18504 return func(value, noop, 'x');
18508 assert.deepEqual(actual, expected);
18511 QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
18514 var actual = func([], noop, undefined);
18515 assert.strictEqual(actual, undefined);
18518 QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is given (test in IE > 9 and modern browsers)', function(assert) {
18522 object = { '0': 1, 'length': 0 };
18524 if ('__proto__' in array) {
18525 array.__proto__ = object;
18526 assert.strictEqual(func(array, noop), undefined);
18529 skipAssert(assert);
18531 assert.strictEqual(func(object, noop), undefined);
18534 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
18538 assert.strictEqual(_(array)[methodName](add), 6);
18541 skipAssert(assert);
18545 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
18549 assert.ok(_(array).chain()[methodName](add) instanceof _);
18552 skipAssert(assert);
18557 /*--------------------------------------------------------------------------*/
18559 QUnit.module('lodash.reject');
18562 var array = [1, 2, 3];
18564 QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
18567 assert.deepEqual(_.reject(array, isEven), [1, 3]);
18571 /*--------------------------------------------------------------------------*/
18573 QUnit.module('filter methods');
18575 lodashStable.each(['filter', 'reject'], function(methodName) {
18576 var array = [1, 2, 3, 4],
18577 func = _[methodName],
18578 isFilter = methodName == 'filter',
18579 objects = [{ 'a': 0 }, { 'a': 1 }];
18581 QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
18584 var actual = func([0], function(value, index, array) {
18589 assert.deepEqual(actual, [0]);
18592 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
18595 assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
18598 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
18601 assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
18604 QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
18608 var wrapped = _(array);
18610 var actual = wrapped[methodName](function(n) {
18614 assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
18616 actual = wrapped[methodName](function(n) {
18620 assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
18623 skipAssert(assert, 2);
18627 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
18631 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
18632 predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); },
18633 actual = _(array).slice(1).map(square)[methodName](predicate).value();
18635 assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
18637 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
18638 return ['key' + index, index];
18641 actual = _(object).mapValues(square)[methodName](predicate).value();
18642 assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
18645 skipAssert(assert, 2);
18649 QUnit.test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
18654 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
18655 expected = [1, 0, lodashStable.map(array.slice(1), square)];
18657 _(array).slice(1)[methodName](function(value, index, array) {
18658 args || (args = slice.call(arguments));
18661 assert.deepEqual(args, [1, 0, array.slice(1)]);
18664 _(array).slice(1).map(square)[methodName](function(value, index, array) {
18665 args || (args = slice.call(arguments));
18668 assert.deepEqual(args, expected);
18671 _(array).slice(1).map(square)[methodName](function(value, index) {
18672 args || (args = slice.call(arguments));
18675 assert.deepEqual(args, expected);
18678 _(array).slice(1).map(square)[methodName](function(value) {
18679 args || (args = slice.call(arguments));
18682 assert.deepEqual(args, [1]);
18685 _(array).slice(1).map(square)[methodName](function() {
18686 args || (args = slice.call(arguments));
18689 assert.deepEqual(args, expected);
18692 skipAssert(assert, 5);
18697 /*--------------------------------------------------------------------------*/
18699 QUnit.module('lodash.remove');
18702 QUnit.test('should modify the array and return removed elements', function(assert) {
18705 var array = [1, 2, 3, 4];
18707 var actual = _.remove(array, function(n) {
18711 assert.deepEqual(array, [1, 3]);
18712 assert.deepEqual(actual, [2, 4]);
18715 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
18720 clone = array.slice();
18722 _.remove(array, function(n, index) {
18723 var args = slice.call(arguments);
18724 args[2] = args[2].slice();
18725 argsList.push(args);
18726 return isEven(index);
18729 assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
18732 QUnit.test('should work with `_.matches` shorthands', function(assert) {
18735 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
18736 _.remove(objects, { 'a': 1 });
18737 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
18740 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
18743 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
18744 _.remove(objects, ['a', 1]);
18745 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
18748 QUnit.test('should work with `_.property` shorthands', function(assert) {
18751 var objects = [{ 'a': 0 }, { 'a': 1 }];
18752 _.remove(objects, 'a');
18753 assert.deepEqual(objects, [{ 'a': 0 }]);
18756 QUnit.test('should preserve holes in arrays', function(assert) {
18759 var array = [1, 2, 3, 4];
18763 _.remove(array, function(n) {
18767 assert.notOk('0' in array);
18768 assert.notOk('2' in array);
18771 QUnit.test('should treat holes as `undefined`', function(assert) {
18774 var array = [1, 2, 3];
18777 _.remove(array, function(n) {
18781 assert.deepEqual(array, [1, 3]);
18784 QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
18787 var array = [1, 2, 3];
18789 _.remove(array, function(n, index) {
18790 return isEven(index);
18793 assert.deepEqual(array, [2]);
18797 /*--------------------------------------------------------------------------*/
18799 QUnit.module('lodash.repeat');
18802 var string = 'abc';
18804 QUnit.test('should repeat a string `n` times', function(assert) {
18807 assert.strictEqual(_.repeat('*', 3), '***');
18808 assert.strictEqual(_.repeat(string, 2), 'abcabc');
18811 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
18814 var expected = lodashStable.map(falsey, function(value) {
18815 return value === undefined ? string : '';
18818 var actual = lodashStable.map(falsey, function(n, index) {
18819 return index ? _.repeat(string, n) : _.repeat(string);
18822 assert.deepEqual(actual, expected);
18825 QUnit.test('should return an empty string if `n` is <= `0`', function(assert) {
18828 assert.strictEqual(_.repeat(string, 0), '');
18829 assert.strictEqual(_.repeat(string, -2), '');
18832 QUnit.test('should coerce `n` to an integer', function(assert) {
18835 assert.strictEqual(_.repeat(string, '2'), 'abcabc');
18836 assert.strictEqual(_.repeat(string, 2.6), 'abcabc');
18837 assert.strictEqual(_.repeat('*', { 'valueOf': alwaysThree }), '***');
18840 QUnit.test('should coerce `string` to a string', function(assert) {
18843 assert.strictEqual(_.repeat(Object(string), 2), 'abcabc');
18844 assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
18847 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18850 var actual = lodashStable.map(['a', 'b', 'c'], _.repeat);
18851 assert.deepEqual(actual, ['a', 'b', 'c']);
18855 /*--------------------------------------------------------------------------*/
18857 QUnit.module('lodash.replace');
18860 QUnit.test('should replace the matched pattern', function(assert) {
18863 var string = 'abcde';
18864 assert.strictEqual(_.replace(string, 'de', '123'), 'abc123');
18865 assert.strictEqual(_.replace(string, /[bd]/g, '-'), 'a-c-e');
18869 /*--------------------------------------------------------------------------*/
18871 QUnit.module('lodash.result');
18874 var object = { 'a': 1, 'b': alwaysB };
18876 QUnit.test('should invoke function values', function(assert) {
18879 assert.strictEqual(_.result(object, 'b'), 'b');
18882 QUnit.test('should invoke default function values', function(assert) {
18885 var actual = _.result(object, 'c', object.b);
18886 assert.strictEqual(actual, 'b');
18889 QUnit.test('should invoke nested function values', function(assert) {
18892 var value = { 'a': lodashStable.constant({ 'b': alwaysB }) };
18894 lodashStable.each(['a.b', ['a', 'b']], function(path) {
18895 assert.strictEqual(_.result(value, path), 'b');
18899 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
18902 var value = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
18904 lodashStable.each(['a.b', ['a', 'b']], function(path) {
18905 assert.strictEqual(_.result(value, path), 1);
18910 /*--------------------------------------------------------------------------*/
18912 QUnit.module('lodash.get and lodash.result');
18914 lodashStable.each(['get', 'result'], function(methodName) {
18915 var func = _[methodName];
18917 QUnit.test('`_.' + methodName + '` should get string keyed property values', function(assert) {
18920 var object = { 'a': 1 };
18922 lodashStable.each(['a', ['a']], function(path) {
18923 assert.strictEqual(func(object, path), 1);
18927 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
18930 var object = { '-0': 'a', '0': 'b' },
18931 props = [-0, Object(-0), 0, Object(0)];
18933 var actual = lodashStable.map(props, function(key) {
18934 return func(object, key);
18937 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
18940 QUnit.test('`_.' + methodName + '` should get symbol keyed property values', function(assert) {
18945 object[symbol] = 1;
18947 assert.strictEqual(func(object, symbol), 1);
18950 skipAssert(assert);
18954 QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
18957 var object = { 'a': { 'b': 2 } };
18959 lodashStable.each(['a.b', ['a', 'b']], function(path) {
18960 assert.strictEqual(func(object, path), 2);
18964 QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
18967 var object = { 'a.b': 1, 'a': { 'b': 2 } };
18969 lodashStable.each(['a.b', ['a.b']], function(path) {
18970 assert.strictEqual(func(object, path), 1);
18974 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
18977 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
18978 assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
18981 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
18984 var object = { 'a': 1 };
18985 assert.strictEqual(func(object, 'a[]'), 1);
18988 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
18991 lodashStable.each([['', ''], [[], ['']]], function(pair) {
18992 assert.strictEqual(func({}, pair[0]), undefined);
18993 assert.strictEqual(func({ '': 3 }, pair[1]), 3);
18997 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
19000 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
19003 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
19004 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
19007 lodashStable.each(paths, function(path) {
19008 assert.strictEqual(func(object, path), 8);
19012 QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
19015 lodashStable.each(['constructor', ['constructor']], function(path) {
19016 assert.strictEqual(func(null, path), undefined);
19017 assert.strictEqual(func(undefined, path), undefined);
19021 QUnit.test('`_.' + methodName + '` should return `undefined` with deep paths when `object` is nullish', function(assert) {
19024 var values = [null, undefined],
19025 expected = lodashStable.map(values, noop),
19026 paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
19028 lodashStable.each(paths, function(path) {
19029 var actual = lodashStable.map(values, function(value) {
19030 return func(value, path);
19033 assert.deepEqual(actual, expected);
19037 QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
19040 var object = { 'a': [, null] };
19042 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
19043 assert.strictEqual(func(object, path), undefined);
19047 QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
19050 var object = { 'a': { 'b': null } };
19052 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19053 assert.strictEqual(func(object, path), null);
19057 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
19060 var paths = ['a.b', ['a', 'b']];
19062 lodashStable.each(paths, function(path) {
19063 numberProto.a = { 'b': 2 };
19064 assert.strictEqual(func(0, path), 2);
19065 delete numberProto.a;
19069 QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
19072 var object = { 'a': {} },
19073 values = empties.concat(true, new Date, 1, /x/, 'a');
19075 var expected = lodashStable.transform(values, function(result, value) {
19076 result.push(value, value, value, value);
19079 var actual = lodashStable.transform(values, function(result, value) {
19080 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19082 func(object, path, value),
19083 func(null, path, value)
19088 assert.deepEqual(actual, expected);
19091 QUnit.test('`_.' + methodName + '` should return the default value when `path` is empty', function(assert) {
19094 assert.strictEqual(func({}, [], 'a'), 'a');
19098 /*--------------------------------------------------------------------------*/
19100 QUnit.module('lodash.rest');
19103 function fn(a, b, c) {
19104 return slice.call(arguments);
19107 QUnit.test('should apply a rest parameter to `func`', function(assert) {
19110 var rest = _.rest(fn);
19111 assert.deepEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
19114 QUnit.test('should work with `start`', function(assert) {
19117 var rest = _.rest(fn, 1);
19118 assert.deepEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
19121 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
19124 var values = [-1, NaN, 'a'],
19125 expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
19127 var actual = lodashStable.map(values, function(value) {
19128 var rest = _.rest(fn, value);
19129 return rest(1, 2, 3, 4);
19132 assert.deepEqual(actual, expected);
19135 QUnit.test('should coerce `start` to an integer', function(assert) {
19138 var rest = _.rest(fn, 1.6);
19139 assert.deepEqual(rest(1, 2, 3), [1, [2, 3]]);
19142 QUnit.test('should use an empty array when `start` is not reached', function(assert) {
19145 var rest = _.rest(fn);
19146 assert.deepEqual(rest(1), [1, undefined, []]);
19149 QUnit.test('should work on functions with more than three parameters', function(assert) {
19152 var rest = _.rest(function(a, b, c, d) {
19153 return slice.call(arguments);
19156 assert.deepEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
19160 /*--------------------------------------------------------------------------*/
19162 QUnit.module('lodash.reverse');
19165 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
19166 smallArray = [0, 1, 2, null];
19168 QUnit.test('should reverse `array`', function(assert) {
19171 var array = [1, 2, 3],
19172 actual = _.reverse(array);
19174 assert.deepEqual(array, [3, 2, 1]);
19175 assert.strictEqual(actual, array);
19178 QUnit.test('should return the wrapped reversed `array`', function(assert) {
19182 lodashStable.times(2, function(index) {
19183 var array = (index ? largeArray : smallArray).slice(),
19184 clone = array.slice(),
19185 wrapped = _(array).reverse(),
19186 actual = wrapped.value();
19188 assert.ok(wrapped instanceof _);
19189 assert.strictEqual(actual, array);
19190 assert.deepEqual(actual, clone.slice().reverse());
19194 skipAssert(assert, 6);
19198 QUnit.test('should work in a lazy sequence', function(assert) {
19202 lodashStable.times(2, function(index) {
19203 var array = (index ? largeArray : smallArray).slice(),
19204 expected = array.slice(),
19205 actual = _(array).slice(1).reverse().value();
19207 assert.deepEqual(actual, expected.slice(1).reverse());
19208 assert.deepEqual(array, expected);
19212 skipAssert(assert, 4);
19216 QUnit.test('should be lazy when in a lazy sequence', function(assert) {
19221 'toString': function() {
19222 throw new Error('spy was revealed');
19226 var array = largeArray.concat(spy),
19227 expected = array.slice();
19230 var wrapped = _(array).slice(1).map(String).reverse(),
19231 actual = wrapped.last();
19234 assert.ok(wrapped instanceof _);
19235 assert.strictEqual(actual, '1');
19236 assert.deepEqual(array, expected);
19239 skipAssert(assert, 3);
19243 QUnit.test('should work in a hybrid sequence', function(assert) {
19247 lodashStable.times(2, function(index) {
19248 var clone = (index ? largeArray : smallArray).slice();
19250 lodashStable.each(['map', 'filter'], function(methodName) {
19251 var array = clone.slice(),
19252 expected = clone.slice(1, -1).reverse(),
19253 actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
19255 assert.deepEqual(actual, expected);
19257 array = clone.slice();
19258 actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
19260 assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
19265 skipAssert(assert, 8);
19269 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
19273 lodashStable.times(2, function(index) {
19274 var array = (index ? largeArray : smallArray).slice(),
19275 expected = array.slice().reverse(),
19276 wrapped = _(array).chain().reverse().head();
19278 assert.ok(wrapped instanceof _);
19279 assert.strictEqual(wrapped.value(), _.head(expected));
19280 assert.deepEqual(array, expected);
19284 skipAssert(assert, 6);
19289 /*--------------------------------------------------------------------------*/
19291 QUnit.module('round methods');
19293 lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
19294 var func = _[methodName],
19295 isCeil = methodName == 'ceil',
19296 isFloor = methodName == 'floor';
19298 QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
19301 var actual = func(4.006);
19302 assert.strictEqual(actual, isCeil ? 5 : 4);
19305 QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
19308 var actual = func(4.006, 0);
19309 assert.strictEqual(actual, isCeil ? 5 : 4);
19312 QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
19315 var actual = func(4.016, 2);
19316 assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
19318 actual = func(4.1, 2);
19319 assert.strictEqual(actual, 4.1);
19322 QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
19325 var actual = func(4160, -2);
19326 assert.strictEqual(actual, isFloor ? 4100 : 4200);
19329 QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
19332 var actual = func(4.006, NaN);
19333 assert.strictEqual(actual, isCeil ? 5 : 4);
19335 var expected = isFloor ? 4.01 : 4.02;
19337 actual = func(4.016, 2.6);
19338 assert.strictEqual(actual, expected);
19340 actual = func(4.016, '+2');
19341 assert.strictEqual(actual, expected);
19344 QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
19347 var actual = func(5e1, 2);
19348 assert.deepEqual(actual, 50);
19350 actual = func('5e', 1);
19351 assert.deepEqual(actual, NaN);
19353 actual = func('5e1e1', 1);
19354 assert.deepEqual(actual, NaN);
19357 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19360 var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
19361 expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
19363 var actual = lodashStable.map(values, function(args) {
19364 return 1 / func.apply(undefined, args);
19367 assert.deepEqual(actual, expected);
19371 /*--------------------------------------------------------------------------*/
19373 QUnit.module('lodash.runInContext');
19376 QUnit.test('should not require a fully populated `context` object', function(assert) {
19379 if (!isModularize) {
19380 var lodash = _.runInContext({
19381 'setTimeout': function(callback) {
19387 lodash.delay(function() { pass = true; }, 32);
19391 skipAssert(assert);
19395 QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
19398 if (!isModularize) {
19399 lodashStable.times(2, _.uniqueId);
19401 var oldId = Number(_.uniqueId()),
19402 lodash = _.runInContext();
19404 assert.ok(_.uniqueId() > oldId);
19406 var id = lodash.uniqueId();
19407 assert.strictEqual(id, '1');
19408 assert.ok(id < oldId);
19411 skipAssert(assert, 3);
19416 /*--------------------------------------------------------------------------*/
19418 QUnit.module('lodash.sample');
19421 var array = [1, 2, 3];
19423 QUnit.test('should return a random element', function(assert) {
19426 var actual = _.sample(array);
19427 assert.ok(lodashStable.includes(array, actual));
19430 QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
19433 var expected = lodashStable.map(empties, noop);
19435 var actual = lodashStable.transform(empties, function(result, value) {
19437 result.push(_.sample(value));
19441 assert.deepEqual(actual, expected);
19444 QUnit.test('should sample an object', function(assert) {
19447 var object = { 'a': 1, 'b': 2, 'c': 3 },
19448 actual = _.sample(object);
19450 assert.ok(lodashStable.includes(array, actual));
19454 /*--------------------------------------------------------------------------*/
19456 QUnit.module('lodash.sampleSize');
19459 var array = [1, 2, 3];
19461 QUnit.test('should return an array of random elements', function(assert) {
19464 var actual = _.sampleSize(array, 2);
19466 assert.strictEqual(actual.length, 2);
19467 assert.deepEqual(lodashStable.difference(actual, array), []);
19470 QUnit.test('should contain elements of the collection', function(assert) {
19473 var actual = _.sampleSize(array, array.length).sort();
19475 assert.deepEqual(actual, array);
19478 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
19481 var expected = lodashStable.map(falsey, function(value) {
19482 return value === undefined ? ['a'] : [];
19485 var actual = lodashStable.map(falsey, function(size, index) {
19486 return index ? _.sampleSize(['a'], size) : _.sampleSize(['a']);
19489 assert.deepEqual(actual, expected);
19492 QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
19495 lodashStable.each([0, -1, -Infinity], function(n) {
19496 assert.deepEqual(_.sampleSize(array, n), []);
19500 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
19503 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
19504 var actual = _.sampleSize(array, n).sort();
19505 assert.deepEqual(actual, array);
19509 QUnit.test('should coerce `n` to an integer', function(assert) {
19512 var actual = _.sampleSize(array, 1.6);
19513 assert.strictEqual(actual.length, 1);
19516 QUnit.test('should return an empty array for empty collections', function(assert) {
19519 var expected = lodashStable.map(empties, alwaysEmptyArray);
19521 var actual = lodashStable.transform(empties, function(result, value) {
19523 result.push(_.sampleSize(value, 1));
19527 assert.deepEqual(actual, expected);
19530 QUnit.test('should sample an object', function(assert) {
19533 var object = { 'a': 1, 'b': 2, 'c': 3 },
19534 actual = _.sampleSize(object, 2);
19536 assert.strictEqual(actual.length, 2);
19537 assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
19540 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19543 var actual = lodashStable.map([['a']], _.sampleSize);
19544 assert.deepEqual(actual, [['a']]);
19548 /*--------------------------------------------------------------------------*/
19550 QUnit.module('lodash.setWith');
19553 QUnit.test('should work with a `customizer` callback', function(assert) {
19556 var actual = _.setWith({ '0': {} }, '[0][1][2]', 3, function(value) {
19557 return lodashStable.isObject(value) ? undefined : {};
19560 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
19563 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
19566 var actual = _.setWith({}, 'a[0].b.c', 4, noop);
19567 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
19571 /*--------------------------------------------------------------------------*/
19573 QUnit.module('set methods');
19575 lodashStable.each(['update', 'updateWith', 'set', 'setWith'], function(methodName) {
19576 var func = _[methodName],
19577 isUpdate = methodName == 'update' || methodName == 'updateWith';
19581 updater = isUpdate ? lodashStable.constant(value) : value;
19583 QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
19586 lodashStable.each(['a', ['a']], function(path) {
19587 var object = { 'a': oldValue },
19588 actual = func(object, path, updater);
19590 assert.strictEqual(actual, object);
19591 assert.strictEqual(object.a, value);
19595 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19598 var props = [-0, Object(-0), 0, Object(0)],
19599 expected = lodashStable.map(props, lodashStable.constant(value));
19601 var actual = lodashStable.map(props, function(key) {
19602 var object = { '-0': 'a', '0': 'b' };
19603 func(object, key, updater);
19604 return object[lodashStable.toString(key)];
19607 assert.deepEqual(actual, expected);
19610 QUnit.test('`_.' + methodName + '` should unset symbol keyed property values', function(assert) {
19615 object[symbol] = 1;
19617 assert.strictEqual(_.unset(object, symbol), true);
19618 assert.notOk(symbol in object);
19621 skipAssert(assert, 2);
19625 QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
19628 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19629 var object = { 'a': { 'b': oldValue } },
19630 actual = func(object, path, updater);
19632 assert.strictEqual(actual, object);
19633 assert.strictEqual(object.a.b, value);
19637 QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
19640 lodashStable.each(['a.b', ['a.b']], function(path) {
19641 var object = { 'a.b': oldValue },
19642 actual = func(object, path, updater);
19644 assert.strictEqual(actual, object);
19645 assert.deepEqual(object, { 'a.b': value });
19649 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
19652 var object = { 'a,b,c': 1, 'a': { 'b': { 'c': 1 } } };
19654 func(object, ['a', 'b', 'c'], updater);
19655 assert.strictEqual(object.a.b.c, value);
19658 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
19663 func(object, 'a[]', updater);
19664 assert.deepEqual(object, { 'a': value });
19667 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
19670 lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
19673 func(object, pair[0], updater);
19674 assert.deepEqual(object, index ? {} : { '': value });
19676 func(object, pair[1], updater);
19677 assert.deepEqual(object, { '': value });
19681 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
19684 var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': oldValue } } } } } } } };
19687 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
19688 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
19691 lodashStable.each(paths, function(path) {
19692 func(object, path, updater);
19693 assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, value);
19694 object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = oldValue;
19698 QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
19703 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
19704 var actual = func(object, path, updater);
19706 assert.strictEqual(actual, object);
19707 assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': value } }] });
19708 assert.notOk('0' in object.a);
19714 QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
19717 var values = [null, undefined],
19718 expected = [[null, null], [undefined, undefined]];
19720 var actual = lodashStable.map(values, function(value) {
19722 return [func(value, 'a.b', updater), func(value, ['a', 'b'], updater)];
19728 assert.deepEqual(actual, expected);
19731 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
19734 var object = { 'a': '' },
19735 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
19737 lodashStable.each(paths, function(path) {
19738 func(0, path, updater);
19739 assert.strictEqual(0..a, value);
19740 delete numberProto.a;
19743 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
19744 func(object, path, updater);
19745 assert.strictEqual(stringProto.replace.b, value);
19746 delete stringProto.replace.b;
19750 QUnit.test('`_.' + methodName + '` should not error on paths over primitives in strict mode', function(assert) {
19755 lodashStable.each(['a', 'a.a.a'], function(path) {
19756 numberProto.a = oldValue;
19758 func(0, path, updater);
19759 assert.strictEqual(0..a, oldValue);
19761 assert.ok(false, e.message);
19765 delete numberProto.a;
19768 QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
19773 func(object, ['1a', '2b', '3c'], updater);
19774 assert.deepEqual(object, { '1a': { '2b': { '3c': value } } });
19777 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
19780 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
19781 if (defineProperty) {
19784 updater = isUpdate ? lodashStable.constant(value) : value;
19786 defineProperty(object, 'a', {
19787 'enumerable': true,
19788 'configurable': true,
19789 'get': lodashStable.constant(value),
19790 'set': function() { pass = false; }
19793 func(object, 'a', updater);
19797 skipAssert(assert);
19803 /*--------------------------------------------------------------------------*/
19805 QUnit.module('lodash.shuffle');
19808 var array = [1, 2, 3],
19809 object = { 'a': 1, 'b': 2, 'c': 3 };
19811 QUnit.test('should return a new array', function(assert) {
19814 assert.notStrictEqual(_.shuffle(array), array);
19817 QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
19820 assert.deepEqual(_.shuffle(array).sort(), array);
19821 assert.deepEqual(_.shuffle(object).sort(), array);
19824 QUnit.test('should shuffle small collections', function(assert) {
19827 var actual = lodashStable.times(1000, function(assert) {
19828 return _.shuffle([1, 2]);
19831 assert.deepEqual(lodashStable.sortBy(lodashStable.uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
19834 QUnit.test('should treat number values for `collection` as empty', function(assert) {
19837 assert.deepEqual(_.shuffle(1), []);
19841 /*--------------------------------------------------------------------------*/
19843 QUnit.module('lodash.size');
19846 var args = arguments,
19849 QUnit.test('should return the number of own enumerable string keyed properties of an object', function(assert) {
19852 assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
19855 QUnit.test('should return the length of an array', function(assert) {
19858 assert.strictEqual(_.size(array), 3);
19861 QUnit.test('should accept a falsey `object` argument', function(assert) {
19864 var expected = lodashStable.map(falsey, alwaysZero);
19866 var actual = lodashStable.map(falsey, function(object, index) {
19868 return index ? _.size(object) : _.size();
19872 assert.deepEqual(actual, expected);
19875 QUnit.test('should work with `arguments` objects', function(assert) {
19878 assert.strictEqual(_.size(args), 3);
19881 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
19884 function Foo(elements) {
19885 push.apply(this, elements);
19887 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
19889 assert.strictEqual(_.size(new Foo(array)), 3);
19892 QUnit.test('should work with maps', function(assert) {
19896 lodashStable.each([new Map, realm.map], function(map) {
19899 assert.strictEqual(_.size(map), 2);
19904 skipAssert(assert, 2);
19908 QUnit.test('should work with sets', function(assert) {
19912 lodashStable.each([new Set, realm.set], function(set) {
19915 assert.strictEqual(_.size(set), 2);
19920 skipAssert(assert, 2);
19924 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
19927 assert.strictEqual(_.size({ 'length': -1 }), 1);
19930 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
19933 assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
19936 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
19939 assert.strictEqual(_.size({ 'length': '0' }), 1);
19943 /*--------------------------------------------------------------------------*/
19945 QUnit.module('lodash.slice');
19948 var array = [1, 2, 3];
19950 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
19953 var actual = _.slice(array);
19954 assert.deepEqual(actual, array);
19955 assert.notStrictEqual(actual, array);
19958 QUnit.test('should work with a positive `start`', function(assert) {
19961 assert.deepEqual(_.slice(array, 1), [2, 3]);
19962 assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
19965 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
19968 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
19969 assert.deepEqual(_.slice(array, start), []);
19973 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
19976 var expected = lodashStable.map(falsey, lodashStable.constant(array));
19978 var actual = lodashStable.map(falsey, function(start) {
19979 return _.slice(array, start);
19982 assert.deepEqual(actual, expected);
19985 QUnit.test('should work with a negative `start`', function(assert) {
19988 assert.deepEqual(_.slice(array, -1), [3]);
19991 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
19994 lodashStable.each([-3, -4, -Infinity], function(start) {
19995 assert.deepEqual(_.slice(array, start), array);
19999 QUnit.test('should work with `start` >= `end`', function(assert) {
20002 lodashStable.each([2, 3], function(start) {
20003 assert.deepEqual(_.slice(array, start, 2), []);
20007 QUnit.test('should work with a positive `end`', function(assert) {
20010 assert.deepEqual(_.slice(array, 0, 1), [1]);
20013 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
20016 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
20017 assert.deepEqual(_.slice(array, 0, end), array);
20021 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
20024 var expected = lodashStable.map(falsey, function(value) {
20025 return value === undefined ? array : [];
20028 var actual = lodashStable.map(falsey, function(end, index) {
20029 return index ? _.slice(array, 0, end) : _.slice(array, 0);
20032 assert.deepEqual(actual, expected);
20035 QUnit.test('should work with a negative `end`', function(assert) {
20038 assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
20041 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
20044 lodashStable.each([-3, -4, -Infinity], function(end) {
20045 assert.deepEqual(_.slice(array, 0, end), []);
20049 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
20052 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
20054 var actual = lodashStable.map(positions, function(pos) {
20055 return _.slice.apply(_, [array].concat(pos));
20058 assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
20061 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20064 var array = [[1], [2, 3]],
20065 actual = lodashStable.map(array, _.slice);
20067 assert.deepEqual(actual, array);
20068 assert.notStrictEqual(actual, array);
20071 QUnit.test('should work in a lazy sequence', function(assert) {
20075 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
20076 length = array.length,
20077 wrapped = _(array);
20079 lodashStable.each(['map', 'filter'], function(methodName) {
20080 assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
20081 assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
20082 assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
20083 assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
20085 assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
20086 assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
20087 assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
20088 assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
20090 assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
20091 assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
20092 assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
20094 assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
20095 assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
20097 assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
20098 assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
20099 assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
20100 assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
20101 assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
20102 assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
20106 skipAssert(assert, 38);
20111 /*--------------------------------------------------------------------------*/
20113 QUnit.module('lodash.some');
20116 QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
20119 assert.strictEqual(_.some([false, 1, ''], identity), true);
20120 assert.strictEqual(_.some([null, 'a', 0], identity), true);
20123 QUnit.test('should return `false` for empty collections', function(assert) {
20126 var expected = lodashStable.map(empties, alwaysFalse);
20128 var actual = lodashStable.map(empties, function(value) {
20130 return _.some(value, identity);
20134 assert.deepEqual(actual, expected);
20137 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
20142 assert.strictEqual(_.some([null, true, null], function(value) {
20147 assert.strictEqual(count, 2);
20150 QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
20153 assert.strictEqual(_.some([false, false, false], identity), false);
20154 assert.strictEqual(_.some([null, 0, ''], identity), false);
20157 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
20160 var values = [, null, undefined],
20161 expected = lodashStable.map(values, alwaysFalse);
20163 var actual = lodashStable.map(values, function(value, index) {
20164 var array = [0, 0];
20165 return index ? _.some(array, value) : _.some(array);
20168 assert.deepEqual(actual, expected);
20170 expected = lodashStable.map(values, alwaysTrue);
20171 actual = lodashStable.map(values, function(value, index) {
20172 var array = [0, 1];
20173 return index ? _.some(array, value) : _.some(array);
20176 assert.deepEqual(actual, expected);
20179 QUnit.test('should work with `_.property` shorthands', function(assert) {
20182 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
20183 assert.strictEqual(_.some(objects, 'a'), false);
20184 assert.strictEqual(_.some(objects, 'b'), true);
20187 QUnit.test('should work with `_.matches` shorthands', function(assert) {
20190 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
20191 assert.strictEqual(_.some(objects, { 'a': 0 }), true);
20192 assert.strictEqual(_.some(objects, { 'b': 2 }), false);
20195 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20198 var actual = lodashStable.map([[1]], _.some);
20199 assert.deepEqual(actual, [true]);
20203 /*--------------------------------------------------------------------------*/
20205 QUnit.module('lodash.sortBy');
20209 { 'a': 'x', 'b': 3 },
20210 { 'a': 'y', 'b': 4 },
20211 { 'a': 'x', 'b': 1 },
20212 { 'a': 'y', 'b': 2 }
20215 QUnit.test('should sort in ascending order by `iteratee`', function(assert) {
20218 var actual = lodashStable.map(_.sortBy(objects, function(object) {
20222 assert.deepEqual(actual, [1, 2, 3, 4]);
20225 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
20228 var array = [3, 2, 1],
20229 values = [, null, undefined],
20230 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
20232 var actual = lodashStable.map(values, function(value, index) {
20233 return index ? _.sortBy(array, value) : _.sortBy(array);
20236 assert.deepEqual(actual, expected);
20239 QUnit.test('should work with `_.property` shorthands', function(assert) {
20242 var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
20243 assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
20246 QUnit.test('should work with an object for `collection`', function(assert) {
20249 var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, Math.sin);
20250 assert.deepEqual(actual, [3, 1, 2]);
20253 QUnit.test('should move symbol, `null`, `undefined`, and `NaN` values to the end', function(assert) {
20256 var symbol1 = Symbol ? Symbol('a') : null,
20257 symbol2 = Symbol ? Symbol('b') : null,
20258 array = [NaN, undefined, null, 4, symbol1, null, 1, symbol2, undefined, 3, NaN, 2],
20259 expected = [1, 2, 3, 4, symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20261 assert.deepEqual(_.sortBy(array), expected);
20263 array = [NaN, undefined, symbol1, null, 'd', null, 'a', symbol2, undefined, 'c', NaN, 'b'];
20264 expected = ['a', 'b', 'c', 'd', symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20266 assert.deepEqual(_.sortBy(array), expected);
20269 QUnit.test('should treat number values for `collection` as empty', function(assert) {
20272 assert.deepEqual(_.sortBy(1), []);
20275 QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
20278 var actual = _.sortBy(objects, function(object) {
20279 var result = [object.a, object.b];
20280 result.toString = function() { return String(this[0]); };
20284 assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
20287 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20290 var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
20291 assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
20295 /*--------------------------------------------------------------------------*/
20297 QUnit.module('sortBy methods');
20299 lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
20300 var func = _[methodName];
20302 function Pair(a, b, c) {
20309 { 'a': 'x', 'b': 3 },
20310 { 'a': 'y', 'b': 4 },
20311 { 'a': 'x', 'b': 1 },
20312 { 'a': 'y', 'b': 2 }
20315 var stableArray = [
20316 new Pair(1, 1, 1), new Pair(1, 2, 1),
20317 new Pair(1, 1, 1), new Pair(1, 2, 1),
20318 new Pair(1, 3, 1), new Pair(1, 4, 1),
20319 new Pair(1, 5, 1), new Pair(1, 6, 1),
20320 new Pair(2, 1, 2), new Pair(2, 2, 2),
20321 new Pair(2, 3, 2), new Pair(2, 4, 2),
20322 new Pair(2, 5, 2), new Pair(2, 6, 2),
20323 new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
20324 new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
20325 new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
20328 var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
20330 QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
20333 var actual = func(objects, ['a', 'b']);
20334 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20337 QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
20340 var actual = func(objects, ['a', function(object) { return object.b; }]);
20341 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20344 QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
20347 lodashStable.each([stableArray, stableObject], function(value, index) {
20348 var actual = func(value, ['a', 'c']);
20349 assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
20353 QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
20357 var actual = func(objects.concat(null, undefined), ['a', 'b']);
20360 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
20363 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
20367 { 'a': 'x', '0': 3 },
20368 { 'a': 'y', '0': 4 },
20369 { 'a': 'x', '0': 1 },
20370 { 'a': 'y', '0': 2 }
20373 var funcs = [func, lodashStable.partialRight(func, 'bogus')];
20375 lodashStable.each(['a', 0, [0]], function(props, index) {
20376 var expected = lodashStable.map(funcs, lodashStable.constant(
20378 ? [objects[2], objects[3], objects[0], objects[1]]
20379 : [objects[0], objects[2], objects[1], objects[3]]
20382 var actual = lodashStable.map(funcs, function(func) {
20383 return lodashStable.reduce([props], func, objects);
20386 assert.deepEqual(actual, expected);
20391 /*--------------------------------------------------------------------------*/
20393 QUnit.module('sortedIndex methods');
20395 lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
20396 var func = _[methodName],
20397 isSortedIndex = methodName == 'sortedIndex';
20399 QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
20402 var array = [30, 50],
20403 values = [30, 40, 50],
20404 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20406 var actual = lodashStable.map(values, function(value) {
20407 return func(array, value);
20410 assert.deepEqual(actual, expected);
20413 QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
20416 var array = ['a', 'c'],
20417 values = ['a', 'b', 'c'],
20418 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20420 var actual = lodashStable.map(values, function(value) {
20421 return func(array, value);
20424 assert.deepEqual(actual, expected);
20427 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument and a `value`', function(assert) {
20430 var expected = lodashStable.map(falsey, lodashStable.constant([0, 0, 0]));
20432 var actual = lodashStable.map(falsey, function(array) {
20433 return [func(array, 1), func(array, undefined), func(array, NaN)];
20436 assert.deepEqual(actual, expected);
20439 QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
20442 var symbol1 = Symbol ? Symbol('a') : null,
20443 symbol2 = Symbol ? Symbol('b') : null,
20444 expected = [1, '2', {}, symbol1, symbol2, null, undefined, NaN, NaN];
20446 lodashStable.each([
20447 [NaN, symbol1, null, 1, '2', {}, symbol2, NaN, undefined],
20448 ['2', null, 1, symbol1, NaN, {}, NaN, symbol2, undefined]
20449 ], function(array) {
20450 assert.deepEqual(_.sortBy(array), expected);
20451 assert.strictEqual(func(expected, 3), 2);
20452 assert.strictEqual(func(expected, symbol1), (isSortedIndex ? 3 : (Symbol ? 5 : 6)));
20453 assert.strictEqual(func(expected, null), (isSortedIndex ? (Symbol ? 5 : 3) : 6));
20454 assert.strictEqual(func(expected, undefined), isSortedIndex ? 6 : 7);
20455 assert.strictEqual(func(expected, NaN), isSortedIndex ? 7 : 9);
20460 /*--------------------------------------------------------------------------*/
20462 QUnit.module('sortedIndexBy methods');
20464 lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
20465 var func = _[methodName],
20466 isSortedIndexBy = methodName == 'sortedIndexBy';
20468 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
20473 func([30, 50], 40, function(assert) {
20474 args || (args = slice.call(arguments));
20477 assert.deepEqual(args, [40]);
20480 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
20483 var objects = [{ 'x': 30 }, { 'x': 50 }],
20484 actual = func(objects, { 'x': 40 }, 'x');
20486 assert.strictEqual(actual, 1);
20489 QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
20492 lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
20494 values = [MAX_ARRAY_LENGTH, NaN, undefined];
20496 array.length = length;
20498 lodashStable.each(values, function(value) {
20501 var actual = func(array, value, function(value) {
20506 var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
20508 : Math.min(length, MAX_ARRAY_INDEX);
20510 // Avoid false fails in older Firefox.
20511 if (array.length == length) {
20512 assert.ok(steps == 32 || steps == 33);
20513 assert.strictEqual(actual, expected);
20516 skipAssert(assert, 2);
20523 /*--------------------------------------------------------------------------*/
20525 QUnit.module('sortedIndexOf methods');
20527 lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
20528 var func = _[methodName],
20529 isSortedIndexOf = methodName == 'sortedIndexOf';
20531 QUnit.test('`_.' + methodName + '` should perform a binary search', function(assert) {
20534 var sorted = [4, 4, 5, 5, 6, 6];
20535 assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
20539 /*--------------------------------------------------------------------------*/
20541 QUnit.module('lodash.sortedUniq');
20544 QUnit.test('should return unique values of a sorted array', function(assert) {
20547 var expected = [1, 2, 3];
20549 lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
20550 assert.deepEqual(_.sortedUniq(array), expected);
20555 /*--------------------------------------------------------------------------*/
20557 QUnit.module('lodash.split');
20560 QUnit.test('should split a string by `separator`', function(assert) {
20563 var string = 'abcde';
20564 assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
20565 assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
20566 assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
20569 QUnit.test('should return an array containing an empty string for empty values', function(assert) {
20572 var values = [, null, undefined, ''],
20573 expected = lodashStable.map(values, lodashStable.constant(['']));
20575 var actual = lodashStable.map(values, function(value, index) {
20576 return index ? _.split(value) : _.split();
20579 assert.deepEqual(actual, expected);
20582 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20585 var strings = ['abc', 'def', 'ghi'],
20586 actual = lodashStable.map(strings, _.split);
20588 assert.deepEqual(actual, [['abc'], ['def'], ['ghi']]);
20591 QUnit.test('should allow mixed string and array prototype methods', function(assert) {
20595 var wrapped = _('abc');
20596 assert.strictEqual(wrapped.split('b').join(','), 'a,c');
20599 skipAssert(assert);
20604 /*--------------------------------------------------------------------------*/
20606 QUnit.module('lodash.spread');
20609 function fn(a, b, c) {
20610 return slice.call(arguments);
20613 QUnit.test('should spread arguments to `func`', function(assert) {
20616 var spread = _.spread(fn);
20617 assert.deepEqual(spread([4, 2]), [4, 2]);
20620 QUnit.test('should accept a falsey `array` argument', function(assert) {
20623 var spread = _.spread(alwaysTrue),
20624 expected = lodashStable.map(falsey, alwaysTrue);
20626 var actual = lodashStable.map(falsey, function(array, index) {
20628 return index ? spread(array) : spread();
20632 assert.deepEqual(actual, expected);
20635 QUnit.test('should provide the correct `func` arguments', function(assert) {
20640 var spread = _.spread(function() {
20641 args = slice.call(arguments);
20644 spread([4, 2], 'ignored');
20645 assert.deepEqual(args, [4, 2]);
20648 QUnit.test('should work with `start`', function(assert) {
20651 var spread = _.spread(fn, 1);
20652 assert.deepEqual(spread(1, [2, 3, 4]), [1, 2, 3, 4]);
20655 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
20658 var values = [-1, NaN, 'a'],
20659 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
20661 var actual = lodashStable.map(values, function(value) {
20662 var spread = _.spread(fn, value);
20663 return spread([1, 2, 3, 4]);
20666 assert.deepEqual(actual, expected);
20669 QUnit.test('should coerce `start` to an integer', function(assert) {
20672 var spread = _.spread(fn, 1.6);
20673 assert.deepEqual(spread(1, [2, 3]), [1, 2, 3]);
20677 /*--------------------------------------------------------------------------*/
20679 QUnit.module('lodash.startCase');
20682 QUnit.test('should uppercase only the first character of each word', function(assert) {
20685 assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar');
20686 assert.strictEqual(_.startCase('fooBar'), 'Foo Bar');
20687 assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR');
20691 /*--------------------------------------------------------------------------*/
20693 QUnit.module('lodash.startsWith');
20696 var string = 'abc';
20698 QUnit.test('should return `true` if a string starts with `target`', function(assert) {
20701 assert.strictEqual(_.startsWith(string, 'a'), true);
20704 QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
20707 assert.strictEqual(_.startsWith(string, 'b'), false);
20710 QUnit.test('should work with a `position` argument', function(assert) {
20713 assert.strictEqual(_.startsWith(string, 'b', 1), true);
20716 QUnit.test('should work with `position` >= `string.length`', function(assert) {
20719 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
20720 assert.strictEqual(_.startsWith(string, 'a', position), false);
20724 QUnit.test('should treat falsey `position` values as `0`', function(assert) {
20727 var expected = lodashStable.map(falsey, alwaysTrue);
20729 var actual = lodashStable.map(falsey, function(position) {
20730 return _.startsWith(string, 'a', position);
20733 assert.deepEqual(actual, expected);
20736 QUnit.test('should treat a negative `position` as `0`', function(assert) {
20739 lodashStable.each([-1, -3, -Infinity], function(position) {
20740 assert.strictEqual(_.startsWith(string, 'a', position), true);
20741 assert.strictEqual(_.startsWith(string, 'b', position), false);
20745 QUnit.test('should coerce `position` to an integer', function(assert) {
20748 assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
20751 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
20754 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
20755 return _.startsWith(string, '', position, true);
20760 /*--------------------------------------------------------------------------*/
20762 QUnit.module('lodash.startsWith and lodash.endsWith');
20764 lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
20765 var func = _[methodName],
20766 isStartsWith = methodName == 'startsWith';
20768 var string = 'abc',
20769 chr = isStartsWith ? 'a' : 'c';
20771 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
20774 assert.strictEqual(func(Object(string), chr), true);
20775 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
20778 QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
20781 assert.strictEqual(func(string, Object(chr)), true);
20782 assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
20785 QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
20788 var position = isStartsWith ? 1 : 2;
20789 assert.strictEqual(func(string, 'b', Object(position)), true);
20790 assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
20794 /*--------------------------------------------------------------------------*/
20796 QUnit.module('lodash.subtract');
20799 QUnit.test('should subtract two numbers', function(assert) {
20802 assert.strictEqual(_.subtract(6, 4), 2);
20803 assert.strictEqual(_.subtract(-6, 4), -10);
20804 assert.strictEqual(_.subtract(-6, -4), -2);
20807 QUnit.test('should coerce arguments to numbers', function(assert) {
20810 assert.strictEqual(_.subtract('6', '4'), 2);
20811 assert.deepEqual(_.subtract('x', 'y'), NaN);
20815 /*--------------------------------------------------------------------------*/
20817 QUnit.module('math operator methods');
20819 lodashStable.each(['add', 'divide', 'multiply', 'subtract'], function(methodName) {
20820 var func = _[methodName];
20822 QUnit.test('`_.' + methodName + '` should return `0` when no arguments are given', function(assert) {
20825 assert.strictEqual(func(), 0);
20828 QUnit.test('`_.' + methodName + '` should work with only one defined argument', function(assert) {
20831 assert.strictEqual(func(6), 6);
20832 assert.strictEqual(func(6, undefined), 6);
20833 assert.strictEqual(func(undefined, 4), 4);
20836 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
20839 var values = [0, '0', -0, '-0'],
20840 expected = [[0, Infinity], ['0', Infinity], [-0, -Infinity], ['-0', -Infinity]];
20842 lodashStable.times(2, function(index) {
20843 var actual = lodashStable.map(values, function(value) {
20844 var result = index ? func(undefined, value) : func(value);
20845 return [result, 1 / result];
20848 assert.deepEqual(actual, expected);
20852 QUnit.test('`_.' + methodName + '` should convert objects to `NaN`', function(assert) {
20855 assert.deepEqual(func(0, {}), NaN);
20856 assert.deepEqual(func({}, 0), NaN);
20859 QUnit.test('`_.' + methodName + '` should convert symbols to `NaN`', function(assert) {
20863 assert.deepEqual(func(0, symbol), NaN);
20864 assert.deepEqual(func(symbol, 0), NaN);
20867 skipAssert(assert, 2);
20871 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
20875 var actual = _(1)[methodName](2);
20876 assert.notOk(actual instanceof _);
20879 skipAssert(assert);
20883 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
20887 var actual = _(1).chain()[methodName](2);
20888 assert.ok(actual instanceof _);
20891 skipAssert(assert);
20896 /*--------------------------------------------------------------------------*/
20898 QUnit.module('lodash.sumBy');
20901 var array = [6, 4, 2],
20902 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
20904 QUnit.test('should work with an `iteratee` argument', function(assert) {
20907 var actual = _.sumBy(objects, function(object) {
20911 assert.deepEqual(actual, 6);
20914 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
20919 _.sumBy(array, function() {
20920 args || (args = slice.call(arguments));
20923 assert.deepEqual(args, [6]);
20926 QUnit.test('should work with `_.property` shorthands', function(assert) {
20929 var arrays = [[2], [3], [1]];
20930 assert.strictEqual(_.sumBy(arrays, 0), 6);
20931 assert.strictEqual(_.sumBy(objects, 'a'), 6);
20935 /*--------------------------------------------------------------------------*/
20937 QUnit.module('sum methods');
20939 lodashStable.each(['sum', 'sumBy'], function(methodName) {
20940 var array = [6, 4, 2],
20941 func = _[methodName];
20943 QUnit.test('`_.' + methodName + '` should return the sum of an array of numbers', function(assert) {
20946 assert.strictEqual(func(array), 12);
20949 QUnit.test('`_.' + methodName + '` should return `0` when passing empty `array` values', function(assert) {
20952 var expected = lodashStable.map(empties, alwaysZero);
20954 var actual = lodashStable.map(empties, function(value) {
20955 return func(value);
20958 assert.deepEqual(actual, expected);
20961 QUnit.test('`_.' + methodName + '` should skip `undefined` values', function(assert) {
20964 assert.strictEqual(func([1, undefined]), 1);
20967 QUnit.test('`_.' + methodName + '` should not skip `NaN` values', function(assert) {
20970 assert.deepEqual(func([1, NaN]), NaN);
20973 QUnit.test('`_.' + methodName + '` should not coerce values to numbers', function(assert) {
20976 assert.strictEqual(func(['1', '2']), '12');
20980 /*--------------------------------------------------------------------------*/
20982 QUnit.module('lodash.tail');
20985 var array = [1, 2, 3];
20987 QUnit.test('should accept a falsey `array` argument', function(assert) {
20990 var expected = lodashStable.map(falsey, alwaysEmptyArray);
20992 var actual = lodashStable.map(falsey, function(array, index) {
20994 return index ? _.tail(array) : _.tail();
20998 assert.deepEqual(actual, expected);
21001 QUnit.test('should exclude the first element', function(assert) {
21004 assert.deepEqual(_.tail(array), [2, 3]);
21007 QUnit.test('should return an empty when querying empty arrays', function(assert) {
21010 assert.deepEqual(_.tail([]), []);
21013 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21016 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21017 actual = lodashStable.map(array, _.tail);
21019 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
21022 QUnit.test('should work in a lazy sequence', function(assert) {
21026 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21029 var actual = _(array).tail().filter(function(value) {
21030 values.push(value);
21035 assert.deepEqual(actual, []);
21036 assert.deepEqual(values, array.slice(1));
21040 actual = _(array).filter(function(value) {
21041 values.push(value);
21042 return isEven(value);
21047 assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
21048 assert.deepEqual(values, array);
21051 skipAssert(assert, 4);
21055 QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
21059 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21060 iteratee = function() { pass = false; },
21062 actual = _(array).slice(0, 1).tail().map(iteratee).value();
21065 assert.deepEqual(actual, []);
21068 actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
21071 assert.deepEqual(actual, []);
21074 skipAssert(assert, 4);
21079 /*--------------------------------------------------------------------------*/
21081 QUnit.module('lodash.take');
21084 var array = [1, 2, 3];
21086 QUnit.test('should take the first two elements', function(assert) {
21089 assert.deepEqual(_.take(array, 2), [1, 2]);
21092 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21095 var expected = lodashStable.map(falsey, function(value) {
21096 return value === undefined ? [1] : [];
21099 var actual = lodashStable.map(falsey, function(n) {
21100 return _.take(array, n);
21103 assert.deepEqual(actual, expected);
21106 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21109 lodashStable.each([0, -1, -Infinity], function(n) {
21110 assert.deepEqual(_.take(array, n), []);
21114 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
21117 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21118 assert.deepEqual(_.take(array, n), array);
21122 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21125 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21126 actual = lodashStable.map(array, _.take);
21128 assert.deepEqual(actual, [[1], [4], [7]]);
21131 QUnit.test('should work in a lazy sequence', function(assert) {
21135 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
21136 predicate = function(value) { values.push(value); return isEven(value); },
21138 actual = _(array).take(2).take().value();
21140 assert.deepEqual(actual, _.take(_.take(array, 2)));
21142 actual = _(array).filter(predicate).take(2).take().value();
21143 assert.deepEqual(values, [1, 2]);
21144 assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
21146 actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
21147 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
21151 actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
21152 assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
21153 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
21156 skipAssert(assert, 6);
21161 /*--------------------------------------------------------------------------*/
21163 QUnit.module('lodash.takeRight');
21166 var array = [1, 2, 3];
21168 QUnit.test('should take the last two elements', function(assert) {
21171 assert.deepEqual(_.takeRight(array, 2), [2, 3]);
21174 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21177 var expected = lodashStable.map(falsey, function(value) {
21178 return value === undefined ? [3] : [];
21181 var actual = lodashStable.map(falsey, function(n) {
21182 return _.takeRight(array, n);
21185 assert.deepEqual(actual, expected);
21188 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21191 lodashStable.each([0, -1, -Infinity], function(n) {
21192 assert.deepEqual(_.takeRight(array, n), []);
21196 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
21199 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21200 assert.deepEqual(_.takeRight(array, n), array);
21204 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21207 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21208 actual = lodashStable.map(array, _.takeRight);
21210 assert.deepEqual(actual, [[3], [6], [9]]);
21213 QUnit.test('should work in a lazy sequence', function(assert) {
21217 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21218 predicate = function(value) { values.push(value); return isEven(value); },
21220 actual = _(array).takeRight(2).takeRight().value();
21222 assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
21224 actual = _(array).filter(predicate).takeRight(2).takeRight().value();
21225 assert.deepEqual(values, array);
21226 assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
21228 actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
21229 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
21233 actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
21234 assert.deepEqual(values, array);
21235 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
21238 skipAssert(assert, 6);
21243 /*--------------------------------------------------------------------------*/
21245 QUnit.module('lodash.takeRightWhile');
21248 var array = [1, 2, 3, 4];
21251 { 'a': 0, 'b': 0 },
21252 { 'a': 1, 'b': 1 },
21256 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21259 var actual = _.takeRightWhile(array, function(n) {
21263 assert.deepEqual(actual, [3, 4]);
21266 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
21271 _.takeRightWhile(array, function() {
21272 args = slice.call(arguments);
21275 assert.deepEqual(args, [4, 3, array]);
21278 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21281 assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
21284 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21287 assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
21290 QUnit.test('should work with `_.property` shorthands', function(assert) {
21293 assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
21296 QUnit.test('should work in a lazy sequence', function(assert) {
21300 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21301 predicate = function(n) { return n > 2; },
21302 expected = _.takeRightWhile(array, predicate),
21303 wrapped = _(array).takeRightWhile(predicate);
21305 assert.deepEqual(wrapped.value(), expected);
21306 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21307 assert.strictEqual(wrapped.last(), _.last(expected));
21310 skipAssert(assert, 3);
21314 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
21319 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21320 expected = [square(LARGE_ARRAY_SIZE), LARGE_ARRAY_SIZE - 1, lodashStable.map(array.slice(1), square)];
21322 _(array).slice(1).takeRightWhile(function(value, index, array) {
21323 args = slice.call(arguments);
21326 assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
21328 _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
21329 args = slice.call(arguments);
21332 assert.deepEqual(args, expected);
21334 _(array).slice(1).map(square).takeRightWhile(function(value, index) {
21335 args = slice.call(arguments);
21338 assert.deepEqual(args, expected);
21340 _(array).slice(1).map(square).takeRightWhile(function(index) {
21341 args = slice.call(arguments);
21344 assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
21346 _(array).slice(1).map(square).takeRightWhile(function() {
21347 args = slice.call(arguments);
21350 assert.deepEqual(args, expected);
21353 skipAssert(assert, 5);
21358 /*--------------------------------------------------------------------------*/
21360 QUnit.module('lodash.takeWhile');
21363 var array = [1, 2, 3, 4];
21366 { 'a': 2, 'b': 2 },
21367 { 'a': 1, 'b': 1 },
21371 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21374 var actual = _.takeWhile(array, function(n) {
21378 assert.deepEqual(actual, [1, 2]);
21381 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
21386 _.takeWhile(array, function() {
21387 args = slice.call(arguments);
21390 assert.deepEqual(args, [1, 0, array]);
21393 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21396 assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
21399 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21402 assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
21404 QUnit.test('should work with `_.property` shorthands', function(assert) {
21407 assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
21410 QUnit.test('should work in a lazy sequence', function(assert) {
21414 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21415 predicate = function(n) { return n < 3; },
21416 expected = _.takeWhile(array, predicate),
21417 wrapped = _(array).takeWhile(predicate);
21419 assert.deepEqual(wrapped.value(), expected);
21420 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21421 assert.strictEqual(wrapped.last(), _.last(expected));
21424 skipAssert(assert, 3);
21428 QUnit.test('should work in a lazy sequence with `take`', function(assert) {
21432 var array = lodashStable.range(LARGE_ARRAY_SIZE);
21434 var actual = _(array)
21435 .takeWhile(function(n) { return n < 4; })
21437 .takeWhile(function(n) { return n == 0; })
21440 assert.deepEqual(actual, [0]);
21443 skipAssert(assert);
21447 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
21452 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21453 expected = [1, 0, lodashStable.map(array.slice(1), square)];
21455 _(array).slice(1).takeWhile(function(value, index, array) {
21456 args = slice.call(arguments);
21459 assert.deepEqual(args, [1, 0, array.slice(1)]);
21461 _(array).slice(1).map(square).takeWhile(function(value, index, array) {
21462 args = slice.call(arguments);
21465 assert.deepEqual(args, expected);
21467 _(array).slice(1).map(square).takeWhile(function(value, index) {
21468 args = slice.call(arguments);
21471 assert.deepEqual(args, expected);
21473 _(array).slice(1).map(square).takeWhile(function(value) {
21474 args = slice.call(arguments);
21477 assert.deepEqual(args, [1]);
21479 _(array).slice(1).map(square).takeWhile(function() {
21480 args = slice.call(arguments);
21483 assert.deepEqual(args, expected);
21486 skipAssert(assert, 5);
21491 /*--------------------------------------------------------------------------*/
21493 QUnit.module('lodash.tap');
21496 QUnit.test('should intercept and return the given value', function(assert) {
21503 var actual = _.tap(array, function(value) {
21504 intercepted = value;
21507 assert.strictEqual(actual, array);
21508 assert.strictEqual(intercepted, array);
21511 skipAssert(assert, 2);
21515 QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
21522 var wrapped = _(array).tap(function(value) {
21523 intercepted = value;
21527 assert.ok(wrapped instanceof _);
21530 assert.strictEqual(intercepted, array);
21533 skipAssert(assert, 2);
21538 /*--------------------------------------------------------------------------*/
21540 QUnit.module('lodash.template');
21543 QUnit.test('should escape values in "escape" delimiters', function(assert) {
21546 var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
21547 expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'`\/</p>')),
21548 data = { 'value': '&<>"\'`\/' };
21550 var actual = lodashStable.map(strings, function(string) {
21551 return _.template(string)(data);
21554 assert.deepEqual(actual, expected);
21557 QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
21560 var compiled = _.template('<%= typeof __e %>');
21561 assert.strictEqual(compiled({}), 'undefined');
21564 QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
21567 var compiled = _.template(
21569 for (var key in collection) {\
21570 %><li><%= collection[key] %></li><%\
21574 var data = { 'collection': { 'a': 'A', 'b': 'B' } },
21575 actual = compiled(data);
21577 assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
21580 QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
21583 var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
21584 data = { 'value': true };
21586 assert.strictEqual(compiled(data), 'yap');
21589 QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
21592 var compiled = _.template('<% var b = a; %><%= b.value %>'),
21593 data = { 'a': { 'value': 1 } };
21595 assert.strictEqual(compiled(data), '1');
21598 QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
21601 var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
21602 expected = lodashStable.map(strings, lodashStable.constant('ABC')),
21603 data = { 'a': 'A' };
21605 var actual = lodashStable.map(strings, function(string) {
21606 return _.template(string)(data);
21609 assert.deepEqual(actual, expected);
21612 QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
21615 var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
21616 data = { 'a': true };
21618 assert.strictEqual(compiled(data), 'a="A"');
21621 QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
21624 var compiled = _.template('<%= value ? value : "b" %>'),
21625 data = { 'value': 'a' };
21627 assert.strictEqual(compiled(data), 'a');
21630 QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
21633 var compiled = _.template('<%= typeof Math.abs %>');
21636 var actual = compiled();
21639 assert.strictEqual(actual, 'function');
21642 QUnit.test('should support complex "interpolate" delimiters', function(assert) {
21645 lodashStable.forOwn({
21646 '<%= a + b %>': '3',
21647 '<%= b - a %>': '1',
21648 '<%= a = b %>': '2',
21649 '<%= !a %>': 'false',
21651 '<%= a * b %>': '2',
21652 '<%= a / b %>': '0.5',
21653 '<%= a % b %>': '1',
21654 '<%= a >> b %>': '0',
21655 '<%= a << b %>': '4',
21656 '<%= a & b %>': '0',
21657 '<%= a ^ b %>': '3',
21658 '<%= a | b %>': '3',
21659 '<%= {}.toString.call(0) %>': numberTag,
21660 '<%= a.toFixed(2) %>': '1.00',
21661 '<%= obj["a"] %>': '1',
21662 '<%= delete a %>': 'true',
21663 '<%= "a" in obj %>': 'true',
21664 '<%= obj instanceof Object %>': 'true',
21665 '<%= new Boolean %>': 'false',
21666 '<%= typeof a %>': 'number',
21667 '<%= void a %>': ''
21669 function(value, key) {
21670 var compiled = _.template(key),
21671 data = { 'a': 1, 'b': 2 };
21673 assert.strictEqual(compiled(data), value, key);
21677 QUnit.test('should support ES6 template delimiters', function(assert) {
21680 var data = { 'value': 2 };
21681 assert.strictEqual(_.template('1${value}3')(data), '123');
21682 assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
21685 QUnit.test('should support the "imports" option', function(assert) {
21688 var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
21689 assert.strictEqual(compiled({}), '1');
21692 QUnit.test('should support the "variable" options', function(assert) {
21695 var compiled = _.template(
21696 '<% _.each( data.a, function( value ) { %>' +
21697 '<%= value.valueOf() %>' +
21698 '<% }) %>', { 'variable': 'data' }
21701 var data = { 'a': [1, 2, 3] };
21704 assert.strictEqual(compiled(data), '123');
21706 assert.ok(false, e.message);
21710 QUnit.test('should support custom delimiters', function(assert) {
21713 lodashStable.times(2, function(index) {
21714 var settingsClone = lodashStable.clone(_.templateSettings);
21716 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
21717 'escape': /\{\{-([\s\S]+?)\}\}/g,
21718 'evaluate': /\{\{([\s\S]+?)\}\}/g,
21719 'interpolate': /\{\{=([\s\S]+?)\}\}/g
21722 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
21723 compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
21724 data = { 'collection': ['a & A', 'b & B'] };
21726 assert.strictEqual(compiled(data), expected);
21727 lodashStable.assign(_.templateSettings, settingsClone);
21731 QUnit.test('should support custom delimiters containing special characters', function(assert) {
21734 lodashStable.times(2, function(index) {
21735 var settingsClone = lodashStable.clone(_.templateSettings);
21737 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
21738 'escape': /<\?-([\s\S]+?)\?>/g,
21739 'evaluate': /<\?([\s\S]+?)\?>/g,
21740 'interpolate': /<\?=([\s\S]+?)\?>/g
21743 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
21744 compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
21745 data = { 'collection': ['a & A', 'b & B'] };
21747 assert.strictEqual(compiled(data), expected);
21748 lodashStable.assign(_.templateSettings, settingsClone);
21752 QUnit.test('should use a `with` statement by default', function(assert) {
21755 var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
21756 actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
21758 assert.strictEqual(actual, '1b012');
21761 QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
21764 var lodash = _.templateSettings.imports._,
21765 settingsClone = lodashStable.clone(lodash.templateSettings);
21767 lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
21768 'interpolate': /\{\{=([\s\S]+?)\}\}/g
21771 var compiled = _.template('{{= a }}');
21772 assert.strictEqual(compiled({ 'a': 1 }), '1');
21774 if (settingsClone) {
21775 lodashStable.assign(lodash.templateSettings, settingsClone);
21777 delete lodash.templateSettings;
21781 QUnit.test('should fallback to `_.templateSettings`', function(assert) {
21784 var lodash = _.templateSettings.imports._,
21785 delimiter = _.templateSettings.interpolate;
21787 _.templateSettings.imports._ = { 'escape': lodashStable.escape };
21788 _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
21790 var compiled = _.template('{{= a }}');
21791 assert.strictEqual(compiled({ 'a': 1 }), '1');
21793 _.templateSettings.imports._ = lodash;
21794 _.templateSettings.interpolate = delimiter;
21797 QUnit.test('should ignore `null` delimiters', function(assert) {
21801 'escape': /\{\{-([\s\S]+?)\}\}/g,
21802 'evaluate': /\{\{([\s\S]+?)\}\}/g,
21803 'interpolate': /\{\{=([\s\S]+?)\}\}/g
21806 lodashStable.forOwn({
21807 'escape': '{{- a }}',
21808 'evaluate': '{{ print(a) }}',
21809 'interpolate': '{{= a }}'
21811 function(value, key) {
21812 var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
21813 settings[key] = delimiter[key];
21815 var expected = '1 <%- a %> <% print(a) %> <%= a %>',
21816 compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
21819 assert.strictEqual(compiled(data), expected);
21823 QUnit.test('should work without delimiters', function(assert) {
21826 var expected = 'abc';
21827 assert.strictEqual(_.template(expected)({}), expected);
21830 QUnit.test('should work with `this` references', function(assert) {
21833 var compiled = _.template('a<%= this.String("b") %>c');
21834 assert.strictEqual(compiled(), 'abc');
21836 var object = { 'b': 'B' };
21837 object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
21838 assert.strictEqual(object.compiled(), 'ABC');
21841 QUnit.test('should work with backslashes', function(assert) {
21844 var compiled = _.template('<%= a %> \\b'),
21845 data = { 'a': 'A' };
21847 assert.strictEqual(compiled(data), 'A \\b');
21850 QUnit.test('should work with escaped characters in string literals', function(assert) {
21853 var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
21854 assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
21856 var data = { 'a': 'A' };
21857 compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
21858 assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
21861 QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
21864 var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
21865 assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
21868 QUnit.test('should work with statements containing quotes', function(assert) {
21871 var compiled = _.template("<%\
21872 if (a == 'A' || a == \"a\") {\
21877 var data = { 'a': 'A' };
21878 assert.strictEqual(compiled(data), "'a',\"A\"");
21881 QUnit.test('should work with templates containing newlines and comments', function(assert) {
21884 var compiled = _.template('<%\n\
21885 // A code comment.\n\
21886 if (value) { value += 3; }\n\
21887 %><p><%= value %></p>'
21890 assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
21893 QUnit.test('should not error with IE conditional comments enabled (test with development build)', function(assert) {
21896 var compiled = _.template(''),
21908 QUnit.test('should tokenize delimiters', function(assert) {
21911 var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
21912 data = { 'type': 1 };
21914 assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
21917 QUnit.test('should evaluate delimiters once', function(assert) {
21921 compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
21922 data = { 'func': function(value) { actual.push(value); } };
21925 assert.deepEqual(actual, ['a', 'b', 'c']);
21928 QUnit.test('should match delimiters before escaping text', function(assert) {
21931 var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
21932 assert.strictEqual(compiled(), '<<\n a \n>>');
21935 QUnit.test('should resolve nullish values to an empty string', function(assert) {
21938 var compiled = _.template('<%= a %><%- a %>'),
21939 data = { 'a': null };
21941 assert.strictEqual(compiled(data), '');
21943 data = { 'a': undefined };
21944 assert.strictEqual(compiled(data), '');
21946 data = { 'a': {} };
21947 compiled = _.template('<%= a.b %><%- a.b %>');
21948 assert.strictEqual(compiled(data), '');
21951 QUnit.test('should return an empty string for empty values', function(assert) {
21954 var values = [, null, undefined, ''],
21955 expected = lodashStable.map(values, alwaysEmptyString),
21958 var actual = lodashStable.map(values, function(value, index) {
21959 var compiled = index ? _.template(value) : _.template();
21960 return compiled(data);
21963 assert.deepEqual(actual, expected);
21966 QUnit.test('should parse delimiters without newlines', function(assert) {
21969 var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
21970 compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
21971 data = { 'value': true };
21973 assert.strictEqual(compiled(data), expected);
21976 QUnit.test('should support recursive calls', function(assert) {
21979 var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
21980 data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
21982 assert.strictEqual(compiled(data), 'AB');
21985 QUnit.test('should coerce `text` argument to a string', function(assert) {
21988 var object = { 'toString': lodashStable.constant('<%= a %>') },
21991 assert.strictEqual(_.template(object)(data), '1');
21994 QUnit.test('should not modify the `options` object', function(assert) {
21998 _.template('', options);
21999 assert.deepEqual(options, {});
22002 QUnit.test('should not modify `_.templateSettings` when `options` are given', function(assert) {
22005 var data = { 'a': 1 };
22007 assert.notOk('a' in _.templateSettings);
22008 _.template('', {}, data);
22009 assert.notOk('a' in _.templateSettings);
22011 delete _.templateSettings.a;
22014 QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
22024 assert.ok(pass, '`data` value');
22029 _.template('', 1)(1);
22033 assert.ok(pass, '`options` value');
22036 QUnit.test('should expose the source on compiled templates', function(assert) {
22039 var compiled = _.template('x'),
22040 values = [String(compiled), compiled.source],
22041 expected = lodashStable.map(values, alwaysTrue);
22043 var actual = lodashStable.map(values, function(value) {
22044 return lodashStable.includes(value, '__p');
22047 assert.deepEqual(actual, expected);
22050 QUnit.test('should expose the source on SyntaxErrors', function(assert) {
22054 _.template('<% if x %>');
22056 var source = e.source;
22058 assert.ok(lodashStable.includes(source, '__p'));
22061 QUnit.test('should not include sourceURLs in the source', function(assert) {
22064 var options = { 'sourceURL': '/a/b/c' },
22065 compiled = _.template('x', options),
22066 values = [compiled.source, undefined];
22069 _.template('<% if x %>', options);
22071 values[1] = e.source;
22073 var expected = lodashStable.map(values, alwaysFalse);
22075 var actual = lodashStable.map(values, function(value) {
22076 return lodashStable.includes(value, 'sourceURL');
22079 assert.deepEqual(actual, expected);
22082 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22085 var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
22086 compiles = lodashStable.map(array, _.template),
22087 data = { 'a': 'one', 'b': '`two`', 'c': 'three' };
22089 var actual = lodashStable.map(compiles, function(compiled) {
22090 return compiled(data);
22093 assert.deepEqual(actual, ['one', '`two`', 'three']);
22097 /*--------------------------------------------------------------------------*/
22099 QUnit.module('lodash.truncate');
22102 var string = 'hi-diddly-ho there, neighborino';
22104 QUnit.test('should use a default `length` of `30`', function(assert) {
22107 assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
22110 QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
22113 assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
22114 assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
22117 QUnit.test('should truncate string the given length', function(assert) {
22120 assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
22123 QUnit.test('should support a `omission` option', function(assert) {
22126 assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
22129 QUnit.test('should coerce nullish `omission` values to strings', function(assert) {
22132 assert.strictEqual(_.truncate(string, { 'omission': null }), 'hi-diddly-ho there, neighbnull');
22133 assert.strictEqual(_.truncate(string, { 'omission': undefined }), 'hi-diddly-ho there, nundefined');
22136 QUnit.test('should support a `length` option', function(assert) {
22139 assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
22142 QUnit.test('should support a `separator` option', function(assert) {
22145 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
22146 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
22147 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
22150 QUnit.test('should treat negative `length` as `0`', function(assert) {
22153 lodashStable.each([0, -2], function(length) {
22154 assert.strictEqual(_.truncate(string, { 'length': length }), '...');
22158 QUnit.test('should coerce `length` to an integer', function(assert) {
22161 lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
22162 var actual = index > 1 ? 'h...' : '...';
22163 assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
22167 QUnit.test('should coerce `string` to a string', function(assert) {
22170 assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
22171 assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
22174 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22177 var actual = lodashStable.map([string, string, string], _.truncate),
22178 truncated = 'hi-diddly-ho there, neighbo...';
22180 assert.deepEqual(actual, [truncated, truncated, truncated]);
22184 /*--------------------------------------------------------------------------*/
22186 QUnit.module('lodash.throttle');
22189 QUnit.test('should throttle a function', function(assert) {
22192 var done = assert.async();
22195 throttled = _.throttle(function() { callCount++; }, 32);
22201 var lastCount = callCount;
22202 assert.ok(callCount > 0);
22204 setTimeout(function() {
22205 assert.ok(callCount > lastCount);
22210 QUnit.test('subsequent calls should return the result of the first call', function(assert) {
22213 var done = assert.async();
22215 var throttled = _.throttle(identity, 32),
22216 result = [throttled('a'), throttled('b')];
22218 assert.deepEqual(result, ['a', 'a']);
22220 setTimeout(function() {
22221 var result = [throttled('x'), throttled('y')];
22222 assert.notEqual(result[0], 'a');
22223 assert.notStrictEqual(result[0], undefined);
22225 assert.notEqual(result[1], 'y');
22226 assert.notStrictEqual(result[1], undefined);
22231 QUnit.test('should clear timeout when `func` is called', function(assert) {
22234 var done = assert.async();
22236 if (!isModularize) {
22240 var getTime = function() {
22241 return ++dateCount == 5
22246 var lodash = _.runInContext(lodashStable.assign({}, root, {
22247 'Date': lodashStable.assign(function() {
22248 return { 'getTime': getTime };
22254 var throttled = lodash.throttle(function() { callCount++; }, 32);
22259 setTimeout(function() {
22260 assert.strictEqual(callCount, 2);
22265 skipAssert(assert);
22270 QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
22273 var done = assert.async();
22276 throttled = _.throttle(function() { callCount++; }, 32);
22279 assert.strictEqual(callCount, 1);
22281 setTimeout(function() {
22282 assert.strictEqual(callCount, 1);
22287 lodashStable.times(2, function(index) {
22288 QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
22291 var done = assert.async();
22294 limit = (argv || isPhantom) ? 1000 : 320,
22295 options = index ? { 'leading': false } : {},
22296 throttled = _.throttle(function() { callCount++; }, 32, options);
22298 var start = +new Date;
22299 while ((new Date - start) < limit) {
22302 var actual = callCount > 1;
22303 setTimeout(function() {
22310 QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
22313 var done = assert.async();
22317 var throttled = _.throttle(function() {
22319 }, 128, { 'leading': false });
22323 setTimeout(function() {
22324 assert.strictEqual(callCount, 1);
22328 setTimeout(function() {
22329 assert.strictEqual(callCount, 1);
22332 setTimeout(function() {
22333 assert.strictEqual(callCount, 2);
22338 QUnit.test('should apply default options', function(assert) {
22341 var done = assert.async();
22344 throttled = _.throttle(function() { callCount++; }, 32, {});
22348 assert.strictEqual(callCount, 1);
22350 setTimeout(function() {
22351 assert.strictEqual(callCount, 2);
22356 QUnit.test('should support a `leading` option', function(assert) {
22359 var withLeading = _.throttle(identity, 32, { 'leading': true });
22360 assert.strictEqual(withLeading('a'), 'a');
22362 var withoutLeading = _.throttle(identity, 32, { 'leading': false });
22363 assert.strictEqual(withoutLeading('a'), undefined);
22366 QUnit.test('should support a `trailing` option', function(assert) {
22369 var done = assert.async();
22374 var withTrailing = _.throttle(function(value) {
22377 }, 64, { 'trailing': true });
22379 var withoutTrailing = _.throttle(function(value) {
22382 }, 64, { 'trailing': false });
22384 assert.strictEqual(withTrailing('a'), 'a');
22385 assert.strictEqual(withTrailing('b'), 'a');
22387 assert.strictEqual(withoutTrailing('a'), 'a');
22388 assert.strictEqual(withoutTrailing('b'), 'a');
22390 setTimeout(function() {
22391 assert.strictEqual(withCount, 2);
22392 assert.strictEqual(withoutCount, 1);
22397 QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
22400 var done = assert.async();
22404 var throttled = _.throttle(function() {
22406 }, 64, { 'trailing': false });
22411 setTimeout(function() {
22416 setTimeout(function() {
22417 assert.ok(callCount > 1);
22423 /*--------------------------------------------------------------------------*/
22425 QUnit.module('lodash.debounce and lodash.throttle');
22427 lodashStable.each(['debounce', 'throttle'], function(methodName) {
22428 var func = _[methodName],
22429 isDebounce = methodName == 'debounce';
22431 QUnit.test('`_.' + methodName + '` should not error for non-object `options` values', function(assert) {
22444 QUnit.test('`_.' + methodName + '` should use a default `wait` of `0`', function(assert) {
22447 var done = assert.async();
22450 funced = func(function() { callCount++; });
22454 setTimeout(function() {
22456 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22461 QUnit.test('`_.' + methodName + '` should invoke `func` with the correct `this` binding', function(assert) {
22464 var done = assert.async();
22467 object = { 'funced': func(function() { actual.push(this); }, 32) },
22468 expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
22474 setTimeout(function() {
22475 assert.deepEqual(actual, expected);
22480 QUnit.test('`_.' + methodName + '` supports recursive calls', function(assert) {
22483 var done = assert.async();
22486 args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
22487 expected = args.slice(),
22488 queue = args.slice();
22490 var funced = func(function() {
22491 var current = [this];
22492 push.apply(current, arguments);
22493 actual.push(current);
22495 var next = queue.shift();
22497 funced.call(next[0], next[1]);
22501 var next = queue.shift();
22502 funced.call(next[0], next[1]);
22503 assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
22505 setTimeout(function() {
22506 assert.deepEqual(actual, expected.slice(0, actual.length));
22511 QUnit.test('`_.' + methodName + '` should work if the system time is set backwards', function(assert) {
22514 var done = assert.async();
22516 if (!isModularize) {
22520 var getTime = function() {
22521 return ++dateCount === 4
22522 ? +new Date(2012, 3, 23, 23, 27, 18)
22526 var lodash = _.runInContext(lodashStable.assign({}, root, {
22527 'Date': lodashStable.assign(function() {
22528 return { 'getTime': getTime, 'valueOf': getTime };
22534 var funced = lodash[methodName](function() {
22540 setTimeout(function() {
22542 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22547 skipAssert(assert);
22552 QUnit.test('`_.' + methodName + '` should support cancelling delayed calls', function(assert) {
22555 var done = assert.async();
22559 var funced = func(function() {
22561 }, 32, { 'leading': false });
22566 setTimeout(function() {
22567 assert.strictEqual(callCount, 0);
22572 QUnit.test('`_.' + methodName + '` should reset `lastCalled` after cancelling', function(assert) {
22575 var done = assert.async();
22579 var funced = func(function() {
22580 return ++callCount;
22581 }, 32, { 'leading': true });
22583 assert.strictEqual(funced(), 1);
22586 assert.strictEqual(funced(), 2);
22589 setTimeout(function() {
22590 assert.strictEqual(callCount, 3);
22595 QUnit.test('`_.' + methodName + '` should support flushing delayed calls', function(assert) {
22598 var done = assert.async();
22602 var funced = func(function() {
22603 return ++callCount;
22604 }, 32, { 'leading': false });
22607 assert.strictEqual(funced.flush(), 1);
22609 setTimeout(function() {
22610 assert.strictEqual(callCount, 1);
22615 QUnit.test('`_.' + methodName + '` should noop `cancel` and `flush` when nothing is queued', function(assert) {
22618 var done = assert.async();
22621 funced = func(function() { callCount++; }, 32);
22624 assert.strictEqual(funced.flush(), undefined);
22626 setTimeout(function() {
22627 assert.strictEqual(callCount, 0);
22633 /*--------------------------------------------------------------------------*/
22635 QUnit.module('lodash.times');
22638 QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
22641 lodashStable.each([-Infinity, NaN, Infinity], function(n) {
22642 assert.deepEqual(_.times(n), []);
22646 QUnit.test('should coerce `n` to an integer', function(assert) {
22649 var actual = _.times(2.6, _.indentify);
22650 assert.deepEqual(actual, [0, 1]);
22653 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
22658 _.times(1, function(assert) {
22659 args || (args = slice.call(arguments));
22662 assert.deepEqual(args, [0]);
22665 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
22668 var values = [, null, undefined],
22669 expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
22671 var actual = lodashStable.map(values, function(value, index) {
22672 return index ? _.times(3, value) : _.times(3);
22675 assert.deepEqual(actual, expected);
22678 QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
22681 assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
22684 QUnit.test('should return an empty array for falsey and negative `n` arguments', function(assert) {
22687 var values = falsey.concat(-1, -Infinity),
22688 expected = lodashStable.map(values, alwaysEmptyArray);
22690 var actual = lodashStable.map(values, function(value, index) {
22691 return index ? _.times(value) : _.times();
22694 assert.deepEqual(actual, expected);
22697 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
22701 assert.deepEqual(_(3).times(), [0, 1, 2]);
22704 skipAssert(assert);
22708 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
22712 assert.ok(_(3).chain().times() instanceof _);
22715 skipAssert(assert);
22720 /*--------------------------------------------------------------------------*/
22722 QUnit.module('lodash.toArray');
22725 QUnit.test('should convert objects to arrays', function(assert) {
22728 assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
22731 QUnit.test('should convert strings to arrays', function(assert) {
22734 assert.deepEqual(_.toArray(''), []);
22735 assert.deepEqual(_.toArray('ab'), ['a', 'b']);
22736 assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
22739 QUnit.test('should convert iterables to arrays', function(assert) {
22742 if (!isNpm && Symbol && Symbol.iterator) {
22743 var object = { '0': 'a', 'length': 1 };
22744 object[Symbol.iterator] = arrayProto[Symbol.iterator];
22746 assert.deepEqual(_.toArray(object), ['a']);
22749 skipAssert(assert);
22753 QUnit.test('should work in a lazy sequence', function(assert) {
22757 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
22758 actual = _(array).slice(1).map(String).toArray().value();
22760 assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
22762 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
22763 return ['key' + index, index];
22766 actual = _(object).toArray().slice(1).map(String).value();
22767 assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
22770 skipAssert(assert, 2);
22775 /*--------------------------------------------------------------------------*/
22777 QUnit.module('lodash.toLower');
22780 QUnit.test('should convert whole string to lower case', function(assert) {
22783 assert.deepEqual(_.toLower('--Foo-Bar--'), '--foo-bar--');
22784 assert.deepEqual(_.toLower('fooBar'), 'foobar');
22785 assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
22789 /*--------------------------------------------------------------------------*/
22791 QUnit.module('lodash.toUpper');
22794 QUnit.test('should convert whole string to upper case', function(assert) {
22797 assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
22798 assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
22799 assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
22803 /*--------------------------------------------------------------------------*/
22805 QUnit.module('lodash.slice and lodash.toArray');
22807 lodashStable.each(['slice', 'toArray'], function(methodName) {
22808 var args = (function() { return arguments; }(1, 2, 3)),
22810 func = _[methodName];
22812 QUnit.test('`_.' + methodName + '` should return a dense array', function(assert) {
22815 var sparse = Array(3);
22818 var actual = func(sparse);
22820 assert.ok('0' in actual);
22821 assert.ok('2' in actual);
22822 assert.deepEqual(actual, sparse);
22825 QUnit.test('`_.' + methodName + '` should treat array-like objects like arrays', function(assert) {
22828 var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 };
22829 assert.deepEqual(func(object), ['a', 'b', 'c']);
22830 assert.deepEqual(func(args), array);
22833 QUnit.test('`_.' + methodName + '` should return a shallow clone of arrays', function(assert) {
22836 var actual = func(array);
22837 assert.deepEqual(actual, array);
22838 assert.notStrictEqual(actual, array);
22841 QUnit.test('`_.' + methodName + '` should work with a node list for `collection`', function(assert) {
22846 var actual = func(document.getElementsByTagName('body'));
22849 assert.deepEqual(actual, [body]);
22852 skipAssert(assert);
22857 /*--------------------------------------------------------------------------*/
22859 QUnit.module('toInteger methods');
22861 lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
22862 var func = _[methodName],
22863 isSafe = methodName == 'toSafeInteger';
22865 QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
22868 assert.strictEqual(func(-5.6), -5);
22869 assert.strictEqual(func('5.6'), 5);
22870 assert.strictEqual(func(), 0);
22871 assert.strictEqual(func(NaN), 0);
22873 var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
22874 assert.strictEqual(func(Infinity), expected);
22875 assert.strictEqual(func(-Infinity), -expected);
22878 QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
22881 assert.strictEqual(1 / func(-0), -Infinity);
22885 /*--------------------------------------------------------------------------*/
22887 QUnit.module('lodash.toLength');
22890 QUnit.test('should return a valid length', function(assert) {
22893 assert.strictEqual(_.toLength(-1), 0);
22894 assert.strictEqual(_.toLength('1'), 1);
22895 assert.strictEqual(_.toLength(1.1), 1);
22896 assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
22899 QUnit.test('should return `value` if a valid length', function(assert) {
22902 assert.strictEqual(_.toLength(0), 0);
22903 assert.strictEqual(_.toLength(3), 3);
22904 assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
22907 QUnit.test('should convert `-0` to `0`', function(assert) {
22910 assert.strictEqual(1 / _.toLength(-0), Infinity);
22914 /*--------------------------------------------------------------------------*/
22916 QUnit.module('number coercion methods');
22918 lodashStable.each(['toInteger', 'toNumber', 'toSafeInteger'], function(methodName) {
22919 var func = _[methodName];
22921 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
22924 var values = [0, '0', -0, '-0'],
22925 expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
22927 lodashStable.times(2, function(index) {
22928 var others = lodashStable.map(values, index ? Object : identity);
22930 var actual = lodashStable.map(others, function(value) {
22931 var result = func(value);
22932 return [result, 1 / result];
22935 assert.deepEqual(actual, expected);
22940 lodashStable.each(['toInteger', 'toLength', 'toNumber', 'toSafeInteger'], function(methodName) {
22941 var func = _[methodName],
22942 isToLength = methodName == 'toLength',
22943 isToNumber = methodName == 'toNumber',
22944 isToSafeInteger = methodName == 'toSafeInteger';
22946 function negative(string) {
22947 return '-' + string;
22950 function pad(string) {
22951 return whitespace + string + whitespace;
22954 function positive(string) {
22955 return '+' + string;
22958 QUnit.test('`_.' + methodName + '` should pass thru primitive number values', function(assert) {
22961 var values = [0, 1, NaN];
22963 var expected = lodashStable.map(values, function(value) {
22964 return (!isToNumber && value !== value) ? 0 : value;
22967 var actual = lodashStable.map(values, func);
22969 assert.deepEqual(actual, expected);
22972 QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
22975 var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
22977 var expected = lodashStable.map(values, function(value) {
22979 if (value == 1.2) {
22982 else if (value == Infinity) {
22983 value = MAX_INTEGER;
22985 else if (value !== value) {
22988 if (isToLength || isToSafeInteger) {
22989 value = Math.min(value, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
22992 var neg = isToLength ? 0 : -value;
22993 return [value, value, neg, neg];
22996 var actual = lodashStable.map(values, function(value) {
22997 return [func(value), func(Object(value)), func(-value), func(Object(-value))];
23000 assert.deepEqual(actual, expected);
23003 QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
23006 var transforms = [identity, pad, positive, negative];
23009 '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
23010 '1e+308', '1e308', '1E+308', '1E308',
23011 '5e-324', '5E-324',
23015 var expected = lodashStable.map(values, function(value) {
23018 if (n == 1.234567890) {
23021 else if (n == Infinity) {
23024 else if (n == Number.MIN_VALUE || n !== n) {
23027 if (isToLength || isToSafeInteger) {
23028 n = Math.min(n, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
23031 var neg = isToLength ? 0 : -n;
23032 return [n, n, n, n, n, n, neg, neg];
23035 var actual = lodashStable.map(values, function(value) {
23036 return lodashStable.flatMap(transforms, function(mod) {
23037 return [func(mod(value)), func(Object(mod(value)))];
23041 assert.deepEqual(actual, expected);
23044 QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
23047 var numbers = [42, 5349, 1715004],
23048 transforms = [identity, pad],
23049 values = ['0b101010', '0o12345', '0x1a2b3c'];
23051 var expected = lodashStable.map(numbers, function(n) {
23052 return lodashStable.times(8, lodashStable.constant(n));
23055 var actual = lodashStable.map(values, function(value) {
23056 var upper = value.toUpperCase();
23057 return lodashStable.flatMap(transforms, function(mod) {
23058 return [func(mod(value)), func(Object(mod(value))), func(mod(upper)), func(Object(mod(upper)))];
23062 assert.deepEqual(actual, expected);
23065 QUnit.test('`_.' + methodName + '` should convert invalid binary/octal strings to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23068 var transforms = [identity, pad, positive, negative],
23069 values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
23071 var expected = lodashStable.map(values, function(n) {
23072 return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
23075 var actual = lodashStable.map(values, function(value) {
23076 return lodashStable.flatMap(transforms, function(mod) {
23077 return [func(mod(value)), func(Object(mod(value)))];
23081 assert.deepEqual(actual, expected);
23084 QUnit.test('`_.' + methodName + '` should convert symbols to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23088 var object1 = Object(symbol),
23089 object2 = Object(symbol),
23090 values = [symbol, object1, object2],
23091 expected = lodashStable.map(values, lodashStable.constant(isToNumber ? NaN : 0));
23093 object2.valueOf = undefined;
23094 var actual = lodashStable.map(values, func);
23096 assert.deepEqual(actual, expected);
23099 skipAssert(assert);
23103 QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
23106 var values = falsey.concat(whitespace);
23108 var expected = lodashStable.map(values, function(value) {
23109 return (isToNumber && value !== whitespace) ? Number(value) : 0;
23112 var actual = lodashStable.map(values, function(value, index) {
23113 return index ? func(value) : func();
23116 assert.deepEqual(actual, expected);
23119 QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
23127 { 'valueOf': '1.1' },
23128 { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
23129 { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
23130 { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
23131 { 'valueOf': lodashStable.constant('-0x1a2b3c') },
23132 { 'toString': lodashStable.constant('-0x1a2b3c') },
23133 { 'valueOf': lodashStable.constant('0o12345') },
23134 { 'toString': lodashStable.constant('0o12345') },
23135 { 'valueOf': lodashStable.constant('0b101010') },
23136 { 'toString': lodashStable.constant('0b101010') }
23141 NaN, 2.2, 1.1, 1.1,
23156 var actual = lodashStable.map(values, func);
23158 assert.deepEqual(actual, expected);
23162 /*--------------------------------------------------------------------------*/
23164 QUnit.module('lodash.toPairs');
23167 QUnit.test('should be aliased', function(assert) {
23170 assert.strictEqual(_.entries, _.toPairs);
23174 /*--------------------------------------------------------------------------*/
23176 QUnit.module('lodash.toPairsIn');
23179 QUnit.test('should be aliased', function(assert) {
23182 assert.strictEqual(_.entriesIn, _.toPairsIn);
23186 /*--------------------------------------------------------------------------*/
23188 QUnit.module('toPairs methods');
23190 lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) {
23191 var func = _[methodName],
23192 isToPairs = methodName == 'toPairs';
23194 QUnit.test('`_.' + methodName + '` should create an array of string keyed-value pairs', function(assert) {
23197 var object = { 'a': 1, 'b': 2 },
23198 actual = lodashStable.sortBy(func(object), 0);
23200 assert.deepEqual(actual, [['a', 1], ['b', 2]]);
23203 QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
23206 var object = { '0': 'a', '1': 'b', 'length': 2 },
23207 actual = lodashStable.sortBy(func(object), 0);
23209 assert.deepEqual(actual, [['0', 'a'], ['1', 'b'], ['length', 2]]);
23212 QUnit.test('`_.' + methodName + '` should ' + (isToPairs ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
23218 Foo.prototype.b = 2;
23220 var expected = isToPairs ? [['a', 1]] : [['a', 1], ['b', 2]],
23221 actual = lodashStable.sortBy(func(new Foo), 0);
23223 assert.deepEqual(actual, expected);
23226 QUnit.test('`_.' + methodName + '` should work with strings', function(assert) {
23229 lodashStable.each(['xo', Object('xo')], function(string) {
23230 var actual = lodashStable.sortBy(func(string), 0);
23231 assert.deepEqual(actual, [['0', 'x'], ['1', 'o']]);
23236 /*--------------------------------------------------------------------------*/
23238 QUnit.module('lodash.toPath');
23241 QUnit.test('should convert a string to a path', function(assert) {
23244 assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
23245 assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
23248 QUnit.test('should coerce array elements to strings', function(assert) {
23251 var array = ['a', 'b', 'c'];
23253 lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
23254 var actual = _.toPath(value);
23255 assert.deepEqual(actual, array);
23256 assert.notStrictEqual(actual, array);
23260 QUnit.test('should a new path array', function(assert) {
23263 assert.notStrictEqual(_.toPath('a.b.c'), _.toPath('a.b.c'));
23266 QUnit.test('should not coerce symbols to strings', function(assert) {
23270 var object = Object(symbol);
23271 lodashStable.each([symbol, object, [symbol], [object]], function(value) {
23272 var actual = _.toPath(value);
23273 assert.ok(lodashStable.isSymbol(actual[0]));
23277 skipAssert(assert, 4);
23281 QUnit.test('should handle complex paths', function(assert) {
23284 var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
23285 assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
23288 QUnit.test('should ignore consecutive brackets and dots', function(assert) {
23291 var expected = ['a'];
23292 assert.deepEqual(_.toPath('a.'), expected);
23293 assert.deepEqual(_.toPath('a[]'), expected);
23295 expected = ['a', 'b'];
23296 assert.deepEqual(_.toPath('a..b'), expected);
23297 assert.deepEqual(_.toPath('a[][]b'), expected);
23301 /*--------------------------------------------------------------------------*/
23303 QUnit.module('lodash.toPlainObject');
23306 var args = arguments;
23308 QUnit.test('should flatten inherited string keyed properties', function(assert) {
23314 Foo.prototype.c = 3;
23316 var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
23317 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
23320 QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
23323 var actual = _.toPlainObject(args),
23324 expected = { '0': 1, '1': 2, '2': 3 };
23326 assert.deepEqual(actual, expected);
23329 QUnit.test('should convert arrays to plain objects', function(assert) {
23332 var actual = _.toPlainObject(['a', 'b', 'c']),
23333 expected = { '0': 'a', '1': 'b', '2': 'c' };
23335 assert.deepEqual(actual, expected);
23339 /*--------------------------------------------------------------------------*/
23341 QUnit.module('lodash.toString');
23344 QUnit.test('should treat nullish values as empty strings', function(assert) {
23347 var values = [, null, undefined],
23348 expected = lodashStable.map(values, alwaysEmptyString);
23350 var actual = lodashStable.map(values, function(value, index) {
23351 return index ? _.toString(value) : _.toString();
23354 assert.deepEqual(actual, expected);
23357 QUnit.test('should preserve the sign of `0`', function(assert) {
23360 var values = [-0, Object(-0), 0, Object(0)],
23361 expected = ['-0', '-0', '0', '0'],
23362 actual = lodashStable.map(values, _.toString);
23364 assert.deepEqual(actual, expected);
23367 QUnit.test('should not error on symbols', function(assert) {
23372 assert.strictEqual(_.toString(symbol), 'Symbol(a)');
23374 assert.ok(false, e.message);
23378 skipAssert(assert);
23382 QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
23386 var wrapped = _([1, 2, 3]);
23387 assert.strictEqual(wrapped.toString(), '1,2,3');
23390 skipAssert(assert);
23395 /*--------------------------------------------------------------------------*/
23397 QUnit.module('lodash.transform');
23406 QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
23409 var accumulators = [, null, undefined],
23411 expected = lodashStable.map(accumulators, alwaysTrue);
23413 var iteratee = function(result, value, key) {
23414 result[key] = square(value);
23417 var mapper = function(accumulator, index) {
23418 return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
23421 var results = lodashStable.map(accumulators, mapper);
23423 var actual = lodashStable.map(results, function(result) {
23424 return result instanceof Foo;
23427 assert.deepEqual(actual, expected);
23429 expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
23430 actual = lodashStable.map(results, lodashStable.toPlainObject);
23432 assert.deepEqual(actual, expected);
23434 object = { 'a': 1, 'b': 2, 'c': 3 };
23435 actual = lodashStable.map(accumulators, mapper);
23437 assert.deepEqual(actual, expected);
23439 object = [1, 2, 3];
23440 expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
23441 actual = lodashStable.map(accumulators, mapper);
23443 assert.deepEqual(actual, expected);
23446 QUnit.test('should create regular arrays from typed arrays', function(assert) {
23449 var expected = lodashStable.map(typedArrays, alwaysTrue);
23451 var actual = lodashStable.map(typedArrays, function(type) {
23452 var Ctor = root[type],
23453 array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
23455 return lodashStable.isArray(_.transform(array, noop));
23458 assert.deepEqual(actual, expected);
23461 QUnit.test('should support an `accumulator` value', function(assert) {
23464 var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
23465 expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
23467 var actual = lodashStable.map(values, function(value) {
23468 return _.transform(value, function(result, value) {
23469 result.push(square(value));
23473 assert.deepEqual(actual, expected);
23475 var object = { 'a': 1, 'b': 4, 'c': 9 },
23476 expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
23478 actual = lodashStable.map(values, function(value) {
23479 return _.transform(value, function(result, value, key) {
23480 result[key] = square(value);
23484 assert.deepEqual(actual, expected);
23486 lodashStable.each([[], {}], function(accumulator) {
23487 var actual = lodashStable.map(values, function(value) {
23488 return _.transform(value, noop, accumulator);
23491 assert.ok(lodashStable.every(actual, function(result) {
23492 return result === accumulator;
23495 assert.strictEqual(_.transform(null, null, accumulator), accumulator);
23499 QUnit.test('should treat sparse arrays as dense', function(assert) {
23502 var actual = _.transform(Array(1), function(result, value, index) {
23503 result[index] = String(value);
23506 assert.deepEqual(actual, ['undefined']);
23509 QUnit.test('should work without an `iteratee` argument', function(assert) {
23512 assert.ok(_.transform(new Foo) instanceof Foo);
23515 QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
23518 var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
23519 values = [false, true, 0, 1, NaN, '', 'a'],
23520 expected = lodashStable.map(values, alwaysEmptyObject);
23522 var results = lodashStable.map(values, function(value) {
23523 return _.transform(value);
23526 assert.deepEqual(results, expected);
23528 expected = lodashStable.map(values, alwaysFalse);
23530 var actual = lodashStable.map(results, function(value, index) {
23531 return value instanceof Ctors[index];
23534 assert.deepEqual(actual, expected);
23537 QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
23540 Foo.prototype.constructor = null;
23541 assert.notOk(_.transform(new Foo) instanceof Foo);
23542 Foo.prototype.constructor = Foo;
23545 QUnit.test('should create an empty object when given a falsey `object` argument', function(assert) {
23548 var expected = lodashStable.map(falsey, alwaysEmptyObject);
23550 var actual = lodashStable.map(falsey, function(object, index) {
23551 return index ? _.transform(object) : _.transform();
23554 assert.deepEqual(actual, expected);
23557 lodashStable.each({
23558 'array': [1, 2, 3],
23559 'object': { 'a': 1, 'b': 2, 'c': 3 }
23561 function(object, key) {
23562 QUnit.test('should provide the correct `iteratee` arguments when transforming an ' + key, function(assert) {
23567 _.transform(object, function() {
23568 args || (args = slice.call(arguments));
23571 var first = args[0];
23572 if (key == 'array') {
23573 assert.ok(first !== object && lodashStable.isArray(first));
23574 assert.deepEqual(args, [first, 1, 0, object]);
23576 assert.ok(first !== object && lodashStable.isPlainObject(first));
23577 assert.deepEqual(args, [first, 1, 'a', object]);
23582 QUnit.test('should create an object from the same realm as `object`', function(assert) {
23585 var objects = lodashStable.filter(realm, function(value) {
23586 return lodashStable.isObject(value) && !lodashStable.isElement(value);
23589 var expected = lodashStable.map(objects, alwaysTrue);
23591 var actual = lodashStable.map(objects, function(object) {
23592 var Ctor = object.constructor,
23593 result = _.transform(object);
23595 if (result === object) {
23598 if (lodashStable.isTypedArray(object)) {
23599 return result instanceof Array;
23601 return result instanceof Ctor || !(new Ctor instanceof Ctor);
23604 assert.deepEqual(actual, expected);
23608 /*--------------------------------------------------------------------------*/
23610 QUnit.module('trim methods');
23612 lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
23613 var func = _[methodName],
23617 parts.push('leading');
23620 parts.push('trailing');
23622 parts = parts.join(' and ');
23624 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
23627 var string = whitespace + 'a b c' + whitespace,
23628 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
23630 assert.strictEqual(func(string), expected);
23633 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
23636 var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
23637 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
23639 assert.strictEqual(func(object), expected);
23642 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
23645 var string = '-_-a-b-c-_-',
23646 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
23648 assert.strictEqual(func(string, '_-'), expected);
23651 QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
23654 var object = { 'toString': lodashStable.constant('_-') },
23655 string = '-_-a-b-c-_-',
23656 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
23658 assert.strictEqual(func(string, object), expected);
23661 QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
23664 lodashStable.each([null, '_-'], function(chars) {
23665 assert.strictEqual(func(null, chars), '');
23666 assert.strictEqual(func(undefined, chars), '');
23667 assert.strictEqual(func('', chars), '');
23671 QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
23674 var string = whitespace + 'a b c' + whitespace,
23675 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
23677 assert.strictEqual(func(string, undefined), expected);
23678 assert.strictEqual(func(string, ''), string);
23681 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
23684 var string = Object(whitespace + 'a b c' + whitespace),
23685 trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
23686 actual = lodashStable.map([string, string, string], func);
23688 assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
23691 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
23695 var string = whitespace + 'a b c' + whitespace,
23696 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
23698 assert.strictEqual(_(string)[methodName](), expected);
23701 skipAssert(assert);
23705 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
23709 var string = whitespace + 'a b c' + whitespace;
23710 assert.ok(_(string).chain()[methodName]() instanceof _);
23713 skipAssert(assert);
23718 /*--------------------------------------------------------------------------*/
23720 QUnit.module('uncommon symbols');
23723 var flag = '\ud83c\uddfa\ud83c\uddf8',
23724 heart = '\u2764' + emojiVar,
23725 hearts = '\ud83d\udc95',
23726 comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68',
23727 hashKeycap = '#' + emojiVar + '\u20e3',
23728 leafs = '\ud83c\udf42',
23729 mic = '\ud83c\udf99',
23730 noMic = mic + '\u20e0',
23731 raisedHand = '\u270B' + emojiVar,
23732 rocket = '\ud83d\ude80',
23733 thumbsUp = '\ud83d\udc4d';
23735 QUnit.test('should account for astral symbols', function(assert) {
23738 var allHearts = _.repeat(hearts, 10),
23739 chars = hearts + comboGlyph,
23740 string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
23741 trimChars = comboGlyph + hearts,
23742 trimString = trimChars + string + trimChars;
23744 assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
23745 assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
23746 assert.strictEqual(_.capitalize(rocket), rocket);
23748 assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
23749 assert.strictEqual(_.padStart(string, 16), ' ' + string);
23750 assert.strictEqual(_.padEnd(string, 16), string + ' ');
23752 assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
23753 assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
23754 assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
23756 assert.strictEqual(_.size(string), 13);
23757 assert.deepEqual(_.split(string, ' '), ['A', leafs + ',', comboGlyph + ',', 'and', rocket]);
23758 assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
23759 assert.deepEqual(_.split(string, undefined), [string]);
23760 assert.deepEqual(_.split(string, undefined, -1), [string]);
23761 assert.deepEqual(_.split(string, undefined, 0), []);
23763 var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];
23765 assert.deepEqual(_.split(string, ''), expected);
23766 assert.deepEqual(_.split(string, '', 6), expected.slice(0, 6));
23767 assert.deepEqual(_.toArray(string), expected);
23769 assert.strictEqual(_.trim(trimString, chars), string);
23770 assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
23771 assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
23773 assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
23774 assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
23776 assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
23777 assert.deepEqual(_.toArray(hashKeycap), [hashKeycap]);
23778 assert.deepEqual(_.toArray(noMic), [noMic]);
23780 lodashStable.times(2, function(index) {
23781 var separator = index ? RegExp(hearts) : hearts,
23782 options = { 'length': 4, 'separator': separator },
23783 actual = _.truncate(string, options);
23785 assert.strictEqual(actual, 'A...');
23786 assert.strictEqual(actual.length, 4);
23788 actual = _.truncate(allHearts, options);
23789 assert.strictEqual(actual, hearts + '...');
23790 assert.strictEqual(actual.length, 5);
23794 QUnit.test('should account for combining diacritical marks', function(assert) {
23797 var values = lodashStable.map(comboMarks, function(mark) {
23801 var expected = lodashStable.map(values, function(value) {
23802 return [1, [value], [value]];
23805 var actual = lodashStable.map(values, function(value) {
23806 return [_.size(value), _.toArray(value), _.words(value)];
23809 assert.deepEqual(actual, expected);
23812 QUnit.test('should account for fitzpatrick modifiers', function(assert) {
23815 var values = lodashStable.map(fitzModifiers, function(modifier) {
23816 return thumbsUp + modifier;
23819 var expected = lodashStable.map(values, function(value) {
23820 return [1, [value], [value]];
23823 var actual = lodashStable.map(values, function(value) {
23824 return [_.size(value), _.toArray(value), _.words(value)];
23827 assert.deepEqual(actual, expected);
23830 QUnit.test('should account for regional symbols', function(assert) {
23833 var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
23834 regionals = pair.join(' ');
23836 assert.strictEqual(_.size(flag), 1);
23837 assert.strictEqual(_.size(regionals), 3);
23839 assert.deepEqual(_.toArray(flag), [flag]);
23840 assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
23842 assert.deepEqual(_.words(flag), [flag]);
23843 assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
23846 QUnit.test('should account for variation selectors', function(assert) {
23849 assert.strictEqual(_.size(heart), 1);
23850 assert.deepEqual(_.toArray(heart), [heart]);
23851 assert.deepEqual(_.words(heart), [heart]);
23854 QUnit.test('should account for variation selectors with fitzpatrick modifiers', function(assert) {
23857 var values = lodashStable.map(fitzModifiers, function(modifier) {
23858 return raisedHand + modifier;
23861 var expected = lodashStable.map(values, function(value) {
23862 return [1, [value], [value]];
23865 var actual = lodashStable.map(values, function(value) {
23866 return [_.size(value), _.toArray(value), _.words(value)];
23869 assert.deepEqual(actual, expected);
23872 QUnit.test('should match lone surrogates', function(assert) {
23875 var pair = hearts.split(''),
23876 surrogates = pair[0] + ' ' + pair[1];
23878 assert.strictEqual(_.size(surrogates), 3);
23879 assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
23880 assert.deepEqual(_.words(surrogates), []);
23883 QUnit.test('should match side by side fitzpatrick modifiers separately ', function(assert) {
23886 var string = fitzModifiers[0] + fitzModifiers[0];
23887 assert.deepEqual(_.toArray(string), [fitzModifiers[0], fitzModifiers[0]]);
23891 /*--------------------------------------------------------------------------*/
23893 QUnit.module('lodash.unary');
23897 return slice.call(arguments);
23900 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
23903 var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
23904 assert.deepEqual(actual, [6, 8, 10]);
23907 QUnit.test('should work when provided less than the capped number of arguments', function(assert) {
23910 var capped = _.unary(fn);
23911 assert.deepEqual(capped(), []);
23915 /*--------------------------------------------------------------------------*/
23917 QUnit.module('lodash.unescape');
23920 var escaped = '&<>"'\/',
23921 unescaped = '&<>"\'\/';
23923 escaped += escaped;
23924 unescaped += unescaped;
23926 QUnit.test('should unescape entities in order', function(assert) {
23929 assert.strictEqual(_.unescape('&lt;'), '<');
23932 QUnit.test('should unescape the proper entities', function(assert) {
23935 assert.strictEqual(_.unescape(escaped), unescaped);
23938 QUnit.test('should not unescape the "/" entity', function(assert) {
23941 assert.strictEqual(_.unescape('/'), '/');
23944 QUnit.test('should handle strings with nothing to unescape', function(assert) {
23947 assert.strictEqual(_.unescape('abc'), 'abc');
23950 QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
23953 assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
23957 /*--------------------------------------------------------------------------*/
23959 QUnit.module('lodash.unionBy');
23962 QUnit.test('should accept an `iteratee` argument', function(assert) {
23965 var actual = _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
23966 assert.deepEqual(actual, [2.1, 1.2, 4.3]);
23968 actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
23969 assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
23972 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
23977 _.unionBy([2.1, 1.2], [4.3, 2.4], function() {
23978 args || (args = slice.call(arguments));
23981 assert.deepEqual(args, [2.1]);
23985 /*--------------------------------------------------------------------------*/
23987 QUnit.module('lodash.unionWith');
23990 QUnit.test('should work with a `comparator` argument', function(assert) {
23993 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
23994 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
23995 actual = _.unionWith(objects, others, lodashStable.isEqual);
23997 assert.deepEqual(actual, [objects[0], objects[1], others[0]]);
24001 /*--------------------------------------------------------------------------*/
24003 QUnit.module('union methods');
24005 lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
24006 var args = (function() { return arguments; }(1, 2, 3)),
24007 func = _[methodName];
24009 QUnit.test('`_.' + methodName + '` should return the union of the given arrays', function(assert) {
24012 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
24013 assert.deepEqual(actual, [1, 3, 2, 5, 4]);
24016 QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
24019 var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
24020 assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
24023 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
24027 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
24028 assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
24029 assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
24033 /*--------------------------------------------------------------------------*/
24035 QUnit.module('lodash.uniq');
24038 QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
24041 var array = [[2, 1, 2], [1, 2, 1]],
24042 actual = lodashStable.map(array, lodashStable.uniq);
24044 assert.deepEqual(actual, [[2, 1], [1, 2]]);
24048 /*--------------------------------------------------------------------------*/
24050 QUnit.module('uniqBy methods');
24052 lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
24053 var func = _[methodName],
24054 isSorted = methodName == 'sortedUniqBy',
24055 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24058 objects = _.sortBy(objects, 'a');
24060 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
24063 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
24065 var actual = func(objects, function(object) {
24069 assert.deepEqual(actual, expected);
24072 QUnit.test('should work with large arrays', function(assert) {
24075 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
24079 var actual = func(largeArray, String);
24081 assert.deepEqual(actual, [[1, 2]]);
24082 assert.strictEqual(actual[0], largeArray[0]);
24085 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
24090 func(objects, function() {
24091 args || (args = slice.call(arguments));
24094 assert.deepEqual(args, [objects[0]]);
24097 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
24100 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
24101 actual = func(objects, 'a');
24103 assert.deepEqual(actual, expected);
24105 var arrays = [[2], [3], [1], [2], [3], [1]];
24107 arrays = lodashStable.sortBy(arrays, 0);
24109 expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
24110 actual = func(arrays, 0);
24112 assert.deepEqual(actual, expected);
24115 lodashStable.each({
24116 'an array': [0, 'a'],
24117 'an object': { '0': 'a' },
24121 function(iteratee, key) {
24122 QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
24125 var actual = func([['a'], ['a'], ['b']], iteratee);
24126 assert.deepEqual(actual, [['a'], ['b']]);
24131 /*--------------------------------------------------------------------------*/
24133 QUnit.module('lodash.uniqWith');
24136 QUnit.test('should work with a `comparator` argument', function(assert) {
24139 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }],
24140 actual = _.uniqWith(objects, lodashStable.isEqual);
24142 assert.deepEqual(actual, [objects[0], objects[1]]);
24145 QUnit.test('should preserve the sign of `0`', function(assert) {
24148 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24149 return isEven(index) ? -0 : 0;
24152 var arrays = [[-0, 0], largeArray],
24153 expected = lodashStable.map(arrays, lodashStable.constant(['-0']));
24155 var actual = lodashStable.map(arrays, function(array) {
24156 return lodashStable.map(_.uniqWith(array, lodashStable.eq), lodashStable.toString);
24159 assert.deepEqual(actual, expected);
24163 /*--------------------------------------------------------------------------*/
24165 QUnit.module('uniq methods');
24167 lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
24168 var func = _[methodName],
24169 isSorted = /^sorted/.test(methodName),
24170 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24173 objects = _.sortBy(objects, 'a');
24176 QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
24179 var array = [2, 3, 1, 2, 3, 1];
24180 assert.deepEqual(func(array), [2, 3, 1]);
24183 QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
24186 var array = [1, 1, 2, 2, 3];
24187 assert.deepEqual(func(array), [1, 2, 3]);
24190 QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
24193 assert.deepEqual(func(objects), objects);
24196 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
24199 var actual = lodashStable.map(func([-0, 0]), lodashStable.toString);
24200 assert.deepEqual(actual, ['0']);
24203 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
24206 assert.deepEqual(func([NaN, NaN]), [NaN]);
24209 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
24212 var largeArray = [],
24213 expected = [0, {}, 'a'],
24214 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24216 lodashStable.each(expected, function(value) {
24217 lodashStable.times(count, function() {
24218 largeArray.push(value);
24222 assert.deepEqual(func(largeArray), expected);
24225 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
24228 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24229 return isEven(index) ? -0 : 0;
24232 var actual = lodashStable.map(func(largeArray), lodashStable.toString);
24233 assert.deepEqual(actual, ['0']);
24236 QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
24239 var largeArray = [],
24240 expected = [null, undefined, false, true, NaN],
24241 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24243 lodashStable.each(expected, function(value) {
24244 lodashStable.times(count, function() {
24245 largeArray.push(value);
24249 assert.deepEqual(func(largeArray), expected);
24252 QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
24256 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
24257 assert.deepEqual(func(largeArray), largeArray);
24260 skipAssert(assert);
24264 QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
24267 // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
24270 Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
24271 Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
24272 Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
24275 var largeArray = [],
24276 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24278 expected = lodashStable.map(expected, function(symbol) {
24279 return symbol || {};
24282 lodashStable.each(expected, function(value) {
24283 lodashStable.times(count, function() {
24284 largeArray.push(value);
24288 assert.deepEqual(func(largeArray), expected);
24291 skipAssert(assert);
24295 QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
24298 var largeArray = [],
24299 expected = ['2', 2, Object('2'), Object(2)],
24300 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24302 lodashStable.each(expected, function(value) {
24303 lodashStable.times(count, function() {
24304 largeArray.push(value);
24308 assert.deepEqual(func(largeArray), expected);
24312 /*--------------------------------------------------------------------------*/
24314 QUnit.module('lodash.uniqueId');
24317 QUnit.test('should generate unique ids', function(assert) {
24320 var actual = lodashStable.times(1000, function(assert) {
24321 return _.uniqueId();
24324 assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
24327 QUnit.test('should return a string value when not providing a prefix argument', function(assert) {
24330 assert.strictEqual(typeof _.uniqueId(), 'string');
24333 QUnit.test('should coerce the prefix argument to a string', function(assert) {
24336 var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
24337 assert.ok(/3\d+,2\d+,1\d+/.test(actual));
24341 /*--------------------------------------------------------------------------*/
24343 QUnit.module('lodash.unset');
24346 QUnit.test('should unset property values', function(assert) {
24349 lodashStable.each(['a', ['a']], function(path) {
24350 var object = { 'a': 1, 'c': 2 };
24351 assert.strictEqual(_.unset(object, path), true);
24352 assert.deepEqual(object, { 'c': 2 });
24356 QUnit.test('should preserve the sign of `0`', function(assert) {
24359 var props = [-0, Object(-0), 0, Object(0)],
24360 expected = lodashStable.map(props, lodashStable.constant([true, false]));
24362 var actual = lodashStable.map(props, function(key) {
24363 var object = { '-0': 'a', '0': 'b' };
24364 return [_.unset(object, key), lodashStable.toString(key) in object];
24367 assert.deepEqual(actual, expected);
24370 QUnit.test('should unset symbol keyed property values', function(assert) {
24375 object[symbol] = 1;
24377 assert.strictEqual(_.unset(object, symbol), true);
24378 assert.notOk(symbol in object);
24381 skipAssert(assert, 2);
24385 QUnit.test('should unset deep property values', function(assert) {
24388 lodashStable.each(['a.b', ['a', 'b']], function(path) {
24389 var object = { 'a': { 'b': null } };
24390 assert.strictEqual(_.unset(object, path), true);
24391 assert.deepEqual(object, { 'a': {} });
24395 QUnit.test('should handle complex paths', function(assert) {
24399 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
24400 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
24403 lodashStable.each(paths, function(path) {
24404 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
24405 assert.strictEqual(_.unset(object, path), true);
24406 assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
24410 QUnit.test('should return `true` for nonexistent paths', function(assert) {
24413 var object = { 'a': { 'b': { 'c': null } } };
24415 lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
24416 assert.strictEqual(_.unset(object, path), true);
24419 assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
24422 QUnit.test('should not error when `object` is nullish', function(assert) {
24425 var values = [null, undefined],
24426 expected = [[true, true], [true, true]];
24428 var actual = lodashStable.map(values, function(value) {
24430 return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
24436 assert.deepEqual(actual, expected);
24439 QUnit.test('should follow `path` over non-plain objects', function(assert) {
24442 var object = { 'a': '' },
24443 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
24445 lodashStable.each(paths, function(path) {
24448 var actual = _.unset(0, path);
24449 assert.strictEqual(actual, true);
24450 assert.notOk('a' in numberProto);
24452 delete numberProto.a;
24455 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
24456 stringProto.replace.b = 1;
24458 var actual = _.unset(object, path);
24459 assert.strictEqual(actual, true);
24460 assert.notOk('a' in stringProto.replace);
24462 delete stringProto.replace.b;
24466 QUnit.test('should return `false` for non-configurable properties', function(assert) {
24471 if (!isStrict && defineProperty) {
24472 defineProperty(object, 'a', {
24473 'configurable': false,
24474 'enumerable': true,
24478 assert.strictEqual(_.unset(object, 'a'), false);
24481 skipAssert(assert);
24486 /*--------------------------------------------------------------------------*/
24488 QUnit.module('lodash.unzipWith');
24491 QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
24494 var array = [[1, 4], [2, 5], [3, 6]];
24496 var actual = _.unzipWith(array, function(a, b, c) {
24500 assert.deepEqual(actual, [6, 15]);
24503 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
24508 _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
24509 args || (args = slice.call(arguments));
24512 assert.deepEqual(args, [1, 2]);
24515 QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
24518 var array = [[1, 3], [2, 4]],
24519 values = [, null, undefined],
24520 expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
24522 var actual = lodashStable.map(values, function(value, index) {
24523 return index ? _.unzipWith(array, value) : _.unzipWith(array);
24526 assert.deepEqual(actual, expected);
24530 /*--------------------------------------------------------------------------*/
24532 QUnit.module('lodash.updateWith');
24535 QUnit.test('should work with a `customizer` callback', function(assert) {
24538 var actual = _.updateWith({ '0': {} }, '[0][1][2]', alwaysThree, function(value) {
24539 return lodashStable.isObject(value) ? undefined : {};
24542 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
24545 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
24548 var actual = _.updateWith({}, 'a[0].b.c', alwaysFour, noop);
24549 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
24553 /*--------------------------------------------------------------------------*/
24555 QUnit.module('update methods');
24557 lodashStable.each(['update', 'updateWith'], function(methodName) {
24558 var func = _[methodName],
24561 QUnit.test('`_.' + methodName + '` should invoke `updater` with the value on `path` of `object`', function(assert) {
24564 var object = { 'a': [{ 'b': { 'c': oldValue } }] },
24565 expected = oldValue + 1;
24567 lodashStable.each(['a[0].b.c', ['a', '0', 'b', 'c']], function(path) {
24568 func(object, path, function(n) {
24569 assert.strictEqual(n, oldValue);
24573 assert.strictEqual(object.a[0].b.c, expected);
24574 object.a[0].b.c = oldValue;
24579 /*--------------------------------------------------------------------------*/
24581 QUnit.module('lodash.upperCase');
24584 QUnit.test('should uppercase as space-separated words', function(assert) {
24587 assert.strictEqual(_.upperCase('--foo-bar--'), 'FOO BAR');
24588 assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
24589 assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
24593 /*--------------------------------------------------------------------------*/
24595 QUnit.module('lodash.upperFirst');
24598 QUnit.test('should uppercase only the first character', function(assert) {
24601 assert.strictEqual(_.upperFirst('fred'), 'Fred');
24602 assert.strictEqual(_.upperFirst('Fred'), 'Fred');
24603 assert.strictEqual(_.upperFirst('FRED'), 'FRED');
24607 /*--------------------------------------------------------------------------*/
24609 QUnit.module('values methods');
24611 lodashStable.each(['values', 'valuesIn'], function(methodName) {
24612 var args = (function() { return arguments; }(1, 2, 3)),
24613 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
24614 func = _[methodName],
24615 isValues = methodName == 'values';
24617 QUnit.test('`_.' + methodName + '` should get string keyed values of `object`', function(assert) {
24620 var object = { 'a': 1, 'b': 2 },
24621 actual = func(object).sort();
24623 assert.deepEqual(actual, [1, 2]);
24626 QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
24629 var object = { '0': 'a', '1': 'b', 'length': 2 },
24630 actual = func(object).sort();
24632 assert.deepEqual(actual, [2, 'a', 'b']);
24635 QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
24641 Foo.prototype.b = 2;
24643 var expected = isValues ? [1] : [1, 2],
24644 actual = func(new Foo).sort();
24646 assert.deepEqual(actual, expected);
24649 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
24652 var values = [args, strictArgs],
24653 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
24655 var actual = lodashStable.map(values, function(value) {
24656 return func(value).sort();
24659 assert.deepEqual(actual, expected);
24663 /*--------------------------------------------------------------------------*/
24665 QUnit.module('lodash.without');
24668 QUnit.test('should use strict equality to determine the values to reject', function(assert) {
24671 var object1 = { 'a': 1 },
24672 object2 = { 'b': 2 },
24673 array = [object1, object2];
24675 assert.deepEqual(_.without(array, { 'a': 1 }), array);
24676 assert.deepEqual(_.without(array, object1), [object2]);
24679 QUnit.test('should remove all occurrences of each value from an array', function(assert) {
24682 var array = [1, 2, 3, 1, 2, 3];
24683 assert.deepEqual(_.without(array, 1, 2), [3, 3]);
24687 /*--------------------------------------------------------------------------*/
24689 QUnit.module('lodash.words');
24692 QUnit.test('should treat latin-1 supplementary letters as words', function(assert) {
24695 var expected = lodashStable.map(burredLetters, function(letter) {
24699 var actual = lodashStable.map(burredLetters, function(letter) {
24700 return _.words(letter);
24703 assert.deepEqual(actual, expected);
24706 QUnit.test('should not treat mathematical operators as words', function(assert) {
24709 var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
24710 expected = lodashStable.map(operators, alwaysEmptyArray),
24711 actual = lodashStable.map(operators, _.words);
24713 assert.deepEqual(actual, expected);
24716 QUnit.test('should not treat punctuation as words', function(assert) {
24720 '\u2012', '\u2013', '\u2014', '\u2015',
24721 '\u2024', '\u2025', '\u2026',
24725 var expected = lodashStable.map(marks, alwaysEmptyArray),
24726 actual = lodashStable.map(marks, _.words);
24728 assert.deepEqual(actual, expected);
24731 QUnit.test('should support a `pattern` argument', function(assert) {
24734 assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
24735 assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
24738 QUnit.test('should work with compound words', function(assert) {
24741 assert.deepEqual(_.words('12Feet'), ['12', 'Feet']);
24742 assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
24743 assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']);
24744 assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']);
24745 assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']);
24746 assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
24747 assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
24748 assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
24749 assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
24750 assert.deepEqual(_.words('XMLHttp'), ['XML', 'Http']);
24751 assert.deepEqual(_.words('XmlHTTP'), ['Xml', 'HTTP']);
24752 assert.deepEqual(_.words('XmlHttp'), ['Xml', 'Http']);
24755 QUnit.test('should work with compound words containing diacritical marks', function(assert) {
24758 assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
24759 assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
24760 assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
24763 QUnit.test('should work with contractions', function(assert) {
24766 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
24768 lodashStable.each(["'", '\u2019'], function(apos) {
24769 var actual = lodashStable.map(postfixes, function(postfix) {
24770 return _.words('a b' + apos + postfix + ' c');
24773 var expected = lodashStable.map(postfixes, function(postfix) {
24774 return ['a', 'b' + apos + postfix, 'c'];
24777 assert.deepEqual(actual, expected);
24781 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
24784 var strings = lodashStable.map(['a', 'b', 'c'], Object),
24785 actual = lodashStable.map(strings, _.words);
24787 assert.deepEqual(actual, [['a'], ['b'], ['c']]);
24791 /*--------------------------------------------------------------------------*/
24793 QUnit.module('lodash.wrap');
24796 QUnit.test('should create a wrapped function', function(assert) {
24799 var p = _.wrap(_.escape, function(func, text) {
24800 return '<p>' + func(text) + '</p>';
24803 assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
24806 QUnit.test('should provide the correct `wrapper` arguments', function(assert) {
24811 var wrapped = _.wrap(noop, function() {
24812 args || (args = slice.call(arguments));
24816 assert.deepEqual(args, [noop, 1, 2, 3]);
24819 QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
24822 var values = [, null, undefined],
24823 expected = lodashStable.map(values, alwaysA);
24825 var actual = lodashStable.map(values, function(value, index) {
24826 var wrapped = index ? _.wrap('a', value) : _.wrap('a');
24827 return wrapped('b', 'c');
24830 assert.deepEqual(actual, expected);
24833 QUnit.test('should not set a `this` binding', function(assert) {
24836 var p = _.wrap(_.escape, function(func) {
24837 return '<p>' + func(this.text) + '</p>';
24840 var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
24841 assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
24845 /*--------------------------------------------------------------------------*/
24847 QUnit.module('xor methods');
24849 lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
24850 var args = (function() { return arguments; }(1, 2, 3)),
24851 func = _[methodName];
24853 QUnit.test('`_.' + methodName + '` should return the symmetric difference of the given arrays', function(assert) {
24856 var actual = func([1, 2, 5], [2, 3, 5], [3, 4, 5]);
24857 assert.deepEqual(actual, [1, 4, 5]);
24860 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
24863 var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
24864 assert.deepEqual(actual, [1, 4, 5]);
24866 actual = func([1, 1]);
24867 assert.deepEqual(actual, [1]);
24870 QUnit.test('`_.' + methodName + '` should return a new array when a single array is given', function(assert) {
24874 assert.notStrictEqual(func(array), array);
24877 QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
24881 assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
24884 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
24887 var array = [1, 2];
24888 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
24889 assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
24890 assert.deepEqual(func(array, null, args, null), [3]);
24893 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
24897 var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
24898 assert.ok(wrapped instanceof _);
24901 skipAssert(assert);
24905 QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
24909 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
24910 wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
24912 var actual = lodashStable.map(['head', 'last'], function(methodName) {
24913 return wrapped[methodName]();
24916 assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
24919 skipAssert(assert);
24924 /*--------------------------------------------------------------------------*/
24926 QUnit.module('lodash.xorBy');
24929 QUnit.test('should accept an `iteratee` argument', function(assert) {
24932 var actual = _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
24933 assert.deepEqual(actual, [1.2, 4.3]);
24935 actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
24936 assert.deepEqual(actual, [{ 'x': 2 }]);
24939 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
24944 _.xorBy([2.1, 1.2], [4.3, 2.4], function() {
24945 args || (args = slice.call(arguments));
24948 assert.deepEqual(args, [4.3]);
24952 /*--------------------------------------------------------------------------*/
24954 QUnit.module('lodash.xorWith');
24957 QUnit.test('should work with a `comparator` argument', function(assert) {
24960 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
24961 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
24962 actual = _.xorWith(objects, others, lodashStable.isEqual);
24964 assert.deepEqual(actual, [objects[1], others[0]]);
24968 /*--------------------------------------------------------------------------*/
24970 QUnit.module('zipObject methods');
24972 lodashStable.each(['zipObject', 'zipObjectDeep'], function(methodName) {
24973 var func = _[methodName],
24974 object = { 'barney': 36, 'fred': 40 },
24975 isDeep = methodName == 'zipObjectDeep';
24977 QUnit.test('`_.' + methodName + '` should zip together key/value arrays into an object', function(assert) {
24980 var actual = func(['barney', 'fred'], [36, 40]);
24981 assert.deepEqual(actual, object);
24984 QUnit.test('`_.' + methodName + '` should ignore extra `values`', function(assert) {
24987 assert.deepEqual(func(['a'], [1, 2]), { 'a': 1 });
24990 QUnit.test('`_.' + methodName + '` should assign `undefined` values for extra `keys`', function(assert) {
24993 assert.deepEqual(func(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
24996 QUnit.test('`_.' + methodName + '` should ' + (isDeep ? '' : 'not ') + 'support deep paths', function(assert) {
24999 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path, index) {
25000 var expected = isDeep ? ({ 'a': { 'b': { 'c': 1 } } }) : (index ? { 'a,b,c': 1 } : { 'a.b.c': 1 });
25001 assert.deepEqual(func([path], [1]), expected);
25005 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
25009 var values = lodashStable.range(LARGE_ARRAY_SIZE),
25010 props = lodashStable.map(values, function(value) { return 'key' + value; }),
25011 actual = _(props)[methodName](values).map(square).filter(isEven).take().value();
25013 assert.deepEqual(actual, _.take(_.filter(_.map(func(props, values), square), isEven)));
25016 skipAssert(assert);
25021 /*--------------------------------------------------------------------------*/
25023 QUnit.module('lodash.zipWith');
25026 QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
25029 var array1 = [1, 2, 3],
25030 array2 = [4, 5, 6],
25031 array3 = [7, 8, 9];
25033 var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
25037 assert.deepEqual(actual, [12, 15, 18]);
25039 var actual = _.zipWith(array1, [], function(a, b) {
25040 return a + (b || 0);
25043 assert.deepEqual(actual, [1, 2, 3]);
25046 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
25051 _.zipWith([1, 2], [3, 4], [5, 6], function() {
25052 args || (args = slice.call(arguments));
25055 assert.deepEqual(args, [1, 3, 5]);
25058 QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
25061 var array1 = [1, 2],
25063 values = [, null, undefined],
25064 expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
25066 var actual = lodashStable.map(values, function(value, index) {
25067 return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
25070 assert.deepEqual(actual, expected);
25074 /*--------------------------------------------------------------------------*/
25076 QUnit.module('lodash.unzip and lodash.zip');
25078 lodashStable.each(['unzip', 'zip'], function(methodName, index) {
25079 var func = _[methodName];
25080 func = lodashStable.bind(index ? func.apply : func.call, func, null);
25083 'an empty array': [
25092 [['barney', 'fred'], [36, 40]],
25093 [['barney', 36], ['fred', 40]]
25096 [['barney', 'fred'], [36, 40], [false, true]],
25097 [['barney', 36, false], ['fred', 40, true]]
25101 lodashStable.forOwn(object, function(pair, key) {
25102 QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
25105 var actual = func(pair[0]);
25106 assert.deepEqual(actual, pair[1]);
25107 assert.deepEqual(func(actual), actual.length ? pair[0] : []);
25111 QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
25115 [['barney', 36], ['fred', 40, false]],
25116 [['barney', 'fred'], [36, 40], [undefined, false]]
25119 var actual = func(pair[0]);
25120 assert.ok('0' in actual[2]);
25121 assert.deepEqual(actual, pair[1]);
25123 actual = func(actual);
25124 assert.ok('2' in actual[0]);
25125 assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
25128 QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
25131 var expected = lodashStable.map(falsey, alwaysEmptyArray);
25133 var actual = lodashStable.map(falsey, function(value) {
25134 return func([value, value, value]);
25137 assert.deepEqual(actual, expected);
25140 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
25143 var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
25144 assert.deepEqual(func(array), [[1, 3], [2, 4]]);
25147 QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
25150 var expected = [['barney', 'fred'], [36, 40]];
25151 assert.deepEqual(func(func(func(func(expected)))), expected);
25155 /*--------------------------------------------------------------------------*/
25157 QUnit.module('lodash(...).commit');
25160 QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
25165 wrapped = _(array).push(2).push(3);
25167 assert.deepEqual(array, [1]);
25169 var otherWrapper = wrapped.commit();
25170 assert.ok(otherWrapper instanceof _);
25171 assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
25172 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
25175 skipAssert(assert, 4);
25179 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
25183 var wrapped = _([1]).chain().commit().head();
25184 assert.ok(wrapped instanceof _);
25185 assert.strictEqual(wrapped.value(), 1);
25188 skipAssert(assert, 2);
25193 /*--------------------------------------------------------------------------*/
25195 QUnit.module('lodash(...).next');
25197 lodashStable.each([false, true], function(implict) {
25198 function chain(value) {
25199 return implict ? _(value) : _.chain(value);
25202 var chainType = 'in an ' + (implict ? 'implict' : 'explict') + ' chain';
25204 QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
25208 var wrapped = chain([1, 2]);
25210 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
25211 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
25212 assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
25215 skipAssert(assert, 3);
25219 QUnit.test('should act as an iterable ' + chainType, function(assert) {
25222 if (!isNpm && Symbol && Symbol.iterator) {
25223 var array = [1, 2],
25224 wrapped = chain(array);
25226 assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
25227 assert.deepEqual(_.toArray(wrapped), array);
25230 skipAssert(assert, 2);
25234 QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
25237 if (!isNpm && Array.from) {
25238 var hearts = '\ud83d\udc95',
25239 values = [[1], { 'a': 1 }, hearts];
25241 lodashStable.each(values, function(value) {
25242 var wrapped = chain(value);
25243 assert.deepEqual(Array.from(wrapped), _.toArray(value));
25247 skipAssert(assert, 3);
25251 QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
25254 if (!isNpm && Symbol && Symbol.iterator) {
25255 var array = [1, 2],
25256 wrapped = chain(array);
25258 assert.deepEqual(_.toArray(wrapped), array);
25259 assert.deepEqual(_.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
25261 var other = wrapped.filter();
25262 assert.deepEqual(_.toArray(other), array, 'reset for new chain segments');
25263 assert.deepEqual(_.toArray(wrapped), [], 'iterator is still exhausted');
25266 skipAssert(assert, 4);
25270 QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
25273 if (!isNpm && Symbol && Symbol.iterator) {
25274 var array = lodashStable.range(LARGE_ARRAY_SIZE),
25275 predicate = function(value) { values.push(value); return isEven(value); },
25277 wrapped = chain(array);
25279 assert.deepEqual(_.toArray(wrapped), array);
25281 wrapped = wrapped.filter(predicate);
25282 assert.deepEqual(_.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
25283 assert.deepEqual(values, array, 'memoizes iterator values');
25286 skipAssert(assert, 3);
25291 /*--------------------------------------------------------------------------*/
25293 QUnit.module('lodash(...).plant');
25296 QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
25300 var array1 = [5, null, 3, null, 1],
25301 array2 = [10, null, 8, null, 6],
25302 wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
25303 wrapped2 = wrapped1.plant(array2);
25305 assert.deepEqual(wrapped2.value(), [36, 64]);
25306 assert.deepEqual(wrapped1.value(), [1, 9]);
25309 skipAssert(assert, 2);
25313 QUnit.test('should clone `chainAll` settings', function(assert) {
25317 var array1 = [2, 4],
25319 wrapped1 = _(array1).chain().map(square),
25320 wrapped2 = wrapped1.plant(array2);
25322 assert.deepEqual(wrapped2.head().value(), 36);
25325 skipAssert(assert);
25329 QUnit.test('should reset iterator data on cloned sequences', function(assert) {
25332 if (!isNpm && Symbol && Symbol.iterator) {
25333 var array1 = [2, 4],
25335 wrapped1 = _(array1).map(square);
25337 assert.deepEqual(_.toArray(wrapped1), [4, 16]);
25338 assert.deepEqual(_.toArray(wrapped1), []);
25340 var wrapped2 = wrapped1.plant(array2);
25341 assert.deepEqual(_.toArray(wrapped2), [36, 64]);
25344 skipAssert(assert, 3);
25349 /*--------------------------------------------------------------------------*/
25351 QUnit.module('lodash(...).pop');
25354 QUnit.test('should remove elements from the end of `array`', function(assert) {
25358 var array = [1, 2],
25359 wrapped = _(array);
25361 assert.strictEqual(wrapped.pop(), 2);
25362 assert.deepEqual(wrapped.value(), [1]);
25363 assert.strictEqual(wrapped.pop(), 1);
25365 var actual = wrapped.value();
25366 assert.deepEqual(actual, []);
25367 assert.strictEqual(actual, array);
25370 skipAssert(assert, 5);
25374 QUnit.test('should accept falsey arguments', function(assert) {
25378 var expected = lodashStable.map(falsey, alwaysTrue);
25380 var actual = lodashStable.map(falsey, function(value, index) {
25382 var result = index ? _(value).pop() : _().pop();
25383 return result === undefined;
25387 assert.deepEqual(actual, expected);
25390 skipAssert(assert);
25395 /*--------------------------------------------------------------------------*/
25397 QUnit.module('lodash(...).push');
25400 QUnit.test('should append elements to `array`', function(assert) {
25405 wrapped = _(array).push(2, 3),
25406 actual = wrapped.value();
25408 assert.strictEqual(actual, array);
25409 assert.deepEqual(actual, [1, 2, 3]);
25412 skipAssert(assert, 2);
25416 QUnit.test('should accept falsey arguments', function(assert) {
25420 var expected = lodashStable.map(falsey, alwaysTrue);
25422 var actual = lodashStable.map(falsey, function(value, index) {
25424 var result = index ? _(value).push(1).value() : _().push(1).value();
25425 return lodashStable.eq(result, value);
25429 assert.deepEqual(actual, expected);
25432 skipAssert(assert);
25437 /*--------------------------------------------------------------------------*/
25439 QUnit.module('lodash(...).shift');
25442 QUnit.test('should remove elements from the front of `array`', function(assert) {
25446 var array = [1, 2],
25447 wrapped = _(array);
25449 assert.strictEqual(wrapped.shift(), 1);
25450 assert.deepEqual(wrapped.value(), [2]);
25451 assert.strictEqual(wrapped.shift(), 2);
25453 var actual = wrapped.value();
25454 assert.deepEqual(actual, []);
25455 assert.strictEqual(actual, array);
25458 skipAssert(assert, 5);
25462 QUnit.test('should accept falsey arguments', function(assert) {
25466 var expected = lodashStable.map(falsey, alwaysTrue);
25468 var actual = lodashStable.map(falsey, function(value, index) {
25470 var result = index ? _(value).shift() : _().shift();
25471 return result === undefined;
25475 assert.deepEqual(actual, expected);
25478 skipAssert(assert);
25483 /*--------------------------------------------------------------------------*/
25485 QUnit.module('lodash(...).sort');
25488 QUnit.test('should return the wrapped sorted `array`', function(assert) {
25492 var array = [3, 1, 2],
25493 wrapped = _(array).sort(),
25494 actual = wrapped.value();
25496 assert.strictEqual(actual, array);
25497 assert.deepEqual(actual, [1, 2, 3]);
25500 skipAssert(assert, 2);
25504 QUnit.test('should accept falsey arguments', function(assert) {
25508 var expected = lodashStable.map(falsey, alwaysTrue);
25510 var actual = lodashStable.map(falsey, function(value, index) {
25512 var result = index ? _(value).sort().value() : _().sort().value();
25513 return lodashStable.eq(result, value);
25517 assert.deepEqual(actual, expected);
25520 skipAssert(assert);
25525 /*--------------------------------------------------------------------------*/
25527 QUnit.module('lodash(...).splice');
25530 QUnit.test('should support removing and inserting elements', function(assert) {
25534 var array = [1, 2],
25535 wrapped = _(array);
25537 assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
25538 assert.deepEqual(wrapped.value(), [1, 3]);
25539 assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
25541 var actual = wrapped.value();
25542 assert.deepEqual(actual, []);
25543 assert.strictEqual(actual, array);
25546 skipAssert(assert, 5);
25550 QUnit.test('should accept falsey arguments', function(assert) {
25554 var expected = lodashStable.map(falsey, alwaysTrue);
25556 var actual = lodashStable.map(falsey, function(value, index) {
25558 var result = index ? _(value).splice(0, 1).value() : _().splice(0, 1).value();
25559 return lodashStable.isEqual(result, []);
25563 assert.deepEqual(actual, expected);
25566 skipAssert(assert);
25571 /*--------------------------------------------------------------------------*/
25573 QUnit.module('lodash(...).unshift');
25576 QUnit.test('should prepend elements to `array`', function(assert) {
25581 wrapped = _(array).unshift(1, 2),
25582 actual = wrapped.value();
25584 assert.strictEqual(actual, array);
25585 assert.deepEqual(actual, [1, 2, 3]);
25588 skipAssert(assert, 2);
25592 QUnit.test('should accept falsey arguments', function(assert) {
25596 var expected = lodashStable.map(falsey, alwaysTrue);
25598 var actual = lodashStable.map(falsey, function(value, index) {
25600 var result = index ? _(value).unshift(1).value() : _().unshift(1).value();
25601 return lodashStable.eq(result, value);
25605 assert.deepEqual(actual, expected);
25608 skipAssert(assert);
25613 /*--------------------------------------------------------------------------*/
25615 QUnit.module('lodash(...).value');
25618 QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
25623 wrapped = _(array).push(2).push(3);
25625 assert.deepEqual(array, [1]);
25626 assert.deepEqual(wrapped.value(), [1, 2, 3]);
25627 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
25628 assert.deepEqual(array, [1, 2, 3, 2, 3]);
25631 skipAssert(assert, 4);
25635 QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
25639 var wrapped = _(123);
25640 assert.strictEqual(Number(wrapped), 123);
25643 skipAssert(assert);
25647 QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
25650 if (!isNpm && JSON) {
25651 var wrapped = _([1, 2, 3]);
25652 assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
25655 skipAssert(assert);
25659 QUnit.test('should be aliased', function(assert) {
25663 var expected = _.prototype.value;
25664 assert.strictEqual(_.prototype.toJSON, expected);
25665 assert.strictEqual(_.prototype.valueOf, expected);
25668 skipAssert(assert, 2);
25673 /*--------------------------------------------------------------------------*/
25675 QUnit.module('lodash(...) methods that return the wrapped modified array');
25685 lodashStable.each(funcs, function(methodName) {
25686 QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
25690 var array = [1, 2, 3],
25691 wrapped = _(array),
25692 actual = wrapped[methodName]();
25694 assert.ok(actual instanceof _);
25695 assert.notStrictEqual(actual, wrapped);
25698 skipAssert(assert, 2);
25704 /*--------------------------------------------------------------------------*/
25706 QUnit.module('lodash(...) methods that return new wrapped values');
25717 'intersectionWith',
25739 lodashStable.each(funcs, function(methodName) {
25740 QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
25744 var value = methodName == 'split' ? 'abc' : [1, 2, 3],
25745 wrapped = _(value),
25746 actual = wrapped[methodName]();
25748 assert.ok(actual instanceof _);
25749 assert.notStrictEqual(actual, wrapped);
25752 skipAssert(assert, 2);
25758 /*--------------------------------------------------------------------------*/
25760 QUnit.module('lodash(...) methods that return unwrapped values');
25857 lodashStable.each(funcs, function(methodName) {
25858 QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
25862 var actual = _()[methodName]();
25863 assert.notOk(actual instanceof _);
25866 skipAssert(assert);
25870 QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
25874 var actual = _().chain()[methodName]();
25875 assert.ok(actual instanceof _);
25878 skipAssert(assert);
25884 /*--------------------------------------------------------------------------*/
25886 QUnit.module('"Arrays" category methods');
25889 var args = (function() { return arguments; }(1, null, [3], null, 5)),
25890 sortedArgs = (function() { return arguments; }(1, [3], 5, null, null)),
25891 array = [1, 2, 3, 4, 5, 6];
25893 QUnit.test('should work with `arguments` objects', function(assert) {
25896 function message(methodName) {
25897 return '`_.' + methodName + '` should work with `arguments` objects';
25900 assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
25901 assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
25903 assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
25904 assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
25906 assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
25907 assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
25908 assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
25909 assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
25910 assert.deepEqual(_.dropWhile(args,identity), [null, [3], null, 5], message('dropWhile'));
25911 assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
25912 assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
25913 assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
25914 assert.deepEqual(_.head(args), 1, message('head'));
25915 assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
25916 assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
25917 assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
25918 assert.deepEqual(_.last(args), 5, message('last'));
25919 assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
25920 assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
25921 assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
25922 assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
25923 assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
25924 assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
25925 assert.deepEqual(_.take(args, 2), [1, null], message('take'));
25926 assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
25927 assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
25928 assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
25929 assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
25930 assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
25931 assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
25934 QUnit.test('should accept falsey primary arguments', function(assert) {
25937 function message(methodName) {
25938 return '`_.' + methodName + '` should accept falsey primary arguments';
25941 assert.deepEqual(_.difference(null, array), [], message('difference'));
25942 assert.deepEqual(_.intersection(null, array), [], message('intersection'));
25943 assert.deepEqual(_.union(null, array), array, message('union'));
25944 assert.deepEqual(_.xor(null, array), array, message('xor'));
25947 QUnit.test('should accept falsey secondary arguments', function(assert) {
25950 function message(methodName) {
25951 return '`_.' + methodName + '` should accept falsey secondary arguments';
25954 assert.deepEqual(_.difference(array, null), array, message('difference'));
25955 assert.deepEqual(_.intersection(array, null), [], message('intersection'));
25956 assert.deepEqual(_.union(array, null), array, message('union'));
25960 /*--------------------------------------------------------------------------*/
25962 QUnit.module('"Strings" category methods');
25965 var stringMethods = [
25988 lodashStable.each(stringMethods, function(methodName) {
25989 var func = _[methodName];
25991 QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
25994 var values = [, null, undefined, ''],
25995 expected = lodashStable.map(values, alwaysEmptyString);
25997 var actual = lodashStable.map(values, function(value, index) {
25998 return index ? func(value) : func();
26001 assert.deepEqual(actual, expected);
26006 /*--------------------------------------------------------------------------*/
26008 QUnit.module('lodash methods');
26011 var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
26012 return lodashStable.startsWith(methodName, '_');
26053 var rejectFalsey = [
26056 ].concat(checkFuncs);
26058 var returnArrays = [
26096 var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
26098 QUnit.test('should accept falsey arguments', function(assert) {
26099 assert.expect(308);
26101 var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
26103 lodashStable.each(acceptFalsey, function(methodName) {
26104 var expected = emptyArrays,
26105 func = _[methodName],
26108 var actual = lodashStable.map(falsey, function(value, index) {
26110 return index ? func(value) : func();
26116 if (methodName == 'noConflict') {
26119 else if (methodName == 'pull' || methodName == 'pullAll') {
26122 if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
26123 assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
26125 assert.ok(pass, '`_.' + methodName + '` accepts falsey arguments');
26128 // Skip tests for missing methods of modularized builds.
26129 lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
26130 if (!_[methodName]) {
26131 skipAssert(assert);
26136 QUnit.test('should return an array', function(assert) {
26139 var array = [1, 2, 3];
26141 lodashStable.each(returnArrays, function(methodName) {
26143 func = _[methodName];
26145 switch (methodName) {
26147 actual = func(array, 'toFixed');
26150 actual = func(array, 1);
26153 actual = func(array);
26155 assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
26157 var isPull = methodName == 'pull' || methodName == 'pullAll';
26158 assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the given array');
26162 QUnit.test('should throw an error for falsey arguments', function(assert) {
26165 lodashStable.each(rejectFalsey, function(methodName) {
26166 var expected = lodashStable.map(falsey, alwaysTrue),
26167 func = _[methodName];
26169 var actual = lodashStable.map(falsey, function(value, index) {
26170 var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
26173 index ? func(value) : func();
26175 pass = !pass && (e instanceof TypeError) &&
26176 (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
26181 assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
26185 QUnit.test('should not set a `this` binding', function(assert) {
26188 lodashStable.each(noBinding, function(methodName) {
26189 var fn = function() { return this.a; },
26190 func = _[methodName],
26191 isNegate = methodName == 'negate',
26192 object = { 'a': 1 },
26193 expected = isNegate ? false : 1;
26195 var wrapper = func(_.bind(fn, object));
26196 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
26198 wrapper = _.bind(func(fn), object);
26199 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
26201 object.wrapper = func(fn);
26202 assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
26206 QUnit.test('should not contain minified method names (test production builds)', function(assert) {
26209 var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
26210 assert.ok(lodashStable.every(_.functions(_), function(methodName) {
26211 return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
26216 /*--------------------------------------------------------------------------*/
26218 QUnit.config.asyncRetries = 10;
26219 QUnit.config.hidepassed = true;
26222 QUnit.config.noglobals = true;