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 /** Stub functions. */
87 var stubA = function() { return 'a'; },
88 stubB = function() { return 'b'; },
89 stubC = function() { return 'c'; };
91 var stubTrue = function() { return true; },
92 stubFalse = function() { return false; };
94 var stubNaN = function() { return NaN; },
95 stubNull = function() { return null; };
97 var stubZero = function() { return 0; },
98 stubOne = function() { return 1; },
99 stubTwo = function() { return 2; },
100 stubThree = function() { return 3; },
101 stubFour = function() { return 4; };
103 var stubArray = function() { return []; },
104 stubObject = function() { return {}; },
105 stubString = 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) || 'default' in require(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 // Assign `setTimeout` to itself to avoid being flagged as a leak.
237 setProperty(root, 'setTimeout', setTimeout);
239 // Exit early if going to run tests in a PhantomJS web page.
240 if (phantom && isModularize) {
241 var page = require('webpage').create();
243 page.onCallback = function(details) {
244 var coverage = details.coverage;
246 var fs = require('fs'),
247 cwd = fs.workingDirectory,
250 fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
252 phantom.exit(details.failed ? 1 : 0);
255 page.onConsoleMessage = function(message) {
256 console.log(message);
259 page.onInitialized = function() {
260 page.evaluate(function() {
261 document.addEventListener('DOMContentLoaded', function() {
262 QUnit.done(function(details) {
263 details.coverage = window.__coverage__;
264 callPhantom(details);
270 page.open(filePath, function(status) {
271 if (status != 'success') {
272 console.log('PhantomJS failed to load page: ' + filePath);
277 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
281 /*--------------------------------------------------------------------------*/
283 /** Used to test Web Workers. */
284 var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
285 (document && document.origin != 'null') && root.Worker;
287 /** Used to test host objects in IE. */
289 var xml = new ActiveXObject('Microsoft.XMLDOM');
292 /** Poison the free variable `root` in Node.js */
294 defineProperty(global.root, 'root', {
295 'configurable': false,
297 'get': function() { throw new ReferenceError; }
301 /** Load QUnit and extras. */
302 var QUnit = root.QUnit || require('qunit-extras');
304 /** Load stable Lodash. */
305 var lodashStable = root.lodashStable;
308 lodashStable = interopRequire('../node_modules/lodash/lodash.js');
310 console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
313 lodashStable = lodashStable.noConflict();
316 /** The `lodash` function to test. */
317 var _ = root._ || (root._ = interopRequire(filePath));
319 /** Used to test pseudo private map caches. */
320 var mapCaches = (function() {
321 var MapCache = _.memoize.Cache;
323 'Hash': new MapCache().__data__.hash.constructor,
326 _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
327 var stack = lodashStable.last(arguments);
328 result.ListCache = stack.__data__.constructor;
329 result.Stack = stack.constructor;
334 /** Used to detect instrumented istanbul code coverage runs. */
335 var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) {
336 return /^(?:\$\$cov_\d+\$\$)$/.test(key);
339 /** Used to test generator functions. */
340 var generator = lodashStable.attempt(function() {
341 return Function('return function*(){}');
344 /** Used to restore the `_` reference. */
345 var oldDash = root._;
348 * Used to check for problems removing whitespace. For a whitespace reference,
349 * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
351 var whitespace = lodashStable.filter([
352 // Basic whitespace characters.
353 ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
356 '\n', '\r', '\u2028', '\u2029',
358 // Unicode category "Zs" space separators.
359 '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
360 '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
362 function(chr) { return /\s/.exec(chr); })
366 * Creates a custom error object.
370 * @param {string} message The error message.
372 function CustomError(message) {
373 this.name = 'CustomError';
374 this.message = message;
377 CustomError.prototype = lodashStable.create(Error.prototype, {
378 'constructor': CustomError
382 * Removes all own enumerable string keyed properties from a given object.
385 * @param {Object} object The object to empty.
387 function emptyObject(object) {
388 lodashStable.forOwn(object, function(value, key, object) {
394 * Extracts the unwrapped value from its wrapper.
397 * @param {Object} wrapper The wrapper to unwrap.
398 * @returns {*} Returns the unwrapped value.
400 function getUnwrappedValue(wrapper) {
402 actions = wrapper.__actions__,
403 length = actions.length,
404 result = wrapper.__wrapped__;
406 while (++index < length) {
408 action = actions[index];
410 push.apply(args, action.args);
411 result = action.func.apply(action.thisArg, args);
417 * Loads the module of `id`. If the module has an `exports.default`, the
418 * exported default value is returned as the resolved module.
421 * @param {string} id The identifier of the module to resolve.
422 * @returns {*} Returns the resolved module.
424 function interopRequire(id) {
425 var result = require(id);
426 return 'default' in result ? result['default'] : result;
430 * Sets a non-enumerable property value on `object`.
432 * Note: This function is used to avoid a bug in older versions of V8 where
433 * overwriting non-enumerable built-ins makes them enumerable.
434 * See https://code.google.com/p/v8/issues/detail?id=1623
437 * @param {Object} object The object modify.
438 * @param {string} key The name of the property to set.
439 * @param {*} value The property value.
441 function setProperty(object, key, value) {
443 defineProperty(object, key, {
444 'configurable': true,
456 * Skips a given number of tests with a passing result.
459 * @param {Object} assert The QUnit assert object.
460 * @param {number} [count=1] The number of tests to skip.
462 function skipAssert(assert, count) {
463 count || (count = 1);
465 assert.ok(true, 'test skipped');
469 /*--------------------------------------------------------------------------*/
471 // Add bizarro values.
473 if (document || (typeof require != 'function')) {
476 var nativeString = fnToString.call(toString),
477 reToString = /toString/g;
479 function createToString(funcName) {
480 return lodashStable.constant(nativeString.replace(reToString, funcName));
483 // Allow bypassing native checks.
484 setProperty(funcProto, 'toString', function wrapper() {
485 setProperty(funcProto, 'toString', fnToString);
486 var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
487 setProperty(funcProto, 'toString', wrapper);
491 // Add prototype extensions.
492 funcProto._method = noop;
495 setProperty(Object, 'create', (function() {
497 return function(prototype) {
498 if (lodashStable.isObject(prototype)) {
499 object.prototype = prototype;
500 var result = new object;
501 object.prototype = undefined;
507 setProperty(Object, 'getOwnPropertySymbols', undefined);
509 var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
510 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
511 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
515 defineProperty(root, 'Buffer', {
516 'configurable': true,
518 'get': function get() {
519 var caller = get.caller,
520 name = caller ? caller.name : '';
522 if (!(name == 'runInContext' || name.length == 1 || /\b_\.isBuffer\b/.test(caller))) {
529 setProperty(root, 'Map', (function() {
535 setProperty(root, 'Map', Map);
540 setProperty(root.Map, 'toString', createToString('Map'));
542 setProperty(root, 'Promise', noop);
543 setProperty(root, 'Set', noop);
544 setProperty(root, 'Symbol', undefined);
545 setProperty(root, 'WeakMap', noop);
547 // Fake `WinRTError`.
548 setProperty(root, 'WinRTError', Error);
550 // Clear cache so lodash can be reloaded.
551 emptyObject(require.cache);
553 // Load lodash and expose it to the bad extensions/shims.
554 lodashBizarro = interopRequire(filePath);
557 // Restore built-in methods.
558 setProperty(Object, 'create', create);
559 setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
560 setProperty(root, 'Buffer', Buffer);
563 Object.getOwnPropertySymbols = getSymbols;
565 delete Object.getOwnPropertySymbols;
568 setProperty(root, 'Map', Map);
573 setProperty(root, 'Promise', Promise);
578 setProperty(root, 'Set', Set);
583 setProperty(root, 'Symbol', Symbol);
588 setProperty(root, 'WeakMap', WeakMap);
592 delete root.WinRTError;
593 delete funcProto._method;
596 // Add other realm values from the `vm` module.
597 lodashStable.attempt(function() {
598 lodashStable.assign(realm, require('vm').runInNewContext([
600 ' var noop = function() {},',
604 " 'ArrayBuffer': root.ArrayBuffer,",
605 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
607 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
608 " 'boolean': Object(false),",
609 " 'date': new Date,",
610 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
611 " 'function': noop,",
612 " 'map': root.Map ? new root.Map : undefined,",
615 " 'number': Object(0),",
616 " 'object': { 'a': 1 },",
617 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
619 " 'set': root.Set ? new root.Set : undefined,",
620 " 'string': Object('a'),",
621 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
622 " 'undefined': undefined,",
623 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
624 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
627 " ['" + arrayViews.join("', '") + "'].forEach(function(type) {",
628 ' var Ctor = root[type]',
629 ' object[type] = Ctor;',
630 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
638 // Add other realm values from an iframe.
639 lodashStable.attempt(function() {
642 var iframe = document.createElement('iframe');
643 iframe.frameBorder = iframe.height = iframe.width = 0;
644 body.appendChild(iframe);
646 var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
651 ' var noop = function() {},',
655 " 'ArrayBuffer': root.ArrayBuffer,",
656 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
658 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
659 " 'boolean': Object(false),",
660 " 'date': new Date,",
661 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
662 " 'function': noop,",
663 " 'map': root.Map ? new root.Map : undefined,",
666 " 'number': Object(0),",
667 " 'object': { 'a': 1 },",
668 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
670 " 'set': root.Set ? new root.Set : undefined,",
671 " 'string': Object('a'),",
672 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
673 " 'undefined': undefined,",
674 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
675 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
678 "_.each(['" + arrayViews.join("', '") + "'], function(type) {",
679 ' var Ctor = root[type];',
680 ' object[type] = Ctor;',
681 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
684 '_.assign(_._realm, object);',
693 lodashStable.attempt(function() {
694 var worker = new Worker('./asset/worker.js?t=' + (+new Date));
695 worker.addEventListener('message', function(e) {
696 _._VERSION = e.data || '';
699 worker.postMessage(ui.buildPath);
702 // Expose internal modules for better code coverage.
703 lodashStable.attempt(function() {
704 var path = require('path'),
705 basePath = path.dirname(filePath);
707 if (isModularize && !(amd || isNpm)) {
712 ], function(funcName) {
713 _['_' + funcName] = interopRequire(path.join(basePath, '_' + funcName));
718 /*--------------------------------------------------------------------------*/
721 console.log('Running lodash tests.');
722 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
725 QUnit.module(basename);
728 QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
732 assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
739 QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
742 if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
743 assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
749 QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
753 assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
760 QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
763 var done = assert.async();
766 var limit = 30000 / QUnit.config.asyncRetries,
769 var attempt = function() {
770 var actual = _._VERSION;
771 if ((new Date - start) < limit && typeof actual != 'string') {
772 setTimeout(attempt, 16);
775 assert.strictEqual(actual, _.VERSION);
787 QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
791 assert.notOk('_method' in lodashBizarro);
798 QUnit.test('should avoid non-native built-ins', function(assert) {
801 function message(lodashMethod, nativeMethod) {
802 return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
810 var object = { 'a': 1 },
811 otherObject = { 'b': 2 },
812 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
816 var actual = lodashBizarro.keysIn(new Foo).sort();
820 var label = message('_.keysIn', 'Object#propertyIsEnumerable');
821 assert.deepEqual(actual, ['a', 'b'], label);
824 var actual = lodashBizarro.isEmpty({});
828 var label = message('_.isEmpty', 'Object#propertyIsEnumerable');
829 assert.strictEqual(actual, true, label);
833 lodashBizarro.difference([object, otherObject], largeArray),
834 lodashBizarro.intersection(largeArray, [object]),
835 lodashBizarro.uniq(largeArray)
840 label = message('_.difference`, `_.intersection`, and `_.uniq', 'Object.create` and `Map');
841 assert.deepEqual(actual, [[otherObject], [object], [object]], label);
848 lodashBizarro.clone(object),
849 lodashBizarro.cloneDeep(object)
854 label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
855 assert.deepEqual(actual, [object, object], label);
858 var symObject = Object(symbol);
860 // Avoid symbol detection in Babel's `typeof` helper.
861 symObject.constructor = Object;
864 Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
865 Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
866 Symbol ? lodashBizarro.toString(symObject) : ''
871 label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
872 assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
875 var map = new lodashBizarro.memoize.Cache;
876 actual = map.set('a', 1).get('a');
880 label = message('_.memoize.Cache', 'Map');
881 assert.deepEqual(actual, 1, label);
884 map = new (Map || Object);
885 if (Symbol && Symbol.iterator) {
886 map[Symbol.iterator] = null;
888 actual = lodashBizarro.toArray(map);
892 label = message('_.toArray', 'Map');
893 assert.deepEqual(actual, [], label);
896 skipAssert(assert, 7);
901 /*--------------------------------------------------------------------------*/
903 QUnit.module('isIndex');
906 var func = _._isIndex;
908 QUnit.test('should return `true` for indexes', function(assert) {
912 var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
913 expected = lodashStable.map(values, stubTrue);
915 var actual = lodashStable.map(values, function(args) {
916 return func.apply(undefined, args);
919 assert.deepEqual(actual, expected);
926 QUnit.test('should return `false` for non-indexes', function(assert) {
930 var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
931 expected = lodashStable.map(values, stubFalse);
933 var actual = lodashStable.map(values, function(args) {
934 return func.apply(undefined, args);
937 assert.deepEqual(actual, expected);
945 /*--------------------------------------------------------------------------*/
947 QUnit.module('isIterateeCall');
951 func = _._isIterateeCall,
954 QUnit.test('should return `true` for iteratee calls', function(assert) {
961 assert.strictEqual(func(1, 0, array), true);
962 assert.strictEqual(func(1, 'a', object), true);
963 assert.strictEqual(func(1, 'a', new Foo), true);
966 skipAssert(assert, 3);
970 QUnit.test('should return `false` for non-iteratee calls', function(assert) {
974 assert.strictEqual(func(2, 0, array), false);
975 assert.strictEqual(func(1, 1.1, array), false);
976 assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
977 assert.strictEqual(func(1, 'b', object), false);
980 skipAssert(assert, 4);
984 QUnit.test('should work with `NaN` values', function(assert) {
988 assert.strictEqual(func(NaN, 0, [NaN]), true);
989 assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
992 skipAssert(assert, 2);
996 QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
1001 var actual = func(1, { 'toString': null }, [1]);
1003 var message = e.message;
1005 assert.strictEqual(actual, false, message || '');
1013 /*--------------------------------------------------------------------------*/
1015 QUnit.module('map caches');
1018 var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop];
1020 var pairs = lodashStable.map(keys, function(key, index) {
1021 var lastIndex = keys.length - 1;
1022 return [key, keys[lastIndex - index]];
1025 var largeStack = new mapCaches.Stack(pairs);
1027 lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
1028 largeStack.set({}, {});
1032 'hashes': new mapCaches.Hash(pairs),
1033 'list caches': new mapCaches.ListCache(pairs),
1034 'map caches': new mapCaches.MapCache(pairs),
1035 'stack caches': new mapCaches.Stack(pairs),
1036 'large stacks': largeStack
1039 lodashStable.forOwn(caches, function(cache, key) {
1040 QUnit.test('should implement a `Map` interface for ' + key, function(assert) {
1043 lodashStable.each(keys, function(key, index) {
1044 var value = pairs[index][1];
1046 assert.deepEqual(cache.get(key), value);
1047 assert.strictEqual(cache.has(key), true);
1048 assert.strictEqual(cache['delete'](key), true);
1049 assert.strictEqual(cache.has(key), false);
1050 assert.strictEqual(cache.get(key), undefined);
1051 assert.strictEqual(cache['delete'](key), false);
1052 assert.strictEqual(cache.set(key, value), cache);
1053 assert.strictEqual(cache.has(key), true);
1056 assert.strictEqual(cache.clear(), undefined);
1057 assert.ok(lodashStable.every(keys, function(key) {
1058 return !cache.has(key);
1064 /*--------------------------------------------------------------------------*/
1066 QUnit.module('lodash constructor');
1069 var values = empties.concat(true, 1, 'a'),
1070 expected = lodashStable.map(values, stubTrue);
1072 QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
1076 var actual = lodashStable.map(values, function(value) {
1077 return _(value) instanceof _;
1080 assert.deepEqual(actual, expected);
1087 QUnit.test('should return the given `lodash` instances', function(assert) {
1091 var actual = lodashStable.map(values, function(value) {
1092 var wrapped = _(value);
1093 return _(wrapped) === wrapped;
1096 assert.deepEqual(actual, expected);
1103 QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
1106 if (!isNpm && lodashBizarro) {
1107 var actual = lodashStable.map(values, function(value) {
1108 var wrapped = _(lodashBizarro(value)),
1109 unwrapped = wrapped.value();
1111 return wrapped instanceof _ &&
1112 ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
1115 assert.deepEqual(actual, expected);
1123 /*--------------------------------------------------------------------------*/
1125 QUnit.module('lodash.add');
1128 QUnit.test('should add two numbers', function(assert) {
1131 assert.strictEqual(_.add(6, 4), 10);
1132 assert.strictEqual(_.add(-6, 4), -2);
1133 assert.strictEqual(_.add(-6, -4), -10);
1136 QUnit.test('should not coerce arguments to numbers', function(assert) {
1139 assert.strictEqual(_.add('6', '4'), '64');
1140 assert.strictEqual(_.add('x', 'y'), 'xy');
1144 /*--------------------------------------------------------------------------*/
1146 QUnit.module('lodash.after');
1149 function after(n, times) {
1151 lodashStable.times(times, _.after(n, function() { count++; }));
1155 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1158 assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
1159 assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
1160 assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
1161 assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
1164 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1167 assert.strictEqual(after(NaN, 1), 1);
1170 QUnit.test('should not set a `this` binding', function(assert) {
1173 var after = _.after(1, function(assert) { return ++this.count; }),
1174 object = { 'after': after, 'count': 0 };
1177 assert.strictEqual(object.after(), 2);
1178 assert.strictEqual(object.count, 2);
1182 /*--------------------------------------------------------------------------*/
1184 QUnit.module('lodash.ary');
1187 function fn(a, b, c) {
1188 return slice.call(arguments);
1191 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
1194 var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
1195 assert.deepEqual(actual, [6, 8, 10]);
1197 var capped = _.ary(fn, 2);
1198 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
1201 QUnit.test('should use `func.length` if `n` is not given', function(assert) {
1204 var capped = _.ary(fn);
1205 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
1208 QUnit.test('should treat a negative `n` as `0`', function(assert) {
1211 var capped = _.ary(fn, -1);
1214 var actual = capped('a');
1217 assert.deepEqual(actual, []);
1220 QUnit.test('should coerce `n` to an integer', function(assert) {
1223 var values = ['1', 1.6, 'xyz'],
1224 expected = [['a'], ['a'], []];
1226 var actual = lodashStable.map(values, function(n) {
1227 var capped = _.ary(fn, n);
1228 return capped('a', 'b');
1231 assert.deepEqual(actual, expected);
1234 QUnit.test('should work when given less than the capped number of arguments', function(assert) {
1237 var capped = _.ary(fn, 3);
1238 assert.deepEqual(capped('a'), ['a']);
1241 QUnit.test('should use the existing `ary` if smaller', function(assert) {
1244 var capped = _.ary(_.ary(fn, 1), 2);
1245 assert.deepEqual(capped('a', 'b', 'c'), ['a']);
1248 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
1251 var funcs = lodashStable.map([fn], _.ary),
1252 actual = funcs[0]('a', 'b', 'c');
1254 assert.deepEqual(actual, ['a', 'b', 'c']);
1257 QUnit.test('should work when combined with other methods that use metadata', function(assert) {
1260 var array = ['a', 'b', 'c'],
1261 includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
1263 assert.strictEqual(includes('b')(array, 2), true);
1266 includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
1267 assert.strictEqual(includes('b')(array, 2), true);
1275 /*--------------------------------------------------------------------------*/
1277 QUnit.module('lodash.assignIn');
1280 QUnit.test('should be aliased', function(assert) {
1283 assert.strictEqual(_.extend, _.assignIn);
1287 /*--------------------------------------------------------------------------*/
1289 QUnit.module('lodash.assign and lodash.assignIn');
1291 lodashStable.each(['assign', 'assignIn'], function(methodName) {
1292 var func = _[methodName];
1294 QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
1297 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
1300 QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
1303 var expected = { 'a': 1, 'b': 2, 'c': 3 };
1304 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
1305 assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
1308 QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
1311 var expected = { 'a': 3, 'b': 2, 'c': 1 };
1312 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1315 QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
1318 var expected = { 'a': null, 'b': undefined, 'c': null };
1319 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1322 QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
1328 'configurable': true,
1330 'set': function() { throw new Error; }
1338 'constructor': Object,
1339 'toString': lodashStable.constant('source')
1342 defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
1346 defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
1350 defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
1354 defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
1355 'get': lodashStable.constant(Object)
1359 var actual = func(object, source);
1362 assert.deepEqual(actual, source);
1365 QUnit.test('`_.' + methodName + '` should treat sparse array sources as dense', function(assert) {
1371 assert.deepEqual(func({}, array), { '0': 1, '1': undefined, '2': 3 });
1374 QUnit.test('`_.' + methodName + '` should assign values of prototype objects', function(assert) {
1378 Foo.prototype.a = 1;
1380 assert.deepEqual(func({}, Foo.prototype), { 'a': 1 });
1383 QUnit.test('`_.' + methodName + '` should coerce string sources to objects', function(assert) {
1386 assert.deepEqual(func({}, 'a'), { '0': 'a' });
1390 /*--------------------------------------------------------------------------*/
1392 QUnit.module('lodash.assignInWith');
1395 QUnit.test('should be aliased', function(assert) {
1398 assert.strictEqual(_.extendWith, _.assignInWith);
1402 /*--------------------------------------------------------------------------*/
1404 QUnit.module('lodash.assignWith and lodash.assignInWith');
1406 lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
1407 var func = _[methodName];
1409 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
1412 var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
1413 return a === undefined ? b : a;
1416 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
1419 QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
1422 var expected = { 'a': undefined };
1423 assert.deepEqual(func({}, expected, noop), expected);
1427 /*--------------------------------------------------------------------------*/
1429 QUnit.module('lodash.at');
1432 var args = arguments,
1433 array = ['a', 'b', 'c'],
1434 object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
1436 QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
1439 var actual = _.at(array, [0, 2]);
1440 assert.deepEqual(actual, ['a', 'c']);
1443 QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
1446 var actual = _.at(array, [2, 4, 0]);
1447 assert.deepEqual(actual, ['c', undefined, 'a']);
1450 QUnit.test('should work with non-index keys on array values', function(assert) {
1453 var values = lodashStable.reject(empties, function(value) {
1454 return (value === 0) || lodashStable.isArray(value);
1457 var array = lodashStable.transform(values, function(result, value) {
1461 var expected = lodashStable.map(values, stubOne),
1462 actual = _.at(array, values);
1464 assert.deepEqual(actual, expected);
1467 QUnit.test('should return an empty array when no keys are given', function(assert) {
1470 assert.deepEqual(_.at(array), []);
1471 assert.deepEqual(_.at(array, [], []), []);
1474 QUnit.test('should accept multiple key arguments', function(assert) {
1477 var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
1478 assert.deepEqual(actual, ['d', 'a', 'c']);
1481 QUnit.test('should work with a falsey `object` argument when keys are given', function(assert) {
1484 var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
1486 var actual = lodashStable.map(falsey, function(object) {
1488 return _.at(object, 0, 1, 'pop', 'push');
1492 assert.deepEqual(actual, expected);
1495 QUnit.test('should work with an `arguments` object for `object`', function(assert) {
1498 var actual = _.at(args, [2, 0]);
1499 assert.deepEqual(actual, [3, 1]);
1502 QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
1505 var actual = _.at([1, 2, 3, 4, 5], args);
1506 assert.deepEqual(actual, [2, 3, 4]);
1509 QUnit.test('should work with an object for `object`', function(assert) {
1512 var actual = _.at(object, ['a[0].b.c', 'a[1]']);
1513 assert.deepEqual(actual, [3, 4]);
1516 QUnit.test('should pluck inherited property values', function(assert) {
1522 Foo.prototype.b = 2;
1524 var actual = _.at(new Foo, 'b');
1525 assert.deepEqual(actual, [2]);
1528 QUnit.test('should work in a lazy sequence', function(assert) {
1532 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
1535 lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
1536 lodashStable.times(2, function(index) {
1537 var array = index ? largeArray : smallArray,
1538 wrapped = _(array).map(identity).at(paths);
1540 assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
1545 skipAssert(assert, 6);
1549 QUnit.test('should support shortcut fusion', function(assert) {
1553 var array = lodashStable.range(LARGE_ARRAY_SIZE),
1555 iteratee = function(value) { count++; return square(value); },
1556 lastIndex = LARGE_ARRAY_SIZE - 1;
1558 lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
1560 var actual = _(array).map(iteratee).at(n).value(),
1561 expected = index < 2 ? 1 : 0;
1563 assert.strictEqual(count, expected);
1565 expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
1566 assert.deepEqual(actual, expected);
1570 skipAssert(assert, 8);
1574 QUnit.test('work with an object for `object` when chaining', function(assert) {
1578 var paths = ['a[0].b.c', 'a[1]'],
1579 actual = _(object).map(identity).at(paths).value();
1581 assert.deepEqual(actual, _.at(_.map(object, identity), paths));
1583 var indexObject = { '0': 1 };
1584 actual = _(indexObject).at(0).value();
1585 assert.deepEqual(actual, _.at(indexObject, 0));
1588 skipAssert(assert, 2);
1593 /*--------------------------------------------------------------------------*/
1595 QUnit.module('lodash.attempt');
1598 QUnit.test('should return the result of `func`', function(assert) {
1601 assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
1604 QUnit.test('should provide additional arguments to `func`', function(assert) {
1607 var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
1608 assert.deepEqual(actual, [1, 2]);
1611 QUnit.test('should return the caught error', function(assert) {
1614 var expected = lodashStable.map(errors, stubTrue);
1616 var actual = lodashStable.map(errors, function(error) {
1617 return _.attempt(function() { throw error; }) === error;
1620 assert.deepEqual(actual, expected);
1623 QUnit.test('should coerce errors to error objects', function(assert) {
1626 var actual = _.attempt(function() { throw 'x'; });
1627 assert.ok(lodashStable.isEqual(actual, Error('x')));
1630 QUnit.test('should preserve custom errors', function(assert) {
1633 var actual = _.attempt(function() { throw new CustomError('x'); });
1634 assert.ok(actual instanceof CustomError);
1637 QUnit.test('should work with an error object from another realm', function(assert) {
1641 var expected = lodashStable.map(realm.errors, stubTrue);
1643 var actual = lodashStable.map(realm.errors, function(error) {
1644 return _.attempt(function() { throw error; }) === error;
1647 assert.deepEqual(actual, expected);
1654 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1658 assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
1665 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1669 assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
1677 /*--------------------------------------------------------------------------*/
1679 QUnit.module('lodash.before');
1682 function before(n, times) {
1684 lodashStable.times(times, _.before(n, function() { count++; }));
1688 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1691 assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
1692 assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
1693 assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
1694 assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
1697 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1700 assert.strictEqual(before(NaN, 1), 0);
1703 QUnit.test('should not set a `this` binding', function(assert) {
1706 var before = _.before(2, function(assert) { return ++this.count; }),
1707 object = { 'before': before, 'count': 0 };
1710 assert.strictEqual(object.before(), 1);
1711 assert.strictEqual(object.count, 1);
1715 /*--------------------------------------------------------------------------*/
1717 QUnit.module('lodash.bind');
1721 var result = [this];
1722 push.apply(result, arguments);
1726 QUnit.test('should bind a function to an object', function(assert) {
1730 bound = _.bind(fn, object);
1732 assert.deepEqual(bound('a'), [object, 'a']);
1735 QUnit.test('should accept a falsey `thisArg` argument', function(assert) {
1738 var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
1739 expected = lodashStable.map(values, function(value) { return [value]; });
1741 var actual = lodashStable.map(values, function(value) {
1743 var bound = _.bind(fn, value);
1748 assert.ok(lodashStable.every(actual, function(value, index) {
1749 return lodashStable.isEqual(value, expected[index]);
1753 QUnit.test('should bind a function to nullish values', function(assert) {
1756 var bound = _.bind(fn, null),
1757 actual = bound('a');
1759 assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
1760 assert.strictEqual(actual[1], 'a');
1762 lodashStable.times(2, function(index) {
1763 bound = index ? _.bind(fn, undefined) : _.bind(fn);
1764 actual = bound('b');
1766 assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
1767 assert.strictEqual(actual[1], 'b');
1771 QUnit.test('should partially apply arguments ', function(assert) {
1775 bound = _.bind(fn, object, 'a');
1777 assert.deepEqual(bound(), [object, 'a']);
1779 bound = _.bind(fn, object, 'a');
1780 assert.deepEqual(bound('b'), [object, 'a', 'b']);
1782 bound = _.bind(fn, object, 'a', 'b');
1783 assert.deepEqual(bound(), [object, 'a', 'b']);
1784 assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
1787 QUnit.test('should support placeholders', function(assert) {
1791 ph = _.bind.placeholder,
1792 bound = _.bind(fn, object, ph, 'b', ph);
1794 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
1795 assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
1796 assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
1797 assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
1800 QUnit.test('should use `_.placeholder` when set', function(assert) {
1803 if (!isModularize) {
1804 var _ph = _.placeholder = {},
1805 ph = _.bind.placeholder,
1807 bound = _.bind(fn, object, _ph, 'b', ph);
1809 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']);
1810 delete _.placeholder;
1817 QUnit.test('should create a function with a `length` of `0`', function(assert) {
1820 var fn = function(a, b, c) {},
1821 bound = _.bind(fn, {});
1823 assert.strictEqual(bound.length, 0);
1825 bound = _.bind(fn, {}, 1);
1826 assert.strictEqual(bound.length, 0);
1829 QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
1836 var bound = _.bind(Foo, { 'a': 1 }),
1837 newBound = new bound;
1839 assert.strictEqual(bound().a, 1);
1840 assert.strictEqual(newBound.a, undefined);
1841 assert.ok(newBound instanceof Foo);
1844 QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
1853 var thisArg = { 'a': 1 },
1854 boundFoo = _.bind(Foo, thisArg),
1855 boundBar = _.bind(Bar, thisArg),
1857 expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
1859 var actual = lodashStable.times(count, function(index) {
1862 case 0: return [new boundFoo().a, new boundBar().a];
1863 case 1: return [new boundFoo(1).a, new boundBar(1).a];
1864 case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
1865 case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
1866 case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
1867 case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
1868 case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
1869 case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
1870 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];
1875 assert.deepEqual(actual, expected);
1878 QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
1881 function Foo(value) {
1882 return value && object;
1885 var bound = _.bind(Foo),
1888 assert.ok(new bound instanceof Foo);
1889 assert.strictEqual(new bound(true), object);
1892 QUnit.test('should append array arguments to partially applied arguments', function(assert) {
1896 bound = _.bind(fn, object, 'a');
1898 assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
1901 QUnit.test('should not rebind functions', function(assert) {
1908 var bound1 = _.bind(fn, object1),
1909 bound2 = _.bind(bound1, object2, 'a'),
1910 bound3 = _.bind(bound1, object3, 'b');
1912 assert.deepEqual(bound1(), [object1]);
1913 assert.deepEqual(bound2(), [object1, 'a']);
1914 assert.deepEqual(bound3(), [object1, 'b']);
1917 QUnit.test('should not error when instantiating bound built-ins', function(assert) {
1920 var Ctor = _.bind(Date, null),
1921 expected = new Date(2012, 4, 23, 0, 0, 0, 0);
1924 var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
1927 assert.deepEqual(actual, expected);
1929 Ctor = _.bind(Date, null, 2012, 4, 23);
1932 actual = new Ctor(0, 0, 0, 0);
1935 assert.deepEqual(actual, expected);
1938 QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
1941 var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
1943 if (typeof createCtor == 'function') {
1944 var bound = _.bind(createCtor()),
1946 expected = lodashStable.times(count, stubTrue);
1948 var actual = lodashStable.times(count, function(index) {
1951 case 0: return !!(new bound);
1952 case 1: return !!(new bound(1));
1953 case 2: return !!(new bound(1, 2));
1954 case 3: return !!(new bound(1, 2, 3));
1955 case 4: return !!(new bound(1, 2, 3, 4));
1956 case 5: return !!(new bound(1, 2, 3, 4, 5));
1957 case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
1958 case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
1963 assert.deepEqual(actual, expected);
1970 QUnit.test('should return a wrapped value when chaining', function(assert) {
1975 bound = _(fn).bind({}, 'a', 'b');
1977 assert.ok(bound instanceof _);
1979 var actual = bound.value()('c');
1980 assert.deepEqual(actual, [object, 'a', 'b', 'c']);
1983 skipAssert(assert, 2);
1988 /*--------------------------------------------------------------------------*/
1990 QUnit.module('lodash.bindAll');
1993 var args = arguments;
2002 '-0': function() { return this._n0; },
2003 '0': function() { return this._p0; },
2004 'a': function() { return this._a; },
2005 'b': function() { return this._b; },
2006 'c': function() { return this._c; },
2007 'd': function() { return this._d; }
2010 QUnit.test('should accept individual method names', function(assert) {
2013 var object = lodashStable.cloneDeep(source);
2014 _.bindAll(object, 'a', 'b');
2016 var actual = lodashStable.map(['a', 'b', 'c'], function(key) {
2017 return object[key].call({});
2020 assert.deepEqual(actual, [1, 2, undefined]);
2023 QUnit.test('should accept arrays of method names', function(assert) {
2026 var object = lodashStable.cloneDeep(source);
2027 _.bindAll(object, ['a', 'b'], ['c']);
2029 var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(key) {
2030 return object[key].call({});
2033 assert.deepEqual(actual, [1, 2, 3, undefined]);
2036 QUnit.test('should preserve the sign of `0`', function(assert) {
2039 var props = [-0, Object(-0), 0, Object(0)];
2041 var actual = lodashStable.map(props, function(key) {
2042 var object = lodashStable.cloneDeep(source);
2043 _.bindAll(object, key);
2044 return object[lodashStable.toString(key)].call({});
2047 assert.deepEqual(actual, [-2, -2, -1, -1]);
2050 QUnit.test('should work with an array `object` argument', function(assert) {
2053 var array = ['push', 'pop'];
2055 assert.strictEqual(array.pop, arrayProto.pop);
2058 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
2061 var object = lodashStable.cloneDeep(source);
2062 _.bindAll(object, args);
2064 var actual = lodashStable.map(args, function(key) {
2065 return object[key].call({});
2068 assert.deepEqual(actual, [1]);
2072 /*--------------------------------------------------------------------------*/
2074 QUnit.module('lodash.bindKey');
2077 QUnit.test('should work when the target function is overwritten', function(assert) {
2082 'greet': function(greeting) {
2083 return this.user + ' says: ' + greeting;
2087 var bound = _.bindKey(object, 'greet', 'hi');
2088 assert.strictEqual(bound(), 'fred says: hi');
2090 object.greet = function(greeting) {
2091 return this.user + ' says: ' + greeting + '!';
2094 assert.strictEqual(bound(), 'fred says: hi!');
2097 QUnit.test('should support placeholders', function(assert) {
2102 return slice.call(arguments);
2106 var ph = _.bindKey.placeholder,
2107 bound = _.bindKey(object, 'fn', ph, 'b', ph);
2109 assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
2110 assert.deepEqual(bound('a'), ['a', 'b', undefined]);
2111 assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
2112 assert.deepEqual(bound(), [undefined, 'b', undefined]);
2115 QUnit.test('should use `_.placeholder` when set', function(assert) {
2118 if (!isModularize) {
2121 return slice.call(arguments);
2125 var _ph = _.placeholder = {},
2126 ph = _.bindKey.placeholder,
2127 bound = _.bindKey(object, 'fn', _ph, 'b', ph);
2129 assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']);
2130 delete _.placeholder;
2137 QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
2140 function Foo(value) {
2141 return value && object;
2144 var object = { 'Foo': Foo },
2145 bound = _.bindKey(object, 'Foo');
2147 assert.ok(new bound instanceof Foo);
2148 assert.strictEqual(new bound(true), object);
2152 /*--------------------------------------------------------------------------*/
2154 QUnit.module('case methods');
2156 lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
2157 var methodName = caseName + 'Case',
2158 func = _[methodName];
2161 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
2162 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__'
2165 var converted = (function() {
2167 case 'camel': return 'fooBar';
2168 case 'kebab': return 'foo-bar';
2169 case 'lower': return 'foo bar';
2170 case 'snake': return 'foo_bar';
2171 case 'start': return 'Foo Bar';
2172 case 'upper': return 'FOO BAR';
2176 QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
2179 var actual = lodashStable.map(strings, function(string) {
2180 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2181 return func(string) === expected;
2184 assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
2187 QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
2190 var actual = lodashStable.map(strings, function(string) {
2191 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2192 return func(func(string)) === expected;
2195 assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
2198 QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
2201 var actual = lodashStable.map(burredLetters, function(burred, index) {
2202 var letter = deburredLetters[index];
2203 if (caseName == 'start') {
2204 letter = lodashStable.capitalize(letter);
2205 } else if (caseName == 'upper') {
2206 letter = letter.toUpperCase();
2208 letter = letter.toLowerCase();
2210 return func(burred) === letter;
2213 assert.deepEqual(actual, lodashStable.map(burredLetters, stubTrue));
2216 QUnit.test('`_.' + methodName + '` should remove contraction apostrophes', function(assert) {
2219 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
2221 lodashStable.each(["'", '\u2019'], function(apos) {
2222 var actual = lodashStable.map(postfixes, function(postfix) {
2223 return func('a b' + apos + postfix + ' c');
2226 var expected = lodashStable.map(postfixes, function(postfix) {
2228 case 'camel': return 'aB' + postfix + 'C';
2229 case 'kebab': return 'a-b' + postfix + '-c';
2230 case 'lower': return 'a b' + postfix + ' c';
2231 case 'snake': return 'a_b' + postfix + '_c';
2232 case 'start': return 'A B' + postfix + ' C';
2233 case 'upper': return 'A B' + postfix.toUpperCase() + ' C';
2237 assert.deepEqual(actual, expected);
2241 QUnit.test('`_.' + methodName + '` should remove latin-1 mathematical operators', function(assert) {
2244 var actual = lodashStable.map(['\xd7', '\xf7'], func);
2245 assert.deepEqual(actual, ['', '']);
2248 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
2251 var string = 'foo bar';
2252 assert.strictEqual(func(Object(string)), converted);
2253 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
2256 QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
2260 assert.strictEqual(_('foo bar')[methodName](), converted);
2267 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
2271 assert.ok(_('foo bar').chain()[methodName]() instanceof _);
2280 QUnit.test('should get the original value after cycling through all case methods', function(assert) {
2283 var funcs = [_.camelCase, _.kebabCase, _.lowerCase, _.snakeCase, _.startCase, _.lowerCase, _.camelCase];
2285 var actual = lodashStable.reduce(funcs, function(result, func) {
2286 return func(result);
2287 }, 'enable 6h format');
2289 assert.strictEqual(actual, 'enable6HFormat');
2293 /*--------------------------------------------------------------------------*/
2295 QUnit.module('lodash.camelCase');
2298 QUnit.test('should work with numbers', function(assert) {
2301 assert.strictEqual(_.camelCase('12 feet'), '12Feet');
2302 assert.strictEqual(_.camelCase('enable 6h format'), 'enable6HFormat');
2303 assert.strictEqual(_.camelCase('enable 24H format'), 'enable24HFormat');
2304 assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
2305 assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
2306 assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
2309 QUnit.test('should handle acronyms', function(assert) {
2312 lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
2313 assert.strictEqual(_.camelCase(string), 'safeHtml');
2316 lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
2317 assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
2320 lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
2321 assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
2326 /*--------------------------------------------------------------------------*/
2328 QUnit.module('lodash.capitalize');
2331 QUnit.test('should capitalize the first character of a string', function(assert) {
2334 assert.strictEqual(_.capitalize('fred'), 'Fred');
2335 assert.strictEqual(_.capitalize('Fred'), 'Fred');
2336 assert.strictEqual(_.capitalize(' fred'), ' fred');
2340 /*--------------------------------------------------------------------------*/
2342 QUnit.module('lodash.castArray');
2345 QUnit.test('should wrap non-array items in an array', function(assert) {
2348 var values = falsey.concat(true, 1, 'a', { 'a': 1 }),
2349 expected = lodashStable.map(values, function(value) { return [value]; }),
2350 actual = lodashStable.map(values, _.castArray);
2352 assert.deepEqual(actual, expected);
2355 QUnit.test('should return array values by reference', function(assert) {
2359 assert.strictEqual(_.castArray(array), array);
2362 QUnit.test('should return an empty array when no arguments are given', function(assert) {
2365 assert.deepEqual(_.castArray(), []);
2369 /*--------------------------------------------------------------------------*/
2371 QUnit.module('lodash.chain');
2374 QUnit.test('should return a wrapped value', function(assert) {
2378 var actual = _.chain({ 'a': 0 });
2379 assert.ok(actual instanceof _);
2386 QUnit.test('should return existing wrapped values', function(assert) {
2390 var wrapped = _({ 'a': 0 });
2391 assert.strictEqual(_.chain(wrapped), wrapped);
2392 assert.strictEqual(wrapped.chain(), wrapped);
2395 skipAssert(assert, 2);
2399 QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
2403 var array = ['c', 'b', 'a'];
2405 assert.ok(_.chain(array).head() instanceof _);
2406 assert.ok(_(array).chain().head() instanceof _);
2408 assert.ok(_.chain(array).isArray() instanceof _);
2409 assert.ok(_(array).chain().isArray() instanceof _);
2411 assert.ok(_.chain(array).sortBy().head() instanceof _);
2412 assert.ok(_(array).chain().sortBy().head() instanceof _);
2415 skipAssert(assert, 6);
2419 QUnit.test('should chain multiple methods', function(assert) {
2423 lodashStable.times(2, function(index) {
2424 var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
2425 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 },
2426 wrapped = index ? _(array).chain() : _.chain(array);
2428 var actual = wrapped
2430 .map(function(value) { return value.split(''); })
2432 .reduce(function(object, chr) {
2433 object[chr] || (object[chr] = 0);
2439 assert.deepEqual(actual, expected);
2441 array = [1, 2, 3, 4, 5, 6];
2442 wrapped = index ? _(array).chain() : _.chain(array);
2445 .filter(function(n) { return n % 2 != 0; })
2446 .reject(function(n) { return n % 3 == 0; })
2447 .sortBy(function(n) { return -n; })
2450 assert.deepEqual(actual, [5, 1]);
2453 wrapped = index ? _(array).chain() : _.chain(array);
2458 .tap(function(value) { value.pop(); })
2462 assert.deepEqual(actual, [25, 16, 9, 4]);
2466 skipAssert(assert, 6);
2471 /*--------------------------------------------------------------------------*/
2473 QUnit.module('lodash.chunk');
2476 var array = [0, 1, 2, 3, 4, 5];
2478 QUnit.test('should return chunked arrays', function(assert) {
2481 var actual = _.chunk(array, 3);
2482 assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
2485 QUnit.test('should return the last chunk as remaining elements', function(assert) {
2488 var actual = _.chunk(array, 4);
2489 assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
2492 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
2495 var expected = lodashStable.map(falsey, function(value) {
2496 return value === undefined ? [[0], [1], [2], [3], [4], [5]] : [];
2499 var actual = lodashStable.map(falsey, function(size, index) {
2500 return index ? _.chunk(array, size) : _.chunk(array);
2503 assert.deepEqual(actual, expected);
2506 QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
2509 var values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity),
2510 expected = lodashStable.map(values, stubArray);
2512 var actual = lodashStable.map(values, function(n) {
2513 return _.chunk(array, n);
2516 assert.deepEqual(actual, expected);
2519 QUnit.test('should coerce `size` to an integer', function(assert) {
2522 assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
2525 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
2528 var actual = lodashStable.map([[1, 2], [3, 4]], _.chunk);
2529 assert.deepEqual(actual, [[[1], [2]], [[3], [4]]]);
2533 /*--------------------------------------------------------------------------*/
2535 QUnit.module('lodash.clamp');
2538 QUnit.test('should work with a `max` argument', function(assert) {
2541 assert.strictEqual(_.clamp(5, 3), 3);
2542 assert.strictEqual(_.clamp(1, 3), 1);
2545 QUnit.test('should clamp negative numbers', function(assert) {
2548 assert.strictEqual(_.clamp(-10, -5, 5), -5);
2549 assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
2550 assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
2553 QUnit.test('should clamp positive numbers', function(assert) {
2556 assert.strictEqual(_.clamp(10, -5, 5), 5);
2557 assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
2558 assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
2561 QUnit.test('should not alter negative numbers in range', function(assert) {
2564 assert.strictEqual(_.clamp(-4, -5, 5), -4);
2565 assert.strictEqual(_.clamp(-5, -5, 5), -5);
2566 assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
2569 QUnit.test('should not alter positive numbers in range', function(assert) {
2572 assert.strictEqual(_.clamp(4, -5, 5), 4);
2573 assert.strictEqual(_.clamp(5, -5, 5), 5);
2574 assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
2577 QUnit.test('should not alter `0` in range', function(assert) {
2580 assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
2583 QUnit.test('should clamp to `0`', function(assert) {
2586 assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
2589 QUnit.test('should not alter `-0` in range', function(assert) {
2592 assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
2595 QUnit.test('should clamp to `-0`', function(assert) {
2598 assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
2601 QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
2604 assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
2607 QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
2610 assert.deepEqual(_.clamp(1, -5, NaN), 0);
2611 assert.deepEqual(_.clamp(-1, NaN, 5), 0);
2615 /*--------------------------------------------------------------------------*/
2617 QUnit.module('clone methods');
2623 Foo.prototype.b = 1;
2624 Foo.c = function() {};
2637 '`arguments` objects': arguments,
2638 'arrays': ['a', ''],
2639 'array-like objects': { '0': 'a', '1': '', 'length': 3 },
2641 'boolean objects': Object(false),
2642 'date objects': new Date,
2643 'Foo instances': new Foo,
2644 'objects': { 'a': 0, 'b': 1, 'c': 2 },
2645 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
2646 'objects from another document': realm.object || {},
2648 'null values': null,
2650 'number objects': Object(0),
2654 'string objects': Object('a'),
2655 'undefined values': undefined
2658 objects.arrays.length = 3;
2661 'DOM elements': body,
2663 'generators': generator
2666 lodashStable.each(errors, function(error) {
2667 uncloneable[error.name + 's'] = error;
2670 QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
2673 var array = [{ 'a': 0 }, { 'b': 1 }],
2674 actual = _.clone(array);
2676 assert.deepEqual(actual, array);
2677 assert.ok(actual !== array && actual[0] === array[0]);
2680 QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
2684 'foo': { 'b': { 'c': { 'd': {} } } },
2688 object.foo.b.c.d = object;
2689 object.bar.b = object.foo.b;
2691 var actual = _.cloneDeep(object);
2692 assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
2695 QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
2699 lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
2700 cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
2703 var clone = _.cloneDeep(cyclical),
2704 actual = clone['v' + LARGE_ARRAY_SIZE][0];
2706 assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
2707 assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
2710 QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
2715 _.cloneDeepWith({ 'a': 1 }, function() {
2716 actual = _.last(arguments);
2720 ? actual.constructor.name == 'Stack'
2721 : actual instanceof mapCaches.Stack
2725 lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
2726 var func = _[methodName],
2727 isDeep = methodName == 'cloneDeep';
2729 lodashStable.forOwn(objects, function(object, key) {
2730 QUnit.test('`_.' + methodName + '` should clone ' + key, function(assert) {
2733 var isEqual = (key == 'maps' || key == 'sets') ? _.isEqual : lodashStable.isEqual,
2734 actual = func(object);
2736 assert.ok(isEqual(actual, object));
2738 if (lodashStable.isObject(object)) {
2739 assert.notStrictEqual(actual, object);
2741 assert.strictEqual(actual, object);
2746 QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
2750 var actual = func(arrayBuffer);
2751 assert.strictEqual(actual.byteLength, arrayBuffer.byteLength);
2752 assert.notStrictEqual(actual, arrayBuffer);
2755 skipAssert(assert, 2);
2759 QUnit.test('`_.' + methodName + '` should clone buffers', function(assert) {
2763 var buffer = new Buffer([1, 2]),
2764 actual = func(buffer);
2766 assert.strictEqual(actual.byteLength, buffer.byteLength);
2767 assert.strictEqual(actual.inspect(), buffer.inspect());
2768 assert.notStrictEqual(actual, buffer);
2771 assert.strictEqual(actual[0], isDeep ? 2 : 1);
2774 skipAssert(assert, 4);
2778 QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
2781 var array = /c/.exec('abcde'),
2782 actual = func(array);
2784 assert.strictEqual(actual.index, 2);
2785 assert.strictEqual(actual.input, 'abcde');
2788 QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
2792 regexp.exec('abcde');
2794 assert.strictEqual(func(regexp).lastIndex, 3);
2797 QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
2800 var values = lodashStable.map([false, true, 1, 'a'], function(value) {
2801 var object = Object(value);
2806 var expected = lodashStable.map(values, stubTrue);
2808 var actual = lodashStable.map(values, function(value) {
2809 return func(value).a === 1;
2812 assert.deepEqual(actual, expected);
2815 QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
2818 var actual = func(Foo.prototype);
2820 assert.notOk(actual instanceof Foo);
2821 assert.deepEqual(actual, { 'b': 1 });
2824 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone', function(assert) {
2827 assert.ok(func(new Foo) instanceof Foo);
2830 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone even when the `constructor` is incorrect', function(assert) {
2833 Foo.prototype.constructor = Object;
2834 assert.ok(func(new Foo) instanceof Foo);
2835 Foo.prototype.constructor = Foo;
2838 QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
2841 Foo.prototype.constructor = null;
2842 assert.notOk(func(new Foo) instanceof Foo);
2843 Foo.prototype.constructor = Foo;
2846 QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
2850 'constructor': objectProto.constructor,
2851 'hasOwnProperty': objectProto.hasOwnProperty,
2852 'isPrototypeOf': objectProto.isPrototypeOf,
2853 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
2854 'toLocaleString': objectProto.toLocaleString,
2855 'toString': objectProto.toString,
2856 'valueOf': objectProto.valueOf
2859 var actual = func(object);
2861 assert.deepEqual(actual, object);
2862 assert.notStrictEqual(actual, object);
2865 QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
2869 this[symbol] = { 'c': 1 };
2873 var symbol2 = Symbol('b');
2874 Foo.prototype[symbol2] = 2;
2876 var object = { 'a': { 'b': new Foo } };
2877 object[symbol] = { 'b': 1 };
2879 var actual = func(object);
2881 assert.deepEqual(getSymbols(actual.a.b), [symbol]);
2884 assert.deepEqual(actual[symbol], object[symbol]);
2885 assert.deepEqual(actual.a.b[symbol], object.a.b[symbol]);
2888 assert.strictEqual(actual[symbol], object[symbol]);
2889 assert.strictEqual(actual.a, object.a);
2893 skipAssert(assert, 3);
2897 QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
2901 assert.strictEqual(func(symbol), symbol);
2903 var object = Object(symbol),
2904 actual = func(object);
2906 assert.strictEqual(typeof actual, 'object');
2907 assert.strictEqual(typeof actual.valueOf(), 'symbol');
2908 assert.notStrictEqual(actual, object);
2911 skipAssert(assert, 4);
2915 QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
2919 assert.strictEqual(func(symbol), symbol);
2926 QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
2930 var element = document.createElement('div');
2933 assert.deepEqual(func(element), {});
2935 assert.ok(false, e.message);
2943 QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
2948 var objects = lodashStable.transform(_, function(result, value, key) {
2949 if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) &&
2950 !lodashStable.isArguments(value) && !lodashStable.isElement(value) &&
2951 !lodashStable.isFunction(value)) {
2952 props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
2957 var expected = lodashStable.map(objects, stubTrue);
2959 var actual = lodashStable.map(objects, function(object) {
2960 var Ctor = object.constructor,
2961 result = func(object);
2963 return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
2966 assert.deepEqual(actual, expected, props.join(', '));
2969 QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
2972 var expected = [{ 'a': [0] }, { 'b': [1] }],
2973 actual = lodashStable.map(expected, func);
2975 assert.deepEqual(actual, expected);
2978 assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
2980 assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
2984 QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
2988 var object = objects.objects,
2989 actual = _(object)[methodName]();
2991 assert.deepEqual(actual, object);
2992 assert.notStrictEqual(actual, object);
2995 skipAssert(assert, 2);
2999 lodashStable.each(arrayViews, function(type) {
3000 QUnit.test('`_.' + methodName + '` should clone ' + type + ' values', function(assert) {
3003 var Ctor = root[type];
3005 lodashStable.times(2, function(index) {
3007 var buffer = new ArrayBuffer(24),
3008 view = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
3009 actual = func(view);
3011 assert.deepEqual(actual, view);
3012 assert.notStrictEqual(actual, view);
3013 assert.strictEqual(actual.buffer === view.buffer, !isDeep);
3014 assert.strictEqual(actual.byteOffset, view.byteOffset);
3015 assert.strictEqual(actual.length, view.length);
3018 skipAssert(assert, 5);
3024 lodashStable.forOwn(uncloneable, function(value, key) {
3025 QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
3029 var object = { 'a': value, 'b': { 'c': value } },
3030 actual = func(object),
3031 expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
3033 assert.deepEqual(actual, object);
3034 assert.notStrictEqual(actual, object);
3035 assert.deepEqual(func(value), expected);
3038 skipAssert(assert, 3);
3044 lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
3045 var func = _[methodName],
3046 isDeep = methodName == 'cloneDeepWith';
3048 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
3054 func(object, function() {
3055 var length = arguments.length,
3056 args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
3058 argsList.push(args);
3061 assert.deepEqual(argsList, isDeep ? [[object], [1, 'a', object]] : [[object]]);
3064 QUnit.test('`_.' + methodName + '` should handle cloning when `customizer` returns `undefined`', function(assert) {
3067 var actual = func({ 'a': { 'b': 'c' } }, noop);
3068 assert.deepEqual(actual, { 'a': { 'b': 'c' } });
3071 lodashStable.forOwn(uncloneable, function(value, key) {
3072 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
3075 var customizer = function(value) {
3076 return lodashStable.isPlainObject(value) ? undefined : value;
3079 var actual = func(value, customizer);
3080 assert.strictEqual(actual, value);
3082 var object = { 'a': value, 'b': { 'c': value } };
3083 actual = func(object, customizer);
3085 assert.deepEqual(actual, object);
3086 assert.notStrictEqual(actual, object);
3092 /*--------------------------------------------------------------------------*/
3094 QUnit.module('lodash.compact');
3097 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
3099 QUnit.test('should filter falsey values', function(assert) {
3102 var array = ['0', '1', '2'];
3103 assert.deepEqual(_.compact(falsey.concat(array)), array);
3106 QUnit.test('should work when in-between lazy operators', function(assert) {
3110 var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
3111 assert.deepEqual(actual, []);
3113 actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
3114 assert.deepEqual(actual, [true, 1, 'a']);
3117 skipAssert(assert, 2);
3121 QUnit.test('should work in a lazy sequence', function(assert) {
3125 var actual = _(largeArray).slice(1).compact().reverse().take().value();
3126 assert.deepEqual(actual, _.take(_.compact(_.slice(largeArray, 1)).reverse()));
3133 QUnit.test('should work in a lazy sequence with a custom `_.iteratee`', function(assert) {
3136 if (!isModularize) {
3137 var iteratee = _.iteratee,
3140 _.iteratee = identity;
3143 var actual = _(largeArray).slice(1).compact().value();
3144 pass = lodashStable.isEqual(actual, _.compact(_.slice(largeArray, 1)));
3145 } catch (e) {console.log(e);}
3148 _.iteratee = iteratee;
3156 /*--------------------------------------------------------------------------*/
3158 QUnit.module('lodash.concat');
3161 QUnit.test('should shallow clone `array`', function(assert) {
3164 var array = [1, 2, 3],
3165 actual = _.concat(array);
3167 assert.deepEqual(actual, array);
3168 assert.notStrictEqual(actual, array);
3171 QUnit.test('should concat arrays and values', function(assert) {
3175 actual = _.concat(array, 2, [3], [[4]]);
3177 assert.deepEqual(actual, [1, 2, 3, [4]]);
3178 assert.deepEqual(array, [1]);
3181 QUnit.test('should cast non-array `array` values to arrays', function(assert) {
3184 var values = [, null, undefined, false, true, 1, NaN, 'a'];
3186 var expected = lodashStable.map(values, function(value, index) {
3187 return index ? [value] : [];
3190 var actual = lodashStable.map(values, function(value, index) {
3191 return index ? _.concat(value) : _.concat();
3194 assert.deepEqual(actual, expected);
3196 expected = lodashStable.map(values, function(value) {
3197 return [value, 2, [3]];
3200 actual = lodashStable.map(values, function(value) {
3201 return _.concat(value, [2], [[3]]);
3204 assert.deepEqual(actual, expected);
3207 QUnit.test('should treat sparse arrays as dense', function(assert) {
3211 actual = _.concat(Array(1), Array(1));
3213 expected.push(undefined, undefined);
3215 assert.ok('0'in actual);
3216 assert.ok('1' in actual);
3217 assert.deepEqual(actual, expected);
3220 QUnit.test('should return a new wrapped array', function(assert) {
3225 wrapped = _(array).concat([2, 3]),
3226 actual = wrapped.value();
3228 assert.deepEqual(array, [1]);
3229 assert.deepEqual(actual, [1, 2, 3]);
3232 skipAssert(assert, 2);
3237 /*--------------------------------------------------------------------------*/
3239 QUnit.module('lodash.cond');
3242 QUnit.test('should create a conditional function', function(assert) {
3246 [lodashStable.matches({ 'a': 1 }), stubA],
3247 [lodashStable.matchesProperty('b', 1), stubB],
3248 [lodashStable.property('c'), stubC]
3251 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3252 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3253 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3256 QUnit.test('should provide arguments to functions', function(assert) {
3261 expected = ['a', 'b', 'c'];
3263 var cond = _.cond([[
3264 function() { args1 || (args1 = slice.call(arguments)); return true; },
3265 function() { args2 || (args2 = slice.call(arguments)); }
3268 cond('a', 'b', 'c');
3270 assert.deepEqual(args1, expected);
3271 assert.deepEqual(args2, expected);
3274 QUnit.test('should work with predicate shorthands', function(assert) {
3278 [{ 'a': 1 }, stubA],
3283 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3284 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3285 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3288 QUnit.test('should return `undefined` when no condition is met', function(assert) {
3291 var cond = _.cond([[stubFalse, stubA]]);
3292 assert.strictEqual(cond({ 'a': 1 }), undefined);
3295 QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
3298 lodashStable.each([false, true], function(value) {
3299 assert.raises(function() { _.cond([[stubTrue, value]])(); }, TypeError);
3303 QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
3307 [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
3310 var object = { 'cond': cond, 'a': 1, 'b': 2 };
3311 assert.strictEqual(object.cond('a', 'b'), 2);
3315 /*--------------------------------------------------------------------------*/
3317 QUnit.module('lodash.conforms');
3326 QUnit.test('should create a function that checks if a given object conforms to `source`', function(assert) {
3329 var conforms = _.conforms({
3330 'b': function(value) { return value > 4; }
3333 var actual = lodashStable.filter(objects, conforms);
3334 assert.deepEqual(actual, [objects[0], objects[2]]);
3336 conforms = _.conforms({
3337 'b': function(value) { return value > 8; },
3338 'a': function(value) { return value > 1; }
3341 actual = lodashStable.filter(objects, conforms);
3342 assert.deepEqual(actual, [objects[2]]);
3345 QUnit.test('should not match by inherited `source` properties', function(assert) {
3349 this.a = function(value) {
3353 Foo.prototype.b = function(value) {
3357 var conforms = _.conforms(new Foo),
3358 actual = lodashStable.filter(objects, conforms);
3360 assert.deepEqual(actual, [objects[1], objects[2]]);
3363 QUnit.test('should not invoke `source` predicates for missing `object` properties', function(assert) {
3368 var conforms = _.conforms({
3369 'a': function() { count++; return true; }
3372 assert.strictEqual(conforms({}), false);
3373 assert.strictEqual(count, 0);
3376 QUnit.test('should work with a function for `object`', function(assert) {
3385 var conforms = _.conforms({
3386 'a': function(value) { return value > 1; }
3389 assert.strictEqual(conforms(Foo), false);
3390 assert.strictEqual(conforms(Bar), true);
3393 QUnit.test('should work with a function for `source`', function(assert) {
3397 Foo.a = function(value) { return value > 1; };
3399 var objects = [{ 'a': 1 }, { 'a': 2 }],
3400 actual = lodashStable.filter(objects, _.conforms(Foo));
3402 assert.deepEqual(actual, [objects[1]]);
3405 QUnit.test('should work with a non-plain `object`', function(assert) {
3411 Foo.prototype.b = 2;
3413 var conforms = _.conforms({
3414 'b': function(value) { return value > 1; }
3417 assert.strictEqual(conforms(new Foo), true);
3420 QUnit.test('should return `false` when `object` is nullish', function(assert) {
3423 var values = [, null, undefined],
3424 expected = lodashStable.map(values, stubFalse);
3426 var conforms = _.conforms({
3427 'a': function(value) { return value > 1; }
3430 var actual = lodashStable.map(values, function(value, index) {
3432 return index ? conforms(value) : conforms();
3436 assert.deepEqual(actual, expected);
3439 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
3442 var values = [, null, undefined],
3443 expected = lodashStable.map(values, stubTrue),
3444 conforms = _.conforms({});
3446 var actual = lodashStable.map(values, function(value, index) {
3448 return index ? conforms(value) : conforms();
3452 assert.deepEqual(actual, expected);
3455 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
3458 var object = { 'a': 1 },
3459 expected = lodashStable.map(empties, stubTrue);
3461 var actual = lodashStable.map(empties, function(value) {
3462 var conforms = _.conforms(value);
3463 return conforms(object);
3466 assert.deepEqual(actual, expected);
3469 QUnit.test('should not change behavior if `source` is modified', function(assert) {
3473 'a': function(value) { return value > 1; }
3476 var object = { 'a': 2 },
3477 conforms = _.conforms(source);
3479 assert.strictEqual(conforms(object), true);
3481 source.a = function(value) { return value < 2; };
3482 assert.strictEqual(conforms(object), true);
3486 /*--------------------------------------------------------------------------*/
3488 QUnit.module('lodash.constant');
3491 QUnit.test('should create a function that returns `value`', function(assert) {
3494 var object = { 'a': 1 },
3495 values = Array(2).concat(empties, true, 1, 'a'),
3496 constant = _.constant(object);
3498 var results = lodashStable.map(values, function(value, index) {
3500 return index ? constant.call({}) : constant();
3502 return constant(value);
3505 assert.ok(lodashStable.every(results, function(result) {
3506 return result === object;
3510 QUnit.test('should work with falsey values', function(assert) {
3513 var expected = lodashStable.map(falsey, stubTrue);
3515 var actual = lodashStable.map(falsey, function(value, index) {
3516 var constant = index ? _.constant(value) : _.constant(),
3517 result = constant();
3519 return (result === value) || (result !== result && value !== value);
3522 assert.deepEqual(actual, expected);
3525 QUnit.test('should return a wrapped value when chaining', function(assert) {
3529 var wrapped = _(true).constant();
3530 assert.ok(wrapped instanceof _);
3538 /*--------------------------------------------------------------------------*/
3540 QUnit.module('lodash.countBy');
3543 var array = [6.1, 4.2, 6.3];
3545 QUnit.test('should transform keys by `iteratee`', function(assert) {
3548 var actual = _.countBy(array, Math.floor);
3549 assert.deepEqual(actual, { '4': 1, '6': 2 });
3552 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
3555 var array = [4, 6, 6],
3556 values = [, null, undefined],
3557 expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
3559 var actual = lodashStable.map(values, function(value, index) {
3560 return index ? _.countBy(array, value) : _.countBy(array);
3563 assert.deepEqual(actual, expected);
3566 QUnit.test('should work with `_.property` shorthands', function(assert) {
3569 var actual = _.countBy(['one', 'two', 'three'], 'length');
3570 assert.deepEqual(actual, { '3': 2, '5': 1 });
3573 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
3576 var actual = _.countBy(array, function(n) {
3577 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
3580 assert.deepEqual(actual.constructor, 1);
3581 assert.deepEqual(actual.hasOwnProperty, 2);
3584 QUnit.test('should work with a number for `iteratee`', function(assert) {
3593 assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
3594 assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
3597 QUnit.test('should work with an object for `collection`', function(assert) {
3600 var actual = _.countBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
3601 assert.deepEqual(actual, { '4': 1, '6': 2 });
3604 QUnit.test('should work in a lazy sequence', function(assert) {
3608 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
3609 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
3610 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
3613 var actual = _(array).countBy().map(square).filter(isEven).take().value();
3615 assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
3623 /*--------------------------------------------------------------------------*/
3625 QUnit.module('lodash.create');
3637 QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
3640 Circle.prototype = _.create(Shape.prototype);
3641 Circle.prototype.constructor = Circle;
3643 var actual = new Circle;
3645 assert.ok(actual instanceof Circle);
3646 assert.ok(actual instanceof Shape);
3647 assert.notStrictEqual(Circle.prototype, Shape.prototype);
3650 QUnit.test('should assign `properties` to the created object', function(assert) {
3653 var expected = { 'constructor': Circle, 'radius': 0 };
3654 Circle.prototype = _.create(Shape.prototype, expected);
3656 var actual = new Circle;
3658 assert.ok(actual instanceof Circle);
3659 assert.ok(actual instanceof Shape);
3660 assert.deepEqual(Circle.prototype, expected);
3663 QUnit.test('should assign own properties', function(assert) {
3670 Foo.prototype.b = 2;
3672 assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
3675 QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
3681 var object = _.create(new Foo, { 'a': 1 });
3682 assert.deepEqual(lodashStable.keys(object), ['a']);
3685 QUnit.test('should accept a falsey `prototype` argument', function(assert) {
3688 var expected = lodashStable.map(falsey, stubObject);
3690 var actual = lodashStable.map(falsey, function(prototype, index) {
3691 return index ? _.create(prototype) : _.create();
3694 assert.deepEqual(actual, expected);
3697 QUnit.test('should ignore primitive `prototype` arguments and use an empty object instead', function(assert) {
3700 var expected = lodashStable.map(primitives, stubTrue);
3702 var actual = lodashStable.map(primitives, function(value, index) {
3703 return lodashStable.isPlainObject(index ? _.create(value) : _.create());
3706 assert.deepEqual(actual, expected);
3709 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
3712 var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
3713 expected = lodashStable.map(array, stubTrue),
3714 objects = lodashStable.map(array, _.create);
3716 var actual = lodashStable.map(objects, function(object) {
3717 return object.a === 1 && !_.keys(object).length;
3720 assert.deepEqual(actual, expected);
3724 /*--------------------------------------------------------------------------*/
3726 QUnit.module('lodash.curry');
3729 function fn(a, b, c, d) {
3730 return slice.call(arguments);
3733 QUnit.test('should curry based on the number of arguments given', function(assert) {
3736 var curried = _.curry(fn),
3737 expected = [1, 2, 3, 4];
3739 assert.deepEqual(curried(1)(2)(3)(4), expected);
3740 assert.deepEqual(curried(1, 2)(3, 4), expected);
3741 assert.deepEqual(curried(1, 2, 3, 4), expected);
3744 QUnit.test('should allow specifying `arity`', function(assert) {
3747 var curried = _.curry(fn, 3),
3748 expected = [1, 2, 3];
3750 assert.deepEqual(curried(1)(2, 3), expected);
3751 assert.deepEqual(curried(1, 2)(3), expected);
3752 assert.deepEqual(curried(1, 2, 3), expected);
3755 QUnit.test('should coerce `arity` to an integer', function(assert) {
3758 var values = ['0', 0.6, 'xyz'],
3759 expected = lodashStable.map(values, stubArray);
3761 var actual = lodashStable.map(values, function(arity) {
3762 return _.curry(fn, arity)();
3765 assert.deepEqual(actual, expected);
3766 assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
3769 QUnit.test('should support placeholders', function(assert) {
3772 var curried = _.curry(fn),
3773 ph = curried.placeholder;
3775 assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
3776 assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
3777 assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
3778 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
3781 QUnit.test('should persist placeholders', function(assert) {
3784 var curried = _.curry(fn),
3785 ph = curried.placeholder,
3786 actual = curried(ph, ph, ph, 'd')('a')(ph)('b')('c');
3788 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3791 QUnit.test('should use `_.placeholder` when set', function(assert) {
3794 if (!isModularize) {
3795 var curried = _.curry(fn),
3796 _ph = _.placeholder = {},
3797 ph = curried.placeholder;
3799 assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]);
3800 delete _.placeholder;
3807 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3810 var curried = _.curry(fn, 3);
3811 assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
3812 assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
3813 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3816 QUnit.test('should create a function with a `length` of `0`', function(assert) {
3819 lodashStable.times(2, function(index) {
3820 var curried = index ? _.curry(fn, 4) : _.curry(fn);
3821 assert.strictEqual(curried.length, 0);
3822 assert.strictEqual(curried(1).length, 0);
3823 assert.strictEqual(curried(1, 2).length, 0);
3827 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3830 function Foo(value) {
3831 return value && object;
3834 var curried = _.curry(Foo),
3837 assert.ok(new curried(false) instanceof Foo);
3838 assert.strictEqual(new curried(true), object);
3841 QUnit.test('should not set a `this` binding', function(assert) {
3844 var fn = function(a, b, c) {
3845 var value = this || {};
3846 return [value[a], value[b], value[c]];
3849 var object = { 'a': 1, 'b': 2, 'c': 3 },
3850 expected = [1, 2, 3];
3852 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
3853 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
3854 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3856 assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
3857 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
3858 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
3860 object.curried = _.curry(fn);
3861 assert.deepEqual(object.curried('a')('b')('c'), Array(3));
3862 assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
3863 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3866 QUnit.test('should work with partialed methods', function(assert) {
3869 var curried = _.curry(fn),
3870 expected = [1, 2, 3, 4];
3872 var a = _.partial(curried, 1),
3873 b = _.bind(a, null, 2),
3874 c = _.partialRight(b, 4),
3875 d = _.partialRight(b(3), 4);
3877 assert.deepEqual(c(3), expected);
3878 assert.deepEqual(d(), expected);
3882 /*--------------------------------------------------------------------------*/
3884 QUnit.module('lodash.curryRight');
3887 function fn(a, b, c, d) {
3888 return slice.call(arguments);
3891 QUnit.test('should curry based on the number of arguments given', function(assert) {
3894 var curried = _.curryRight(fn),
3895 expected = [1, 2, 3, 4];
3897 assert.deepEqual(curried(4)(3)(2)(1), expected);
3898 assert.deepEqual(curried(3, 4)(1, 2), expected);
3899 assert.deepEqual(curried(1, 2, 3, 4), expected);
3902 QUnit.test('should allow specifying `arity`', function(assert) {
3905 var curried = _.curryRight(fn, 3),
3906 expected = [1, 2, 3];
3908 assert.deepEqual(curried(3)(1, 2), expected);
3909 assert.deepEqual(curried(2, 3)(1), expected);
3910 assert.deepEqual(curried(1, 2, 3), expected);
3913 QUnit.test('should coerce `arity` to an integer', function(assert) {
3916 var values = ['0', 0.6, 'xyz'],
3917 expected = lodashStable.map(values, stubArray);
3919 var actual = lodashStable.map(values, function(arity) {
3920 return _.curryRight(fn, arity)();
3923 assert.deepEqual(actual, expected);
3924 assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
3927 QUnit.test('should support placeholders', function(assert) {
3930 var curried = _.curryRight(fn),
3931 expected = [1, 2, 3, 4],
3932 ph = curried.placeholder;
3934 assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
3935 assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
3936 assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
3937 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
3940 QUnit.test('should persist placeholders', function(assert) {
3943 var curried = _.curryRight(fn),
3944 ph = curried.placeholder,
3945 actual = curried('a', ph, ph, ph)('b')(ph)('c')('d');
3947 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3950 QUnit.test('should use `_.placeholder` when set', function(assert) {
3953 if (!isModularize) {
3954 var curried = _.curryRight(fn),
3955 _ph = _.placeholder = {},
3956 ph = curried.placeholder;
3958 assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]);
3959 delete _.placeholder;
3966 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3969 var curried = _.curryRight(fn, 3);
3970 assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
3971 assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
3972 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3975 QUnit.test('should create a function with a `length` of `0`', function(assert) {
3978 lodashStable.times(2, function(index) {
3979 var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
3980 assert.strictEqual(curried.length, 0);
3981 assert.strictEqual(curried(4).length, 0);
3982 assert.strictEqual(curried(3, 4).length, 0);
3986 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3989 function Foo(value) {
3990 return value && object;
3993 var curried = _.curryRight(Foo),
3996 assert.ok(new curried(false) instanceof Foo);
3997 assert.strictEqual(new curried(true), object);
4000 QUnit.test('should not set a `this` binding', function(assert) {
4003 var fn = function(a, b, c) {
4004 var value = this || {};
4005 return [value[a], value[b], value[c]];
4008 var object = { 'a': 1, 'b': 2, 'c': 3 },
4009 expected = [1, 2, 3];
4011 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
4012 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
4013 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
4015 assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
4016 assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
4017 assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
4019 object.curried = _.curryRight(fn);
4020 assert.deepEqual(object.curried('c')('b')('a'), Array(3));
4021 assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
4022 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
4025 QUnit.test('should work with partialed methods', function(assert) {
4028 var curried = _.curryRight(fn),
4029 expected = [1, 2, 3, 4];
4031 var a = _.partialRight(curried, 4),
4032 b = _.partialRight(a, 3),
4033 c = _.bind(b, null, 1),
4034 d = _.partial(b(2), 1);
4036 assert.deepEqual(c(2), expected);
4037 assert.deepEqual(d(), expected);
4041 /*--------------------------------------------------------------------------*/
4043 QUnit.module('curry methods');
4045 lodashStable.each(['curry', 'curryRight'], function(methodName) {
4046 var func = _[methodName],
4047 fn = function(a, b) { return slice.call(arguments); },
4048 isCurry = methodName == 'curry';
4050 QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
4053 function run(a, b) {
4057 var curried = func(run);
4060 var actual = curried(1)(2);
4063 assert.strictEqual(actual, 3);
4066 QUnit.test('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function(assert) {
4069 var curried = _.curry(function hasOwnProperty(a, b, c) {
4073 var expected = [1, 2, 3];
4075 assert.deepEqual(curried(1)(2)(3), expected);
4078 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
4081 var array = [fn, fn, fn],
4082 object = { 'a': fn, 'b': fn, 'c': fn };
4084 lodashStable.each([array, object], function(collection) {
4085 var curries = lodashStable.map(collection, func),
4086 expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
4088 var actual = lodashStable.map(curries, function(curried) {
4089 return curried('a')('b');
4092 assert.deepEqual(actual, expected);
4097 /*--------------------------------------------------------------------------*/
4099 QUnit.module('lodash.debounce');
4102 QUnit.test('should debounce a function', function(assert) {
4105 var done = assert.async();
4109 var debounced = _.debounce(function(value) {
4114 var results = [debounced('a'), debounced('b'), debounced('c')];
4115 assert.deepEqual(results, [undefined, undefined, undefined]);
4116 assert.strictEqual(callCount, 0);
4118 setTimeout(function() {
4119 assert.strictEqual(callCount, 1);
4121 var results = [debounced('d'), debounced('e'), debounced('f')];
4122 assert.deepEqual(results, ['c', 'c', 'c']);
4123 assert.strictEqual(callCount, 1);
4126 setTimeout(function() {
4127 assert.strictEqual(callCount, 2);
4132 QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
4135 var done = assert.async();
4137 var debounced = _.debounce(identity, 32);
4140 setTimeout(function() {
4141 assert.notEqual(debounced('b'), 'b');
4144 setTimeout(function() {
4145 assert.notEqual(debounced('c'), 'c');
4150 QUnit.test('should not immediately call `func` when `wait` is `0`', function(assert) {
4153 var done = assert.async();
4156 debounced = _.debounce(function() { ++callCount; }, 0);
4160 assert.strictEqual(callCount, 0);
4162 setTimeout(function() {
4163 assert.strictEqual(callCount, 1);
4168 QUnit.test('should apply default options', function(assert) {
4171 var done = assert.async();
4174 debounced = _.debounce(function() { callCount++; }, 32, {});
4177 assert.strictEqual(callCount, 0);
4179 setTimeout(function() {
4180 assert.strictEqual(callCount, 1);
4185 QUnit.test('should support a `leading` option', function(assert) {
4188 var done = assert.async();
4190 var callCounts = [0, 0];
4192 var withLeading = _.debounce(function() {
4194 }, 32, { 'leading': true });
4196 var withLeadingAndTrailing = _.debounce(function() {
4198 }, 32, { 'leading': true });
4201 assert.strictEqual(callCounts[0], 1);
4203 withLeadingAndTrailing();
4204 withLeadingAndTrailing();
4205 assert.strictEqual(callCounts[1], 1);
4207 setTimeout(function() {
4208 assert.deepEqual(callCounts, [1, 2]);
4211 assert.strictEqual(callCounts[0], 2);
4217 QUnit.test('subsequent leading debounced calls return the last `func` result', function(assert) {
4220 var done = assert.async();
4222 var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
4223 results = [debounced('a'), debounced('b')];
4225 assert.deepEqual(results, ['a', 'a']);
4227 setTimeout(function() {
4228 var results = [debounced('c'), debounced('d')];
4229 assert.deepEqual(results, ['c', 'c']);
4234 QUnit.test('should support a `trailing` option', function(assert) {
4237 var done = assert.async();
4242 var withTrailing = _.debounce(function() {
4244 }, 32, { 'trailing': true });
4246 var withoutTrailing = _.debounce(function() {
4248 }, 32, { 'trailing': false });
4251 assert.strictEqual(withCount, 0);
4254 assert.strictEqual(withoutCount, 0);
4256 setTimeout(function() {
4257 assert.strictEqual(withCount, 1);
4258 assert.strictEqual(withoutCount, 0);
4263 QUnit.test('should support a `maxWait` option', function(assert) {
4266 var done = assert.async();
4270 var debounced = _.debounce(function(value) {
4273 }, 32, { 'maxWait': 64 });
4277 assert.strictEqual(callCount, 0);
4279 setTimeout(function() {
4280 assert.strictEqual(callCount, 1);
4283 assert.strictEqual(callCount, 1);
4286 setTimeout(function() {
4287 assert.strictEqual(callCount, 2);
4292 QUnit.test('should support `maxWait` in a tight loop', function(assert) {
4295 var done = assert.async();
4297 var limit = (argv || isPhantom) ? 1000 : 320,
4301 var withMaxWait = _.debounce(function() {
4303 }, 64, { 'maxWait': 128 });
4305 var withoutMaxWait = _.debounce(function() {
4309 var start = +new Date;
4310 while ((new Date - start) < limit) {
4314 var actual = [Boolean(withoutCount), Boolean(withCount)];
4315 setTimeout(function() {
4316 assert.deepEqual(actual, [false, true]);
4321 QUnit.test('should queue a trailing call for subsequent debounced calls after `maxWait`', function(assert) {
4324 var done = assert.async();
4328 var debounced = _.debounce(function() {
4330 }, 64, { 'maxWait': 64 });
4334 lodashStable.times(20, function(index) {
4335 setTimeout(debounced, 54 + index);
4338 setTimeout(function() {
4339 assert.strictEqual(callCount, 2);
4344 QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
4347 var done = assert.async();
4351 var debounced = _.debounce(function() {
4353 }, 32, { 'maxWait': 64 });
4357 setTimeout(function() {
4359 assert.strictEqual(callCount, 1);
4362 setTimeout(function() {
4363 assert.strictEqual(callCount, 2);
4368 QUnit.test('should invoke the trailing call with the correct arguments and `this` binding', function(assert) {
4371 var done = assert.async();
4377 var debounced = _.debounce(function(value) {
4379 push.apply(actual, arguments);
4380 return ++callCount != 2;
4381 }, 32, { 'leading': true, 'maxWait': 64 });
4384 if (!debounced.call(object, 'a')) {
4388 setTimeout(function() {
4389 assert.strictEqual(callCount, 2);
4390 assert.deepEqual(actual, [object, 'a']);
4396 /*--------------------------------------------------------------------------*/
4398 QUnit.module('lodash.deburr');
4401 QUnit.test('should convert latin-1 supplementary letters to basic latin', function(assert) {
4404 var actual = lodashStable.map(burredLetters, _.deburr);
4405 assert.deepEqual(actual, deburredLetters);
4408 QUnit.test('should not deburr latin-1 mathematical operators', function(assert) {
4411 var operators = ['\xd7', '\xf7'],
4412 actual = lodashStable.map(operators, _.deburr);
4414 assert.deepEqual(actual, operators);
4417 QUnit.test('should deburr combining diacritical marks', function(assert) {
4420 var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
4422 var actual = lodashStable.map(comboMarks, function(chr) {
4423 return _.deburr('e' + chr + 'i');
4426 assert.deepEqual(actual, expected);
4430 /*--------------------------------------------------------------------------*/
4432 QUnit.module('lodash.defaults');
4435 QUnit.test('should assign source properties if missing on `object`', function(assert) {
4438 assert.deepEqual(_.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 }), { 'a': 1, 'b': 2 });
4441 QUnit.test('should accept multiple sources', function(assert) {
4444 var expected = { 'a': 1, 'b': 2, 'c': 3 };
4445 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 }), expected);
4446 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 }), expected);
4449 QUnit.test('should not overwrite `null` values', function(assert) {
4452 var actual = _.defaults({ 'a': null }, { 'a': 1 });
4453 assert.strictEqual(actual.a, null);
4456 QUnit.test('should overwrite `undefined` values', function(assert) {
4459 var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
4460 assert.strictEqual(actual.a, 1);
4463 QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
4467 'constructor': objectProto.constructor,
4468 'hasOwnProperty': objectProto.hasOwnProperty,
4469 'isPrototypeOf': objectProto.isPrototypeOf,
4470 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
4471 'toLocaleString': objectProto.toLocaleString,
4472 'toString': objectProto.toString,
4473 'valueOf': objectProto.valueOf
4478 'hasOwnProperty': 2,
4480 'propertyIsEnumerable': 4,
4481 'toLocaleString': 5,
4486 assert.deepEqual(_.defaults({}, source), source);
4487 assert.deepEqual(_.defaults({}, object, source), object);
4491 /*--------------------------------------------------------------------------*/
4493 QUnit.module('lodash.defaultsDeep');
4496 QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
4499 var object = { 'a': { 'b': 2 }, 'd': 4 },
4500 source = { 'a': { 'b': 3, 'c': 3 }, 'e': 5 },
4501 expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
4503 assert.deepEqual(_.defaultsDeep(object, source), expected);
4506 QUnit.test('should accept multiple sources', function(assert) {
4509 var source1 = { 'a': { 'b': 3 } },
4510 source2 = { 'a': { 'c': 3 } },
4511 source3 = { 'a': { 'b': 3, 'c': 3 } },
4512 source4 = { 'a': { 'c': 4 } },
4513 expected = { 'a': { 'b': 2, 'c': 3 } };
4515 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
4516 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
4519 QUnit.test('should not overwrite `null` values', function(assert) {
4522 var object = { 'a': { 'b': null } },
4523 source = { 'a': { 'b': 2 } },
4524 actual = _.defaultsDeep(object, source);
4526 assert.strictEqual(actual.a.b, null);
4529 QUnit.test('should not overwrite regexp values', function(assert) {
4532 var object = { 'a': { 'b': /x/ } },
4533 source = { 'a': { 'b': /y/ } },
4534 actual = _.defaultsDeep(object, source);
4536 assert.deepEqual(actual.a.b, /x/);
4539 QUnit.test('should not convert function properties to objects', function(assert) {
4542 var actual = _.defaultsDeep({}, { 'a': noop });
4543 assert.strictEqual(actual.a, noop);
4545 actual = _.defaultsDeep({}, { 'a': { 'b': noop } });
4546 assert.strictEqual(actual.a.b, noop);
4549 QUnit.test('should overwrite `undefined` values', function(assert) {
4552 var object = { 'a': { 'b': undefined } },
4553 source = { 'a': { 'b': 2 } },
4554 actual = _.defaultsDeep(object, source);
4556 assert.strictEqual(actual.a.b, 2);
4559 QUnit.test('should merge sources containing circular references', function(assert) {
4563 'foo': { 'b': { 'c': { 'd': {} } } },
4568 'foo': { 'b': { 'c': { 'd': {} } } },
4572 object.foo.b.c.d = object;
4573 source.foo.b.c.d = source;
4574 source.bar.b = source.foo.b;
4576 var actual = _.defaultsDeep(object, source);
4578 assert.strictEqual(actual.bar.b, actual.foo.b);
4579 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
4582 QUnit.test('should not modify sources', function(assert) {
4585 var source1 = { 'a': 1, 'b': { 'c': 2 } },
4586 source2 = { 'b': { 'c': 3, 'd': 3 } },
4587 actual = _.defaultsDeep({}, source1, source2);
4589 assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
4590 assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
4591 assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
4594 QUnit.test('should not attempt a merge of a string into an array', function(assert) {
4597 var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
4598 assert.deepEqual(actual, { 'a': ['abc'] });
4602 /*--------------------------------------------------------------------------*/
4604 QUnit.module('lodash.defer');
4607 QUnit.test('should defer `func` execution', function(assert) {
4610 var done = assert.async();
4613 _.defer(function() { pass = true; });
4615 setTimeout(function() {
4621 QUnit.test('should provide additional arguments to `func`', function(assert) {
4624 var done = assert.async();
4628 _.defer(function() {
4629 args = slice.call(arguments);
4632 setTimeout(function() {
4633 assert.deepEqual(args, [1, 2]);
4638 QUnit.test('should be cancelable', function(assert) {
4641 var done = assert.async();
4644 timerId = _.defer(function() { pass = false; });
4646 clearTimeout(timerId);
4648 setTimeout(function() {
4655 /*--------------------------------------------------------------------------*/
4657 QUnit.module('lodash.delay');
4660 QUnit.test('should delay `func` execution', function(assert) {
4663 var done = assert.async();
4666 _.delay(function() { pass = true; }, 32);
4668 setTimeout(function() {
4672 setTimeout(function() {
4678 QUnit.test('should provide additional arguments to `func`', function(assert) {
4681 var done = assert.async();
4685 _.delay(function() {
4686 args = slice.call(arguments);
4689 setTimeout(function() {
4690 assert.deepEqual(args, [1, 2]);
4695 QUnit.test('should use a default `wait` of `0`', function(assert) {
4698 var done = assert.async();
4701 _.delay(function() { pass = true; });
4705 setTimeout(function() {
4711 QUnit.test('should be cancelable', function(assert) {
4714 var done = assert.async();
4717 timerId = _.delay(function() { pass = false; }, 32);
4719 clearTimeout(timerId);
4721 setTimeout(function() {
4727 QUnit.test('should work with mocked `setTimeout`', function(assert) {
4732 setTimeout = root.setTimeout;
4734 setProperty(root, 'setTimeout', function(func) { func(); });
4735 _.delay(function() { pass = true; }, 32);
4736 setProperty(root, 'setTimeout', setTimeout);
4746 /*--------------------------------------------------------------------------*/
4748 QUnit.module('difference methods');
4750 lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
4751 var args = (function() { return arguments; }(1, 2, 3)),
4752 func = _[methodName];
4754 QUnit.test('`_.' + methodName + '` should return the difference of two arrays', function(assert) {
4757 var actual = func([2, 1], [2, 3]);
4758 assert.deepEqual(actual, [1]);
4761 QUnit.test('`_.' + methodName + '` should return the difference of multiple arrays', function(assert) {
4764 var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
4765 assert.deepEqual(actual, [1]);
4768 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
4771 var array = [-0, 0];
4773 var actual = lodashStable.map(array, function(value) {
4774 return func(array, [value]);
4777 assert.deepEqual(actual, [[], []]);
4779 actual = lodashStable.map(func([-0, 1], [1]), lodashStable.toString);
4780 assert.deepEqual(actual, ['0']);
4783 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
4786 assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
4789 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
4792 var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
4793 array2 = lodashStable.range(LARGE_ARRAY_SIZE),
4798 array1.push(a, b, c);
4799 array2.push(b, c, a);
4801 assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
4804 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
4807 var array = [-0, 0];
4809 var actual = lodashStable.map(array, function(value) {
4810 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
4811 return func(array, largeArray);
4814 assert.deepEqual(actual, [[], []]);
4816 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne);
4817 actual = lodashStable.map(func([-0, 1], largeArray), lodashStable.toString);
4818 assert.deepEqual(actual, ['0']);
4821 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
4824 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
4825 assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
4828 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
4833 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
4835 assert.deepEqual(func([object1, object2], largeArray), [object2]);
4838 QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
4841 var array = [1, null, 3];
4843 assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
4844 assert.deepEqual(func(null, array, 1), []);
4845 assert.deepEqual(func(array, args, null), [null]);
4849 /*--------------------------------------------------------------------------*/
4851 QUnit.module('lodash.differenceBy');
4854 QUnit.test('should accept an `iteratee` argument', function(assert) {
4857 var actual = _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
4858 assert.deepEqual(actual, [1.2]);
4860 actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
4861 assert.deepEqual(actual, [{ 'x': 2 }]);
4864 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
4869 _.differenceBy([2.1, 1.2], [2.3, 3.4], function() {
4870 args || (args = slice.call(arguments));
4873 assert.deepEqual(args, [2.3]);
4877 /*--------------------------------------------------------------------------*/
4879 QUnit.module('lodash.differenceWith');
4882 QUnit.test('should work with a `comparator` argument', function(assert) {
4885 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
4886 actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
4888 assert.deepEqual(actual, [objects[1]]);
4891 QUnit.test('should preserve the sign of `0`', function(assert) {
4894 var array = [-0, 1],
4895 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne),
4896 others = [[1], largeArray],
4897 expected = lodashStable.map(others, lodashStable.constant(['-0']));
4899 var actual = lodashStable.map(others, function(other) {
4900 return lodashStable.map(_.differenceWith(array, other, lodashStable.eq), lodashStable.toString);
4903 assert.deepEqual(actual, expected);
4907 /*--------------------------------------------------------------------------*/
4909 QUnit.module('lodash.divide');
4912 QUnit.test('should divide two numbers', function(assert) {
4915 assert.strictEqual(_.divide(6, 4), 1.5);
4916 assert.strictEqual(_.divide(-6, 4), -1.5);
4917 assert.strictEqual(_.divide(-6, -4), 1.5);
4920 QUnit.test('should coerce arguments to numbers', function(assert) {
4923 assert.strictEqual(_.divide('6', '4'), 1.5);
4924 assert.deepEqual(_.divide('x', 'y'), NaN);
4928 /*--------------------------------------------------------------------------*/
4930 QUnit.module('lodash.drop');
4933 var array = [1, 2, 3];
4935 QUnit.test('should drop the first two elements', function(assert) {
4938 assert.deepEqual(_.drop(array, 2), [3]);
4941 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4944 var expected = lodashStable.map(falsey, function(value) {
4945 return value === undefined ? [2, 3] : array;
4948 var actual = lodashStable.map(falsey, function(n) {
4949 return _.drop(array, n);
4952 assert.deepEqual(actual, expected);
4955 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4958 lodashStable.each([0, -1, -Infinity], function(n) {
4959 assert.deepEqual(_.drop(array, n), array);
4963 QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
4966 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4967 assert.deepEqual(_.drop(array, n), []);
4971 QUnit.test('should coerce `n` to an integer', function(assert) {
4974 assert.deepEqual(_.drop(array, 1.6), [2, 3]);
4977 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4980 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4981 actual = lodashStable.map(array, _.drop);
4983 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
4986 QUnit.test('should work in a lazy sequence', function(assert) {
4990 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4991 predicate = function(value) { values.push(value); return isEven(value); },
4993 actual = _(array).drop(2).drop().value();
4995 assert.deepEqual(actual, array.slice(3));
4997 actual = _(array).filter(predicate).drop(2).drop().value();
4998 assert.deepEqual(values, array);
4999 assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
5001 actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
5002 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
5006 actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
5007 assert.deepEqual(values, array.slice(1));
5008 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
5011 skipAssert(assert, 6);
5016 /*--------------------------------------------------------------------------*/
5018 QUnit.module('lodash.dropRight');
5021 var array = [1, 2, 3];
5023 QUnit.test('should drop the last two elements', function(assert) {
5026 assert.deepEqual(_.dropRight(array, 2), [1]);
5029 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
5032 var expected = lodashStable.map(falsey, function(value) {
5033 return value === undefined ? [1, 2] : array;
5036 var actual = lodashStable.map(falsey, function(n) {
5037 return _.dropRight(array, n);
5040 assert.deepEqual(actual, expected);
5043 QUnit.test('should return all elements when `n` < `1`', function(assert) {
5046 lodashStable.each([0, -1, -Infinity], function(n) {
5047 assert.deepEqual(_.dropRight(array, n), array);
5051 QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
5054 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
5055 assert.deepEqual(_.dropRight(array, n), []);
5059 QUnit.test('should coerce `n` to an integer', function(assert) {
5062 assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
5065 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5068 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
5069 actual = lodashStable.map(array, _.dropRight);
5071 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
5074 QUnit.test('should work in a lazy sequence', function(assert) {
5078 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5079 predicate = function(value) { values.push(value); return isEven(value); },
5081 actual = _(array).dropRight(2).dropRight().value();
5083 assert.deepEqual(actual, array.slice(0, -3));
5085 actual = _(array).filter(predicate).dropRight(2).dropRight().value();
5086 assert.deepEqual(values, array);
5087 assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
5089 actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
5090 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
5094 actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
5095 assert.deepEqual(values, array.slice(0, -1));
5096 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
5099 skipAssert(assert, 6);
5104 /*--------------------------------------------------------------------------*/
5106 QUnit.module('lodash.dropRightWhile');
5109 var array = [1, 2, 3, 4];
5117 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5120 var actual = _.dropRightWhile(array, function(n) {
5124 assert.deepEqual(actual, [1, 2]);
5127 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
5132 _.dropRightWhile(array, function() {
5133 args = slice.call(arguments);
5136 assert.deepEqual(args, [4, 3, array]);
5139 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5142 assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
5145 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5148 assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
5151 QUnit.test('should work with `_.property` shorthands', function(assert) {
5154 assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
5157 QUnit.test('should return a wrapped value when chaining', function(assert) {
5161 var wrapped = _(array).dropRightWhile(function(n) {
5165 assert.ok(wrapped instanceof _);
5166 assert.deepEqual(wrapped.value(), [1, 2]);
5169 skipAssert(assert, 2);
5174 /*--------------------------------------------------------------------------*/
5176 QUnit.module('lodash.dropWhile');
5179 var array = [1, 2, 3, 4];
5187 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5190 var actual = _.dropWhile(array, function(n) {
5194 assert.deepEqual(actual, [3, 4]);
5197 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
5202 _.dropWhile(array, function() {
5203 args = slice.call(arguments);
5206 assert.deepEqual(args, [1, 0, array]);
5209 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5212 assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
5215 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5218 assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
5221 QUnit.test('should work with `_.property` shorthands', function(assert) {
5224 assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
5227 QUnit.test('should work in a lazy sequence', function(assert) {
5231 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
5232 predicate = function(n) { return n < 3; },
5233 expected = _.dropWhile(array, predicate),
5234 wrapped = _(array).dropWhile(predicate);
5236 assert.deepEqual(wrapped.value(), expected);
5237 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
5238 assert.strictEqual(wrapped.last(), _.last(expected));
5241 skipAssert(assert, 3);
5245 QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
5249 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
5251 var actual = _(array)
5252 .dropWhile(function(n) { return n == 1; })
5254 .dropWhile(function(n) { return n == 3; })
5257 assert.deepEqual(actual, array.slice(3));
5265 /*--------------------------------------------------------------------------*/
5267 QUnit.module('lodash.endsWith');
5272 QUnit.test('should return `true` if a string ends with `target`', function(assert) {
5275 assert.strictEqual(_.endsWith(string, 'c'), true);
5278 QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
5281 assert.strictEqual(_.endsWith(string, 'b'), false);
5284 QUnit.test('should work with a `position` argument', function(assert) {
5287 assert.strictEqual(_.endsWith(string, 'b', 2), true);
5290 QUnit.test('should work with `position` >= `length`', function(assert) {
5293 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5294 assert.strictEqual(_.endsWith(string, 'c', position), true);
5298 QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
5301 var expected = lodashStable.map(falsey, stubTrue);
5303 var actual = lodashStable.map(falsey, function(position) {
5304 return _.endsWith(string, position === undefined ? 'c' : '', position);
5307 assert.deepEqual(actual, expected);
5310 QUnit.test('should treat a negative `position` as `0`', function(assert) {
5313 lodashStable.each([-1, -3, -Infinity], function(position) {
5314 assert.ok(lodashStable.every(string, function(chr) {
5315 return !_.endsWith(string, chr, position);
5317 assert.strictEqual(_.endsWith(string, '', position), true);
5321 QUnit.test('should coerce `position` to an integer', function(assert) {
5324 assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
5327 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
5330 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5331 return _.endsWith(string, '', position, true);
5336 /*--------------------------------------------------------------------------*/
5338 QUnit.module('lodash.eq');
5341 QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
5344 assert.strictEqual(_.eq(), true);
5345 assert.strictEqual(_.eq(undefined), true);
5346 assert.strictEqual(_.eq(0, -0), true);
5347 assert.strictEqual(_.eq(NaN, NaN), true);
5348 assert.strictEqual(_.eq(1, 1), true);
5350 assert.strictEqual(_.eq(null, undefined), false);
5351 assert.strictEqual(_.eq(1, Object(1)), false);
5352 assert.strictEqual(_.eq(1, '1'), false);
5353 assert.strictEqual(_.eq(1, '1'), false);
5355 var object = { 'a': 1 };
5356 assert.strictEqual(_.eq(object, object), true);
5357 assert.strictEqual(_.eq(object, { 'a': 1 }), false);
5361 /*--------------------------------------------------------------------------*/
5363 QUnit.module('lodash.escape');
5366 var escaped = '&<>"'`\/',
5367 unescaped = '&<>"\'`\/';
5370 unescaped += unescaped;
5372 QUnit.test('should escape values', function(assert) {
5375 assert.strictEqual(_.escape(unescaped), escaped);
5378 QUnit.test('should not escape the "/" character', function(assert) {
5381 assert.strictEqual(_.escape('/'), '/');
5384 QUnit.test('should handle strings with nothing to escape', function(assert) {
5387 assert.strictEqual(_.escape('abc'), 'abc');
5390 QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
5393 assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
5397 /*--------------------------------------------------------------------------*/
5399 QUnit.module('lodash.escapeRegExp');
5402 var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
5403 unescaped = '^$.*+?()[]{}|\\';
5405 QUnit.test('should escape values', function(assert) {
5408 assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
5411 QUnit.test('should handle strings with nothing to escape', function(assert) {
5414 assert.strictEqual(_.escapeRegExp('abc'), 'abc');
5417 QUnit.test('should return an empty string for empty values', function(assert) {
5420 var values = [, null, undefined, ''],
5421 expected = lodashStable.map(values, stubString);
5423 var actual = lodashStable.map(values, function(value, index) {
5424 return index ? _.escapeRegExp(value) : _.escapeRegExp();
5427 assert.deepEqual(actual, expected);
5431 /*--------------------------------------------------------------------------*/
5433 QUnit.module('lodash.every');
5436 QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
5439 assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
5442 QUnit.test('should return `true` for empty collections', function(assert) {
5445 var expected = lodashStable.map(empties, stubTrue);
5447 var actual = lodashStable.map(empties, function(value) {
5449 return _.every(value, identity);
5453 assert.deepEqual(actual, expected);
5456 QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
5461 assert.strictEqual(_.every([true, null, true], function(value) {
5466 assert.strictEqual(count, 2);
5469 QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
5472 assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
5475 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
5478 var values = [, null, undefined],
5479 expected = lodashStable.map(values, stubFalse);
5481 var actual = lodashStable.map(values, function(value, index) {
5483 return index ? _.every(array, value) : _.every(array);
5486 assert.deepEqual(actual, expected);
5488 expected = lodashStable.map(values, stubTrue);
5489 actual = lodashStable.map(values, function(value, index) {
5491 return index ? _.every(array, value) : _.every(array);
5494 assert.deepEqual(actual, expected);
5497 QUnit.test('should work with `_.property` shorthands', function(assert) {
5500 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
5501 assert.strictEqual(_.every(objects, 'a'), false);
5502 assert.strictEqual(_.every(objects, 'b'), true);
5505 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5508 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
5509 assert.strictEqual(_.every(objects, { 'a': 0 }), true);
5510 assert.strictEqual(_.every(objects, { 'b': 1 }), false);
5513 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5516 var actual = lodashStable.map([[1]], _.every);
5517 assert.deepEqual(actual, [true]);
5521 /*--------------------------------------------------------------------------*/
5523 QUnit.module('strict mode checks');
5525 lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults'], function(methodName) {
5526 var func = _[methodName],
5527 isBindAll = methodName == 'bindAll';
5529 QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
5533 var object = freeze({ 'a': undefined, 'b': function() {} }),
5537 func(object, isBindAll ? 'b' : { 'a': 1 });
5549 /*--------------------------------------------------------------------------*/
5551 QUnit.module('lodash.fill');
5554 QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
5557 var array = [1, 2, 3];
5558 assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
5561 QUnit.test('should use `undefined` for `value` if not given', function(assert) {
5564 var array = [1, 2, 3],
5565 actual = _.fill(array);
5567 assert.deepEqual(actual, Array(3));
5568 assert.ok(lodashStable.every(actual, function(value, index) {
5569 return index in actual;
5573 QUnit.test('should work with a positive `start`', function(assert) {
5576 var array = [1, 2, 3];
5577 assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
5580 QUnit.test('should work with a `start` >= `length`', function(assert) {
5583 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
5584 var array = [1, 2, 3];
5585 assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
5589 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
5592 var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
5594 var actual = lodashStable.map(falsey, function(start) {
5595 var array = [1, 2, 3];
5596 return _.fill(array, 'a', start);
5599 assert.deepEqual(actual, expected);
5602 QUnit.test('should work with a negative `start`', function(assert) {
5605 var array = [1, 2, 3];
5606 assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
5609 QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
5612 lodashStable.each([-3, -4, -Infinity], function(start) {
5613 var array = [1, 2, 3];
5614 assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
5618 QUnit.test('should work with `start` >= `end`', function(assert) {
5621 lodashStable.each([2, 3], function(start) {
5622 var array = [1, 2, 3];
5623 assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
5627 QUnit.test('should work with a positive `end`', function(assert) {
5630 var array = [1, 2, 3];
5631 assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
5634 QUnit.test('should work with a `end` >= `length`', function(assert) {
5637 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
5638 var array = [1, 2, 3];
5639 assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
5643 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
5646 var expected = lodashStable.map(falsey, function(value) {
5647 return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
5650 var actual = lodashStable.map(falsey, function(end) {
5651 var array = [1, 2, 3];
5652 return _.fill(array, 'a', 0, end);
5655 assert.deepEqual(actual, expected);
5658 QUnit.test('should work with a negative `end`', function(assert) {
5661 var array = [1, 2, 3];
5662 assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
5665 QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
5668 lodashStable.each([-3, -4, -Infinity], function(end) {
5669 var array = [1, 2, 3];
5670 assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
5674 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
5677 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
5679 var actual = lodashStable.map(positions, function(pos) {
5680 var array = [1, 2, 3];
5681 return _.fill.apply(_, [array, 'a'].concat(pos));
5684 assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
5687 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5690 var array = [[1, 2], [3, 4]],
5691 actual = lodashStable.map(array, _.fill);
5693 assert.deepEqual(actual, [[0, 0], [1, 1]]);
5696 QUnit.test('should return a wrapped value when chaining', function(assert) {
5700 var array = [1, 2, 3],
5701 wrapped = _(array).fill('a'),
5702 actual = wrapped.value();
5704 assert.ok(wrapped instanceof _);
5705 assert.strictEqual(actual, array);
5706 assert.deepEqual(actual, ['a', 'a', 'a']);
5709 skipAssert(assert, 3);
5714 /*--------------------------------------------------------------------------*/
5716 QUnit.module('lodash.filter');
5719 var array = [1, 2, 3];
5721 QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
5724 assert.deepEqual(_.filter(array, isEven), [2]);
5727 QUnit.test('should iterate over an object with numeric keys (test in Mobile Safari 8)', function(assert) {
5730 // Trigger a mobile Safari 8 JIT bug.
5731 // See https://github.com/lodash/lodash/issues/799.
5733 object = { '1': 'foo', '8': 'bar', '50': 'baz' };
5735 lodashStable.times(1000, function(assert) {
5736 _.filter([], stubTrue);
5739 _.filter(object, function() {
5744 assert.strictEqual(counter, 3);
5748 /*--------------------------------------------------------------------------*/
5750 lodashStable.each(['find', 'findLast', 'findIndex', 'findLastIndex', 'findKey', 'findLastKey'], function(methodName) {
5751 QUnit.module('lodash.' + methodName);
5753 var func = _[methodName];
5763 'find': [objects[1], undefined, objects[2]],
5764 'findLast': [objects[2], undefined, objects[2]],
5765 'findIndex': [1, -1, 2],
5766 'findLastIndex': [2, -1, 2],
5767 'findKey': ['1', undefined, '2'],
5768 'findLastKey': ['2', undefined, '2']
5771 QUnit.test('`_.' + methodName + '` should return the found value', function(assert) {
5774 assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
5777 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` if value is not found', function(assert) {
5780 assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
5783 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
5786 assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
5789 QUnit.test('`_.' + methodName + '` should work with `_.matchesProperty` shorthands', function(assert) {
5792 assert.strictEqual(func(objects, ['b', 2]), expected[2]);
5795 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
5798 assert.strictEqual(func(objects, 'b'), expected[0]);
5801 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` for empty collections', function(assert) {
5804 var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
5805 expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
5807 var actual = lodashStable.map(emptyValues, function(value) {
5809 return func(value, { 'a': 3 });
5813 assert.deepEqual(actual, expecting);
5818 var array = [1, 2, 3, 4];
5821 'find': [0, 1, 2, 3],
5822 'findLast': [3, 2, 1, 0],
5823 'findIndex': [0, 1, 2, 3],
5824 'findLastIndex': [3, 2, 1, 0]
5827 if (expected != null) {
5828 QUnit.test('`_.' + methodName + '` should pass the index as the second argument for `iteratee`', function(assert) {
5833 func(array, function(n, index) {
5838 assert.deepEqual(actual, expected);
5844 var array = [1, 2, 3, 4];
5846 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
5859 assert.strictEqual(_(array)[methodName](), expected);
5866 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
5870 assert.ok(_(array).chain()[methodName]() instanceof _);
5877 QUnit.test('`_.' + methodName + '` should not execute immediately when explicitly chaining', function(assert) {
5881 var wrapped = _(array).chain()[methodName]();
5882 assert.strictEqual(wrapped.__wrapped__, array);
5889 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
5893 var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5896 lodashStable.times(2, function(index) {
5897 var array = index ? largeArray : smallArray,
5898 wrapped = _(array).filter(isEven);
5900 assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
5904 skipAssert(assert, 2);
5917 if (expected != null) {
5918 QUnit.test('`_.' + methodName + '` should work with an object for `collection`', function(assert) {
5921 var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(n) {
5925 assert.strictEqual(actual, expected);
5932 'find': ['a', 'b', 'c'],
5933 'findLast': ['c', 'b', 'a'],
5934 'findKey': ['a', 'b', 'c'],
5935 'findLastKey': ['c', 'b', 'a']
5938 if (expected != null) {
5939 QUnit.test('`_.' + methodName + '` should pass the key as the second argument for `iteratee`', function(assert) {
5944 func({ 'a': 1, 'b': 2, 'c': 3 }, function(n, key) {
5949 assert.deepEqual(actual, expected);
5955 /*--------------------------------------------------------------------------*/
5957 QUnit.module('lodash.find and lodash.findLast');
5959 lodashStable.each(['find', 'findLast'], function(methodName) {
5960 var isFind = methodName == 'find';
5962 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5968 array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5969 iteratee = function(value) { mapCount++; return square(value); },
5970 predicate = function(value) { findCount++; return isEven(value); },
5971 actual = _(array).map(iteratee)[methodName](predicate);
5973 assert.strictEqual(findCount, isFind ? 2 : 1);
5974 assert.strictEqual(mapCount, isFind ? 2 : 1);
5975 assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
5978 skipAssert(assert, 3);
5983 /*--------------------------------------------------------------------------*/
5985 QUnit.module('lodash.find and lodash.includes');
5987 lodashStable.each(['includes', 'find'], function(methodName) {
5988 var args = (function() { return arguments; }(1, 2, 3, 4)),
5989 func = _[methodName],
5990 isIncludes = methodName == 'includes',
5991 resolve = methodName == 'find' ? lodashStable.curry(lodashStable.eq) : identity;
5994 'an `arguments` object': args,
5995 'an array': [1, 2, 3, 4]
5997 function(collection, key) {
5998 var values = lodashStable.toArray(collection);
6000 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a positive `fromIndex`', function(assert) {
6004 isIncludes || values[2],
6005 isIncludes ? false : undefined
6009 func(collection, resolve(values[2]), 2),
6010 func(collection, resolve(values[1]), 2)
6013 assert.deepEqual(actual, expected);
6016 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
6019 var indexes = [4, 6, Math.pow(2, 32), Infinity];
6021 var expected = lodashStable.map(indexes, function() {
6022 var result = isIncludes ? false : undefined;
6023 return [result, result, result];
6026 var actual = lodashStable.map(indexes, function(fromIndex) {
6028 func(collection, resolve(1), fromIndex),
6029 func(collection, resolve(undefined), fromIndex),
6030 func(collection, resolve(''), fromIndex)
6034 assert.deepEqual(actual, expected);
6037 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
6040 var expected = lodashStable.map(falsey, lodashStable.constant(isIncludes || values[0]));
6042 var actual = lodashStable.map(falsey, function(fromIndex) {
6043 return func(collection, resolve(values[0]), fromIndex);
6046 assert.deepEqual(actual, expected);
6049 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
6053 isIncludes || values[0],
6054 isIncludes || values[0],
6055 isIncludes ? false : undefined
6059 func(collection, resolve(values[0]), 0.1),
6060 func(collection, resolve(values[0]), NaN),
6061 func(collection, resolve(values[0]), '1')
6064 assert.deepEqual(actual, expected);
6067 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex`', function(assert) {
6071 isIncludes || values[2],
6072 isIncludes ? false : undefined
6076 func(collection, resolve(values[2]), -2),
6077 func(collection, resolve(values[1]), -2)
6080 assert.deepEqual(actual, expected);
6083 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
6086 var indexes = [-4, -6, -Infinity],
6087 expected = lodashStable.map(indexes, lodashStable.constant(isIncludes || values[0]));
6089 var actual = lodashStable.map(indexes, function(fromIndex) {
6090 return func(collection, resolve(values[0]), fromIndex);
6093 assert.deepEqual(actual, expected);
6098 /*--------------------------------------------------------------------------*/
6100 QUnit.module('lodash.findIndex and lodash.indexOf');
6102 lodashStable.each(['findIndex', 'indexOf'], function(methodName) {
6103 var array = [1, 2, 3, 1, 2, 3],
6104 func = _[methodName],
6105 resolve = methodName == 'findIndex' ? lodashStable.curry(lodashStable.eq) : identity;
6107 QUnit.test('`_.' + methodName + '` should return the index of the first matched value', function(assert) {
6110 assert.strictEqual(func(array, resolve(3)), 2);
6113 QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
6116 assert.strictEqual(func(array, resolve(1), 2), 3);
6119 QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
6122 var values = [6, 8, Math.pow(2, 32), Infinity],
6123 expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
6125 var actual = lodashStable.map(values, function(fromIndex) {
6127 func(array, resolve(undefined), fromIndex),
6128 func(array, resolve(1), fromIndex),
6129 func(array, resolve(''), fromIndex)
6133 assert.deepEqual(actual, expected);
6136 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
6139 assert.strictEqual(func(array, resolve(2), -3), 4);
6142 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
6145 var values = [-6, -8, -Infinity],
6146 expected = lodashStable.map(values, stubZero);
6148 var actual = lodashStable.map(values, function(fromIndex) {
6149 return func(array, resolve(1), fromIndex);
6152 assert.deepEqual(actual, expected);
6155 QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values as `0`', function(assert) {
6158 var expected = lodashStable.map(falsey, stubZero);
6160 var actual = lodashStable.map(falsey, function(fromIndex) {
6161 return func(array, resolve(1), fromIndex);
6164 assert.deepEqual(actual, expected);
6167 QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
6170 assert.strictEqual(func(array, resolve(2), 1.2), 1);
6174 /*--------------------------------------------------------------------------*/
6176 QUnit.module('lodash.findLast');
6179 var args = (function() { return arguments; }(1, 2, 3, 4)),
6180 resolve = lodashStable.curry(lodashStable.eq);
6183 'an `arguments` object': args,
6184 'an array': [1, 2, 3, 4],
6186 function(collection, key) {
6187 var values = lodashStable.toArray(collection);
6189 QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
6198 _.findLast(collection, resolve(values[2]), 2),
6199 _.findLast(collection, resolve(values[3]), 2)
6202 assert.deepEqual(actual, expected);
6205 QUnit.test('should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
6208 var indexes = [4, 6, Math.pow(2, 32), Infinity];
6210 var expected = lodashStable.map(indexes, lodashStable.constant([values[0], undefined, undefined]));
6212 var actual = lodashStable.map(indexes, function(fromIndex) {
6214 _.findLast(collection, resolve(1), fromIndex),
6215 _.findLast(collection, resolve(undefined), fromIndex),
6216 _.findLast(collection, resolve(''), fromIndex)
6220 assert.deepEqual(actual, expected);
6223 QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values correctly', function(assert) {
6226 var expected = lodashStable.map(falsey, function(value) {
6227 return value === undefined ? values[3] : undefined;
6230 var actual = lodashStable.map(falsey, function(fromIndex) {
6231 return _.findLast(collection, resolve(values[3]), fromIndex);
6234 assert.deepEqual(actual, expected);
6237 QUnit.test('should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
6247 _.findLast(collection, resolve(values[0]), 0.1),
6248 _.findLast(collection, resolve(values[0]), NaN),
6249 _.findLast(collection, resolve(values[2]), '1')
6252 assert.deepEqual(actual, expected);
6255 QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
6264 _.findLast(collection, resolve(values[2]), -2),
6265 _.findLast(collection, resolve(values[3]), -2)
6268 assert.deepEqual(actual, expected);
6271 QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
6274 var indexes = [-4, -6, -Infinity],
6275 expected = lodashStable.map(indexes, lodashStable.constant(values[0]));
6277 var actual = lodashStable.map(indexes, function(fromIndex) {
6278 return _.findLast(collection, resolve(values[0]), fromIndex);
6281 assert.deepEqual(actual, expected);
6286 /*--------------------------------------------------------------------------*/
6288 QUnit.module('lodash.flip');
6292 return slice.call(arguments);
6295 QUnit.test('should flip arguments provided to `func`', function(assert) {
6298 var flipped = _.flip(fn);
6299 assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
6303 /*--------------------------------------------------------------------------*/
6305 QUnit.module('lodash.flatMapDepth');
6308 var array = [1, [2, [3, [4]], 5]];
6310 QUnit.test('should use a default `depth` of `1`', function(assert) {
6313 assert.deepEqual(_.flatMapDepth(array, identity), [1, 2, [3, [4]], 5]);
6316 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
6319 var values = [, null, undefined],
6320 expected = lodashStable.map(values, lodashStable.constant([1, 2, [3, [4]], 5]));
6322 var actual = lodashStable.map(values, function(value, index) {
6323 return index ? _.flatMapDepth(array, value) : _.flatMapDepth(array);
6326 assert.deepEqual(actual, expected);
6329 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
6332 lodashStable.each([-1, 0], function(depth) {
6333 assert.deepEqual(_.flatMapDepth(array, identity, depth), [1, [2, [3, [4]], 5]]);
6337 QUnit.test('should coerce `depth` to an integer', function(assert) {
6340 assert.deepEqual(_.flatMapDepth(array, identity, 2.2), [1, 2, 3, [4], 5]);
6344 /*--------------------------------------------------------------------------*/
6346 QUnit.module('flatMap methods');
6348 lodashStable.each(['flatMap', 'flatMapDeep', 'flatMapDepth'], function(methodName) {
6349 var func = _[methodName],
6350 array = [1, 2, 3, 4];
6352 function duplicate(n) {
6356 QUnit.test('`_.' + methodName + '` should map values in `array` to a new flattened array', function(assert) {
6359 var actual = func(array, duplicate),
6360 expected = lodashStable.flatten(lodashStable.map(array, duplicate));
6362 assert.deepEqual(actual, expected);
6365 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
6368 var objects = [{ 'a': [1, 2] }, { 'a': [3, 4] }];
6369 assert.deepEqual(func(objects, 'a'), array);
6372 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
6378 Foo.prototype.b = [3, 4];
6380 var actual = func(new Foo, identity);
6381 assert.deepEqual(actual, [1, 2]);
6384 QUnit.test('`_.' + methodName + '` should use `_.identity` when `iteratee` is nullish', function(assert) {
6387 var array = [[1, 2], [3, 4]],
6388 object = { 'a': [1, 2], 'b': [3, 4] },
6389 values = [, null, undefined],
6390 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
6392 lodashStable.each([array, object], function(collection) {
6393 var actual = lodashStable.map(values, function(value, index) {
6394 return index ? func(collection, value) : func(collection);
6397 assert.deepEqual(actual, expected);
6401 QUnit.test('`_.' + methodName + '` should accept a falsey `collection` argument', function(assert) {
6404 var expected = lodashStable.map(falsey, stubArray);
6406 var actual = lodashStable.map(falsey, function(collection, index) {
6408 return index ? func(collection) : func();
6412 assert.deepEqual(actual, expected);
6415 QUnit.test('`_.' + methodName + '` should treat number values for `collection` as empty', function(assert) {
6418 assert.deepEqual(func(1), []);
6421 QUnit.test('`_.' + methodName + '` should work with objects with non-number length properties', function(assert) {
6424 var object = { 'length': [1, 2] };
6425 assert.deepEqual(func(object, identity), [1, 2]);
6429 /*--------------------------------------------------------------------------*/
6431 QUnit.module('lodash.flattenDepth');
6434 var array = [1, [2, [3, [4]], 5]];
6436 QUnit.test('should use a default `depth` of `1`', function(assert) {
6439 assert.deepEqual(_.flattenDepth(array), [1, 2, [3, [4]], 5]);
6442 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
6445 lodashStable.each([-1, 0], function(depth) {
6446 assert.deepEqual(_.flattenDepth(array, depth), [1, [2, [3, [4]], 5]]);
6450 QUnit.test('should coerce `depth` to an integer', function(assert) {
6453 assert.deepEqual(_.flattenDepth(array, 2.2), [1, 2, 3, [4], 5]);
6457 /*--------------------------------------------------------------------------*/
6459 QUnit.module('flatten methods');
6462 var args = arguments,
6463 array = [1, [2, [3, [4]], 5]];
6465 QUnit.test('should flatten `arguments` objects', function(assert) {
6468 var array = [args, [args]];
6470 assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
6471 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
6472 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);
6475 QUnit.test('should treat sparse arrays as dense', function(assert) {
6478 var array = [[1, 2, 3], Array(3)],
6479 expected = [1, 2, 3];
6481 expected.push(undefined, undefined, undefined);
6483 lodashStable.each([_.flatten(array), _.flattenDeep(array), _.flattenDepth(array)], function(actual) {
6484 assert.deepEqual(actual, expected);
6485 assert.ok('4' in actual);
6489 QUnit.test('should work with extremely large arrays', function(assert) {
6492 lodashStable.times(3, function(index) {
6493 var expected = Array(5e5);
6495 var func = _.flatten;
6497 func = _.flattenDeep;
6498 } else if (index == 2) {
6499 func = _.flattenDepth;
6501 assert.deepEqual(func([expected]), expected);
6503 assert.ok(false, e.message);
6508 QUnit.test('should work with empty arrays', function(assert) {
6511 var array = [[], [[]], [[], [[[]]]]];
6513 assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
6514 assert.deepEqual(_.flattenDeep(array), []);
6515 assert.deepEqual(_.flattenDepth(array, 2), [[[]]]);
6518 QUnit.test('should support flattening of nested arrays', function(assert) {
6521 assert.deepEqual(_.flatten(array), [1, 2, [3, [4]], 5]);
6522 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
6523 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, [4], 5]);
6526 QUnit.test('should return an empty array for non array-like objects', function(assert) {
6530 nonArray = { 'a': 1 };
6532 assert.deepEqual(_.flatten(nonArray), expected);
6533 assert.deepEqual(_.flattenDeep(nonArray), expected);
6534 assert.deepEqual(_.flattenDepth(nonArray, 2), expected);
6537 QUnit.test('should return a wrapped value when chaining', function(assert) {
6541 var wrapped = _(array),
6542 actual = wrapped.flatten();
6544 assert.ok(actual instanceof _);
6545 assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);
6547 actual = wrapped.flattenDeep();
6549 assert.ok(actual instanceof _);
6550 assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);
6552 actual = wrapped.flattenDepth(2);
6554 assert.ok(actual instanceof _);
6555 assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);
6558 skipAssert(assert, 6);
6563 /*--------------------------------------------------------------------------*/
6565 QUnit.module('flow methods');
6567 lodashStable.each(['flow', 'flowRight'], function(methodName) {
6568 var func = _[methodName],
6569 isFlow = methodName == 'flow';
6571 QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
6574 var fixed = function(n) { return n.toFixed(1); },
6575 combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
6577 assert.strictEqual(combined(1, 2), '9.0');
6580 QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
6583 assert.notStrictEqual(func(noop), noop);
6586 QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are given', function(assert) {
6589 _.times(2, function(index) {
6591 var combined = index ? func([]) : func();
6592 assert.strictEqual(combined('a'), 'a');
6594 assert.ok(false, e.message);
6596 assert.strictEqual(combined.length, 0);
6597 assert.notStrictEqual(combined, identity);
6601 QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
6604 var curried = _.curry(identity);
6606 var combined = isFlow
6607 ? func(_.head, curried)
6608 : func(curried, _.head);
6610 assert.strictEqual(combined([1]), 1);
6613 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
6618 array = lodashStable.range(LARGE_ARRAY_SIZE),
6619 iteratee = function(value) { mapCount++; return square(value); },
6620 predicate = function(value) { filterCount++; return isEven(value); };
6622 lodashStable.times(2, function(index) {
6623 var filter1 = _.filter,
6624 filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
6625 filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
6628 map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
6629 map3 = (_.map = index ? map2 : map1, map2(iteratee));
6632 take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
6633 take3 = (_.take = index ? take2 : take1, take2(2));
6635 var combined = isFlow
6636 ? func(map3, filter3, _.compact, take3)
6637 : func(take3, _.compact, filter3, map3);
6639 filterCount = mapCount = 0;
6640 assert.deepEqual(combined(array), [4, 16]);
6642 if (!isNpm && WeakMap && WeakMap.name) {
6643 assert.strictEqual(filterCount, 5, 'filterCount');
6644 assert.strictEqual(mapCount, 5, 'mapCount');
6647 skipAssert(assert, 2);
6655 QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
6658 var curried = _.curry(_.ary(_.map, 2), 2),
6659 getProp = curried(curried.placeholder, 'a'),
6660 objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
6662 var combined = isFlow
6663 ? func(getProp, _.uniq)
6664 : func(_.uniq, getProp);
6666 assert.deepEqual(combined(objects), [1, 2]);
6669 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
6673 var wrapped = _(noop)[methodName]();
6674 assert.ok(wrapped instanceof _);
6682 /*--------------------------------------------------------------------------*/
6684 QUnit.module('lodash.forEach');
6687 QUnit.test('should be aliased', function(assert) {
6690 assert.strictEqual(_.each, _.forEach);
6694 /*--------------------------------------------------------------------------*/
6696 QUnit.module('lodash.forEachRight');
6699 QUnit.test('should be aliased', function(assert) {
6702 assert.strictEqual(_.eachRight, _.forEachRight);
6706 /*--------------------------------------------------------------------------*/
6708 QUnit.module('forIn methods');
6710 lodashStable.each(['forIn', 'forInRight'], function(methodName) {
6711 var func = _[methodName];
6713 QUnit.test('`_.' + methodName + '` iterates over inherited string keyed properties', function(assert) {
6719 Foo.prototype.b = 2;
6722 func(new Foo, function(value, key) { keys.push(key); });
6723 assert.deepEqual(keys.sort(), ['a', 'b']);
6727 /*--------------------------------------------------------------------------*/
6729 QUnit.module('forOwn methods');
6731 lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
6732 var func = _[methodName];
6734 QUnit.test('`_.' + methodName + '` should iterate over `length` properties', function(assert) {
6737 var object = { '0': 'zero', '1': 'one', 'length': 2 },
6740 func(object, function(value, prop) { props.push(prop); });
6741 assert.deepEqual(props.sort(), ['0', '1', 'length']);
6745 /*--------------------------------------------------------------------------*/
6747 QUnit.module('iteration methods');
6781 var arrayMethods = [
6788 var collectionMethods = [
6807 var forInMethods = [
6814 var iterationMethods = [
6824 var objectMethods = [
6837 var rightMethods = [
6846 var unwrappedMethods = [
6869 lodashStable.each(methods, function(methodName) {
6870 var array = [1, 2, 3],
6871 func = _[methodName],
6872 isBy = /(^partition|By)$/.test(methodName),
6873 isFind = /^find/.test(methodName),
6874 isOmitPick = /^(?:omit|pick)By$/.test(methodName),
6875 isSome = methodName == 'some';
6877 QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
6882 expected = [1, 0, array];
6884 func(array, function() {
6885 args || (args = slice.call(arguments));
6888 if (lodashStable.includes(rightMethods, methodName)) {
6892 if (lodashStable.includes(objectMethods, methodName)) {
6896 expected.length = isOmitPick ? 2 : 1;
6898 assert.deepEqual(args, expected);
6905 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
6912 var expected = lodashStable.includes(objectMethods, methodName)
6913 ? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
6914 : [[1, 0, array], [undefined, 1, array], [3, 2, array]];
6917 expected = lodashStable.map(expected, function(args) {
6918 return args.slice(0, isOmitPick ? 2 : 1);
6921 else if (lodashStable.includes(objectMethods, methodName)) {
6922 expected = lodashStable.map(expected, function(args) {
6927 if (lodashStable.includes(rightMethods, methodName)) {
6931 func(array, function() {
6932 argsList.push(slice.call(arguments));
6933 return !(isFind || isSome);
6936 assert.deepEqual(argsList, expected);
6944 lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
6945 var array = [1, 2, 3],
6946 func = _[methodName],
6947 isEvery = methodName == 'every';
6951 QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
6956 func(array, function(value, key) {
6961 assert.notOk(lodashStable.includes(keys, 'a'));
6969 lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
6970 var array = [1, 2, 3],
6971 isBaseEach = methodName == '_baseEach';
6973 QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
6976 if (!(isBaseEach || isNpm)) {
6977 var wrapped = _(array)[methodName](noop);
6978 assert.ok(wrapped instanceof _);
6986 lodashStable.each(unwrappedMethods, function(methodName) {
6987 var array = [1, 2, 3];
6989 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
6993 var actual = _(array)[methodName](noop);
6994 assert.notOk(actual instanceof _);
7001 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
7005 var wrapped = _(array).chain(),
7006 actual = wrapped[methodName](noop);
7008 assert.ok(actual instanceof _);
7009 assert.notStrictEqual(actual, wrapped);
7012 skipAssert(assert, 2);
7017 lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
7018 var func = _[methodName];
7020 QUnit.test('`_.' + methodName + '` iterates over own string keyed properties of objects', function(assert) {
7026 Foo.prototype.b = 2;
7030 func(new Foo, function(value) { values.push(value); });
7031 assert.deepEqual(values, [1]);
7039 lodashStable.each(iterationMethods, function(methodName) {
7040 var array = [1, 2, 3],
7041 func = _[methodName];
7043 QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
7047 assert.strictEqual(func(array, Boolean), array);
7055 lodashStable.each(collectionMethods, function(methodName) {
7056 var func = _[methodName];
7058 QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
7062 var isIteratedAsObject = function(object) {
7064 func(object, function() { result = true; }, 0);
7068 var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
7069 expected = lodashStable.map(values, stubTrue);
7071 var actual = lodashStable.map(values, function(length) {
7072 return isIteratedAsObject({ 'length': length });
7075 var Foo = function(a) {};
7078 assert.deepEqual(actual, expected);
7079 assert.ok(isIteratedAsObject(Foo));
7080 assert.notOk(isIteratedAsObject({ 'length': 0 }));
7083 skipAssert(assert, 3);
7088 lodashStable.each(methods, function(methodName) {
7089 var func = _[methodName],
7090 isFind = /^find/.test(methodName),
7091 isSome = methodName == 'some',
7092 isReduce = /^reduce/.test(methodName);
7094 QUnit.test('`_.' + methodName + '` should ignore changes to `length`', function(assert) {
7101 func(array, function() {
7105 return !(isFind || isSome);
7106 }, isReduce ? array : null);
7108 assert.strictEqual(count, 1);
7116 lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
7117 var func = _[methodName],
7118 isFind = /^find/.test(methodName),
7119 isSome = methodName == 'some',
7120 isReduce = /^reduce/.test(methodName);
7122 QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
7127 object = { 'a': 1 };
7129 func(object, function() {
7133 return !(isFind || isSome);
7134 }, isReduce ? object : null);
7136 assert.strictEqual(count, 1);
7145 /*--------------------------------------------------------------------------*/
7147 QUnit.module('object assignments');
7149 lodashStable.each(['assign', 'assignIn', 'defaults', 'merge'], function(methodName) {
7150 var func = _[methodName],
7151 isAssign = methodName == 'assign',
7152 isDefaults = methodName == 'defaults';
7154 QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
7157 var expected = lodashStable.map(primitives, function(value) {
7158 var object = Object(value);
7163 var actual = lodashStable.map(primitives, function(value) {
7164 return func(value, { 'a': 1 });
7167 assert.deepEqual(actual, expected);
7170 QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'string keyed source properties', function(assert) {
7176 Foo.prototype.b = 2;
7178 var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
7179 assert.deepEqual(func({}, new Foo), expected);
7182 QUnit.test('`_.' + methodName + '` should not skip a trailing function source', function(assert) {
7188 assert.deepEqual(func({}, { 'a': 1 }, fn), { 'a': 1, 'b': 2 });
7191 QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
7195 assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
7197 assert.ok(false, e.message);
7201 QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
7204 var source = { 'a': 1 },
7205 values = [null, undefined],
7206 expected = lodashStable.map(values, stubTrue);
7208 var actual = lodashStable.map(values, function(value) {
7209 var object = func(value, source);
7210 return object !== source && lodashStable.isEqual(object, source);
7213 assert.deepEqual(actual, expected);
7215 actual = lodashStable.map(values, function(value) {
7216 return lodashStable.isEqual(func(value), {});
7219 assert.deepEqual(actual, expected);
7222 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
7225 var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
7226 expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
7233 assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
7234 assert.deepEqual(lodashStable.reduce(fn, func, { 'a': 0 }), expected);
7237 QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
7241 var wrapped = _({ 'a': 1 }),
7242 actual = wrapped[methodName]({ 'b': 2 });
7244 assert.notStrictEqual(actual, wrapped);
7252 lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
7253 var func = _[methodName];
7255 QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
7259 Foo.prototype.a = 1;
7261 var actual = func(new Foo, { 'b': 2 });
7262 assert.notOk(_.has(actual, 'a'));
7266 lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'merge', 'mergeWith'], function(methodName) {
7267 var func = _[methodName];
7269 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
7272 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
7276 defineProperty(object, 'a', {
7278 'configurable': true,
7279 'get': lodashStable.constant(value),
7280 'set': function() { pass = false; }
7283 func(object, { 'a': value });
7289 lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
7290 var func = _[methodName],
7291 isMergeWith = methodName == 'mergeWith';
7293 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
7297 object = { 'a': 1 },
7298 source = { 'a': 2 },
7299 expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
7301 func(object, source, function() {
7302 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7305 assert.deepEqual(args, expected, 'primitive property values');
7308 object = { 'a': 1 };
7309 source = { 'b': 2 };
7310 expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
7312 func(object, source, function() {
7313 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7316 assert.deepEqual(args, expected, 'missing destination property');
7319 objectValue = [1, 2],
7320 sourceValue = { 'b': 2 };
7322 object = { 'a': objectValue };
7323 source = { 'a': sourceValue };
7324 expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
7327 expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
7329 func(object, source, function() {
7330 argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7333 assert.deepEqual(argsList, expected, 'object property values');
7336 QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
7339 function callback() {}
7342 var actual = func({ 'a': 1 }, callback);
7343 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
7345 actual = func({ 'a': 1 }, callback, { 'c': 3 });
7346 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
7350 /*--------------------------------------------------------------------------*/
7352 QUnit.module('exit early');
7354 lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
7355 var func = _[methodName];
7357 QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
7361 var array = [1, 2, 3],
7364 func(array, function(value, other) {
7365 values.push(lodashStable.isArray(value) ? other : value);
7369 assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
7376 QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
7380 var object = { 'a': 1, 'b': 2, 'c': 3 },
7383 func(object, function(value, other) {
7384 values.push(lodashStable.isArray(value) ? other : value);
7388 assert.strictEqual(values.length, 1);
7396 /*--------------------------------------------------------------------------*/
7398 QUnit.module('`__proto__` property bugs');
7401 QUnit.test('internal data objects should work with the `__proto__` key', function(assert) {
7404 var stringLiteral = '__proto__',
7405 stringObject = Object(stringLiteral),
7406 expected = [stringLiteral, stringObject];
7408 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
7409 return isEven(count) ? stringLiteral : stringObject;
7412 assert.deepEqual(_.difference(largeArray, largeArray), []);
7413 assert.deepEqual(_.intersection(largeArray, largeArray), expected);
7414 assert.deepEqual(_.uniq(largeArray), expected);
7415 assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
7419 /*--------------------------------------------------------------------------*/
7421 QUnit.module('lodash.fromPairs');
7424 QUnit.test('should accept a two dimensional array', function(assert) {
7427 var array = [['a', 1], ['b', 2]],
7428 object = { 'a': 1, 'b': 2 },
7429 actual = _.fromPairs(array);
7431 assert.deepEqual(actual, object);
7434 QUnit.test('should accept a falsey `array` argument', function(assert) {
7437 var expected = lodashStable.map(falsey, stubObject);
7439 var actual = lodashStable.map(falsey, function(array, index) {
7441 return index ? _.fromPairs(array) : _.fromPairs();
7445 assert.deepEqual(actual, expected);
7448 QUnit.test('should not support deep paths', function(assert) {
7451 var actual = _.fromPairs([['a.b', 1]]);
7452 assert.deepEqual(actual, { 'a.b': 1 });
7455 QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
7458 var object = { 'a.b': 1 };
7459 assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
7462 QUnit.test('should work in a lazy sequence', function(assert) {
7466 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
7467 return ['key' + index, index];
7470 var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
7472 assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
7480 /*--------------------------------------------------------------------------*/
7482 QUnit.module('lodash.functions');
7485 QUnit.test('should return the function names of an object', function(assert) {
7488 var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': noop },
7489 actual = _.functions(object).sort();
7491 assert.deepEqual(actual, ['b', 'd']);
7494 QUnit.test('should not include inherited functions', function(assert) {
7501 Foo.prototype.c = noop;
7503 assert.deepEqual(_.functions(new Foo), ['a']);
7507 /*--------------------------------------------------------------------------*/
7509 QUnit.module('lodash.groupBy');
7512 var array = [6.1, 4.2, 6.3];
7514 QUnit.test('should transform keys by `iteratee`', function(assert) {
7517 var actual = _.groupBy(array, Math.floor);
7518 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7521 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
7524 var array = [6, 4, 6],
7525 values = [, null, undefined],
7526 expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
7528 var actual = lodashStable.map(values, function(value, index) {
7529 return index ? _.groupBy(array, value) : _.groupBy(array);
7532 assert.deepEqual(actual, expected);
7535 QUnit.test('should work with `_.property` shorthands', function(assert) {
7538 var actual = _.groupBy(['one', 'two', 'three'], 'length');
7539 assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
7542 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
7545 var actual = _.groupBy(array, function(n) {
7546 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
7549 assert.deepEqual(actual.constructor, [4.2]);
7550 assert.deepEqual(actual.hasOwnProperty, [6.1, 6.3]);
7553 QUnit.test('should work with a number for `iteratee`', function(assert) {
7562 assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
7563 assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
7566 QUnit.test('should work with an object for `collection`', function(assert) {
7569 var actual = _.groupBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
7570 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7573 QUnit.test('should work in a lazy sequence', function(assert) {
7577 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
7578 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
7579 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
7582 var iteratee = function(value) { value.push(value[0]); return value; },
7583 predicate = function(value) { return isEven(value[0]); },
7584 actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
7586 assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
7594 /*--------------------------------------------------------------------------*/
7596 QUnit.module('lodash.gt');
7599 QUnit.test('should return `true` if `value` > `other`', function(assert) {
7602 assert.strictEqual(_.gt(3, 1), true);
7603 assert.strictEqual(_.gt('def', 'abc'), true);
7606 QUnit.test('should return `false` if `value` is <= `other`', function(assert) {
7609 assert.strictEqual(_.gt(1, 3), false);
7610 assert.strictEqual(_.gt(3, 3), false);
7611 assert.strictEqual(_.gt('abc', 'def'), false);
7612 assert.strictEqual(_.gt('def', 'def'), false);
7616 /*--------------------------------------------------------------------------*/
7618 QUnit.module('lodash.gte');
7621 QUnit.test('should return `true` if `value` >= `other`', function(assert) {
7624 assert.strictEqual(_.gte(3, 1), true);
7625 assert.strictEqual(_.gte(3, 3), true);
7626 assert.strictEqual(_.gte('def', 'abc'), true);
7627 assert.strictEqual(_.gte('def', 'def'), true);
7630 QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
7633 assert.strictEqual(_.gte(1, 3), false);
7634 assert.strictEqual(_.gte('abc', 'def'), false);
7638 /*--------------------------------------------------------------------------*/
7640 QUnit.module('has methods');
7642 lodashStable.each(['has', 'hasIn'], function(methodName) {
7643 var args = (function() { return arguments; }(1, 2, 3)),
7644 func = _[methodName],
7645 isHas = methodName == 'has';
7647 QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
7650 var object = { 'a': 1 };
7652 lodashStable.each(['a', ['a']], function(path) {
7653 assert.strictEqual(func(object, path), true);
7657 QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
7660 var object = { 'hasOwnProperty': null, 'a': 1 };
7661 assert.strictEqual(func(object, 'a'), true);
7664 QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
7667 var object = { 'a': { 'b': 2 } };
7669 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7670 assert.strictEqual(func(object, path), true);
7673 lodashStable.each(['a.a', ['a', 'a']], function(path) {
7674 assert.strictEqual(func(object, path), false);
7678 QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
7682 fn.toString = lodashStable.constant('fn');
7684 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
7685 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
7686 values = [null, undefined, fn, {}];
7688 var actual = lodashStable.transform(objects, function(result, object, index) {
7689 var key = values[index];
7690 lodashStable.each([key, [key]], function(path) {
7691 var prop = _.property(key);
7692 result.push(prop(object));
7696 assert.deepEqual(actual, expected);
7699 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7702 assert.strictEqual(func(args, 1), true);
7705 QUnit.test('`_.' + methodName + '` should work with a non-string `path`', function(assert) {
7708 var array = [1, 2, 3];
7710 lodashStable.each([1, [1]], function(path) {
7711 assert.strictEqual(func(array, path), true);
7715 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
7718 var object = { '-0': 'a', '0': 'b' },
7719 props = [-0, Object(-0), 0, Object(0)],
7720 expected = lodashStable.map(props, stubTrue);
7722 var actual = lodashStable.map(props, function(key) {
7723 return func(object, key);
7726 assert.deepEqual(actual, expected);
7729 QUnit.test('`_.' + methodName + '` should work with a symbol `path`', function(assert) {
7737 var symbol2 = Symbol('b');
7738 Foo.prototype[symbol2] = 2;
7739 var path = isHas ? symbol : symbol2;
7741 assert.strictEqual(func(new Foo, path), true);
7748 QUnit.test('`_.' + methodName + '` should work for objects with a `[[Prototype]]` of `null`', function(assert) {
7752 var object = create(null);
7754 assert.strictEqual(func(object, 1), true);
7761 QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
7764 var object = { 'a.b': 1 };
7766 lodashStable.each(['a.b', ['a.b']], function(path) {
7767 assert.strictEqual(func(object, path), true);
7771 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7775 Foo.prototype.a = 1;
7777 lodashStable.each(['a', ['a']], function(path) {
7778 assert.strictEqual(func(new Foo, path), !isHas);
7782 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
7786 Foo.prototype.a = { 'b': 1 };
7788 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7789 assert.strictEqual(func(new Foo, path), !isHas);
7793 QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
7796 var string = Object('abc');
7800 var values = [Array(3), args, string],
7801 expected = lodashStable.map(values, stubTrue);
7803 var actual = lodashStable.map(values, function(value) {
7804 return func(value, 0);
7807 assert.deepEqual(actual, expected);
7809 expected = lodashStable.map(values, lodashStable.constant([true, true]));
7811 actual = lodashStable.map(values, function(value) {
7812 return lodashStable.map(['a[0]', ['a', '0']], function(path) {
7813 return func({ 'a': value }, path);
7817 assert.deepEqual(actual, expected);
7821 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
7824 var values = [null, undefined],
7825 expected = lodashStable.map(values, stubFalse);
7827 lodashStable.each(['constructor', ['constructor']], function(path) {
7828 var actual = lodashStable.map(values, function(value) {
7829 return func(value, path);
7832 assert.deepEqual(actual, expected);
7836 QUnit.test('`_.' + methodName + '` should return `false` for deep paths when `object` is nullish', function(assert) {
7839 var values = [null, undefined],
7840 expected = lodashStable.map(values, stubFalse);
7842 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
7843 var actual = lodashStable.map(values, function(value) {
7844 return func(value, path);
7847 assert.deepEqual(actual, expected);
7851 QUnit.test('`_.' + methodName + '` should return `false` for nullish values of nested objects', function(assert) {
7854 var values = [, null, undefined],
7855 expected = lodashStable.map(values, stubFalse);
7857 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7858 var actual = lodashStable.map(values, function(value, index) {
7859 var object = index ? { 'a': value } : {};
7860 return func(object, path);
7863 assert.deepEqual(actual, expected);
7868 /*--------------------------------------------------------------------------*/
7870 QUnit.module('lodash.head');
7873 var array = [1, 2, 3, 4];
7875 QUnit.test('should return the first element', function(assert) {
7878 assert.strictEqual(_.head(array), 1);
7881 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
7885 assert.strictEqual(_.head([]), undefined);
7886 arrayProto.length = 0;
7889 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7892 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7893 actual = lodashStable.map(array, _.head);
7895 assert.deepEqual(actual, [1, 4, 7]);
7898 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7902 assert.strictEqual(_(array).head(), 1);
7909 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7913 assert.ok(_(array).chain().head() instanceof _);
7920 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
7924 var wrapped = _(array).chain().head();
7925 assert.strictEqual(wrapped.__wrapped__, array);
7932 QUnit.test('should work in a lazy sequence', function(assert) {
7936 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
7939 lodashStable.times(2, function(index) {
7940 var array = index ? largeArray : smallArray,
7941 wrapped = _(array).filter(isEven);
7943 assert.strictEqual(wrapped.head(), _.head(_.filter(array, isEven)));
7947 skipAssert(assert, 2);
7951 QUnit.test('should be aliased', function(assert) {
7954 assert.strictEqual(_.first, _.head);
7958 /*--------------------------------------------------------------------------*/
7960 QUnit.module('lodash.identity');
7963 QUnit.test('should return the first argument given', function(assert) {
7966 var object = { 'name': 'fred' };
7967 assert.strictEqual(_.identity(object), object);
7971 /*--------------------------------------------------------------------------*/
7973 QUnit.module('lodash.includes');
7977 'an `arguments` object': arguments,
7978 'an array': [1, 2, 3, 4],
7979 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
7982 function(collection, key) {
7983 QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
7986 assert.strictEqual(_.includes(collection, 3), true);
7989 QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
7992 assert.strictEqual(_.includes(collection, 5), false);
7995 QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
7998 assert.strictEqual(_.includes(collection, 2, 1.2), true);
8001 QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
8005 assert.strictEqual(_(collection).includes(3), true);
8012 QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
8016 assert.ok(_(collection).chain().includes(3) instanceof _);
8026 'object': Object('abc')
8028 function(collection, key) {
8029 QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
8032 assert.strictEqual(_.includes(collection, 'bc'), true);
8033 assert.strictEqual(_.includes(collection, 'd'), false);
8037 QUnit.test('should return `false` for empty collections', function(assert) {
8040 var expected = lodashStable.map(empties, stubFalse);
8042 var actual = lodashStable.map(empties, function(value) {
8044 return _.includes(value);
8048 assert.deepEqual(actual, expected);
8051 QUnit.test('should work with a string and a `fromIndex` >= `length`', function(assert) {
8054 var string = '1234',
8055 length = string.length,
8056 indexes = [4, 6, Math.pow(2, 32), Infinity];
8058 var expected = lodashStable.map(indexes, function(index) {
8059 return [false, false, index == length];
8062 var actual = lodashStable.map(indexes, function(fromIndex) {
8064 _.includes(string, 1, fromIndex),
8065 _.includes(string, undefined, fromIndex),
8066 _.includes(string, '', fromIndex)
8070 assert.deepEqual(actual, expected);
8073 QUnit.test('should match `NaN`', function(assert) {
8076 assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
8079 QUnit.test('should match `-0` as `0`', function(assert) {
8082 assert.strictEqual(_.includes([-0], 0), true);
8083 assert.strictEqual(_.includes([0], -0), true);
8086 QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
8089 var array1 = [1, 2, 3],
8092 assert.ok(lodashStable.every(array1, lodashStable.partial(_.includes, array2)));
8096 /*--------------------------------------------------------------------------*/
8098 QUnit.module('lodash.initial');
8101 var array = [1, 2, 3];
8103 QUnit.test('should accept a falsey `array` argument', function(assert) {
8106 var expected = lodashStable.map(falsey, stubArray);
8108 var actual = lodashStable.map(falsey, function(array, index) {
8110 return index ? _.initial(array) : _.initial();
8114 assert.deepEqual(actual, expected);
8117 QUnit.test('should exclude last element', function(assert) {
8120 assert.deepEqual(_.initial(array), [1, 2]);
8123 QUnit.test('should return an empty when querying empty arrays', function(assert) {
8126 assert.deepEqual(_.initial([]), []);
8129 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
8132 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
8133 actual = lodashStable.map(array, _.initial);
8135 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
8138 QUnit.test('should work in a lazy sequence', function(assert) {
8142 var array = lodashStable.range(LARGE_ARRAY_SIZE),
8145 var actual = _(array).initial().filter(function(value) {
8151 assert.deepEqual(actual, []);
8152 assert.deepEqual(values, _.initial(array));
8156 actual = _(array).filter(function(value) {
8158 return isEven(value);
8163 assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
8164 assert.deepEqual(values, array);
8167 skipAssert(assert, 4);
8172 /*--------------------------------------------------------------------------*/
8174 QUnit.module('lodash.inRange');
8177 QUnit.test('should work with an `end` argument', function(assert) {
8180 assert.strictEqual(_.inRange(3, 5), true);
8181 assert.strictEqual(_.inRange(5, 5), false);
8182 assert.strictEqual(_.inRange(6, 5), false);
8185 QUnit.test('should work with `start` and `end` arguments', function(assert) {
8188 assert.strictEqual(_.inRange(1, 1, 5), true);
8189 assert.strictEqual(_.inRange(3, 1, 5), true);
8190 assert.strictEqual(_.inRange(0, 1, 5), false);
8191 assert.strictEqual(_.inRange(5, 1, 5), false);
8194 QUnit.test('should treat falsey `start` arguments as `0`', function(assert) {
8197 lodashStable.each(falsey, function(value, index) {
8199 assert.strictEqual(_.inRange(0, value), false);
8200 assert.strictEqual(_.inRange(0, value, 1), true);
8202 assert.strictEqual(_.inRange(0), false);
8207 QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
8210 assert.strictEqual(_.inRange(2, 5, 1), true);
8211 assert.strictEqual(_.inRange(-3, -2, -6), true);
8214 QUnit.test('should work with a floating point `n` value', function(assert) {
8217 assert.strictEqual(_.inRange(0.5, 5), true);
8218 assert.strictEqual(_.inRange(1.2, 1, 5), true);
8219 assert.strictEqual(_.inRange(5.2, 5), false);
8220 assert.strictEqual(_.inRange(0.5, 1, 5), false);
8223 QUnit.test('should coerce arguments to finite numbers', function(assert) {
8226 var actual = [_.inRange(0, '0', 1), _.inRange(0, '1'), _.inRange(0, 0, '1'), _.inRange(0, NaN, 1), _.inRange(-1, -1, NaN)],
8227 expected = lodashStable.map(actual, stubTrue);
8229 assert.deepEqual(actual, expected);
8233 /*--------------------------------------------------------------------------*/
8235 QUnit.module('intersection methods');
8237 lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
8238 var args = (function() { return arguments; }(1, 2, 3)),
8239 func = _[methodName];
8241 QUnit.test('`_.' + methodName + '` should return the intersection of two arrays', function(assert) {
8244 var actual = func([2, 1], [2, 3]);
8245 assert.deepEqual(actual, [2]);
8248 QUnit.test('`_.' + methodName + '` should return the intersection of multiple arrays', function(assert) {
8251 var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
8252 assert.deepEqual(actual, [3]);
8255 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
8258 var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
8259 assert.deepEqual(actual, [1, 2]);
8262 QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
8265 var actual = func([1, 1, 3, 2, 2]);
8266 assert.deepEqual(actual, [1, 3, 2]);
8269 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
8272 var array = [0, 1, null, 3],
8275 assert.deepEqual(func(array, args), expected);
8276 assert.deepEqual(func(args, array), expected);
8279 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
8282 var values = [-0, 0],
8283 expected = lodashStable.map(values, lodashStable.constant(['0']));
8285 var actual = lodashStable.map(values, function(value) {
8286 return lodashStable.map(func(values, [value]), lodashStable.toString);
8289 assert.deepEqual(actual, expected);
8292 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
8295 var actual = func([1, NaN, 3], [NaN, 5, NaN]);
8296 assert.deepEqual(actual, [NaN]);
8299 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
8302 var values = [-0, 0],
8303 expected = lodashStable.map(values, lodashStable.constant(['0']));
8305 var actual = lodashStable.map(values, function(value) {
8306 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
8307 return lodashStable.map(func(values, largeArray), lodashStable.toString);
8310 assert.deepEqual(actual, expected);
8313 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
8316 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
8317 assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
8320 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
8324 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
8326 assert.deepEqual(func([object], largeArray), [object]);
8327 assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
8330 QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
8333 var array = [0, 1, null, 3];
8334 assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
8335 assert.deepEqual(func(null, array, null, [2, 3]), []);
8336 assert.deepEqual(func(array, null, args, null), []);
8339 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
8343 var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
8344 assert.ok(wrapped instanceof _);
8345 assert.deepEqual(wrapped.value(), [1, 2]);
8348 skipAssert(assert, 2);
8353 /*--------------------------------------------------------------------------*/
8355 QUnit.module('lodash.intersectionBy');
8358 QUnit.test('should accept an `iteratee` argument', function(assert) {
8361 var actual = _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8362 assert.deepEqual(actual, [2.1]);
8364 actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8365 assert.deepEqual(actual, [{ 'x': 1 }]);
8368 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
8373 _.intersectionBy([2.1, 1.2], [2.3, 3.4], function() {
8374 args || (args = slice.call(arguments));
8377 assert.deepEqual(args, [2.3]);
8381 /*--------------------------------------------------------------------------*/
8383 QUnit.module('lodash.intersectionWith');
8386 QUnit.test('should work with a `comparator` argument', function(assert) {
8389 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
8390 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
8391 actual = _.intersectionWith(objects, others, lodashStable.isEqual);
8393 assert.deepEqual(actual, [objects[0]]);
8396 QUnit.test('should preserve the sign of `0`', function(assert) {
8400 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubZero),
8401 others = [[0], largeArray],
8402 expected = lodashStable.map(others, lodashStable.constant(['-0']));
8404 var actual = lodashStable.map(others, function(other) {
8405 return lodashStable.map(_.intersectionWith(array, other, lodashStable.eq), lodashStable.toString);
8408 assert.deepEqual(actual, expected);
8412 /*--------------------------------------------------------------------------*/
8414 QUnit.module('lodash.invert');
8417 QUnit.test('should invert an object', function(assert) {
8420 var object = { 'a': 1, 'b': 2 },
8421 actual = _.invert(object);
8423 assert.deepEqual(actual, { '1': 'a', '2': 'b' });
8424 assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
8427 QUnit.test('should work with values that shadow keys on `Object.prototype`', function(assert) {
8430 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
8431 assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
8434 QUnit.test('should work with an object that has a `length` property', function(assert) {
8437 var object = { '0': 'a', '1': 'b', 'length': 2 };
8438 assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
8441 QUnit.test('should return a wrapped value when chaining', function(assert) {
8445 var object = { 'a': 1, 'b': 2 },
8446 wrapped = _(object).invert();
8448 assert.ok(wrapped instanceof _);
8449 assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
8452 skipAssert(assert, 2);
8457 /*--------------------------------------------------------------------------*/
8459 QUnit.module('lodash.invertBy');
8462 var object = { 'a': 1, 'b': 2, 'c': 1 };
8464 QUnit.test('should transform keys by `iteratee`', function(assert) {
8467 var expected = { 'group1': ['a', 'c'], 'group2': ['b'] };
8469 var actual = _.invertBy(object, function(value) {
8470 return 'group' + value;
8473 assert.deepEqual(actual, expected);
8476 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
8479 var values = [, null, undefined],
8480 expected = lodashStable.map(values, lodashStable.constant({ '1': ['a', 'c'], '2': ['b'] }));
8482 var actual = lodashStable.map(values, function(value, index) {
8483 return index ? _.invertBy(object, value) : _.invertBy(object);
8486 assert.deepEqual(actual, expected);
8489 QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
8492 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' },
8493 expected = { 'hasOwnProperty': ['a'], 'constructor': ['b'] };
8495 assert.ok(lodashStable.isEqual(_.invertBy(object), expected));
8498 QUnit.test('should return a wrapped value when chaining', function(assert) {
8502 var wrapped = _(object).invertBy();
8504 assert.ok(wrapped instanceof _);
8505 assert.deepEqual(wrapped.value(), { '1': ['a', 'c'], '2': ['b'] });
8508 skipAssert(assert, 2);
8513 /*--------------------------------------------------------------------------*/
8515 QUnit.module('lodash.invoke');
8518 QUnit.test('should invoke a method on `object`', function(assert) {
8521 var object = { 'a': lodashStable.constant('A') },
8522 actual = _.invoke(object, 'a');
8524 assert.strictEqual(actual, 'A');
8527 QUnit.test('should support invoking with arguments', function(assert) {
8530 var object = { 'a': function(a, b) { return [a, b]; } },
8531 actual = _.invoke(object, 'a', 1, 2);
8533 assert.deepEqual(actual, [1, 2]);
8536 QUnit.test('should not error on nullish elements', function(assert) {
8539 var values = [null, undefined],
8540 expected = lodashStable.map(values, noop);
8542 var actual = lodashStable.map(values, function(value) {
8544 return _.invoke(value, 'a.b', 1, 2);
8548 assert.deepEqual(actual, expected);
8551 QUnit.test('should preserve the sign of `0`', function(assert) {
8554 var object = { '-0': stubA, '0': stubB },
8555 props = [-0, Object(-0), 0, Object(0)];
8557 var actual = lodashStable.map(props, function(key) {
8558 return _.invoke(object, key);
8561 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
8564 QUnit.test('should support deep paths', function(assert) {
8567 var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
8569 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8570 var actual = _.invoke(object, path, 1, 2);
8571 assert.deepEqual(actual, [1, 2]);
8575 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8578 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8580 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8581 assert.deepEqual(_.invoke(object, path), 1);
8585 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8589 var object = { 'a': stubOne };
8590 assert.strictEqual(_(object).invoke('a'), 1);
8597 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8601 var object = { 'a': stubOne };
8602 assert.ok(_(object).chain().invoke('a') instanceof _);
8610 /*--------------------------------------------------------------------------*/
8612 QUnit.module('lodash.invokeMap');
8615 QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
8618 var array = ['a', 'b', 'c'],
8619 actual = _.invokeMap(array, 'toUpperCase');
8621 assert.deepEqual(actual, ['A', 'B', 'C']);
8624 QUnit.test('should support invoking with arguments', function(assert) {
8627 var array = [function() { return slice.call(arguments); }],
8628 actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
8630 assert.deepEqual(actual, [['a', 'b', 'c']]);
8633 QUnit.test('should work with a function for `methodName`', function(assert) {
8636 var array = ['a', 'b', 'c'];
8638 var actual = _.invokeMap(array, function(left, right) {
8639 return left + this.toUpperCase() + right;
8642 assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
8645 QUnit.test('should work with an object for `collection`', function(assert) {
8648 var object = { 'a': 1, 'b': 2, 'c': 3 },
8649 actual = _.invokeMap(object, 'toFixed', 1);
8651 assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
8654 QUnit.test('should treat number values for `collection` as empty', function(assert) {
8657 assert.deepEqual(_.invokeMap(1), []);
8660 QUnit.test('should not error on nullish elements', function(assert) {
8663 var array = ['a', null, undefined, 'd'];
8666 var actual = _.invokeMap(array, 'toUpperCase');
8669 assert.deepEqual(actual, ['A', undefined, undefined, 'D']);
8672 QUnit.test('should not error on elements with missing properties', function(assert) {
8675 var objects = lodashStable.map([null, undefined, stubOne], function(value) {
8676 return { 'a': value };
8679 var expected = lodashStable.map(objects, function(object) {
8680 return object.a ? object.a() : undefined;
8684 var actual = _.invokeMap(objects, 'a');
8687 assert.deepEqual(actual, expected);
8690 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8693 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8695 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8696 assert.deepEqual(_.invokeMap([object], path), [1]);
8700 QUnit.test('should return a wrapped value when chaining', function(assert) {
8704 var array = ['a', 'b', 'c'],
8706 actual = wrapped.invokeMap('toUpperCase');
8708 assert.ok(actual instanceof _);
8709 assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
8711 actual = wrapped.invokeMap(function(left, right) {
8712 return left + this.toUpperCase() + right;
8715 assert.ok(actual instanceof _);
8716 assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
8719 skipAssert(assert, 4);
8723 QUnit.test('should support shortcut fusion', function(assert) {
8728 method = function() { count++; return this.index; };
8730 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
8731 return { 'index': index, 'method': method };
8734 var actual = _(array).invokeMap('method').take(1).value();
8736 assert.strictEqual(count, 1);
8737 assert.deepEqual(actual, [0]);
8740 skipAssert(assert, 2);
8745 /*--------------------------------------------------------------------------*/
8747 QUnit.module('lodash.isArguments');
8750 var args = (function() { return arguments; }(1, 2, 3)),
8751 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
8753 QUnit.test('should return `true` for `arguments` objects', function(assert) {
8756 assert.strictEqual(_.isArguments(args), true);
8757 assert.strictEqual(_.isArguments(strictArgs), true);
8760 QUnit.test('should return `false` for non `arguments` objects', function(assert) {
8763 var expected = lodashStable.map(falsey, stubFalse);
8765 var actual = lodashStable.map(falsey, function(value, index) {
8766 return index ? _.isArguments(value) : _.isArguments();
8769 assert.deepEqual(actual, expected);
8771 assert.strictEqual(_.isArguments([1, 2, 3]), false);
8772 assert.strictEqual(_.isArguments(true), false);
8773 assert.strictEqual(_.isArguments(new Date), false);
8774 assert.strictEqual(_.isArguments(new Error), false);
8775 assert.strictEqual(_.isArguments(_), false);
8776 assert.strictEqual(_.isArguments(slice), false);
8777 assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
8778 assert.strictEqual(_.isArguments(1), false);
8779 assert.strictEqual(_.isArguments(/x/), false);
8780 assert.strictEqual(_.isArguments('a'), false);
8781 assert.strictEqual(_.isArguments(symbol), false);
8784 QUnit.test('should work with an `arguments` object from another realm', function(assert) {
8787 if (realm.arguments) {
8788 assert.strictEqual(_.isArguments(realm.arguments), true);
8796 /*--------------------------------------------------------------------------*/
8798 QUnit.module('lodash.isArray');
8801 var args = arguments;
8803 QUnit.test('should return `true` for arrays', function(assert) {
8806 assert.strictEqual(_.isArray([1, 2, 3]), true);
8809 QUnit.test('should return `false` for non-arrays', function(assert) {
8812 var expected = lodashStable.map(falsey, stubFalse);
8814 var actual = lodashStable.map(falsey, function(value, index) {
8815 return index ? _.isArray(value) : _.isArray();
8818 assert.deepEqual(actual, expected);
8820 assert.strictEqual(_.isArray(args), false);
8821 assert.strictEqual(_.isArray(true), false);
8822 assert.strictEqual(_.isArray(new Date), false);
8823 assert.strictEqual(_.isArray(new Error), false);
8824 assert.strictEqual(_.isArray(_), false);
8825 assert.strictEqual(_.isArray(slice), false);
8826 assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
8827 assert.strictEqual(_.isArray(1), false);
8828 assert.strictEqual(_.isArray(/x/), false);
8829 assert.strictEqual(_.isArray('a'), false);
8830 assert.strictEqual(_.isArray(symbol), false);
8833 QUnit.test('should work with an array from another realm', function(assert) {
8837 assert.strictEqual(_.isArray(realm.array), true);
8845 /*--------------------------------------------------------------------------*/
8847 QUnit.module('lodash.isArrayBuffer');
8850 var args = arguments;
8852 QUnit.test('should return `true` for array buffers', function(assert) {
8856 assert.strictEqual(_.isArrayBuffer(arrayBuffer), true);
8863 QUnit.test('should return `false` for non array buffers', function(assert) {
8866 var expected = lodashStable.map(falsey, stubFalse);
8868 var actual = lodashStable.map(falsey, function(value, index) {
8869 return index ? _.isArrayBuffer(value) : _.isArrayBuffer();
8872 assert.deepEqual(actual, expected);
8874 assert.strictEqual(_.isArrayBuffer(args), false);
8875 assert.strictEqual(_.isArrayBuffer([1, 2, 3]), false);
8876 assert.strictEqual(_.isArrayBuffer(true), false);
8877 assert.strictEqual(_.isArrayBuffer(new Date), false);
8878 assert.strictEqual(_.isArrayBuffer(new Error), false);
8879 assert.strictEqual(_.isArrayBuffer(_), false);
8880 assert.strictEqual(_.isArrayBuffer(slice), false);
8881 assert.strictEqual(_.isArrayBuffer({ 'a': 1 }), false);
8882 assert.strictEqual(_.isArrayBuffer(1), false);
8883 assert.strictEqual(_.isArrayBuffer(/x/), false);
8884 assert.strictEqual(_.isArrayBuffer('a'), false);
8885 assert.strictEqual(_.isArrayBuffer(symbol), false);
8888 QUnit.test('should work with array buffers from another realm', function(assert) {
8891 if (realm.arrayBuffer) {
8892 assert.strictEqual(_.isArrayBuffer(realm.arrayBuffer), true);
8900 /*--------------------------------------------------------------------------*/
8902 QUnit.module('lodash.isArrayLike');
8905 var args = arguments;
8907 QUnit.test('should return `true` for array-like values', function(assert) {
8910 var values = [args, [1, 2, 3], { '0': 1, 'length': 1 }, 'a'],
8911 expected = lodashStable.map(values, stubTrue),
8912 actual = lodashStable.map(values, _.isArrayLike);
8914 assert.deepEqual(actual, expected);
8917 QUnit.test('should return `false` for non-arrays', function(assert) {
8920 var expected = lodashStable.map(falsey, function(value) {
8921 return value === '';
8924 var actual = lodashStable.map(falsey, function(value, index) {
8925 return index ? _.isArrayLike(value) : _.isArrayLike();
8928 assert.deepEqual(actual, expected);
8930 assert.strictEqual(_.isArrayLike(true), false);
8931 assert.strictEqual(_.isArrayLike(new Date), false);
8932 assert.strictEqual(_.isArrayLike(new Error), false);
8933 assert.strictEqual(_.isArrayLike(_), false);
8934 assert.strictEqual(_.isArrayLike(generator), false);
8935 assert.strictEqual(_.isArrayLike(slice), false);
8936 assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
8937 assert.strictEqual(_.isArrayLike(1), false);
8938 assert.strictEqual(_.isArrayLike(/x/), false);
8939 assert.strictEqual(_.isArrayLike(symbol), false);
8942 QUnit.test('should work with an array from another realm', function(assert) {
8946 var values = [realm.arguments, realm.array, realm.string],
8947 expected = lodashStable.map(values, stubTrue),
8948 actual = lodashStable.map(values, _.isArrayLike);
8950 assert.deepEqual(actual, expected);
8958 /*--------------------------------------------------------------------------*/
8960 QUnit.module('lodash.isBoolean');
8963 var args = arguments;
8965 QUnit.test('should return `true` for booleans', function(assert) {
8968 assert.strictEqual(_.isBoolean(true), true);
8969 assert.strictEqual(_.isBoolean(false), true);
8970 assert.strictEqual(_.isBoolean(Object(true)), true);
8971 assert.strictEqual(_.isBoolean(Object(false)), true);
8974 QUnit.test('should return `false` for non-booleans', function(assert) {
8977 var expected = lodashStable.map(falsey, function(value) {
8978 return value === false;
8981 var actual = lodashStable.map(falsey, function(value, index) {
8982 return index ? _.isBoolean(value) : _.isBoolean();
8985 assert.deepEqual(actual, expected);
8987 assert.strictEqual(_.isBoolean(args), false);
8988 assert.strictEqual(_.isBoolean([1, 2, 3]), false);
8989 assert.strictEqual(_.isBoolean(new Date), false);
8990 assert.strictEqual(_.isBoolean(new Error), false);
8991 assert.strictEqual(_.isBoolean(_), false);
8992 assert.strictEqual(_.isBoolean(slice), false);
8993 assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
8994 assert.strictEqual(_.isBoolean(1), false);
8995 assert.strictEqual(_.isBoolean(/x/), false);
8996 assert.strictEqual(_.isBoolean('a'), false);
8997 assert.strictEqual(_.isBoolean(symbol), false);
9000 QUnit.test('should work with a boolean from another realm', function(assert) {
9003 if (realm.boolean) {
9004 assert.strictEqual(_.isBoolean(realm.boolean), true);
9012 /*--------------------------------------------------------------------------*/
9014 QUnit.module('lodash.isBuffer');
9017 var args = arguments;
9019 QUnit.test('should return `true` for buffers', function(assert) {
9023 assert.strictEqual(_.isBuffer(new Buffer(2)), true);
9030 QUnit.test('should return `false` for non-buffers', function(assert) {
9033 var expected = lodashStable.map(falsey, stubFalse);
9035 var actual = lodashStable.map(falsey, function(value, index) {
9036 return index ? _.isBuffer(value) : _.isBuffer();
9039 assert.deepEqual(actual, expected);
9041 assert.strictEqual(_.isBuffer(args), false);
9042 assert.strictEqual(_.isBuffer([1, 2, 3]), false);
9043 assert.strictEqual(_.isBuffer(true), false);
9044 assert.strictEqual(_.isBuffer(new Date), false);
9045 assert.strictEqual(_.isBuffer(new Error), false);
9046 assert.strictEqual(_.isBuffer(_), false);
9047 assert.strictEqual(_.isBuffer(slice), false);
9048 assert.strictEqual(_.isBuffer({ 'a': 1 }), false);
9049 assert.strictEqual(_.isBuffer(1), false);
9050 assert.strictEqual(_.isBuffer(/x/), false);
9051 assert.strictEqual(_.isBuffer('a'), false);
9052 assert.strictEqual(_.isBuffer(symbol), false);
9055 QUnit.test('should return `false` if `Buffer` is not defined', function(assert) {
9058 if (!isStrict && Buffer && lodashBizarro) {
9059 assert.strictEqual(lodashBizarro.isBuffer(new Buffer(2)), false);
9067 /*--------------------------------------------------------------------------*/
9069 QUnit.module('lodash.isDate');
9072 var args = arguments;
9074 QUnit.test('should return `true` for dates', function(assert) {
9077 assert.strictEqual(_.isDate(new Date), true);
9080 QUnit.test('should return `false` for non-dates', function(assert) {
9083 var expected = lodashStable.map(falsey, stubFalse);
9085 var actual = lodashStable.map(falsey, function(value, index) {
9086 return index ? _.isDate(value) : _.isDate();
9089 assert.deepEqual(actual, expected);
9091 assert.strictEqual(_.isDate(args), false);
9092 assert.strictEqual(_.isDate([1, 2, 3]), false);
9093 assert.strictEqual(_.isDate(true), false);
9094 assert.strictEqual(_.isDate(new Error), false);
9095 assert.strictEqual(_.isDate(_), false);
9096 assert.strictEqual(_.isDate(slice), false);
9097 assert.strictEqual(_.isDate({ 'a': 1 }), false);
9098 assert.strictEqual(_.isDate(1), false);
9099 assert.strictEqual(_.isDate(/x/), false);
9100 assert.strictEqual(_.isDate('a'), false);
9101 assert.strictEqual(_.isDate(symbol), false);
9104 QUnit.test('should work with a date object from another realm', function(assert) {
9108 assert.strictEqual(_.isDate(realm.date), true);
9116 /*--------------------------------------------------------------------------*/
9118 QUnit.module('lodash.isElement');
9121 var args = arguments;
9123 function Element() {
9127 QUnit.test('should return `false` for plain objects', function(assert) {
9130 var element = body || new Element;
9132 assert.strictEqual(_.isElement(element), true);
9133 assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
9134 assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
9135 assert.strictEqual(_.isElement({ 'nodeType': true }), false);
9136 assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
9137 assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
9138 assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
9141 QUnit.test('should return `false` for non DOM elements', function(assert) {
9144 var expected = lodashStable.map(falsey, stubFalse);
9146 var actual = lodashStable.map(falsey, function(value, index) {
9147 return index ? _.isElement(value) : _.isElement();
9150 assert.deepEqual(actual, expected);
9152 assert.strictEqual(_.isElement(args), false);
9153 assert.strictEqual(_.isElement([1, 2, 3]), false);
9154 assert.strictEqual(_.isElement(true), false);
9155 assert.strictEqual(_.isElement(new Date), false);
9156 assert.strictEqual(_.isElement(new Error), false);
9157 assert.strictEqual(_.isElement(_), false);
9158 assert.strictEqual(_.isElement(slice), false);
9159 assert.strictEqual(_.isElement({ 'a': 1 }), false);
9160 assert.strictEqual(_.isElement(1), false);
9161 assert.strictEqual(_.isElement(/x/), false);
9162 assert.strictEqual(_.isElement('a'), false);
9163 assert.strictEqual(_.isElement(symbol), false);
9166 QUnit.test('should work with a DOM element from another realm', function(assert) {
9169 if (realm.element) {
9170 assert.strictEqual(_.isElement(realm.element), true);
9178 /*--------------------------------------------------------------------------*/
9180 QUnit.module('lodash.isEmpty');
9183 var args = arguments;
9185 QUnit.test('should return `true` for empty values', function(assert) {
9188 var expected = lodashStable.map(empties, stubTrue),
9189 actual = lodashStable.map(empties, _.isEmpty);
9191 assert.deepEqual(actual, expected);
9193 assert.strictEqual(_.isEmpty(true), true);
9194 assert.strictEqual(_.isEmpty(slice), true);
9195 assert.strictEqual(_.isEmpty(1), true);
9196 assert.strictEqual(_.isEmpty(NaN), true);
9197 assert.strictEqual(_.isEmpty(/x/), true);
9198 assert.strictEqual(_.isEmpty(symbol), true);
9199 assert.strictEqual(_.isEmpty(), true);
9202 assert.strictEqual(_.isEmpty(new Buffer(0)), true);
9203 assert.strictEqual(_.isEmpty(new Buffer(1)), false);
9206 skipAssert(assert, 2);
9210 QUnit.test('should return `false` for non-empty values', function(assert) {
9213 assert.strictEqual(_.isEmpty([0]), false);
9214 assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
9215 assert.strictEqual(_.isEmpty('a'), false);
9218 QUnit.test('should work with an object that has a `length` property', function(assert) {
9221 assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
9224 QUnit.test('should work with `arguments` objects', function(assert) {
9227 assert.strictEqual(_.isEmpty(args), false);
9230 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
9233 function Foo(elements) {
9234 push.apply(this, elements);
9236 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
9238 assert.strictEqual(_.isEmpty(new Foo([])), true);
9241 QUnit.test('should work with maps', function(assert) {
9245 lodashStable.each([new Map, realm.map], function(map) {
9246 assert.strictEqual(_.isEmpty(map), true);
9248 assert.strictEqual(_.isEmpty(map), false);
9253 skipAssert(assert, 4);
9257 QUnit.test('should work with sets', function(assert) {
9261 lodashStable.each([new Set, realm.set], function(set) {
9262 assert.strictEqual(_.isEmpty(set), true);
9264 assert.strictEqual(_.isEmpty(set), false);
9269 skipAssert(assert, 4);
9273 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
9277 Foo.prototype.length = -1;
9279 assert.strictEqual(_.isEmpty(new Foo), true);
9282 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
9286 Foo.prototype.length = MAX_SAFE_INTEGER + 1;
9288 assert.strictEqual(_.isEmpty(new Foo), true);
9291 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
9294 assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
9297 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
9301 assert.strictEqual(_({}).isEmpty(), true);
9308 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
9312 assert.ok(_({}).chain().isEmpty() instanceof _);
9320 /*--------------------------------------------------------------------------*/
9322 QUnit.module('lodash.isEqual');
9325 var symbol1 = Symbol ? Symbol('a') : true,
9326 symbol2 = Symbol ? Symbol('b') : false;
9328 QUnit.test('should compare primitives', function(assert) {
9332 [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
9333 [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
9334 [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
9335 ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
9336 [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
9337 [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
9338 [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
9339 [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
9340 [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
9343 var expected = lodashStable.map(pairs, function(pair) {
9347 var actual = lodashStable.map(pairs, function(pair) {
9348 return _.isEqual(pair[0], pair[1]);
9351 assert.deepEqual(actual, expected);
9354 QUnit.test('should compare arrays', function(assert) {
9357 var array1 = [true, null, 1, 'a', undefined],
9358 array2 = [true, null, 1, 'a', undefined];
9360 assert.strictEqual(_.isEqual(array1, array2), true);
9362 array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9363 array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9365 assert.strictEqual(_.isEqual(array1, array2), true);
9371 array2[1] = undefined;
9374 assert.strictEqual(_.isEqual(array1, array2), true);
9376 array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
9377 array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
9379 assert.strictEqual(_.isEqual(array1, array2), true);
9384 assert.strictEqual(_.isEqual(array1, array2), false);
9389 assert.strictEqual(_.isEqual(array1, array2), false);
9392 QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
9395 var array1 = [1, 2, 3],
9398 array1.every = array1.filter = array1.forEach =
9399 array1.indexOf = array1.lastIndexOf = array1.map =
9400 array1.some = array1.reduce = array1.reduceRight = null;
9402 array2.concat = array2.join = array2.pop =
9403 array2.reverse = array2.shift = array2.slice =
9404 array2.sort = array2.splice = array2.unshift = null;
9406 assert.strictEqual(_.isEqual(array1, array2), true);
9414 assert.strictEqual(_.isEqual(array1, array2), true);
9416 array1 = /c/.exec('abcde');
9419 assert.strictEqual(_.isEqual(array1, array2), true);
9422 QUnit.test('should compare sparse arrays', function(assert) {
9425 var array = Array(1);
9427 assert.strictEqual(_.isEqual(array, Array(1)), true);
9428 assert.strictEqual(_.isEqual(array, [undefined]), true);
9429 assert.strictEqual(_.isEqual(array, Array(2)), false);
9432 QUnit.test('should compare plain objects', function(assert) {
9435 var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
9436 object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
9438 assert.strictEqual(_.isEqual(object1, object2), true);
9440 object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9441 object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9443 assert.strictEqual(_.isEqual(object1, object2), true);
9445 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9446 object2 = { 'a': 3, 'b': 2, 'c': 1 };
9448 assert.strictEqual(_.isEqual(object1, object2), false);
9450 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9451 object2 = { 'd': 1, 'e': 2, 'f': 3 };
9453 assert.strictEqual(_.isEqual(object1, object2), false);
9455 object1 = { 'a': 1, 'b': 2 };
9456 object2 = { 'a': 1, 'b': 2, 'c': 3 };
9458 assert.strictEqual(_.isEqual(object1, object2), false);
9461 QUnit.test('should compare objects regardless of key order', function(assert) {
9464 var object1 = { 'a': 1, 'b': 2, 'c': 3 },
9465 object2 = { 'c': 3, 'a': 1, 'b': 2 };
9467 assert.strictEqual(_.isEqual(object1, object2), true);
9470 QUnit.test('should compare nested objects', function(assert) {
9479 'f': ['a', Object('b'), 'c'],
9481 'h': new Date(2012, 4, 23),
9488 'a': [1, Object(2), 3],
9493 'f': ['a', 'b', 'c'],
9495 'h': new Date(2012, 4, 23),
9501 assert.strictEqual(_.isEqual(object1, object2), true);
9504 QUnit.test('should compare object instances', function(assert) {
9510 Foo.prototype.a = 1;
9515 Bar.prototype.a = 2;
9517 assert.strictEqual(_.isEqual(new Foo, new Foo), true);
9518 assert.strictEqual(_.isEqual(new Foo, new Bar), false);
9519 assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
9520 assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
9523 QUnit.test('should compare objects with constructor properties', function(assert) {
9526 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
9527 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
9528 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
9529 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
9530 assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
9533 QUnit.test('should compare arrays with circular references', function(assert) {
9539 array1.push(array1);
9540 array2.push(array2);
9542 assert.strictEqual(_.isEqual(array1, array2), true);
9547 assert.strictEqual(_.isEqual(array1, array2), true);
9552 assert.strictEqual(_.isEqual(array1, array2), false);
9554 array1 = ['a', 'b', 'c'];
9556 array2 = ['a', ['a', 'b', 'c'], 'c'];
9558 assert.strictEqual(_.isEqual(array1, array2), false);
9561 QUnit.test('should compare objects with circular references', function(assert) {
9567 object1.a = object1;
9568 object2.a = object2;
9570 assert.strictEqual(_.isEqual(object1, object2), true);
9573 object2.b = Object(0);
9575 assert.strictEqual(_.isEqual(object1, object2), true);
9577 object1.c = Object(1);
9578 object2.c = Object(2);
9580 assert.strictEqual(_.isEqual(object1, object2), false);
9582 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9583 object1.b = object1;
9584 object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
9586 assert.strictEqual(_.isEqual(object1, object2), false);
9589 QUnit.test('should compare objects with multiple circular references', function(assert) {
9595 (array1[0].a = array1).push(array1);
9596 (array2[0].a = array2).push(array2);
9598 assert.strictEqual(_.isEqual(array1, array2), true);
9601 array2[0].b = Object(0);
9603 assert.strictEqual(_.isEqual(array1, array2), true);
9605 array1[0].c = Object(1);
9606 array2[0].c = Object(2);
9608 assert.strictEqual(_.isEqual(array1, array2), false);
9611 QUnit.test('should compare objects with complex circular references', function(assert) {
9615 'foo': { 'b': { 'c': { 'd': {} } } },
9620 'foo': { 'b': { 'c': { 'd': {} } } },
9624 object1.foo.b.c.d = object1;
9625 object1.bar.b = object1.foo.b;
9627 object2.foo.b.c.d = object2;
9628 object2.bar.b = object2.foo.b;
9630 assert.strictEqual(_.isEqual(object1, object2), true);
9633 QUnit.test('should compare objects with shared property values', function(assert) {
9645 object1.b = object1.a;
9647 assert.strictEqual(_.isEqual(object1, object2), true);
9650 QUnit.test('should treat objects created by `Object.create(null)` like a plain object', function(assert) {
9656 Foo.prototype.constructor = null;
9658 var object2 = { 'a': 1 };
9659 assert.strictEqual(_.isEqual(new Foo, object2), false);
9662 var object1 = create(null);
9664 assert.strictEqual(_.isEqual(object1, object2), true);
9671 QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
9675 object = { 'toString': function() { return primitive; } },
9676 values = [true, null, 1, 'a', undefined],
9677 expected = lodashStable.map(values, stubFalse);
9679 var actual = lodashStable.map(values, function(value) {
9681 return _.isEqual(object, value);
9684 assert.deepEqual(actual, expected);
9687 QUnit.test('should avoid common type coercions', function(assert) {
9690 assert.strictEqual(_.isEqual(true, Object(false)), false);
9691 assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
9692 assert.strictEqual(_.isEqual(false, Object('')), false);
9693 assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
9694 assert.strictEqual(_.isEqual(0, ''), false);
9695 assert.strictEqual(_.isEqual(1, true), false);
9696 assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
9697 assert.strictEqual(_.isEqual('36', 36), false);
9698 assert.strictEqual(_.isEqual(36, '36'), false);
9701 QUnit.test('should compare `arguments` objects', function(assert) {
9704 var args1 = (function() { return arguments; }(1, 2, 3)),
9705 args2 = (function() { return arguments; }(1, 2, 3)),
9706 args3 = (function() { return arguments; }(1, 2));
9708 assert.strictEqual(_.isEqual(args1, args2), true);
9709 assert.strictEqual(_.isEqual(args1, args3), false);
9712 QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
9715 var args = (function() { return arguments; }(1, 2, 3)),
9716 object = { '0': 1, '1': 2, '2': 3 };
9719 Foo.prototype = object;
9721 assert.strictEqual(_.isEqual(args, object), true);
9722 assert.strictEqual(_.isEqual(object, args), true);
9724 assert.strictEqual(_.isEqual(args, new Foo), false);
9725 assert.strictEqual(_.isEqual(new Foo, args), false);
9728 QUnit.test('should compare array buffers', function(assert) {
9732 var buffer1 = new ArrayBuffer(4),
9733 buffer2 = new ArrayBuffer(8);
9735 assert.strictEqual(_.isEqual(buffer1, buffer2), false);
9737 buffer1 = new Int8Array([-1]).buffer;
9738 buffer2 = new Uint8Array([255]).buffer;
9740 assert.strictEqual(_.isEqual(buffer1, buffer2), true);
9743 skipAssert(assert, 2);
9747 QUnit.test('should compare array views', function(assert) {
9750 lodashStable.times(2, function(index) {
9751 var ns = index ? realm : root;
9753 var pairs = lodashStable.map(arrayViews, function(type, viewIndex) {
9754 var otherType = arrayViews[(viewIndex + 1) % arrayViews.length],
9755 CtorA = ns[type] || function(n) { this.n = n; },
9756 CtorB = ns[otherType] || function(n) { this.n = n; },
9757 bufferA = ns[type] ? new ns.ArrayBuffer(8) : 8,
9758 bufferB = ns[otherType] ? new ns.ArrayBuffer(8) : 8,
9759 bufferC = ns[otherType] ? new ns.ArrayBuffer(16) : 16;
9761 return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
9764 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9766 var actual = lodashStable.map(pairs, function(pair) {
9767 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9770 assert.deepEqual(actual, expected);
9774 QUnit.test('should compare date objects', function(assert) {
9777 var date = new Date(2012, 4, 23);
9779 assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
9780 assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false);
9781 assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false);
9782 assert.strictEqual(_.isEqual(new Date('a'), new Date('a')), false);
9785 QUnit.test('should compare error objects', function(assert) {
9788 var pairs = lodashStable.map([
9796 ], function(type, index, errorTypes) {
9797 var otherType = errorTypes[++index % errorTypes.length],
9799 CtorB = root[otherType];
9801 return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
9804 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9806 var actual = lodashStable.map(pairs, function(pair) {
9807 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9810 assert.deepEqual(actual, expected);
9813 QUnit.test('should compare functions', function(assert) {
9816 function a() { return 1 + 2; }
9817 function b() { return 1 + 2; }
9819 assert.strictEqual(_.isEqual(a, a), true);
9820 assert.strictEqual(_.isEqual(a, b), false);
9823 QUnit.test('should compare maps', function(assert) {
9827 lodashStable.each([[map, new Map], [map, realm.map]], function(maps) {
9833 assert.strictEqual(_.isEqual(map1, map2), false);
9837 assert.strictEqual(_.isEqual(map1, map2), true);
9839 map1['delete']('a');
9841 assert.strictEqual(_.isEqual(map1, map2), true);
9843 map2['delete']('a');
9844 assert.strictEqual(_.isEqual(map1, map2), false);
9851 skipAssert(assert, 8);
9855 QUnit.test('should compare maps with circular references', function(assert) {
9862 map1.set('a', map1);
9863 map2.set('a', map2);
9864 assert.strictEqual(_.isEqual(map1, map2), true);
9868 assert.strictEqual(_.isEqual(map1, map2), false);
9871 skipAssert(assert, 2);
9875 QUnit.test('should compare promises by reference', function(assert) {
9879 lodashStable.each([[promise, Promise.resolve(1)], [promise, realm.promise]], function(promises) {
9880 var promise1 = promises[0],
9881 promise2 = promises[1];
9883 assert.strictEqual(_.isEqual(promise1, promise2), false);
9884 assert.strictEqual(_.isEqual(promise1, promise1), true);
9888 skipAssert(assert, 4);
9892 QUnit.test('should compare regexes', function(assert) {
9895 assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
9896 assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
9897 assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
9898 assert.strictEqual(_.isEqual(/x/, /y/), false);
9899 assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
9902 QUnit.test('should compare sets', function(assert) {
9906 lodashStable.each([[set, new Set], [set, realm.set]], function(sets) {
9912 assert.strictEqual(_.isEqual(set1, set2), false);
9916 assert.strictEqual(_.isEqual(set1, set2), true);
9920 assert.strictEqual(_.isEqual(set1, set2), true);
9923 assert.strictEqual(_.isEqual(set1, set2), false);
9930 skipAssert(assert, 8);
9934 QUnit.test('should compare sets with circular references', function(assert) {
9943 assert.strictEqual(_.isEqual(set1, set2), true);
9947 assert.strictEqual(_.isEqual(set1, set2), false);
9950 skipAssert(assert, 2);
9954 QUnit.test('should work as an iteratee for `_.every`', function(assert) {
9957 var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
9961 QUnit.test('should return `true` for like-objects from different documents', function(assert) {
9965 assert.strictEqual(_.isEqual([1], realm.array), true);
9966 assert.strictEqual(_.isEqual([2], realm.array), false);
9967 assert.strictEqual(_.isEqual({ 'a': 1 }, realm.object), true);
9968 assert.strictEqual(_.isEqual({ 'a': 2 }, realm.object), false);
9971 skipAssert(assert, 4);
9975 QUnit.test('should not error on DOM elements', function(assert) {
9979 var element1 = document.createElement('div'),
9980 element2 = element1.cloneNode(true);
9983 assert.strictEqual(_.isEqual(element1, element2), false);
9985 assert.ok(false, e.message);
9993 QUnit.test('should compare wrapped values', function(assert) {
9996 var stamp = +new Date;
9999 [[1, 2], [1, 2], [1, 2, 3]],
10000 [true, true, false],
10001 [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
10002 [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
10004 [NaN, NaN, Infinity],
10009 lodashStable.each(values, function(vals) {
10011 var wrapped1 = _(vals[0]),
10012 wrapped2 = _(vals[1]),
10013 actual = wrapped1.isEqual(wrapped2);
10015 assert.strictEqual(actual, true);
10016 assert.strictEqual(_.isEqual(_(actual), _(true)), true);
10018 wrapped1 = _(vals[0]);
10019 wrapped2 = _(vals[2]);
10021 actual = wrapped1.isEqual(wrapped2);
10022 assert.strictEqual(actual, false);
10023 assert.strictEqual(_.isEqual(_(actual), _(false)), true);
10026 skipAssert(assert, 4);
10031 QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
10035 var object1 = _({ 'a': 1, 'b': 2 }),
10036 object2 = { 'a': 1, 'b': 2 };
10038 assert.strictEqual(object1.isEqual(object2), true);
10039 assert.strictEqual(_.isEqual(object1, object2), true);
10041 object1 = _({ 'a': 1, 'b': 2 });
10042 object2 = { 'a': 1, 'b': 1 };
10044 assert.strictEqual(object1.isEqual(object2), false);
10045 assert.strictEqual(_.isEqual(object1, object2), false);
10048 skipAssert(assert, 4);
10052 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
10056 assert.strictEqual(_('a').isEqual('a'), true);
10059 skipAssert(assert);
10063 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
10067 assert.ok(_('a').chain().isEqual('a') instanceof _);
10070 skipAssert(assert);
10075 /*--------------------------------------------------------------------------*/
10077 QUnit.module('lodash.isEqualWith');
10080 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
10084 object1 = { 'a': [1, 2], 'b': null },
10085 object2 = { 'a': [1, 2], 'b': null };
10087 object1.b = object2;
10088 object2.b = object1;
10091 [object1, object2],
10092 [object1.a, object2.a, 'a', object1, object2],
10093 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10094 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10095 [object1.b, object2.b, 'b', object1.b, object2.b],
10096 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
10097 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
10098 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
10099 [object1.b.b, object2.b.b, 'b', object1.b.b, object2.b.b]
10102 _.isEqualWith(object1, object2, function(assert) {
10103 var length = arguments.length,
10104 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
10106 argsList.push(args);
10109 assert.deepEqual(argsList, expected);
10112 QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
10115 assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
10116 assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
10117 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
10120 QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
10123 var customizer = function(value) {
10124 return _.isString(value) || undefined;
10127 assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
10128 assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
10129 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10132 QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
10135 var customizer = function(value) {
10136 return _.isString(value) ? false : undefined;
10139 assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
10140 assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
10141 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10144 QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
10147 var actual = _.isEqualWith('a', 'b', stubC);
10148 assert.strictEqual(actual, true);
10150 var values = _.without(falsey, undefined),
10151 expected = lodashStable.map(values, stubFalse);
10154 lodashStable.each(values, function(value) {
10155 actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
10158 assert.deepEqual(actual, expected);
10161 QUnit.test('should ensure `customizer` is a function', function(assert) {
10164 var array = [1, 2, 3],
10165 eq = _.partial(_.isEqualWith, array),
10166 actual = lodashStable.map([array, [1, 0, 3]], eq);
10168 assert.deepEqual(actual, [true, false]);
10171 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
10174 var value = { 'a': { 'b': 2 } };
10177 var map1 = new Map;
10178 map1.set('a', value);
10180 var map2 = new Map;
10181 map2.set('a', value);
10184 var set1 = new Set;
10187 var set2 = new Set;
10190 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
10193 array = lodashStable.toArray(pair[0]);
10196 [pair[0], pair[1]],
10197 [array[0], array[0], 0, array, array],
10198 [array[0][0], array[0][0], 0, array[0], array[0]],
10199 [array[0][1], array[0][1], 1, array[0], array[0]]
10203 expected.length = 2;
10205 _.isEqualWith(pair[0], pair[1], function() {
10206 var length = arguments.length,
10207 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
10209 argsList.push(args);
10212 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
10215 skipAssert(assert);
10221 /*--------------------------------------------------------------------------*/
10223 QUnit.module('lodash.isError');
10226 var args = arguments;
10228 QUnit.test('should return `true` for error objects', function(assert) {
10231 var expected = lodashStable.map(errors, stubTrue);
10233 var actual = lodashStable.map(errors, function(error) {
10234 return _.isError(error) === true;
10237 assert.deepEqual(actual, expected);
10240 QUnit.test('should return `true` for subclassed values', function(assert) {
10243 assert.strictEqual(_.isError(new CustomError('x')), true);
10246 QUnit.test('should return `false` for non error objects', function(assert) {
10249 var expected = lodashStable.map(falsey, stubFalse);
10251 var actual = lodashStable.map(falsey, function(value, index) {
10252 return index ? _.isError(value) : _.isError();
10255 assert.deepEqual(actual, expected);
10257 assert.strictEqual(_.isError(args), false);
10258 assert.strictEqual(_.isError([1, 2, 3]), false);
10259 assert.strictEqual(_.isError(true), false);
10260 assert.strictEqual(_.isError(new Date), false);
10261 assert.strictEqual(_.isError(_), false);
10262 assert.strictEqual(_.isError(slice), false);
10263 assert.strictEqual(_.isError({ 'a': 1 }), false);
10264 assert.strictEqual(_.isError(1), false);
10265 assert.strictEqual(_.isError(/x/), false);
10266 assert.strictEqual(_.isError('a'), false);
10267 assert.strictEqual(_.isError(symbol), false);
10270 QUnit.test('should work with an error object from another realm', function(assert) {
10273 if (realm.errors) {
10274 var expected = lodashStable.map(realm.errors, stubTrue);
10276 var actual = lodashStable.map(realm.errors, function(error) {
10277 return _.isError(error) === true;
10280 assert.deepEqual(actual, expected);
10283 skipAssert(assert);
10288 /*--------------------------------------------------------------------------*/
10290 QUnit.module('lodash.isFinite');
10293 var args = arguments;
10295 QUnit.test('should return `true` for finite values', function(assert) {
10298 var values = [0, 1, 3.14, -1],
10299 expected = lodashStable.map(values, stubTrue),
10300 actual = lodashStable.map(values, _.isFinite);
10302 assert.deepEqual(actual, expected);
10305 QUnit.test('should return `false` for non-finite values', function(assert) {
10308 var values = [NaN, Infinity, -Infinity, Object(1)],
10309 expected = lodashStable.map(values, stubFalse),
10310 actual = lodashStable.map(values, _.isFinite);
10312 assert.deepEqual(actual, expected);
10315 QUnit.test('should return `false` for non-numeric values', function(assert) {
10318 var values = [undefined, [], true, '', ' ', '2px'],
10319 expected = lodashStable.map(values, stubFalse),
10320 actual = lodashStable.map(values, _.isFinite);
10322 assert.deepEqual(actual, expected);
10324 assert.strictEqual(_.isFinite(args), false);
10325 assert.strictEqual(_.isFinite([1, 2, 3]), false);
10326 assert.strictEqual(_.isFinite(true), false);
10327 assert.strictEqual(_.isFinite(new Date), false);
10328 assert.strictEqual(_.isFinite(new Error), false);
10329 assert.strictEqual(_.isFinite({ 'a': 1 }), false);
10330 assert.strictEqual(_.isFinite(/x/), false);
10331 assert.strictEqual(_.isFinite('a'), false);
10332 assert.strictEqual(_.isFinite(symbol), false);
10335 QUnit.test('should return `false` for numeric string values', function(assert) {
10338 var values = ['2', '0', '08'],
10339 expected = lodashStable.map(values, stubFalse),
10340 actual = lodashStable.map(values, _.isFinite);
10342 assert.deepEqual(actual, expected);
10346 /*--------------------------------------------------------------------------*/
10348 QUnit.module('lodash.isFunction');
10351 var args = arguments;
10353 QUnit.test('should return `true` for functions', function(assert) {
10356 assert.strictEqual(_.isFunction(_), true);
10357 assert.strictEqual(_.isFunction(slice), true);
10360 QUnit.test('should return `true` for generator functions', function(assert) {
10363 assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
10366 QUnit.test('should return `true` for array view constructors', function(assert) {
10369 var expected = lodashStable.map(arrayViews, function(type) {
10370 return objToString.call(root[type]) == funcTag;
10373 var actual = lodashStable.map(arrayViews, function(type) {
10374 return _.isFunction(root[type]);
10377 assert.deepEqual(actual, expected);
10380 QUnit.test('should return `false` for non-functions', function(assert) {
10383 var expected = lodashStable.map(falsey, stubFalse);
10385 var actual = lodashStable.map(falsey, function(value, index) {
10386 return index ? _.isFunction(value) : _.isFunction();
10389 assert.deepEqual(actual, expected);
10391 assert.strictEqual(_.isFunction(args), false);
10392 assert.strictEqual(_.isFunction([1, 2, 3]), false);
10393 assert.strictEqual(_.isFunction(true), false);
10394 assert.strictEqual(_.isFunction(new Date), false);
10395 assert.strictEqual(_.isFunction(new Error), false);
10396 assert.strictEqual(_.isFunction({ 'a': 1 }), false);
10397 assert.strictEqual(_.isFunction(1), false);
10398 assert.strictEqual(_.isFunction(/x/), false);
10399 assert.strictEqual(_.isFunction('a'), false);
10400 assert.strictEqual(_.isFunction(symbol), false);
10403 assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
10405 skipAssert(assert);
10409 QUnit.test('should work with host objects in IE 8 document mode (test in IE 11)', function(assert) {
10412 // Trigger a Chakra JIT bug.
10413 // See https://github.com/jashkenas/underscore/issues/1621.
10414 lodashStable.each([body, xml], function(object) {
10416 lodashStable.times(100, _.isFunction);
10417 assert.strictEqual(_.isFunction(object), false);
10420 skipAssert(assert);
10425 QUnit.test('should work with a function from another realm', function(assert) {
10428 if (realm.function) {
10429 assert.strictEqual(_.isFunction(realm.function), true);
10432 skipAssert(assert);
10437 /*--------------------------------------------------------------------------*/
10439 QUnit.module('isInteger methods');
10441 lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
10442 var args = arguments,
10443 func = _[methodName],
10444 isSafe = methodName == 'isSafeInteger';
10446 QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
10449 var values = [-1, 0, 1],
10450 expected = lodashStable.map(values, stubTrue);
10452 var actual = lodashStable.map(values, function(value) {
10453 return func(value);
10456 assert.deepEqual(actual, expected);
10457 assert.strictEqual(func(MAX_INTEGER), !isSafe);
10460 QUnit.test('should return `false` for non-integer number values', function(assert) {
10463 var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
10464 expected = lodashStable.map(values, stubFalse);
10466 var actual = lodashStable.map(values, function(value) {
10467 return func(value);
10470 assert.deepEqual(actual, expected);
10473 QUnit.test('should return `false` for non-numeric values', function(assert) {
10476 var expected = lodashStable.map(falsey, function(value) {
10477 return value === 0;
10480 var actual = lodashStable.map(falsey, function(value, index) {
10481 return index ? func(value) : func();
10484 assert.deepEqual(actual, expected);
10486 assert.strictEqual(func(args), false);
10487 assert.strictEqual(func([1, 2, 3]), false);
10488 assert.strictEqual(func(true), false);
10489 assert.strictEqual(func(new Date), false);
10490 assert.strictEqual(func(new Error), false);
10491 assert.strictEqual(func({ 'a': 1 }), false);
10492 assert.strictEqual(func(/x/), false);
10493 assert.strictEqual(func('a'), false);
10494 assert.strictEqual(func(symbol), false);
10498 /*--------------------------------------------------------------------------*/
10500 QUnit.module('lodash.isLength');
10503 QUnit.test('should return `true` for lengths', function(assert) {
10506 var values = [0, 3, MAX_SAFE_INTEGER],
10507 expected = lodashStable.map(values, stubTrue),
10508 actual = lodashStable.map(values, _.isLength);
10510 assert.deepEqual(actual, expected);
10513 QUnit.test('should return `false` for non-lengths', function(assert) {
10516 var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
10517 expected = lodashStable.map(values, stubFalse),
10518 actual = lodashStable.map(values, _.isLength);
10520 assert.deepEqual(actual, expected);
10524 /*--------------------------------------------------------------------------*/
10526 QUnit.module('lodash.isMap');
10529 var args = arguments;
10531 QUnit.test('should return `true` for maps', function(assert) {
10535 assert.strictEqual(_.isMap(map), true);
10538 skipAssert(assert);
10542 QUnit.test('should return `false` for non-maps', function(assert) {
10545 var expected = lodashStable.map(falsey, stubFalse);
10547 var actual = lodashStable.map(falsey, function(value, index) {
10548 return index ? _.isMap(value) : _.isMap();
10551 assert.deepEqual(actual, expected);
10553 assert.strictEqual(_.isMap(args), false);
10554 assert.strictEqual(_.isMap([1, 2, 3]), false);
10555 assert.strictEqual(_.isMap(true), false);
10556 assert.strictEqual(_.isMap(new Date), false);
10557 assert.strictEqual(_.isMap(new Error), false);
10558 assert.strictEqual(_.isMap(_), false);
10559 assert.strictEqual(_.isMap(slice), false);
10560 assert.strictEqual(_.isMap({ 'a': 1 }), false);
10561 assert.strictEqual(_.isMap(1), false);
10562 assert.strictEqual(_.isMap(/x/), false);
10563 assert.strictEqual(_.isMap('a'), false);
10564 assert.strictEqual(_.isMap(symbol), false);
10565 assert.strictEqual(_.isMap(weakMap), false);
10568 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
10571 var values = [false, true],
10572 expected = lodashStable.map(values, stubFalse);
10574 var actual = lodashStable.map(values, function(value) {
10575 return _.isMap({ 'constructor': value });
10578 assert.deepEqual(actual, expected);
10581 QUnit.test('should work with maps from another realm', function(assert) {
10585 assert.strictEqual(_.isMap(realm.map), true);
10588 skipAssert(assert);
10593 /*--------------------------------------------------------------------------*/
10595 QUnit.module('lodash.isMatch');
10598 QUnit.test('should perform a deep comparison between `object` and `source`', function(assert) {
10601 var object = { 'a': 1, 'b': 2, 'c': 3 };
10602 assert.strictEqual(_.isMatch(object, { 'a': 1 }), true);
10603 assert.strictEqual(_.isMatch(object, { 'b': 1 }), false);
10604 assert.strictEqual(_.isMatch(object, { 'a': 1, 'c': 3 }), true);
10605 assert.strictEqual(_.isMatch(object, { 'c': 3, 'd': 4 }), false);
10607 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
10608 assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true);
10611 QUnit.test('should match inherited string keyed `object` properties', function(assert) {
10617 Foo.prototype.b = 2;
10619 assert.strictEqual(_.isMatch({ 'a': new Foo }, { 'a': { 'b': 2 } }), true);
10622 QUnit.test('should not match by inherited `source` properties', function(assert) {
10628 Foo.prototype.b = 2;
10630 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
10632 expected = lodashStable.map(objects, stubTrue);
10634 var actual = lodashStable.map(objects, function(object) {
10635 return _.isMatch(object, source);
10638 assert.deepEqual(actual, expected);
10641 QUnit.test('should compare a variety of `source` property values', function(assert) {
10644 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
10645 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } };
10647 assert.strictEqual(_.isMatch(object1, object1), true);
10648 assert.strictEqual(_.isMatch(object1, object2), false);
10651 QUnit.test('should match `-0` as `0`', function(assert) {
10654 var object1 = { 'a': -0 },
10655 object2 = { 'a': 0 };
10657 assert.strictEqual(_.isMatch(object1, object2), true);
10658 assert.strictEqual(_.isMatch(object2, object1), true);
10661 QUnit.test('should compare functions by reference', function(assert) {
10664 var object1 = { 'a': lodashStable.noop },
10665 object2 = { 'a': noop },
10666 object3 = { 'a': {} };
10668 assert.strictEqual(_.isMatch(object1, object1), true);
10669 assert.strictEqual(_.isMatch(object2, object1), false);
10670 assert.strictEqual(_.isMatch(object3, object1), false);
10673 QUnit.test('should work with a function for `object`', function(assert) {
10677 Foo.a = { 'b': 2, 'c': 3 };
10679 assert.strictEqual(_.isMatch(Foo, { 'a': { 'b': 2 } }), true);
10682 QUnit.test('should work with a function for `source`', function(assert) {
10687 Foo.b = function() {};
10690 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }];
10692 var actual = lodashStable.map(objects, function(object) {
10693 return _.isMatch(object, Foo);
10696 assert.deepEqual(actual, [false, true]);
10699 QUnit.test('should work with a non-plain `object`', function(assert) {
10702 function Foo(object) { lodashStable.assign(this, object); }
10704 var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) });
10705 assert.strictEqual(_.isMatch(object, { 'a': { 'b': 2 } }), true);
10708 QUnit.test('should partial match arrays', function(assert) {
10711 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
10712 source = { 'a': ['d'] },
10713 predicate = function(object) { return _.isMatch(object, source); },
10714 actual = lodashStable.filter(objects, predicate);
10716 assert.deepEqual(actual, [objects[1]]);
10718 source = { 'a': ['b', 'd'] };
10719 actual = lodashStable.filter(objects, predicate);
10721 assert.deepEqual(actual, []);
10723 source = { 'a': ['d', 'b'] };
10724 actual = lodashStable.filter(objects, predicate);
10726 assert.deepEqual(actual, []);
10729 QUnit.test('should partial match arrays with duplicate values', function(assert) {
10732 var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
10733 source = { 'a': [2, 2] };
10735 var actual = lodashStable.filter(objects, function(object) {
10736 return _.isMatch(object, source);
10739 assert.deepEqual(actual, [objects[1]]);
10742 QUnit.test('should partial match arrays of objects', function(assert) {
10745 var source = { 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] };
10748 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
10749 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
10752 var actual = lodashStable.filter(objects, function(object) {
10753 return _.isMatch(object, source);
10756 assert.deepEqual(actual, [objects[0]]);
10759 QUnit.test('should partial match maps', function(assert) {
10763 var objects = [{ 'a': new Map }, { 'a': new Map }];
10764 objects[0].a.set('a', 1);
10765 objects[1].a.set('a', 1);
10766 objects[1].a.set('b', 2);
10771 var source = { 'a': map },
10772 predicate = function(object) { return _.isMatch(object, source); },
10773 actual = lodashStable.filter(objects, predicate);
10775 assert.deepEqual(actual, [objects[1]]);
10777 map['delete']('b');
10778 actual = lodashStable.filter(objects, predicate);
10780 assert.deepEqual(actual, objects);
10783 actual = lodashStable.filter(objects, predicate);
10785 assert.deepEqual(actual, []);
10788 skipAssert(assert, 3);
10792 QUnit.test('should partial match sets', function(assert) {
10796 var objects = [{ 'a': new Set }, { 'a': new Set }];
10797 objects[0].a.add(1);
10798 objects[1].a.add(1);
10799 objects[1].a.add(2);
10804 var source = { 'a': set },
10805 predicate = function(object) { return _.isMatch(object, source); },
10806 actual = lodashStable.filter(objects, predicate);
10808 assert.deepEqual(actual, [objects[1]]);
10811 actual = lodashStable.filter(objects, predicate);
10813 assert.deepEqual(actual, objects);
10816 actual = lodashStable.filter(objects, predicate);
10818 assert.deepEqual(actual, []);
10821 skipAssert(assert, 3);
10825 QUnit.test('should match `undefined` values', function(assert) {
10828 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
10829 source = { 'b': undefined },
10830 predicate = function(object) { return _.isMatch(object, source); },
10831 actual = lodashStable.map(objects, predicate),
10832 expected = [false, false, true];
10834 assert.deepEqual(actual, expected);
10836 source = { 'a': 1, 'b': undefined };
10837 actual = lodashStable.map(objects, predicate);
10839 assert.deepEqual(actual, expected);
10841 objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }];
10842 source = { 'a': { 'c': undefined } };
10843 actual = lodashStable.map(objects, predicate);
10845 assert.deepEqual(actual, expected);
10848 QUnit.test('should match `undefined` values on primitives', function(assert) {
10852 numberProto.b = undefined;
10855 assert.strictEqual(_.isMatch(1, { 'b': undefined }), true);
10857 assert.ok(false, e.message);
10860 assert.strictEqual(_.isMatch(1, { 'a': 1, 'b': undefined }), true);
10862 assert.ok(false, e.message);
10864 numberProto.a = { 'b': 1, 'c': undefined };
10866 assert.strictEqual(_.isMatch(1, { 'a': { 'c': undefined } }), true);
10868 assert.ok(false, e.message);
10870 delete numberProto.a;
10871 delete numberProto.b;
10874 QUnit.test('should return `false` when `object` is nullish', function(assert) {
10877 var values = [null, undefined],
10878 expected = lodashStable.map(values, stubFalse),
10879 source = { 'a': 1 };
10881 var actual = lodashStable.map(values, function(value) {
10883 return _.isMatch(value, source);
10887 assert.deepEqual(actual, expected);
10890 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
10893 var values = [null, undefined],
10894 expected = lodashStable.map(values, stubTrue),
10897 var actual = lodashStable.map(values, function(value) {
10899 return _.isMatch(value, source);
10903 assert.deepEqual(actual, expected);
10906 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
10909 var object = { 'a': 1 },
10910 expected = lodashStable.map(empties, stubTrue);
10912 var actual = lodashStable.map(empties, function(value) {
10913 return _.isMatch(object, value);
10916 assert.deepEqual(actual, expected);
10919 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
10922 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
10923 source = { 'a': [], 'b': {} };
10925 var actual = lodashStable.filter(objects, function(object) {
10926 return _.isMatch(object, source);
10929 assert.deepEqual(actual, objects);
10933 /*--------------------------------------------------------------------------*/
10935 QUnit.module('lodash.isMatchWith');
10938 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
10942 object1 = { 'a': [1, 2], 'b': null },
10943 object2 = { 'a': [1, 2], 'b': null };
10945 object1.b = object2;
10946 object2.b = object1;
10949 [object1.a, object2.a, 'a', object1, object2],
10950 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10951 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10952 [object1.b, object2.b, 'b', object1, object2],
10953 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
10954 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
10955 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
10956 [object1.b.b, object2.b.b, 'b', object1.b, object2.b],
10957 [object1.b.b.a, object2.b.b.a, 'a', object1.b.b, object2.b.b],
10958 [object1.b.b.a[0], object2.b.b.a[0], 0, object1.b.b.a, object2.b.b.a],
10959 [object1.b.b.a[1], object2.b.b.a[1], 1, object1.b.b.a, object2.b.b.a],
10960 [object1.b.b.b, object2.b.b.b, 'b', object1.b.b, object2.b.b]
10963 _.isMatchWith(object1, object2, function(assert) {
10964 argsList.push(slice.call(arguments, 0, -1));
10967 assert.deepEqual(argsList, expected);
10970 QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
10973 assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
10976 QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
10979 var customizer = function(value) {
10980 return _.isString(value) || undefined;
10983 assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
10984 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10987 QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
10990 var customizer = function(value) {
10991 return _.isString(value) ? false : undefined;
10994 assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
10995 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10998 QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
11001 var object = { 'a': 1 },
11002 actual = _.isMatchWith(object, { 'a': 1 }, stubA);
11004 assert.strictEqual(actual, true);
11006 var expected = lodashStable.map(falsey, stubFalse);
11009 lodashStable.each(falsey, function(value) {
11010 actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
11013 assert.deepEqual(actual, expected);
11016 QUnit.test('should provide `stack` to `customizer`', function(assert) {
11021 _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
11022 actual = _.last(arguments);
11026 ? actual.constructor.name == 'Stack'
11027 : actual instanceof mapCaches.Stack
11031 QUnit.test('should ensure `customizer` is a function', function(assert) {
11034 var object = { 'a': 1 },
11035 matches = _.partial(_.isMatchWith, object),
11036 actual = lodashStable.map([object, { 'a': 2 }], matches);
11038 assert.deepEqual(actual, [true, false]);
11041 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
11044 var value = { 'a': { 'b': 2 } };
11047 var map1 = new Map;
11048 map1.set('a', value);
11050 var map2 = new Map;
11051 map2.set('a', value);
11054 var set1 = new Set;
11057 var set2 = new Set;
11060 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
11063 array = lodashStable.toArray(pair[0]),
11064 object1 = { 'a': pair[0] },
11065 object2 = { 'a': pair[1] };
11068 [pair[0], pair[1], 'a', object1, object2],
11069 [array[0], array[0], 0, array, array],
11070 [array[0][0], array[0][0], 0, array[0], array[0]],
11071 [array[0][1], array[0][1], 1, array[0], array[0]]
11075 expected.length = 2;
11077 _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
11078 argsList.push(slice.call(arguments, 0, -1));
11081 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
11084 skipAssert(assert);
11090 /*--------------------------------------------------------------------------*/
11092 QUnit.module('lodash.isNaN');
11095 var args = arguments;
11097 QUnit.test('should return `true` for NaNs', function(assert) {
11100 assert.strictEqual(_.isNaN(NaN), true);
11101 assert.strictEqual(_.isNaN(Object(NaN)), true);
11104 QUnit.test('should return `false` for non-NaNs', function(assert) {
11107 var expected = lodashStable.map(falsey, function(value) {
11108 return value !== value;
11111 var actual = lodashStable.map(falsey, function(value, index) {
11112 return index ? _.isNaN(value) : _.isNaN();
11115 assert.deepEqual(actual, expected);
11117 assert.strictEqual(_.isNaN(args), false);
11118 assert.strictEqual(_.isNaN([1, 2, 3]), false);
11119 assert.strictEqual(_.isNaN(true), false);
11120 assert.strictEqual(_.isNaN(new Date), false);
11121 assert.strictEqual(_.isNaN(new Error), false);
11122 assert.strictEqual(_.isNaN(_), false);
11123 assert.strictEqual(_.isNaN(slice), false);
11124 assert.strictEqual(_.isNaN({ 'a': 1 }), false);
11125 assert.strictEqual(_.isNaN(1), false);
11126 assert.strictEqual(_.isNaN(Object(1)), false);
11127 assert.strictEqual(_.isNaN(/x/), false);
11128 assert.strictEqual(_.isNaN('a'), false);
11129 assert.strictEqual(_.isNaN(symbol), false);
11132 QUnit.test('should work with `NaN` from another realm', function(assert) {
11135 if (realm.object) {
11136 assert.strictEqual(_.isNaN(realm.nan), true);
11139 skipAssert(assert);
11144 /*--------------------------------------------------------------------------*/
11146 QUnit.module('lodash.isNative');
11149 var args = arguments;
11151 QUnit.test('should return `true` for native methods', function(assert) {
11154 var values = [Array, body && body.cloneNode, create, root.encodeURI, Promise, slice, Uint8Array],
11155 expected = lodashStable.map(values, Boolean),
11156 actual = lodashStable.map(values, _.isNative);
11158 assert.deepEqual(actual, expected);
11161 QUnit.test('should return `false` for non-native methods', function(assert) {
11164 var expected = lodashStable.map(falsey, stubFalse);
11166 var actual = lodashStable.map(falsey, function(value, index) {
11167 return index ? _.isNative(value) : _.isNative();
11170 assert.deepEqual(actual, expected);
11172 assert.strictEqual(_.isNative(args), false);
11173 assert.strictEqual(_.isNative([1, 2, 3]), false);
11174 assert.strictEqual(_.isNative(true), false);
11175 assert.strictEqual(_.isNative(new Date), false);
11176 assert.strictEqual(_.isNative(new Error), false);
11177 assert.strictEqual(_.isNative(_), false);
11178 assert.strictEqual(_.isNative({ 'a': 1 }), false);
11179 assert.strictEqual(_.isNative(1), false);
11180 assert.strictEqual(_.isNative(/x/), false);
11181 assert.strictEqual(_.isNative('a'), false);
11182 assert.strictEqual(_.isNative(symbol), false);
11185 QUnit.test('should work with native functions from another realm', function(assert) {
11188 if (realm.element) {
11189 assert.strictEqual(_.isNative(realm.element.cloneNode), true);
11192 skipAssert(assert);
11194 if (realm.object) {
11195 assert.strictEqual(_.isNative(realm.object.valueOf), true);
11198 skipAssert(assert);
11202 QUnit.test('should throw an error if core-js is detected', function(assert) {
11205 if (!isModularize) {
11206 var lodash = _.runInContext({
11207 '__core-js_shared__': {}
11210 assert.raises(function() { lodash.isNative(noop); });
11213 skipAssert(assert);
11217 QUnit.test('should detect methods masquerading as native', function(assert) {
11221 var path = require('path'),
11222 basePath = path.dirname(filePath),
11223 uid = 'e0gvgyrad1jor',
11224 coreKey = '__core-js_shared__',
11225 fakeSrcKey = 'Symbol(src)_1.' + uid;
11227 root[coreKey] = { 'keys': { 'IE_PROTO': 'Symbol(IE_PROTO)_3.' + uid } };
11228 emptyObject(require.cache);
11230 var baseIsNative = interopRequire(path.join(basePath, '_baseIsNative'));
11231 assert.strictEqual(baseIsNative(slice), true);
11233 slice[fakeSrcKey] = slice + '';
11234 assert.strictEqual(baseIsNative(slice), false);
11236 delete slice[fakeSrcKey];
11237 delete root[coreKey];
11240 skipAssert(assert, 2);
11245 /*--------------------------------------------------------------------------*/
11247 QUnit.module('lodash.isNil');
11250 var args = arguments;
11252 QUnit.test('should return `true` for nullish values', function(assert) {
11255 assert.strictEqual(_.isNil(null), true);
11256 assert.strictEqual(_.isNil(), true);
11257 assert.strictEqual(_.isNil(undefined), true);
11260 QUnit.test('should return `false` for non-nullish values', function(assert) {
11263 var expected = lodashStable.map(falsey, function(value) {
11264 return value == null;
11267 var actual = lodashStable.map(falsey, function(value, index) {
11268 return index ? _.isNil(value) : _.isNil();
11271 assert.deepEqual(actual, expected);
11273 assert.strictEqual(_.isNil(args), false);
11274 assert.strictEqual(_.isNil([1, 2, 3]), false);
11275 assert.strictEqual(_.isNil(true), false);
11276 assert.strictEqual(_.isNil(new Date), false);
11277 assert.strictEqual(_.isNil(new Error), false);
11278 assert.strictEqual(_.isNil(_), false);
11279 assert.strictEqual(_.isNil(slice), false);
11280 assert.strictEqual(_.isNil({ 'a': 1 }), false);
11281 assert.strictEqual(_.isNil(1), false);
11282 assert.strictEqual(_.isNil(/x/), false);
11283 assert.strictEqual(_.isNil('a'), false);
11286 assert.strictEqual(_.isNil(symbol), false);
11289 skipAssert(assert);
11293 QUnit.test('should work with nils from another realm', function(assert) {
11296 if (realm.object) {
11297 assert.strictEqual(_.isNil(realm.null), true);
11298 assert.strictEqual(_.isNil(realm.undefined), true);
11301 skipAssert(assert, 2);
11306 /*--------------------------------------------------------------------------*/
11308 QUnit.module('lodash.isNull');
11311 var args = arguments;
11313 QUnit.test('should return `true` for `null` values', function(assert) {
11316 assert.strictEqual(_.isNull(null), true);
11319 QUnit.test('should return `false` for non `null` values', function(assert) {
11322 var expected = lodashStable.map(falsey, function(value) {
11323 return value === null;
11326 var actual = lodashStable.map(falsey, function(value, index) {
11327 return index ? _.isNull(value) : _.isNull();
11330 assert.deepEqual(actual, expected);
11332 assert.strictEqual(_.isNull(args), false);
11333 assert.strictEqual(_.isNull([1, 2, 3]), false);
11334 assert.strictEqual(_.isNull(true), false);
11335 assert.strictEqual(_.isNull(new Date), false);
11336 assert.strictEqual(_.isNull(new Error), false);
11337 assert.strictEqual(_.isNull(_), false);
11338 assert.strictEqual(_.isNull(slice), false);
11339 assert.strictEqual(_.isNull({ 'a': 1 }), false);
11340 assert.strictEqual(_.isNull(1), false);
11341 assert.strictEqual(_.isNull(/x/), false);
11342 assert.strictEqual(_.isNull('a'), false);
11343 assert.strictEqual(_.isNull(symbol), false);
11346 QUnit.test('should work with nulls from another realm', function(assert) {
11349 if (realm.object) {
11350 assert.strictEqual(_.isNull(realm.null), true);
11353 skipAssert(assert);
11358 /*--------------------------------------------------------------------------*/
11360 QUnit.module('lodash.isNumber');
11363 var args = arguments;
11365 QUnit.test('should return `true` for numbers', function(assert) {
11368 assert.strictEqual(_.isNumber(0), true);
11369 assert.strictEqual(_.isNumber(Object(0)), true);
11370 assert.strictEqual(_.isNumber(NaN), true);
11373 QUnit.test('should return `false` for non-numbers', function(assert) {
11376 var expected = lodashStable.map(falsey, function(value) {
11377 return typeof value == 'number';
11380 var actual = lodashStable.map(falsey, function(value, index) {
11381 return index ? _.isNumber(value) : _.isNumber();
11384 assert.deepEqual(actual, expected);
11386 assert.strictEqual(_.isNumber(args), false);
11387 assert.strictEqual(_.isNumber([1, 2, 3]), false);
11388 assert.strictEqual(_.isNumber(true), false);
11389 assert.strictEqual(_.isNumber(new Date), false);
11390 assert.strictEqual(_.isNumber(new Error), false);
11391 assert.strictEqual(_.isNumber(_), false);
11392 assert.strictEqual(_.isNumber(slice), false);
11393 assert.strictEqual(_.isNumber({ 'a': 1 }), false);
11394 assert.strictEqual(_.isNumber(/x/), false);
11395 assert.strictEqual(_.isNumber('a'), false);
11396 assert.strictEqual(_.isNumber(symbol), false);
11399 QUnit.test('should work with numbers from another realm', function(assert) {
11402 if (realm.number) {
11403 assert.strictEqual(_.isNumber(realm.number), true);
11406 skipAssert(assert);
11410 QUnit.test('should avoid `[xpconnect wrapped native prototype]` in Firefox', function(assert) {
11413 assert.strictEqual(_.isNumber(+'2'), true);
11417 /*--------------------------------------------------------------------------*/
11419 QUnit.module('lodash.isObject');
11422 var args = arguments;
11424 QUnit.test('should return `true` for objects', function(assert) {
11427 assert.strictEqual(_.isObject(args), true);
11428 assert.strictEqual(_.isObject([1, 2, 3]), true);
11429 assert.strictEqual(_.isObject(Object(false)), true);
11430 assert.strictEqual(_.isObject(new Date), true);
11431 assert.strictEqual(_.isObject(new Error), true);
11432 assert.strictEqual(_.isObject(_), true);
11433 assert.strictEqual(_.isObject(slice), true);
11434 assert.strictEqual(_.isObject({ 'a': 1 }), true);
11435 assert.strictEqual(_.isObject(Object(0)), true);
11436 assert.strictEqual(_.isObject(/x/), true);
11437 assert.strictEqual(_.isObject(Object('a')), true);
11440 assert.strictEqual(_.isObject(body), true);
11443 skipAssert(assert);
11446 assert.strictEqual(_.isObject(Object(symbol)), true);
11449 skipAssert(assert);
11453 QUnit.test('should return `false` for non-objects', function(assert) {
11456 var values = falsey.concat(true, 1, 'a', symbol),
11457 expected = lodashStable.map(values, stubFalse);
11459 var actual = lodashStable.map(values, function(value, index) {
11460 return index ? _.isObject(value) : _.isObject();
11463 assert.deepEqual(actual, expected);
11466 QUnit.test('should work with objects from another realm', function(assert) {
11469 if (realm.element) {
11470 assert.strictEqual(_.isObject(realm.element), true);
11473 skipAssert(assert);
11475 if (realm.object) {
11476 assert.strictEqual(_.isObject(realm.boolean), true);
11477 assert.strictEqual(_.isObject(realm.date), true);
11478 assert.strictEqual(_.isObject(realm.function), true);
11479 assert.strictEqual(_.isObject(realm.number), true);
11480 assert.strictEqual(_.isObject(realm.object), true);
11481 assert.strictEqual(_.isObject(realm.regexp), true);
11482 assert.strictEqual(_.isObject(realm.string), true);
11485 skipAssert(assert, 7);
11489 QUnit.test('should avoid V8 bug #2291 (test in Chrome 19-20)', function(assert) {
11492 // Trigger a V8 JIT bug.
11493 // See https://code.google.com/p/v8/issues/detail?id=2291.
11496 // First, have a comparison statement.
11499 // Then perform the check with `object`.
11500 _.isObject(object);
11502 assert.strictEqual(_.isObject('a'), false);
11506 /*--------------------------------------------------------------------------*/
11508 QUnit.module('lodash.isObjectLike');
11511 var args = arguments;
11513 QUnit.test('should return `true` for objects', function(assert) {
11516 assert.strictEqual(_.isObjectLike(args), true);
11517 assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
11518 assert.strictEqual(_.isObjectLike(Object(false)), true);
11519 assert.strictEqual(_.isObjectLike(new Date), true);
11520 assert.strictEqual(_.isObjectLike(new Error), true);
11521 assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
11522 assert.strictEqual(_.isObjectLike(Object(0)), true);
11523 assert.strictEqual(_.isObjectLike(/x/), true);
11524 assert.strictEqual(_.isObjectLike(Object('a')), true);
11527 QUnit.test('should return `false` for non-objects', function(assert) {
11530 var values = falsey.concat(true, _, slice, 1, 'a', symbol),
11531 expected = lodashStable.map(values, stubFalse);
11533 var actual = lodashStable.map(values, function(value, index) {
11534 return index ? _.isObjectLike(value) : _.isObjectLike();
11537 assert.deepEqual(actual, expected);
11540 QUnit.test('should work with objects from another realm', function(assert) {
11543 if (realm.object) {
11544 assert.strictEqual(_.isObjectLike(realm.boolean), true);
11545 assert.strictEqual(_.isObjectLike(realm.date), true);
11546 assert.strictEqual(_.isObjectLike(realm.number), true);
11547 assert.strictEqual(_.isObjectLike(realm.object), true);
11548 assert.strictEqual(_.isObjectLike(realm.regexp), true);
11549 assert.strictEqual(_.isObjectLike(realm.string), true);
11552 skipAssert(assert, 6);
11557 /*--------------------------------------------------------------------------*/
11559 QUnit.module('lodash.isPlainObject');
11562 var element = document && document.createElement('div');
11564 QUnit.test('should detect plain objects', function(assert) {
11571 assert.strictEqual(_.isPlainObject({}), true);
11572 assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
11573 assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
11574 assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
11575 assert.strictEqual(_.isPlainObject(new Foo(1)), false);
11578 QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
11582 var object = create(null);
11583 assert.strictEqual(_.isPlainObject(object), true);
11585 object.constructor = objectProto.constructor;
11586 assert.strictEqual(_.isPlainObject(object), true);
11589 skipAssert(assert, 2);
11593 QUnit.test('should return `true` for plain objects with a custom `valueOf` property', function(assert) {
11596 assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
11599 var valueOf = element.valueOf;
11600 element.valueOf = 0;
11602 assert.strictEqual(_.isPlainObject(element), false);
11603 element.valueOf = valueOf;
11606 skipAssert(assert);
11610 QUnit.test('should return `false` for objects with a custom `[[Prototype]]`', function(assert) {
11614 var object = create({ 'a': 1 });
11615 assert.strictEqual(_.isPlainObject(object), false);
11618 skipAssert(assert);
11622 QUnit.test('should return `false` for DOM elements', function(assert) {
11626 assert.strictEqual(_.isPlainObject(element), false);
11628 skipAssert(assert);
11632 QUnit.test('should return `false` for Object objects without a `toStringTag` of "Object"', function(assert) {
11635 assert.strictEqual(_.isPlainObject(arguments), false);
11636 assert.strictEqual(_.isPlainObject(Error), false);
11637 assert.strictEqual(_.isPlainObject(Math), false);
11640 QUnit.test('should return `false` for non-objects', function(assert) {
11643 var expected = lodashStable.map(falsey, stubFalse);
11645 var actual = lodashStable.map(falsey, function(value, index) {
11646 return index ? _.isPlainObject(value) : _.isPlainObject();
11649 assert.deepEqual(actual, expected);
11651 assert.strictEqual(_.isPlainObject(true), false);
11652 assert.strictEqual(_.isPlainObject('a'), false);
11653 assert.strictEqual(_.isPlainObject(symbol), false);
11656 QUnit.test('should work with objects from another realm', function(assert) {
11659 if (realm.object) {
11660 assert.strictEqual(_.isPlainObject(realm.object), true);
11663 skipAssert(assert);
11668 /*--------------------------------------------------------------------------*/
11670 QUnit.module('lodash.isRegExp');
11673 var args = arguments;
11675 QUnit.test('should return `true` for regexes', function(assert) {
11678 assert.strictEqual(_.isRegExp(/x/), true);
11679 assert.strictEqual(_.isRegExp(RegExp('x')), true);
11682 QUnit.test('should return `false` for non-regexes', function(assert) {
11685 var expected = lodashStable.map(falsey, stubFalse);
11687 var actual = lodashStable.map(falsey, function(value, index) {
11688 return index ? _.isRegExp(value) : _.isRegExp();
11691 assert.deepEqual(actual, expected);
11693 assert.strictEqual(_.isRegExp(args), false);
11694 assert.strictEqual(_.isRegExp([1, 2, 3]), false);
11695 assert.strictEqual(_.isRegExp(true), false);
11696 assert.strictEqual(_.isRegExp(new Date), false);
11697 assert.strictEqual(_.isRegExp(new Error), false);
11698 assert.strictEqual(_.isRegExp(_), false);
11699 assert.strictEqual(_.isRegExp(slice), false);
11700 assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
11701 assert.strictEqual(_.isRegExp(1), false);
11702 assert.strictEqual(_.isRegExp('a'), false);
11703 assert.strictEqual(_.isRegExp(symbol), false);
11706 QUnit.test('should work with regexes from another realm', function(assert) {
11709 if (realm.regexp) {
11710 assert.strictEqual(_.isRegExp(realm.regexp), true);
11713 skipAssert(assert);
11718 /*--------------------------------------------------------------------------*/
11720 QUnit.module('lodash.isSet');
11723 var args = arguments;
11725 QUnit.test('should return `true` for sets', function(assert) {
11729 assert.strictEqual(_.isSet(set), true);
11732 skipAssert(assert);
11736 QUnit.test('should return `false` for non-sets', function(assert) {
11739 var expected = lodashStable.map(falsey, stubFalse);
11741 var actual = lodashStable.map(falsey, function(value, index) {
11742 return index ? _.isSet(value) : _.isSet();
11745 assert.deepEqual(actual, expected);
11747 assert.strictEqual(_.isSet(args), false);
11748 assert.strictEqual(_.isSet([1, 2, 3]), false);
11749 assert.strictEqual(_.isSet(true), false);
11750 assert.strictEqual(_.isSet(new Date), false);
11751 assert.strictEqual(_.isSet(new Error), false);
11752 assert.strictEqual(_.isSet(_), false);
11753 assert.strictEqual(_.isSet(slice), false);
11754 assert.strictEqual(_.isSet({ 'a': 1 }), false);
11755 assert.strictEqual(_.isSet(1), false);
11756 assert.strictEqual(_.isSet(/x/), false);
11757 assert.strictEqual(_.isSet('a'), false);
11758 assert.strictEqual(_.isSet(symbol), false);
11759 assert.strictEqual(_.isSet(weakSet), false);
11762 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
11765 var values = [false, true],
11766 expected = lodashStable.map(values, stubFalse);
11768 var actual = lodashStable.map(values, function(value) {
11769 return _.isSet({ 'constructor': value });
11772 assert.deepEqual(actual, expected);
11775 QUnit.test('should work with weak sets from another realm', function(assert) {
11779 assert.strictEqual(_.isSet(realm.set), true);
11782 skipAssert(assert);
11787 /*--------------------------------------------------------------------------*/
11789 QUnit.module('lodash.isString');
11792 var args = arguments;
11794 QUnit.test('should return `true` for strings', function(assert) {
11797 assert.strictEqual(_.isString('a'), true);
11798 assert.strictEqual(_.isString(Object('a')), true);
11801 QUnit.test('should return `false` for non-strings', function(assert) {
11804 var expected = lodashStable.map(falsey, function(value) {
11805 return value === '';
11808 var actual = lodashStable.map(falsey, function(value, index) {
11809 return index ? _.isString(value) : _.isString();
11812 assert.deepEqual(actual, expected);
11814 assert.strictEqual(_.isString(args), false);
11815 assert.strictEqual(_.isString([1, 2, 3]), false);
11816 assert.strictEqual(_.isString(true), false);
11817 assert.strictEqual(_.isString(new Date), false);
11818 assert.strictEqual(_.isString(new Error), false);
11819 assert.strictEqual(_.isString(_), false);
11820 assert.strictEqual(_.isString(slice), false);
11821 assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
11822 assert.strictEqual(_.isString(1), false);
11823 assert.strictEqual(_.isString(/x/), false);
11824 assert.strictEqual(_.isString(symbol), false);
11827 QUnit.test('should work with strings from another realm', function(assert) {
11830 if (realm.string) {
11831 assert.strictEqual(_.isString(realm.string), true);
11834 skipAssert(assert);
11839 /*--------------------------------------------------------------------------*/
11841 QUnit.module('lodash.isSymbol');
11844 var args = arguments;
11846 QUnit.test('should return `true` for symbols', function(assert) {
11850 assert.strictEqual(_.isSymbol(symbol), true);
11851 assert.strictEqual(_.isSymbol(Object(symbol)), true);
11854 skipAssert(assert, 2);
11858 QUnit.test('should return `false` for non-symbols', function(assert) {
11861 var expected = lodashStable.map(falsey, stubFalse);
11863 var actual = lodashStable.map(falsey, function(value, index) {
11864 return index ? _.isSymbol(value) : _.isSymbol();
11867 assert.deepEqual(actual, expected);
11869 assert.strictEqual(_.isSymbol(args), false);
11870 assert.strictEqual(_.isSymbol([1, 2, 3]), false);
11871 assert.strictEqual(_.isSymbol(true), false);
11872 assert.strictEqual(_.isSymbol(new Date), false);
11873 assert.strictEqual(_.isSymbol(new Error), false);
11874 assert.strictEqual(_.isSymbol(_), false);
11875 assert.strictEqual(_.isSymbol(slice), false);
11876 assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
11877 assert.strictEqual(_.isSymbol(1), false);
11878 assert.strictEqual(_.isSymbol(/x/), false);
11879 assert.strictEqual(_.isSymbol('a'), false);
11882 QUnit.test('should work with symbols from another realm', function(assert) {
11885 if (Symbol && realm.symbol) {
11886 assert.strictEqual(_.isSymbol(realm.symbol), true);
11889 skipAssert(assert);
11894 /*--------------------------------------------------------------------------*/
11896 QUnit.module('lodash.isTypedArray');
11899 var args = arguments;
11901 QUnit.test('should return `true` for typed arrays', function(assert) {
11904 var expected = lodashStable.map(typedArrays, function(type) {
11905 return type in root;
11908 var actual = lodashStable.map(typedArrays, function(type) {
11909 var Ctor = root[type];
11910 return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
11913 assert.deepEqual(actual, expected);
11916 QUnit.test('should return `false` for non typed arrays', function(assert) {
11919 var expected = lodashStable.map(falsey, stubFalse);
11921 var actual = lodashStable.map(falsey, function(value, index) {
11922 return index ? _.isTypedArray(value) : _.isTypedArray();
11925 assert.deepEqual(actual, expected);
11927 assert.strictEqual(_.isTypedArray(args), false);
11928 assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
11929 assert.strictEqual(_.isTypedArray(true), false);
11930 assert.strictEqual(_.isTypedArray(new Date), false);
11931 assert.strictEqual(_.isTypedArray(new Error), false);
11932 assert.strictEqual(_.isTypedArray(_), false);
11933 assert.strictEqual(_.isTypedArray(slice), false);
11934 assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
11935 assert.strictEqual(_.isTypedArray(1), false);
11936 assert.strictEqual(_.isTypedArray(/x/), false);
11937 assert.strictEqual(_.isTypedArray('a'), false);
11938 assert.strictEqual(_.isTypedArray(symbol), false);
11941 QUnit.test('should work with typed arrays from another realm', function(assert) {
11944 if (realm.object) {
11945 var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
11947 var expected = lodashStable.map(props, function(key) {
11948 return realm[key] !== undefined;
11951 var actual = lodashStable.map(props, function(key) {
11952 var value = realm[key];
11953 return value ? _.isTypedArray(value) : false;
11956 assert.deepEqual(actual, expected);
11959 skipAssert(assert);
11964 /*--------------------------------------------------------------------------*/
11966 QUnit.module('lodash.isUndefined');
11969 var args = arguments;
11971 QUnit.test('should return `true` for `undefined` values', function(assert) {
11974 assert.strictEqual(_.isUndefined(), true);
11975 assert.strictEqual(_.isUndefined(undefined), true);
11978 QUnit.test('should return `false` for non `undefined` values', function(assert) {
11981 var expected = lodashStable.map(falsey, function(value) {
11982 return value === undefined;
11985 var actual = lodashStable.map(falsey, function(value, index) {
11986 return index ? _.isUndefined(value) : _.isUndefined();
11989 assert.deepEqual(actual, expected);
11991 assert.strictEqual(_.isUndefined(args), false);
11992 assert.strictEqual(_.isUndefined([1, 2, 3]), false);
11993 assert.strictEqual(_.isUndefined(true), false);
11994 assert.strictEqual(_.isUndefined(new Date), false);
11995 assert.strictEqual(_.isUndefined(new Error), false);
11996 assert.strictEqual(_.isUndefined(_), false);
11997 assert.strictEqual(_.isUndefined(slice), false);
11998 assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
11999 assert.strictEqual(_.isUndefined(1), false);
12000 assert.strictEqual(_.isUndefined(/x/), false);
12001 assert.strictEqual(_.isUndefined('a'), false);
12004 assert.strictEqual(_.isUndefined(symbol), false);
12007 skipAssert(assert);
12011 QUnit.test('should work with `undefined` from another realm', function(assert) {
12014 if (realm.object) {
12015 assert.strictEqual(_.isUndefined(realm.undefined), true);
12018 skipAssert(assert);
12023 /*--------------------------------------------------------------------------*/
12025 QUnit.module('lodash.isWeakMap');
12028 var args = arguments;
12030 QUnit.test('should return `true` for weak maps', function(assert) {
12034 assert.strictEqual(_.isWeakMap(weakMap), true);
12037 skipAssert(assert);
12041 QUnit.test('should return `false` for non weak maps', function(assert) {
12044 var expected = lodashStable.map(falsey, stubFalse);
12046 var actual = lodashStable.map(falsey, function(value, index) {
12047 return index ? _.isWeakMap(value) : _.isWeakMap();
12050 assert.deepEqual(actual, expected);
12052 assert.strictEqual(_.isWeakMap(args), false);
12053 assert.strictEqual(_.isWeakMap([1, 2, 3]), false);
12054 assert.strictEqual(_.isWeakMap(true), false);
12055 assert.strictEqual(_.isWeakMap(new Date), false);
12056 assert.strictEqual(_.isWeakMap(new Error), false);
12057 assert.strictEqual(_.isWeakMap(_), false);
12058 assert.strictEqual(_.isWeakMap(slice), false);
12059 assert.strictEqual(_.isWeakMap({ 'a': 1 }), false);
12060 assert.strictEqual(_.isWeakMap(map), false);
12061 assert.strictEqual(_.isWeakMap(1), false);
12062 assert.strictEqual(_.isWeakMap(/x/), false);
12063 assert.strictEqual(_.isWeakMap('a'), false);
12064 assert.strictEqual(_.isWeakMap(symbol), false);
12067 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
12070 var values = [false, true],
12071 expected = lodashStable.map(values, stubFalse);
12073 var actual = lodashStable.map(values, function(value) {
12074 return _.isWeakMap({ 'constructor': value });
12077 assert.deepEqual(actual, expected);
12080 QUnit.test('should work with weak maps from another realm', function(assert) {
12083 if (realm.weakMap) {
12084 assert.strictEqual(_.isWeakMap(realm.weakMap), true);
12087 skipAssert(assert);
12092 /*--------------------------------------------------------------------------*/
12094 QUnit.module('lodash.isWeakSet');
12097 var args = arguments;
12099 QUnit.test('should return `true` for weak sets', function(assert) {
12103 assert.strictEqual(_.isWeakSet(weakSet), true);
12106 skipAssert(assert);
12110 QUnit.test('should return `false` for non weak sets', function(assert) {
12113 var expected = lodashStable.map(falsey, stubFalse);
12115 var actual = lodashStable.map(falsey, function(value, index) {
12116 return index ? _.isWeakSet(value) : _.isWeakSet();
12119 assert.deepEqual(actual, expected);
12121 assert.strictEqual(_.isWeakSet(args), false);
12122 assert.strictEqual(_.isWeakSet([1, 2, 3]), false);
12123 assert.strictEqual(_.isWeakSet(true), false);
12124 assert.strictEqual(_.isWeakSet(new Date), false);
12125 assert.strictEqual(_.isWeakSet(new Error), false);
12126 assert.strictEqual(_.isWeakSet(_), false);
12127 assert.strictEqual(_.isWeakSet(slice), false);
12128 assert.strictEqual(_.isWeakSet({ 'a': 1 }), false);
12129 assert.strictEqual(_.isWeakSet(1), false);
12130 assert.strictEqual(_.isWeakSet(/x/), false);
12131 assert.strictEqual(_.isWeakSet('a'), false);
12132 assert.strictEqual(_.isWeakSet(set), false);
12133 assert.strictEqual(_.isWeakSet(symbol), false);
12136 QUnit.test('should work with weak sets from another realm', function(assert) {
12139 if (realm.weakSet) {
12140 assert.strictEqual(_.isWeakSet(realm.weakSet), true);
12143 skipAssert(assert);
12148 /*--------------------------------------------------------------------------*/
12150 QUnit.module('isType checks');
12153 QUnit.test('should return `false` for subclassed values', function(assert) {
12157 'isArray', 'isBoolean', 'isDate', 'isFunction',
12158 'isNumber', 'isRegExp', 'isString'
12161 lodashStable.each(funcs, function(methodName) {
12163 Foo.prototype = root[methodName.slice(2)].prototype;
12165 var object = new Foo;
12166 if (objToString.call(object) == objectTag) {
12167 assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
12170 skipAssert(assert);
12175 QUnit.test('should not error on host objects (test in IE)', function(assert) {
12179 'isArguments', 'isArray', 'isArrayBuffer', 'isArrayLike', 'isBoolean',
12180 'isBuffer', 'isDate', 'isElement', 'isError', 'isFinite', 'isFunction',
12181 'isInteger', 'isMap', 'isNaN', 'isNil', 'isNull', 'isNumber', 'isObject',
12182 'isObjectLike', 'isRegExp', 'isSet', 'isSafeInteger', 'isString',
12183 'isUndefined', 'isWeakMap', 'isWeakSet'
12186 lodashStable.each(funcs, function(methodName) {
12191 _[methodName](xml);
12195 assert.ok(pass, '`_.' + methodName + '` should not error');
12198 skipAssert(assert);
12204 /*--------------------------------------------------------------------------*/
12206 QUnit.module('lodash.iteratee');
12209 QUnit.test('should provide arguments to `func`', function(assert) {
12212 var fn = function() { return slice.call(arguments); },
12213 iteratee = _.iteratee(fn),
12214 actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
12216 assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
12219 QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
12223 values = [, null, undefined],
12224 expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
12226 var actual = lodashStable.map(values, function(value, index) {
12227 var identity = index ? _.iteratee(value) : _.iteratee();
12228 return [!isNpm && identity, identity(object)];
12231 assert.deepEqual(actual, expected);
12234 QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
12237 var matches = _.iteratee({ 'a': 1, 'b': 2 });
12238 assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
12239 assert.strictEqual(matches({ 'b': 2 }), false);
12242 QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
12246 { 'a': { 'b': 2, 'c': 3 } },
12247 { 'a': 1, 'b': 2 },
12251 lodashStable.each(sources, function(source, index) {
12252 var object = lodashStable.cloneDeep(source),
12253 matches = _.iteratee(source);
12255 assert.strictEqual(matches(object), true);
12266 assert.strictEqual(matches(object), true);
12267 assert.strictEqual(matches(source), false);
12271 QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
12274 var array = ['a', undefined],
12275 matches = _.iteratee([0, 'a']);
12277 assert.strictEqual(matches(array), true);
12279 matches = _.iteratee(['0', 'a']);
12280 assert.strictEqual(matches(array), true);
12282 matches = _.iteratee([1, undefined]);
12283 assert.strictEqual(matches(array), true);
12286 QUnit.test('should support deep paths for `_.matchesProperty` shorthands', function(assert) {
12289 var object = { 'a': { 'b': { 'c': 1, 'd': 2 } } },
12290 matches = _.iteratee(['a.b', { 'c': 1 }]);
12292 assert.strictEqual(matches(object), true);
12295 QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
12299 { 'a': { 'b': 2, 'c': 3 } },
12300 { 'a': 1, 'b': 2 },
12304 lodashStable.each(sources, function(source, index) {
12305 var object = { 'a': lodashStable.cloneDeep(source) },
12306 matches = _.iteratee(['a', source]);
12308 assert.strictEqual(matches(object), true);
12319 assert.strictEqual(matches(object), true);
12320 assert.strictEqual(matches({ 'a': source }), false);
12324 QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
12328 prop = _.iteratee(0);
12330 assert.strictEqual(prop(array), 'a');
12332 prop = _.iteratee('0');
12333 assert.strictEqual(prop(array), 'a');
12336 QUnit.test('should support deep paths for `_.property` shorthands', function(assert) {
12339 var object = { 'a': { 'b': 2 } },
12340 prop = _.iteratee('a.b');
12342 assert.strictEqual(prop(object), 2);
12345 QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
12348 var fn = function() {
12349 var result = [this.a];
12350 push.apply(result, arguments);
12354 var expected = [1, 2, 3],
12355 object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
12357 assert.deepEqual(object.iteratee(3), expected);
12359 object.iteratee = _.iteratee(_.partialRight(fn, 3));
12360 assert.deepEqual(object.iteratee(2), expected);
12363 QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
12366 var iteratee = _.iteratee;
12369 assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
12371 _.iteratee = iteratee;
12374 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
12377 var fn = function() { return this instanceof Number; },
12378 array = [fn, fn, fn],
12379 iteratees = lodashStable.map(array, _.iteratee),
12380 expected = lodashStable.map(array, stubFalse);
12382 var actual = lodashStable.map(iteratees, function(iteratee) {
12386 assert.deepEqual(actual, expected);
12390 /*--------------------------------------------------------------------------*/
12392 QUnit.module('custom `_.iteratee` methods');
12395 var array = ['one', 'two', 'three'],
12396 getPropA = _.partial(_.property, 'a'),
12397 getPropB = _.partial(_.property, 'b'),
12398 getLength = _.partial(_.property, 'length'),
12399 iteratee = _.iteratee;
12401 var getSum = function() {
12402 return function(result, object) {
12403 return result + object.a;
12408 { 'a': 0, 'b': 0 },
12409 { 'a': 1, 'b': 0 },
12413 QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
12416 if (!isModularize) {
12417 _.iteratee = getLength;
12418 assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
12419 _.iteratee = iteratee;
12422 skipAssert(assert);
12426 QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
12429 if (!isModularize) {
12430 _.iteratee = getPropA;
12431 assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
12432 _.iteratee = iteratee;
12435 skipAssert(assert);
12439 QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
12442 if (!isModularize) {
12443 _.iteratee = getPropB;
12444 assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
12445 _.iteratee = iteratee;
12448 skipAssert(assert);
12452 QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
12455 if (!isModularize) {
12456 _.iteratee = getPropB;
12457 assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
12458 _.iteratee = iteratee;
12461 skipAssert(assert);
12465 QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
12468 if (!isModularize) {
12469 _.iteratee = getPropA;
12470 assert.strictEqual(_.every(objects.slice(1)), true);
12471 _.iteratee = iteratee;
12474 skipAssert(assert);
12478 QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
12481 if (!isModularize) {
12482 var objects = [{ 'a': 0 }, { 'a': 1 }];
12484 _.iteratee = getPropA;
12485 assert.deepEqual(_.filter(objects), [objects[1]]);
12486 _.iteratee = iteratee;
12489 skipAssert(assert);
12493 QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
12496 if (!isModularize) {
12497 _.iteratee = getPropA;
12498 assert.strictEqual(_.find(objects), objects[1]);
12499 _.iteratee = iteratee;
12502 skipAssert(assert);
12506 QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
12509 if (!isModularize) {
12510 _.iteratee = getPropA;
12511 assert.strictEqual(_.findIndex(objects), 1);
12512 _.iteratee = iteratee;
12515 skipAssert(assert);
12519 QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
12522 if (!isModularize) {
12523 _.iteratee = getPropA;
12524 assert.strictEqual(_.findLast(objects), objects[2]);
12525 _.iteratee = iteratee;
12528 skipAssert(assert);
12532 QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
12535 if (!isModularize) {
12536 _.iteratee = getPropA;
12537 assert.strictEqual(_.findLastIndex(objects), 2);
12538 _.iteratee = iteratee;
12541 skipAssert(assert);
12545 QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
12548 if (!isModularize) {
12549 _.iteratee = getPropB;
12550 assert.strictEqual(_.findKey(objects), '2');
12551 _.iteratee = iteratee;
12554 skipAssert(assert);
12558 QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
12561 if (!isModularize) {
12562 _.iteratee = getPropB;
12563 assert.strictEqual(_.findLastKey(objects), '2');
12564 _.iteratee = iteratee;
12567 skipAssert(assert);
12571 QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
12574 if (!isModularize) {
12575 _.iteratee = getLength;
12576 assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
12577 _.iteratee = iteratee;
12580 skipAssert(assert);
12584 QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
12587 if (!isModularize) {
12588 _.iteratee = getPropA;
12589 assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
12590 _.iteratee = iteratee;
12593 skipAssert(assert);
12597 QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
12600 if (!isModularize) {
12601 _.iteratee = getLength;
12602 assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
12603 _.iteratee = iteratee;
12606 skipAssert(assert);
12610 QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
12613 if (!isModularize) {
12614 _.iteratee = getPropA;
12615 assert.deepEqual(_.map(objects), [0, 1, 1]);
12616 _.iteratee = iteratee;
12619 skipAssert(assert);
12623 QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
12626 if (!isModularize) {
12627 _.iteratee = getPropB;
12628 assert.deepEqual(_.mapKeys({ 'a': { 'b': 2 } }), { '2': { 'b': 2 } });
12629 _.iteratee = iteratee;
12632 skipAssert(assert);
12636 QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
12639 if (!isModularize) {
12640 _.iteratee = getPropB;
12641 assert.deepEqual(_.mapValues({ 'a': { 'b': 2 } }), { 'a': 2 });
12642 _.iteratee = iteratee;
12645 skipAssert(assert);
12649 QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
12652 if (!isModularize) {
12653 _.iteratee = getPropB;
12654 assert.deepEqual(_.maxBy(objects), objects[2]);
12655 _.iteratee = iteratee;
12658 skipAssert(assert);
12662 QUnit.test('`_.meanBy` should use `_.iteratee` internally', function(assert) {
12665 if (!isModularize) {
12666 _.iteratee = getPropA;
12667 assert.strictEqual(_.meanBy(objects), 2 / 3);
12668 _.iteratee = iteratee;
12671 skipAssert(assert);
12675 QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
12678 if (!isModularize) {
12679 _.iteratee = getPropB;
12680 assert.deepEqual(_.minBy(objects), objects[0]);
12681 _.iteratee = iteratee;
12684 skipAssert(assert);
12688 QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
12691 if (!isModularize) {
12692 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
12694 _.iteratee = getPropA;
12695 assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
12696 _.iteratee = iteratee;
12699 skipAssert(assert);
12703 QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
12706 if (!isModularize) {
12707 _.iteratee = getPropA;
12708 assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
12709 _.iteratee = iteratee;
12712 skipAssert(assert);
12716 QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
12719 if (!isModularize) {
12720 _.iteratee = getSum;
12721 assert.strictEqual(_.reduce(objects, undefined, 0), 2);
12722 _.iteratee = iteratee;
12725 skipAssert(assert);
12729 QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
12732 if (!isModularize) {
12733 _.iteratee = getSum;
12734 assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
12735 _.iteratee = iteratee;
12738 skipAssert(assert);
12742 QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
12745 if (!isModularize) {
12746 var objects = [{ 'a': 0 }, { 'a': 1 }];
12748 _.iteratee = getPropA;
12749 assert.deepEqual(_.reject(objects), [objects[0]]);
12750 _.iteratee = iteratee;
12753 skipAssert(assert);
12757 QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
12760 if (!isModularize) {
12761 var objects = [{ 'a': 0 }, { 'a': 1 }];
12763 _.iteratee = getPropA;
12765 assert.deepEqual(objects, [{ 'a': 0 }]);
12766 _.iteratee = iteratee;
12769 skipAssert(assert);
12773 QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
12776 if (!isModularize) {
12777 _.iteratee = getPropB;
12778 assert.strictEqual(_.some(objects), true);
12779 _.iteratee = iteratee;
12782 skipAssert(assert);
12786 QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
12789 if (!isModularize) {
12790 _.iteratee = getPropA;
12791 assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
12792 _.iteratee = iteratee;
12795 skipAssert(assert);
12799 QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
12802 if (!isModularize) {
12803 var objects = [{ 'a': 30 }, { 'a': 50 }];
12805 _.iteratee = getPropA;
12806 assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
12807 _.iteratee = iteratee;
12810 skipAssert(assert);
12814 QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
12817 if (!isModularize) {
12818 var objects = [{ 'a': 30 }, { 'a': 50 }];
12820 _.iteratee = getPropA;
12821 assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
12822 _.iteratee = iteratee;
12825 skipAssert(assert);
12829 QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
12832 if (!isModularize) {
12833 _.iteratee = getPropB;
12834 assert.strictEqual(_.sumBy(objects), 1);
12835 _.iteratee = iteratee;
12838 skipAssert(assert);
12842 QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
12845 if (!isModularize) {
12846 _.iteratee = getPropB;
12847 assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
12848 _.iteratee = iteratee;
12851 skipAssert(assert);
12855 QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
12858 if (!isModularize) {
12859 _.iteratee = getPropB;
12860 assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
12861 _.iteratee = iteratee;
12864 skipAssert(assert);
12868 QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
12871 if (!isModularize) {
12872 _.iteratee = function() {
12873 return function(result, object) {
12874 result.sum += object.a;
12878 assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
12879 _.iteratee = iteratee;
12882 skipAssert(assert);
12886 QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
12889 if (!isModularize) {
12890 _.iteratee = getPropB;
12891 assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
12892 _.iteratee = iteratee;
12895 skipAssert(assert);
12899 QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
12902 if (!isModularize) {
12903 _.iteratee = getPropB;
12904 assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
12905 _.iteratee = iteratee;
12908 skipAssert(assert);
12912 QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
12915 if (!isModularize) {
12916 _.iteratee = getPropA;
12917 assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
12918 _.iteratee = iteratee;
12921 skipAssert(assert);
12926 /*--------------------------------------------------------------------------*/
12928 QUnit.module('lodash.join');
12931 var array = ['a', 'b', 'c'];
12933 QUnit.test('should return join all array elements into a string', function(assert) {
12936 assert.strictEqual(_.join(array, '~'), 'a~b~c');
12939 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12943 var wrapped = _(array);
12944 assert.strictEqual(wrapped.join('~'), 'a~b~c');
12945 assert.strictEqual(wrapped.value(), array);
12948 skipAssert(assert, 2);
12952 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12956 assert.ok(_(array).chain().join('~') instanceof _);
12959 skipAssert(assert);
12964 /*--------------------------------------------------------------------------*/
12966 QUnit.module('lodash.keyBy');
12970 { 'dir': 'left', 'code': 97 },
12971 { 'dir': 'right', 'code': 100 }
12974 QUnit.test('should transform keys by `iteratee`', function(assert) {
12977 var expected = { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } };
12979 var actual = _.keyBy(array, function(object) {
12980 return String.fromCharCode(object.code);
12983 assert.deepEqual(actual, expected);
12986 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
12989 var array = [4, 6, 6],
12990 values = [, null, undefined],
12991 expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
12993 var actual = lodashStable.map(values, function(value, index) {
12994 return index ? _.keyBy(array, value) : _.keyBy(array);
12997 assert.deepEqual(actual, expected);
13000 QUnit.test('should work with `_.property` shorthands', function(assert) {
13003 var expected = { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } },
13004 actual = _.keyBy(array, 'dir');
13006 assert.deepEqual(actual, expected);
13009 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
13012 var actual = _.keyBy([6.1, 4.2, 6.3], function(n) {
13013 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
13016 assert.deepEqual(actual.constructor, 4.2);
13017 assert.deepEqual(actual.hasOwnProperty, 6.3);
13020 QUnit.test('should work with a number for `iteratee`', function(assert) {
13029 assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
13030 assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
13033 QUnit.test('should work with an object for `collection`', function(assert) {
13036 var actual = _.keyBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
13037 assert.deepEqual(actual, { '4': 4.2, '6': 6.3 });
13040 QUnit.test('should work in a lazy sequence', function(assert) {
13044 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
13045 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
13046 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
13049 var actual = _(array).keyBy().map(square).filter(isEven).take().value();
13051 assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
13054 skipAssert(assert);
13059 /*--------------------------------------------------------------------------*/
13061 QUnit.module('keys methods');
13063 lodashStable.each(['keys', 'keysIn'], function(methodName) {
13064 var args = (function() { return arguments; }(1, 2, 3)),
13065 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
13066 func = _[methodName],
13067 isKeys = methodName == 'keys';
13069 QUnit.test('`_.' + methodName + '` should return the string keyed property names of `object`', function(assert) {
13072 var actual = func({ 'a': 1, 'b': 1 }).sort();
13074 assert.deepEqual(actual, ['a', 'b']);
13077 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties', function(assert) {
13083 Foo.prototype.b = 2;
13085 var expected = isKeys ? ['a'] : ['a', 'b'],
13086 actual = func(new Foo).sort();
13088 assert.deepEqual(actual, expected);
13091 QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
13094 var expected = lodashStable.map(primitives, function(value) {
13095 return typeof value == 'string' ? ['0'] : [];
13098 var actual = lodashStable.map(primitives, func);
13099 assert.deepEqual(actual, expected);
13101 // IE 9 doesn't box numbers in for-in loops.
13103 assert.deepEqual(func(0), isKeys ? [] : ['a']);
13104 delete numberProto.a;
13107 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
13113 var actual = func(array).sort();
13115 assert.deepEqual(actual, ['0', '1', '2']);
13118 QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) {
13122 lodashStable.each([null, undefined], function(value) {
13123 assert.deepEqual(func(value), []);
13125 delete objectProto.a;
13128 QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
13134 var actual = func(array).sort();
13136 assert.deepEqual(actual, ['0', 'a']);
13139 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of arrays', function(assert) {
13144 var expected = isKeys ? ['0'] : ['0', 'a'],
13145 actual = func([1]).sort();
13147 assert.deepEqual(actual, expected);
13149 delete arrayProto.a;
13152 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
13155 var values = [args, strictArgs],
13156 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2']));
13158 var actual = lodashStable.map(values, function(value) {
13159 return func(value).sort();
13162 assert.deepEqual(actual, expected);
13165 QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
13168 var values = [args, strictArgs],
13169 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
13171 var actual = lodashStable.map(values, function(value) {
13173 var result = func(value).sort();
13178 assert.deepEqual(actual, expected);
13181 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of `arguments` objects', function(assert) {
13184 var values = [args, strictArgs],
13185 expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
13187 var actual = lodashStable.map(values, function(value) {
13189 var result = func(value).sort();
13190 delete objectProto.a;
13194 assert.deepEqual(actual, expected);
13197 QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
13200 var actual = func(Object('abc')).sort();
13202 assert.deepEqual(actual, ['0', '1', '2']);
13205 QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
13208 var object = Object('a');
13211 var actual = func(object).sort();
13213 assert.deepEqual(actual, ['0', 'a']);
13216 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of string objects', function(assert) {
13221 var expected = isKeys ? ['0'] : ['0', 'a'],
13222 actual = func(Object('a')).sort();
13224 assert.deepEqual(actual, expected);
13226 delete stringProto.a;
13229 QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
13233 Foo.prototype.a = 1;
13235 var expected = ['a'];
13236 assert.deepEqual(func(Foo.prototype), expected);
13238 Foo.prototype = { 'constructor': Foo, 'a': 1 };
13239 assert.deepEqual(func(Foo.prototype), expected);
13241 var Fake = { 'prototype': {} };
13242 Fake.prototype.constructor = Fake;
13243 assert.deepEqual(func(Fake.prototype), ['constructor']);
13247 /*--------------------------------------------------------------------------*/
13249 QUnit.module('lodash.last');
13252 var array = [1, 2, 3, 4];
13254 QUnit.test('should return the last element', function(assert) {
13257 assert.strictEqual(_.last(array), 4);
13260 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
13266 assert.strictEqual(_.last([]), undefined);
13269 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
13272 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
13273 actual = lodashStable.map(array, _.last);
13275 assert.deepEqual(actual, [3, 6, 9]);
13278 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
13282 assert.strictEqual(_(array).last(), 4);
13285 skipAssert(assert);
13289 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
13293 assert.ok(_(array).chain().last() instanceof _);
13296 skipAssert(assert);
13300 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
13304 var wrapped = _(array).chain().last();
13305 assert.strictEqual(wrapped.__wrapped__, array);
13308 skipAssert(assert);
13312 QUnit.test('should work in a lazy sequence', function(assert) {
13316 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
13317 smallArray = array;
13319 lodashStable.times(2, function(index) {
13320 var array = index ? largeArray : smallArray,
13321 wrapped = _(array).filter(isEven);
13323 assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
13327 skipAssert(assert, 2);
13332 /*--------------------------------------------------------------------------*/
13334 QUnit.module('lodash.lowerCase');
13337 QUnit.test('should lowercase as space-separated words', function(assert) {
13340 assert.strictEqual(_.lowerCase('--Foo-Bar--'), 'foo bar');
13341 assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
13342 assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
13346 /*--------------------------------------------------------------------------*/
13348 QUnit.module('lodash.lowerFirst');
13351 QUnit.test('should lowercase only the first character', function(assert) {
13354 assert.strictEqual(_.lowerFirst('fred'), 'fred');
13355 assert.strictEqual(_.lowerFirst('Fred'), 'fred');
13356 assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
13360 /*--------------------------------------------------------------------------*/
13362 QUnit.module('lodash.lt');
13365 QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
13368 assert.strictEqual(_.lt(1, 3), true);
13369 assert.strictEqual(_.lt('abc', 'def'), true);
13372 QUnit.test('should return `false` if `value` >= `other`', function(assert) {
13375 assert.strictEqual(_.lt(3, 1), false);
13376 assert.strictEqual(_.lt(3, 3), false);
13377 assert.strictEqual(_.lt('def', 'abc'), false);
13378 assert.strictEqual(_.lt('def', 'def'), false);
13382 /*--------------------------------------------------------------------------*/
13384 QUnit.module('lodash.lte');
13387 QUnit.test('should return `true` if `value` is <= `other`', function(assert) {
13390 assert.strictEqual(_.lte(1, 3), true);
13391 assert.strictEqual(_.lte(3, 3), true);
13392 assert.strictEqual(_.lte('abc', 'def'), true);
13393 assert.strictEqual(_.lte('def', 'def'), true);
13396 QUnit.test('should return `false` if `value` > `other`', function(assert) {
13399 assert.strictEqual(_.lt(3, 1), false);
13400 assert.strictEqual(_.lt('def', 'abc'), false);
13404 /*--------------------------------------------------------------------------*/
13406 QUnit.module('lodash.findLastIndex and lodash.lastIndexOf');
13408 lodashStable.each(['findLastIndex', 'lastIndexOf'], function(methodName) {
13409 var array = [1, 2, 3, 1, 2, 3],
13410 func = _[methodName],
13411 resolve = methodName == 'findLastIndex' ? lodashStable.curry(lodashStable.eq) : identity;
13413 QUnit.test('`_.' + methodName + '` should return the index of the last matched value', function(assert) {
13416 assert.strictEqual(func(array, resolve(3)), 5);
13419 QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
13422 assert.strictEqual(func(array, resolve(1), 2), 0);
13425 QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
13428 var values = [6, 8, Math.pow(2, 32), Infinity],
13429 expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
13431 var actual = lodashStable.map(values, function(fromIndex) {
13433 func(array, resolve(undefined), fromIndex),
13434 func(array, resolve(1), fromIndex),
13435 func(array, resolve(''), fromIndex)
13439 assert.deepEqual(actual, expected);
13442 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
13445 assert.strictEqual(func(array, resolve(2), -3), 1);
13448 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
13451 var values = [-6, -8, -Infinity],
13452 expected = lodashStable.map(values, stubZero);
13454 var actual = lodashStable.map(values, function(fromIndex) {
13455 return func(array, resolve(1), fromIndex);
13458 assert.deepEqual(actual, expected);
13461 QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values correctly', function(assert) {
13464 var expected = lodashStable.map(falsey, function(value) {
13465 return value === undefined ? 5 : -1;
13468 var actual = lodashStable.map(falsey, function(fromIndex) {
13469 return func(array, resolve(3), fromIndex);
13472 assert.deepEqual(actual, expected);
13475 QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
13478 assert.strictEqual(func(array, resolve(2), 4.2), 4);
13482 /*--------------------------------------------------------------------------*/
13484 QUnit.module('indexOf methods');
13486 lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
13487 var func = _[methodName],
13488 isIndexOf = !/last/i.test(methodName),
13489 isSorted = /^sorted/.test(methodName);
13491 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument', function(assert) {
13494 var expected = lodashStable.map(falsey, lodashStable.constant(-1));
13496 var actual = lodashStable.map(falsey, function(array, index) {
13498 return index ? func(array) : func();
13502 assert.deepEqual(actual, expected);
13505 QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
13508 var array = [1, 2, 3],
13511 assert.strictEqual(func(array, 4), -1);
13512 assert.strictEqual(func(array, 4, true), -1);
13513 assert.strictEqual(func(array, undefined, true), -1);
13515 assert.strictEqual(func(empty, undefined), -1);
13516 assert.strictEqual(func(empty, undefined, true), -1);
13519 QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
13525 assert.strictEqual(func(array, undefined), -1);
13526 assert.strictEqual(func(array, 0, true), -1);
13529 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
13532 var array = isSorted
13534 : [1, NaN, 3, NaN, 5, NaN];
13537 assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
13538 skipAssert(assert, 2);
13541 assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
13542 assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
13543 assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
13547 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
13550 assert.strictEqual(func([-0], 0), 0);
13551 assert.strictEqual(func([0], -0), 0);
13555 /*--------------------------------------------------------------------------*/
13557 QUnit.module('lodash.map');
13560 var array = [1, 2];
13562 QUnit.test('should map values in `collection` to a new array', function(assert) {
13565 var object = { 'a': 1, 'b': 2 },
13566 expected = ['1', '2'];
13568 assert.deepEqual(_.map(array, String), expected);
13569 assert.deepEqual(_.map(object, String), expected);
13572 QUnit.test('should work with `_.property` shorthands', function(assert) {
13575 var objects = [{ 'a': 'x' }, { 'a': 'y' }];
13576 assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
13579 QUnit.test('should iterate over own string keyed properties of objects', function(assert) {
13585 Foo.prototype.b = 2;
13587 var actual = _.map(new Foo, identity);
13588 assert.deepEqual(actual, [1]);
13591 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13594 var object = { 'a': 1, 'b': 2 },
13595 values = [, null, undefined],
13596 expected = lodashStable.map(values, lodashStable.constant([1, 2]));
13598 lodashStable.each([array, object], function(collection) {
13599 var actual = lodashStable.map(values, function(value, index) {
13600 return index ? _.map(collection, value) : _.map(collection);
13603 assert.deepEqual(actual, expected);
13607 QUnit.test('should accept a falsey `collection` argument', function(assert) {
13610 var expected = lodashStable.map(falsey, stubArray);
13612 var actual = lodashStable.map(falsey, function(collection, index) {
13614 return index ? _.map(collection) : _.map();
13618 assert.deepEqual(actual, expected);
13621 QUnit.test('should treat number values for `collection` as empty', function(assert) {
13624 assert.deepEqual(_.map(1), []);
13627 QUnit.test('should treat a nodelist as an array-like object', function(assert) {
13631 var actual = _.map(document.getElementsByTagName('body'), function(element) {
13632 return element.nodeName.toLowerCase();
13635 assert.deepEqual(actual, ['body']);
13638 skipAssert(assert);
13642 QUnit.test('should work with objects with non-number length properties', function(assert) {
13645 var value = { 'value': 'x' },
13646 object = { 'length': { 'value': 'x' } };
13648 assert.deepEqual(_.map(object, identity), [value]);
13651 QUnit.test('should return a wrapped value when chaining', function(assert) {
13655 assert.ok(_(array).map(noop) instanceof _);
13658 skipAssert(assert);
13662 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
13667 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
13668 expected = [1, 0, _.map(array.slice(1), square)];
13670 _(array).slice(1).map(function(value, index, array) {
13671 args || (args = slice.call(arguments));
13674 assert.deepEqual(args, [1, 0, array.slice(1)]);
13677 _(array).slice(1).map(square).map(function(value, index, array) {
13678 args || (args = slice.call(arguments));
13681 assert.deepEqual(args, expected);
13684 _(array).slice(1).map(square).map(function(value, index) {
13685 args || (args = slice.call(arguments));
13688 assert.deepEqual(args, expected);
13691 _(array).slice(1).map(square).map(function(value) {
13692 args || (args = slice.call(arguments));
13695 assert.deepEqual(args, [1]);
13698 _(array).slice(1).map(square).map(function() {
13699 args || (args = slice.call(arguments));
13702 assert.deepEqual(args, expected);
13705 skipAssert(assert, 5);
13710 /*--------------------------------------------------------------------------*/
13712 QUnit.module('lodash.mapKeys');
13715 var array = [1, 2],
13716 object = { 'a': 1, 'b': 2 };
13718 QUnit.test('should map keys in `object` to a new object', function(assert) {
13721 var actual = _.mapKeys(object, String);
13722 assert.deepEqual(actual, { '1': 1, '2': 2 });
13725 QUnit.test('should treat arrays like objects', function(assert) {
13728 var actual = _.mapKeys(array, String);
13729 assert.deepEqual(actual, { '1': 1, '2': 2 });
13732 QUnit.test('should work with `_.property` shorthands', function(assert) {
13735 var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
13736 assert.deepEqual(actual, { 'c': { 'b': 'c' } });
13739 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13742 var object = { 'a': 1, 'b': 2 },
13743 values = [, null, undefined],
13744 expected = lodashStable.map(values, lodashStable.constant({ '1': 1, '2': 2 }));
13746 var actual = lodashStable.map(values, function(value, index) {
13747 return index ? _.mapKeys(object, value) : _.mapKeys(object);
13750 assert.deepEqual(actual, expected);
13754 /*--------------------------------------------------------------------------*/
13756 QUnit.module('lodash.mapValues');
13759 var array = [1, 2],
13760 object = { 'a': 1, 'b': 2 };
13762 QUnit.test('should map values in `object` to a new object', function(assert) {
13765 var actual = _.mapValues(object, String);
13766 assert.deepEqual(actual, { 'a': '1', 'b': '2' });
13769 QUnit.test('should treat arrays like objects', function(assert) {
13772 var actual = _.mapValues(array, String);
13773 assert.deepEqual(actual, { '0': '1', '1': '2' });
13776 QUnit.test('should work with `_.property` shorthands', function(assert) {
13779 var actual = _.mapValues({ 'a': { 'b': 2 } }, 'b');
13780 assert.deepEqual(actual, { 'a': 2 });
13783 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13786 var object = { 'a': 1, 'b': 2 },
13787 values = [, null, undefined],
13788 expected = lodashStable.map(values, lodashStable.constant([true, false]));
13790 var actual = lodashStable.map(values, function(value, index) {
13791 var result = index ? _.mapValues(object, value) : _.mapValues(object);
13792 return [lodashStable.isEqual(result, object), result === object];
13795 assert.deepEqual(actual, expected);
13799 /*--------------------------------------------------------------------------*/
13801 QUnit.module('lodash.mapKeys and lodash.mapValues');
13803 lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
13804 var func = _[methodName],
13805 object = { 'a': 1, 'b': 2 };
13807 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
13813 Foo.prototype.b = 'b';
13815 var actual = func(new Foo, function(value, key) { return key; });
13816 assert.deepEqual(actual, { 'a': 'a' });
13819 QUnit.test('`_.' + methodName + '` should accept a falsey `object` argument', function(assert) {
13822 var expected = lodashStable.map(falsey, stubObject);
13824 var actual = lodashStable.map(falsey, function(object, index) {
13826 return index ? func(object) : func();
13830 assert.deepEqual(actual, expected);
13833 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
13837 assert.ok(_(object)[methodName](noop) instanceof _);
13840 skipAssert(assert);
13845 /*--------------------------------------------------------------------------*/
13847 QUnit.module('lodash.matches');
13850 QUnit.test('should create a function that performs a deep comparison between `source` and a given object', function(assert) {
13853 var object = { 'a': 1, 'b': 2, 'c': 3 },
13854 matches = _.matches({ 'a': 1 });
13856 assert.strictEqual(matches.length, 1);
13857 assert.strictEqual(matches(object), true);
13859 matches = _.matches({ 'b': 1 });
13860 assert.strictEqual(matches(object), false);
13862 matches = _.matches({ 'a': 1, 'c': 3 });
13863 assert.strictEqual(matches(object), true);
13865 matches = _.matches({ 'c': 3, 'd': 4 });
13866 assert.strictEqual(matches(object), false);
13868 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
13869 matches = _.matches({ 'a': { 'b': { 'c': 1 } } });
13871 assert.strictEqual(matches(object), true);
13874 QUnit.test('should match inherited string keyed `object` properties', function(assert) {
13880 Foo.prototype.b = 2;
13882 var object = { 'a': new Foo },
13883 matches = _.matches({ 'a': { 'b': 2 } });
13885 assert.strictEqual(matches(object), true);
13888 QUnit.test('should not match by inherited `source` properties', function(assert) {
13894 Foo.prototype.b = 2;
13896 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
13898 actual = lodashStable.map(objects, _.matches(source)),
13899 expected = lodashStable.map(objects, stubTrue);
13901 assert.deepEqual(actual, expected);
13904 QUnit.test('should compare a variety of `source` property values', function(assert) {
13907 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
13908 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
13909 matches = _.matches(object1);
13911 assert.strictEqual(matches(object1), true);
13912 assert.strictEqual(matches(object2), false);
13915 QUnit.test('should match `-0` as `0`', function(assert) {
13918 var object1 = { 'a': -0 },
13919 object2 = { 'a': 0 },
13920 matches = _.matches(object1);
13922 assert.strictEqual(matches(object2), true);
13924 matches = _.matches(object2);
13925 assert.strictEqual(matches(object1), true);
13928 QUnit.test('should compare functions by reference', function(assert) {
13931 var object1 = { 'a': lodashStable.noop },
13932 object2 = { 'a': noop },
13933 object3 = { 'a': {} },
13934 matches = _.matches(object1);
13936 assert.strictEqual(matches(object1), true);
13937 assert.strictEqual(matches(object2), false);
13938 assert.strictEqual(matches(object3), false);
13941 QUnit.test('should work with a function for `object`', function(assert) {
13945 Foo.a = { 'b': 2, 'c': 3 };
13947 var matches = _.matches({ 'a': { 'b': 2 } });
13948 assert.strictEqual(matches(Foo), true);
13951 QUnit.test('should work with a function for `source`', function(assert) {
13956 Foo.b = function() {};
13959 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
13960 actual = lodashStable.map(objects, _.matches(Foo));
13962 assert.deepEqual(actual, [false, true]);
13965 QUnit.test('should work with a non-plain `object`', function(assert) {
13968 function Foo(object) { lodashStable.assign(this, object); }
13970 var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) }),
13971 matches = _.matches({ 'a': { 'b': 2 } });
13973 assert.strictEqual(matches(object), true);
13976 QUnit.test('should partial match arrays', function(assert) {
13979 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
13980 actual = lodashStable.filter(objects, _.matches({ 'a': ['d'] }));
13982 assert.deepEqual(actual, [objects[1]]);
13984 actual = lodashStable.filter(objects, _.matches({ 'a': ['b', 'd'] }));
13985 assert.deepEqual(actual, []);
13987 actual = lodashStable.filter(objects, _.matches({ 'a': ['d', 'b'] }));
13988 assert.deepEqual(actual, []);
13991 QUnit.test('should partial match arrays with duplicate values', function(assert) {
13994 var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
13995 actual = lodashStable.filter(objects, _.matches({ 'a': [2, 2] }));
13997 assert.deepEqual(actual, [objects[1]]);
14000 QUnit.test('should partial match arrays of objects', function(assert) {
14004 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
14005 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
14008 var actual = lodashStable.filter(objects, _.matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
14009 assert.deepEqual(actual, [objects[0]]);
14012 QUnit.test('should partial match maps', function(assert) {
14016 var objects = [{ 'a': new Map }, { 'a': new Map }];
14017 objects[0].a.set('a', 1);
14018 objects[1].a.set('a', 1);
14019 objects[1].a.set('b', 2);
14023 var actual = lodashStable.filter(objects, _.matches({ 'a': map }));
14025 assert.deepEqual(actual, [objects[1]]);
14027 map['delete']('b');
14028 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
14030 assert.deepEqual(actual, objects);
14033 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
14035 assert.deepEqual(actual, []);
14038 skipAssert(assert, 3);
14042 QUnit.test('should partial match sets', function(assert) {
14046 var objects = [{ 'a': new Set }, { 'a': new Set }];
14047 objects[0].a.add(1);
14048 objects[1].a.add(1);
14049 objects[1].a.add(2);
14053 var actual = lodashStable.filter(objects, _.matches({ 'a': set }));
14055 assert.deepEqual(actual, [objects[1]]);
14058 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
14060 assert.deepEqual(actual, objects);
14063 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
14065 assert.deepEqual(actual, []);
14068 skipAssert(assert, 3);
14072 QUnit.test('should match `undefined` values', function(assert) {
14075 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
14076 actual = lodashStable.map(objects, _.matches({ 'b': undefined })),
14077 expected = [false, false, true];
14079 assert.deepEqual(actual, expected);
14081 actual = lodashStable.map(objects, _.matches({ 'a': 1, 'b': undefined }));
14083 assert.deepEqual(actual, expected);
14085 objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }];
14086 actual = lodashStable.map(objects, _.matches({ 'a': { 'c': undefined } }));
14088 assert.deepEqual(actual, expected);
14091 QUnit.test('should match `undefined` values on primitives', function(assert) {
14095 numberProto.b = undefined;
14098 var matches = _.matches({ 'b': undefined });
14099 assert.strictEqual(matches(1), true);
14101 assert.ok(false, e.message);
14104 matches = _.matches({ 'a': 1, 'b': undefined });
14105 assert.strictEqual(matches(1), true);
14107 assert.ok(false, e.message);
14109 numberProto.a = { 'b': 1, 'c': undefined };
14111 matches = _.matches({ 'a': { 'c': undefined } });
14112 assert.strictEqual(matches(1), true);
14114 assert.ok(false, e.message);
14116 delete numberProto.a;
14117 delete numberProto.b;
14120 QUnit.test('should return `false` when `object` is nullish', function(assert) {
14123 var values = [, null, undefined],
14124 expected = lodashStable.map(values, stubFalse),
14125 matches = _.matches({ 'a': 1 });
14127 var actual = lodashStable.map(values, function(value, index) {
14129 return index ? matches(value) : matches();
14133 assert.deepEqual(actual, expected);
14136 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
14139 var values = [, null, undefined],
14140 expected = lodashStable.map(values, stubTrue),
14141 matches = _.matches({});
14143 var actual = lodashStable.map(values, function(value, index) {
14145 return index ? matches(value) : matches();
14149 assert.deepEqual(actual, expected);
14152 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
14155 var object = { 'a': 1 },
14156 expected = lodashStable.map(empties, stubTrue);
14158 var actual = lodashStable.map(empties, function(value) {
14159 var matches = _.matches(value);
14160 return matches(object);
14163 assert.deepEqual(actual, expected);
14166 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
14169 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
14170 actual = lodashStable.filter(objects, _.matches({ 'a': [], 'b': {} }));
14172 assert.deepEqual(actual, objects);
14175 QUnit.test('should not change behavior if `source` is modified', function(assert) {
14179 { 'a': { 'b': 2, 'c': 3 } },
14180 { 'a': 1, 'b': 2 },
14184 lodashStable.each(sources, function(source, index) {
14185 var object = lodashStable.cloneDeep(source),
14186 matches = _.matches(source);
14188 assert.strictEqual(matches(object), true);
14199 assert.strictEqual(matches(object), true);
14200 assert.strictEqual(matches(source), false);
14205 /*--------------------------------------------------------------------------*/
14207 QUnit.module('lodash.matchesProperty');
14210 QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
14213 var object = { 'a': 1, 'b': 2, 'c': 3 },
14214 matches = _.matchesProperty('a', 1);
14216 assert.strictEqual(matches.length, 1);
14217 assert.strictEqual(matches(object), true);
14219 matches = _.matchesProperty('b', 3);
14220 assert.strictEqual(matches(object), false);
14222 matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
14223 assert.strictEqual(matches({ 'a': object }), true);
14225 matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
14226 assert.strictEqual(matches(object), false);
14228 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
14229 matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
14231 assert.strictEqual(matches(object), true);
14234 QUnit.test('should support deep paths', function(assert) {
14237 var object = { 'a': { 'b': 2 } };
14239 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14240 var matches = _.matchesProperty(path, 2);
14241 assert.strictEqual(matches(object), true);
14245 QUnit.test('should work with a non-string `path`', function(assert) {
14248 var array = [1, 2, 3];
14250 lodashStable.each([1, [1]], function(path) {
14251 var matches = _.matchesProperty(path, 2);
14252 assert.strictEqual(matches(array), true);
14256 QUnit.test('should preserve the sign of `0`', function(assert) {
14259 var object1 = { '-0': 'a' },
14260 object2 = { '0': 'b' },
14261 pairs = [[object1, object2], [object1, object2], [object2, object1], [object2, object1]],
14262 props = [-0, Object(-0), 0, Object(0)],
14263 values = ['a', 'a', 'b', 'b'],
14264 expected = lodashStable.map(props, lodashStable.constant([true, false]));
14266 var actual = lodashStable.map(props, function(key, index) {
14267 var matches = _.matchesProperty(key, values[index]),
14268 pair = pairs[index];
14270 return [matches(pair[0]), matches(pair[1])];
14273 assert.deepEqual(actual, expected);
14276 QUnit.test('should coerce key to a string', function(assert) {
14280 fn.toString = lodashStable.constant('fn');
14282 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
14283 values = [null, undefined, fn, {}];
14285 var expected = lodashStable.transform(values, function(result) {
14286 result.push(true, true);
14289 var actual = lodashStable.transform(objects, function(result, object, index) {
14290 var key = values[index];
14291 lodashStable.each([key, [key]], function(path) {
14292 var matches = _.matchesProperty(path, object[key]);
14293 result.push(matches(object));
14297 assert.deepEqual(actual, expected);
14300 QUnit.test('should match a key over a path', function(assert) {
14303 var object = { 'a.b': 1, 'a': { 'b': 2 } };
14305 lodashStable.each(['a.b', ['a.b']], function(path) {
14306 var matches = _.matchesProperty(path, 1);
14307 assert.strictEqual(matches(object), true);
14311 QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
14316 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
14317 var matches = _.matchesProperty(path, 1);
14318 assert.strictEqual(matches(object), false);
14322 QUnit.test('should return `false` for deep paths when `object` is nullish', function(assert) {
14325 var values = [, null, undefined],
14326 expected = lodashStable.map(values, stubFalse);
14328 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
14329 var matches = _.matchesProperty(path, 1);
14331 var actual = lodashStable.map(values, function(value, index) {
14333 return index ? matches(value) : matches();
14337 assert.deepEqual(actual, expected);
14341 QUnit.test('should match inherited string keyed `srcValue` properties', function(assert) {
14345 Foo.prototype.b = 2;
14347 var object = { 'a': new Foo };
14349 lodashStable.each(['a', ['a']], function(path) {
14350 var matches = _.matchesProperty(path, { 'b': 2 });
14351 assert.strictEqual(matches(object), true);
14355 QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
14361 Foo.prototype.b = 2;
14363 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
14364 expected = lodashStable.map(objects, stubTrue);
14366 lodashStable.each(['a', ['a']], function(path) {
14367 assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
14371 QUnit.test('should compare a variety of values', function(assert) {
14374 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
14375 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
14376 matches = _.matchesProperty('a', object1);
14378 assert.strictEqual(matches({ 'a': object1 }), true);
14379 assert.strictEqual(matches({ 'a': object2 }), false);
14382 QUnit.test('should match `-0` as `0`', function(assert) {
14385 var matches = _.matchesProperty('a', -0);
14386 assert.strictEqual(matches({ 'a': 0 }), true);
14388 matches = _.matchesProperty('a', 0);
14389 assert.strictEqual(matches({ 'a': -0 }), true);
14392 QUnit.test('should compare functions by reference', function(assert) {
14395 var object1 = { 'a': lodashStable.noop },
14396 object2 = { 'a': noop },
14397 object3 = { 'a': {} },
14398 matches = _.matchesProperty('a', object1);
14400 assert.strictEqual(matches({ 'a': object1 }), true);
14401 assert.strictEqual(matches({ 'a': object2 }), false);
14402 assert.strictEqual(matches({ 'a': object3 }), false);
14405 QUnit.test('should work with a function for `srcValue`', function(assert) {
14410 Foo.b = function() {};
14413 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
14414 actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
14416 assert.deepEqual(actual, [false, true]);
14419 QUnit.test('should work with a non-plain `srcValue`', function(assert) {
14422 function Foo(object) { lodashStable.assign(this, object); }
14424 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
14425 matches = _.matchesProperty('a', { 'b': 1 });
14427 assert.strictEqual(matches(object), true);
14430 QUnit.test('should partial match arrays', function(assert) {
14433 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
14434 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
14436 assert.deepEqual(actual, [objects[1]]);
14438 actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
14439 assert.deepEqual(actual, []);
14441 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
14442 assert.deepEqual(actual, []);
14445 QUnit.test('should partial match arrays with duplicate values', function(assert) {
14448 var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
14449 actual = lodashStable.filter(objects, _.matchesProperty('a', [2, 2]));
14451 assert.deepEqual(actual, [objects[1]]);
14454 QUnit.test('should partial match arrays of objects', function(assert) {
14458 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
14459 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
14462 var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
14463 assert.deepEqual(actual, [objects[0]]);
14465 QUnit.test('should partial match maps', function(assert) {
14469 var objects = [{ 'a': new Map }, { 'a': new Map }];
14470 objects[0].a.set('a', 1);
14471 objects[1].a.set('a', 1);
14472 objects[1].a.set('b', 2);
14476 var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14478 assert.deepEqual(actual, [objects[1]]);
14480 map['delete']('b');
14481 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14483 assert.deepEqual(actual, objects);
14486 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14488 assert.deepEqual(actual, []);
14491 skipAssert(assert, 3);
14495 QUnit.test('should partial match sets', function(assert) {
14499 var objects = [{ 'a': new Set }, { 'a': new Set }];
14500 objects[0].a.add(1);
14501 objects[1].a.add(1);
14502 objects[1].a.add(2);
14506 var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14508 assert.deepEqual(actual, [objects[1]]);
14511 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14513 assert.deepEqual(actual, objects);
14516 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14518 assert.deepEqual(actual, []);
14521 skipAssert(assert, 3);
14525 QUnit.test('should match `undefined` values', function(assert) {
14528 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
14529 actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
14530 expected = [false, false, true];
14532 assert.deepEqual(actual, expected);
14534 objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
14535 actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
14537 assert.deepEqual(actual, expected);
14540 QUnit.test('should match `undefined` values of nested objects', function(assert) {
14543 var object = { 'a': { 'b': undefined } };
14545 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14546 var matches = _.matchesProperty(path, undefined);
14547 assert.strictEqual(matches(object), true);
14550 lodashStable.each(['a.a', ['a', 'a']], function(path) {
14551 var matches = _.matchesProperty(path, undefined);
14552 assert.strictEqual(matches(object), false);
14556 QUnit.test('should match `undefined` values on primitives', function(assert) {
14560 numberProto.b = undefined;
14563 var matches = _.matchesProperty('b', undefined);
14564 assert.strictEqual(matches(1), true);
14566 assert.ok(false, e.message);
14568 numberProto.a = { 'b': 1, 'c': undefined };
14570 matches = _.matchesProperty('a', { 'c': undefined });
14571 assert.strictEqual(matches(1), true);
14573 assert.ok(false, e.message);
14575 delete numberProto.a;
14576 delete numberProto.b;
14579 QUnit.test('should return `false` when `object` is nullish', function(assert) {
14582 var values = [, null, undefined],
14583 expected = lodashStable.map(values, stubFalse);
14585 lodashStable.each(['constructor', ['constructor']], function(path) {
14586 var matches = _.matchesProperty(path, 1);
14588 var actual = lodashStable.map(values, function(value, index) {
14590 return index ? matches(value) : matches();
14594 assert.deepEqual(actual, expected);
14598 QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
14601 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
14602 matches = _.matchesProperty('a', { 'a': [], 'b': {} });
14604 var actual = lodashStable.filter(objects, function(object) {
14605 return matches({ 'a': object });
14608 assert.deepEqual(actual, objects);
14611 QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
14614 lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
14615 var object = lodashStable.cloneDeep(source),
14616 matches = _.matchesProperty('a', source);
14618 assert.strictEqual(matches({ 'a': object }), true);
14629 assert.strictEqual(matches({ 'a': object }), true);
14630 assert.strictEqual(matches({ 'a': source }), false);
14635 /*--------------------------------------------------------------------------*/
14637 QUnit.module('lodash.max');
14640 QUnit.test('should return the largest value from a collection', function(assert) {
14643 assert.strictEqual(_.max([1, 2, 3]), 3);
14646 QUnit.test('should return `undefined` for empty collections', function(assert) {
14649 var values = falsey.concat([[]]),
14650 expected = lodashStable.map(values, noop);
14652 var actual = lodashStable.map(values, function(value, index) {
14654 return index ? _.max(value) : _.max();
14658 assert.deepEqual(actual, expected);
14661 QUnit.test('should work with non-numeric collection values', function(assert) {
14664 assert.strictEqual(_.max(['a', 'b']), 'b');
14668 /*--------------------------------------------------------------------------*/
14670 QUnit.module('lodash.mean');
14673 QUnit.test('should return the mean of an array of numbers', function(assert) {
14676 var array = [4, 2, 8, 6];
14677 assert.strictEqual(_.mean(array), 5);
14680 QUnit.test('should return `NaN` when passing empty `array` values', function(assert) {
14683 var expected = lodashStable.map(empties, stubNaN),
14684 actual = lodashStable.map(empties, _.mean);
14686 assert.deepEqual(actual, expected);
14690 /*--------------------------------------------------------------------------*/
14692 QUnit.module('lodash.meanBy');
14695 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
14697 QUnit.test('should work with an `iteratee` argument', function(assert) {
14700 var actual = _.meanBy(objects, function(object) {
14704 assert.deepEqual(actual, 2);
14707 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
14712 _.meanBy(objects, function() {
14713 args || (args = slice.call(arguments));
14716 assert.deepEqual(args, [{ 'a': 2 }]);
14719 QUnit.test('should work with `_.property` shorthands', function(assert) {
14722 var arrays = [[2], [3], [1]];
14723 assert.strictEqual(_.meanBy(arrays, 0), 2);
14724 assert.strictEqual(_.meanBy(objects, 'a'), 2);
14728 /*--------------------------------------------------------------------------*/
14730 QUnit.module('lodash.memoize');
14733 QUnit.test('should memoize results based on the first argument given', function(assert) {
14736 var memoized = _.memoize(function(a, b, c) {
14740 assert.strictEqual(memoized(1, 2, 3), 6);
14741 assert.strictEqual(memoized(1, 3, 5), 6);
14744 QUnit.test('should support a `resolver` argument', function(assert) {
14747 var fn = function(a, b, c) { return a + b + c; },
14748 memoized = _.memoize(fn, fn);
14750 assert.strictEqual(memoized(1, 2, 3), 6);
14751 assert.strictEqual(memoized(1, 3, 5), 9);
14754 QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
14757 var fn = function(a, b, c) { return a + this.b + this.c; },
14758 memoized = _.memoize(fn, fn);
14760 var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
14761 assert.strictEqual(object.memoized(1), 6);
14765 assert.strictEqual(object.memoized(1), 9);
14768 QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
14771 assert.raises(function() { _.memoize(noop, true); }, TypeError);
14774 QUnit.test('should not error if `resolver` is falsey', function(assert) {
14777 var expected = lodashStable.map(falsey, stubTrue);
14779 var actual = lodashStable.map(falsey, function(resolver, index) {
14781 return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
14785 assert.deepEqual(actual, expected);
14788 QUnit.test('should check cache for own properties', function(assert) {
14795 'propertyIsEnumerable',
14801 var memoized = _.memoize(identity);
14803 var actual = lodashStable.map(props, function(value) {
14804 return memoized(value);
14807 assert.deepEqual(actual, props);
14810 QUnit.test('should cache the `__proto__` key', function(assert) {
14816 lodashStable.times(2, function(index) {
14818 resolver = index && identity;
14820 var memoized = _.memoize(function() {
14825 var cache = memoized.cache;
14830 assert.strictEqual(count, 1);
14831 assert.strictEqual(cache.get(key), array);
14832 assert.notOk(cache.__data__ instanceof Array);
14833 assert.strictEqual(cache['delete'](key), true);
14837 QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
14840 var oldCache = _.memoize.Cache;
14843 this.__data__ = [];
14846 Cache.prototype = {
14847 'get': function(key) {
14848 var entry = _.find(this.__data__, function(entry) {
14849 return key === entry.key;
14851 return entry && entry.value;
14853 'has': function(key) {
14854 return _.some(this.__data__, function(entry) {
14855 return key === entry.key;
14858 'set': function(key, value) {
14859 this.__data__.push({ 'key': key, 'value': value });
14864 _.memoize.Cache = Cache;
14866 var memoized = _.memoize(function(object) {
14867 return 'value:' + object.id;
14870 var cache = memoized.cache,
14871 key1 = { 'id': 'a' },
14872 key2 = { 'id': 'b' };
14874 assert.strictEqual(memoized(key1), 'value:a');
14875 assert.strictEqual(cache.has(key1), true);
14877 assert.strictEqual(memoized(key2), 'value:b');
14878 assert.strictEqual(cache.has(key2), true);
14880 _.memoize.Cache = oldCache;
14883 QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
14886 var oldCache = _.memoize.Cache;
14889 this.__data__ = [];
14892 Cache.prototype = {
14893 'get': function(key) {
14894 return _.find(this.__data__, function(entry) {
14895 return key === entry.key;
14898 'has': function(key) {
14899 return _.some(this.__data__, function(entry) {
14900 return key === entry.key;
14903 'set': function(key, value) {
14904 var result = new Cache;
14905 result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
14910 _.memoize.Cache = Cache;
14912 var memoized = _.memoize(function(object) {
14916 var key1 = { 'id': 'a' },
14917 key2 = { 'id': 'b' };
14922 var cache = memoized.cache;
14923 assert.strictEqual(cache.has(key1), true);
14924 assert.strictEqual(cache.has(key2), true);
14926 _.memoize.Cache = oldCache;
14930 /*--------------------------------------------------------------------------*/
14932 QUnit.module('lodash.merge');
14935 var args = arguments;
14937 QUnit.test('should merge `source` into `object`', function(assert) {
14942 { 'name': 'barney' },
14956 { 'height': '5\'4"' },
14957 { 'height': '5\'5"' }
14963 { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
14964 { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
14968 assert.deepEqual(_.merge(names, ages, heights), expected);
14971 QUnit.test('should merge sources containing circular references', function(assert) {
14980 'foo': { 'b': { 'c': { 'd': {} } } },
14984 source.foo.b.c.d = source;
14985 source.bar.b = source.foo.b;
14987 var actual = _.merge(object, source);
14989 assert.notStrictEqual(actual.bar.b, actual.foo.b);
14990 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
14993 QUnit.test('should work with four arguments', function(assert) {
14996 var expected = { 'a': 4 },
14997 actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
14999 assert.deepEqual(actual, expected);
15002 QUnit.test('should merge onto function `object` values', function(assert) {
15007 var source = { 'a': 1 },
15008 actual = _.merge(Foo, source);
15010 assert.strictEqual(actual, Foo);
15011 assert.strictEqual(Foo.a, 1);
15014 QUnit.test('should not merge onto function values of sources', function(assert) {
15017 var source1 = { 'a': function() {} },
15018 source2 = { 'a': { 'b': 2 } },
15019 actual = _.merge({}, source1, source2);
15021 assert.deepEqual(actual, { 'a': { 'b': 2 } });
15023 actual = _.merge(source1, source2);
15025 assert.strictEqual(typeof actual.a, 'function');
15026 assert.strictEqual(actual.a.b, 2);
15029 QUnit.test('should merge onto non-plain `object` values', function(assert) {
15034 var object = new Foo,
15035 actual = _.merge(object, { 'a': 1 });
15037 assert.strictEqual(actual, object);
15038 assert.strictEqual(object.a, 1);
15041 QUnit.test('should treat sparse array sources as dense', function(assert) {
15047 var actual = _.merge([], array),
15048 expected = array.slice();
15050 expected[1] = undefined;
15052 assert.ok('1' in actual);
15053 assert.deepEqual(actual, expected);
15056 QUnit.test('should merge `arguments` objects', function(assert) {
15059 var object1 = { 'value': args },
15060 object2 = { 'value': { '3': 4 } },
15061 expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
15062 actual = _.merge(object1, object2);
15064 assert.notOk('3' in args);
15065 assert.notOk(_.isArguments(actual.value));
15066 assert.deepEqual(actual.value, expected);
15067 object1.value = args;
15069 actual = _.merge(object2, object1);
15070 assert.notOk(_.isArguments(actual.value));
15071 assert.deepEqual(actual.value, expected);
15073 expected = { '0': 1, '1': 2, '2': 3 };
15075 actual = _.merge({}, object1);
15076 assert.notOk(_.isArguments(actual.value));
15077 assert.deepEqual(actual.value, expected);
15080 QUnit.test('should merge typed arrays', function(assert) {
15085 array3 = [0, 0, 0, 0],
15086 array4 = [0, 0, 0, 0, 0, 0, 0, 0];
15088 var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
15089 buffer = ArrayBuffer && new ArrayBuffer(8);
15091 // Juggle for `Float64Array` shim.
15092 if (root.Float64Array && (new Float64Array(buffer)).length == 8) {
15093 arrays[1] = array4;
15095 var expected = lodashStable.map(typedArrays, function(type, index) {
15096 var array = arrays[index].slice();
15098 return root[type] ? { 'value': array } : false;
15101 var actual = lodashStable.map(typedArrays, function(type) {
15102 var Ctor = root[type];
15103 return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
15106 assert.ok(lodashStable.isArray(actual));
15107 assert.deepEqual(actual, expected);
15109 expected = lodashStable.map(typedArrays, function(type, index) {
15110 var array = arrays[index].slice();
15112 return root[type] ? { 'value': array } : false;
15115 actual = lodashStable.map(typedArrays, function(type, index) {
15116 var Ctor = root[type],
15117 array = lodashStable.range(arrays[index].length);
15120 return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
15123 assert.ok(lodashStable.isArray(actual));
15124 assert.deepEqual(actual, expected);
15127 QUnit.test('should assign `null` values', function(assert) {
15130 var actual = _.merge({ 'a': 1 }, { 'a': null });
15131 assert.strictEqual(actual.a, null);
15134 QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) {
15139 var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
15140 expected = lodashStable.map(values, stubTrue);
15142 var actual = lodashStable.map(values, function(value) {
15143 var object = _.merge({}, { 'value': value });
15144 return object.value === value;
15147 assert.deepEqual(actual, expected);
15150 QUnit.test('should deep clone array/typed-array/plain-object sources', function(assert) {
15153 var typedArray = Uint8Array
15154 ? new Uint8Array(new ArrayBuffer(2))
15155 : { 'buffer': [0, 0] };
15157 var props = ['0', 'a', 'buffer'],
15158 values = [[{ 'a': 1 }], { 'a': [1] }, typedArray],
15159 expected = lodashStable.map(values, stubTrue);
15161 var actual = lodashStable.map(values, function(value, index) {
15162 var key = props[index],
15163 object = _.merge({}, { 'value': value }),
15164 newValue = object.value;
15167 newValue !== value &&
15168 newValue[key] !== value[key] &&
15169 lodashStable.isEqual(newValue, value)
15173 assert.deepEqual(actual, expected);
15176 QUnit.test('should not augment source objects', function(assert) {
15179 var source1 = { 'a': [{ 'a': 1 }] },
15180 source2 = { 'a': [{ 'b': 2 }] },
15181 actual = _.merge({}, source1, source2);
15183 assert.deepEqual(source1.a, [{ 'a': 1 }]);
15184 assert.deepEqual(source2.a, [{ 'b': 2 }]);
15185 assert.deepEqual(actual.a, [{ 'a': 1, 'b': 2 }]);
15187 var source1 = { 'a': [[1, 2, 3]] },
15188 source2 = { 'a': [[3, 4]] },
15189 actual = _.merge({}, source1, source2);
15191 assert.deepEqual(source1.a, [[1, 2, 3]]);
15192 assert.deepEqual(source2.a, [[3, 4]]);
15193 assert.deepEqual(actual.a, [[3, 4, 3]]);
15196 QUnit.test('should merge plain-objects onto non plain-objects', function(assert) {
15199 function Foo(object) {
15200 lodashStable.assign(this, object);
15203 var object = { 'a': 1 },
15204 actual = _.merge(new Foo, object);
15206 assert.ok(actual instanceof Foo);
15207 assert.deepEqual(actual, new Foo(object));
15209 actual = _.merge([new Foo], [object]);
15210 assert.ok(actual[0] instanceof Foo);
15211 assert.deepEqual(actual, [new Foo(object)]);
15214 QUnit.test('should not assign `undefined` values', function(assert) {
15217 var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
15218 assert.deepEqual(actual, { 'a': 1 });
15221 QUnit.test('should skip `undefined` values in array sources if a destination value exists', function(assert) {
15227 var actual = _.merge([4, 5, 6], array),
15228 expected = [1, 5, 3];
15230 assert.deepEqual(actual, expected);
15233 array[1] = undefined;
15235 actual = _.merge([4, 5, 6], array);
15236 assert.deepEqual(actual, expected);
15239 QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
15245 defineProperty(object, 'a', {
15246 'enumerable': true,
15247 'configurable': true,
15248 'get': function() { pass = false; },
15249 'set': function() { pass = false; }
15252 _.merge(object, object);
15256 QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
15259 var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
15260 actual = _.merge(object, { 'a': ['x'] });
15262 assert.deepEqual(actual, { 'a': ['x', 'y'] });
15264 actual = _.merge({ 'a': {} }, { 'a': [] });
15265 assert.deepEqual(actual, { 'a': [] });
15268 QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
15271 var object = { 'a': 'abcde' },
15272 actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
15274 assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
15277 QUnit.test('should not error on DOM elements', function(assert) {
15280 var object1 = { 'el': document && document.createElement('div') },
15281 object2 = { 'el': document && document.createElement('div') },
15282 pairs = [[{}, object1], [object1, object2]],
15283 expected = lodashStable.map(pairs, stubTrue);
15285 var actual = lodashStable.map(pairs, function(pair) {
15287 return _.merge(pair[0], pair[1]).el === pair[1].el;
15291 assert.deepEqual(actual, expected);
15295 /*--------------------------------------------------------------------------*/
15297 QUnit.module('lodash.mergeWith');
15300 QUnit.test('should handle merging when `customizer` returns `undefined`', function(assert) {
15303 var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
15304 assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
15306 actual = _.mergeWith([], [undefined], identity);
15307 assert.deepEqual(actual, [undefined]);
15310 QUnit.test('should clone sources when `customizer` returns `undefined`', function(assert) {
15313 var source1 = { 'a': { 'b': { 'c': 1 } } },
15314 source2 = { 'a': { 'b': { 'd': 2 } } };
15316 _.mergeWith({}, source1, source2, noop);
15317 assert.deepEqual(source1.a.b, { 'c': 1 });
15320 QUnit.test('should defer to `customizer` for non `undefined` results', function(assert) {
15323 var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
15324 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15327 assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
15330 QUnit.test('should provide `stack` to `customizer`', function(assert) {
15335 _.mergeWith({}, { 'a': { 'b': 2 } }, function() {
15336 actual = _.last(arguments);
15340 ? actual.constructor.name == 'Stack'
15341 : actual instanceof mapCaches.Stack
15345 QUnit.test('should overwrite primitives with source object clones', function(assert) {
15348 var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) {
15349 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15352 assert.deepEqual(actual, { 'a': { 'b': ['c'] } });
15355 QUnit.test('should pop the stack of sources for each sibling property', function(assert) {
15358 var array = ['b', 'c'],
15359 object = { 'a': ['a'] },
15360 source = { 'a': array, 'b': array };
15362 var actual = _.mergeWith(object, source, function(a, b) {
15363 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15366 assert.deepEqual(actual, { 'a': ['a', 'b', 'c'], 'b': ['b', 'c'] });
15370 /*--------------------------------------------------------------------------*/
15372 QUnit.module('lodash.method');
15375 QUnit.test('should create a function that calls a method of a given object', function(assert) {
15378 var object = { 'a': stubOne };
15380 lodashStable.each(['a', ['a']], function(path) {
15381 var method = _.method(path);
15382 assert.strictEqual(method.length, 1);
15383 assert.strictEqual(method(object), 1);
15387 QUnit.test('should work with deep property values', function(assert) {
15390 var object = { 'a': { 'b': stubTwo } };
15392 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15393 var method = _.method(path);
15394 assert.strictEqual(method(object), 2);
15398 QUnit.test('should work with a non-string `path`', function(assert) {
15401 var array = lodashStable.times(3, _.constant);
15403 lodashStable.each([1, [1]], function(path) {
15404 var method = _.method(path);
15405 assert.strictEqual(method(array), 1);
15409 QUnit.test('should coerce key to a string', function(assert) {
15413 fn.toString = lodashStable.constant('fn');
15415 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15416 objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
15417 values = [null, undefined, fn, {}];
15419 var actual = lodashStable.transform(objects, function(result, object, index) {
15420 var key = values[index];
15421 lodashStable.each([key, [key]], function(path) {
15422 var method = _.method(key);
15423 result.push(method(object));
15427 assert.deepEqual(actual, expected);
15430 QUnit.test('should work with inherited property values', function(assert) {
15434 Foo.prototype.a = stubOne;
15436 lodashStable.each(['a', ['a']], function(path) {
15437 var method = _.method(path);
15438 assert.strictEqual(method(new Foo), 1);
15442 QUnit.test('should use a key over a path', function(assert) {
15445 var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
15447 lodashStable.each(['a.b', ['a.b']], function(path) {
15448 var method = _.method(path);
15449 assert.strictEqual(method(object), 1);
15453 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15456 var values = [, null, undefined],
15457 expected = lodashStable.map(values, noop);
15459 lodashStable.each(['constructor', ['constructor']], function(path) {
15460 var method = _.method(path);
15462 var actual = lodashStable.map(values, function(value, index) {
15463 return index ? method(value) : method();
15466 assert.deepEqual(actual, expected);
15470 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15473 var values = [, null, undefined],
15474 expected = lodashStable.map(values, noop);
15476 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15477 var method = _.method(path);
15479 var actual = lodashStable.map(values, function(value, index) {
15480 return index ? method(value) : method();
15483 assert.deepEqual(actual, expected);
15487 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15492 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15493 var method = _.method(path);
15494 assert.strictEqual(method(object), undefined);
15498 QUnit.test('should apply partial arguments to function', function(assert) {
15503 return slice.call(arguments);
15507 lodashStable.each(['fn', ['fn']], function(path) {
15508 var method = _.method(path, 1, 2, 3);
15509 assert.deepEqual(method(object), [1, 2, 3]);
15513 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15516 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
15518 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15519 var method = _.method(path);
15520 assert.strictEqual(method(object), 1);
15525 /*--------------------------------------------------------------------------*/
15527 QUnit.module('lodash.methodOf');
15530 QUnit.test('should create a function that calls a method of a given key', function(assert) {
15533 var object = { 'a': stubOne };
15535 lodashStable.each(['a', ['a']], function(path) {
15536 var methodOf = _.methodOf(object);
15537 assert.strictEqual(methodOf.length, 1);
15538 assert.strictEqual(methodOf(path), 1);
15542 QUnit.test('should work with deep property values', function(assert) {
15545 var object = { 'a': { 'b': stubTwo } };
15547 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15548 var methodOf = _.methodOf(object);
15549 assert.strictEqual(methodOf(path), 2);
15553 QUnit.test('should work with a non-string `path`', function(assert) {
15556 var array = lodashStable.times(3, _.constant);
15558 lodashStable.each([1, [1]], function(path) {
15559 var methodOf = _.methodOf(array);
15560 assert.strictEqual(methodOf(path), 1);
15564 QUnit.test('should coerce key to a string', function(assert) {
15568 fn.toString = lodashStable.constant('fn');
15570 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15571 objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
15572 values = [null, undefined, fn, {}];
15574 var actual = lodashStable.transform(objects, function(result, object, index) {
15575 var key = values[index];
15576 lodashStable.each([key, [key]], function(path) {
15577 var methodOf = _.methodOf(object);
15578 result.push(methodOf(key));
15582 assert.deepEqual(actual, expected);
15585 QUnit.test('should work with inherited property values', function(assert) {
15589 Foo.prototype.a = stubOne;
15591 lodashStable.each(['a', ['a']], function(path) {
15592 var methodOf = _.methodOf(new Foo);
15593 assert.strictEqual(methodOf(path), 1);
15597 QUnit.test('should use a key over a path', function(assert) {
15600 var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
15602 lodashStable.each(['a.b', ['a.b']], function(path) {
15603 var methodOf = _.methodOf(object);
15604 assert.strictEqual(methodOf(path), 1);
15608 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15611 var values = [, null, undefined],
15612 expected = lodashStable.map(values, noop);
15614 lodashStable.each(['constructor', ['constructor']], function(path) {
15615 var actual = lodashStable.map(values, function(value, index) {
15616 var methodOf = index ? _.methodOf() : _.methodOf(value);
15617 return methodOf(path);
15620 assert.deepEqual(actual, expected);
15624 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
15627 var values = [, null, undefined],
15628 expected = lodashStable.map(values, noop);
15630 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15631 var actual = lodashStable.map(values, function(value, index) {
15632 var methodOf = index ? _.methodOf() : _.methodOf(value);
15633 return methodOf(path);
15636 assert.deepEqual(actual, expected);
15640 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15644 methodOf = _.methodOf(object);
15646 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15647 assert.strictEqual(methodOf(path), undefined);
15651 QUnit.test('should apply partial arguments to function', function(assert) {
15656 return slice.call(arguments);
15660 var methodOf = _.methodOf(object, 1, 2, 3);
15662 lodashStable.each(['fn', ['fn']], function(path) {
15663 assert.deepEqual(methodOf(path), [1, 2, 3]);
15667 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15670 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
15671 methodOf = _.methodOf(object);
15673 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15674 assert.strictEqual(methodOf(path), 1);
15679 /*--------------------------------------------------------------------------*/
15681 QUnit.module('lodash.min');
15684 QUnit.test('should return the smallest value from a collection', function(assert) {
15687 assert.strictEqual(_.min([1, 2, 3]), 1);
15690 QUnit.test('should return `undefined` for empty collections', function(assert) {
15693 var values = falsey.concat([[]]),
15694 expected = lodashStable.map(values, noop);
15696 var actual = lodashStable.map(values, function(value, index) {
15698 return index ? _.min(value) : _.min();
15702 assert.deepEqual(actual, expected);
15705 QUnit.test('should work with non-numeric collection values', function(assert) {
15708 assert.strictEqual(_.min(['a', 'b']), 'a');
15712 /*--------------------------------------------------------------------------*/
15714 QUnit.module('extremum methods');
15716 lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
15717 var func = _[methodName],
15718 isMax = /^max/.test(methodName);
15720 QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
15723 var curr = new Date,
15724 past = new Date(0);
15726 assert.strictEqual(func([curr, past]), isMax ? curr : past);
15729 QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
15732 var array = lodashStable.range(0, 5e5);
15733 assert.strictEqual(func(array), isMax ? 499999 : 0);
15736 QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
15740 var actual = _([40])[methodName]();
15741 assert.strictEqual(actual, 40);
15744 skipAssert(assert);
15749 lodashStable.each(['maxBy', 'minBy'], function(methodName) {
15750 var array = [1, 2, 3],
15751 func = _[methodName],
15752 isMax = methodName == 'maxBy';
15754 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
15757 var actual = func(array, function(n) {
15761 assert.strictEqual(actual, isMax ? 1 : 3);
15764 QUnit.test('should work with `_.property` shorthands', function(assert) {
15767 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
15768 actual = func(objects, 'a');
15770 assert.deepEqual(actual, objects[isMax ? 1 : 2]);
15772 var arrays = [[2], [3], [1]];
15773 actual = func(arrays, 0);
15775 assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
15778 QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
15781 var value = isMax ? -Infinity : Infinity,
15782 object = { 'a': value };
15784 var actual = func([object, { 'a': value }], function(object) {
15788 assert.strictEqual(actual, object);
15792 /*--------------------------------------------------------------------------*/
15794 QUnit.module('lodash.mixin');
15797 function reset(wrapper) {
15799 delete wrapper.prototype.a;
15801 delete wrapper.prototype.b;
15804 function Wrapper(value) {
15805 if (!(this instanceof Wrapper)) {
15806 return new Wrapper(value);
15808 if (_.has(value, '__wrapped__')) {
15809 var actions = slice.call(value.__actions__),
15810 chain = value.__chain__;
15812 value = value.__wrapped__;
15814 this.__wrapped__ = value;
15815 this.__actions__ = actions || [];
15816 this.__chain__ = chain || false;
15819 Wrapper.prototype.value = function() {
15820 return getUnwrappedValue(this);
15824 source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
15826 QUnit.test('should mixin `source` methods into lodash', function(assert) {
15832 assert.strictEqual(_.a(array), 'a');
15833 assert.strictEqual(_(array).a().value(), 'a');
15834 assert.notOk('b' in _);
15835 assert.notOk('b' in _.prototype);
15840 skipAssert(assert, 4);
15844 QUnit.test('should mixin chaining methods by reference', function(assert) {
15851 assert.strictEqual(_.a(array), 'b');
15852 assert.strictEqual(_(array).a().value(), 'a');
15857 skipAssert(assert, 2);
15861 QUnit.test('should use a default `object` of `this`', function(assert) {
15864 var object = lodashStable.create(_);
15865 object.mixin(source);
15867 assert.strictEqual(object.a(array), 'a');
15868 assert.notOk('a' in _);
15869 assert.notOk('a' in _.prototype);
15874 QUnit.test('should accept an `object` argument', function(assert) {
15878 _.mixin(object, source);
15879 assert.strictEqual(object.a(array), 'a');
15882 QUnit.test('should accept a function `object`', function(assert) {
15885 _.mixin(Wrapper, source);
15887 var wrapped = Wrapper(array),
15888 actual = wrapped.a();
15890 assert.strictEqual(actual.value(), 'a');
15891 assert.ok(actual instanceof Wrapper);
15896 QUnit.test('should return `object`', function(assert) {
15900 assert.strictEqual(_.mixin(object, source), object);
15901 assert.strictEqual(_.mixin(Wrapper, source), Wrapper);
15902 assert.strictEqual(_.mixin(), _);
15907 QUnit.test('should not assign inherited `source` methods', function(assert) {
15911 Foo.prototype.a = noop;
15914 assert.strictEqual(_.mixin(object, new Foo), object);
15917 QUnit.test('should accept an `options` argument', function(assert) {
15920 function message(func, chain) {
15921 return (func === _ ? 'lodash' : 'given') + ' function should ' + (chain ? '' : 'not ') + 'chain';
15924 lodashStable.each([_, Wrapper], function(func) {
15925 lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
15928 _.mixin(source, options);
15930 _.mixin(func, source, options);
15932 var wrapped = func(array),
15933 actual = wrapped.a();
15935 if (options.chain) {
15936 assert.strictEqual(actual.value(), 'a', message(func, true));
15937 assert.ok(actual instanceof func, message(func, true));
15939 assert.strictEqual(actual, 'a', message(func, false));
15940 assert.notOk(actual instanceof func, message(func, false));
15945 skipAssert(assert, 2);
15951 QUnit.test('should not extend lodash when an `object` is given with an empty `options` object', function(assert) {
15954 _.mixin({ 'a': noop }, {});
15955 assert.notOk('a' in _);
15959 QUnit.test('should not error for non-object `options` values', function(assert) {
15965 _.mixin({}, source, 1);
15974 _.mixin(source, 1);
15983 QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
15986 lodashStable.each([_, Wrapper], function(func) {
15989 var wrapped = _(source),
15990 actual = wrapped.mixin();
15992 assert.strictEqual(actual.value(), _);
15996 actual = wrapped.mixin(source);
15997 assert.notStrictEqual(actual, wrapped);
16002 skipAssert(assert);
16007 QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
16011 _.mixin({ 'a': _.countBy, 'b': _.filter });
16013 var array = lodashStable.range(LARGE_ARRAY_SIZE),
16014 actual = _(array).a().map(square).b(isEven).take().value();
16016 assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
16021 skipAssert(assert);
16026 /*--------------------------------------------------------------------------*/
16028 QUnit.module('lodash.multiply');
16031 QUnit.test('should multiply two numbers', function(assert) {
16034 assert.strictEqual(_.multiply(6, 4), 24);
16035 assert.strictEqual(_.multiply(-6, 4), -24);
16036 assert.strictEqual(_.multiply(-6, -4), 24);
16039 QUnit.test('should coerce arguments to numbers', function(assert) {
16042 assert.strictEqual(_.multiply('6', '4'), 24);
16043 assert.deepEqual(_.multiply('x', 'y'), NaN);
16047 /*--------------------------------------------------------------------------*/
16049 QUnit.module('lodash.orderBy');
16053 { 'a': 'x', 'b': 3 },
16054 { 'a': 'y', 'b': 4 },
16055 { 'a': 'x', 'b': 1 },
16056 { 'a': 'y', 'b': 2 }
16059 QUnit.test('should sort by a single property by a specified order', function(assert) {
16062 var actual = _.orderBy(objects, 'a', 'desc');
16063 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
16066 QUnit.test('should sort by multiple properties by specified orders', function(assert) {
16069 var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
16070 assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
16073 QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
16076 var expected = [objects[2], objects[0], objects[3], objects[1]],
16077 actual = _.orderBy(objects, ['a', 'b']);
16079 assert.deepEqual(actual, expected);
16081 expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
16083 actual = lodashStable.map(falsey, function(order, index) {
16084 return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
16087 assert.deepEqual(actual, expected);
16090 QUnit.test('should work with `orders` specified as string objects', function(assert) {
16093 var actual = _.orderBy(objects, ['a'], [Object('desc')]);
16094 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
16098 /*--------------------------------------------------------------------------*/
16100 QUnit.module('lodash.overArgs');
16104 return slice.call(arguments);
16107 QUnit.test('should transform each argument', function(assert) {
16110 var over = _.overArgs(fn, doubled, square);
16111 assert.deepEqual(over(5, 10), [10, 100]);
16114 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16117 var over = _.overArgs(fn, undefined, null);
16118 assert.deepEqual(over('a', 'b'), ['a', 'b']);
16121 QUnit.test('should work with `_.property` shorthands', function(assert) {
16124 var over = _.overArgs(fn, 'b', 'a');
16125 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [2, 1]);
16128 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16131 var over = _.overArgs(fn, { 'b': 1 }, { 'a': 1 });
16132 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
16135 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16138 var over = _.overArgs(fn, ['b', 1], [['a', 1]]);
16139 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
16142 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16145 var over = _.overArgs(fn, ['a', 1]);
16146 assert.deepEqual(over({ 'a': 1 }, { '1': 2 }), [1, 2]);
16148 over = _.overArgs(fn, [['a', 1]]);
16149 assert.deepEqual(over({ 'a': 1 }), [true]);
16152 QUnit.test('should flatten `transforms`', function(assert) {
16155 var over = _.overArgs(fn, [doubled, square], String);
16156 assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
16159 QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
16162 var over = _.overArgs(fn, doubled, square);
16163 assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
16166 QUnit.test('should not transform any arguments if no transforms are given', function(assert) {
16169 var over = _.overArgs(fn);
16170 assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
16173 QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
16176 var over = _.overArgs(fn, doubled, identity);
16177 assert.deepEqual(over(5), [10]);
16180 QUnit.test('should provide the correct argument to each transform', function(assert) {
16184 transform = function() { argsList.push(slice.call(arguments)); },
16185 over = _.overArgs(noop, transform, transform, transform);
16188 assert.deepEqual(argsList, [['a'], ['b']]);
16191 QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
16194 var over = _.overArgs(function(x) {
16200 var object = { 'over': over, 'true': 1 };
16201 assert.strictEqual(object.over(object), 1);
16205 /*--------------------------------------------------------------------------*/
16207 QUnit.module('lodash.negate');
16210 QUnit.test('should create a function that negates the result of `func`', function(assert) {
16213 var negate = _.negate(isEven);
16215 assert.strictEqual(negate(1), true);
16216 assert.strictEqual(negate(2), false);
16220 /*--------------------------------------------------------------------------*/
16222 QUnit.module('lodash.noConflict');
16225 QUnit.test('should return the `lodash` function', function(assert) {
16228 if (!isModularize) {
16229 assert.strictEqual(_.noConflict(), oldDash);
16230 assert.notStrictEqual(root._, oldDash);
16234 skipAssert(assert, 2);
16238 QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) {
16241 if (!isModularize) {
16242 var object = root._ = {};
16243 assert.strictEqual(_.noConflict(), oldDash);
16244 assert.strictEqual(root._, object);
16248 skipAssert(assert, 2);
16252 QUnit.test('should work with a `root` of `this`', function(assert) {
16255 if (!coverage && !document && !isModularize && realm.object) {
16256 var fs = require('fs'),
16257 vm = require('vm'),
16259 context = vm.createContext({ '_': expected, 'console': console }),
16260 source = fs.readFileSync(filePath, 'utf8');
16262 vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
16264 assert.strictEqual(context._, expected);
16265 assert.ok(context.lodash);
16268 skipAssert(assert, 2);
16273 /*--------------------------------------------------------------------------*/
16275 QUnit.module('lodash.now');
16278 QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
16281 var done = assert.async();
16283 var stamp = +new Date,
16286 assert.ok(actual >= stamp);
16288 setTimeout(function() {
16289 assert.ok(_.now() > actual);
16294 QUnit.test('should work with mocked `Date.now`', function(assert) {
16297 var now = Date.now;
16300 var actual = _.now();
16303 assert.strictEqual(actual, 'a');
16307 /*--------------------------------------------------------------------------*/
16309 QUnit.module('lodash.nth');
16312 var array = ['a', 'b', 'c', 'd'];
16314 QUnit.test('should get the nth element of `array`', function(assert) {
16317 var actual = lodashStable.map(array, function(value, index) {
16318 return _.nth(array, index);
16321 assert.deepEqual(actual, array);
16324 QUnit.test('should work with a negative `n`', function(assert) {
16327 var actual = lodashStable.map(lodashStable.range(1, array.length + 1), function(n) {
16328 return _.nth(array, -n);
16331 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16334 QUnit.test('should coerce `n` to an integer', function(assert) {
16337 var values = falsey,
16338 expected = lodashStable.map(values, stubA);
16340 var actual = lodashStable.map(values, function(n) {
16341 return n ? _.nth(array, n) : _.nth(array);
16344 assert.deepEqual(actual, expected);
16346 values = ['1', 1.6];
16347 expected = lodashStable.map(values, stubB);
16349 actual = lodashStable.map(values, function(n) {
16350 return _.nth(array, n);
16353 assert.deepEqual(actual, expected);
16356 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16359 var values = [null, undefined, []],
16360 expected = lodashStable.map(values, noop);
16362 var actual = lodashStable.map(values, function(array) {
16363 return _.nth(array, 1);
16366 assert.deepEqual(actual, expected);
16369 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16372 var array = [1, 2],
16373 values = [Infinity, array.length],
16374 expected = lodashStable.map(values, noop);
16378 var actual = lodashStable.map(values, function(n) {
16379 return _.nth(array, n);
16382 assert.deepEqual(actual, expected);
16386 /*--------------------------------------------------------------------------*/
16388 QUnit.module('lodash.nthArg');
16391 var args = ['a', 'b', 'c', 'd'];
16393 QUnit.test('should create a function that returns its nth argument', function(assert) {
16396 var actual = lodashStable.map(args, function(value, index) {
16397 var func = _.nthArg(index);
16398 return func.apply(undefined, args);
16401 assert.deepEqual(actual, args);
16404 QUnit.test('should work with a negative `n`', function(assert) {
16407 var actual = lodashStable.map(lodashStable.range(1, args.length + 1), function(n) {
16408 var func = _.nthArg(-n);
16409 return func.apply(undefined, args);
16412 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16415 QUnit.test('should coerce `n` to an integer', function(assert) {
16418 var values = falsey,
16419 expected = lodashStable.map(values, stubA);
16421 var actual = lodashStable.map(values, function(n) {
16422 var func = n ? _.nthArg(n) : _.nthArg();
16423 return func.apply(undefined, args);
16426 assert.deepEqual(actual, expected);
16428 values = ['1', 1.6];
16429 expected = lodashStable.map(values, stubB);
16431 actual = lodashStable.map(values, function(n) {
16432 var func = _.nthArg(n);
16433 return func.apply(undefined, args);
16436 assert.deepEqual(actual, expected);
16439 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16442 var func = _.nthArg(1);
16443 assert.strictEqual(func(), undefined);
16446 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16449 var values = [Infinity, args.length],
16450 expected = lodashStable.map(values, noop);
16452 var actual = lodashStable.map(values, function(n) {
16453 var func = _.nthArg(n);
16454 return func.apply(undefined, args);
16457 assert.deepEqual(actual, expected);
16461 /*--------------------------------------------------------------------------*/
16463 QUnit.module('lodash.omit');
16466 var args = arguments,
16467 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16469 QUnit.test('should flatten `props`', function(assert) {
16472 assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
16473 assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
16476 QUnit.test('should work with a primitive `object` argument', function(assert) {
16482 assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
16484 delete stringProto.a;
16485 delete stringProto.b;
16488 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
16492 lodashStable.each([null, undefined], function(value) {
16493 assert.deepEqual(_.omit(value, 'valueOf'), {});
16495 delete objectProto.a;
16498 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
16501 assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
16504 QUnit.test('should coerce property names to strings', function(assert) {
16507 assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
16511 /*--------------------------------------------------------------------------*/
16513 QUnit.module('lodash.omitBy');
16516 QUnit.test('should work with a predicate argument', function(assert) {
16519 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16521 var actual = _.omitBy(object, function(n) {
16522 return n != 2 && n != 4;
16525 assert.deepEqual(actual, { 'b': 2, 'd': 4 });
16529 /*--------------------------------------------------------------------------*/
16531 QUnit.module('omit methods');
16533 lodashStable.each(['omit', 'omitBy'], function(methodName) {
16534 var expected = { 'b': 2, 'd': 4 },
16535 func = _[methodName],
16536 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
16537 resolve = lodashStable.nthArg(1);
16539 if (methodName == 'omitBy') {
16540 resolve = function(object, props) {
16541 props = lodashStable.castArray(props);
16542 return function(value) {
16543 return lodashStable.some(props, function(key) {
16544 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
16545 return object[key] === value;
16550 QUnit.test('`_.' + methodName + '` should create an object with omitted string keyed properties', function(assert) {
16553 assert.deepEqual(func(object, resolve(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
16554 assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
16557 QUnit.test('`_.' + methodName + '` should include inherited string keyed properties', function(assert) {
16561 Foo.prototype = object;
16563 assert.deepEqual(func(new Foo, resolve(object, ['a', 'c'])), expected);
16566 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
16569 var object = { '-0': 'a', '0': 'b' },
16570 props = [-0, Object(-0), 0, Object(0)],
16571 expected = [{ '0': 'b' }, { '0': 'b' }, { '-0': 'a' }, { '-0': 'a' }];
16573 var actual = lodashStable.map(props, function(key) {
16574 return func(object, resolve(object, key));
16577 assert.deepEqual(actual, expected);
16580 QUnit.test('`_.' + methodName + '` should include symbol properties', function(assert) {
16589 var symbol2 = Symbol('b');
16590 Foo.prototype[symbol2] = 2;
16593 actual = func(foo, resolve(foo, 'a'));
16595 assert.strictEqual(actual[symbol], 1);
16596 assert.strictEqual(actual[symbol2], 2);
16599 skipAssert(assert, 2);
16603 QUnit.test('`_.' + methodName + '` should create an object with omitted symbol properties', function(assert) {
16612 var symbol2 = Symbol('b');
16613 Foo.prototype[symbol2] = 2;
16616 actual = func(foo, resolve(foo, symbol));
16618 assert.strictEqual(actual.a, 0);
16619 assert.strictEqual(actual[symbol], undefined);
16620 assert.strictEqual(actual[symbol2], 2);
16622 actual = func(foo, resolve(foo, symbol2));
16624 assert.strictEqual(actual.a, 0);
16625 assert.strictEqual(actual[symbol], 1);
16626 assert.strictEqual(actual[symbol2], undefined);
16629 skipAssert(assert, 6);
16633 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
16636 var array = [1, 2, 3];
16637 assert.deepEqual(func(array, resolve(array, ['0', '2'])), { '1': 2 });
16641 /*--------------------------------------------------------------------------*/
16643 QUnit.module('lodash.once');
16646 QUnit.test('should invoke `func` once', function(assert) {
16650 once = _.once(function() { return ++count; });
16653 assert.strictEqual(once(), 1);
16654 assert.strictEqual(count, 1);
16657 QUnit.test('should ignore recursive calls', function(assert) {
16662 var once = _.once(function() {
16667 assert.strictEqual(once(), 1);
16668 assert.strictEqual(count, 1);
16671 QUnit.test('should not throw more than once', function(assert) {
16676 var once = _.once(function() {
16680 assert.raises(once);
16691 /*--------------------------------------------------------------------------*/
16693 QUnit.module('lodash.over');
16696 QUnit.test('should create a function that invokes `iteratees`', function(assert) {
16699 var over = _.over(Math.max, Math.min);
16700 assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
16703 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16706 var over = _.over(undefined, null);
16707 assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
16710 QUnit.test('should work with `_.property` shorthands', function(assert) {
16713 var over = _.over('b', 'a');
16714 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [2, 1]);
16717 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16720 var over = _.over({ 'b': 1 }, { 'a': 1 });
16721 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [false, true]);
16724 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16727 var over = _.over(['b', 2], [['a', 2]]);
16729 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [true, false]);
16730 assert.deepEqual(over({ 'a': 2, 'b': 1 }), [false, true]);
16733 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16736 var over = _.over(['a', 1]);
16738 assert.deepEqual(over({ 'a': 1, '1': 2 }), [1, 2]);
16739 assert.deepEqual(over({ 'a': 2, '1': 1 }), [2, 1]);
16741 over = _.over([['a', 1]]);
16743 assert.deepEqual(over({ 'a': 1 }), [true]);
16744 assert.deepEqual(over({ 'a': 2 }), [false]);
16747 QUnit.test('should provide arguments to predicates', function(assert) {
16750 var over = _.over(function() {
16751 return slice.call(arguments);
16754 assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
16757 QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
16760 var over = _.over(function() { return this.b; }, function() { return this.a; }),
16761 object = { 'over': over, 'a': 1, 'b': 2 };
16763 assert.deepEqual(object.over(), [2, 1]);
16767 /*--------------------------------------------------------------------------*/
16769 QUnit.module('lodash.overEvery');
16772 QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
16775 var over = _.overEvery(stubTrue, stubOne, stubA);
16776 assert.strictEqual(over(), true);
16779 QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
16783 countFalse = function() { count++; return false; },
16784 countTrue = function() { count++; return true; },
16785 over = _.overEvery(countTrue, countFalse, countTrue);
16787 assert.strictEqual(over(), false);
16788 assert.strictEqual(count, 2);
16791 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16794 var over = _.overEvery(undefined, null);
16796 assert.strictEqual(over(true), true);
16797 assert.strictEqual(over(false), false);
16800 QUnit.test('should work with `_.property` shorthands', function(assert) {
16803 var over = _.overEvery('b', 'a');
16805 assert.strictEqual(over({ 'a': 1, 'b': 1 }), true);
16806 assert.strictEqual(over({ 'a': 0, 'b': 1 }), false);
16809 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16812 var over = _.overEvery({ 'b': 2 }, { 'a': 1 });
16814 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16815 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16818 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16821 var over = _.overEvery(['b', 2], [['a', 1]]);
16823 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16824 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16827 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16830 var over = _.overEvery(['a', 1]);
16832 assert.strictEqual(over({ 'a': 1, '1': 1 }), true);
16833 assert.strictEqual(over({ 'a': 1, '1': 0 }), false);
16834 assert.strictEqual(over({ 'a': 0, '1': 1 }), false);
16836 over = _.overEvery([['a', 1]]);
16838 assert.strictEqual(over({ 'a': 1 }), true);
16839 assert.strictEqual(over({ 'a': 2 }), false);
16842 QUnit.test('should flatten `predicates`', function(assert) {
16845 var over = _.overEvery(stubTrue, [stubFalse]);
16846 assert.strictEqual(over(), false);
16849 QUnit.test('should provide arguments to predicates', function(assert) {
16854 var over = _.overEvery(function() {
16855 args = slice.call(arguments);
16858 over('a', 'b', 'c');
16859 assert.deepEqual(args, ['a', 'b', 'c']);
16862 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16865 var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
16866 object = { 'over': over, 'a': 1, 'b': 2 };
16868 assert.strictEqual(object.over(), true);
16871 assert.strictEqual(object.over(), false);
16875 /*--------------------------------------------------------------------------*/
16877 QUnit.module('lodash.overSome');
16880 QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
16883 var over = _.overSome(stubFalse, stubOne, stubString);
16884 assert.strictEqual(over(), true);
16886 over = _.overSome(stubNull, stubA, stubZero);
16887 assert.strictEqual(over(), true);
16890 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
16894 countFalse = function() { count++; return false; },
16895 countTrue = function() { count++; return true; },
16896 over = _.overSome(countFalse, countTrue, countFalse);
16898 assert.strictEqual(over(), true);
16899 assert.strictEqual(count, 2);
16902 QUnit.test('should return `false` if all predicates return falsey', function(assert) {
16905 var over = _.overSome(stubFalse, stubFalse, stubFalse);
16906 assert.strictEqual(over(), false);
16908 over = _.overSome(stubNull, stubZero, stubString);
16909 assert.strictEqual(over(), false);
16912 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16915 var over = _.overSome(undefined, null);
16917 assert.strictEqual(over(true), true);
16918 assert.strictEqual(over(false), false);
16921 QUnit.test('should work with `_.property` shorthands', function(assert) {
16924 var over = _.overSome('b', 'a');
16926 assert.strictEqual(over({ 'a': 1, 'b': 0 }), true);
16927 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16930 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16933 var over = _.overSome({ 'b': 2 }, { 'a': 1 });
16935 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16936 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16939 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16942 var over = _.overSome(['a', 1], [['b', 2]]);
16944 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16945 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16948 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16951 var over = _.overSome(['a', 1]);
16953 assert.strictEqual(over({ 'a': 0, '1': 0 }), false);
16954 assert.strictEqual(over({ 'a': 1, '1': 0 }), true);
16955 assert.strictEqual(over({ 'a': 0, '1': 1 }), true);
16957 over = _.overSome([['a', 1]]);
16959 assert.strictEqual(over({ 'a': 1 }), true);
16960 assert.strictEqual(over({ 'a': 2 }), false);
16963 QUnit.test('should flatten `predicates`', function(assert) {
16966 var over = _.overSome(stubFalse, [stubTrue]);
16967 assert.strictEqual(over(), true);
16970 QUnit.test('should provide arguments to predicates', function(assert) {
16975 var over = _.overSome(function() {
16976 args = slice.call(arguments);
16979 over('a', 'b', 'c');
16980 assert.deepEqual(args, ['a', 'b', 'c']);
16983 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16986 var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
16987 object = { 'over': over, 'a': 1, 'b': 2 };
16989 assert.strictEqual(object.over(), true);
16991 object.a = object.b = 0;
16992 assert.strictEqual(object.over(), false);
16996 /*--------------------------------------------------------------------------*/
16998 QUnit.module('lodash.pad');
17001 var string = 'abc';
17003 QUnit.test('should pad a string to a given length', function(assert) {
17006 var values = [, undefined],
17007 expected = lodashStable.map(values, lodashStable.constant(' abc '));
17009 var actual = lodashStable.map(values, function(value, index) {
17010 return index ? _.pad(string, 6, value) : _.pad(string, 6);
17013 assert.deepEqual(actual, expected);
17016 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
17019 assert.strictEqual(_.pad(string, 8), ' abc ');
17020 assert.strictEqual(_.pad(string, 8, '_-'), '_-abc_-_');
17023 QUnit.test('should coerce `string` to a string', function(assert) {
17026 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
17027 expected = lodashStable.map(values, stubTrue);
17029 var actual = lodashStable.map(values, function(value) {
17030 return _.pad(value, 6) === ' abc ';
17033 assert.deepEqual(actual, expected);
17037 /*--------------------------------------------------------------------------*/
17039 QUnit.module('lodash.padEnd');
17042 var string = 'abc';
17044 QUnit.test('should pad a string to a given length', function(assert) {
17047 var values = [, undefined],
17048 expected = lodashStable.map(values, lodashStable.constant('abc '));
17050 var actual = lodashStable.map(values, function(value, index) {
17051 return index ? _.padEnd(string, 6, value) : _.padEnd(string, 6);
17054 assert.deepEqual(actual, expected);
17057 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
17060 assert.strictEqual(_.padEnd(string, 6, '_-'), 'abc_-_');
17063 QUnit.test('should coerce `string` to a string', function(assert) {
17066 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
17067 expected = lodashStable.map(values, stubTrue);
17069 var actual = lodashStable.map(values, function(value) {
17070 return _.padEnd(value, 6) === 'abc ';
17073 assert.deepEqual(actual, expected);
17077 /*--------------------------------------------------------------------------*/
17079 QUnit.module('lodash.padStart');
17082 var string = 'abc';
17084 QUnit.test('should pad a string to a given length', function(assert) {
17087 var values = [, undefined],
17088 expected = lodashStable.map(values, lodashStable.constant(' abc'));
17090 var actual = lodashStable.map(values, function(value, index) {
17091 return index ? _.padStart(string, 6, value) : _.padStart(string, 6);
17094 assert.deepEqual(actual, expected);
17097 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
17100 assert.strictEqual(_.padStart(string, 6, '_-'), '_-_abc');
17103 QUnit.test('should coerce `string` to a string', function(assert) {
17106 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
17107 expected = lodashStable.map(values, stubTrue);
17109 var actual = lodashStable.map(values, function(value) {
17110 return _.padStart(value, 6) === ' abc';
17113 assert.deepEqual(actual, expected);
17117 /*--------------------------------------------------------------------------*/
17119 QUnit.module('pad methods');
17121 lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
17122 var func = _[methodName],
17123 isPad = methodName == 'pad',
17124 isStart = methodName == 'padStart',
17127 QUnit.test('`_.' + methodName + '` should not pad if string is >= `length`', function(assert) {
17130 assert.strictEqual(func(string, 2), string);
17131 assert.strictEqual(func(string, 3), string);
17134 QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
17137 lodashStable.each([0, -2], function(length) {
17138 assert.strictEqual(func(string, length), string);
17142 QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
17145 lodashStable.each(['', '4'], function(length) {
17146 var actual = length ? (isStart ? ' abc' : 'abc ') : string;
17147 assert.strictEqual(func(string, length), actual);
17151 QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
17154 lodashStable.each([undefined, '_-'], function(chars) {
17155 var expected = chars ? (isPad ? '__' : chars) : ' ';
17156 assert.strictEqual(func(null, 2, chars), expected);
17157 assert.strictEqual(func(undefined, 2, chars), expected);
17158 assert.strictEqual(func('', 2, chars), expected);
17162 QUnit.test('`_.' + methodName + '` should return `string` when `chars` coerces to an empty string', function(assert) {
17165 var values = ['', Object('')],
17166 expected = lodashStable.map(values, lodashStable.constant(string));
17168 var actual = lodashStable.map(values, function(value) {
17169 return _.pad(string, 6, value);
17172 assert.deepEqual(actual, expected);
17176 /*--------------------------------------------------------------------------*/
17178 QUnit.module('lodash.parseInt');
17181 QUnit.test('should accept a `radix` argument', function(assert) {
17184 var expected = lodashStable.range(2, 37);
17186 var actual = lodashStable.map(expected, function(radix) {
17187 return _.parseInt('10', radix);
17190 assert.deepEqual(actual, expected);
17193 QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
17196 assert.strictEqual(_.parseInt('10'), 10);
17197 assert.strictEqual(_.parseInt('10', 0), 10);
17198 assert.strictEqual(_.parseInt('10', 10), 10);
17199 assert.strictEqual(_.parseInt('10', undefined), 10);
17202 QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
17205 lodashStable.each(['0x20', '0X20'], function(string) {
17206 assert.strictEqual(_.parseInt(string), 32);
17207 assert.strictEqual(_.parseInt(string, 0), 32);
17208 assert.strictEqual(_.parseInt(string, 16), 32);
17209 assert.strictEqual(_.parseInt(string, undefined), 32);
17213 QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
17216 assert.strictEqual(_.parseInt('08'), 8);
17217 assert.strictEqual(_.parseInt('08', 10), 8);
17220 QUnit.test('should parse strings with leading whitespace (test in Chrome and Firefox)', function(assert) {
17223 var expected = [8, 8, 10, 10, 32, 32, 32, 32];
17225 lodashStable.times(2, function(index) {
17227 func = (index ? (lodashBizarro || {}) : _).parseInt;
17230 lodashStable.times(2, function(otherIndex) {
17231 var string = otherIndex ? '10' : '08';
17233 func(whitespace + string, 10),
17234 func(whitespace + string)
17238 lodashStable.each(['0x20', '0X20'], function(string) {
17240 func(whitespace + string),
17241 func(whitespace + string, 16)
17245 assert.deepEqual(actual, expected);
17248 skipAssert(assert);
17253 QUnit.test('should coerce `radix` to a number', function(assert) {
17256 var object = { 'valueOf': stubZero };
17257 assert.strictEqual(_.parseInt('08', object), 8);
17258 assert.strictEqual(_.parseInt('0x20', object), 32);
17261 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
17264 var strings = lodashStable.map(['6', '08', '10'], Object),
17265 actual = lodashStable.map(strings, _.parseInt);
17267 assert.deepEqual(actual, [6, 8, 10]);
17269 actual = lodashStable.map('123', _.parseInt);
17270 assert.deepEqual(actual, [1, 2, 3]);
17274 /*--------------------------------------------------------------------------*/
17276 QUnit.module('partial methods');
17278 lodashStable.each(['partial', 'partialRight'], function(methodName) {
17279 var func = _[methodName],
17280 isPartial = methodName == 'partial',
17281 ph = func.placeholder;
17283 QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
17286 var par = func(identity, 'a');
17287 assert.strictEqual(par(), 'a');
17290 QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
17293 var fn = function(a, b) { return [a, b]; },
17294 par = func(fn, 'a'),
17295 expected = isPartial ? ['a', 'b'] : ['b', 'a'];
17297 assert.deepEqual(par('b'), expected);
17300 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
17303 var fn = function() { return arguments.length; },
17306 assert.strictEqual(par(), 0);
17309 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
17312 var par = func(identity);
17313 assert.strictEqual(par('a'), 'a');
17316 QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
17319 var fn = function() { return slice.call(arguments); },
17320 par = func(fn, ph, 'b', ph);
17322 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
17323 assert.deepEqual(par('a'), ['a', 'b', undefined]);
17324 assert.deepEqual(par(), [undefined, 'b', undefined]);
17327 assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
17329 par = func(fn, ph, 'c', ph);
17330 assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
17334 QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) {
17337 if (!isModularize) {
17338 var _ph = _.placeholder = {},
17339 fn = function() { return slice.call(arguments); },
17340 par = func(fn, _ph, 'b', ph),
17341 expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph];
17343 assert.deepEqual(par('a', 'c'), expected);
17344 delete _.placeholder;
17347 skipAssert(assert);
17351 QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
17354 var fn = function(a, b, c) {},
17355 par = func(fn, 'a');
17357 assert.strictEqual(par.length, 0);
17360 QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
17363 function Foo(value) {
17364 return value && object;
17370 assert.ok(new par instanceof Foo);
17371 assert.strictEqual(new par(true), object);
17374 QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
17377 function greet(greeting, name) {
17378 return greeting + ' ' + name;
17381 var par1 = func(greet, 'hi'),
17382 par2 = func(par1, 'barney'),
17383 par3 = func(par1, 'pebbles');
17385 assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
17386 assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
17387 assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
17390 QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
17393 var fn = function(a, b, c) { return a + b + c; },
17394 curried = _.curry(func(fn, 1), 2);
17396 assert.strictEqual(curried(2, 3), 6);
17397 assert.strictEqual(curried(2)(3), 6);
17400 QUnit.test('should work with placeholders and curried functions', function(assert) {
17403 var fn = function() { return slice.call(arguments); },
17404 curried = _.curry(fn),
17405 par = func(curried, ph, 'b', ph, 'd');
17407 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
17411 /*--------------------------------------------------------------------------*/
17413 QUnit.module('lodash.partialRight');
17416 QUnit.test('should work as a deep `_.defaults`', function(assert) {
17419 var object = { 'a': { 'b': 2 } },
17420 source = { 'a': { 'b': 3, 'c': 3 } },
17421 expected = { 'a': { 'b': 2, 'c': 3 } };
17423 var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
17424 return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
17427 assert.deepEqual(defaultsDeep(object, source), expected);
17431 /*--------------------------------------------------------------------------*/
17433 QUnit.module('methods using `createWrapper`');
17437 return slice.call(arguments);
17440 var ph1 = _.bind.placeholder,
17441 ph2 = _.bindKey.placeholder,
17442 ph3 = _.partial.placeholder,
17443 ph4 = _.partialRight.placeholder;
17445 QUnit.test('should work with combinations of partial functions', function(assert) {
17448 var a = _.partial(fn),
17449 b = _.partialRight(a, 3),
17450 c = _.partial(b, 1);
17452 assert.deepEqual(c(2), [1, 2, 3]);
17455 QUnit.test('should work with combinations of bound and partial functions', function(assert) {
17458 var fn = function() {
17459 var result = [this.a];
17460 push.apply(result, arguments);
17464 var expected = [1, 2, 3, 4],
17465 object = { 'a': 1, 'fn': fn };
17467 var a = _.bindKey(object, 'fn'),
17468 b = _.partialRight(a, 4),
17469 c = _.partial(b, 2);
17471 assert.deepEqual(c(3), expected);
17473 a = _.bind(fn, object);
17474 b = _.partialRight(a, 4);
17475 c = _.partial(b, 2);
17477 assert.deepEqual(c(3), expected);
17479 a = _.partial(fn, 2);
17480 b = _.bind(a, object);
17481 c = _.partialRight(b, 4);
17483 assert.deepEqual(c(3), expected);
17486 QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
17489 function Foo(a, b, c) {
17490 return b === 0 && object;
17493 var combo = _.partial(_.partialRight(Foo, 3), 1),
17496 assert.ok(new combo(2) instanceof Foo);
17497 assert.strictEqual(new combo(0), object);
17500 QUnit.test('should work with combinations of functions with placeholders', function(assert) {
17503 var expected = [1, 2, 3, 4, 5, 6],
17504 object = { 'fn': fn };
17506 var a = _.bindKey(object, 'fn', ph2, 2),
17507 b = _.partialRight(a, ph4, 6),
17508 c = _.partial(b, 1, ph3, 4);
17510 assert.deepEqual(c(3, 5), expected);
17512 a = _.bind(fn, object, ph1, 2);
17513 b = _.partialRight(a, ph4, 6);
17514 c = _.partial(b, 1, ph3, 4);
17516 assert.deepEqual(c(3, 5), expected);
17518 a = _.partial(fn, ph3, 2);
17519 b = _.bind(a, object, 1, ph1, 4);
17520 c = _.partialRight(b, ph4, 6);
17522 assert.deepEqual(c(3, 5), expected);
17525 QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
17528 var expected = [1, 2, 3, 4],
17529 object = { 'fn': fn };
17531 var a = _.bindKey(object, 'fn', ph2, 2),
17532 b = _.partialRight(a, ph4, 4),
17533 c = _.partial(b, ph3, 3);
17535 assert.deepEqual(c(1), expected);
17537 a = _.bind(fn, object, ph1, 2);
17538 b = _.partialRight(a, ph4, 4);
17539 c = _.partial(b, ph3, 3);
17541 assert.deepEqual(c(1), expected);
17543 a = _.partial(fn, ph3, 2);
17544 b = _.bind(a, object, ph1, 3);
17545 c = _.partialRight(b, ph4, 4);
17547 assert.deepEqual(c(1), expected);
17550 QUnit.test('should work with recursively bound functions', function(assert) {
17553 var fn = function() {
17557 var a = _.bind(fn, { 'a': 1 }),
17558 b = _.bind(a, { 'a': 2 }),
17559 c = _.bind(b, { 'a': 3 });
17561 assert.strictEqual(c(), 1);
17564 QUnit.test('should work when hot', function(assert) {
17567 lodashStable.times(2, function(index) {
17568 var fn = function() {
17569 var result = [this];
17570 push.apply(result, arguments);
17575 bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17576 expected = [object, 1, 2, 3];
17578 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17579 var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17580 return index ? bound2(3) : bound2(1, 2, 3);
17583 assert.deepEqual(actual, expected);
17585 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17586 var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17587 bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17589 return index ? bound2(3) : bound2(1, 2, 3);
17592 assert.deepEqual(actual, expected);
17595 lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
17596 var fn = function(a, b, c) { return [a, b, c]; },
17597 curried = _[methodName](fn),
17598 expected = index ? [3, 2, 1] : [1, 2, 3];
17600 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17601 return curried(1)(2)(3);
17604 assert.deepEqual(actual, expected);
17606 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17607 var curried = _[methodName](fn);
17608 return curried(1)(2)(3);
17611 assert.deepEqual(actual, expected);
17614 lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
17615 var func = _[methodName],
17616 fn = function() { return slice.call(arguments); },
17617 par1 = func(fn, 1),
17618 expected = index ? [3, 2, 1] : [1, 2, 3];
17620 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17621 var par2 = func(par1, 2);
17625 assert.deepEqual(actual, expected);
17627 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17628 var par1 = func(fn, 1),
17629 par2 = func(par1, 2);
17634 assert.deepEqual(actual, expected);
17639 /*--------------------------------------------------------------------------*/
17641 QUnit.module('lodash.partition');
17644 var array = [1, 0, 1];
17646 QUnit.test('should split elements into two groups by `predicate`', function(assert) {
17649 assert.deepEqual(_.partition([], identity), [[], []]);
17650 assert.deepEqual(_.partition(array, stubTrue), [array, []]);
17651 assert.deepEqual(_.partition(array, stubFalse), [[], array]);
17654 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
17657 var values = [, null, undefined],
17658 expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
17660 var actual = lodashStable.map(values, function(value, index) {
17661 return index ? _.partition(array, value) : _.partition(array);
17664 assert.deepEqual(actual, expected);
17667 QUnit.test('should work with `_.property` shorthands', function(assert) {
17670 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
17671 actual = _.partition(objects, 'a');
17673 assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
17676 QUnit.test('should work with a number for `predicate`', function(assert) {
17685 assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
17686 assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
17689 QUnit.test('should work with an object for `collection`', function(assert) {
17692 var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
17693 assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
17697 /*--------------------------------------------------------------------------*/
17699 QUnit.module('lodash.pick');
17702 var args = arguments,
17703 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
17705 QUnit.test('should flatten `props`', function(assert) {
17708 assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
17709 assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
17712 QUnit.test('should work with a primitive `object` argument', function(assert) {
17715 assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
17718 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
17721 lodashStable.each([null, undefined], function(value) {
17722 assert.deepEqual(_.pick(value, 'valueOf'), {});
17726 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
17729 assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
17732 QUnit.test('should coerce property names to strings', function(assert) {
17735 assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
17739 /*--------------------------------------------------------------------------*/
17741 QUnit.module('lodash.pickBy');
17744 QUnit.test('should work with a predicate argument', function(assert) {
17747 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
17749 var actual = _.pickBy(object, function(n) {
17750 return n == 1 || n == 3;
17753 assert.deepEqual(actual, { 'a': 1, 'c': 3 });
17757 /*--------------------------------------------------------------------------*/
17759 QUnit.module('pick methods');
17761 lodashStable.each(['pick', 'pickBy'], function(methodName) {
17762 var expected = { 'a': 1, 'c': 3 },
17763 func = _[methodName],
17764 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
17765 resolve = lodashStable.nthArg(1);
17767 if (methodName == 'pickBy') {
17768 resolve = function(object, props) {
17769 props = lodashStable.castArray(props);
17770 return function(value) {
17771 return lodashStable.some(props, function(key) {
17772 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
17773 return object[key] === value;
17778 QUnit.test('`_.' + methodName + '` should create an object of picked string keyed properties', function(assert) {
17781 assert.deepEqual(func(object, resolve(object, 'a')), { 'a': 1 });
17782 assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
17785 QUnit.test('`_.' + methodName + '` should pick inherited string keyed properties', function(assert) {
17789 Foo.prototype = object;
17792 assert.deepEqual(func(foo, resolve(foo, ['a', 'c'])), expected);
17795 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
17798 var object = { '-0': 'a', '0': 'b' },
17799 props = [-0, Object(-0), 0, Object(0)],
17800 expected = [{ '-0': 'a' }, { '-0': 'a' }, { '0': 'b' }, { '0': 'b' }];
17802 var actual = lodashStable.map(props, function(key) {
17803 return func(object, resolve(object, key));
17806 assert.deepEqual(actual, expected);
17809 QUnit.test('`_.' + methodName + '` should pick symbol properties', function(assert) {
17817 var symbol2 = Symbol('b');
17818 Foo.prototype[symbol2] = 2;
17821 actual = func(foo, resolve(foo, [symbol, symbol2]));
17823 assert.strictEqual(actual[symbol], 1);
17824 assert.strictEqual(actual[symbol2], 2);
17827 skipAssert(assert, 2);
17831 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
17834 var array = [1, 2, 3];
17835 assert.deepEqual(func(array, resolve(array, '1')), { '1': 2 });
17839 /*--------------------------------------------------------------------------*/
17841 QUnit.module('lodash.property');
17844 QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
17847 var object = { 'a': 1 };
17849 lodashStable.each(['a', ['a']], function(path) {
17850 var prop = _.property(path);
17851 assert.strictEqual(prop.length, 1);
17852 assert.strictEqual(prop(object), 1);
17856 QUnit.test('should pluck deep property values', function(assert) {
17859 var object = { 'a': { 'b': 2 } };
17861 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17862 var prop = _.property(path);
17863 assert.strictEqual(prop(object), 2);
17867 QUnit.test('should pluck inherited property values', function(assert) {
17871 Foo.prototype.a = 1;
17873 lodashStable.each(['a', ['a']], function(path) {
17874 var prop = _.property(path);
17875 assert.strictEqual(prop(new Foo), 1);
17879 QUnit.test('should work with a non-string `path`', function(assert) {
17882 var array = [1, 2, 3];
17884 lodashStable.each([1, [1]], function(path) {
17885 var prop = _.property(path);
17886 assert.strictEqual(prop(array), 2);
17890 QUnit.test('should preserve the sign of `0`', function(assert) {
17893 var object = { '-0': 'a', '0': 'b' },
17894 props = [-0, Object(-0), 0, Object(0)];
17896 var actual = lodashStable.map(props, function(key) {
17897 var prop = _.property(key);
17898 return prop(object);
17901 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
17904 QUnit.test('should coerce key to a string', function(assert) {
17908 fn.toString = lodashStable.constant('fn');
17910 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
17911 values = [null, undefined, fn, {}];
17913 var actual = lodashStable.transform(objects, function(result, object, index) {
17914 var key = values[index];
17915 lodashStable.each([key, [key]], function(path) {
17916 var prop = _.property(key);
17917 result.push(prop(object));
17921 assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
17924 QUnit.test('should pluck a key over a path', function(assert) {
17927 var object = { 'a.b': 1, 'a': { 'b': 2 } };
17929 lodashStable.each(['a.b', ['a.b']], function(path) {
17930 var prop = _.property(path);
17931 assert.strictEqual(prop(object), 1);
17935 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
17938 var values = [, null, undefined],
17939 expected = lodashStable.map(values, noop);
17941 lodashStable.each(['constructor', ['constructor']], function(path) {
17942 var prop = _.property(path);
17944 var actual = lodashStable.map(values, function(value, index) {
17945 return index ? prop(value) : prop();
17948 assert.deepEqual(actual, expected);
17952 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
17955 var values = [, null, undefined],
17956 expected = lodashStable.map(values, noop);
17958 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
17959 var prop = _.property(path);
17961 var actual = lodashStable.map(values, function(value, index) {
17962 return index ? prop(value) : prop();
17965 assert.deepEqual(actual, expected);
17969 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
17974 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
17975 var prop = _.property(path);
17976 assert.strictEqual(prop(object), undefined);
17981 /*--------------------------------------------------------------------------*/
17983 QUnit.module('lodash.propertyOf');
17986 QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
17989 var object = { 'a': 1 },
17990 propOf = _.propertyOf(object);
17992 assert.strictEqual(propOf.length, 1);
17993 lodashStable.each(['a', ['a']], function(path) {
17994 assert.strictEqual(propOf(path), 1);
17998 QUnit.test('should pluck deep property values', function(assert) {
18001 var object = { 'a': { 'b': 2 } },
18002 propOf = _.propertyOf(object);
18004 lodashStable.each(['a.b', ['a', 'b']], function(path) {
18005 assert.strictEqual(propOf(path), 2);
18009 QUnit.test('should pluck inherited property values', function(assert) {
18015 Foo.prototype.b = 2;
18017 var propOf = _.propertyOf(new Foo);
18019 lodashStable.each(['b', ['b']], function(path) {
18020 assert.strictEqual(propOf(path), 2);
18024 QUnit.test('should work with a non-string `path`', function(assert) {
18027 var array = [1, 2, 3],
18028 propOf = _.propertyOf(array);
18030 lodashStable.each([1, [1]], function(path) {
18031 assert.strictEqual(propOf(path), 2);
18035 QUnit.test('should preserve the sign of `0`', function(assert) {
18038 var object = { '-0': 'a', '0': 'b' },
18039 props = [-0, Object(-0), 0, Object(0)];
18041 var actual = lodashStable.map(props, function(key) {
18042 var propOf = _.propertyOf(object);
18043 return propOf(key);
18046 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
18049 QUnit.test('should coerce key to a string', function(assert) {
18053 fn.toString = lodashStable.constant('fn');
18055 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
18056 values = [null, undefined, fn, {}];
18058 var actual = lodashStable.transform(objects, function(result, object, index) {
18059 var key = values[index];
18060 lodashStable.each([key, [key]], function(path) {
18061 var propOf = _.propertyOf(object);
18062 result.push(propOf(key));
18066 assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
18069 QUnit.test('should pluck a key over a path', function(assert) {
18072 var object = { 'a.b': 1, 'a': { 'b': 2 } },
18073 propOf = _.propertyOf(object);
18075 lodashStable.each(['a.b', ['a.b']], function(path) {
18076 assert.strictEqual(propOf(path), 1);
18080 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
18083 var values = [, null, undefined],
18084 expected = lodashStable.map(values, noop);
18086 lodashStable.each(['constructor', ['constructor']], function(path) {
18087 var actual = lodashStable.map(values, function(value, index) {
18088 var propOf = index ? _.propertyOf(value) : _.propertyOf();
18089 return propOf(path);
18092 assert.deepEqual(actual, expected);
18096 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
18099 var values = [, null, undefined],
18100 expected = lodashStable.map(values, noop);
18102 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
18103 var actual = lodashStable.map(values, function(value, index) {
18104 var propOf = index ? _.propertyOf(value) : _.propertyOf();
18105 return propOf(path);
18108 assert.deepEqual(actual, expected);
18112 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
18115 var propOf = _.propertyOf({});
18117 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
18118 assert.strictEqual(propOf(path), undefined);
18123 /*--------------------------------------------------------------------------*/
18125 QUnit.module('lodash.pullAll');
18128 QUnit.test('should work with the same value for `array` and `values`', function(assert) {
18131 var array = [{ 'a': 1 }, { 'b': 2 }],
18132 actual = _.pullAll(array, array);
18134 assert.deepEqual(actual, []);
18138 /*--------------------------------------------------------------------------*/
18140 QUnit.module('lodash.pullAllBy');
18143 QUnit.test('should accept an `iteratee` argument', function(assert) {
18146 var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
18148 var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
18152 assert.deepEqual(actual, [{ 'x': 2 }]);
18155 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
18159 array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
18161 _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
18162 args || (args = slice.call(arguments));
18165 assert.deepEqual(args, [{ 'x': 1 }]);
18169 /*--------------------------------------------------------------------------*/
18171 QUnit.module('lodash.pullAllWith');
18174 QUnit.test('should work with a `comparator` argument', function(assert) {
18177 var objects = [{ 'x': 1, 'y': 1 }, { 'x': 2, 'y': 2 }, { 'x': 3, 'y': 3 }],
18178 expected = [objects[0], objects[2]],
18179 actual = _.pullAllWith(objects, [{ 'x': 2, 'y': 2 }], lodashStable.isEqual);
18181 assert.deepEqual(actual, expected);
18185 /*--------------------------------------------------------------------------*/
18187 QUnit.module('pull methods');
18189 lodashStable.each(['pull', 'pullAll', 'pullAllWith'], function(methodName) {
18190 var func = _[methodName],
18191 isPull = methodName == 'pull';
18193 function pull(array, values) {
18195 ? func.apply(undefined, [array].concat(values))
18196 : func(array, values);
18199 QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
18202 var array = [1, 2, 3],
18203 actual = pull(array, [1, 3]);
18205 assert.strictEqual(actual, array);
18206 assert.deepEqual(array, [2]);
18209 QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
18212 var array = [1, 2, 3, 4];
18217 assert.notOk('0' in array);
18218 assert.notOk('2' in array);
18221 QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
18224 var array = [1, 2, 3];
18227 pull(array, [undefined]);
18228 assert.deepEqual(array, [1, 3]);
18231 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
18234 var array = [1, NaN, 3, NaN];
18236 pull(array, [NaN]);
18237 assert.deepEqual(array, [1, 3]);
18241 /*--------------------------------------------------------------------------*/
18243 QUnit.module('lodash.pullAt');
18246 QUnit.test('should modify the array and return removed elements', function(assert) {
18249 var array = [1, 2, 3],
18250 actual = _.pullAt(array, [0, 1]);
18252 assert.deepEqual(array, [3]);
18253 assert.deepEqual(actual, [1, 2]);
18256 QUnit.test('should work with unsorted indexes', function(assert) {
18259 var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
18260 actual = _.pullAt(array, [1, 3, 11, 7, 5, 9]);
18262 assert.deepEqual(array, [1, 3, 5, 7, 9, 11]);
18263 assert.deepEqual(actual, [2, 4, 12, 8, 6, 10]);
18266 QUnit.test('should work with repeated indexes', function(assert) {
18269 var array = [1, 2, 3, 4],
18270 actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
18272 assert.deepEqual(array, [4]);
18273 assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
18276 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
18279 var array = ['a', 'b', 'c'],
18280 actual = _.pullAt(array, [2, 4, 0]);
18282 assert.deepEqual(array, ['b']);
18283 assert.deepEqual(actual, ['c', undefined, 'a']);
18286 QUnit.test('should flatten `indexes`', function(assert) {
18289 var array = ['a', 'b', 'c'];
18290 assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
18291 assert.deepEqual(array, ['b']);
18293 array = ['a', 'b', 'c', 'd'];
18294 assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
18295 assert.deepEqual(array, ['b']);
18298 QUnit.test('should return an empty array when no indexes are given', function(assert) {
18301 var array = ['a', 'b', 'c'],
18302 actual = _.pullAt(array);
18304 assert.deepEqual(array, ['a', 'b', 'c']);
18305 assert.deepEqual(actual, []);
18307 actual = _.pullAt(array, [], []);
18309 assert.deepEqual(array, ['a', 'b', 'c']);
18310 assert.deepEqual(actual, []);
18313 QUnit.test('should work with non-index paths', function(assert) {
18316 var values = lodashStable.reject(empties, function(value) {
18317 return (value === 0) || lodashStable.isArray(value);
18318 }).concat(-1, 1.1);
18320 var array = lodashStable.transform(values, function(result, value) {
18324 var expected = lodashStable.map(values, stubOne),
18325 actual = _.pullAt(array, values);
18327 assert.deepEqual(actual, expected);
18329 expected = lodashStable.map(values, noop),
18330 actual = lodashStable.at(array, values);
18332 assert.deepEqual(actual, expected);
18335 QUnit.test('should preserve the sign of `0`', function(assert) {
18338 var props = [-0, Object(-0), 0, Object(0)];
18340 var actual = lodashStable.map(props, function(key) {
18343 return _.pullAt(array, key);
18346 assert.deepEqual(actual, [[-2], [-2], [-1], [-1]]);
18349 QUnit.test('should work with deep paths', function(assert) {
18353 array.a = { 'b': 2 };
18355 var actual = _.pullAt(array, 'a.b');
18357 assert.deepEqual(actual, [2]);
18358 assert.deepEqual(array.a, {});
18361 actual = _.pullAt(array, 'a.b.c');
18364 assert.deepEqual(actual, [undefined]);
18367 QUnit.test('should work with a falsey `array` argument when keys are given', function(assert) {
18370 var values = falsey.slice(),
18371 expected = lodashStable.map(values, lodashStable.constant(Array(4)));
18373 var actual = lodashStable.map(values, function(array) {
18375 return _.pullAt(array, 0, 1, 'pop', 'push');
18379 assert.deepEqual(actual, expected);
18383 /*--------------------------------------------------------------------------*/
18385 QUnit.module('lodash.random');
18388 var array = Array(1000);
18390 QUnit.test('should return `0` or `1` when no arguments are given', function(assert) {
18393 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18397 assert.deepEqual(actual, [0, 1]);
18400 QUnit.test('should support a `min` and `max` argument', function(assert) {
18406 assert.ok(lodashStable.some(array, function() {
18407 var result = _.random(min, max);
18408 return result >= min && result <= max;
18412 QUnit.test('should support not providing a `max` argument', function(assert) {
18418 assert.ok(lodashStable.some(array, function() {
18419 var result = _.random(max);
18420 return result >= min && result <= max;
18424 QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
18429 expected = [2, 3, 4];
18431 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18432 return _.random(min, max);
18435 assert.deepEqual(actual, expected);
18438 QUnit.test('should support large integer values', function(assert) {
18441 var min = Math.pow(2, 31),
18442 max = Math.pow(2, 62);
18444 assert.ok(lodashStable.every(array, function() {
18445 var result = _.random(min, max);
18446 return result >= min && result <= max;
18449 assert.ok(lodashStable.some(array, function() {
18450 return _.random(MAX_INTEGER);
18454 QUnit.test('should coerce arguments to finite numbers', function(assert) {
18457 assert.strictEqual(_.random('1', '1'), 1);
18458 assert.strictEqual(_.random(NaN, NaN), 0);
18461 QUnit.test('should support floats', function(assert) {
18466 actual = _.random(min, max);
18468 assert.ok(actual % 1);
18469 assert.ok(actual >= min && actual <= max);
18472 QUnit.test('should support providing a `floating` argument', function(assert) {
18475 var actual = _.random(true);
18476 assert.ok(actual % 1 && actual >= 0 && actual <= 1);
18478 actual = _.random(2, true);
18479 assert.ok(actual % 1 && actual >= 0 && actual <= 2);
18481 actual = _.random(2, 4, true);
18482 assert.ok(actual % 1 && actual >= 2 && actual <= 4);
18485 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18488 var array = [1, 2, 3],
18489 expected = lodashStable.map(array, stubTrue),
18490 randoms = lodashStable.map(array, _.random);
18492 var actual = lodashStable.map(randoms, function(result, index) {
18493 return result >= 0 && result <= array[index] && (result % 1) == 0;
18496 assert.deepEqual(actual, expected);
18500 /*--------------------------------------------------------------------------*/
18502 QUnit.module('range methods');
18504 lodashStable.each(['range', 'rangeRight'], function(methodName) {
18505 var func = _[methodName],
18506 isRange = methodName == 'range';
18508 function resolve(range) {
18509 return isRange ? range : range.reverse();
18512 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `end` is given', function(assert) {
18515 assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
18516 assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
18519 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `start` and `end` are given', function(assert) {
18522 assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
18523 assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
18526 QUnit.test('`_.' + methodName + '` should work with `start`, `end`, and `step` arguments', function(assert) {
18529 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18530 assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
18531 assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
18534 QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
18537 assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
18540 QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
18543 assert.deepEqual(func(1, 5, 20), [1]);
18546 QUnit.test('`_.' + methodName + '` should work with a negative `step`', function(assert) {
18549 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18550 assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
18553 QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
18556 var actual = func(-0, 1);
18557 assert.strictEqual(1 / actual[0], -Infinity);
18560 QUnit.test('`_.' + methodName + '` should treat falsey `start` arguments as `0`', function(assert) {
18563 lodashStable.each(falsey, function(value, index) {
18565 assert.deepEqual(func(value), []);
18566 assert.deepEqual(func(value, 1), [0]);
18568 assert.deepEqual(func(), []);
18573 QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
18576 var actual = [func('0', 1), func('1'), func(0, 1, '1'), func(NaN), func(NaN, NaN)];
18577 assert.deepEqual(actual, [[0], [0], [0], [], []]);
18580 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
18583 var array = [1, 2, 3],
18584 object = { 'a': 1, 'b': 2, 'c': 3 },
18585 expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
18587 lodashStable.each([array, object], function(collection) {
18588 var actual = lodashStable.map(collection, func);
18589 assert.deepEqual(actual, expected);
18594 /*--------------------------------------------------------------------------*/
18596 QUnit.module('lodash.rearg');
18600 return slice.call(arguments);
18603 QUnit.test('should reorder arguments provided to `func`', function(assert) {
18606 var rearged = _.rearg(fn, [2, 0, 1]);
18607 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18610 QUnit.test('should work with repeated indexes', function(assert) {
18613 var rearged = _.rearg(fn, [1, 1, 1]);
18614 assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
18617 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
18620 var rearged = _.rearg(fn, [1, 4]);
18621 assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
18624 QUnit.test('should use `undefined` for non-index values', function(assert) {
18627 var values = lodashStable.reject(empties, function(value) {
18628 return (value === 0) || lodashStable.isArray(value);
18629 }).concat(-1, 1.1);
18631 var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
18633 var actual = lodashStable.map(values, function(value) {
18634 var rearged = _.rearg(fn, [value]);
18635 return rearged('a', 'b', 'c');
18638 assert.deepEqual(actual, expected);
18641 QUnit.test('should not rearrange arguments when no indexes are given', function(assert) {
18644 var rearged = _.rearg(fn);
18645 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18647 rearged = _.rearg(fn, [], []);
18648 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18651 QUnit.test('should accept multiple index arguments', function(assert) {
18654 var rearged = _.rearg(fn, 2, 0, 1);
18655 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18658 QUnit.test('should accept multiple arrays of indexes', function(assert) {
18661 var rearged = _.rearg(fn, [2], [0, 1]);
18662 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18665 QUnit.test('should work with fewer indexes than arguments', function(assert) {
18668 var rearged = _.rearg(fn, [1, 0]);
18669 assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
18672 QUnit.test('should work on functions that have been rearged', function(assert) {
18675 var rearged1 = _.rearg(fn, 2, 1, 0),
18676 rearged2 = _.rearg(rearged1, 1, 0, 2);
18678 assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
18682 /*--------------------------------------------------------------------------*/
18684 QUnit.module('lodash.reduce');
18687 var array = [1, 2, 3];
18689 QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
18692 assert.strictEqual(_.reduce(array), 1);
18695 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
18700 _.reduce(array, function() {
18701 args || (args = slice.call(arguments));
18704 assert.deepEqual(args, [0, 1, 0, array]);
18707 _.reduce(array, function() {
18708 args || (args = slice.call(arguments));
18711 assert.deepEqual(args, [1, 2, 1, array]);
18714 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
18718 object = { 'a': 1, 'b': 2 },
18719 firstKey = _.head(_.keys(object));
18721 var expected = firstKey == 'a'
18722 ? [0, 1, 'a', object]
18723 : [0, 2, 'b', object];
18725 _.reduce(object, function() {
18726 args || (args = slice.call(arguments));
18729 assert.deepEqual(args, expected);
18732 expected = firstKey == 'a'
18733 ? [1, 2, 'b', object]
18734 : [2, 1, 'a', object];
18736 _.reduce(object, function() {
18737 args || (args = slice.call(arguments));
18740 assert.deepEqual(args, expected);
18744 /*--------------------------------------------------------------------------*/
18746 QUnit.module('lodash.reduceRight');
18749 var array = [1, 2, 3];
18751 QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
18754 assert.strictEqual(_.reduceRight(array), 3);
18757 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
18762 _.reduceRight(array, function() {
18763 args || (args = slice.call(arguments));
18766 assert.deepEqual(args, [0, 3, 2, array]);
18769 _.reduceRight(array, function() {
18770 args || (args = slice.call(arguments));
18773 assert.deepEqual(args, [3, 2, 1, array]);
18776 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
18780 object = { 'a': 1, 'b': 2 },
18781 isFIFO = lodashStable.keys(object)[0] == 'a';
18783 var expected = isFIFO
18784 ? [0, 2, 'b', object]
18785 : [0, 1, 'a', object];
18787 _.reduceRight(object, function() {
18788 args || (args = slice.call(arguments));
18791 assert.deepEqual(args, expected);
18795 ? [2, 1, 'a', object]
18796 : [1, 2, 'b', object];
18798 _.reduceRight(object, function() {
18799 args || (args = slice.call(arguments));
18802 assert.deepEqual(args, expected);
18806 /*--------------------------------------------------------------------------*/
18808 QUnit.module('reduce methods');
18810 lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
18811 var func = _[methodName],
18813 isReduce = methodName == 'reduce';
18815 QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
18818 var actual = func(['a', 'b', 'c'], function(accumulator, value) {
18819 return accumulator + value;
18822 assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
18825 QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
18829 expected = lodashStable.map(empties, noop);
18831 lodashStable.each(empties, function(value) {
18833 actual.push(func(value, noop));
18837 assert.deepEqual(actual, expected);
18840 QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
18843 var expected = lodashStable.map(empties, lodashStable.constant('x'));
18845 var actual = lodashStable.map(empties, function(value) {
18847 return func(value, noop, 'x');
18851 assert.deepEqual(actual, expected);
18854 QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
18857 var actual = func([], noop, undefined);
18858 assert.strictEqual(actual, undefined);
18861 QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is given (test in IE > 9 and modern browsers)', function(assert) {
18865 object = { '0': 1, 'length': 0 };
18867 if ('__proto__' in array) {
18868 array.__proto__ = object;
18869 assert.strictEqual(func(array, noop), undefined);
18872 skipAssert(assert);
18874 assert.strictEqual(func(object, noop), undefined);
18877 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
18881 assert.strictEqual(_(array)[methodName](add), 6);
18884 skipAssert(assert);
18888 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
18892 assert.ok(_(array).chain()[methodName](add) instanceof _);
18895 skipAssert(assert);
18900 /*--------------------------------------------------------------------------*/
18902 QUnit.module('lodash.reject');
18905 var array = [1, 2, 3];
18907 QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
18910 assert.deepEqual(_.reject(array, isEven), [1, 3]);
18914 /*--------------------------------------------------------------------------*/
18916 QUnit.module('filter methods');
18918 lodashStable.each(['filter', 'reject'], function(methodName) {
18919 var array = [1, 2, 3, 4],
18920 func = _[methodName],
18921 isFilter = methodName == 'filter',
18922 objects = [{ 'a': 0 }, { 'a': 1 }];
18924 QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
18927 var actual = func([0], function(value, index, array) {
18932 assert.deepEqual(actual, [0]);
18935 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
18938 assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
18941 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
18944 assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
18947 QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
18951 var wrapped = _(array);
18953 var actual = wrapped[methodName](function(n) {
18957 assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
18959 actual = wrapped[methodName](function(n) {
18963 assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
18966 skipAssert(assert, 2);
18970 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
18974 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
18975 predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); },
18976 actual = _(array).slice(1).map(square)[methodName](predicate).value();
18978 assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
18980 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
18981 return ['key' + index, index];
18984 actual = _(object).mapValues(square)[methodName](predicate).value();
18985 assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
18988 skipAssert(assert, 2);
18992 QUnit.test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
18997 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
18998 expected = [1, 0, lodashStable.map(array.slice(1), square)];
19000 _(array).slice(1)[methodName](function(value, index, array) {
19001 args || (args = slice.call(arguments));
19004 assert.deepEqual(args, [1, 0, array.slice(1)]);
19007 _(array).slice(1).map(square)[methodName](function(value, index, array) {
19008 args || (args = slice.call(arguments));
19011 assert.deepEqual(args, expected);
19014 _(array).slice(1).map(square)[methodName](function(value, index) {
19015 args || (args = slice.call(arguments));
19018 assert.deepEqual(args, expected);
19021 _(array).slice(1).map(square)[methodName](function(value) {
19022 args || (args = slice.call(arguments));
19025 assert.deepEqual(args, [1]);
19028 _(array).slice(1).map(square)[methodName](function() {
19029 args || (args = slice.call(arguments));
19032 assert.deepEqual(args, expected);
19035 skipAssert(assert, 5);
19040 /*--------------------------------------------------------------------------*/
19042 QUnit.module('lodash.remove');
19045 QUnit.test('should modify the array and return removed elements', function(assert) {
19048 var array = [1, 2, 3, 4],
19049 actual = _.remove(array, isEven);
19051 assert.deepEqual(array, [1, 3]);
19052 assert.deepEqual(actual, [2, 4]);
19055 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
19060 clone = array.slice();
19062 _.remove(array, function(n, index) {
19063 var args = slice.call(arguments);
19064 args[2] = args[2].slice();
19065 argsList.push(args);
19066 return isEven(index);
19069 assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
19072 QUnit.test('should work with `_.matches` shorthands', function(assert) {
19075 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
19076 _.remove(objects, { 'a': 1 });
19077 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
19080 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
19083 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
19084 _.remove(objects, ['a', 1]);
19085 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
19088 QUnit.test('should work with `_.property` shorthands', function(assert) {
19091 var objects = [{ 'a': 0 }, { 'a': 1 }];
19092 _.remove(objects, 'a');
19093 assert.deepEqual(objects, [{ 'a': 0 }]);
19096 QUnit.test('should preserve holes in arrays', function(assert) {
19099 var array = [1, 2, 3, 4];
19103 _.remove(array, function(n) {
19107 assert.notOk('0' in array);
19108 assert.notOk('2' in array);
19111 QUnit.test('should treat holes as `undefined`', function(assert) {
19114 var array = [1, 2, 3];
19117 _.remove(array, function(n) {
19121 assert.deepEqual(array, [1, 3]);
19124 QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
19127 var array = [1, 2, 3];
19129 _.remove(array, function(n, index) {
19130 return isEven(index);
19133 assert.deepEqual(array, [2]);
19137 /*--------------------------------------------------------------------------*/
19139 QUnit.module('lodash.repeat');
19142 var string = 'abc';
19144 QUnit.test('should repeat a string `n` times', function(assert) {
19147 assert.strictEqual(_.repeat('*', 3), '***');
19148 assert.strictEqual(_.repeat(string, 2), 'abcabc');
19151 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
19154 var expected = lodashStable.map(falsey, function(value) {
19155 return value === undefined ? string : '';
19158 var actual = lodashStable.map(falsey, function(n, index) {
19159 return index ? _.repeat(string, n) : _.repeat(string);
19162 assert.deepEqual(actual, expected);
19165 QUnit.test('should return an empty string if `n` is <= `0`', function(assert) {
19168 assert.strictEqual(_.repeat(string, 0), '');
19169 assert.strictEqual(_.repeat(string, -2), '');
19172 QUnit.test('should coerce `n` to an integer', function(assert) {
19175 assert.strictEqual(_.repeat(string, '2'), 'abcabc');
19176 assert.strictEqual(_.repeat(string, 2.6), 'abcabc');
19177 assert.strictEqual(_.repeat('*', { 'valueOf': stubThree }), '***');
19180 QUnit.test('should coerce `string` to a string', function(assert) {
19183 assert.strictEqual(_.repeat(Object(string), 2), 'abcabc');
19184 assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
19187 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19190 var actual = lodashStable.map(['a', 'b', 'c'], _.repeat);
19191 assert.deepEqual(actual, ['a', 'b', 'c']);
19195 /*--------------------------------------------------------------------------*/
19197 QUnit.module('lodash.replace');
19200 QUnit.test('should replace the matched pattern', function(assert) {
19203 var string = 'abcde';
19204 assert.strictEqual(_.replace(string, 'de', '123'), 'abc123');
19205 assert.strictEqual(_.replace(string, /[bd]/g, '-'), 'a-c-e');
19209 /*--------------------------------------------------------------------------*/
19211 QUnit.module('lodash.result');
19214 var object = { 'a': 1, 'b': stubB };
19216 QUnit.test('should invoke function values', function(assert) {
19219 assert.strictEqual(_.result(object, 'b'), 'b');
19222 QUnit.test('should invoke default function values', function(assert) {
19225 var actual = _.result(object, 'c', object.b);
19226 assert.strictEqual(actual, 'b');
19229 QUnit.test('should invoke nested function values', function(assert) {
19232 var value = { 'a': lodashStable.constant({ 'b': stubB }) };
19234 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19235 assert.strictEqual(_.result(value, path), 'b');
19239 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
19242 var value = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
19244 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19245 assert.strictEqual(_.result(value, path), 1);
19250 /*--------------------------------------------------------------------------*/
19252 QUnit.module('lodash.get and lodash.result');
19254 lodashStable.each(['get', 'result'], function(methodName) {
19255 var func = _[methodName];
19257 QUnit.test('`_.' + methodName + '` should get string keyed property values', function(assert) {
19260 var object = { 'a': 1 };
19262 lodashStable.each(['a', ['a']], function(path) {
19263 assert.strictEqual(func(object, path), 1);
19267 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19270 var object = { '-0': 'a', '0': 'b' },
19271 props = [-0, Object(-0), 0, Object(0)];
19273 var actual = lodashStable.map(props, function(key) {
19274 return func(object, key);
19277 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
19280 QUnit.test('`_.' + methodName + '` should get symbol keyed property values', function(assert) {
19285 object[symbol] = 1;
19287 assert.strictEqual(func(object, symbol), 1);
19290 skipAssert(assert);
19294 QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
19297 var object = { 'a': { 'b': 2 } };
19299 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19300 assert.strictEqual(func(object, path), 2);
19304 QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
19307 var object = { 'a.b': 1, 'a': { 'b': 2 } };
19309 lodashStable.each(['a.b', ['a.b']], function(path) {
19310 assert.strictEqual(func(object, path), 1);
19314 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
19317 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
19318 assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
19321 QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
19324 var object = { 'a': { '': 1 } };
19325 assert.strictEqual(func(object, 'a[]'), 1);
19328 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
19331 lodashStable.each([['', ''], [[], ['']]], function(pair) {
19332 assert.strictEqual(func({}, pair[0]), undefined);
19333 assert.strictEqual(func({ '': 3 }, pair[1]), 3);
19337 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
19340 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
19343 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
19344 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
19347 lodashStable.each(paths, function(path) {
19348 assert.strictEqual(func(object, path), 8);
19352 QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
19355 lodashStable.each(['constructor', ['constructor']], function(path) {
19356 assert.strictEqual(func(null, path), undefined);
19357 assert.strictEqual(func(undefined, path), undefined);
19361 QUnit.test('`_.' + methodName + '` should return `undefined` with deep paths when `object` is nullish', function(assert) {
19364 var values = [null, undefined],
19365 expected = lodashStable.map(values, noop),
19366 paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
19368 lodashStable.each(paths, function(path) {
19369 var actual = lodashStable.map(values, function(value) {
19370 return func(value, path);
19373 assert.deepEqual(actual, expected);
19377 QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
19380 var object = { 'a': [, null] };
19382 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
19383 assert.strictEqual(func(object, path), undefined);
19387 QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
19390 var object = { 'a': { 'b': null } };
19392 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19393 assert.strictEqual(func(object, path), null);
19397 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
19400 var paths = ['a.b', ['a', 'b']];
19402 lodashStable.each(paths, function(path) {
19403 numberProto.a = { 'b': 2 };
19404 assert.strictEqual(func(0, path), 2);
19405 delete numberProto.a;
19409 QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
19412 var object = { 'a': {} },
19413 values = empties.concat(true, new Date, 1, /x/, 'a');
19415 var expected = lodashStable.transform(values, function(result, value) {
19416 result.push(value, value, value, value);
19419 var actual = lodashStable.transform(values, function(result, value) {
19420 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19422 func(object, path, value),
19423 func(null, path, value)
19428 assert.deepEqual(actual, expected);
19431 QUnit.test('`_.' + methodName + '` should return the default value when `path` is empty', function(assert) {
19434 assert.strictEqual(func({}, [], 'a'), 'a');
19438 /*--------------------------------------------------------------------------*/
19440 QUnit.module('lodash.rest');
19443 function fn(a, b, c) {
19444 return slice.call(arguments);
19447 QUnit.test('should apply a rest parameter to `func`', function(assert) {
19450 var rest = _.rest(fn);
19451 assert.deepEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
19454 QUnit.test('should work with `start`', function(assert) {
19457 var rest = _.rest(fn, 1);
19458 assert.deepEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
19461 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
19464 var values = [-1, NaN, 'a'],
19465 expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
19467 var actual = lodashStable.map(values, function(value) {
19468 var rest = _.rest(fn, value);
19469 return rest(1, 2, 3, 4);
19472 assert.deepEqual(actual, expected);
19475 QUnit.test('should coerce `start` to an integer', function(assert) {
19478 var rest = _.rest(fn, 1.6);
19479 assert.deepEqual(rest(1, 2, 3), [1, [2, 3]]);
19482 QUnit.test('should use an empty array when `start` is not reached', function(assert) {
19485 var rest = _.rest(fn);
19486 assert.deepEqual(rest(1), [1, undefined, []]);
19489 QUnit.test('should work on functions with more than three parameters', function(assert) {
19492 var rest = _.rest(function(a, b, c, d) {
19493 return slice.call(arguments);
19496 assert.deepEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
19500 /*--------------------------------------------------------------------------*/
19502 QUnit.module('lodash.reverse');
19505 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
19506 smallArray = [0, 1, 2, null];
19508 QUnit.test('should reverse `array`', function(assert) {
19511 var array = [1, 2, 3],
19512 actual = _.reverse(array);
19514 assert.strictEqual(actual, array);
19515 assert.deepEqual(array, [3, 2, 1]);
19518 QUnit.test('should return the wrapped reversed `array`', function(assert) {
19522 lodashStable.times(2, function(index) {
19523 var array = (index ? largeArray : smallArray).slice(),
19524 clone = array.slice(),
19525 wrapped = _(array).reverse(),
19526 actual = wrapped.value();
19528 assert.ok(wrapped instanceof _);
19529 assert.strictEqual(actual, array);
19530 assert.deepEqual(actual, clone.slice().reverse());
19534 skipAssert(assert, 6);
19538 QUnit.test('should work in a lazy sequence', function(assert) {
19542 lodashStable.times(2, function(index) {
19543 var array = (index ? largeArray : smallArray).slice(),
19544 expected = array.slice(),
19545 actual = _(array).slice(1).reverse().value();
19547 assert.deepEqual(actual, expected.slice(1).reverse());
19548 assert.deepEqual(array, expected);
19552 skipAssert(assert, 4);
19556 QUnit.test('should be lazy when in a lazy sequence', function(assert) {
19561 'toString': function() {
19562 throw new Error('spy was revealed');
19566 var array = largeArray.concat(spy),
19567 expected = array.slice();
19570 var wrapped = _(array).slice(1).map(String).reverse(),
19571 actual = wrapped.last();
19574 assert.ok(wrapped instanceof _);
19575 assert.strictEqual(actual, '1');
19576 assert.deepEqual(array, expected);
19579 skipAssert(assert, 3);
19583 QUnit.test('should work in a hybrid sequence', function(assert) {
19587 lodashStable.times(2, function(index) {
19588 var clone = (index ? largeArray : smallArray).slice();
19590 lodashStable.each(['map', 'filter'], function(methodName) {
19591 var array = clone.slice(),
19592 expected = clone.slice(1, -1).reverse(),
19593 actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
19595 assert.deepEqual(actual, expected);
19597 array = clone.slice();
19598 actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
19600 assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
19605 skipAssert(assert, 8);
19609 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
19613 lodashStable.times(2, function(index) {
19614 var array = (index ? largeArray : smallArray).slice(),
19615 expected = array.slice().reverse(),
19616 wrapped = _(array).chain().reverse().head();
19618 assert.ok(wrapped instanceof _);
19619 assert.strictEqual(wrapped.value(), _.head(expected));
19620 assert.deepEqual(array, expected);
19624 skipAssert(assert, 6);
19629 /*--------------------------------------------------------------------------*/
19631 QUnit.module('round methods');
19633 lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
19634 var func = _[methodName],
19635 isCeil = methodName == 'ceil',
19636 isFloor = methodName == 'floor';
19638 QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
19641 var actual = func(4.006);
19642 assert.strictEqual(actual, isCeil ? 5 : 4);
19645 QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
19648 var actual = func(4.006, 0);
19649 assert.strictEqual(actual, isCeil ? 5 : 4);
19652 QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
19655 var actual = func(4.016, 2);
19656 assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
19658 actual = func(4.1, 2);
19659 assert.strictEqual(actual, 4.1);
19662 QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
19665 var actual = func(4160, -2);
19666 assert.strictEqual(actual, isFloor ? 4100 : 4200);
19669 QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
19672 var actual = func(4.006, NaN);
19673 assert.strictEqual(actual, isCeil ? 5 : 4);
19675 var expected = isFloor ? 4.01 : 4.02;
19677 actual = func(4.016, 2.6);
19678 assert.strictEqual(actual, expected);
19680 actual = func(4.016, '+2');
19681 assert.strictEqual(actual, expected);
19684 QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
19687 var actual = func(5e1, 2);
19688 assert.deepEqual(actual, 50);
19690 actual = func('5e', 1);
19691 assert.deepEqual(actual, NaN);
19693 actual = func('5e1e1', 1);
19694 assert.deepEqual(actual, NaN);
19697 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19700 var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
19701 expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
19703 var actual = lodashStable.map(values, function(args) {
19704 return 1 / func.apply(undefined, args);
19707 assert.deepEqual(actual, expected);
19710 QUnit.test('`_.' + methodName + '` should not return `NaN` for large `precision` values', function(assert) {
19714 _.round(10.0000001, 1000),
19715 _.round(MAX_SAFE_INTEGER, 293)
19718 var expected = lodashStable.map(results, stubFalse),
19719 actual = lodashStable.map(results, lodashStable.isNaN);
19721 assert.deepEqual(actual, expected);
19725 /*--------------------------------------------------------------------------*/
19727 QUnit.module('lodash.runInContext');
19730 QUnit.test('should not require a fully populated `context` object', function(assert) {
19733 if (!isModularize) {
19734 var lodash = _.runInContext({
19735 'setTimeout': function(func) { func(); }
19739 lodash.delay(function() { pass = true; }, 32);
19743 skipAssert(assert);
19747 QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
19750 if (!isModularize) {
19751 lodashStable.times(2, _.uniqueId);
19753 var oldId = Number(_.uniqueId()),
19754 lodash = _.runInContext();
19756 assert.ok(_.uniqueId() > oldId);
19758 var id = lodash.uniqueId();
19759 assert.strictEqual(id, '1');
19760 assert.ok(id < oldId);
19763 skipAssert(assert, 3);
19768 /*--------------------------------------------------------------------------*/
19770 QUnit.module('lodash.sample');
19773 var array = [1, 2, 3];
19775 QUnit.test('should return a random element', function(assert) {
19778 var actual = _.sample(array);
19779 assert.ok(lodashStable.includes(array, actual));
19782 QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
19785 var expected = lodashStable.map(empties, noop);
19787 var actual = lodashStable.transform(empties, function(result, value) {
19789 result.push(_.sample(value));
19793 assert.deepEqual(actual, expected);
19796 QUnit.test('should sample an object', function(assert) {
19799 var object = { 'a': 1, 'b': 2, 'c': 3 },
19800 actual = _.sample(object);
19802 assert.ok(lodashStable.includes(array, actual));
19806 /*--------------------------------------------------------------------------*/
19808 QUnit.module('lodash.sampleSize');
19811 var array = [1, 2, 3];
19813 QUnit.test('should return an array of random elements', function(assert) {
19816 var actual = _.sampleSize(array, 2);
19818 assert.strictEqual(actual.length, 2);
19819 assert.deepEqual(lodashStable.difference(actual, array), []);
19822 QUnit.test('should contain elements of the collection', function(assert) {
19825 var actual = _.sampleSize(array, array.length).sort();
19827 assert.deepEqual(actual, array);
19830 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
19833 var expected = lodashStable.map(falsey, function(value) {
19834 return value === undefined ? ['a'] : [];
19837 var actual = lodashStable.map(falsey, function(size, index) {
19838 return index ? _.sampleSize(['a'], size) : _.sampleSize(['a']);
19841 assert.deepEqual(actual, expected);
19844 QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
19847 lodashStable.each([0, -1, -Infinity], function(n) {
19848 assert.deepEqual(_.sampleSize(array, n), []);
19852 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
19855 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
19856 var actual = _.sampleSize(array, n).sort();
19857 assert.deepEqual(actual, array);
19861 QUnit.test('should coerce `n` to an integer', function(assert) {
19864 var actual = _.sampleSize(array, 1.6);
19865 assert.strictEqual(actual.length, 1);
19868 QUnit.test('should return an empty array for empty collections', function(assert) {
19871 var expected = lodashStable.map(empties, stubArray);
19873 var actual = lodashStable.transform(empties, function(result, value) {
19875 result.push(_.sampleSize(value, 1));
19879 assert.deepEqual(actual, expected);
19882 QUnit.test('should sample an object', function(assert) {
19885 var object = { 'a': 1, 'b': 2, 'c': 3 },
19886 actual = _.sampleSize(object, 2);
19888 assert.strictEqual(actual.length, 2);
19889 assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
19892 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19895 var actual = lodashStable.map([['a']], _.sampleSize);
19896 assert.deepEqual(actual, [['a']]);
19900 /*--------------------------------------------------------------------------*/
19902 QUnit.module('lodash.setWith');
19905 QUnit.test('should work with a `customizer` callback', function(assert) {
19908 var actual = _.setWith({ '0': {} }, '[0][1][2]', 3, function(value) {
19909 return lodashStable.isObject(value) ? undefined : {};
19912 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
19915 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
19918 var actual = _.setWith({}, 'a[0].b.c', 4, noop);
19919 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
19923 /*--------------------------------------------------------------------------*/
19925 QUnit.module('set methods');
19927 lodashStable.each(['update', 'updateWith', 'set', 'setWith'], function(methodName) {
19928 var func = _[methodName],
19929 isUpdate = methodName == 'update' || methodName == 'updateWith';
19933 updater = isUpdate ? lodashStable.constant(value) : value;
19935 QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
19938 lodashStable.each(['a', ['a']], function(path) {
19939 var object = { 'a': oldValue },
19940 actual = func(object, path, updater);
19942 assert.strictEqual(actual, object);
19943 assert.strictEqual(object.a, value);
19947 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19950 var props = [-0, Object(-0), 0, Object(0)],
19951 expected = lodashStable.map(props, lodashStable.constant(value));
19953 var actual = lodashStable.map(props, function(key) {
19954 var object = { '-0': 'a', '0': 'b' };
19955 func(object, key, updater);
19956 return object[lodashStable.toString(key)];
19959 assert.deepEqual(actual, expected);
19962 QUnit.test('`_.' + methodName + '` should unset symbol keyed property values', function(assert) {
19967 object[symbol] = 1;
19969 assert.strictEqual(_.unset(object, symbol), true);
19970 assert.notOk(symbol in object);
19973 skipAssert(assert, 2);
19977 QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
19980 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19981 var object = { 'a': { 'b': oldValue } },
19982 actual = func(object, path, updater);
19984 assert.strictEqual(actual, object);
19985 assert.strictEqual(object.a.b, value);
19989 QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
19992 lodashStable.each(['a.b', ['a.b']], function(path) {
19993 var object = { 'a.b': oldValue },
19994 actual = func(object, path, updater);
19996 assert.strictEqual(actual, object);
19997 assert.deepEqual(object, { 'a.b': value });
20001 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
20004 var object = { 'a,b,c': 1, 'a': { 'b': { 'c': 1 } } };
20006 func(object, ['a', 'b', 'c'], updater);
20007 assert.strictEqual(object.a.b.c, value);
20010 QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
20015 func(object, 'a[]', updater);
20016 assert.deepEqual(object, { 'a': { '': value } });
20019 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
20022 lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
20025 func(object, pair[0], updater);
20026 assert.deepEqual(object, index ? {} : { '': value });
20028 func(object, pair[1], updater);
20029 assert.deepEqual(object, { '': value });
20033 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
20036 var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': oldValue } } } } } } } };
20039 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
20040 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
20043 lodashStable.each(paths, function(path) {
20044 func(object, path, updater);
20045 assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, value);
20046 object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = oldValue;
20050 QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
20055 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
20056 var actual = func(object, path, updater);
20058 assert.strictEqual(actual, object);
20059 assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': value } }] });
20060 assert.notOk('0' in object.a);
20066 QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
20069 var values = [null, undefined],
20070 expected = [[null, null], [undefined, undefined]];
20072 var actual = lodashStable.map(values, function(value) {
20074 return [func(value, 'a.b', updater), func(value, ['a', 'b'], updater)];
20080 assert.deepEqual(actual, expected);
20083 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
20086 var object = { 'a': '' },
20087 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
20089 lodashStable.each(paths, function(path) {
20090 func(0, path, updater);
20091 assert.strictEqual(0..a, value);
20092 delete numberProto.a;
20095 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
20096 func(object, path, updater);
20097 assert.strictEqual(stringProto.replace.b, value);
20098 delete stringProto.replace.b;
20102 QUnit.test('`_.' + methodName + '` should not error on paths over primitives in strict mode', function(assert) {
20107 lodashStable.each(['a', 'a.a.a'], function(path) {
20108 numberProto.a = oldValue;
20110 func(0, path, updater);
20111 assert.strictEqual(0..a, oldValue);
20113 assert.ok(false, e.message);
20117 delete numberProto.a;
20120 QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
20125 func(object, ['1a', '2b', '3c'], updater);
20126 assert.deepEqual(object, { '1a': { '2b': { '3c': value } } });
20129 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
20132 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
20135 updater = isUpdate ? lodashStable.constant(value) : value;
20137 defineProperty(object, 'a', {
20138 'enumerable': true,
20139 'configurable': true,
20140 'get': lodashStable.constant(value),
20141 'set': function() { pass = false; }
20144 func(object, 'a', updater);
20150 /*--------------------------------------------------------------------------*/
20152 QUnit.module('lodash.shuffle');
20155 var array = [1, 2, 3],
20156 object = { 'a': 1, 'b': 2, 'c': 3 };
20158 QUnit.test('should return a new array', function(assert) {
20161 assert.notStrictEqual(_.shuffle(array), array);
20164 QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
20167 assert.deepEqual(_.shuffle(array).sort(), array);
20168 assert.deepEqual(_.shuffle(object).sort(), array);
20171 QUnit.test('should shuffle small collections', function(assert) {
20174 var actual = lodashStable.times(1000, function(assert) {
20175 return _.shuffle([1, 2]);
20178 assert.deepEqual(lodashStable.sortBy(lodashStable.uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
20181 QUnit.test('should treat number values for `collection` as empty', function(assert) {
20184 assert.deepEqual(_.shuffle(1), []);
20188 /*--------------------------------------------------------------------------*/
20190 QUnit.module('lodash.size');
20193 var args = arguments,
20196 QUnit.test('should return the number of own enumerable string keyed properties of an object', function(assert) {
20199 assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
20202 QUnit.test('should return the length of an array', function(assert) {
20205 assert.strictEqual(_.size(array), 3);
20208 QUnit.test('should accept a falsey `object` argument', function(assert) {
20211 var expected = lodashStable.map(falsey, stubZero);
20213 var actual = lodashStable.map(falsey, function(object, index) {
20215 return index ? _.size(object) : _.size();
20219 assert.deepEqual(actual, expected);
20222 QUnit.test('should work with `arguments` objects', function(assert) {
20225 assert.strictEqual(_.size(args), 3);
20228 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
20231 function Foo(elements) {
20232 push.apply(this, elements);
20234 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
20236 assert.strictEqual(_.size(new Foo(array)), 3);
20239 QUnit.test('should work with maps', function(assert) {
20243 lodashStable.each([new Map, realm.map], function(map) {
20246 assert.strictEqual(_.size(map), 2);
20251 skipAssert(assert, 2);
20255 QUnit.test('should work with sets', function(assert) {
20259 lodashStable.each([new Set, realm.set], function(set) {
20262 assert.strictEqual(_.size(set), 2);
20267 skipAssert(assert, 2);
20271 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
20274 assert.strictEqual(_.size({ 'length': -1 }), 1);
20277 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
20280 assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
20283 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
20286 assert.strictEqual(_.size({ 'length': '0' }), 1);
20290 /*--------------------------------------------------------------------------*/
20292 QUnit.module('lodash.slice');
20295 var array = [1, 2, 3];
20297 QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
20300 var actual = _.slice(array);
20301 assert.deepEqual(actual, array);
20302 assert.notStrictEqual(actual, array);
20305 QUnit.test('should work with a positive `start`', function(assert) {
20308 assert.deepEqual(_.slice(array, 1), [2, 3]);
20309 assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
20312 QUnit.test('should work with a `start` >= `length`', function(assert) {
20315 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
20316 assert.deepEqual(_.slice(array, start), []);
20320 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
20323 var expected = lodashStable.map(falsey, lodashStable.constant(array));
20325 var actual = lodashStable.map(falsey, function(start) {
20326 return _.slice(array, start);
20329 assert.deepEqual(actual, expected);
20332 QUnit.test('should work with a negative `start`', function(assert) {
20335 assert.deepEqual(_.slice(array, -1), [3]);
20338 QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
20341 lodashStable.each([-3, -4, -Infinity], function(start) {
20342 assert.deepEqual(_.slice(array, start), array);
20346 QUnit.test('should work with `start` >= `end`', function(assert) {
20349 lodashStable.each([2, 3], function(start) {
20350 assert.deepEqual(_.slice(array, start, 2), []);
20354 QUnit.test('should work with a positive `end`', function(assert) {
20357 assert.deepEqual(_.slice(array, 0, 1), [1]);
20360 QUnit.test('should work with a `end` >= `length`', function(assert) {
20363 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
20364 assert.deepEqual(_.slice(array, 0, end), array);
20368 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
20371 var expected = lodashStable.map(falsey, function(value) {
20372 return value === undefined ? array : [];
20375 var actual = lodashStable.map(falsey, function(end, index) {
20376 return index ? _.slice(array, 0, end) : _.slice(array, 0);
20379 assert.deepEqual(actual, expected);
20382 QUnit.test('should work with a negative `end`', function(assert) {
20385 assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
20388 QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
20391 lodashStable.each([-3, -4, -Infinity], function(end) {
20392 assert.deepEqual(_.slice(array, 0, end), []);
20396 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
20399 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
20401 var actual = lodashStable.map(positions, function(pos) {
20402 return _.slice.apply(_, [array].concat(pos));
20405 assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
20408 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20411 var array = [[1], [2, 3]],
20412 actual = lodashStable.map(array, _.slice);
20414 assert.deepEqual(actual, array);
20415 assert.notStrictEqual(actual, array);
20418 QUnit.test('should work in a lazy sequence', function(assert) {
20422 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
20423 length = array.length,
20424 wrapped = _(array);
20426 lodashStable.each(['map', 'filter'], function(methodName) {
20427 assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
20428 assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
20429 assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
20430 assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
20432 assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
20433 assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
20434 assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
20435 assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
20437 assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
20438 assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
20439 assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
20441 assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
20442 assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
20444 assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
20445 assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
20446 assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
20447 assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
20448 assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
20449 assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
20453 skipAssert(assert, 38);
20458 /*--------------------------------------------------------------------------*/
20460 QUnit.module('lodash.some');
20463 QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
20466 assert.strictEqual(_.some([false, 1, ''], identity), true);
20467 assert.strictEqual(_.some([null, 'a', 0], identity), true);
20470 QUnit.test('should return `false` for empty collections', function(assert) {
20473 var expected = lodashStable.map(empties, stubFalse);
20475 var actual = lodashStable.map(empties, function(value) {
20477 return _.some(value, identity);
20481 assert.deepEqual(actual, expected);
20484 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
20489 assert.strictEqual(_.some([null, true, null], function(value) {
20494 assert.strictEqual(count, 2);
20497 QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
20500 assert.strictEqual(_.some([false, false, false], identity), false);
20501 assert.strictEqual(_.some([null, 0, ''], identity), false);
20504 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
20507 var values = [, null, undefined],
20508 expected = lodashStable.map(values, stubFalse);
20510 var actual = lodashStable.map(values, function(value, index) {
20511 var array = [0, 0];
20512 return index ? _.some(array, value) : _.some(array);
20515 assert.deepEqual(actual, expected);
20517 expected = lodashStable.map(values, stubTrue);
20518 actual = lodashStable.map(values, function(value, index) {
20519 var array = [0, 1];
20520 return index ? _.some(array, value) : _.some(array);
20523 assert.deepEqual(actual, expected);
20526 QUnit.test('should work with `_.property` shorthands', function(assert) {
20529 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
20530 assert.strictEqual(_.some(objects, 'a'), false);
20531 assert.strictEqual(_.some(objects, 'b'), true);
20534 QUnit.test('should work with `_.matches` shorthands', function(assert) {
20537 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
20538 assert.strictEqual(_.some(objects, { 'a': 0 }), true);
20539 assert.strictEqual(_.some(objects, { 'b': 2 }), false);
20542 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20545 var actual = lodashStable.map([[1]], _.some);
20546 assert.deepEqual(actual, [true]);
20550 /*--------------------------------------------------------------------------*/
20552 QUnit.module('lodash.sortBy');
20556 { 'a': 'x', 'b': 3 },
20557 { 'a': 'y', 'b': 4 },
20558 { 'a': 'x', 'b': 1 },
20559 { 'a': 'y', 'b': 2 }
20562 QUnit.test('should sort in ascending order by `iteratee`', function(assert) {
20565 var actual = lodashStable.map(_.sortBy(objects, function(object) {
20569 assert.deepEqual(actual, [1, 2, 3, 4]);
20572 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
20575 var array = [3, 2, 1],
20576 values = [, null, undefined],
20577 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
20579 var actual = lodashStable.map(values, function(value, index) {
20580 return index ? _.sortBy(array, value) : _.sortBy(array);
20583 assert.deepEqual(actual, expected);
20586 QUnit.test('should work with `_.property` shorthands', function(assert) {
20589 var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
20590 assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
20593 QUnit.test('should work with an object for `collection`', function(assert) {
20596 var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, Math.sin);
20597 assert.deepEqual(actual, [3, 1, 2]);
20600 QUnit.test('should move symbol, `null`, `undefined`, and `NaN` values to the end', function(assert) {
20603 var symbol1 = Symbol ? Symbol('a') : null,
20604 symbol2 = Symbol ? Symbol('b') : null,
20605 array = [NaN, undefined, null, 4, symbol1, null, 1, symbol2, undefined, 3, NaN, 2],
20606 expected = [1, 2, 3, 4, symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20608 assert.deepEqual(_.sortBy(array), expected);
20610 array = [NaN, undefined, symbol1, null, 'd', null, 'a', symbol2, undefined, 'c', NaN, 'b'];
20611 expected = ['a', 'b', 'c', 'd', symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20613 assert.deepEqual(_.sortBy(array), expected);
20616 QUnit.test('should treat number values for `collection` as empty', function(assert) {
20619 assert.deepEqual(_.sortBy(1), []);
20622 QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
20625 var actual = _.sortBy(objects, function(object) {
20626 var result = [object.a, object.b];
20627 result.toString = function() { return String(this[0]); };
20631 assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
20634 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20637 var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
20638 assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
20642 /*--------------------------------------------------------------------------*/
20644 QUnit.module('sortBy methods');
20646 lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
20647 var func = _[methodName];
20649 function Pair(a, b, c) {
20656 { 'a': 'x', 'b': 3 },
20657 { 'a': 'y', 'b': 4 },
20658 { 'a': 'x', 'b': 1 },
20659 { 'a': 'y', 'b': 2 }
20662 var stableArray = [
20663 new Pair(1, 1, 1), new Pair(1, 2, 1),
20664 new Pair(1, 1, 1), new Pair(1, 2, 1),
20665 new Pair(1, 3, 1), new Pair(1, 4, 1),
20666 new Pair(1, 5, 1), new Pair(1, 6, 1),
20667 new Pair(2, 1, 2), new Pair(2, 2, 2),
20668 new Pair(2, 3, 2), new Pair(2, 4, 2),
20669 new Pair(2, 5, 2), new Pair(2, 6, 2),
20670 new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
20671 new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
20672 new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
20675 var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
20677 QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
20680 var actual = func(objects, ['a', 'b']);
20681 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20684 QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
20687 var actual = func(objects, ['a', function(object) { return object.b; }]);
20688 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20691 QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
20694 lodashStable.each([stableArray, stableObject], function(value, index) {
20695 var actual = func(value, ['a', 'c']);
20696 assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
20700 QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
20704 var actual = func(objects.concat(null, undefined), ['a', 'b']);
20707 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
20710 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
20714 { 'a': 'x', '0': 3 },
20715 { 'a': 'y', '0': 4 },
20716 { 'a': 'x', '0': 1 },
20717 { 'a': 'y', '0': 2 }
20720 var funcs = [func, lodashStable.partialRight(func, 'bogus')];
20722 lodashStable.each(['a', 0, [0]], function(props, index) {
20723 var expected = lodashStable.map(funcs, lodashStable.constant(
20725 ? [objects[2], objects[3], objects[0], objects[1]]
20726 : [objects[0], objects[2], objects[1], objects[3]]
20729 var actual = lodashStable.map(funcs, function(func) {
20730 return lodashStable.reduce([props], func, objects);
20733 assert.deepEqual(actual, expected);
20738 /*--------------------------------------------------------------------------*/
20740 QUnit.module('sortedIndex methods');
20742 lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
20743 var func = _[methodName],
20744 isSortedIndex = methodName == 'sortedIndex';
20746 QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
20749 var array = [30, 50],
20750 values = [30, 40, 50],
20751 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20753 var actual = lodashStable.map(values, function(value) {
20754 return func(array, value);
20757 assert.deepEqual(actual, expected);
20760 QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
20763 var array = ['a', 'c'],
20764 values = ['a', 'b', 'c'],
20765 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20767 var actual = lodashStable.map(values, function(value) {
20768 return func(array, value);
20771 assert.deepEqual(actual, expected);
20774 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument and a `value`', function(assert) {
20777 var expected = lodashStable.map(falsey, lodashStable.constant([0, 0, 0]));
20779 var actual = lodashStable.map(falsey, function(array) {
20780 return [func(array, 1), func(array, undefined), func(array, NaN)];
20783 assert.deepEqual(actual, expected);
20786 QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
20789 var symbol1 = Symbol ? Symbol('a') : null,
20790 symbol2 = Symbol ? Symbol('b') : null,
20791 symbol3 = Symbol ? Symbol('c') : null,
20792 expected = [1, '2', {}, symbol1, symbol2, null, undefined, NaN, NaN];
20794 lodashStable.each([
20795 [NaN, symbol1, null, 1, '2', {}, symbol2, NaN, undefined],
20796 ['2', null, 1, symbol1, NaN, {}, NaN, symbol2, undefined]
20797 ], function(array) {
20798 assert.deepEqual(_.sortBy(array), expected);
20799 assert.strictEqual(func(expected, 3), 2);
20800 assert.strictEqual(func(expected, symbol3), isSortedIndex ? 3 : (Symbol ? 5 : 6));
20801 assert.strictEqual(func(expected, null), isSortedIndex ? (Symbol ? 5 : 3) : 6);
20802 assert.strictEqual(func(expected, undefined), isSortedIndex ? 6 : 7);
20803 assert.strictEqual(func(expected, NaN), isSortedIndex ? 7 : 9);
20807 QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for nulls', function(assert) {
20810 var array = [null, null];
20812 assert.strictEqual(func(array, null), isSortedIndex ? 0 : 2);
20813 assert.strictEqual(func(array, 1), 0);
20814 assert.strictEqual(func(array, 'a'), 0);
20817 QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for symbols', function(assert) {
20820 var symbol1 = Symbol ? Symbol('a') : null,
20821 symbol2 = Symbol ? Symbol('b') : null,
20822 symbol3 = Symbol ? Symbol('c') : null,
20823 array = [symbol1, symbol2];
20825 assert.strictEqual(func(array, symbol3), isSortedIndex ? 0 : 2);
20826 assert.strictEqual(func(array, 1), 0);
20827 assert.strictEqual(func(array, 'a'), 0);
20831 /*--------------------------------------------------------------------------*/
20833 QUnit.module('sortedIndexBy methods');
20835 lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
20836 var func = _[methodName],
20837 isSortedIndexBy = methodName == 'sortedIndexBy';
20839 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
20844 func([30, 50], 40, function(assert) {
20845 args || (args = slice.call(arguments));
20848 assert.deepEqual(args, [40]);
20851 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
20854 var objects = [{ 'x': 30 }, { 'x': 50 }],
20855 actual = func(objects, { 'x': 40 }, 'x');
20857 assert.strictEqual(actual, 1);
20860 QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
20863 lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
20865 values = [MAX_ARRAY_LENGTH, NaN, undefined];
20867 array.length = length;
20869 lodashStable.each(values, function(value) {
20872 var actual = func(array, value, function(value) {
20877 var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
20879 : Math.min(length, MAX_ARRAY_INDEX);
20881 // Avoid false fails in older Firefox.
20882 if (array.length == length) {
20883 assert.ok(steps == 32 || steps == 33);
20884 assert.strictEqual(actual, expected);
20887 skipAssert(assert, 2);
20894 /*--------------------------------------------------------------------------*/
20896 QUnit.module('sortedIndexOf methods');
20898 lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
20899 var func = _[methodName],
20900 isSortedIndexOf = methodName == 'sortedIndexOf';
20902 QUnit.test('`_.' + methodName + '` should perform a binary search', function(assert) {
20905 var sorted = [4, 4, 5, 5, 6, 6];
20906 assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
20910 /*--------------------------------------------------------------------------*/
20912 QUnit.module('lodash.sortedUniq');
20915 QUnit.test('should return unique values of a sorted array', function(assert) {
20918 var expected = [1, 2, 3];
20920 lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
20921 assert.deepEqual(_.sortedUniq(array), expected);
20926 /*--------------------------------------------------------------------------*/
20928 QUnit.module('lodash.split');
20931 QUnit.test('should split a string by `separator`', function(assert) {
20934 var string = 'abcde';
20935 assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
20936 assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
20937 assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
20940 QUnit.test('should return an array containing an empty string for empty values', function(assert) {
20943 var values = [, null, undefined, ''],
20944 expected = lodashStable.map(values, lodashStable.constant(['']));
20946 var actual = lodashStable.map(values, function(value, index) {
20947 return index ? _.split(value) : _.split();
20950 assert.deepEqual(actual, expected);
20953 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20956 var strings = ['abc', 'def', 'ghi'],
20957 actual = lodashStable.map(strings, _.split);
20959 assert.deepEqual(actual, [['abc'], ['def'], ['ghi']]);
20962 QUnit.test('should allow mixed string and array prototype methods', function(assert) {
20966 var wrapped = _('abc');
20967 assert.strictEqual(wrapped.split('b').join(','), 'a,c');
20970 skipAssert(assert);
20975 /*--------------------------------------------------------------------------*/
20977 QUnit.module('lodash.spread');
20980 function fn(a, b, c) {
20981 return slice.call(arguments);
20984 QUnit.test('should spread arguments to `func`', function(assert) {
20987 var spread = _.spread(fn);
20988 assert.deepEqual(spread([4, 2]), [4, 2]);
20991 QUnit.test('should accept a falsey `array` argument', function(assert) {
20994 var spread = _.spread(stubTrue),
20995 expected = lodashStable.map(falsey, stubTrue);
20997 var actual = lodashStable.map(falsey, function(array, index) {
20999 return index ? spread(array) : spread();
21003 assert.deepEqual(actual, expected);
21006 QUnit.test('should provide the correct `func` arguments', function(assert) {
21011 var spread = _.spread(function() {
21012 args = slice.call(arguments);
21015 spread([4, 2], 'ignored');
21016 assert.deepEqual(args, [4, 2]);
21019 QUnit.test('should work with `start`', function(assert) {
21022 var spread = _.spread(fn, 1);
21023 assert.deepEqual(spread(1, [2, 3, 4]), [1, 2, 3, 4]);
21026 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
21029 var values = [-1, NaN, 'a'],
21030 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
21032 var actual = lodashStable.map(values, function(value) {
21033 var spread = _.spread(fn, value);
21034 return spread([1, 2, 3, 4]);
21037 assert.deepEqual(actual, expected);
21040 QUnit.test('should coerce `start` to an integer', function(assert) {
21043 var spread = _.spread(fn, 1.6);
21044 assert.deepEqual(spread(1, [2, 3]), [1, 2, 3]);
21048 /*--------------------------------------------------------------------------*/
21050 QUnit.module('lodash.startCase');
21053 QUnit.test('should uppercase only the first character of each word', function(assert) {
21056 assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar');
21057 assert.strictEqual(_.startCase('fooBar'), 'Foo Bar');
21058 assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR');
21062 /*--------------------------------------------------------------------------*/
21064 QUnit.module('lodash.startsWith');
21067 var string = 'abc';
21069 QUnit.test('should return `true` if a string starts with `target`', function(assert) {
21072 assert.strictEqual(_.startsWith(string, 'a'), true);
21075 QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
21078 assert.strictEqual(_.startsWith(string, 'b'), false);
21081 QUnit.test('should work with a `position` argument', function(assert) {
21084 assert.strictEqual(_.startsWith(string, 'b', 1), true);
21087 QUnit.test('should work with `position` >= `length`', function(assert) {
21090 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
21091 assert.strictEqual(_.startsWith(string, 'a', position), false);
21095 QUnit.test('should treat falsey `position` values as `0`', function(assert) {
21098 var expected = lodashStable.map(falsey, stubTrue);
21100 var actual = lodashStable.map(falsey, function(position) {
21101 return _.startsWith(string, 'a', position);
21104 assert.deepEqual(actual, expected);
21107 QUnit.test('should treat a negative `position` as `0`', function(assert) {
21110 lodashStable.each([-1, -3, -Infinity], function(position) {
21111 assert.strictEqual(_.startsWith(string, 'a', position), true);
21112 assert.strictEqual(_.startsWith(string, 'b', position), false);
21116 QUnit.test('should coerce `position` to an integer', function(assert) {
21119 assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
21122 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
21125 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
21126 return _.startsWith(string, '', position, true);
21131 /*--------------------------------------------------------------------------*/
21133 QUnit.module('lodash.startsWith and lodash.endsWith');
21135 lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
21136 var func = _[methodName],
21137 isStartsWith = methodName == 'startsWith';
21139 var string = 'abc',
21140 chr = isStartsWith ? 'a' : 'c';
21142 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
21145 assert.strictEqual(func(Object(string), chr), true);
21146 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
21149 QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
21152 assert.strictEqual(func(string, Object(chr)), true);
21153 assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
21156 QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
21159 var position = isStartsWith ? 1 : 2;
21160 assert.strictEqual(func(string, 'b', Object(position)), true);
21161 assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
21165 /*--------------------------------------------------------------------------*/
21167 QUnit.module('stub methods');
21169 lodashStable.each(['noop', 'stubTrue', 'stubFalse', 'stubArray', 'stubObject', 'stubString'], function(methodName) {
21170 var func = _[methodName];
21173 'stubArray': [[], 'an empty array'],
21174 'stubFalse': [false, '`false`'],
21175 'stubObject': [{}, 'an empty object'],
21176 'stubString': ['', 'an empty string'],
21177 'stubTrue': [true, '`true`'],
21178 'noop': [undefined, '`undefined`']
21181 var values = Array(2).concat(empties, true, 1, 'a'),
21182 expected = lodashStable.map(values, lodashStable.constant(pair[0]));
21184 QUnit.test('`_.' + methodName + '` should return ' + pair[1], function(assert) {
21187 var actual = lodashStable.map(values, function(value, index) {
21189 return index ? func.call({}) : func();
21191 return func(value);
21194 assert.deepEqual(actual, expected);
21198 /*--------------------------------------------------------------------------*/
21200 QUnit.module('lodash.subtract');
21203 QUnit.test('should subtract two numbers', function(assert) {
21206 assert.strictEqual(_.subtract(6, 4), 2);
21207 assert.strictEqual(_.subtract(-6, 4), -10);
21208 assert.strictEqual(_.subtract(-6, -4), -2);
21211 QUnit.test('should coerce arguments to numbers', function(assert) {
21214 assert.strictEqual(_.subtract('6', '4'), 2);
21215 assert.deepEqual(_.subtract('x', 'y'), NaN);
21219 /*--------------------------------------------------------------------------*/
21221 QUnit.module('math operator methods');
21223 lodashStable.each(['add', 'divide', 'multiply', 'subtract'], function(methodName) {
21224 var func = _[methodName];
21226 QUnit.test('`_.' + methodName + '` should return `0` when no arguments are given', function(assert) {
21229 assert.strictEqual(func(), 0);
21232 QUnit.test('`_.' + methodName + '` should work with only one defined argument', function(assert) {
21235 assert.strictEqual(func(6), 6);
21236 assert.strictEqual(func(6, undefined), 6);
21237 assert.strictEqual(func(undefined, 4), 4);
21240 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
21243 var values = [0, '0', -0, '-0'],
21244 expected = [[0, Infinity], ['0', Infinity], [-0, -Infinity], ['-0', -Infinity]];
21246 lodashStable.times(2, function(index) {
21247 var actual = lodashStable.map(values, function(value) {
21248 var result = index ? func(undefined, value) : func(value);
21249 return [result, 1 / result];
21252 assert.deepEqual(actual, expected);
21256 QUnit.test('`_.' + methodName + '` should convert objects to `NaN`', function(assert) {
21259 assert.deepEqual(func(0, {}), NaN);
21260 assert.deepEqual(func({}, 0), NaN);
21263 QUnit.test('`_.' + methodName + '` should convert symbols to `NaN`', function(assert) {
21267 assert.deepEqual(func(0, symbol), NaN);
21268 assert.deepEqual(func(symbol, 0), NaN);
21271 skipAssert(assert, 2);
21275 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
21279 var actual = _(1)[methodName](2);
21280 assert.notOk(actual instanceof _);
21283 skipAssert(assert);
21287 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
21291 var actual = _(1).chain()[methodName](2);
21292 assert.ok(actual instanceof _);
21295 skipAssert(assert);
21300 /*--------------------------------------------------------------------------*/
21302 QUnit.module('lodash.sumBy');
21305 var array = [6, 4, 2],
21306 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
21308 QUnit.test('should work with an `iteratee` argument', function(assert) {
21311 var actual = _.sumBy(objects, function(object) {
21315 assert.deepEqual(actual, 6);
21318 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
21323 _.sumBy(array, function() {
21324 args || (args = slice.call(arguments));
21327 assert.deepEqual(args, [6]);
21330 QUnit.test('should work with `_.property` shorthands', function(assert) {
21333 var arrays = [[2], [3], [1]];
21334 assert.strictEqual(_.sumBy(arrays, 0), 6);
21335 assert.strictEqual(_.sumBy(objects, 'a'), 6);
21339 /*--------------------------------------------------------------------------*/
21341 QUnit.module('sum methods');
21343 lodashStable.each(['sum', 'sumBy'], function(methodName) {
21344 var array = [6, 4, 2],
21345 func = _[methodName];
21347 QUnit.test('`_.' + methodName + '` should return the sum of an array of numbers', function(assert) {
21350 assert.strictEqual(func(array), 12);
21353 QUnit.test('`_.' + methodName + '` should return `0` when passing empty `array` values', function(assert) {
21356 var expected = lodashStable.map(empties, stubZero);
21358 var actual = lodashStable.map(empties, function(value) {
21359 return func(value);
21362 assert.deepEqual(actual, expected);
21365 QUnit.test('`_.' + methodName + '` should skip `undefined` values', function(assert) {
21368 assert.strictEqual(func([1, undefined]), 1);
21371 QUnit.test('`_.' + methodName + '` should not skip `NaN` values', function(assert) {
21374 assert.deepEqual(func([1, NaN]), NaN);
21377 QUnit.test('`_.' + methodName + '` should not coerce values to numbers', function(assert) {
21380 assert.strictEqual(func(['1', '2']), '12');
21384 /*--------------------------------------------------------------------------*/
21386 QUnit.module('lodash.tail');
21389 var array = [1, 2, 3];
21391 QUnit.test('should accept a falsey `array` argument', function(assert) {
21394 var expected = lodashStable.map(falsey, stubArray);
21396 var actual = lodashStable.map(falsey, function(array, index) {
21398 return index ? _.tail(array) : _.tail();
21402 assert.deepEqual(actual, expected);
21405 QUnit.test('should exclude the first element', function(assert) {
21408 assert.deepEqual(_.tail(array), [2, 3]);
21411 QUnit.test('should return an empty when querying empty arrays', function(assert) {
21414 assert.deepEqual(_.tail([]), []);
21417 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21420 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21421 actual = lodashStable.map(array, _.tail);
21423 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
21426 QUnit.test('should work in a lazy sequence', function(assert) {
21430 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21433 var actual = _(array).tail().filter(function(value) {
21434 values.push(value);
21439 assert.deepEqual(actual, []);
21440 assert.deepEqual(values, array.slice(1));
21444 actual = _(array).filter(function(value) {
21445 values.push(value);
21446 return isEven(value);
21451 assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
21452 assert.deepEqual(values, array);
21455 skipAssert(assert, 4);
21459 QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
21463 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21464 iteratee = function() { pass = false; },
21466 actual = _(array).slice(0, 1).tail().map(iteratee).value();
21469 assert.deepEqual(actual, []);
21472 actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
21475 assert.deepEqual(actual, []);
21478 skipAssert(assert, 4);
21483 /*--------------------------------------------------------------------------*/
21485 QUnit.module('lodash.take');
21488 var array = [1, 2, 3];
21490 QUnit.test('should take the first two elements', function(assert) {
21493 assert.deepEqual(_.take(array, 2), [1, 2]);
21496 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21499 var expected = lodashStable.map(falsey, function(value) {
21500 return value === undefined ? [1] : [];
21503 var actual = lodashStable.map(falsey, function(n) {
21504 return _.take(array, n);
21507 assert.deepEqual(actual, expected);
21510 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21513 lodashStable.each([0, -1, -Infinity], function(n) {
21514 assert.deepEqual(_.take(array, n), []);
21518 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
21521 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21522 assert.deepEqual(_.take(array, n), array);
21526 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21529 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21530 actual = lodashStable.map(array, _.take);
21532 assert.deepEqual(actual, [[1], [4], [7]]);
21535 QUnit.test('should work in a lazy sequence', function(assert) {
21539 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
21540 predicate = function(value) { values.push(value); return isEven(value); },
21542 actual = _(array).take(2).take().value();
21544 assert.deepEqual(actual, _.take(_.take(array, 2)));
21546 actual = _(array).filter(predicate).take(2).take().value();
21547 assert.deepEqual(values, [1, 2]);
21548 assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
21550 actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
21551 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
21555 actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
21556 assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
21557 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
21560 skipAssert(assert, 6);
21565 /*--------------------------------------------------------------------------*/
21567 QUnit.module('lodash.takeRight');
21570 var array = [1, 2, 3];
21572 QUnit.test('should take the last two elements', function(assert) {
21575 assert.deepEqual(_.takeRight(array, 2), [2, 3]);
21578 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21581 var expected = lodashStable.map(falsey, function(value) {
21582 return value === undefined ? [3] : [];
21585 var actual = lodashStable.map(falsey, function(n) {
21586 return _.takeRight(array, n);
21589 assert.deepEqual(actual, expected);
21592 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21595 lodashStable.each([0, -1, -Infinity], function(n) {
21596 assert.deepEqual(_.takeRight(array, n), []);
21600 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
21603 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21604 assert.deepEqual(_.takeRight(array, n), array);
21608 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21611 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21612 actual = lodashStable.map(array, _.takeRight);
21614 assert.deepEqual(actual, [[3], [6], [9]]);
21617 QUnit.test('should work in a lazy sequence', function(assert) {
21621 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21622 predicate = function(value) { values.push(value); return isEven(value); },
21624 actual = _(array).takeRight(2).takeRight().value();
21626 assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
21628 actual = _(array).filter(predicate).takeRight(2).takeRight().value();
21629 assert.deepEqual(values, array);
21630 assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
21632 actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
21633 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
21637 actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
21638 assert.deepEqual(values, array);
21639 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
21642 skipAssert(assert, 6);
21647 /*--------------------------------------------------------------------------*/
21649 QUnit.module('lodash.takeRightWhile');
21652 var array = [1, 2, 3, 4];
21655 { 'a': 0, 'b': 0 },
21656 { 'a': 1, 'b': 1 },
21660 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21663 var actual = _.takeRightWhile(array, function(n) {
21667 assert.deepEqual(actual, [3, 4]);
21670 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
21675 _.takeRightWhile(array, function() {
21676 args = slice.call(arguments);
21679 assert.deepEqual(args, [4, 3, array]);
21682 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21685 assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
21688 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21691 assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
21694 QUnit.test('should work with `_.property` shorthands', function(assert) {
21697 assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
21700 QUnit.test('should work in a lazy sequence', function(assert) {
21704 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21705 predicate = function(n) { return n > 2; },
21706 expected = _.takeRightWhile(array, predicate),
21707 wrapped = _(array).takeRightWhile(predicate);
21709 assert.deepEqual(wrapped.value(), expected);
21710 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21711 assert.strictEqual(wrapped.last(), _.last(expected));
21714 skipAssert(assert, 3);
21718 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
21723 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21724 expected = [square(LARGE_ARRAY_SIZE), LARGE_ARRAY_SIZE - 1, lodashStable.map(array.slice(1), square)];
21726 _(array).slice(1).takeRightWhile(function(value, index, array) {
21727 args = slice.call(arguments);
21730 assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
21732 _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
21733 args = slice.call(arguments);
21736 assert.deepEqual(args, expected);
21738 _(array).slice(1).map(square).takeRightWhile(function(value, index) {
21739 args = slice.call(arguments);
21742 assert.deepEqual(args, expected);
21744 _(array).slice(1).map(square).takeRightWhile(function(index) {
21745 args = slice.call(arguments);
21748 assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
21750 _(array).slice(1).map(square).takeRightWhile(function() {
21751 args = slice.call(arguments);
21754 assert.deepEqual(args, expected);
21757 skipAssert(assert, 5);
21762 /*--------------------------------------------------------------------------*/
21764 QUnit.module('lodash.takeWhile');
21767 var array = [1, 2, 3, 4];
21770 { 'a': 2, 'b': 2 },
21771 { 'a': 1, 'b': 1 },
21775 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21778 var actual = _.takeWhile(array, function(n) {
21782 assert.deepEqual(actual, [1, 2]);
21785 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
21790 _.takeWhile(array, function() {
21791 args = slice.call(arguments);
21794 assert.deepEqual(args, [1, 0, array]);
21797 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21800 assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
21803 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21806 assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
21808 QUnit.test('should work with `_.property` shorthands', function(assert) {
21811 assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
21814 QUnit.test('should work in a lazy sequence', function(assert) {
21818 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21819 predicate = function(n) { return n < 3; },
21820 expected = _.takeWhile(array, predicate),
21821 wrapped = _(array).takeWhile(predicate);
21823 assert.deepEqual(wrapped.value(), expected);
21824 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21825 assert.strictEqual(wrapped.last(), _.last(expected));
21828 skipAssert(assert, 3);
21832 QUnit.test('should work in a lazy sequence with `take`', function(assert) {
21836 var array = lodashStable.range(LARGE_ARRAY_SIZE);
21838 var actual = _(array)
21839 .takeWhile(function(n) { return n < 4; })
21841 .takeWhile(function(n) { return n == 0; })
21844 assert.deepEqual(actual, [0]);
21847 skipAssert(assert);
21851 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
21856 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21857 expected = [1, 0, lodashStable.map(array.slice(1), square)];
21859 _(array).slice(1).takeWhile(function(value, index, array) {
21860 args = slice.call(arguments);
21863 assert.deepEqual(args, [1, 0, array.slice(1)]);
21865 _(array).slice(1).map(square).takeWhile(function(value, index, array) {
21866 args = slice.call(arguments);
21869 assert.deepEqual(args, expected);
21871 _(array).slice(1).map(square).takeWhile(function(value, index) {
21872 args = slice.call(arguments);
21875 assert.deepEqual(args, expected);
21877 _(array).slice(1).map(square).takeWhile(function(value) {
21878 args = slice.call(arguments);
21881 assert.deepEqual(args, [1]);
21883 _(array).slice(1).map(square).takeWhile(function() {
21884 args = slice.call(arguments);
21887 assert.deepEqual(args, expected);
21890 skipAssert(assert, 5);
21895 /*--------------------------------------------------------------------------*/
21897 QUnit.module('lodash.tap');
21900 QUnit.test('should intercept and return the given value', function(assert) {
21907 var actual = _.tap(array, function(value) {
21908 intercepted = value;
21911 assert.strictEqual(actual, array);
21912 assert.strictEqual(intercepted, array);
21915 skipAssert(assert, 2);
21919 QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
21926 var wrapped = _(array).tap(function(value) {
21927 intercepted = value;
21931 assert.ok(wrapped instanceof _);
21934 assert.strictEqual(intercepted, array);
21937 skipAssert(assert, 2);
21942 /*--------------------------------------------------------------------------*/
21944 QUnit.module('lodash.template');
21947 QUnit.test('should escape values in "escape" delimiters', function(assert) {
21950 var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
21951 expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'`\/</p>')),
21952 data = { 'value': '&<>"\'`\/' };
21954 var actual = lodashStable.map(strings, function(string) {
21955 return _.template(string)(data);
21958 assert.deepEqual(actual, expected);
21961 QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
21964 var compiled = _.template('<%= typeof __e %>');
21965 assert.strictEqual(compiled({}), 'undefined');
21968 QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
21971 var compiled = _.template(
21973 for (var key in collection) {\
21974 %><li><%= collection[key] %></li><%\
21978 var data = { 'collection': { 'a': 'A', 'b': 'B' } },
21979 actual = compiled(data);
21981 assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
21984 QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
21987 var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
21988 data = { 'value': true };
21990 assert.strictEqual(compiled(data), 'yap');
21993 QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
21996 var compiled = _.template('<% var b = a; %><%= b.value %>'),
21997 data = { 'a': { 'value': 1 } };
21999 assert.strictEqual(compiled(data), '1');
22002 QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
22005 var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
22006 expected = lodashStable.map(strings, lodashStable.constant('ABC')),
22007 data = { 'a': 'A' };
22009 var actual = lodashStable.map(strings, function(string) {
22010 return _.template(string)(data);
22013 assert.deepEqual(actual, expected);
22016 QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
22019 var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
22020 data = { 'a': true };
22022 assert.strictEqual(compiled(data), 'a="A"');
22025 QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
22028 var compiled = _.template('<%= value ? value : "b" %>'),
22029 data = { 'value': 'a' };
22031 assert.strictEqual(compiled(data), 'a');
22034 QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
22037 var compiled = _.template('<%= typeof Math.abs %>');
22040 var actual = compiled();
22043 assert.strictEqual(actual, 'function');
22046 QUnit.test('should support complex "interpolate" delimiters', function(assert) {
22049 lodashStable.forOwn({
22050 '<%= a + b %>': '3',
22051 '<%= b - a %>': '1',
22052 '<%= a = b %>': '2',
22053 '<%= !a %>': 'false',
22055 '<%= a * b %>': '2',
22056 '<%= a / b %>': '0.5',
22057 '<%= a % b %>': '1',
22058 '<%= a >> b %>': '0',
22059 '<%= a << b %>': '4',
22060 '<%= a & b %>': '0',
22061 '<%= a ^ b %>': '3',
22062 '<%= a | b %>': '3',
22063 '<%= {}.toString.call(0) %>': numberTag,
22064 '<%= a.toFixed(2) %>': '1.00',
22065 '<%= obj["a"] %>': '1',
22066 '<%= delete a %>': 'true',
22067 '<%= "a" in obj %>': 'true',
22068 '<%= obj instanceof Object %>': 'true',
22069 '<%= new Boolean %>': 'false',
22070 '<%= typeof a %>': 'number',
22071 '<%= void a %>': ''
22073 function(value, key) {
22074 var compiled = _.template(key),
22075 data = { 'a': 1, 'b': 2 };
22077 assert.strictEqual(compiled(data), value, key);
22081 QUnit.test('should support ES6 template delimiters', function(assert) {
22084 var data = { 'value': 2 };
22085 assert.strictEqual(_.template('1${value}3')(data), '123');
22086 assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
22089 QUnit.test('should support the "imports" option', function(assert) {
22092 var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
22093 assert.strictEqual(compiled({}), '1');
22096 QUnit.test('should support the "variable" options', function(assert) {
22099 var compiled = _.template(
22100 '<% _.each( data.a, function( value ) { %>' +
22101 '<%= value.valueOf() %>' +
22102 '<% }) %>', { 'variable': 'data' }
22105 var data = { 'a': [1, 2, 3] };
22108 assert.strictEqual(compiled(data), '123');
22110 assert.ok(false, e.message);
22114 QUnit.test('should support custom delimiters', function(assert) {
22117 lodashStable.times(2, function(index) {
22118 var settingsClone = lodashStable.clone(_.templateSettings);
22120 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
22121 'escape': /\{\{-([\s\S]+?)\}\}/g,
22122 'evaluate': /\{\{([\s\S]+?)\}\}/g,
22123 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22126 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
22127 compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
22128 data = { 'collection': ['a & A', 'b & B'] };
22130 assert.strictEqual(compiled(data), expected);
22131 lodashStable.assign(_.templateSettings, settingsClone);
22135 QUnit.test('should support custom delimiters containing special characters', function(assert) {
22138 lodashStable.times(2, function(index) {
22139 var settingsClone = lodashStable.clone(_.templateSettings);
22141 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
22142 'escape': /<\?-([\s\S]+?)\?>/g,
22143 'evaluate': /<\?([\s\S]+?)\?>/g,
22144 'interpolate': /<\?=([\s\S]+?)\?>/g
22147 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
22148 compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
22149 data = { 'collection': ['a & A', 'b & B'] };
22151 assert.strictEqual(compiled(data), expected);
22152 lodashStable.assign(_.templateSettings, settingsClone);
22156 QUnit.test('should use a `with` statement by default', function(assert) {
22159 var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
22160 actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
22162 assert.strictEqual(actual, '1b012');
22165 QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
22168 var lodash = _.templateSettings.imports._,
22169 settingsClone = lodashStable.clone(lodash.templateSettings);
22171 lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
22172 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22175 var compiled = _.template('{{= a }}');
22176 assert.strictEqual(compiled({ 'a': 1 }), '1');
22178 if (settingsClone) {
22179 lodashStable.assign(lodash.templateSettings, settingsClone);
22181 delete lodash.templateSettings;
22185 QUnit.test('should fallback to `_.templateSettings`', function(assert) {
22188 var lodash = _.templateSettings.imports._,
22189 delimiter = _.templateSettings.interpolate;
22191 _.templateSettings.imports._ = { 'escape': lodashStable.escape };
22192 _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
22194 var compiled = _.template('{{= a }}');
22195 assert.strictEqual(compiled({ 'a': 1 }), '1');
22197 _.templateSettings.imports._ = lodash;
22198 _.templateSettings.interpolate = delimiter;
22201 QUnit.test('should ignore `null` delimiters', function(assert) {
22205 'escape': /\{\{-([\s\S]+?)\}\}/g,
22206 'evaluate': /\{\{([\s\S]+?)\}\}/g,
22207 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22210 lodashStable.forOwn({
22211 'escape': '{{- a }}',
22212 'evaluate': '{{ print(a) }}',
22213 'interpolate': '{{= a }}'
22215 function(value, key) {
22216 var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
22217 settings[key] = delimiter[key];
22219 var expected = '1 <%- a %> <% print(a) %> <%= a %>',
22220 compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
22223 assert.strictEqual(compiled(data), expected);
22227 QUnit.test('should work without delimiters', function(assert) {
22230 var expected = 'abc';
22231 assert.strictEqual(_.template(expected)({}), expected);
22234 QUnit.test('should work with `this` references', function(assert) {
22237 var compiled = _.template('a<%= this.String("b") %>c');
22238 assert.strictEqual(compiled(), 'abc');
22240 var object = { 'b': 'B' };
22241 object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
22242 assert.strictEqual(object.compiled(), 'ABC');
22245 QUnit.test('should work with backslashes', function(assert) {
22248 var compiled = _.template('<%= a %> \\b'),
22249 data = { 'a': 'A' };
22251 assert.strictEqual(compiled(data), 'A \\b');
22254 QUnit.test('should work with escaped characters in string literals', function(assert) {
22257 var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
22258 assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
22260 var data = { 'a': 'A' };
22261 compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
22262 assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
22265 QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
22268 var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
22269 assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
22272 QUnit.test('should work with statements containing quotes', function(assert) {
22275 var compiled = _.template("<%\
22276 if (a == 'A' || a == \"a\") {\
22281 var data = { 'a': 'A' };
22282 assert.strictEqual(compiled(data), "'a',\"A\"");
22285 QUnit.test('should work with templates containing newlines and comments', function(assert) {
22288 var compiled = _.template('<%\n\
22289 // A code comment.\n\
22290 if (value) { value += 3; }\n\
22291 %><p><%= value %></p>'
22294 assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
22297 QUnit.test('should not error with IE conditional comments enabled (test with development build)', function(assert) {
22300 var compiled = _.template(''),
22312 QUnit.test('should tokenize delimiters', function(assert) {
22315 var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
22316 data = { 'type': 1 };
22318 assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
22321 QUnit.test('should evaluate delimiters once', function(assert) {
22325 compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
22326 data = { 'func': function(value) { actual.push(value); } };
22329 assert.deepEqual(actual, ['a', 'b', 'c']);
22332 QUnit.test('should match delimiters before escaping text', function(assert) {
22335 var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
22336 assert.strictEqual(compiled(), '<<\n a \n>>');
22339 QUnit.test('should resolve nullish values to an empty string', function(assert) {
22342 var compiled = _.template('<%= a %><%- a %>'),
22343 data = { 'a': null };
22345 assert.strictEqual(compiled(data), '');
22347 data = { 'a': undefined };
22348 assert.strictEqual(compiled(data), '');
22350 data = { 'a': {} };
22351 compiled = _.template('<%= a.b %><%- a.b %>');
22352 assert.strictEqual(compiled(data), '');
22355 QUnit.test('should return an empty string for empty values', function(assert) {
22358 var values = [, null, undefined, ''],
22359 expected = lodashStable.map(values, stubString),
22362 var actual = lodashStable.map(values, function(value, index) {
22363 var compiled = index ? _.template(value) : _.template();
22364 return compiled(data);
22367 assert.deepEqual(actual, expected);
22370 QUnit.test('should parse delimiters without newlines', function(assert) {
22373 var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
22374 compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
22375 data = { 'value': true };
22377 assert.strictEqual(compiled(data), expected);
22380 QUnit.test('should support recursive calls', function(assert) {
22383 var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
22384 data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
22386 assert.strictEqual(compiled(data), 'AB');
22389 QUnit.test('should coerce `text` argument to a string', function(assert) {
22392 var object = { 'toString': lodashStable.constant('<%= a %>') },
22395 assert.strictEqual(_.template(object)(data), '1');
22398 QUnit.test('should not modify the `options` object', function(assert) {
22402 _.template('', options);
22403 assert.deepEqual(options, {});
22406 QUnit.test('should not modify `_.templateSettings` when `options` are given', function(assert) {
22409 var data = { 'a': 1 };
22411 assert.notOk('a' in _.templateSettings);
22412 _.template('', {}, data);
22413 assert.notOk('a' in _.templateSettings);
22415 delete _.templateSettings.a;
22418 QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
22428 assert.ok(pass, '`data` value');
22433 _.template('', 1)(1);
22437 assert.ok(pass, '`options` value');
22440 QUnit.test('should expose the source on compiled templates', function(assert) {
22443 var compiled = _.template('x'),
22444 values = [String(compiled), compiled.source],
22445 expected = lodashStable.map(values, stubTrue);
22447 var actual = lodashStable.map(values, function(value) {
22448 return lodashStable.includes(value, '__p');
22451 assert.deepEqual(actual, expected);
22454 QUnit.test('should expose the source on SyntaxErrors', function(assert) {
22458 _.template('<% if x %>');
22460 var source = e.source;
22462 assert.ok(lodashStable.includes(source, '__p'));
22465 QUnit.test('should not include sourceURLs in the source', function(assert) {
22468 var options = { 'sourceURL': '/a/b/c' },
22469 compiled = _.template('x', options),
22470 values = [compiled.source, undefined];
22473 _.template('<% if x %>', options);
22475 values[1] = e.source;
22477 var expected = lodashStable.map(values, stubFalse);
22479 var actual = lodashStable.map(values, function(value) {
22480 return lodashStable.includes(value, 'sourceURL');
22483 assert.deepEqual(actual, expected);
22486 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22489 var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
22490 compiles = lodashStable.map(array, _.template),
22491 data = { 'a': 'one', 'b': '`two`', 'c': 'three' };
22493 var actual = lodashStable.map(compiles, function(compiled) {
22494 return compiled(data);
22497 assert.deepEqual(actual, ['one', '`two`', 'three']);
22501 /*--------------------------------------------------------------------------*/
22503 QUnit.module('lodash.truncate');
22506 var string = 'hi-diddly-ho there, neighborino';
22508 QUnit.test('should use a default `length` of `30`', function(assert) {
22511 assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
22514 QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
22517 assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
22518 assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
22521 QUnit.test('should truncate string the given length', function(assert) {
22524 assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
22527 QUnit.test('should support a `omission` option', function(assert) {
22530 assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
22533 QUnit.test('should coerce nullish `omission` values to strings', function(assert) {
22536 assert.strictEqual(_.truncate(string, { 'omission': null }), 'hi-diddly-ho there, neighbnull');
22537 assert.strictEqual(_.truncate(string, { 'omission': undefined }), 'hi-diddly-ho there, nundefined');
22540 QUnit.test('should support a `length` option', function(assert) {
22543 assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
22546 QUnit.test('should support a `separator` option', function(assert) {
22549 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
22550 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
22551 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
22554 QUnit.test('should treat negative `length` as `0`', function(assert) {
22557 lodashStable.each([0, -2], function(length) {
22558 assert.strictEqual(_.truncate(string, { 'length': length }), '...');
22562 QUnit.test('should coerce `length` to an integer', function(assert) {
22565 lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
22566 var actual = index > 1 ? 'h...' : '...';
22567 assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
22571 QUnit.test('should coerce `string` to a string', function(assert) {
22574 assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
22575 assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
22578 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22581 var actual = lodashStable.map([string, string, string], _.truncate),
22582 truncated = 'hi-diddly-ho there, neighbo...';
22584 assert.deepEqual(actual, [truncated, truncated, truncated]);
22588 /*--------------------------------------------------------------------------*/
22590 QUnit.module('lodash.throttle');
22593 QUnit.test('should throttle a function', function(assert) {
22596 var done = assert.async();
22599 throttled = _.throttle(function() { callCount++; }, 32);
22605 var lastCount = callCount;
22606 assert.ok(callCount);
22608 setTimeout(function() {
22609 assert.ok(callCount > lastCount);
22614 QUnit.test('subsequent calls should return the result of the first call', function(assert) {
22617 var done = assert.async();
22619 var throttled = _.throttle(identity, 32),
22620 results = [throttled('a'), throttled('b')];
22622 assert.deepEqual(results, ['a', 'a']);
22624 setTimeout(function() {
22625 var results = [throttled('c'), throttled('d')];
22626 assert.notEqual(results[0], 'a');
22627 assert.notStrictEqual(results[0], undefined);
22629 assert.notEqual(results[1], 'd');
22630 assert.notStrictEqual(results[1], undefined);
22635 QUnit.test('should clear timeout when `func` is called', function(assert) {
22638 var done = assert.async();
22640 if (!isModularize) {
22644 var lodash = _.runInContext({
22646 'now': function() {
22647 return ++dateCount == 5 ? Infinity : +new Date;
22652 var throttled = lodash.throttle(function() { callCount++; }, 32);
22657 setTimeout(function() {
22658 assert.strictEqual(callCount, 2);
22663 skipAssert(assert);
22668 QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
22671 var done = assert.async();
22674 throttled = _.throttle(function() { callCount++; }, 32);
22677 assert.strictEqual(callCount, 1);
22679 setTimeout(function() {
22680 assert.strictEqual(callCount, 1);
22685 lodashStable.times(2, function(index) {
22686 QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
22689 var done = assert.async();
22692 limit = (argv || isPhantom) ? 1000 : 320,
22693 options = index ? { 'leading': false } : {},
22694 throttled = _.throttle(function() { callCount++; }, 32, options);
22696 var start = +new Date;
22697 while ((new Date - start) < limit) {
22700 var actual = callCount > 1;
22701 setTimeout(function() {
22708 QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
22711 var done = assert.async();
22715 var throttled = _.throttle(function() {
22717 }, 128, { 'leading': false });
22721 setTimeout(function() {
22722 assert.strictEqual(callCount, 1);
22726 setTimeout(function() {
22727 assert.strictEqual(callCount, 1);
22730 setTimeout(function() {
22731 assert.strictEqual(callCount, 2);
22736 QUnit.test('should apply default options', function(assert) {
22739 var done = assert.async();
22742 throttled = _.throttle(function() { callCount++; }, 32, {});
22746 assert.strictEqual(callCount, 1);
22748 setTimeout(function() {
22749 assert.strictEqual(callCount, 2);
22754 QUnit.test('should support a `leading` option', function(assert) {
22757 var withLeading = _.throttle(identity, 32, { 'leading': true });
22758 assert.strictEqual(withLeading('a'), 'a');
22760 var withoutLeading = _.throttle(identity, 32, { 'leading': false });
22761 assert.strictEqual(withoutLeading('a'), undefined);
22764 QUnit.test('should support a `trailing` option', function(assert) {
22767 var done = assert.async();
22772 var withTrailing = _.throttle(function(value) {
22775 }, 64, { 'trailing': true });
22777 var withoutTrailing = _.throttle(function(value) {
22780 }, 64, { 'trailing': false });
22782 assert.strictEqual(withTrailing('a'), 'a');
22783 assert.strictEqual(withTrailing('b'), 'a');
22785 assert.strictEqual(withoutTrailing('a'), 'a');
22786 assert.strictEqual(withoutTrailing('b'), 'a');
22788 setTimeout(function() {
22789 assert.strictEqual(withCount, 2);
22790 assert.strictEqual(withoutCount, 1);
22795 QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
22798 var done = assert.async();
22802 var throttled = _.throttle(function() {
22804 }, 64, { 'trailing': false });
22809 setTimeout(function() {
22814 setTimeout(function() {
22815 assert.ok(callCount > 1);
22820 QUnit.test('should work with a system time of `0`', function(assert) {
22823 var done = assert.async();
22825 if (!isModularize) {
22829 var lodash = _.runInContext({
22831 'now': function() {
22832 return ++dateCount < 4 ? 0 : +new Date;
22837 var throttled = lodash.throttle(function(value) {
22842 var results = [throttled('a'), throttled('b'), throttled('c')];
22843 assert.deepEqual(results, ['a', 'a', 'a']);
22844 assert.strictEqual(callCount, 1);
22846 setTimeout(function() {
22847 assert.strictEqual(callCount, 2);
22852 skipAssert(assert, 3);
22858 /*--------------------------------------------------------------------------*/
22860 QUnit.module('lodash.debounce and lodash.throttle');
22862 lodashStable.each(['debounce', 'throttle'], function(methodName) {
22863 var func = _[methodName],
22864 isDebounce = methodName == 'debounce';
22866 QUnit.test('`_.' + methodName + '` should not error for non-object `options` values', function(assert) {
22879 QUnit.test('`_.' + methodName + '` should use a default `wait` of `0`', function(assert) {
22882 var done = assert.async();
22885 funced = func(function() { callCount++; });
22889 setTimeout(function() {
22891 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22896 QUnit.test('`_.' + methodName + '` should invoke `func` with the correct `this` binding', function(assert) {
22899 var done = assert.async();
22902 object = { 'funced': func(function() { actual.push(this); }, 32) },
22903 expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
22909 setTimeout(function() {
22910 assert.deepEqual(actual, expected);
22915 QUnit.test('`_.' + methodName + '` supports recursive calls', function(assert) {
22918 var done = assert.async();
22921 args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
22922 expected = args.slice(),
22923 queue = args.slice();
22925 var funced = func(function() {
22926 var current = [this];
22927 push.apply(current, arguments);
22928 actual.push(current);
22930 var next = queue.shift();
22932 funced.call(next[0], next[1]);
22936 var next = queue.shift();
22937 funced.call(next[0], next[1]);
22938 assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
22940 setTimeout(function() {
22941 assert.deepEqual(actual, expected.slice(0, actual.length));
22946 QUnit.test('`_.' + methodName + '` should work if the system time is set backwards', function(assert) {
22949 var done = assert.async();
22951 if (!isModularize) {
22955 var lodash = _.runInContext({
22957 'now': function() {
22958 return ++dateCount == 4
22959 ? +new Date(2012, 3, 23, 23, 27, 18)
22965 var funced = lodash[methodName](function() {
22971 setTimeout(function() {
22973 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22978 skipAssert(assert);
22983 QUnit.test('`_.' + methodName + '` should support cancelling delayed calls', function(assert) {
22986 var done = assert.async();
22990 var funced = func(function() {
22992 }, 32, { 'leading': false });
22997 setTimeout(function() {
22998 assert.strictEqual(callCount, 0);
23003 QUnit.test('`_.' + methodName + '` should reset `lastCalled` after cancelling', function(assert) {
23006 var done = assert.async();
23010 var funced = func(function() {
23011 return ++callCount;
23012 }, 32, { 'leading': true });
23014 assert.strictEqual(funced(), 1);
23017 assert.strictEqual(funced(), 2);
23020 setTimeout(function() {
23021 assert.strictEqual(callCount, 3);
23026 QUnit.test('`_.' + methodName + '` should support flushing delayed calls', function(assert) {
23029 var done = assert.async();
23033 var funced = func(function() {
23034 return ++callCount;
23035 }, 32, { 'leading': false });
23038 assert.strictEqual(funced.flush(), 1);
23040 setTimeout(function() {
23041 assert.strictEqual(callCount, 1);
23046 QUnit.test('`_.' + methodName + '` should noop `cancel` and `flush` when nothing is queued', function(assert) {
23049 var done = assert.async();
23052 funced = func(function() { callCount++; }, 32);
23055 assert.strictEqual(funced.flush(), undefined);
23057 setTimeout(function() {
23058 assert.strictEqual(callCount, 0);
23064 /*--------------------------------------------------------------------------*/
23066 QUnit.module('lodash.times');
23069 QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
23072 lodashStable.each([-Infinity, NaN, Infinity], function(n) {
23073 assert.deepEqual(_.times(n), []);
23077 QUnit.test('should coerce `n` to an integer', function(assert) {
23080 var actual = _.times(2.6, _.indentify);
23081 assert.deepEqual(actual, [0, 1]);
23084 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
23089 _.times(1, function(assert) {
23090 args || (args = slice.call(arguments));
23093 assert.deepEqual(args, [0]);
23096 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
23099 var values = [, null, undefined],
23100 expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
23102 var actual = lodashStable.map(values, function(value, index) {
23103 return index ? _.times(3, value) : _.times(3);
23106 assert.deepEqual(actual, expected);
23109 QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
23112 assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
23115 QUnit.test('should return an empty array for falsey and negative `n` arguments', function(assert) {
23118 var values = falsey.concat(-1, -Infinity),
23119 expected = lodashStable.map(values, stubArray);
23121 var actual = lodashStable.map(values, function(value, index) {
23122 return index ? _.times(value) : _.times();
23125 assert.deepEqual(actual, expected);
23128 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
23132 assert.deepEqual(_(3).times(), [0, 1, 2]);
23135 skipAssert(assert);
23139 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
23143 assert.ok(_(3).chain().times() instanceof _);
23146 skipAssert(assert);
23151 /*--------------------------------------------------------------------------*/
23153 QUnit.module('lodash.toArray');
23156 QUnit.test('should convert objects to arrays', function(assert) {
23159 assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
23162 QUnit.test('should convert iterables to arrays', function(assert) {
23165 if (!isNpm && Symbol && Symbol.iterator) {
23166 var object = { '0': 'a', 'length': 1 };
23167 object[Symbol.iterator] = arrayProto[Symbol.iterator];
23169 assert.deepEqual(_.toArray(object), ['a']);
23172 skipAssert(assert);
23176 QUnit.test('should convert maps to arrays', function(assert) {
23183 assert.deepEqual(_.toArray(map), [['a', 1], ['b', 2]]);
23186 skipAssert(assert);
23190 QUnit.test('should convert strings to arrays', function(assert) {
23193 assert.deepEqual(_.toArray(''), []);
23194 assert.deepEqual(_.toArray('ab'), ['a', 'b']);
23195 assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
23198 QUnit.test('should work in a lazy sequence', function(assert) {
23202 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
23203 actual = _(array).slice(1).map(String).toArray().value();
23205 assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
23207 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
23208 return ['key' + index, index];
23211 actual = _(object).toArray().slice(1).map(String).value();
23212 assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
23215 skipAssert(assert, 2);
23220 /*--------------------------------------------------------------------------*/
23222 QUnit.module('lodash.toLower');
23225 QUnit.test('should convert whole string to lower case', function(assert) {
23228 assert.deepEqual(_.toLower('--Foo-Bar--'), '--foo-bar--');
23229 assert.deepEqual(_.toLower('fooBar'), 'foobar');
23230 assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
23234 /*--------------------------------------------------------------------------*/
23236 QUnit.module('lodash.toUpper');
23239 QUnit.test('should convert whole string to upper case', function(assert) {
23242 assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
23243 assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
23244 assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
23248 /*--------------------------------------------------------------------------*/
23250 QUnit.module('lodash.slice and lodash.toArray');
23252 lodashStable.each(['slice', 'toArray'], function(methodName) {
23253 var args = (function() { return arguments; }(1, 2, 3)),
23255 func = _[methodName];
23257 QUnit.test('`_.' + methodName + '` should return a dense array', function(assert) {
23260 var sparse = Array(3);
23263 var actual = func(sparse);
23265 assert.ok('0' in actual);
23266 assert.ok('2' in actual);
23267 assert.deepEqual(actual, sparse);
23270 QUnit.test('`_.' + methodName + '` should treat array-like objects like arrays', function(assert) {
23273 var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 };
23274 assert.deepEqual(func(object), ['a', 'b', 'c']);
23275 assert.deepEqual(func(args), array);
23278 QUnit.test('`_.' + methodName + '` should return a shallow clone of arrays', function(assert) {
23281 var actual = func(array);
23282 assert.deepEqual(actual, array);
23283 assert.notStrictEqual(actual, array);
23286 QUnit.test('`_.' + methodName + '` should work with a node list for `collection`', function(assert) {
23291 var actual = func(document.getElementsByTagName('body'));
23294 assert.deepEqual(actual, [body]);
23297 skipAssert(assert);
23302 /*--------------------------------------------------------------------------*/
23304 QUnit.module('toInteger methods');
23306 lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
23307 var func = _[methodName],
23308 isSafe = methodName == 'toSafeInteger';
23310 QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
23313 assert.strictEqual(func(-5.6), -5);
23314 assert.strictEqual(func('5.6'), 5);
23315 assert.strictEqual(func(), 0);
23316 assert.strictEqual(func(NaN), 0);
23318 var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
23319 assert.strictEqual(func(Infinity), expected);
23320 assert.strictEqual(func(-Infinity), -expected);
23323 QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
23326 assert.strictEqual(1 / func(-0), -Infinity);
23330 /*--------------------------------------------------------------------------*/
23332 QUnit.module('lodash.toLength');
23335 QUnit.test('should return a valid length', function(assert) {
23338 assert.strictEqual(_.toLength(-1), 0);
23339 assert.strictEqual(_.toLength('1'), 1);
23340 assert.strictEqual(_.toLength(1.1), 1);
23341 assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
23344 QUnit.test('should return `value` if a valid length', function(assert) {
23347 assert.strictEqual(_.toLength(0), 0);
23348 assert.strictEqual(_.toLength(3), 3);
23349 assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
23352 QUnit.test('should convert `-0` to `0`', function(assert) {
23355 assert.strictEqual(1 / _.toLength(-0), Infinity);
23359 /*--------------------------------------------------------------------------*/
23361 QUnit.module('number coercion methods');
23363 lodashStable.each(['toFinite', 'toInteger', 'toNumber', 'toSafeInteger'], function(methodName) {
23364 var func = _[methodName];
23366 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
23369 var values = [0, '0', -0, '-0'],
23370 expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
23372 lodashStable.times(2, function(index) {
23373 var others = lodashStable.map(values, index ? Object : identity);
23375 var actual = lodashStable.map(others, function(value) {
23376 var result = func(value);
23377 return [result, 1 / result];
23380 assert.deepEqual(actual, expected);
23385 lodashStable.each(['toFinite', 'toInteger', 'toLength', 'toNumber', 'toSafeInteger'], function(methodName) {
23386 var func = _[methodName],
23387 isToFinite = methodName == 'toFinite',
23388 isToLength = methodName == 'toLength',
23389 isToNumber = methodName == 'toNumber',
23390 isToSafeInteger = methodName == 'toSafeInteger';
23392 function negative(string) {
23393 return '-' + string;
23396 function pad(string) {
23397 return whitespace + string + whitespace;
23400 function positive(string) {
23401 return '+' + string;
23404 QUnit.test('`_.' + methodName + '` should pass thru primitive number values', function(assert) {
23407 var values = [0, 1, NaN];
23409 var expected = lodashStable.map(values, function(value) {
23410 return (!isToNumber && value !== value) ? 0 : value;
23413 var actual = lodashStable.map(values, func);
23415 assert.deepEqual(actual, expected);
23418 QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
23421 var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
23423 var expected = lodashStable.map(values, function(value) {
23425 if (!isToFinite && value == 1.2) {
23428 else if (value == Infinity) {
23429 value = MAX_INTEGER;
23431 else if (value !== value) {
23434 if (isToLength || isToSafeInteger) {
23435 value = Math.min(value, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
23438 var neg = isToLength ? 0 : -value;
23439 return [value, value, neg, neg];
23442 var actual = lodashStable.map(values, function(value) {
23443 return [func(value), func(Object(value)), func(-value), func(Object(-value))];
23446 assert.deepEqual(actual, expected);
23449 QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
23452 var transforms = [identity, pad, positive, negative];
23455 '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
23456 '1e+308', '1e308', '1E+308', '1E308',
23457 '5e-324', '5E-324',
23461 var expected = lodashStable.map(values, function(value) {
23464 if (!isToFinite && n == 1.234567890) {
23467 else if (n == Infinity) {
23470 else if ((!isToFinite && n == Number.MIN_VALUE) || n !== n) {
23473 if (isToLength || isToSafeInteger) {
23474 n = Math.min(n, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
23477 var neg = isToLength ? 0 : -n;
23478 return [n, n, n, n, n, n, neg, neg];
23481 var actual = lodashStable.map(values, function(value) {
23482 return lodashStable.flatMap(transforms, function(mod) {
23483 return [func(mod(value)), func(Object(mod(value)))];
23487 assert.deepEqual(actual, expected);
23490 QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
23493 var numbers = [42, 5349, 1715004],
23494 transforms = [identity, pad],
23495 values = ['0b101010', '0o12345', '0x1a2b3c'];
23497 var expected = lodashStable.map(numbers, function(n) {
23498 return lodashStable.times(8, lodashStable.constant(n));
23501 var actual = lodashStable.map(values, function(value) {
23502 var upper = value.toUpperCase();
23503 return lodashStable.flatMap(transforms, function(mod) {
23504 return [func(mod(value)), func(Object(mod(value))), func(mod(upper)), func(Object(mod(upper)))];
23508 assert.deepEqual(actual, expected);
23511 QUnit.test('`_.' + methodName + '` should convert invalid binary/octal strings to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23514 var transforms = [identity, pad, positive, negative],
23515 values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
23517 var expected = lodashStable.map(values, function(n) {
23518 return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
23521 var actual = lodashStable.map(values, function(value) {
23522 return lodashStable.flatMap(transforms, function(mod) {
23523 return [func(mod(value)), func(Object(mod(value)))];
23527 assert.deepEqual(actual, expected);
23530 QUnit.test('`_.' + methodName + '` should convert symbols to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23534 var object1 = Object(symbol),
23535 object2 = Object(symbol),
23536 values = [symbol, object1, object2],
23537 expected = lodashStable.map(values, lodashStable.constant(isToNumber ? NaN : 0));
23539 object2.valueOf = undefined;
23540 var actual = lodashStable.map(values, func);
23542 assert.deepEqual(actual, expected);
23545 skipAssert(assert);
23549 QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
23552 var values = falsey.concat(whitespace);
23554 var expected = lodashStable.map(values, function(value) {
23555 return (isToNumber && value !== whitespace) ? Number(value) : 0;
23558 var actual = lodashStable.map(values, function(value, index) {
23559 return index ? func(value) : func();
23562 assert.deepEqual(actual, expected);
23565 QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
23573 { 'valueOf': '1.1' },
23574 { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
23575 { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
23576 { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
23577 { 'valueOf': lodashStable.constant('-0x1a2b3c') },
23578 { 'toString': lodashStable.constant('-0x1a2b3c') },
23579 { 'valueOf': lodashStable.constant('0o12345') },
23580 { 'toString': lodashStable.constant('0o12345') },
23581 { 'valueOf': lodashStable.constant('0b101010') },
23582 { 'toString': lodashStable.constant('0b101010') }
23587 NaN, 2.2, 1.1, 1.1,
23602 else if (!isToNumber) {
23611 var actual = lodashStable.map(values, func);
23613 assert.deepEqual(actual, expected);
23617 /*--------------------------------------------------------------------------*/
23619 QUnit.module('lodash.toPairs');
23622 QUnit.test('should be aliased', function(assert) {
23625 assert.strictEqual(_.entries, _.toPairs);
23629 /*--------------------------------------------------------------------------*/
23631 QUnit.module('lodash.toPairsIn');
23634 QUnit.test('should be aliased', function(assert) {
23637 assert.strictEqual(_.entriesIn, _.toPairsIn);
23641 /*--------------------------------------------------------------------------*/
23643 QUnit.module('toPairs methods');
23645 lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) {
23646 var func = _[methodName],
23647 isToPairs = methodName == 'toPairs';
23649 QUnit.test('`_.' + methodName + '` should create an array of string keyed-value pairs', function(assert) {
23652 var object = { 'a': 1, 'b': 2 },
23653 actual = lodashStable.sortBy(func(object), 0);
23655 assert.deepEqual(actual, [['a', 1], ['b', 2]]);
23658 QUnit.test('`_.' + methodName + '` should ' + (isToPairs ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
23664 Foo.prototype.b = 2;
23666 var expected = isToPairs ? [['a', 1]] : [['a', 1], ['b', 2]],
23667 actual = lodashStable.sortBy(func(new Foo), 0);
23669 assert.deepEqual(actual, expected);
23672 QUnit.test('`_.' + methodName + '` should convert objects with a `length` property', function(assert) {
23675 var object = { '0': 'a', '1': 'b', 'length': 2 },
23676 actual = lodashStable.sortBy(func(object), 0);
23678 assert.deepEqual(actual, [['0', 'a'], ['1', 'b'], ['length', 2]]);
23681 QUnit.test('`_.' + methodName + '` should convert maps', function(assert) {
23688 assert.deepEqual(func(map), [['a', 1], ['b', 2]]);
23691 skipAssert(assert);
23695 QUnit.test('`_.' + methodName + '` should convert sets', function(assert) {
23702 assert.deepEqual(func(set), [[1, 1], [2, 2]]);
23705 skipAssert(assert);
23709 QUnit.test('`_.' + methodName + '` should convert strings', function(assert) {
23712 lodashStable.each(['xo', Object('xo')], function(string) {
23713 var actual = lodashStable.sortBy(func(string), 0);
23714 assert.deepEqual(actual, [['0', 'x'], ['1', 'o']]);
23719 /*--------------------------------------------------------------------------*/
23721 QUnit.module('lodash.toPath');
23724 QUnit.test('should convert a string to a path', function(assert) {
23727 assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
23728 assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
23731 QUnit.test('should coerce array elements to strings', function(assert) {
23734 var array = ['a', 'b', 'c'];
23736 lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
23737 var actual = _.toPath(value);
23738 assert.deepEqual(actual, array);
23739 assert.notStrictEqual(actual, array);
23743 QUnit.test('should a new path array', function(assert) {
23746 assert.notStrictEqual(_.toPath('a.b.c'), _.toPath('a.b.c'));
23749 QUnit.test('should not coerce symbols to strings', function(assert) {
23753 var object = Object(symbol);
23754 lodashStable.each([symbol, object, [symbol], [object]], function(value) {
23755 var actual = _.toPath(value);
23756 assert.ok(lodashStable.isSymbol(actual[0]));
23760 skipAssert(assert, 4);
23764 QUnit.test('should handle complex paths', function(assert) {
23767 var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
23768 assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
23771 QUnit.test('should not ignore consecutive brackets and dots', function(assert) {
23774 var expected = ['a', ''];
23775 assert.deepEqual(_.toPath('a.'), expected);
23776 assert.deepEqual(_.toPath('a[]'), expected);
23778 expected = ['a', '', 'b'];
23779 assert.deepEqual(_.toPath('a..b'), expected);
23780 assert.deepEqual(_.toPath('a[][]b'), expected);
23784 /*--------------------------------------------------------------------------*/
23786 QUnit.module('lodash.toPlainObject');
23789 var args = arguments;
23791 QUnit.test('should flatten inherited string keyed properties', function(assert) {
23797 Foo.prototype.c = 3;
23799 var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
23800 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
23803 QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
23806 var actual = _.toPlainObject(args),
23807 expected = { '0': 1, '1': 2, '2': 3 };
23809 assert.deepEqual(actual, expected);
23812 QUnit.test('should convert arrays to plain objects', function(assert) {
23815 var actual = _.toPlainObject(['a', 'b', 'c']),
23816 expected = { '0': 'a', '1': 'b', '2': 'c' };
23818 assert.deepEqual(actual, expected);
23822 /*--------------------------------------------------------------------------*/
23824 QUnit.module('lodash.toString');
23827 QUnit.test('should treat nullish values as empty strings', function(assert) {
23830 var values = [, null, undefined],
23831 expected = lodashStable.map(values, stubString);
23833 var actual = lodashStable.map(values, function(value, index) {
23834 return index ? _.toString(value) : _.toString();
23837 assert.deepEqual(actual, expected);
23840 QUnit.test('should preserve the sign of `0`', function(assert) {
23843 var values = [-0, Object(-0), 0, Object(0)],
23844 expected = ['-0', '-0', '0', '0'],
23845 actual = lodashStable.map(values, _.toString);
23847 assert.deepEqual(actual, expected);
23850 QUnit.test('should not error on symbols', function(assert) {
23855 assert.strictEqual(_.toString(symbol), 'Symbol(a)');
23857 assert.ok(false, e.message);
23861 skipAssert(assert);
23865 QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
23869 var wrapped = _([1, 2, 3]);
23870 assert.strictEqual(wrapped.toString(), '1,2,3');
23873 skipAssert(assert);
23878 /*--------------------------------------------------------------------------*/
23880 QUnit.module('lodash.transform');
23889 QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
23892 var accumulators = [, null, undefined],
23894 expected = lodashStable.map(accumulators, stubTrue);
23896 var iteratee = function(result, value, key) {
23897 result[key] = square(value);
23900 var mapper = function(accumulator, index) {
23901 return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
23904 var results = lodashStable.map(accumulators, mapper);
23906 var actual = lodashStable.map(results, function(result) {
23907 return result instanceof Foo;
23910 assert.deepEqual(actual, expected);
23912 expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
23913 actual = lodashStable.map(results, lodashStable.toPlainObject);
23915 assert.deepEqual(actual, expected);
23917 object = { 'a': 1, 'b': 2, 'c': 3 };
23918 actual = lodashStable.map(accumulators, mapper);
23920 assert.deepEqual(actual, expected);
23922 object = [1, 2, 3];
23923 expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
23924 actual = lodashStable.map(accumulators, mapper);
23926 assert.deepEqual(actual, expected);
23929 QUnit.test('should create regular arrays from typed arrays', function(assert) {
23932 var expected = lodashStable.map(typedArrays, stubTrue);
23934 var actual = lodashStable.map(typedArrays, function(type) {
23935 var Ctor = root[type],
23936 array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
23938 return lodashStable.isArray(_.transform(array, noop));
23941 assert.deepEqual(actual, expected);
23944 QUnit.test('should support an `accumulator` value', function(assert) {
23947 var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
23948 expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
23950 var actual = lodashStable.map(values, function(value) {
23951 return _.transform(value, function(result, value) {
23952 result.push(square(value));
23956 assert.deepEqual(actual, expected);
23958 var object = { 'a': 1, 'b': 4, 'c': 9 },
23959 expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
23961 actual = lodashStable.map(values, function(value) {
23962 return _.transform(value, function(result, value, key) {
23963 result[key] = square(value);
23967 assert.deepEqual(actual, expected);
23969 lodashStable.each([[], {}], function(accumulator) {
23970 var actual = lodashStable.map(values, function(value) {
23971 return _.transform(value, noop, accumulator);
23974 assert.ok(lodashStable.every(actual, function(result) {
23975 return result === accumulator;
23978 assert.strictEqual(_.transform(null, null, accumulator), accumulator);
23982 QUnit.test('should treat sparse arrays as dense', function(assert) {
23985 var actual = _.transform(Array(1), function(result, value, index) {
23986 result[index] = String(value);
23989 assert.deepEqual(actual, ['undefined']);
23992 QUnit.test('should work without an `iteratee` argument', function(assert) {
23995 assert.ok(_.transform(new Foo) instanceof Foo);
23998 QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
24001 var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
24002 values = [false, true, 0, 1, NaN, '', 'a'],
24003 expected = lodashStable.map(values, stubObject);
24005 var results = lodashStable.map(values, function(value) {
24006 return _.transform(value);
24009 assert.deepEqual(results, expected);
24011 expected = lodashStable.map(values, stubFalse);
24013 var actual = lodashStable.map(results, function(value, index) {
24014 return value instanceof Ctors[index];
24017 assert.deepEqual(actual, expected);
24020 QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
24023 Foo.prototype.constructor = null;
24024 assert.notOk(_.transform(new Foo) instanceof Foo);
24025 Foo.prototype.constructor = Foo;
24028 QUnit.test('should create an empty object when given a falsey `object` argument', function(assert) {
24031 var expected = lodashStable.map(falsey, stubObject);
24033 var actual = lodashStable.map(falsey, function(object, index) {
24034 return index ? _.transform(object) : _.transform();
24037 assert.deepEqual(actual, expected);
24040 lodashStable.each({
24041 'array': [1, 2, 3],
24042 'object': { 'a': 1, 'b': 2, 'c': 3 }
24044 function(object, key) {
24045 QUnit.test('should provide the correct `iteratee` arguments when transforming an ' + key, function(assert) {
24050 _.transform(object, function() {
24051 args || (args = slice.call(arguments));
24054 var first = args[0];
24055 if (key == 'array') {
24056 assert.ok(first !== object && lodashStable.isArray(first));
24057 assert.deepEqual(args, [first, 1, 0, object]);
24059 assert.ok(first !== object && lodashStable.isPlainObject(first));
24060 assert.deepEqual(args, [first, 1, 'a', object]);
24065 QUnit.test('should create an object from the same realm as `object`', function(assert) {
24068 var objects = lodashStable.filter(realm, function(value) {
24069 return lodashStable.isObject(value) && !lodashStable.isElement(value);
24072 var expected = lodashStable.map(objects, stubTrue);
24074 var actual = lodashStable.map(objects, function(object) {
24075 var Ctor = object.constructor,
24076 result = _.transform(object);
24078 if (result === object) {
24081 if (lodashStable.isTypedArray(object)) {
24082 return result instanceof Array;
24084 return result instanceof Ctor || !(new Ctor instanceof Ctor);
24087 assert.deepEqual(actual, expected);
24091 /*--------------------------------------------------------------------------*/
24093 QUnit.module('trim methods');
24095 lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
24096 var func = _[methodName],
24100 parts.push('leading');
24103 parts.push('trailing');
24105 parts = parts.join(' and ');
24107 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
24110 var string = whitespace + 'a b c' + whitespace,
24111 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24113 assert.strictEqual(func(string), expected);
24116 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
24119 var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
24120 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24122 assert.strictEqual(func(object), expected);
24125 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
24128 var string = '-_-a-b-c-_-',
24129 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
24131 assert.strictEqual(func(string, '_-'), expected);
24134 QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
24137 var object = { 'toString': lodashStable.constant('_-') },
24138 string = '-_-a-b-c-_-',
24139 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
24141 assert.strictEqual(func(string, object), expected);
24144 QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
24147 lodashStable.each([null, '_-'], function(chars) {
24148 assert.strictEqual(func(null, chars), '');
24149 assert.strictEqual(func(undefined, chars), '');
24150 assert.strictEqual(func('', chars), '');
24154 QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
24157 var string = whitespace + 'a b c' + whitespace,
24158 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24160 assert.strictEqual(func(string, undefined), expected);
24161 assert.strictEqual(func(string, ''), string);
24164 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
24167 var string = Object(whitespace + 'a b c' + whitespace),
24168 trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
24169 actual = lodashStable.map([string, string, string], func);
24171 assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
24174 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
24178 var string = whitespace + 'a b c' + whitespace,
24179 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24181 assert.strictEqual(_(string)[methodName](), expected);
24184 skipAssert(assert);
24188 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
24192 var string = whitespace + 'a b c' + whitespace;
24193 assert.ok(_(string).chain()[methodName]() instanceof _);
24196 skipAssert(assert);
24201 /*--------------------------------------------------------------------------*/
24203 QUnit.module('uncommon symbols');
24206 var flag = '\ud83c\uddfa\ud83c\uddf8',
24207 heart = '\u2764' + emojiVar,
24208 hearts = '\ud83d\udc95',
24209 comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68',
24210 hashKeycap = '#' + emojiVar + '\u20e3',
24211 leafs = '\ud83c\udf42',
24212 mic = '\ud83c\udf99',
24213 noMic = mic + '\u20e0',
24214 raisedHand = '\u270B' + emojiVar,
24215 rocket = '\ud83d\ude80',
24216 thumbsUp = '\ud83d\udc4d';
24218 QUnit.test('should account for astral symbols', function(assert) {
24221 var allHearts = _.repeat(hearts, 10),
24222 chars = hearts + comboGlyph,
24223 string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
24224 trimChars = comboGlyph + hearts,
24225 trimString = trimChars + string + trimChars;
24227 assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
24228 assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
24229 assert.strictEqual(_.capitalize(rocket), rocket);
24231 assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
24232 assert.strictEqual(_.padStart(string, 16), ' ' + string);
24233 assert.strictEqual(_.padEnd(string, 16), string + ' ');
24235 assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
24236 assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
24237 assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
24239 assert.strictEqual(_.size(string), 13);
24240 assert.deepEqual(_.split(string, ' '), ['A', leafs + ',', comboGlyph + ',', 'and', rocket]);
24241 assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
24242 assert.deepEqual(_.split(string, undefined), [string]);
24243 assert.deepEqual(_.split(string, undefined, -1), [string]);
24244 assert.deepEqual(_.split(string, undefined, 0), []);
24246 var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];
24248 assert.deepEqual(_.split(string, ''), expected);
24249 assert.deepEqual(_.split(string, '', 6), expected.slice(0, 6));
24250 assert.deepEqual(_.toArray(string), expected);
24252 assert.strictEqual(_.trim(trimString, chars), string);
24253 assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
24254 assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
24256 assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
24257 assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
24259 assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
24260 assert.deepEqual(_.toArray(hashKeycap), [hashKeycap]);
24261 assert.deepEqual(_.toArray(noMic), [noMic]);
24263 lodashStable.times(2, function(index) {
24264 var separator = index ? RegExp(hearts) : hearts,
24265 options = { 'length': 4, 'separator': separator },
24266 actual = _.truncate(string, options);
24268 assert.strictEqual(actual, 'A...');
24269 assert.strictEqual(actual.length, 4);
24271 actual = _.truncate(allHearts, options);
24272 assert.strictEqual(actual, hearts + '...');
24273 assert.strictEqual(actual.length, 5);
24277 QUnit.test('should account for combining diacritical marks', function(assert) {
24280 var values = lodashStable.map(comboMarks, function(mark) {
24284 var expected = lodashStable.map(values, function(value) {
24285 return [1, [value], [value]];
24288 var actual = lodashStable.map(values, function(value) {
24289 return [_.size(value), _.toArray(value), _.words(value)];
24292 assert.deepEqual(actual, expected);
24295 QUnit.test('should account for fitzpatrick modifiers', function(assert) {
24298 var values = lodashStable.map(fitzModifiers, function(modifier) {
24299 return thumbsUp + modifier;
24302 var expected = lodashStable.map(values, function(value) {
24303 return [1, [value], [value]];
24306 var actual = lodashStable.map(values, function(value) {
24307 return [_.size(value), _.toArray(value), _.words(value)];
24310 assert.deepEqual(actual, expected);
24313 QUnit.test('should account for regional symbols', function(assert) {
24316 var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
24317 regionals = pair.join(' ');
24319 assert.strictEqual(_.size(flag), 1);
24320 assert.strictEqual(_.size(regionals), 3);
24322 assert.deepEqual(_.toArray(flag), [flag]);
24323 assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
24325 assert.deepEqual(_.words(flag), [flag]);
24326 assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
24329 QUnit.test('should account for variation selectors', function(assert) {
24332 assert.strictEqual(_.size(heart), 1);
24333 assert.deepEqual(_.toArray(heart), [heart]);
24334 assert.deepEqual(_.words(heart), [heart]);
24337 QUnit.test('should account for variation selectors with fitzpatrick modifiers', function(assert) {
24340 var values = lodashStable.map(fitzModifiers, function(modifier) {
24341 return raisedHand + modifier;
24344 var expected = lodashStable.map(values, function(value) {
24345 return [1, [value], [value]];
24348 var actual = lodashStable.map(values, function(value) {
24349 return [_.size(value), _.toArray(value), _.words(value)];
24352 assert.deepEqual(actual, expected);
24355 QUnit.test('should match lone surrogates', function(assert) {
24358 var pair = hearts.split(''),
24359 surrogates = pair[0] + ' ' + pair[1];
24361 assert.strictEqual(_.size(surrogates), 3);
24362 assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
24363 assert.deepEqual(_.words(surrogates), []);
24366 QUnit.test('should match side by side fitzpatrick modifiers separately ', function(assert) {
24369 var string = fitzModifiers[0] + fitzModifiers[0];
24370 assert.deepEqual(_.toArray(string), [fitzModifiers[0], fitzModifiers[0]]);
24374 /*--------------------------------------------------------------------------*/
24376 QUnit.module('lodash.unary');
24380 return slice.call(arguments);
24383 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
24386 var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
24387 assert.deepEqual(actual, [6, 8, 10]);
24390 QUnit.test('should work when provided less than the capped number of arguments', function(assert) {
24393 var capped = _.unary(fn);
24394 assert.deepEqual(capped(), []);
24398 /*--------------------------------------------------------------------------*/
24400 QUnit.module('lodash.unescape');
24403 var escaped = '&<>"'\/',
24404 unescaped = '&<>"\'\/';
24406 escaped += escaped;
24407 unescaped += unescaped;
24409 QUnit.test('should unescape entities in order', function(assert) {
24412 assert.strictEqual(_.unescape('&lt;'), '<');
24415 QUnit.test('should unescape the proper entities', function(assert) {
24418 assert.strictEqual(_.unescape(escaped), unescaped);
24421 QUnit.test('should not unescape the "/" entity', function(assert) {
24424 assert.strictEqual(_.unescape('/'), '/');
24427 QUnit.test('should handle strings with nothing to unescape', function(assert) {
24430 assert.strictEqual(_.unescape('abc'), 'abc');
24433 QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
24436 assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
24440 /*--------------------------------------------------------------------------*/
24442 QUnit.module('union methods');
24444 lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
24445 var args = (function() { return arguments; }(1, 2, 3)),
24446 func = _[methodName];
24448 QUnit.test('`_.' + methodName + '` should return the union of two arrays', function(assert) {
24451 var actual = func([2], [1, 2]);
24452 assert.deepEqual(actual, [2, 1]);
24455 QUnit.test('`_.' + methodName + '` should return the union of multiple arrays', function(assert) {
24458 var actual = func([2], [1, 2], [2, 3]);
24459 assert.deepEqual(actual, [2, 1, 3]);
24462 QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
24465 var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
24466 assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
24469 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
24473 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
24474 assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
24475 assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
24479 /*--------------------------------------------------------------------------*/
24481 QUnit.module('lodash.unionBy');
24484 QUnit.test('should accept an `iteratee` argument', function(assert) {
24487 var actual = _.unionBy([2.1], [1.2, 2.3], Math.floor);
24488 assert.deepEqual(actual, [2.1, 1.2]);
24490 actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
24491 assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
24494 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
24499 _.unionBy([2.1], [1.2, 2.3], function() {
24500 args || (args = slice.call(arguments));
24503 assert.deepEqual(args, [2.1]);
24507 /*--------------------------------------------------------------------------*/
24509 QUnit.module('lodash.unionWith');
24512 QUnit.test('should work with a `comparator` argument', function(assert) {
24515 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
24516 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
24517 actual = _.unionWith(objects, others, lodashStable.isEqual);
24519 assert.deepEqual(actual, [objects[0], objects[1], others[0]]);
24523 /*--------------------------------------------------------------------------*/
24525 QUnit.module('uniq methods');
24527 lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
24528 var func = _[methodName],
24529 isSorted = /^sorted/.test(methodName),
24530 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24533 objects = _.sortBy(objects, 'a');
24536 QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
24539 var array = [2, 1, 2];
24540 assert.deepEqual(func(array), [2, 1]);
24543 QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
24546 var array = [1, 2, 2];
24547 assert.deepEqual(func(array), [1, 2]);
24550 QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
24553 assert.deepEqual(func(objects), objects);
24556 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
24559 var actual = lodashStable.map(func([-0, 0]), lodashStable.toString);
24560 assert.deepEqual(actual, ['0']);
24563 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
24566 assert.deepEqual(func([NaN, NaN]), [NaN]);
24569 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
24572 var largeArray = [],
24573 expected = [0, {}, 'a'],
24574 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24576 lodashStable.each(expected, function(value) {
24577 lodashStable.times(count, function() {
24578 largeArray.push(value);
24582 assert.deepEqual(func(largeArray), expected);
24585 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
24588 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24589 return isEven(index) ? -0 : 0;
24592 var actual = lodashStable.map(func(largeArray), lodashStable.toString);
24593 assert.deepEqual(actual, ['0']);
24596 QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
24599 var largeArray = [],
24600 expected = [null, undefined, false, true, NaN],
24601 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24603 lodashStable.each(expected, function(value) {
24604 lodashStable.times(count, function() {
24605 largeArray.push(value);
24609 assert.deepEqual(func(largeArray), expected);
24612 QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
24616 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
24617 assert.deepEqual(func(largeArray), largeArray);
24620 skipAssert(assert);
24624 QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
24627 // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
24630 Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
24631 Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
24632 Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
24635 var largeArray = [],
24636 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24638 expected = lodashStable.map(expected, function(symbol) {
24639 return symbol || {};
24642 lodashStable.each(expected, function(value) {
24643 lodashStable.times(count, function() {
24644 largeArray.push(value);
24648 assert.deepEqual(func(largeArray), expected);
24651 skipAssert(assert);
24655 QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
24658 var largeArray = [],
24659 expected = ['2', 2, Object('2'), Object(2)],
24660 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24662 lodashStable.each(expected, function(value) {
24663 lodashStable.times(count, function() {
24664 largeArray.push(value);
24668 assert.deepEqual(func(largeArray), expected);
24672 /*--------------------------------------------------------------------------*/
24674 QUnit.module('lodash.uniq');
24677 QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
24680 var array = [[2, 1, 2], [1, 2, 1]],
24681 actual = lodashStable.map(array, lodashStable.uniq);
24683 assert.deepEqual(actual, [[2, 1], [1, 2]]);
24687 /*--------------------------------------------------------------------------*/
24689 QUnit.module('uniqBy methods');
24691 lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
24692 var func = _[methodName],
24693 isSorted = methodName == 'sortedUniqBy',
24694 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24697 objects = _.sortBy(objects, 'a');
24699 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
24702 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
24704 var actual = func(objects, function(object) {
24708 assert.deepEqual(actual, expected);
24711 QUnit.test('should work with large arrays', function(assert) {
24714 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
24718 var actual = func(largeArray, String);
24719 assert.strictEqual(actual[0], largeArray[0]);
24720 assert.deepEqual(actual, [[1, 2]]);
24723 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
24728 func(objects, function() {
24729 args || (args = slice.call(arguments));
24732 assert.deepEqual(args, [objects[0]]);
24735 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
24738 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
24739 actual = func(objects, 'a');
24741 assert.deepEqual(actual, expected);
24743 var arrays = [[2], [3], [1], [2], [3], [1]];
24745 arrays = lodashStable.sortBy(arrays, 0);
24747 expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
24748 actual = func(arrays, 0);
24750 assert.deepEqual(actual, expected);
24753 lodashStable.each({
24754 'an array': [0, 'a'],
24755 'an object': { '0': 'a' },
24759 function(iteratee, key) {
24760 QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
24763 var actual = func([['a'], ['a'], ['b']], iteratee);
24764 assert.deepEqual(actual, [['a'], ['b']]);
24769 /*--------------------------------------------------------------------------*/
24771 QUnit.module('lodash.uniqWith');
24774 QUnit.test('should work with a `comparator` argument', function(assert) {
24777 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }],
24778 actual = _.uniqWith(objects, lodashStable.isEqual);
24780 assert.deepEqual(actual, [objects[0], objects[1]]);
24783 QUnit.test('should preserve the sign of `0`', function(assert) {
24786 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24787 return isEven(index) ? -0 : 0;
24790 var arrays = [[-0, 0], largeArray],
24791 expected = lodashStable.map(arrays, lodashStable.constant(['-0']));
24793 var actual = lodashStable.map(arrays, function(array) {
24794 return lodashStable.map(_.uniqWith(array, lodashStable.eq), lodashStable.toString);
24797 assert.deepEqual(actual, expected);
24801 /*--------------------------------------------------------------------------*/
24803 QUnit.module('lodash.uniqueId');
24806 QUnit.test('should generate unique ids', function(assert) {
24809 var actual = lodashStable.times(1000, function(assert) {
24810 return _.uniqueId();
24813 assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
24816 QUnit.test('should return a string value when not providing a prefix argument', function(assert) {
24819 assert.strictEqual(typeof _.uniqueId(), 'string');
24822 QUnit.test('should coerce the prefix argument to a string', function(assert) {
24825 var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
24826 assert.ok(/3\d+,2\d+,1\d+/.test(actual));
24830 /*--------------------------------------------------------------------------*/
24832 QUnit.module('lodash.unset');
24835 QUnit.test('should unset property values', function(assert) {
24838 lodashStable.each(['a', ['a']], function(path) {
24839 var object = { 'a': 1, 'c': 2 };
24840 assert.strictEqual(_.unset(object, path), true);
24841 assert.deepEqual(object, { 'c': 2 });
24845 QUnit.test('should preserve the sign of `0`', function(assert) {
24848 var props = [-0, Object(-0), 0, Object(0)],
24849 expected = lodashStable.map(props, lodashStable.constant([true, false]));
24851 var actual = lodashStable.map(props, function(key) {
24852 var object = { '-0': 'a', '0': 'b' };
24853 return [_.unset(object, key), lodashStable.toString(key) in object];
24856 assert.deepEqual(actual, expected);
24859 QUnit.test('should unset symbol keyed property values', function(assert) {
24864 object[symbol] = 1;
24866 assert.strictEqual(_.unset(object, symbol), true);
24867 assert.notOk(symbol in object);
24870 skipAssert(assert, 2);
24874 QUnit.test('should unset deep property values', function(assert) {
24877 lodashStable.each(['a.b', ['a', 'b']], function(path) {
24878 var object = { 'a': { 'b': null } };
24879 assert.strictEqual(_.unset(object, path), true);
24880 assert.deepEqual(object, { 'a': {} });
24884 QUnit.test('should handle complex paths', function(assert) {
24888 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
24889 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
24892 lodashStable.each(paths, function(path) {
24893 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
24894 assert.strictEqual(_.unset(object, path), true);
24895 assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
24899 QUnit.test('should return `true` for nonexistent paths', function(assert) {
24902 var object = { 'a': { 'b': { 'c': null } } };
24904 lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
24905 assert.strictEqual(_.unset(object, path), true);
24908 assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
24911 QUnit.test('should not error when `object` is nullish', function(assert) {
24914 var values = [null, undefined],
24915 expected = [[true, true], [true, true]];
24917 var actual = lodashStable.map(values, function(value) {
24919 return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
24925 assert.deepEqual(actual, expected);
24928 QUnit.test('should follow `path` over non-plain objects', function(assert) {
24931 var object = { 'a': '' },
24932 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
24934 lodashStable.each(paths, function(path) {
24937 var actual = _.unset(0, path);
24938 assert.strictEqual(actual, true);
24939 assert.notOk('a' in numberProto);
24941 delete numberProto.a;
24944 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
24945 stringProto.replace.b = 1;
24947 var actual = _.unset(object, path);
24948 assert.strictEqual(actual, true);
24949 assert.notOk('a' in stringProto.replace);
24951 delete stringProto.replace.b;
24955 QUnit.test('should return `false` for non-configurable properties', function(assert) {
24961 defineProperty(object, 'a', {
24962 'configurable': false,
24963 'enumerable': true,
24967 assert.strictEqual(_.unset(object, 'a'), false);
24970 skipAssert(assert);
24975 /*--------------------------------------------------------------------------*/
24977 QUnit.module('lodash.unzipWith');
24980 QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
24983 var array = [[1, 4], [2, 5], [3, 6]];
24985 var actual = _.unzipWith(array, function(a, b, c) {
24989 assert.deepEqual(actual, [6, 15]);
24992 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
24997 _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
24998 args || (args = slice.call(arguments));
25001 assert.deepEqual(args, [1, 2]);
25004 QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
25007 var array = [[1, 3], [2, 4]],
25008 values = [, null, undefined],
25009 expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
25011 var actual = lodashStable.map(values, function(value, index) {
25012 return index ? _.unzipWith(array, value) : _.unzipWith(array);
25015 assert.deepEqual(actual, expected);
25019 /*--------------------------------------------------------------------------*/
25021 QUnit.module('lodash.updateWith');
25024 QUnit.test('should work with a `customizer` callback', function(assert) {
25027 var actual = _.updateWith({ '0': {} }, '[0][1][2]', stubThree, function(value) {
25028 return lodashStable.isObject(value) ? undefined : {};
25031 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
25034 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
25037 var actual = _.updateWith({}, 'a[0].b.c', stubFour, noop);
25038 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
25042 /*--------------------------------------------------------------------------*/
25044 QUnit.module('update methods');
25046 lodashStable.each(['update', 'updateWith'], function(methodName) {
25047 var func = _[methodName],
25050 QUnit.test('`_.' + methodName + '` should invoke `updater` with the value on `path` of `object`', function(assert) {
25053 var object = { 'a': [{ 'b': { 'c': oldValue } }] },
25054 expected = oldValue + 1;
25056 lodashStable.each(['a[0].b.c', ['a', '0', 'b', 'c']], function(path) {
25057 func(object, path, function(n) {
25058 assert.strictEqual(n, oldValue);
25062 assert.strictEqual(object.a[0].b.c, expected);
25063 object.a[0].b.c = oldValue;
25068 /*--------------------------------------------------------------------------*/
25070 QUnit.module('lodash.upperCase');
25073 QUnit.test('should uppercase as space-separated words', function(assert) {
25076 assert.strictEqual(_.upperCase('--foo-bar--'), 'FOO BAR');
25077 assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
25078 assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
25082 /*--------------------------------------------------------------------------*/
25084 QUnit.module('lodash.upperFirst');
25087 QUnit.test('should uppercase only the first character', function(assert) {
25090 assert.strictEqual(_.upperFirst('fred'), 'Fred');
25091 assert.strictEqual(_.upperFirst('Fred'), 'Fred');
25092 assert.strictEqual(_.upperFirst('FRED'), 'FRED');
25096 /*--------------------------------------------------------------------------*/
25098 QUnit.module('values methods');
25100 lodashStable.each(['values', 'valuesIn'], function(methodName) {
25101 var args = (function() { return arguments; }(1, 2, 3)),
25102 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
25103 func = _[methodName],
25104 isValues = methodName == 'values';
25106 QUnit.test('`_.' + methodName + '` should get string keyed values of `object`', function(assert) {
25109 var object = { 'a': 1, 'b': 2 },
25110 actual = func(object).sort();
25112 assert.deepEqual(actual, [1, 2]);
25115 QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
25118 var object = { '0': 'a', '1': 'b', 'length': 2 },
25119 actual = func(object).sort();
25121 assert.deepEqual(actual, [2, 'a', 'b']);
25124 QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
25130 Foo.prototype.b = 2;
25132 var expected = isValues ? [1] : [1, 2],
25133 actual = func(new Foo).sort();
25135 assert.deepEqual(actual, expected);
25138 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
25141 var values = [args, strictArgs],
25142 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
25144 var actual = lodashStable.map(values, function(value) {
25145 return func(value).sort();
25148 assert.deepEqual(actual, expected);
25152 /*--------------------------------------------------------------------------*/
25154 QUnit.module('lodash.without');
25157 QUnit.test('should return the difference of values', function(assert) {
25160 var actual = _.without([2, 1, 2, 3], 1, 2);
25161 assert.deepEqual(actual, [3]);
25164 QUnit.test('should use strict equality to determine the values to reject', function(assert) {
25167 var object1 = { 'a': 1 },
25168 object2 = { 'b': 2 },
25169 array = [object1, object2];
25171 assert.deepEqual(_.without(array, { 'a': 1 }), array);
25172 assert.deepEqual(_.without(array, object1), [object2]);
25175 QUnit.test('should remove all occurrences of each value from an array', function(assert) {
25178 var array = [1, 2, 3, 1, 2, 3];
25179 assert.deepEqual(_.without(array, 1, 2), [3, 3]);
25183 /*--------------------------------------------------------------------------*/
25185 QUnit.module('lodash.words');
25188 QUnit.test('should treat latin-1 supplementary letters as words', function(assert) {
25191 var expected = lodashStable.map(burredLetters, function(letter) {
25195 var actual = lodashStable.map(burredLetters, function(letter) {
25196 return _.words(letter);
25199 assert.deepEqual(actual, expected);
25202 QUnit.test('should not treat mathematical operators as words', function(assert) {
25205 var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
25206 expected = lodashStable.map(operators, stubArray),
25207 actual = lodashStable.map(operators, _.words);
25209 assert.deepEqual(actual, expected);
25212 QUnit.test('should not treat punctuation as words', function(assert) {
25216 '\u2012', '\u2013', '\u2014', '\u2015',
25217 '\u2024', '\u2025', '\u2026',
25221 var expected = lodashStable.map(marks, stubArray),
25222 actual = lodashStable.map(marks, _.words);
25224 assert.deepEqual(actual, expected);
25227 QUnit.test('should support a `pattern` argument', function(assert) {
25230 assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
25231 assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
25234 QUnit.test('should work with compound words', function(assert) {
25237 assert.deepEqual(_.words('12Feet'), ['12', 'Feet']);
25238 assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
25239 assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']);
25240 assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']);
25241 assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']);
25242 assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
25243 assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
25244 assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
25245 assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
25246 assert.deepEqual(_.words('XMLHttp'), ['XML', 'Http']);
25247 assert.deepEqual(_.words('XmlHTTP'), ['Xml', 'HTTP']);
25248 assert.deepEqual(_.words('XmlHttp'), ['Xml', 'Http']);
25251 QUnit.test('should work with compound words containing diacritical marks', function(assert) {
25254 assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
25255 assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
25256 assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
25259 QUnit.test('should work with contractions', function(assert) {
25262 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
25264 lodashStable.each(["'", '\u2019'], function(apos) {
25265 var actual = lodashStable.map(postfixes, function(postfix) {
25266 return _.words('a b' + apos + postfix + ' c');
25269 var expected = lodashStable.map(postfixes, function(postfix) {
25270 return ['a', 'b' + apos + postfix, 'c'];
25273 assert.deepEqual(actual, expected);
25277 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
25280 var strings = lodashStable.map(['a', 'b', 'c'], Object),
25281 actual = lodashStable.map(strings, _.words);
25283 assert.deepEqual(actual, [['a'], ['b'], ['c']]);
25287 /*--------------------------------------------------------------------------*/
25289 QUnit.module('lodash.wrap');
25292 QUnit.test('should create a wrapped function', function(assert) {
25295 var p = _.wrap(_.escape, function(func, text) {
25296 return '<p>' + func(text) + '</p>';
25299 assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
25302 QUnit.test('should provide the correct `wrapper` arguments', function(assert) {
25307 var wrapped = _.wrap(noop, function() {
25308 args || (args = slice.call(arguments));
25312 assert.deepEqual(args, [noop, 1, 2, 3]);
25315 QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
25318 var values = [, null, undefined],
25319 expected = lodashStable.map(values, stubA);
25321 var actual = lodashStable.map(values, function(value, index) {
25322 var wrapped = index ? _.wrap('a', value) : _.wrap('a');
25323 return wrapped('b', 'c');
25326 assert.deepEqual(actual, expected);
25329 QUnit.test('should not set a `this` binding', function(assert) {
25332 var p = _.wrap(_.escape, function(func) {
25333 return '<p>' + func(this.text) + '</p>';
25336 var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
25337 assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
25341 /*--------------------------------------------------------------------------*/
25343 QUnit.module('xor methods');
25345 lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
25346 var args = (function() { return arguments; }(1, 2, 3)),
25347 func = _[methodName];
25349 QUnit.test('`_.' + methodName + '` should return the symmetric difference of two arrays', function(assert) {
25352 var actual = func([2, 1], [2, 3]);
25353 assert.deepEqual(actual, [1, 3]);
25356 QUnit.test('`_.' + methodName + '` should return the symmetric difference of multiple arrays', function(assert) {
25359 var actual = func([2, 1], [2, 3], [3, 4]);
25360 assert.deepEqual(actual, [1, 4]);
25363 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
25366 var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
25367 assert.deepEqual(actual, [1, 4, 5]);
25369 actual = func([1, 1]);
25370 assert.deepEqual(actual, [1]);
25373 QUnit.test('`_.' + methodName + '` should return a new array when a single array is given', function(assert) {
25377 assert.notStrictEqual(func(array), array);
25380 QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
25384 assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
25387 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
25390 var array = [1, 2];
25391 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
25392 assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
25393 assert.deepEqual(func(array, null, args, null), [3]);
25396 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
25400 var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
25401 assert.ok(wrapped instanceof _);
25404 skipAssert(assert);
25408 QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
25412 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
25413 wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
25415 var actual = lodashStable.map(['head', 'last'], function(methodName) {
25416 return wrapped[methodName]();
25419 assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
25422 skipAssert(assert);
25427 /*--------------------------------------------------------------------------*/
25429 QUnit.module('lodash.xorBy');
25432 QUnit.test('should accept an `iteratee` argument', function(assert) {
25435 var actual = _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
25436 assert.deepEqual(actual, [1.2, 3.4]);
25438 actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
25439 assert.deepEqual(actual, [{ 'x': 2 }]);
25442 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
25447 _.xorBy([2.1, 1.2], [2.3, 3.4], function() {
25448 args || (args = slice.call(arguments));
25451 assert.deepEqual(args, [2.3]);
25455 /*--------------------------------------------------------------------------*/
25457 QUnit.module('lodash.xorWith');
25460 QUnit.test('should work with a `comparator` argument', function(assert) {
25463 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
25464 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
25465 actual = _.xorWith(objects, others, lodashStable.isEqual);
25467 assert.deepEqual(actual, [objects[1], others[0]]);
25471 /*--------------------------------------------------------------------------*/
25473 QUnit.module('zipObject methods');
25475 lodashStable.each(['zipObject', 'zipObjectDeep'], function(methodName) {
25476 var func = _[methodName],
25477 object = { 'barney': 36, 'fred': 40 },
25478 isDeep = methodName == 'zipObjectDeep';
25480 QUnit.test('`_.' + methodName + '` should zip together key/value arrays into an object', function(assert) {
25483 var actual = func(['barney', 'fred'], [36, 40]);
25484 assert.deepEqual(actual, object);
25487 QUnit.test('`_.' + methodName + '` should ignore extra `values`', function(assert) {
25490 assert.deepEqual(func(['a'], [1, 2]), { 'a': 1 });
25493 QUnit.test('`_.' + methodName + '` should assign `undefined` values for extra `keys`', function(assert) {
25496 assert.deepEqual(func(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
25499 QUnit.test('`_.' + methodName + '` should ' + (isDeep ? '' : 'not ') + 'support deep paths', function(assert) {
25502 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path, index) {
25503 var expected = isDeep ? ({ 'a': { 'b': { 'c': 1 } } }) : (index ? { 'a,b,c': 1 } : { 'a.b.c': 1 });
25504 assert.deepEqual(func([path], [1]), expected);
25508 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
25512 var values = lodashStable.range(LARGE_ARRAY_SIZE),
25513 props = lodashStable.map(values, function(value) { return 'key' + value; }),
25514 actual = _(props)[methodName](values).map(square).filter(isEven).take().value();
25516 assert.deepEqual(actual, _.take(_.filter(_.map(func(props, values), square), isEven)));
25519 skipAssert(assert);
25524 /*--------------------------------------------------------------------------*/
25526 QUnit.module('lodash.zipWith');
25529 QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
25532 var array1 = [1, 2, 3],
25533 array2 = [4, 5, 6],
25534 array3 = [7, 8, 9];
25536 var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
25540 assert.deepEqual(actual, [12, 15, 18]);
25542 var actual = _.zipWith(array1, [], function(a, b) {
25543 return a + (b || 0);
25546 assert.deepEqual(actual, [1, 2, 3]);
25549 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
25554 _.zipWith([1, 2], [3, 4], [5, 6], function() {
25555 args || (args = slice.call(arguments));
25558 assert.deepEqual(args, [1, 3, 5]);
25561 QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
25564 var array1 = [1, 2],
25566 values = [, null, undefined],
25567 expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
25569 var actual = lodashStable.map(values, function(value, index) {
25570 return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
25573 assert.deepEqual(actual, expected);
25577 /*--------------------------------------------------------------------------*/
25579 QUnit.module('lodash.unzip and lodash.zip');
25581 lodashStable.each(['unzip', 'zip'], function(methodName, index) {
25582 var func = _[methodName];
25583 func = lodashStable.bind(index ? func.apply : func.call, func, null);
25586 'an empty array': [
25595 [['barney', 'fred'], [36, 40]],
25596 [['barney', 36], ['fred', 40]]
25599 [['barney', 'fred'], [36, 40], [false, true]],
25600 [['barney', 36, false], ['fred', 40, true]]
25604 lodashStable.forOwn(object, function(pair, key) {
25605 QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
25608 var actual = func(pair[0]);
25609 assert.deepEqual(actual, pair[1]);
25610 assert.deepEqual(func(actual), actual.length ? pair[0] : []);
25614 QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
25618 [['barney', 36], ['fred', 40, false]],
25619 [['barney', 'fred'], [36, 40], [undefined, false]]
25622 var actual = func(pair[0]);
25623 assert.ok('0' in actual[2]);
25624 assert.deepEqual(actual, pair[1]);
25626 actual = func(actual);
25627 assert.ok('2' in actual[0]);
25628 assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
25631 QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
25634 var expected = lodashStable.map(falsey, stubArray);
25636 var actual = lodashStable.map(falsey, function(value) {
25637 return func([value, value, value]);
25640 assert.deepEqual(actual, expected);
25643 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
25646 var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
25647 assert.deepEqual(func(array), [[1, 3], [2, 4]]);
25650 QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
25653 var expected = [['barney', 'fred'], [36, 40]];
25654 assert.deepEqual(func(func(func(func(expected)))), expected);
25658 /*--------------------------------------------------------------------------*/
25660 QUnit.module('lodash(...).commit');
25663 QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
25668 wrapped = _(array).push(2).push(3);
25670 assert.deepEqual(array, [1]);
25672 var otherWrapper = wrapped.commit();
25673 assert.ok(otherWrapper instanceof _);
25674 assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
25675 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
25678 skipAssert(assert, 4);
25682 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
25686 var wrapped = _([1]).chain().commit().head();
25687 assert.ok(wrapped instanceof _);
25688 assert.strictEqual(wrapped.value(), 1);
25691 skipAssert(assert, 2);
25696 /*--------------------------------------------------------------------------*/
25698 QUnit.module('lodash(...).next');
25700 lodashStable.each([false, true], function(implict) {
25701 function chain(value) {
25702 return implict ? _(value) : _.chain(value);
25705 var chainType = 'in an ' + (implict ? 'implict' : 'explict') + ' chain';
25707 QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
25711 var wrapped = chain([1, 2]);
25713 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
25714 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
25715 assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
25718 skipAssert(assert, 3);
25722 QUnit.test('should act as an iterable ' + chainType, function(assert) {
25725 if (!isNpm && Symbol && Symbol.iterator) {
25726 var array = [1, 2],
25727 wrapped = chain(array);
25729 assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
25730 assert.deepEqual(lodashStable.toArray(wrapped), array);
25733 skipAssert(assert, 2);
25737 QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
25740 if (!isNpm && Array.from) {
25741 var hearts = '\ud83d\udc95',
25742 values = [[1], { 'a': 1 }, hearts];
25744 lodashStable.each(values, function(value) {
25745 var wrapped = chain(value);
25746 assert.deepEqual(Array.from(wrapped), _.toArray(value));
25750 skipAssert(assert, 3);
25754 QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
25757 if (!isNpm && Symbol && Symbol.iterator) {
25758 var array = [1, 2],
25759 wrapped = chain(array);
25761 assert.deepEqual(lodashStable.toArray(wrapped), array);
25762 assert.deepEqual(lodashStable.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
25764 var other = wrapped.filter();
25765 assert.deepEqual(lodashStable.toArray(other), array, 'reset for new chain segments');
25766 assert.deepEqual(lodashStable.toArray(wrapped), [], 'iterator is still exhausted');
25769 skipAssert(assert, 4);
25773 QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
25776 if (!isNpm && Symbol && Symbol.iterator) {
25777 var array = lodashStable.range(LARGE_ARRAY_SIZE),
25778 predicate = function(value) { values.push(value); return isEven(value); },
25780 wrapped = chain(array);
25782 assert.deepEqual(lodashStable.toArray(wrapped), array);
25784 wrapped = wrapped.filter(predicate);
25785 assert.deepEqual(lodashStable.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
25786 assert.deepEqual(values, array, 'memoizes iterator values');
25789 skipAssert(assert, 3);
25794 /*--------------------------------------------------------------------------*/
25796 QUnit.module('lodash(...).plant');
25799 QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
25803 var array1 = [5, null, 3, null, 1],
25804 array2 = [10, null, 8, null, 6],
25805 wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
25806 wrapped2 = wrapped1.plant(array2);
25808 assert.deepEqual(wrapped2.value(), [36, 64]);
25809 assert.deepEqual(wrapped1.value(), [1, 9]);
25812 skipAssert(assert, 2);
25816 QUnit.test('should clone `chainAll` settings', function(assert) {
25820 var array1 = [2, 4],
25822 wrapped1 = _(array1).chain().map(square),
25823 wrapped2 = wrapped1.plant(array2);
25825 assert.deepEqual(wrapped2.head().value(), 36);
25828 skipAssert(assert);
25832 QUnit.test('should reset iterator data on cloned sequences', function(assert) {
25835 if (!isNpm && Symbol && Symbol.iterator) {
25836 var array1 = [2, 4],
25838 wrapped1 = _(array1).map(square);
25840 assert.deepEqual(lodashStable.toArray(wrapped1), [4, 16]);
25841 assert.deepEqual(lodashStable.toArray(wrapped1), []);
25843 var wrapped2 = wrapped1.plant(array2);
25844 assert.deepEqual(lodashStable.toArray(wrapped2), [36, 64]);
25847 skipAssert(assert, 3);
25852 /*--------------------------------------------------------------------------*/
25854 QUnit.module('lodash(...).pop');
25857 QUnit.test('should remove elements from the end of `array`', function(assert) {
25861 var array = [1, 2],
25862 wrapped = _(array);
25864 assert.strictEqual(wrapped.pop(), 2);
25865 assert.deepEqual(wrapped.value(), [1]);
25866 assert.strictEqual(wrapped.pop(), 1);
25868 var actual = wrapped.value();
25869 assert.strictEqual(actual, array);
25870 assert.deepEqual(actual, []);
25873 skipAssert(assert, 5);
25877 QUnit.test('should accept falsey arguments', function(assert) {
25881 var expected = lodashStable.map(falsey, stubTrue);
25883 var actual = lodashStable.map(falsey, function(value, index) {
25885 var result = index ? _(value).pop() : _().pop();
25886 return result === undefined;
25890 assert.deepEqual(actual, expected);
25893 skipAssert(assert);
25898 /*--------------------------------------------------------------------------*/
25900 QUnit.module('lodash(...).push');
25903 QUnit.test('should append elements to `array`', function(assert) {
25908 wrapped = _(array).push(2, 3),
25909 actual = wrapped.value();
25911 assert.strictEqual(actual, array);
25912 assert.deepEqual(actual, [1, 2, 3]);
25915 skipAssert(assert, 2);
25919 QUnit.test('should accept falsey arguments', function(assert) {
25923 var expected = lodashStable.map(falsey, stubTrue);
25925 var actual = lodashStable.map(falsey, function(value, index) {
25927 var result = index ? _(value).push(1).value() : _().push(1).value();
25928 return lodashStable.eq(result, value);
25932 assert.deepEqual(actual, expected);
25935 skipAssert(assert);
25940 /*--------------------------------------------------------------------------*/
25942 QUnit.module('lodash(...).shift');
25945 QUnit.test('should remove elements from the front of `array`', function(assert) {
25949 var array = [1, 2],
25950 wrapped = _(array);
25952 assert.strictEqual(wrapped.shift(), 1);
25953 assert.deepEqual(wrapped.value(), [2]);
25954 assert.strictEqual(wrapped.shift(), 2);
25956 var actual = wrapped.value();
25957 assert.strictEqual(actual, array);
25958 assert.deepEqual(actual, []);
25961 skipAssert(assert, 5);
25965 QUnit.test('should accept falsey arguments', function(assert) {
25969 var expected = lodashStable.map(falsey, stubTrue);
25971 var actual = lodashStable.map(falsey, function(value, index) {
25973 var result = index ? _(value).shift() : _().shift();
25974 return result === undefined;
25978 assert.deepEqual(actual, expected);
25981 skipAssert(assert);
25986 /*--------------------------------------------------------------------------*/
25988 QUnit.module('lodash(...).sort');
25991 QUnit.test('should return the wrapped sorted `array`', function(assert) {
25995 var array = [3, 1, 2],
25996 wrapped = _(array).sort(),
25997 actual = wrapped.value();
25999 assert.strictEqual(actual, array);
26000 assert.deepEqual(actual, [1, 2, 3]);
26003 skipAssert(assert, 2);
26007 QUnit.test('should accept falsey arguments', function(assert) {
26011 var expected = lodashStable.map(falsey, stubTrue);
26013 var actual = lodashStable.map(falsey, function(value, index) {
26015 var result = index ? _(value).sort().value() : _().sort().value();
26016 return lodashStable.eq(result, value);
26020 assert.deepEqual(actual, expected);
26023 skipAssert(assert);
26028 /*--------------------------------------------------------------------------*/
26030 QUnit.module('lodash(...).splice');
26033 QUnit.test('should support removing and inserting elements', function(assert) {
26037 var array = [1, 2],
26038 wrapped = _(array);
26040 assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
26041 assert.deepEqual(wrapped.value(), [1, 3]);
26042 assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
26044 var actual = wrapped.value();
26045 assert.strictEqual(actual, array);
26046 assert.deepEqual(actual, []);
26049 skipAssert(assert, 5);
26053 QUnit.test('should accept falsey arguments', function(assert) {
26057 var expected = lodashStable.map(falsey, stubTrue);
26059 var actual = lodashStable.map(falsey, function(value, index) {
26061 var result = index ? _(value).splice(0, 1).value() : _().splice(0, 1).value();
26062 return lodashStable.isEqual(result, []);
26066 assert.deepEqual(actual, expected);
26069 skipAssert(assert);
26074 /*--------------------------------------------------------------------------*/
26076 QUnit.module('lodash(...).unshift');
26079 QUnit.test('should prepend elements to `array`', function(assert) {
26084 wrapped = _(array).unshift(1, 2),
26085 actual = wrapped.value();
26087 assert.strictEqual(actual, array);
26088 assert.deepEqual(actual, [1, 2, 3]);
26091 skipAssert(assert, 2);
26095 QUnit.test('should accept falsey arguments', function(assert) {
26099 var expected = lodashStable.map(falsey, stubTrue);
26101 var actual = lodashStable.map(falsey, function(value, index) {
26103 var result = index ? _(value).unshift(1).value() : _().unshift(1).value();
26104 return lodashStable.eq(result, value);
26108 assert.deepEqual(actual, expected);
26111 skipAssert(assert);
26116 /*--------------------------------------------------------------------------*/
26118 QUnit.module('lodash(...).value');
26121 QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
26126 wrapped = _(array).push(2).push(3);
26128 assert.deepEqual(array, [1]);
26129 assert.deepEqual(wrapped.value(), [1, 2, 3]);
26130 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
26131 assert.deepEqual(array, [1, 2, 3, 2, 3]);
26134 skipAssert(assert, 4);
26138 QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
26142 var wrapped = _(123);
26143 assert.strictEqual(Number(wrapped), 123);
26146 skipAssert(assert);
26150 QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
26153 if (!isNpm && JSON) {
26154 var wrapped = _([1, 2, 3]);
26155 assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
26158 skipAssert(assert);
26162 QUnit.test('should be aliased', function(assert) {
26166 var expected = _.prototype.value;
26167 assert.strictEqual(_.prototype.toJSON, expected);
26168 assert.strictEqual(_.prototype.valueOf, expected);
26171 skipAssert(assert, 2);
26176 /*--------------------------------------------------------------------------*/
26178 QUnit.module('lodash(...) methods that return the wrapped modified array');
26188 lodashStable.each(funcs, function(methodName) {
26189 QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
26193 var array = [1, 2, 3],
26194 wrapped = _(array),
26195 actual = wrapped[methodName]();
26197 assert.ok(actual instanceof _);
26198 assert.notStrictEqual(actual, wrapped);
26201 skipAssert(assert, 2);
26207 /*--------------------------------------------------------------------------*/
26209 QUnit.module('lodash(...) methods that return new wrapped values');
26220 'intersectionWith',
26242 lodashStable.each(funcs, function(methodName) {
26243 QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
26247 var value = methodName == 'split' ? 'abc' : [1, 2, 3],
26248 wrapped = _(value),
26249 actual = wrapped[methodName]();
26251 assert.ok(actual instanceof _);
26252 assert.notStrictEqual(actual, wrapped);
26255 skipAssert(assert, 2);
26261 /*--------------------------------------------------------------------------*/
26263 QUnit.module('lodash(...) methods that return unwrapped values');
26361 lodashStable.each(funcs, function(methodName) {
26362 QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
26366 var actual = _()[methodName]();
26367 assert.notOk(actual instanceof _);
26370 skipAssert(assert);
26374 QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
26378 var actual = _().chain()[methodName]();
26379 assert.ok(actual instanceof _);
26382 skipAssert(assert);
26388 /*--------------------------------------------------------------------------*/
26390 QUnit.module('"Arrays" category methods');
26393 var args = (function() { return arguments; }(1, null, [3], null, 5)),
26394 sortedArgs = (function() { return arguments; }(1, [3], 5, null, null)),
26395 array = [1, 2, 3, 4, 5, 6];
26397 QUnit.test('should work with `arguments` objects', function(assert) {
26400 function message(methodName) {
26401 return '`_.' + methodName + '` should work with `arguments` objects';
26404 assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
26405 assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
26407 assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
26408 assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
26410 assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
26411 assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
26412 assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
26413 assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
26414 assert.deepEqual(_.dropWhile(args,identity), [null, [3], null, 5], message('dropWhile'));
26415 assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
26416 assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
26417 assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
26418 assert.deepEqual(_.head(args), 1, message('head'));
26419 assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
26420 assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
26421 assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
26422 assert.deepEqual(_.last(args), 5, message('last'));
26423 assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
26424 assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
26425 assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
26426 assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
26427 assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
26428 assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
26429 assert.deepEqual(_.take(args, 2), [1, null], message('take'));
26430 assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
26431 assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
26432 assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
26433 assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
26434 assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
26435 assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
26438 QUnit.test('should accept falsey primary arguments', function(assert) {
26441 function message(methodName) {
26442 return '`_.' + methodName + '` should accept falsey primary arguments';
26445 assert.deepEqual(_.difference(null, array), [], message('difference'));
26446 assert.deepEqual(_.intersection(null, array), [], message('intersection'));
26447 assert.deepEqual(_.union(null, array), array, message('union'));
26448 assert.deepEqual(_.xor(null, array), array, message('xor'));
26451 QUnit.test('should accept falsey secondary arguments', function(assert) {
26454 function message(methodName) {
26455 return '`_.' + methodName + '` should accept falsey secondary arguments';
26458 assert.deepEqual(_.difference(array, null), array, message('difference'));
26459 assert.deepEqual(_.intersection(array, null), [], message('intersection'));
26460 assert.deepEqual(_.union(array, null), array, message('union'));
26464 /*--------------------------------------------------------------------------*/
26466 QUnit.module('"Strings" category methods');
26469 var stringMethods = [
26492 lodashStable.each(stringMethods, function(methodName) {
26493 var func = _[methodName];
26495 QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
26498 var values = [, null, undefined, ''],
26499 expected = lodashStable.map(values, stubString);
26501 var actual = lodashStable.map(values, function(value, index) {
26502 return index ? func(value) : func();
26505 assert.deepEqual(actual, expected);
26510 /*--------------------------------------------------------------------------*/
26512 QUnit.module('lodash methods');
26515 var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
26516 return lodashStable.startsWith(methodName, '_');
26557 var rejectFalsey = [
26560 ].concat(checkFuncs);
26562 var returnArrays = [
26600 var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
26602 QUnit.test('should accept falsey arguments', function(assert) {
26603 assert.expect(314);
26605 var arrays = lodashStable.map(falsey, stubArray);
26607 lodashStable.each(acceptFalsey, function(methodName) {
26608 var expected = arrays,
26609 func = _[methodName],
26612 var actual = lodashStable.map(falsey, function(value, index) {
26614 return index ? func(value) : func();
26620 if (methodName == 'noConflict') {
26623 else if (methodName == 'pull' || methodName == 'pullAll') {
26626 if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
26627 assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
26629 assert.ok(pass, '`_.' + methodName + '` accepts falsey arguments');
26632 // Skip tests for missing methods of modularized builds.
26633 lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
26634 if (!_[methodName]) {
26635 skipAssert(assert);
26640 QUnit.test('should return an array', function(assert) {
26643 var array = [1, 2, 3];
26645 lodashStable.each(returnArrays, function(methodName) {
26647 func = _[methodName];
26649 switch (methodName) {
26651 actual = func(array, 'toFixed');
26654 actual = func(array, 1);
26657 actual = func(array);
26659 assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
26661 var isPull = methodName == 'pull' || methodName == 'pullAll';
26662 assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the given array');
26666 QUnit.test('should throw an error for falsey arguments', function(assert) {
26669 lodashStable.each(rejectFalsey, function(methodName) {
26670 var expected = lodashStable.map(falsey, stubTrue),
26671 func = _[methodName];
26673 var actual = lodashStable.map(falsey, function(value, index) {
26674 var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
26677 index ? func(value) : func();
26679 pass = !pass && (e instanceof TypeError) &&
26680 (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
26685 assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
26689 QUnit.test('should not set a `this` binding', function(assert) {
26692 lodashStable.each(noBinding, function(methodName) {
26693 var fn = function() { return this.a; },
26694 func = _[methodName],
26695 isNegate = methodName == 'negate',
26696 object = { 'a': 1 },
26697 expected = isNegate ? false : 1;
26699 var wrapper = func(_.bind(fn, object));
26700 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
26702 wrapper = _.bind(func(fn), object);
26703 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
26705 object.wrapper = func(fn);
26706 assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
26710 QUnit.test('should not contain minified method names (test production builds)', function(assert) {
26713 var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
26714 assert.ok(lodashStable.every(_.functions(_), function(methodName) {
26715 return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
26720 /*--------------------------------------------------------------------------*/
26722 QUnit.config.asyncRetries = 10;
26723 QUnit.config.hidepassed = true;
26726 QUnit.config.noglobals = true;