3 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
6 /** Used to detect when a function becomes hot. */
9 /** Used as the size to cover large array optimizations. */
10 var LARGE_ARRAY_SIZE = 200;
12 /** Used as the `TypeError` message for "Functions" methods. */
13 var FUNC_ERROR_TEXT = 'Expected a function';
15 /** Used as references for various `Number` constants. */
16 var MAX_SAFE_INTEGER = 9007199254740991,
17 MAX_INTEGER = 1.7976931348623157e+308;
19 /** Used as references for the maximum length and index of an array. */
20 var MAX_ARRAY_LENGTH = 4294967295,
21 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
23 /** `Object#toString` result references. */
24 var funcTag = '[object Function]',
25 numberTag = '[object Number]',
26 objectTag = '[object Object]';
28 /** Used as a reference to the global object. */
29 var root = (typeof global == 'object' && global) || this;
31 /** Used to store lodash to test for bad extensions/shims. */
32 var lodashBizarro = root.lodashBizarro;
34 /** Used for native method references. */
35 var arrayProto = Array.prototype,
36 errorProto = Error.prototype,
37 funcProto = Function.prototype,
38 objectProto = Object.prototype,
39 numberProto = Number.prototype,
40 stringProto = String.prototype;
42 /** Method and object shortcuts. */
43 var phantom = root.phantom,
44 process = root.process,
45 amd = root.define && define.amd,
46 argv = process && process.argv,
47 defineProperty = Object.defineProperty,
48 document = !phantom && root.document,
49 body = root.document && root.document.body,
50 create = Object.create,
51 fnToString = funcProto.toString,
52 freeze = Object.freeze,
53 identity = function(value) { return value; },
56 objToString = objectProto.toString,
58 push = arrayProto.push,
60 slice = arrayProto.slice;
62 var ArrayBuffer = root.ArrayBuffer,
67 Uint8Array = root.Uint8Array,
68 WeakMap = root.WeakMap,
69 WeakSet = root.WeakSet;
71 var arrayBuffer = ArrayBuffer ? new ArrayBuffer(2) : undefined,
72 map = Map ? new Map : undefined,
73 set = Set ? new Set : undefined,
74 symbol = Symbol ? Symbol('a') : undefined,
75 weakMap = WeakMap ? new WeakMap : undefined,
76 weakSet = WeakSet ? new WeakSet : undefined;
79 var add = function(x, y) { return x + y; },
80 doubled = function(n) { return n * 2; },
81 isEven = function(n) { return n % 2 == 0; },
82 square = function(n) { return n * n; };
84 /** Constant functions. */
85 var alwaysA = function() { return 'a'; },
86 alwaysB = function() { return 'b'; },
87 alwaysC = function() { return 'c'; };
89 var alwaysTrue = function() { return true; },
90 alwaysFalse = function() { return false; };
92 var alwaysNaN = function() { return NaN; },
93 alwaysNull = function() { return null; },
94 alwaysUndefined = function() { return undefined; };
96 var alwaysZero = function() { return 0; },
97 alwaysOne = function() { return 1; },
98 alwaysTwo = function() { return 2; },
99 alwaysThree = function() { return 3; },
100 alwaysFour = function() { return 4; };
102 var alwaysEmptyArray = function() { return []; },
103 alwaysEmptyObject = function() { return {}; },
104 alwaysEmptyString = function() { return ''; };
106 /** The file path of the lodash file to test. */
107 var filePath = (function() {
109 result = params || [];
113 result = params = phantom.args || require('system').args;
115 var last = result[result.length - 1];
116 result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js';
120 result = require('fs').realpathSync(result);
124 result = require.resolve(result);
130 /** The `ui` object. */
131 var ui = root.ui || (root.ui = {
132 'buildPath': filePath,
134 'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
135 'isStrict': /\bes\b/.test(filePath),
139 /** The basename of the lodash file to test. */
140 var basename = /[\w.-]+$/.exec(filePath)[0];
142 /** Used to indicate testing a modularized build. */
143 var isModularize = ui.isModularize;
145 /** Detect if testing `npm` modules. */
146 var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
148 /** Detect if running in PhantomJS. */
149 var isPhantom = phantom || (typeof callPhantom == 'function');
151 /** Detect if lodash is in strict mode. */
152 var isStrict = ui.isStrict;
154 /*--------------------------------------------------------------------------*/
156 // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
157 root.msWDfn = undefined;
159 // Exit early if going to run tests in a PhantomJS web page.
160 if (phantom && isModularize) {
161 var page = require('webpage').create();
163 page.onCallback = function(details) {
164 var coverage = details.coverage;
166 var fs = require('fs'),
167 cwd = fs.workingDirectory,
170 fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
172 phantom.exit(details.failed ? 1 : 0);
175 page.onConsoleMessage = function(message) {
176 console.log(message);
179 page.onInitialized = function() {
180 page.evaluate(function() {
181 document.addEventListener('DOMContentLoaded', function() {
182 QUnit.done(function(details) {
183 details.coverage = window.__coverage__;
184 callPhantom(details);
190 page.open(filePath, function(status) {
191 if (status != 'success') {
192 console.log('PhantomJS failed to load page: ' + filePath);
197 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
201 /*--------------------------------------------------------------------------*/
203 /** Used to test Web Workers. */
204 var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
205 (document && document.origin != 'null') && root.Worker;
207 /** Used to test host objects in IE. */
209 var xml = new ActiveXObject('Microsoft.XMLDOM');
212 /** Poison the free variable `root` in Node.js */
214 defineProperty(global.root, 'root', {
215 'configurable': false,
217 'get': function() { throw new ReferenceError; }
221 /** Use a single "load" function. */
222 var load = (!amd && typeof require == 'function')
226 /** The unit testing framework. */
227 var QUnit = root.QUnit || (root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js'));
229 /** Load stable Lodash and QUnit Extras. */
230 var lodashStable = root.lodashStable;
233 lodashStable = load('../node_modules/lodash/lodash.js');
235 console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
238 lodashStable = lodashStable.noConflict();
240 lodashStable = lodashStable.runInContext(root);
242 var QUnitExtras = load('../node_modules/qunit-extras/qunit-extras.js');
244 QUnitExtras.runInContext(root);
247 /** The `lodash` function to test. */
248 var _ = root._ || (root._ = (
250 _ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _,
251 (_.runInContext ? _.runInContext(root) : _)
254 /** Used to detect instrumented istanbul code coverage runs. */
255 var coverage = root.__coverage__ || root[lodashStable.findKey(root, function(value, key) {
256 return /^(?:\$\$cov_\d+\$\$)$/.test(key);
259 /** Used to restore the `_` reference. */
260 var oldDash = root._;
262 /** Used to test generator functions. */
263 var generator = lodashStable.attempt(function() {
264 return Function('return function*(){}');
267 /** List of latin-1 supplementary letters to basic latin letters. */
268 var burredLetters = [
269 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce',
270 '\xcf', '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde',
271 '\xdf', '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee',
272 '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff'
275 /** List of combining diacritical marks. */
277 '\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305', '\u0306', '\u0307', '\u0308', '\u0309', '\u030a', '\u030b', '\u030c', '\u030d', '\u030e', '\u030f',
278 '\u0310', '\u0311', '\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317', '\u0318', '\u0319', '\u031a', '\u031b', '\u031c', '\u031d', '\u031e', '\u031f',
279 '\u0320', '\u0321', '\u0322', '\u0323', '\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329', '\u032a', '\u032b', '\u032c', '\u032d', '\u032e', '\u032f',
280 '\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339', '\u033a', '\u033b', '\u033c', '\u033d', '\u033e', '\u033f',
281 '\u0340', '\u0341', '\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347', '\u0348', '\u0349', '\u034a', '\u034b', '\u034c', '\u034d', '\u034e', '\u034f',
282 '\u0350', '\u0351', '\u0352', '\u0353', '\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359', '\u035a', '\u035b', '\u035c', '\u035d', '\u035e', '\u035f',
283 '\u0360', '\u0361', '\u0362', '\u0363', '\u0364', '\u0365', '\u0366', '\u0367', '\u0368', '\u0369', '\u036a', '\u036b', '\u036c', '\u036d', '\u036e', '\u036f',
284 '\ufe20', '\ufe21', '\ufe22', '\ufe23'
287 /** List of `burredLetters` translated to basic latin letters. */
288 var deburredLetters = [
289 'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
290 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th',
291 'ss', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
292 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y'
295 /** Used to specify the emoji style glyph variant of characters. */
296 var emojiVar = '\ufe0f';
298 /** Used to provide falsey values to methods. */
299 var falsey = [, '', 0, false, NaN, null, undefined];
301 /** Used to provide empty values to methods. */
302 var empties = [[], {}].concat(falsey.slice(1));
304 /** Used to test error objects. */
315 /** List of fitzpatrick modifiers. */
316 var fitzModifiers = [
324 /** Used to check whether methods support typed arrays. */
338 * Used to check for problems removing whitespace. For a whitespace reference,
339 * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
341 var whitespace = lodashStable.filter([
342 // Basic whitespace characters.
343 ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
346 '\n', '\r', '\u2028', '\u2029',
348 // Unicode category "Zs" space separators.
349 '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
350 '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
352 function(chr) { return /\s/.exec(chr); })
356 * Creates a custom error object.
360 * @param {string} message The error message.
362 function CustomError(message) {
363 this.name = 'CustomError';
364 this.message = message;
367 CustomError.prototype = lodashStable.create(Error.prototype, {
368 'constructor': CustomError
372 * Removes all own enumerable properties from a given object.
375 * @param {Object} object The object to empty.
377 function emptyObject(object) {
378 lodashStable.forOwn(object, function(value, key, object) {
384 * Extracts the unwrapped value from its wrapper.
387 * @param {Object} wrapper The wrapper to unwrap.
388 * @returns {*} Returns the unwrapped value.
390 function getUnwrappedValue(wrapper) {
392 actions = wrapper.__actions__,
393 length = actions.length,
394 result = wrapper.__wrapped__;
396 while (++index < length) {
398 action = actions[index];
400 push.apply(args, action.args);
401 result = action.func.apply(action.thisArg, args);
407 * Sets a non-enumerable property value on `object`.
409 * Note: This function is used to avoid a bug in older versions of V8 where
410 * overwriting non-enumerable built-ins makes them enumerable.
411 * See https://code.google.com/p/v8/issues/detail?id=1623
414 * @param {Object} object The object modify.
415 * @param {string} key The name of the property to set.
416 * @param {*} value The property value.
418 function setProperty(object, key, value) {
420 defineProperty(object, key, {
421 'configurable': true,
433 * Skips a given number of tests with a passing result.
436 * @param {Object} assert The QUnit assert object.
437 * @param {number} [count=1] The number of tests to skip.
439 function skipAssert(assert, count) {
440 count || (count = 1);
442 assert.ok(true, 'test skipped');
446 /*--------------------------------------------------------------------------*/
448 // Add bizarro values.
450 if (document || (typeof require != 'function')) {
453 var nativeString = fnToString.call(toString),
454 reToString = /toString/g;
456 function createToString(funcName) {
457 return lodashStable.constant(nativeString.replace(reToString, funcName));
460 // Allow bypassing native checks.
461 setProperty(funcProto, 'toString', function wrapper() {
462 setProperty(funcProto, 'toString', fnToString);
463 var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
464 setProperty(funcProto, 'toString', wrapper);
468 // Add prototype extensions.
469 funcProto._method = noop;
472 setProperty(Object, 'create', (function() {
474 return function(prototype) {
475 if (lodashStable.isObject(prototype)) {
476 object.prototype = prototype;
477 var result = new object;
478 object.prototype = undefined;
484 var _getOwnPropertySymbols = Object.getOwnPropertySymbols;
485 setProperty(Object, 'getOwnPropertySymbols', undefined);
487 var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
488 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
489 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
493 defineProperty(root, 'Buffer', {
494 'configurable': true,
496 'get': function get() {
497 var caller = get.caller,
498 name = caller ? caller.name : '';
500 if (!(name == 'runInContext' || name.length == 1 || /\b_\.isBuffer\b/.test(caller))) {
507 setProperty(root, 'Map', (function() {
513 setProperty(root, 'Map', Map);
518 setProperty(root.Map, 'toString', createToString('Map'));
520 setProperty(root, 'Set', noop);
521 setProperty(root, 'Symbol', undefined);
522 setProperty(root, 'WeakMap', noop);
524 // Fake `WinRTError`.
525 setProperty(root, 'WinRTError', Error);
527 // Clear cache so lodash can be reloaded.
528 emptyObject(require.cache);
530 // Load lodash and expose it to the bad extensions/shims.
531 lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
534 // Restore built-in methods.
535 setProperty(Object, 'create', create);
536 setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
537 setProperty(root, 'Buffer', Buffer);
539 if (_getOwnPropertySymbols) {
540 Object.getOwnPropertySymbols = _getOwnPropertySymbols;
542 delete Object.getOwnPropertySymbols;
545 setProperty(root, 'Map', Map);
550 setProperty(root, 'Set', Set);
555 setProperty(root, 'Symbol', Symbol);
560 setProperty(root, 'WeakMap', WeakMap);
564 delete root.WinRTError;
565 delete funcProto._method;
568 // Add other realm values from the `vm` module.
569 lodashStable.attempt(function() {
570 lodashStable.assign(realm, require('vm').runInNewContext([
572 ' var noop = function() {},',
576 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
578 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
579 " 'boolean': Object(false),",
580 " 'date': new Date,",
581 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
582 " 'function': noop,",
583 " 'map': root.Map ? new root.Map : undefined,",
586 " 'number': Object(0),",
587 " 'object': { 'a': 1 },",
589 " 'set': root.Set ? new root.Set : undefined,",
590 " 'string': Object('a'),",
591 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
592 " 'undefined': undefined,",
593 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
594 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
597 " ['" + typedArrays.join("', '") + "'].forEach(function(type) {",
598 ' var Ctor = root[type]',
599 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
607 // Add other realm values from an iframe.
608 lodashStable.attempt(function() {
611 var iframe = document.createElement('iframe');
612 iframe.frameBorder = iframe.height = iframe.width = 0;
613 body.appendChild(iframe);
615 var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
620 ' var noop = function() {},',
624 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
626 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
627 " 'boolean': Object(false),",
628 " 'date': new Date,",
629 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
630 " 'function': noop,",
631 " 'map': root.Map ? new root.Map : undefined,",
634 " 'number': Object(0),",
635 " 'object': { 'a': 1 },",
637 " 'set': root.Set ? new root.Set : undefined,",
638 " 'string': Object('a'),",
639 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
640 " 'undefined': undefined,",
641 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
642 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
645 "_.each(['" + typedArrays.join("', '") + "'], function(type) {",
646 ' var Ctor = root[type];',
647 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
650 '_.assign(_._realm, object);',
659 lodashStable.attempt(function() {
660 var worker = new Worker('./asset/worker.js?t=' + (+new Date));
661 worker.addEventListener('message', function(e) {
662 _._VERSION = e.data || '';
665 worker.postMessage(ui.buildPath);
668 // Expose internal modules for better code coverage.
669 lodashStable.attempt(function() {
670 var path = require('path'),
671 basePath = path.dirname(filePath);
673 if (isModularize && !(amd || isNpm)) {
678 ], function(relPath) {
679 var func = require(path.join(basePath, relPath)),
680 funcName = path.basename(relPath);
682 _['_' + funcName] = func[funcName] || func['default'] || func;
687 /*--------------------------------------------------------------------------*/
690 console.log('Running lodash tests.');
691 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
694 QUnit.module(basename);
697 QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
701 assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
708 QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
711 if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
712 assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
718 QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
722 assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
729 QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
732 var done = assert.async();
735 var limit = 30000 / QUnit.config.asyncRetries,
738 var attempt = function() {
739 var actual = _._VERSION;
740 if ((new Date - start) < limit && typeof actual != 'string') {
741 setTimeout(attempt, 16);
744 assert.strictEqual(actual, _.VERSION);
756 QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
760 assert.notOk('_method' in lodashBizarro);
767 QUnit.test('should avoid non-native built-ins', function(assert) {
770 function message(lodashMethod, nativeMethod) {
771 return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
774 function Foo() { this.a = 1; }
777 var object = { 'a': 1 },
778 otherObject = { 'b': 2 },
779 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
783 var actual = lodashBizarro.keysIn(new Foo).sort();
787 var label = message('_.keysIn', 'Object#propertyIsEnumerable');
788 assert.deepEqual(actual, ['a', 'b'], label);
792 lodashBizarro.difference([object, otherObject], largeArray),
793 lodashBizarro.intersection(largeArray, [object]),
794 lodashBizarro.uniq(largeArray)
799 label = message('_.difference`, `_.intersection`, and `_.uniq', 'Object.create` and `Map');
800 assert.deepEqual(actual, [[otherObject], [object], [object]], label);
807 lodashBizarro.clone(object),
808 lodashBizarro.cloneDeep(object)
813 label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
814 assert.deepEqual(actual, [object, object], label);
817 var symObject = Object(symbol);
819 // Avoid symbol detection in Babel's `typeof` helper.
820 symObject.constructor = Object;
823 Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
824 Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
825 Symbol ? lodashBizarro.toString(symObject) : ''
830 label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
831 assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
834 var map = new lodashBizarro.memoize.Cache;
835 actual = map.set('a', 1).get('a');
839 label = message('_.memoize.Cache', 'Map');
840 assert.deepEqual(actual, 1, label);
843 map = new (Map || Object);
844 if (Symbol && Symbol.iterator) {
845 map[Symbol.iterator] = null;
847 actual = lodashBizarro.toArray(map);
851 label = message('_.toArray', 'Map');
852 assert.deepEqual(actual, [], label);
855 skipAssert(assert, 6);
860 /*--------------------------------------------------------------------------*/
862 QUnit.module('isIndex');
865 var func = _._isIndex;
867 QUnit.test('should return `true` for indexes', function(assert) {
871 var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
872 expected = lodashStable.map(values, alwaysTrue);
874 var actual = lodashStable.map(values, function(args) {
875 return func.apply(undefined, args);
878 assert.deepEqual(actual, expected);
885 QUnit.test('should return `false` for non-indexes', function(assert) {
889 var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
890 expected = lodashStable.map(values, alwaysFalse);
892 var actual = lodashStable.map(values, function(args) {
893 return func.apply(undefined, args);
896 assert.deepEqual(actual, expected);
904 /*--------------------------------------------------------------------------*/
906 QUnit.module('isIterateeCall');
910 func = _._isIterateeCall,
913 QUnit.test('should return `true` for iteratee calls', function(assert) {
920 assert.strictEqual(func(1, 0, array), true);
921 assert.strictEqual(func(1, 'a', object), true);
922 assert.strictEqual(func(1, 'a', new Foo), true);
925 skipAssert(assert, 3);
929 QUnit.test('should return `false` for non-iteratee calls', function(assert) {
933 assert.strictEqual(func(2, 0, array), false);
934 assert.strictEqual(func(1, 1.1, array), false);
935 assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
936 assert.strictEqual(func(1, 'b', object), false);
939 skipAssert(assert, 4);
943 QUnit.test('should work with `NaN` values', function(assert) {
947 assert.strictEqual(func(NaN, 0, [NaN]), true);
948 assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
951 skipAssert(assert, 2);
955 QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
960 var actual = func(1, { 'toString': null }, [1]);
962 var message = e.message;
964 assert.strictEqual(actual, false, message || '');
972 /*--------------------------------------------------------------------------*/
974 QUnit.module('lodash constructor');
977 var values = empties.concat(true, 1, 'a'),
978 expected = lodashStable.map(values, alwaysTrue);
980 QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
984 var actual = lodashStable.map(values, function(value) {
985 return _(value) instanceof _;
988 assert.deepEqual(actual, expected);
995 QUnit.test('should return the given `lodash` instances', function(assert) {
999 var actual = lodashStable.map(values, function(value) {
1000 var wrapped = _(value);
1001 return _(wrapped) === wrapped;
1004 assert.deepEqual(actual, expected);
1011 QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
1014 if (!isNpm && lodashBizarro) {
1015 var actual = lodashStable.map(values, function(value) {
1016 var wrapped = _(lodashBizarro(value)),
1017 unwrapped = wrapped.value();
1019 return wrapped instanceof _ &&
1020 ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
1023 assert.deepEqual(actual, expected);
1031 /*--------------------------------------------------------------------------*/
1033 QUnit.module('lodash.add');
1036 QUnit.test('should add two numbers', function(assert) {
1039 assert.strictEqual(_.add(6, 4), 10);
1040 assert.strictEqual(_.add(-6, 4), -2);
1041 assert.strictEqual(_.add(-6, -4), -10);
1044 QUnit.test('should return `0` when no arguments are given', function(assert) {
1047 assert.strictEqual(_.add(), 0);
1050 QUnit.test('should not coerce arguments to numbers', function(assert) {
1053 assert.strictEqual(_.add('6', '4'), '64');
1054 assert.strictEqual(_.add('x', 'y'), 'xy');
1057 QUnit.test('should work with only an `augend` or `addend`', function(assert) {
1060 assert.strictEqual(_.add(6), 6);
1061 assert.strictEqual(_.add(6, undefined), 6);
1062 assert.strictEqual(_.add(undefined, 4), 4);
1065 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1069 assert.strictEqual(_(1).add(2), 3);
1076 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1080 assert.ok(_(1).chain().add(2) instanceof _);
1088 /*--------------------------------------------------------------------------*/
1090 QUnit.module('lodash.after');
1093 function after(n, times) {
1095 lodashStable.times(times, _.after(n, function() { count++; }));
1099 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1102 assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
1103 assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
1104 assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
1105 assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
1108 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1111 assert.strictEqual(after(NaN, 1), 1);
1114 QUnit.test('should not set a `this` binding', function(assert) {
1117 var after = _.after(1, function(assert) { return ++this.count; }),
1118 object = { 'after': after, 'count': 0 };
1121 assert.strictEqual(object.after(), 2);
1122 assert.strictEqual(object.count, 2);
1126 /*--------------------------------------------------------------------------*/
1128 QUnit.module('lodash.ary');
1131 function fn(a, b, c) {
1132 return slice.call(arguments);
1135 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
1138 var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
1139 assert.deepEqual(actual, [6, 8, 10]);
1141 var capped = _.ary(fn, 2);
1142 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
1145 QUnit.test('should use `func.length` if `n` is not given', function(assert) {
1148 var capped = _.ary(fn);
1149 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
1152 QUnit.test('should treat a negative `n` as `0`', function(assert) {
1155 var capped = _.ary(fn, -1);
1158 var actual = capped('a');
1161 assert.deepEqual(actual, []);
1164 QUnit.test('should coerce `n` to an integer', function(assert) {
1167 var values = ['1', 1.6, 'xyz'],
1168 expected = [['a'], ['a'], []];
1170 var actual = lodashStable.map(values, function(n) {
1171 var capped = _.ary(fn, n);
1172 return capped('a', 'b');
1175 assert.deepEqual(actual, expected);
1178 QUnit.test('should work when given less than the capped number of arguments', function(assert) {
1181 var capped = _.ary(fn, 3);
1182 assert.deepEqual(capped('a'), ['a']);
1185 QUnit.test('should use the existing `ary` if smaller', function(assert) {
1188 var capped = _.ary(_.ary(fn, 1), 2);
1189 assert.deepEqual(capped('a', 'b', 'c'), ['a']);
1192 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
1195 var funcs = lodashStable.map([fn], _.ary),
1196 actual = funcs[0]('a', 'b', 'c');
1198 assert.deepEqual(actual, ['a', 'b', 'c']);
1201 QUnit.test('should work when combined with other methods that use metadata', function(assert) {
1204 var array = ['a', 'b', 'c'],
1205 includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
1207 assert.strictEqual(includes('b')(array, 2), true);
1210 includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
1211 assert.strictEqual(includes('b')(array, 2), true);
1219 /*--------------------------------------------------------------------------*/
1221 QUnit.module('lodash.assignIn');
1224 QUnit.test('should be aliased', function(assert) {
1227 assert.strictEqual(_.extend, _.assignIn);
1231 /*--------------------------------------------------------------------------*/
1233 QUnit.module('lodash.assign and lodash.assignIn');
1235 lodashStable.each(['assign', 'assignIn'], function(methodName) {
1236 var func = _[methodName];
1238 QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
1241 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
1244 QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
1247 var expected = { 'a': 1, 'b': 2, 'c': 3 };
1248 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
1249 assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
1252 QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
1255 var expected = { 'a': 3, 'b': 2, 'c': 1 };
1256 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1259 QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
1262 var expected = { 'a': null, 'b': undefined, 'c': null };
1263 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1266 QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
1272 'configurable': true,
1274 'set': function() { throw new Error; }
1282 'constructor': Object,
1283 'toString': lodashStable.constant('source')
1286 defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
1290 defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
1291 'get': alwaysUndefined
1294 defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
1298 defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
1299 'get': lodashStable.constant(Object)
1303 var actual = func(object, source);
1306 assert.deepEqual(actual, source);
1310 /*--------------------------------------------------------------------------*/
1312 QUnit.module('lodash.assignInWith');
1315 QUnit.test('should be aliased', function(assert) {
1318 assert.strictEqual(_.extendWith, _.assignInWith);
1322 /*--------------------------------------------------------------------------*/
1324 QUnit.module('lodash.assignWith and lodash.assignInWith');
1326 lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
1327 var func = _[methodName];
1329 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
1332 var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
1333 return a === undefined ? b : a;
1336 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
1339 QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
1342 var expected = { 'a': undefined };
1343 assert.deepEqual(func({}, expected, alwaysUndefined), expected);
1347 /*--------------------------------------------------------------------------*/
1349 QUnit.module('lodash.at');
1352 var args = arguments,
1353 array = ['a', 'b', 'c'],
1354 object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
1356 QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
1359 var actual = _.at(array, [0, 2]);
1360 assert.deepEqual(actual, ['a', 'c']);
1363 QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
1366 var actual = _.at(array, [2, 4, 0]);
1367 assert.deepEqual(actual, ['c', undefined, 'a']);
1370 QUnit.test('should work with non-index keys on array values', function(assert) {
1373 var values = lodashStable.reject(empties, function(value) {
1374 return (value === 0) || lodashStable.isArray(value);
1377 var array = lodashStable.transform(values, function(result, value) {
1381 var expected = lodashStable.map(values, alwaysOne),
1382 actual = _.at(array, values);
1384 assert.deepEqual(actual, expected);
1387 QUnit.test('should return an empty array when no keys are given', function(assert) {
1390 assert.deepEqual(_.at(array), []);
1391 assert.deepEqual(_.at(array, [], []), []);
1394 QUnit.test('should accept multiple key arguments', function(assert) {
1397 var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
1398 assert.deepEqual(actual, ['d', 'a', 'c']);
1401 QUnit.test('should work with a falsey `object` argument when keys are given', function(assert) {
1404 var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
1406 var actual = lodashStable.map(falsey, function(object) {
1408 return _.at(object, 0, 1, 'pop', 'push');
1412 assert.deepEqual(actual, expected);
1415 QUnit.test('should work with an `arguments` object for `object`', function(assert) {
1418 var actual = _.at(args, [2, 0]);
1419 assert.deepEqual(actual, [3, 1]);
1422 QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
1425 var actual = _.at([1, 2, 3, 4, 5], args);
1426 assert.deepEqual(actual, [2, 3, 4]);
1429 QUnit.test('should work with an object for `object`', function(assert) {
1432 var actual = _.at(object, ['a[0].b.c', 'a[1]']);
1433 assert.deepEqual(actual, [3, 4]);
1436 QUnit.test('should pluck inherited property values', function(assert) {
1439 function Foo() { this.a = 1; }
1440 Foo.prototype.b = 2;
1442 var actual = _.at(new Foo, 'b');
1443 assert.deepEqual(actual, [2]);
1446 QUnit.test('should work in a lazy sequence', function(assert) {
1450 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
1453 lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
1454 lodashStable.times(2, function(index) {
1455 var array = index ? largeArray : smallArray,
1456 wrapped = _(array).map(identity).at(paths);
1458 assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
1463 skipAssert(assert, 6);
1467 QUnit.test('should support shortcut fusion', function(assert) {
1471 var array = lodashStable.range(LARGE_ARRAY_SIZE),
1473 iteratee = function(value) { count++; return square(value); },
1474 lastIndex = LARGE_ARRAY_SIZE - 1;
1476 lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
1478 var actual = _(array).map(iteratee).at(n).value(),
1479 expected = index < 2 ? 1 : 0;
1481 assert.strictEqual(count, expected);
1483 expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
1484 assert.deepEqual(actual, expected);
1488 skipAssert(assert, 8);
1492 QUnit.test('work with an object for `object` when chaining', function(assert) {
1496 var paths = ['a[0].b.c', 'a[1]'],
1497 actual = _(object).map(identity).at(paths).value();
1499 assert.deepEqual(actual, _.at(_.map(object, identity), paths));
1501 var indexObject = { '0': 1 };
1502 actual = _(indexObject).at(0).value();
1503 assert.deepEqual(actual, _.at(indexObject, 0));
1506 skipAssert(assert, 2);
1511 /*--------------------------------------------------------------------------*/
1513 QUnit.module('lodash.attempt');
1516 QUnit.test('should return the result of `func`', function(assert) {
1519 assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
1522 QUnit.test('should provide additional arguments to `func`', function(assert) {
1525 var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
1526 assert.deepEqual(actual, [1, 2]);
1529 QUnit.test('should return the caught error', function(assert) {
1532 var expected = lodashStable.map(errors, alwaysTrue);
1534 var actual = lodashStable.map(errors, function(error) {
1535 return _.attempt(function() { throw error; }) === error;
1538 assert.deepEqual(actual, expected);
1541 QUnit.test('should coerce errors to error objects', function(assert) {
1544 var actual = _.attempt(function() { throw 'x'; });
1545 assert.ok(lodashStable.isEqual(actual, Error('x')));
1548 QUnit.test('should preserve custom errors', function(assert) {
1551 var actual = _.attempt(function() { throw new CustomError('x'); });
1552 assert.ok(actual instanceof CustomError);
1555 QUnit.test('should work with an error object from another realm', function(assert) {
1559 var expected = lodashStable.map(realm.errors, alwaysTrue);
1561 var actual = lodashStable.map(realm.errors, function(error) {
1562 return _.attempt(function() { throw error; }) === error;
1565 assert.deepEqual(actual, expected);
1572 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1576 assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
1583 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1587 assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
1595 /*--------------------------------------------------------------------------*/
1597 QUnit.module('lodash.before');
1600 function before(n, times) {
1602 lodashStable.times(times, _.before(n, function() { count++; }));
1606 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1609 assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
1610 assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
1611 assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
1612 assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
1615 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1618 assert.strictEqual(before(NaN, 1), 0);
1621 QUnit.test('should not set a `this` binding', function(assert) {
1624 var before = _.before(2, function(assert) { return ++this.count; }),
1625 object = { 'before': before, 'count': 0 };
1628 assert.strictEqual(object.before(), 1);
1629 assert.strictEqual(object.count, 1);
1633 /*--------------------------------------------------------------------------*/
1635 QUnit.module('lodash.bind');
1639 var result = [this];
1640 push.apply(result, arguments);
1644 QUnit.test('should bind a function to an object', function(assert) {
1648 bound = _.bind(fn, object);
1650 assert.deepEqual(bound('a'), [object, 'a']);
1653 QUnit.test('should accept a falsey `thisArg` argument', function(assert) {
1656 var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
1657 expected = lodashStable.map(values, function(value) { return [value]; });
1659 var actual = lodashStable.map(values, function(value) {
1661 var bound = _.bind(fn, value);
1666 assert.ok(lodashStable.every(actual, function(value, index) {
1667 return lodashStable.isEqual(value, expected[index]);
1671 QUnit.test('should bind a function to nullish values', function(assert) {
1674 var bound = _.bind(fn, null),
1675 actual = bound('a');
1677 assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
1678 assert.strictEqual(actual[1], 'a');
1680 lodashStable.times(2, function(index) {
1681 bound = index ? _.bind(fn, undefined) : _.bind(fn);
1682 actual = bound('b');
1684 assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
1685 assert.strictEqual(actual[1], 'b');
1689 QUnit.test('should partially apply arguments ', function(assert) {
1693 bound = _.bind(fn, object, 'a');
1695 assert.deepEqual(bound(), [object, 'a']);
1697 bound = _.bind(fn, object, 'a');
1698 assert.deepEqual(bound('b'), [object, 'a', 'b']);
1700 bound = _.bind(fn, object, 'a', 'b');
1701 assert.deepEqual(bound(), [object, 'a', 'b']);
1702 assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
1705 QUnit.test('should support placeholders', function(assert) {
1709 ph = _.bind.placeholder,
1710 bound = _.bind(fn, object, ph, 'b', ph);
1712 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
1713 assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
1714 assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
1715 assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
1718 QUnit.test('should use `_.placeholder` when set', function(assert) {
1721 if (!isModularize) {
1722 var _ph = _.placeholder = {},
1723 ph = _.bind.placeholder,
1725 bound = _.bind(fn, object, _ph, 'b', ph);
1727 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']);
1728 delete _.placeholder;
1735 QUnit.test('should create a function with a `length` of `0`', function(assert) {
1738 var fn = function(a, b, c) {},
1739 bound = _.bind(fn, {});
1741 assert.strictEqual(bound.length, 0);
1743 bound = _.bind(fn, {}, 1);
1744 assert.strictEqual(bound.length, 0);
1747 QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
1754 var bound = _.bind(Foo, { 'a': 1 }),
1755 newBound = new bound;
1757 assert.strictEqual(bound().a, 1);
1758 assert.strictEqual(newBound.a, undefined);
1759 assert.ok(newBound instanceof Foo);
1762 QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
1771 var thisArg = { 'a': 1 },
1772 boundFoo = _.bind(Foo, thisArg),
1773 boundBar = _.bind(Bar, thisArg),
1775 expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
1777 var actual = lodashStable.times(count, function(index) {
1780 case 0: return [new boundFoo().a, new boundBar().a];
1781 case 1: return [new boundFoo(1).a, new boundBar(1).a];
1782 case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
1783 case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
1784 case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
1785 case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
1786 case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
1787 case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
1788 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];
1793 assert.deepEqual(actual, expected);
1796 QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
1799 function Foo(value) {
1800 return value && object;
1803 var bound = _.bind(Foo),
1806 assert.ok(new bound instanceof Foo);
1807 assert.strictEqual(new bound(true), object);
1810 QUnit.test('should append array arguments to partially applied arguments', function(assert) {
1814 bound = _.bind(fn, object, 'a');
1816 assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
1819 QUnit.test('should not rebind functions', function(assert) {
1826 var bound1 = _.bind(fn, object1),
1827 bound2 = _.bind(bound1, object2, 'a'),
1828 bound3 = _.bind(bound1, object3, 'b');
1830 assert.deepEqual(bound1(), [object1]);
1831 assert.deepEqual(bound2(), [object1, 'a']);
1832 assert.deepEqual(bound3(), [object1, 'b']);
1835 QUnit.test('should not error when instantiating bound built-ins', function(assert) {
1838 var Ctor = _.bind(Date, null),
1839 expected = new Date(2012, 4, 23, 0, 0, 0, 0);
1842 var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
1845 assert.deepEqual(actual, expected);
1847 Ctor = _.bind(Date, null, 2012, 4, 23);
1850 actual = new Ctor(0, 0, 0, 0);
1853 assert.deepEqual(actual, expected);
1856 QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
1859 var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
1861 if (typeof createCtor == 'function') {
1862 var bound = _.bind(createCtor()),
1864 expected = lodashStable.times(count, alwaysTrue);
1866 var actual = lodashStable.times(count, function(index) {
1869 case 0: return !!(new bound);
1870 case 1: return !!(new bound(1));
1871 case 2: return !!(new bound(1, 2));
1872 case 3: return !!(new bound(1, 2, 3));
1873 case 4: return !!(new bound(1, 2, 3, 4));
1874 case 5: return !!(new bound(1, 2, 3, 4, 5));
1875 case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
1876 case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
1881 assert.deepEqual(actual, expected);
1888 QUnit.test('should return a wrapped value when chaining', function(assert) {
1893 bound = _(fn).bind({}, 'a', 'b');
1895 assert.ok(bound instanceof _);
1897 var actual = bound.value()('c');
1898 assert.deepEqual(actual, [object, 'a', 'b', 'c']);
1901 skipAssert(assert, 2);
1906 /*--------------------------------------------------------------------------*/
1908 QUnit.module('lodash.bindAll');
1911 var args = arguments;
1918 'a': function() { return this._a; },
1919 'b': function() { return this._b; },
1920 'c': function() { return this._c; },
1921 'd': function() { return this._d; }
1924 QUnit.test('should accept individual method names', function(assert) {
1927 var object = lodashStable.cloneDeep(source);
1928 _.bindAll(object, 'a', 'b');
1930 var actual = lodashStable.map(['a', 'b', 'c'], function(methodName) {
1931 return object[methodName].call({});
1934 assert.deepEqual(actual, [1, 2, undefined]);
1937 QUnit.test('should accept arrays of method names', function(assert) {
1940 var object = lodashStable.cloneDeep(source);
1941 _.bindAll(object, ['a', 'b'], ['c']);
1943 var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(methodName) {
1944 return object[methodName].call({});
1947 assert.deepEqual(actual, [1, 2, 3, undefined]);
1950 QUnit.test('should work with an array `object` argument', function(assert) {
1953 var array = ['push', 'pop'];
1955 assert.strictEqual(array.pop, arrayProto.pop);
1958 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
1961 var object = lodashStable.cloneDeep(source);
1962 _.bindAll(object, args);
1964 var actual = lodashStable.map(args, function(methodName) {
1965 return object[methodName].call({});
1968 assert.deepEqual(actual, [1]);
1972 /*--------------------------------------------------------------------------*/
1974 QUnit.module('lodash.bindKey');
1977 QUnit.test('should work when the target function is overwritten', function(assert) {
1982 'greet': function(greeting) {
1983 return this.user + ' says: ' + greeting;
1987 var bound = _.bindKey(object, 'greet', 'hi');
1988 assert.strictEqual(bound(), 'fred says: hi');
1990 object.greet = function(greeting) {
1991 return this.user + ' says: ' + greeting + '!';
1994 assert.strictEqual(bound(), 'fred says: hi!');
1997 QUnit.test('should support placeholders', function(assert) {
2002 return slice.call(arguments);
2006 var ph = _.bindKey.placeholder,
2007 bound = _.bindKey(object, 'fn', ph, 'b', ph);
2009 assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
2010 assert.deepEqual(bound('a'), ['a', 'b', undefined]);
2011 assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
2012 assert.deepEqual(bound(), [undefined, 'b', undefined]);
2015 QUnit.test('should use `_.placeholder` when set', function(assert) {
2018 if (!isModularize) {
2021 return slice.call(arguments);
2025 var _ph = _.placeholder = {},
2026 ph = _.bindKey.placeholder,
2027 bound = _.bindKey(object, 'fn', _ph, 'b', ph);
2029 assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']);
2030 delete _.placeholder;
2037 QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
2040 function Foo(value) {
2041 return value && object;
2044 var object = { 'Foo': Foo },
2045 bound = _.bindKey(object, 'Foo');
2047 assert.ok(new bound instanceof Foo);
2048 assert.strictEqual(new bound(true), object);
2052 /*--------------------------------------------------------------------------*/
2054 QUnit.module('case methods');
2056 lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
2057 var methodName = caseName + 'Case',
2058 func = _[methodName];
2061 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
2062 'FOO BAR', 'fooBar', '--foo-bar', '__foo_bar__'
2065 var converted = (function() {
2067 case 'camel': return 'fooBar';
2068 case 'kebab': return 'foo-bar';
2069 case 'lower': return 'foo bar';
2070 case 'snake': return 'foo_bar';
2071 case 'start': return 'Foo Bar';
2072 case 'upper': return 'FOO BAR';
2076 QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
2079 var actual = lodashStable.map(strings, function(string) {
2080 return func(string) === converted;
2083 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
2086 QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
2089 var actual = lodashStable.map(strings, function(string) {
2090 return func(func(string)) === converted;
2093 assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
2096 QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
2099 var actual = lodashStable.map(burredLetters, function(burred, index) {
2100 var letter = deburredLetters[index];
2101 if (caseName == 'start') {
2102 letter = lodashStable.capitalize(letter);
2103 } else if (caseName == 'upper') {
2104 letter = letter.toUpperCase();
2106 letter = letter.toLowerCase();
2108 return func(burred) === letter;
2111 assert.deepEqual(actual, lodashStable.map(burredLetters, alwaysTrue));
2114 QUnit.test('`_.' + methodName + '` should trim latin-1 mathematical operators', function(assert) {
2117 var actual = lodashStable.map(['\xd7', '\xf7'], func);
2118 assert.deepEqual(actual, ['', '']);
2121 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
2124 var string = 'foo bar';
2125 assert.strictEqual(func(Object(string)), converted);
2126 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
2129 QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
2133 assert.strictEqual(_('foo bar')[methodName](), converted);
2140 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
2144 assert.ok(_('foo bar').chain()[methodName]() instanceof _);
2153 QUnit.test('should get the original value after cycling through all case methods', function(assert) {
2156 var funcs = [_.camelCase, _.kebabCase, _.snakeCase, _.startCase, _.camelCase];
2158 var actual = lodashStable.reduce(funcs, function(result, func) {
2159 return func(result);
2160 }, 'enable 6h format');
2162 assert.strictEqual(actual, 'enable6HFormat');
2166 /*--------------------------------------------------------------------------*/
2168 QUnit.module('lodash.camelCase');
2171 QUnit.test('should work with numbers', function(assert) {
2174 assert.strictEqual(_.camelCase('12 feet'), '12Feet');
2175 assert.strictEqual(_.camelCase('enable 6h format'), 'enable6HFormat');
2176 assert.strictEqual(_.camelCase('enable 24H format'), 'enable24HFormat');
2177 assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
2178 assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
2179 assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
2182 QUnit.test('should handle acronyms', function(assert) {
2185 lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
2186 assert.strictEqual(_.camelCase(string), 'safeHtml');
2189 lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
2190 assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
2193 lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
2194 assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
2199 /*--------------------------------------------------------------------------*/
2201 QUnit.module('lodash.capitalize');
2204 QUnit.test('should capitalize the first character of a string', function(assert) {
2207 assert.strictEqual(_.capitalize('fred'), 'Fred');
2208 assert.strictEqual(_.capitalize('Fred'), 'Fred');
2209 assert.strictEqual(_.capitalize(' fred'), ' fred');
2213 /*--------------------------------------------------------------------------*/
2215 QUnit.module('lodash.castArray');
2218 QUnit.test('should wrap non array items in an array', function(assert) {
2221 var values = falsey.concat(true, 1, 'a', { 'a': 1 }),
2222 expected = lodashStable.map(values, function(value) { return [value]; }),
2223 actual = lodashStable.map(values, _.castArray);
2225 assert.deepEqual(actual, expected);
2228 QUnit.test('should return array values by reference', function(assert) {
2232 assert.strictEqual(_.castArray(array), array);
2235 QUnit.test('should return an empty array when no arguments are given', function(assert) {
2238 assert.deepEqual(_.castArray(), []);
2242 /*--------------------------------------------------------------------------*/
2244 QUnit.module('lodash.chain');
2247 QUnit.test('should return a wrapped value', function(assert) {
2251 var actual = _.chain({ 'a': 0 });
2252 assert.ok(actual instanceof _);
2259 QUnit.test('should return existing wrapped values', function(assert) {
2263 var wrapped = _({ 'a': 0 });
2264 assert.strictEqual(_.chain(wrapped), wrapped);
2265 assert.strictEqual(wrapped.chain(), wrapped);
2268 skipAssert(assert, 2);
2272 QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
2276 var array = ['c', 'b', 'a'];
2278 assert.ok(_.chain(array).head() instanceof _);
2279 assert.ok(_(array).chain().head() instanceof _);
2281 assert.ok(_.chain(array).isArray() instanceof _);
2282 assert.ok(_(array).chain().isArray() instanceof _);
2284 assert.ok(_.chain(array).sortBy().head() instanceof _);
2285 assert.ok(_(array).chain().sortBy().head() instanceof _);
2288 skipAssert(assert, 6);
2292 QUnit.test('should chain multiple methods', function(assert) {
2296 lodashStable.times(2, function(index) {
2297 var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
2298 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 },
2299 wrapped = index ? _(array).chain() : _.chain(array);
2301 var actual = wrapped
2303 .map(function(value) { return value.split(''); })
2305 .reduce(function(object, chr) {
2306 object[chr] || (object[chr] = 0);
2312 assert.deepEqual(actual, expected);
2314 array = [1, 2, 3, 4, 5, 6];
2315 wrapped = index ? _(array).chain() : _.chain(array);
2318 .filter(function(n) { return n % 2 != 0; })
2319 .reject(function(n) { return n % 3 == 0; })
2320 .sortBy(function(n) { return -n; })
2323 assert.deepEqual(actual, [5, 1]);
2326 wrapped = index ? _(array).chain() : _.chain(array);
2331 .tap(function(value) { value.pop(); })
2335 assert.deepEqual(actual, [25, 16, 9, 4]);
2339 skipAssert(assert, 6);
2344 /*--------------------------------------------------------------------------*/
2346 QUnit.module('lodash.chunk');
2349 var array = [0, 1, 2, 3, 4, 5];
2351 QUnit.test('should return chunked arrays', function(assert) {
2354 var actual = _.chunk(array, 3);
2355 assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
2358 QUnit.test('should return the last chunk as remaining elements', function(assert) {
2361 var actual = _.chunk(array, 4);
2362 assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
2365 QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
2368 var values = falsey.concat(-1, -Infinity),
2369 expected = lodashStable.map(values, alwaysEmptyArray);
2371 var actual = lodashStable.map(values, function(value, index) {
2372 return index ? _.chunk(array, value) : _.chunk(array);
2375 assert.deepEqual(actual, expected);
2378 QUnit.test('should coerce `size` to an integer', function(assert) {
2381 assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
2385 /*--------------------------------------------------------------------------*/
2387 QUnit.module('lodash.clamp');
2390 QUnit.test('should work with a `max` argument', function(assert) {
2393 assert.strictEqual(_.clamp(5, 3), 3);
2394 assert.strictEqual(_.clamp(1, 3), 1);
2397 QUnit.test('should clamp negative numbers', function(assert) {
2400 assert.strictEqual(_.clamp(-10, -5, 5), -5);
2401 assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
2402 assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
2405 QUnit.test('should clamp positive numbers', function(assert) {
2408 assert.strictEqual(_.clamp(10, -5, 5), 5);
2409 assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
2410 assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
2413 QUnit.test('should not alter negative numbers in range', function(assert) {
2416 assert.strictEqual(_.clamp(-4, -5, 5), -4);
2417 assert.strictEqual(_.clamp(-5, -5, 5), -5);
2418 assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
2421 QUnit.test('should not alter positive numbers in range', function(assert) {
2424 assert.strictEqual(_.clamp(4, -5, 5), 4);
2425 assert.strictEqual(_.clamp(5, -5, 5), 5);
2426 assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
2429 QUnit.test('should not alter `0` in range', function(assert) {
2432 assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
2435 QUnit.test('should clamp to `0`', function(assert) {
2438 assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
2441 QUnit.test('should not alter `-0` in range', function(assert) {
2444 assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
2447 QUnit.test('should clamp to `-0`', function(assert) {
2450 assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
2453 QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
2456 assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
2459 QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
2462 assert.deepEqual(_.clamp(1, -5, NaN), 0);
2463 assert.deepEqual(_.clamp(-1, NaN, 5), 0);
2467 /*--------------------------------------------------------------------------*/
2469 QUnit.module('clone methods');
2472 function Foo() { this.a = 1; }
2473 Foo.prototype.b = 1;
2474 Foo.c = function() {};
2487 '`arguments` objects': arguments,
2488 'arrays': ['a', ''],
2489 'array-like-objects': { '0': 'a', '1': '', 'length': 3 },
2491 'boolean objects': Object(false),
2492 'date objects': new Date,
2493 'Foo instances': new Foo,
2494 'objects': { 'a': 0, 'b': 1, 'c': 2 },
2495 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
2496 'objects from another document': realm.object || {},
2498 'null values': null,
2500 'number objects': Object(0),
2504 'string objects': Object('a'),
2505 'undefined values': undefined
2508 objects.arrays.length = 3;
2511 'DOM elements': body,
2513 'generators': generator
2516 lodashStable.each(errors, function(error) {
2517 uncloneable[error.name + 's'] = error;
2520 QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
2523 var array = [{ 'a': 0 }, { 'b': 1 }],
2524 actual = _.clone(array);
2526 assert.deepEqual(actual, array);
2527 assert.ok(actual !== array && actual[0] === array[0]);
2530 QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
2534 'foo': { 'b': { 'c': { 'd': {} } } },
2538 object.foo.b.c.d = object;
2539 object.bar.b = object.foo.b;
2541 var actual = _.cloneDeep(object);
2542 assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
2545 QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
2549 lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
2550 cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
2553 var clone = _.cloneDeep(cyclical),
2554 actual = clone['v' + LARGE_ARRAY_SIZE][0];
2556 assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
2557 assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
2560 QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
2564 keys = [true, false, 1, -Infinity, NaN, {}, null, 'a', symbol || {}, undefined];
2566 var pairs = lodashStable.map(keys, function(key, index) {
2567 var lastIndex = keys.length - 1;
2568 return [key, keys[lastIndex - index]];
2571 _.cloneDeepWith({ 'a': 1 }, function() {
2572 if (arguments.length > 1) {
2573 Stack || (Stack = _.last(arguments).constructor);
2577 var stacks = [new Stack(pairs), new Stack(pairs)];
2579 lodashStable.times(LARGE_ARRAY_SIZE - pairs.length + 1, function() {
2580 stacks[1].set({}, {});
2583 lodashStable.each(stacks, function(stack) {
2584 lodashStable.each(keys, function(key, index) {
2585 var value = pairs[index][1];
2587 assert.deepEqual(stack.get(key), value);
2588 assert.strictEqual(stack.has(key), true);
2589 assert.strictEqual(stack['delete'](key), true);
2590 assert.strictEqual(stack.has(key), false);
2591 assert.strictEqual(stack.get(key), undefined);
2592 assert.strictEqual(stack['delete'](key), false);
2593 assert.strictEqual(stack.set(key, value), stack);
2594 assert.strictEqual(stack.has(key), true);
2597 assert.strictEqual(stack.clear(), undefined);
2598 assert.ok(lodashStable.every(keys, function(key) {
2599 return !stack.has(key);
2604 lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
2605 var func = _[methodName],
2606 isDeep = methodName == 'cloneDeep';
2608 lodashStable.forOwn(objects, function(object, key) {
2609 QUnit.test('`_.' + methodName + '` should clone ' + key, function(assert) {
2612 var isEqual = (key == 'maps' || key == 'sets') ? _.isEqual : lodashStable.isEqual,
2613 actual = func(object);
2615 assert.ok(isEqual(actual, object));
2617 if (lodashStable.isObject(object)) {
2618 assert.notStrictEqual(actual, object);
2620 assert.strictEqual(actual, object);
2625 QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
2629 var actual = func(arrayBuffer);
2630 assert.strictEqual(actual.byteLength, arrayBuffer.byteLength);
2631 assert.notStrictEqual(actual, arrayBuffer);
2634 skipAssert(assert, 2);
2638 QUnit.test('`_.' + methodName + '` should clone buffers', function(assert) {
2642 var buffer = new Buffer([1, 2]),
2643 actual = func(buffer);
2645 assert.strictEqual(actual.byteLength, buffer.byteLength);
2646 assert.strictEqual(actual.inspect(), buffer.inspect());
2647 assert.notStrictEqual(actual, buffer);
2650 assert.strictEqual(actual[0], isDeep ? 2 : 1);
2653 skipAssert(assert, 4);
2657 QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
2660 var array = /c/.exec('abcde'),
2661 actual = func(array);
2663 assert.strictEqual(actual.index, 2);
2664 assert.strictEqual(actual.input, 'abcde');
2667 QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
2670 // Avoid a regexp literal for older Opera and use `exec` for older Safari.
2671 var regexp = RegExp('c', 'g');
2673 regexp.exec('abcde');
2675 var actual = func(regexp);
2676 assert.strictEqual(actual.lastIndex, 3);
2679 QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
2682 var values = lodashStable.map([true, false, 1, 'a'], function(value) {
2683 var object = Object(value);
2688 var expected = lodashStable.map(values, alwaysTrue);
2690 var actual = lodashStable.map(values, function(value) {
2691 return func(value).a === 1;
2694 assert.deepEqual(actual, expected);
2697 QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
2700 var actual = func(Foo.prototype);
2702 assert.notOk(actual instanceof Foo);
2703 assert.deepEqual(actual, { 'b': 1 });
2706 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone', function(assert) {
2709 assert.ok(func(new Foo) instanceof Foo);
2712 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone even when the `constructor` is incorrect', function(assert) {
2715 Foo.prototype.constructor = Object;
2716 assert.ok(func(new Foo) instanceof Foo);
2717 Foo.prototype.constructor = Foo;
2720 QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
2723 Foo.prototype.constructor = null;
2724 assert.notOk(func(new Foo) instanceof Foo);
2725 Foo.prototype.constructor = Foo;
2728 QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
2732 'constructor': objectProto.constructor,
2733 'hasOwnProperty': objectProto.hasOwnProperty,
2734 'isPrototypeOf': objectProto.isPrototypeOf,
2735 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
2736 'toLocaleString': objectProto.toLocaleString,
2737 'toString': objectProto.toString,
2738 'valueOf': objectProto.valueOf
2741 var actual = func(object);
2743 assert.deepEqual(actual, object);
2744 assert.notStrictEqual(actual, object);
2747 QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
2752 object[symbol] = {};
2753 assert.strictEqual(func(object)[symbol], object[symbol]);
2756 object = { 'a': { 'b': {} } };
2757 object.a.b[symbol] = {};
2758 assert.strictEqual(func(object).a.b[symbol], object.a.b[symbol]);
2765 skipAssert(assert, 2);
2769 QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
2773 assert.strictEqual(func(symbol), symbol);
2775 var object = Object(symbol),
2776 actual = func(object);
2778 assert.strictEqual(typeof actual, 'object');
2779 assert.strictEqual(typeof actual.valueOf(), 'symbol');
2780 assert.notStrictEqual(actual, object);
2783 skipAssert(assert, 4);
2787 QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
2791 assert.strictEqual(func(symbol), symbol);
2798 QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
2802 var element = document.createElement('div');
2805 assert.deepEqual(func(element), {});
2807 assert.ok(false, e.message);
2815 QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
2818 var expected = [{ 'a': [0] }, { 'b': [1] }],
2819 actual = lodashStable.map(expected, func);
2821 assert.deepEqual(actual, expected);
2824 assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
2826 assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
2830 QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
2835 var objects = lodashStable.transform(_, function(result, value, key) {
2836 if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) &&
2837 !lodashStable.isArguments(value) && !lodashStable.isElement(value) &&
2838 !lodashStable.isFunction(value)) {
2839 props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
2844 var expected = lodashStable.map(objects, alwaysTrue);
2846 var actual = lodashStable.map(objects, function(object) {
2847 var Ctor = object.constructor,
2848 result = func(object);
2850 return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
2853 assert.deepEqual(actual, expected, props.join(', '));
2856 QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
2860 var object = objects.objects,
2861 actual = _(object)[methodName]();
2863 assert.deepEqual(actual, object);
2864 assert.notStrictEqual(actual, object);
2867 skipAssert(assert, 2);
2871 lodashStable.each(typedArrays, function(type) {
2872 QUnit.test('`_.' + methodName + '` should clone ' + type + ' arrays', function(assert) {
2875 var Ctor = root[type];
2877 lodashStable.times(2, function(index) {
2879 var buffer = new ArrayBuffer(24),
2880 array = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
2881 actual = func(array);
2883 assert.deepEqual(actual, array);
2884 assert.notStrictEqual(actual, array);
2885 assert.strictEqual(actual.buffer === array.buffer, !isDeep);
2886 assert.strictEqual(actual.byteOffset, array.byteOffset);
2887 assert.strictEqual(actual.length, array.length);
2890 skipAssert(assert, 5);
2896 lodashStable.forOwn(uncloneable, function(value, key) {
2897 QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
2901 var object = { 'a': value, 'b': { 'c': value } },
2902 actual = func(object),
2903 expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
2905 assert.deepEqual(actual, object);
2906 assert.notStrictEqual(actual, object);
2907 assert.deepEqual(func(value), expected);
2910 skipAssert(assert, 3);
2916 lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
2917 var func = _[methodName],
2918 isDeep = methodName == 'cloneDeepWith';
2920 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
2926 func(foo, function() {
2927 var length = arguments.length,
2928 args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
2930 argsList.push(args);
2933 assert.deepEqual(argsList, isDeep ? [[foo], [1, 'a', foo]] : [[foo]]);
2936 QUnit.test('`_.' + methodName + '` should handle cloning if `customizer` returns `undefined`', function(assert) {
2939 var actual = func({ 'a': { 'b': 'c' } }, noop);
2940 assert.deepEqual(actual, { 'a': { 'b': 'c' } });
2943 lodashStable.forOwn(uncloneable, function(value, key) {
2944 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
2947 var customizer = function(value) {
2948 return lodashStable.isPlainObject(value) ? undefined : value;
2951 var actual = func(value, customizer);
2953 assert.deepEqual(actual, value);
2954 assert.strictEqual(actual, value);
2956 var object = { 'a': value, 'b': { 'c': value } };
2957 actual = func(object, customizer);
2959 assert.deepEqual(actual, object);
2960 assert.notStrictEqual(actual, object);
2966 /*--------------------------------------------------------------------------*/
2968 QUnit.module('lodash.compact');
2971 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
2973 QUnit.test('should filter falsey values', function(assert) {
2976 var array = ['0', '1', '2'];
2977 assert.deepEqual(_.compact(falsey.concat(array)), array);
2980 QUnit.test('should work when in-between lazy operators', function(assert) {
2984 var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
2985 assert.deepEqual(actual, []);
2987 actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
2988 assert.deepEqual(actual, [true, 1, 'a']);
2991 skipAssert(assert, 2);
2995 QUnit.test('should work in a lazy sequence', function(assert) {
2999 var actual = _(largeArray).slice(1).compact().reverse().take().value();
3000 assert.deepEqual(actual, _.take(_.compact(_.slice(largeArray, 1)).reverse()));
3007 QUnit.test('should work in a lazy sequence with a custom `_.iteratee`', function(assert) {
3010 if (!isModularize) {
3011 var iteratee = _.iteratee,
3014 _.iteratee = identity;
3017 var actual = _(largeArray).slice(1).compact().value();
3018 pass = lodashStable.isEqual(actual, _.compact(_.slice(largeArray, 1)));
3019 } catch (e) {console.log(e);}
3022 _.iteratee = iteratee;
3030 /*--------------------------------------------------------------------------*/
3032 QUnit.module('lodash.concat');
3035 QUnit.test('should concat arrays and values', function(assert) {
3039 actual = _.concat(array, 2, [3], [[4]]);
3041 assert.deepEqual(actual, [1, 2, 3, [4]]);
3042 assert.deepEqual(array, [1]);
3045 QUnit.test('should return an empty array when `array` is nullish', function(assert) {
3048 var values = [, null, undefined],
3049 expected = lodashStable.map(values, alwaysEmptyArray);
3051 var actual = lodashStable.map(values, function(value, index) {
3053 return index ? _.concat(value) : _.concat();
3057 assert.deepEqual(actual, expected);
3060 QUnit.test('should treat nullish `array` values as empty arrays', function(assert) {
3063 var values = [null, undefined],
3064 expected = lodashStable.map(values, lodashStable.constant([1, 2, [3]]));
3066 var actual = lodashStable.map(values, function(value) {
3068 return _.concat(value, 1, [2], [[3]]);
3072 assert.deepEqual(actual, expected);
3075 QUnit.test('should treat sparse arrays as dense', function(assert) {
3079 actual = _.concat(Array(1), Array(1));
3081 expected.push(undefined, undefined);
3083 assert.ok('0'in actual);
3084 assert.ok('1' in actual);
3085 assert.deepEqual(actual, expected);
3088 QUnit.test('should return a new wrapped array', function(assert) {
3093 wrapped = _(array).concat([2, 3]),
3094 actual = wrapped.value();
3096 assert.deepEqual(array, [1]);
3097 assert.deepEqual(actual, [1, 2, 3]);
3100 skipAssert(assert, 2);
3105 /*--------------------------------------------------------------------------*/
3107 QUnit.module('lodash.cond');
3110 QUnit.test('should create a conditional function', function(assert) {
3114 [lodashStable.matches({ 'a': 1 }), alwaysA],
3115 [lodashStable.matchesProperty('b', 1), alwaysB],
3116 [lodashStable.property('c'), alwaysC]
3119 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3120 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3121 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3124 QUnit.test('should provide arguments to functions', function(assert) {
3129 expected = ['a', 'b', 'c'];
3131 var cond = _.cond([[
3132 function() { args1 || (args1 = slice.call(arguments)); return true; },
3133 function() { args2 || (args2 = slice.call(arguments)); }
3136 cond('a', 'b', 'c');
3138 assert.deepEqual(args1, expected);
3139 assert.deepEqual(args2, expected);
3142 QUnit.test('should work with predicate shorthands', function(assert) {
3146 [{ 'a': 1 }, alwaysA],
3147 [['b', 1], alwaysB],
3151 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3152 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3153 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3156 QUnit.test('should return `undefined` when no condition is met', function(assert) {
3159 var cond = _.cond([[alwaysFalse, alwaysA]]);
3160 assert.strictEqual(cond({ 'a': 1 }), undefined);
3163 QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
3166 lodashStable.each([true, false], function(value) {
3167 assert.raises(function() { _.cond([[alwaysTrue, value]])(); }, TypeError);
3171 QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
3175 [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
3178 var object = { 'cond': cond, 'a': 1, 'b': 2 };
3179 assert.strictEqual(object.cond('a', 'b'), 2);
3183 /*--------------------------------------------------------------------------*/
3185 QUnit.module('lodash.conforms');
3194 QUnit.test('should create a function that checks if a given object conforms to `source`', function(assert) {
3197 var conforms = _.conforms({
3198 'b': function(value) { return value > 4; }
3201 var actual = lodashStable.filter(objects, conforms);
3202 assert.deepEqual(actual, [objects[0], objects[2]]);
3204 conforms = _.conforms({
3205 'b': function(value) { return value > 8; },
3206 'a': function(value) { return value > 1; }
3209 actual = lodashStable.filter(objects, conforms);
3210 assert.deepEqual(actual, [objects[2]]);
3213 QUnit.test('should not match by inherited `source` properties', function(assert) {
3217 this.a = function(value) {
3222 Foo.prototype.b = function(value) {
3226 var conforms = _.conforms(new Foo),
3227 actual = lodashStable.filter(objects, conforms);
3229 assert.deepEqual(actual, [objects[1], objects[2]]);
3232 QUnit.test('should not invoke `source` predicates for missing `object` properties', function(assert) {
3237 var conforms = _.conforms({
3238 'a': function() { count++; return true; }
3241 assert.strictEqual(conforms({}), false);
3242 assert.strictEqual(count, 0);
3245 QUnit.test('should work with a function for `object`', function(assert) {
3254 var conforms = _.conforms({
3255 'a': function(value) { return value > 1; }
3258 assert.strictEqual(conforms(Foo), false);
3259 assert.strictEqual(conforms(Bar), true);
3262 QUnit.test('should work with a function for `source`', function(assert) {
3266 Foo.a = function(value) { return value > 1; };
3268 var objects = [{ 'a': 1 }, { 'a': 2 }],
3269 actual = lodashStable.filter(objects, _.conforms(Foo));
3271 assert.deepEqual(actual, [objects[1]]);
3274 QUnit.test('should work with a non-plain `object`', function(assert) {
3280 Foo.prototype.b = 2;
3282 var conforms = _.conforms({
3283 'b': function(value) { return value > 1; }
3286 assert.strictEqual(conforms(new Foo), true);
3289 QUnit.test('should return `false` when `object` is nullish', function(assert) {
3292 var values = [, null, undefined],
3293 expected = lodashStable.map(values, alwaysFalse);
3295 var conforms = _.conforms({
3296 'a': function(value) { return value > 1; }
3299 var actual = lodashStable.map(values, function(value, index) {
3301 return index ? conforms(value) : conforms();
3305 assert.deepEqual(actual, expected);
3308 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
3311 var values = [, null, undefined],
3312 expected = lodashStable.map(values, alwaysTrue),
3313 conforms = _.conforms({});
3315 var actual = lodashStable.map(values, function(value, index) {
3317 return index ? conforms(value) : conforms();
3321 assert.deepEqual(actual, expected);
3324 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
3327 var object = { 'a': 1 },
3328 expected = lodashStable.map(empties, alwaysTrue);
3330 var actual = lodashStable.map(empties, function(value) {
3331 var conforms = _.conforms(value);
3332 return conforms(object);
3335 assert.deepEqual(actual, expected);
3338 QUnit.test('should not change behavior if `source` is modified', function(assert) {
3342 'a': function(value) { return value > 1; }
3345 var object = { 'a': 2 },
3346 conforms = _.conforms(source);
3348 assert.strictEqual(conforms(object), true);
3350 source.a = function(value) { return value < 2; };
3351 assert.strictEqual(conforms(object), true);
3355 /*--------------------------------------------------------------------------*/
3357 QUnit.module('lodash.constant');
3360 QUnit.test('should create a function that returns `value`', function(assert) {
3363 var object = { 'a': 1 },
3364 values = Array(2).concat(empties, true, 1, 'a'),
3365 constant = _.constant(object),
3366 expected = lodashStable.map(values, function() { return true; });
3368 var actual = lodashStable.map(values, function(value, index) {
3370 var result = constant();
3371 } else if (index == 1) {
3372 result = constant.call({});
3374 result = constant(value);
3376 return result === object;
3379 assert.deepEqual(actual, expected);
3382 QUnit.test('should work with falsey values', function(assert) {
3385 var expected = lodashStable.map(falsey, function() { return true; });
3387 var actual = lodashStable.map(falsey, function(value, index) {
3388 var constant = index ? _.constant(value) : _.constant(),
3389 result = constant();
3391 return (result === value) || (result !== result && value !== value);
3394 assert.deepEqual(actual, expected);
3397 QUnit.test('should return a wrapped value when chaining', function(assert) {
3401 var wrapped = _(true).constant();
3402 assert.ok(wrapped instanceof _);
3410 /*--------------------------------------------------------------------------*/
3412 QUnit.module('lodash.countBy');
3415 var array = [6.1, 4.2, 6.3];
3417 QUnit.test('should transform keys by `iteratee`', function(assert) {
3420 var actual = _.countBy(array, Math.floor);
3421 assert.deepEqual(actual, { '4': 1, '6': 2 });
3424 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
3427 var array = [4, 6, 6],
3428 values = [, null, undefined],
3429 expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
3431 var actual = lodashStable.map(values, function(value, index) {
3432 return index ? _.countBy(array, value) : _.countBy(array);
3435 assert.deepEqual(actual, expected);
3438 QUnit.test('should work with "_.property" shorthands', function(assert) {
3441 var actual = _.countBy(['one', 'two', 'three'], 'length');
3442 assert.deepEqual(actual, { '3': 2, '5': 1 });
3445 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
3448 var actual = _.countBy(array, function(n) {
3449 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
3452 assert.deepEqual(actual.constructor, 1);
3453 assert.deepEqual(actual.hasOwnProperty, 2);
3456 QUnit.test('should work with a number for `iteratee`', function(assert) {
3465 assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
3466 assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
3469 QUnit.test('should work with an object for `collection`', function(assert) {
3472 var actual = _.countBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
3473 assert.deepEqual(actual, { '4': 1, '6': 2 });
3476 QUnit.test('should work in a lazy sequence', function(assert) {
3480 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
3481 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
3482 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
3485 var actual = _(array).countBy().map(square).filter(isEven).take().value();
3487 assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
3495 /*--------------------------------------------------------------------------*/
3497 QUnit.module('lodash.create');
3509 QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
3512 Circle.prototype = _.create(Shape.prototype);
3513 Circle.prototype.constructor = Circle;
3515 var actual = new Circle;
3517 assert.ok(actual instanceof Circle);
3518 assert.ok(actual instanceof Shape);
3519 assert.notStrictEqual(Circle.prototype, Shape.prototype);
3522 QUnit.test('should assign `properties` to the created object', function(assert) {
3525 var expected = { 'constructor': Circle, 'radius': 0 };
3526 Circle.prototype = _.create(Shape.prototype, expected);
3528 var actual = new Circle;
3530 assert.ok(actual instanceof Circle);
3531 assert.ok(actual instanceof Shape);
3532 assert.deepEqual(Circle.prototype, expected);
3535 QUnit.test('should assign own properties', function(assert) {
3542 Foo.prototype.b = 2;
3544 assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
3547 QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
3553 var object = _.create(new Foo, { 'a': 1 });
3554 assert.deepEqual(lodashStable.keys(object), ['a']);
3557 QUnit.test('should accept a falsey `prototype` argument', function(assert) {
3560 var expected = lodashStable.map(falsey, alwaysEmptyObject);
3562 var actual = lodashStable.map(falsey, function(prototype, index) {
3563 return index ? _.create(prototype) : _.create();
3566 assert.deepEqual(actual, expected);
3569 QUnit.test('should ignore primitive `prototype` arguments and use an empty object instead', function(assert) {
3572 var primitives = [true, null, 1, 'a', undefined],
3573 expected = lodashStable.map(primitives, alwaysTrue);
3575 var actual = lodashStable.map(primitives, function(value, index) {
3576 return lodashStable.isPlainObject(index ? _.create(value) : _.create());
3579 assert.deepEqual(actual, expected);
3582 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
3585 var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
3586 expected = lodashStable.map(array, alwaysTrue),
3587 objects = lodashStable.map(array, _.create);
3589 var actual = lodashStable.map(objects, function(object) {
3590 return object.a === 1 && !_.keys(object).length;
3593 assert.deepEqual(actual, expected);
3597 /*--------------------------------------------------------------------------*/
3599 QUnit.module('lodash.curry');
3602 function fn(a, b, c, d) {
3603 return slice.call(arguments);
3606 QUnit.test('should curry based on the number of arguments given', function(assert) {
3609 var curried = _.curry(fn),
3610 expected = [1, 2, 3, 4];
3612 assert.deepEqual(curried(1)(2)(3)(4), expected);
3613 assert.deepEqual(curried(1, 2)(3, 4), expected);
3614 assert.deepEqual(curried(1, 2, 3, 4), expected);
3617 QUnit.test('should allow specifying `arity`', function(assert) {
3620 var curried = _.curry(fn, 3),
3621 expected = [1, 2, 3];
3623 assert.deepEqual(curried(1)(2, 3), expected);
3624 assert.deepEqual(curried(1, 2)(3), expected);
3625 assert.deepEqual(curried(1, 2, 3), expected);
3628 QUnit.test('should coerce `arity` to an integer', function(assert) {
3631 var values = ['0', 0.6, 'xyz'],
3632 expected = lodashStable.map(values, alwaysEmptyArray);
3634 var actual = lodashStable.map(values, function(arity) {
3635 return _.curry(fn, arity)();
3638 assert.deepEqual(actual, expected);
3639 assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
3642 QUnit.test('should support placeholders', function(assert) {
3645 var curried = _.curry(fn),
3646 ph = curried.placeholder;
3648 assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
3649 assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
3650 assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
3651 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
3654 QUnit.test('should persist placeholders', function(assert) {
3657 var curried = _.curry(fn),
3658 ph = curried.placeholder,
3659 actual = curried(ph, ph, ph, 'd')('a')(ph)('b')('c');
3661 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3664 QUnit.test('should use `_.placeholder` when set', function(assert) {
3667 if (!isModularize) {
3668 var curried = _.curry(fn),
3669 _ph = _.placeholder = {},
3670 ph = curried.placeholder;
3672 assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]);
3673 delete _.placeholder;
3680 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3683 var curried = _.curry(fn, 3);
3684 assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
3685 assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
3686 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3689 QUnit.test('should return a function with a `length` of `0`', function(assert) {
3692 lodashStable.times(2, function(index) {
3693 var curried = index ? _.curry(fn, 4) : _.curry(fn);
3694 assert.strictEqual(curried.length, 0);
3695 assert.strictEqual(curried(1).length, 0);
3696 assert.strictEqual(curried(1, 2).length, 0);
3700 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3703 var Foo = function(value) {
3704 return value && object;
3707 var curried = _.curry(Foo),
3710 assert.ok(new curried(false) instanceof Foo);
3711 assert.strictEqual(new curried(true), object);
3714 QUnit.test('should not set a `this` binding', function(assert) {
3717 var fn = function(a, b, c) {
3718 var value = this || {};
3719 return [value[a], value[b], value[c]];
3722 var object = { 'a': 1, 'b': 2, 'c': 3 },
3723 expected = [1, 2, 3];
3725 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
3726 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
3727 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3729 assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
3730 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
3731 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
3733 object.curried = _.curry(fn);
3734 assert.deepEqual(object.curried('a')('b')('c'), Array(3));
3735 assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
3736 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3739 QUnit.test('should work with partialed methods', function(assert) {
3742 var curried = _.curry(fn),
3743 expected = [1, 2, 3, 4];
3745 var a = _.partial(curried, 1),
3746 b = _.bind(a, null, 2),
3747 c = _.partialRight(b, 4),
3748 d = _.partialRight(b(3), 4);
3750 assert.deepEqual(c(3), expected);
3751 assert.deepEqual(d(), expected);
3755 /*--------------------------------------------------------------------------*/
3757 QUnit.module('lodash.curryRight');
3760 function fn(a, b, c, d) {
3761 return slice.call(arguments);
3764 QUnit.test('should curry based on the number of arguments given', function(assert) {
3767 var curried = _.curryRight(fn),
3768 expected = [1, 2, 3, 4];
3770 assert.deepEqual(curried(4)(3)(2)(1), expected);
3771 assert.deepEqual(curried(3, 4)(1, 2), expected);
3772 assert.deepEqual(curried(1, 2, 3, 4), expected);
3775 QUnit.test('should allow specifying `arity`', function(assert) {
3778 var curried = _.curryRight(fn, 3),
3779 expected = [1, 2, 3];
3781 assert.deepEqual(curried(3)(1, 2), expected);
3782 assert.deepEqual(curried(2, 3)(1), expected);
3783 assert.deepEqual(curried(1, 2, 3), expected);
3786 QUnit.test('should coerce `arity` to an integer', function(assert) {
3789 var values = ['0', 0.6, 'xyz'],
3790 expected = lodashStable.map(values, alwaysEmptyArray);
3792 var actual = lodashStable.map(values, function(arity) {
3793 return _.curryRight(fn, arity)();
3796 assert.deepEqual(actual, expected);
3797 assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
3800 QUnit.test('should support placeholders', function(assert) {
3803 var curried = _.curryRight(fn),
3804 expected = [1, 2, 3, 4],
3805 ph = curried.placeholder;
3807 assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
3808 assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
3809 assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
3810 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
3813 QUnit.test('should persist placeholders', function(assert) {
3816 var curried = _.curryRight(fn),
3817 ph = curried.placeholder,
3818 actual = curried('a', ph, ph, ph)('b')(ph)('c')('d');
3820 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3823 QUnit.test('should use `_.placeholder` when set', function(assert) {
3826 if (!isModularize) {
3827 var curried = _.curryRight(fn),
3828 _ph = _.placeholder = {},
3829 ph = curried.placeholder;
3831 assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]);
3832 delete _.placeholder;
3839 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3842 var curried = _.curryRight(fn, 3);
3843 assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
3844 assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
3845 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3848 QUnit.test('should return a function with a `length` of `0`', function(assert) {
3851 lodashStable.times(2, function(index) {
3852 var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
3853 assert.strictEqual(curried.length, 0);
3854 assert.strictEqual(curried(4).length, 0);
3855 assert.strictEqual(curried(3, 4).length, 0);
3859 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3862 var Foo = function(value) {
3863 return value && object;
3866 var curried = _.curryRight(Foo),
3869 assert.ok(new curried(false) instanceof Foo);
3870 assert.strictEqual(new curried(true), object);
3873 QUnit.test('should not set a `this` binding', function(assert) {
3876 var fn = function(a, b, c) {
3877 var value = this || {};
3878 return [value[a], value[b], value[c]];
3881 var object = { 'a': 1, 'b': 2, 'c': 3 },
3882 expected = [1, 2, 3];
3884 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
3885 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
3886 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3888 assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
3889 assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
3890 assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
3892 object.curried = _.curryRight(fn);
3893 assert.deepEqual(object.curried('c')('b')('a'), Array(3));
3894 assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
3895 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3898 QUnit.test('should work with partialed methods', function(assert) {
3901 var curried = _.curryRight(fn),
3902 expected = [1, 2, 3, 4];
3904 var a = _.partialRight(curried, 4),
3905 b = _.partialRight(a, 3),
3906 c = _.bind(b, null, 1),
3907 d = _.partial(b(2), 1);
3909 assert.deepEqual(c(2), expected);
3910 assert.deepEqual(d(), expected);
3914 /*--------------------------------------------------------------------------*/
3916 QUnit.module('curry methods');
3918 lodashStable.each(['curry', 'curryRight'], function(methodName) {
3919 var func = _[methodName],
3920 fn = function(a, b) { return slice.call(arguments); },
3921 isCurry = methodName == 'curry';
3923 QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
3926 function run(a, b) {
3930 var curried = func(run);
3933 var actual = curried(1)(2);
3936 assert.strictEqual(actual, 3);
3939 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
3942 var array = [fn, fn, fn],
3943 object = { 'a': fn, 'b': fn, 'c': fn };
3945 lodashStable.each([array, object], function(collection) {
3946 var curries = lodashStable.map(collection, func),
3947 expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
3949 var actual = lodashStable.map(curries, function(curried) {
3950 return curried('a')('b');
3953 assert.deepEqual(actual, expected);
3957 QUnit.test('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function(assert) {
3960 var curried = _.curry(function hasOwnProperty(a, b, c) {
3964 var expected = [1, 2, 3];
3966 assert.deepEqual(curried(1)(2)(3), expected);
3970 /*--------------------------------------------------------------------------*/
3972 QUnit.module('lodash.debounce');
3975 QUnit.test('should debounce a function', function(assert) {
3978 var done = assert.async();
3981 debounced = _.debounce(function() { callCount++; }, 32);
3987 assert.strictEqual(callCount, 0);
3989 setTimeout(function() {
3990 assert.strictEqual(callCount, 1);
3995 QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
3998 var done = assert.async();
4000 var debounced = _.debounce(identity, 32);
4003 setTimeout(function() {
4004 assert.notEqual(debounced('y'), 'y');
4007 setTimeout(function() {
4008 assert.notEqual(debounced('z'), 'z');
4013 QUnit.test('subsequent "immediate" debounced calls return the last `func` result', function(assert) {
4016 var done = assert.async();
4018 var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
4019 result = [debounced('x'), debounced('y')];
4021 assert.deepEqual(result, ['x', 'x']);
4023 setTimeout(function() {
4024 var result = [debounced('a'), debounced('b')];
4025 assert.deepEqual(result, ['a', 'a']);
4030 QUnit.test('should apply default options', function(assert) {
4033 var done = assert.async();
4037 var debounced = _.debounce(function(value) {
4042 assert.strictEqual(debounced('a'), undefined);
4044 setTimeout(function() {
4045 assert.strictEqual(callCount, 1);
4050 QUnit.test('should support a `leading` option', function(assert) {
4053 var done = assert.async();
4055 var callCounts = [0, 0];
4057 var withLeading = _.debounce(function(value) {
4060 }, 32, { 'leading': true });
4062 assert.strictEqual(withLeading('a'), 'a');
4064 var withoutLeading = _.debounce(identity, 32, { 'leading': false });
4065 assert.strictEqual(withoutLeading('a'), undefined);
4067 var withLeadingAndTrailing = _.debounce(function() {
4069 }, 32, { 'leading': true });
4071 withLeadingAndTrailing();
4072 withLeadingAndTrailing();
4074 assert.strictEqual(callCounts[1], 1);
4076 setTimeout(function() {
4077 assert.deepEqual(callCounts, [1, 2]);
4080 assert.strictEqual(callCounts[0], 2);
4086 QUnit.test('should support a `trailing` option', function(assert) {
4089 var done = assert.async();
4094 var withTrailing = _.debounce(function(value) {
4097 }, 32, { 'trailing': true });
4099 var withoutTrailing = _.debounce(function(value) {
4102 }, 32, { 'trailing': false });
4104 assert.strictEqual(withTrailing('a'), undefined);
4105 assert.strictEqual(withoutTrailing('a'), undefined);
4107 setTimeout(function() {
4108 assert.strictEqual(withCount, 1);
4109 assert.strictEqual(withoutCount, 0);
4114 QUnit.test('should support a `maxWait` option', function(assert) {
4117 var done = assert.async();
4119 var limit = (argv || isPhantom) ? 1000 : 320,
4123 var withMaxWait = _.debounce(function() {
4125 }, 64, { 'maxWait': 128 });
4127 var withoutMaxWait = _.debounce(function() {
4131 var start = +new Date;
4132 while ((new Date - start) < limit) {
4136 var actual = [Boolean(withCount), Boolean(withoutCount)];
4138 setTimeout(function() {
4139 assert.deepEqual(actual, [true, false]);
4144 QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
4147 var done = assert.async();
4151 var debounced = _.debounce(function() {
4153 }, 32, { 'maxWait': 64 });
4157 setTimeout(function() {
4159 assert.strictEqual(callCount, 1);
4162 setTimeout(function() {
4163 assert.strictEqual(callCount, 2);
4168 QUnit.test('should invoke the `trailing` call with the correct arguments and `this` binding', function(assert) {
4171 var done = assert.async();
4177 var debounced = _.debounce(function(value) {
4179 push.apply(actual, arguments);
4180 return ++callCount != 2;
4181 }, 32, { 'leading': true, 'maxWait': 64 });
4184 if (!debounced.call(object, 'a')) {
4188 setTimeout(function() {
4189 assert.strictEqual(callCount, 2);
4190 assert.deepEqual(actual, [object, 'a']);
4196 /*--------------------------------------------------------------------------*/
4198 QUnit.module('lodash.deburr');
4201 QUnit.test('should convert latin-1 supplementary letters to basic latin', function(assert) {
4204 var actual = lodashStable.map(burredLetters, _.deburr);
4205 assert.deepEqual(actual, deburredLetters);
4208 QUnit.test('should not deburr latin-1 mathematical operators', function(assert) {
4211 var operators = ['\xd7', '\xf7'],
4212 actual = lodashStable.map(operators, _.deburr);
4214 assert.deepEqual(actual, operators);
4217 QUnit.test('should deburr combining diacritical marks', function(assert) {
4220 var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
4222 var actual = lodashStable.map(comboMarks, function(chr) {
4223 return _.deburr('e' + chr + 'i');
4226 assert.deepEqual(actual, expected);
4230 /*--------------------------------------------------------------------------*/
4232 QUnit.module('lodash.defaults');
4235 QUnit.test('should assign source properties if missing on `object`', function(assert) {
4238 assert.deepEqual(_.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 }), { 'a': 1, 'b': 2 });
4241 QUnit.test('should accept multiple sources', function(assert) {
4244 var expected = { 'a': 1, 'b': 2, 'c': 3 };
4245 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 }), expected);
4246 assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 }), expected);
4249 QUnit.test('should not overwrite `null` values', function(assert) {
4252 var actual = _.defaults({ 'a': null }, { 'a': 1 });
4253 assert.strictEqual(actual.a, null);
4256 QUnit.test('should overwrite `undefined` values', function(assert) {
4259 var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
4260 assert.strictEqual(actual.a, 1);
4263 QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
4267 'constructor': objectProto.constructor,
4268 'hasOwnProperty': objectProto.hasOwnProperty,
4269 'isPrototypeOf': objectProto.isPrototypeOf,
4270 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
4271 'toLocaleString': objectProto.toLocaleString,
4272 'toString': objectProto.toString,
4273 'valueOf': objectProto.valueOf
4278 'hasOwnProperty': 2,
4280 'propertyIsEnumerable': 4,
4281 'toLocaleString': 5,
4286 assert.deepEqual(_.defaults({}, source), source);
4287 assert.deepEqual(_.defaults({}, object, source), object);
4291 /*--------------------------------------------------------------------------*/
4293 QUnit.module('lodash.defaultsDeep');
4296 QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
4299 var object = { 'a': { 'b': 2 }, 'd': 4 },
4300 source = { 'a': { 'b': 1, 'c': 3 }, 'e': 5 },
4301 expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
4303 assert.deepEqual(_.defaultsDeep(object, source), expected);
4306 QUnit.test('should accept multiple sources', function(assert) {
4309 var source1 = { 'a': { 'b': 3 } },
4310 source2 = { 'a': { 'c': 3 } },
4311 source3 = { 'a': { 'b': 3, 'c': 3 } },
4312 source4 = { 'a': { 'c': 4 } },
4313 expected = { 'a': { 'b': 2, 'c': 3 } };
4315 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
4316 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
4319 QUnit.test('should not overwrite `null` values', function(assert) {
4322 var object = { 'a': { 'b': null } },
4323 source = { 'a': { 'b': 2 } },
4324 actual = _.defaultsDeep(object, source);
4326 assert.strictEqual(actual.a.b, null);
4329 QUnit.test('should not convert function properties to objects', function(assert) {
4332 var actual = _.defaultsDeep({}, { 'a': noop });
4333 assert.strictEqual(actual.a, noop);
4335 actual = _.defaultsDeep({}, { 'a': { 'b': noop } });
4336 assert.strictEqual(actual.a.b, noop);
4339 QUnit.test('should overwrite `undefined` values', function(assert) {
4342 var object = { 'a': { 'b': undefined } },
4343 source = { 'a': { 'b': 2 } },
4344 actual = _.defaultsDeep(object, source);
4346 assert.strictEqual(actual.a.b, 2);
4349 QUnit.test('should merge sources containing circular references', function(assert) {
4353 'foo': { 'b': { 'c': { 'd': {} } } },
4358 'foo': { 'b': { 'c': { 'd': {} } } },
4362 object.foo.b.c.d = object;
4363 source.foo.b.c.d = source;
4364 source.bar.b = source.foo.b;
4366 var actual = _.defaultsDeep(object, source);
4367 assert.ok(actual.bar.b === actual.foo.b && actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
4370 QUnit.test('should not modify sources', function(assert) {
4373 var source1 = { 'a': 1, 'b': { 'c': 2 } },
4374 source2 = { 'b': { 'c': 3, 'd': 3 } },
4375 actual = _.defaultsDeep({}, source1, source2);
4377 assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
4378 assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
4379 assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
4382 QUnit.test('should not attempt a merge of a string into an array', function(assert) {
4385 var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
4386 assert.deepEqual(actual, { 'a': ['abc'] });
4390 /*--------------------------------------------------------------------------*/
4392 QUnit.module('lodash.defer');
4395 QUnit.test('should defer `func` execution', function(assert) {
4398 var done = assert.async();
4401 _.defer(function() { pass = true; });
4403 setTimeout(function() {
4409 QUnit.test('should provide additional arguments to `func`', function(assert) {
4412 var done = assert.async();
4416 _.defer(function() {
4417 args = slice.call(arguments);
4420 setTimeout(function() {
4421 assert.deepEqual(args, [1, 2]);
4426 QUnit.test('should be cancelable', function(assert) {
4429 var done = assert.async();
4433 var timerId = _.defer(function() {
4437 clearTimeout(timerId);
4439 setTimeout(function() {
4446 /*--------------------------------------------------------------------------*/
4448 QUnit.module('lodash.delay');
4451 QUnit.test('should delay `func` execution', function(assert) {
4454 var done = assert.async();
4457 _.delay(function() { pass = true; }, 32);
4459 setTimeout(function() {
4463 setTimeout(function() {
4469 QUnit.test('should provide additional arguments to `func`', function(assert) {
4472 var done = assert.async();
4476 _.delay(function() {
4477 args = slice.call(arguments);
4480 setTimeout(function() {
4481 assert.deepEqual(args, [1, 2]);
4486 QUnit.test('should use a default `wait` of `0`', function(assert) {
4489 var done = assert.async();
4493 _.delay(function() {
4499 setTimeout(function() {
4505 QUnit.test('should be cancelable', function(assert) {
4508 var done = assert.async();
4512 var timerId = _.delay(function() {
4516 clearTimeout(timerId);
4518 setTimeout(function() {
4525 /*--------------------------------------------------------------------------*/
4527 QUnit.module('difference methods');
4529 lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
4530 var args = (function() { return arguments; }(1, 2, 3)),
4531 func = _[methodName];
4533 QUnit.test('`_.' + methodName + '` should return the difference of the given arrays', function(assert) {
4536 var actual = func([1, 2, 3, 4, 5], [5, 2, 10]);
4537 assert.deepEqual(actual, [1, 3, 4]);
4539 actual = func([1, 2, 3, 4, 5], [5, 2, 10], [8, 4]);
4540 assert.deepEqual(actual, [1, 3]);
4543 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
4546 assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
4549 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
4552 var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
4553 array2 = lodashStable.range(LARGE_ARRAY_SIZE),
4558 array1.push(a, b, c);
4559 array2.push(b, c, a);
4561 assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
4564 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
4569 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
4571 assert.deepEqual(func([object1, object2], largeArray), [object2]);
4574 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
4577 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
4578 assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
4581 QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
4584 var array = [1, null, 3];
4585 assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
4586 assert.deepEqual(func(null, array, 1), []);
4587 assert.deepEqual(func(array, args, null), [null]);
4591 /*--------------------------------------------------------------------------*/
4593 QUnit.module('lodash.differenceBy');
4596 QUnit.test('should accept an `iteratee` argument', function(assert) {
4599 var actual = _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
4600 assert.deepEqual(actual, [3.1, 1.3]);
4602 actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
4603 assert.deepEqual(actual, [{ 'x': 2 }]);
4606 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
4611 _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], function() {
4612 args || (args = slice.call(arguments));
4615 assert.deepEqual(args, [4.4]);
4619 /*--------------------------------------------------------------------------*/
4621 QUnit.module('lodash.differenceWith');
4624 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
4626 QUnit.test('should work with a `comparator` argument', function(assert) {
4629 var actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
4630 assert.deepEqual(actual, [{ 'x': 2, 'y': 1 }]);
4634 /*--------------------------------------------------------------------------*/
4636 QUnit.module('lodash.drop');
4639 var array = [1, 2, 3];
4641 QUnit.test('should drop the first two elements', function(assert) {
4644 assert.deepEqual(_.drop(array, 2), [3]);
4647 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4650 var expected = lodashStable.map(falsey, function(value) {
4651 return value === undefined ? [2, 3] : array;
4654 var actual = lodashStable.map(falsey, function(n) {
4655 return _.drop(array, n);
4658 assert.deepEqual(actual, expected);
4661 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4664 lodashStable.each([0, -1, -Infinity], function(n) {
4665 assert.deepEqual(_.drop(array, n), array);
4669 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
4672 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4673 assert.deepEqual(_.drop(array, n), []);
4677 QUnit.test('should coerce `n` to an integer', function(assert) {
4680 assert.deepEqual(_.drop(array, 1.6), [2, 3]);
4683 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4686 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4687 actual = lodashStable.map(array, _.drop);
4689 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
4692 QUnit.test('should work in a lazy sequence', function(assert) {
4696 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4697 predicate = function(value) { values.push(value); return isEven(value); },
4699 actual = _(array).drop(2).drop().value();
4701 assert.deepEqual(actual, array.slice(3));
4703 actual = _(array).filter(predicate).drop(2).drop().value();
4704 assert.deepEqual(values, array);
4705 assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
4707 actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
4708 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
4712 actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
4713 assert.deepEqual(values, array.slice(1));
4714 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
4717 skipAssert(assert, 6);
4722 /*--------------------------------------------------------------------------*/
4724 QUnit.module('lodash.dropRight');
4727 var array = [1, 2, 3];
4729 QUnit.test('should drop the last two elements', function(assert) {
4732 assert.deepEqual(_.dropRight(array, 2), [1]);
4735 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
4738 var expected = lodashStable.map(falsey, function(value) {
4739 return value === undefined ? [1, 2] : array;
4742 var actual = lodashStable.map(falsey, function(n) {
4743 return _.dropRight(array, n);
4746 assert.deepEqual(actual, expected);
4749 QUnit.test('should return all elements when `n` < `1`', function(assert) {
4752 lodashStable.each([0, -1, -Infinity], function(n) {
4753 assert.deepEqual(_.dropRight(array, n), array);
4757 QUnit.test('should return an empty array when `n` >= `array.length`', function(assert) {
4760 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
4761 assert.deepEqual(_.dropRight(array, n), []);
4765 QUnit.test('should coerce `n` to an integer', function(assert) {
4768 assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
4771 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
4774 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
4775 actual = lodashStable.map(array, _.dropRight);
4777 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
4780 QUnit.test('should work in a lazy sequence', function(assert) {
4784 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
4785 predicate = function(value) { values.push(value); return isEven(value); },
4787 actual = _(array).dropRight(2).dropRight().value();
4789 assert.deepEqual(actual, array.slice(0, -3));
4791 actual = _(array).filter(predicate).dropRight(2).dropRight().value();
4792 assert.deepEqual(values, array);
4793 assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
4795 actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
4796 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
4800 actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
4801 assert.deepEqual(values, array.slice(0, -1));
4802 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
4805 skipAssert(assert, 6);
4810 /*--------------------------------------------------------------------------*/
4812 QUnit.module('lodash.dropRightWhile');
4815 var array = [1, 2, 3, 4];
4823 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
4826 var actual = _.dropRightWhile(array, function(n) {
4830 assert.deepEqual(actual, [1, 2]);
4833 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
4838 _.dropRightWhile(array, function() {
4839 args = slice.call(arguments);
4842 assert.deepEqual(args, [4, 3, array]);
4845 QUnit.test('should work with "_.matches" shorthands', function(assert) {
4848 assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
4851 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
4854 assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
4857 QUnit.test('should work with "_.property" shorthands', function(assert) {
4860 assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
4863 QUnit.test('should return a wrapped value when chaining', function(assert) {
4867 var wrapped = _(array).dropRightWhile(function(n) {
4871 assert.ok(wrapped instanceof _);
4872 assert.deepEqual(wrapped.value(), [1, 2]);
4875 skipAssert(assert, 2);
4880 /*--------------------------------------------------------------------------*/
4882 QUnit.module('lodash.dropWhile');
4885 var array = [1, 2, 3, 4];
4893 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
4896 var actual = _.dropWhile(array, function(n) {
4900 assert.deepEqual(actual, [3, 4]);
4903 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
4908 _.dropWhile(array, function() {
4909 args = slice.call(arguments);
4912 assert.deepEqual(args, [1, 0, array]);
4915 QUnit.test('should work with "_.matches" shorthands', function(assert) {
4918 assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
4921 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
4924 assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
4927 QUnit.test('should work with "_.property" shorthands', function(assert) {
4930 assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
4933 QUnit.test('should work in a lazy sequence', function(assert) {
4937 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
4938 predicate = function(n) { return n < 3; },
4939 expected = _.dropWhile(array, predicate),
4940 wrapped = _(array).dropWhile(predicate);
4942 assert.deepEqual(wrapped.value(), expected);
4943 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
4944 assert.strictEqual(wrapped.last(), _.last(expected));
4947 skipAssert(assert, 3);
4951 QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
4955 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
4957 var actual = _(array)
4958 .dropWhile(function(n) { return n == 1; })
4960 .dropWhile(function(n) { return n == 3; })
4963 assert.deepEqual(actual, array.slice(3));
4971 /*--------------------------------------------------------------------------*/
4973 QUnit.module('lodash.endsWith');
4978 QUnit.test('should return `true` if a string ends with `target`', function(assert) {
4981 assert.strictEqual(_.endsWith(string, 'c'), true);
4984 QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
4987 assert.strictEqual(_.endsWith(string, 'b'), false);
4990 QUnit.test('should work with a `position` argument', function(assert) {
4993 assert.strictEqual(_.endsWith(string, 'b', 2), true);
4996 QUnit.test('should work with `position` >= `string.length`', function(assert) {
4999 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5000 assert.strictEqual(_.endsWith(string, 'c', position), true);
5004 QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
5007 var expected = lodashStable.map(falsey, alwaysTrue);
5009 var actual = lodashStable.map(falsey, function(position) {
5010 return _.endsWith(string, position === undefined ? 'c' : '', position);
5013 assert.deepEqual(actual, expected);
5016 QUnit.test('should treat a negative `position` as `0`', function(assert) {
5019 lodashStable.each([-1, -3, -Infinity], function(position) {
5020 assert.ok(lodashStable.every(string, function(chr) {
5021 return _.endsWith(string, chr, position) === false;
5023 assert.strictEqual(_.endsWith(string, '', position), true);
5027 QUnit.test('should coerce `position` to an integer', function(assert) {
5030 assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
5033 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
5036 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5037 return _.endsWith(string, '', position, true);
5042 /*--------------------------------------------------------------------------*/
5044 QUnit.module('lodash.eq');
5047 QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
5050 assert.strictEqual(_.eq(), true);
5051 assert.strictEqual(_.eq(undefined), true);
5052 assert.strictEqual(_.eq(0, -0), true);
5053 assert.strictEqual(_.eq(NaN, NaN), true);
5054 assert.strictEqual(_.eq(1, 1), true);
5056 assert.strictEqual(_.eq(null, undefined), false);
5057 assert.strictEqual(_.eq(1, Object(1)), false);
5058 assert.strictEqual(_.eq(1, '1'), false);
5059 assert.strictEqual(_.eq(1, '1'), false);
5061 var object = { 'a': 1 };
5062 assert.strictEqual(_.eq(object, object), true);
5063 assert.strictEqual(_.eq(object, { 'a': 1 }), false);
5067 /*--------------------------------------------------------------------------*/
5069 QUnit.module('lodash.escape');
5072 var escaped = '&<>"'`\/',
5073 unescaped = '&<>"\'`\/';
5076 unescaped += unescaped;
5078 QUnit.test('should escape values', function(assert) {
5081 assert.strictEqual(_.escape(unescaped), escaped);
5084 QUnit.test('should not escape the "/" character', function(assert) {
5087 assert.strictEqual(_.escape('/'), '/');
5090 QUnit.test('should handle strings with nothing to escape', function(assert) {
5093 assert.strictEqual(_.escape('abc'), 'abc');
5096 QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
5099 assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
5103 /*--------------------------------------------------------------------------*/
5105 QUnit.module('lodash.escapeRegExp');
5108 var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
5109 unescaped = '^$.*+?()[]{}|\\';
5111 QUnit.test('should escape values', function(assert) {
5114 assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
5117 QUnit.test('should handle strings with nothing to escape', function(assert) {
5120 assert.strictEqual(_.escapeRegExp('ghi'), 'ghi');
5123 QUnit.test('should return an empty string for empty values', function(assert) {
5126 var values = [, null, undefined, ''],
5127 expected = lodashStable.map(values, alwaysEmptyString);
5129 var actual = lodashStable.map(values, function(value, index) {
5130 return index ? _.escapeRegExp(value) : _.escapeRegExp();
5133 assert.deepEqual(actual, expected);
5137 /*--------------------------------------------------------------------------*/
5139 QUnit.module('lodash.every');
5142 QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
5145 assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
5148 QUnit.test('should return `true` for empty collections', function(assert) {
5151 var expected = lodashStable.map(empties, alwaysTrue);
5153 var actual = lodashStable.map(empties, function(value) {
5155 return _.every(value, identity);
5159 assert.deepEqual(actual, expected);
5162 QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
5167 assert.strictEqual(_.every([true, null, true], function(value) {
5172 assert.strictEqual(count, 2);
5175 QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
5178 assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
5181 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
5184 var values = [, null, undefined],
5185 expected = lodashStable.map(values, alwaysFalse);
5187 var actual = lodashStable.map(values, function(value, index) {
5189 return index ? _.every(array, value) : _.every(array);
5192 assert.deepEqual(actual, expected);
5194 expected = lodashStable.map(values, alwaysTrue);
5195 actual = lodashStable.map(values, function(value, index) {
5197 return index ? _.every(array, value) : _.every(array);
5200 assert.deepEqual(actual, expected);
5203 QUnit.test('should work with "_.property" shorthands', function(assert) {
5206 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
5207 assert.strictEqual(_.every(objects, 'a'), false);
5208 assert.strictEqual(_.every(objects, 'b'), true);
5211 QUnit.test('should work with "_.matches" shorthands', function(assert) {
5214 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
5215 assert.strictEqual(_.every(objects, { 'a': 0 }), true);
5216 assert.strictEqual(_.every(objects, { 'b': 1 }), false);
5219 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5222 var actual = lodashStable.map([[1]], _.every);
5223 assert.deepEqual(actual, [true]);
5227 /*--------------------------------------------------------------------------*/
5229 QUnit.module('strict mode checks');
5231 lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults'], function(methodName) {
5232 var func = _[methodName],
5233 isBindAll = methodName == 'bindAll';
5235 QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
5239 var object = freeze({ 'a': undefined, 'b': function() {} }),
5243 func(object, isBindAll ? 'b' : { 'a': 1 });
5255 /*--------------------------------------------------------------------------*/
5257 QUnit.module('lodash.fill');
5260 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
5263 var array = [1, 2, 3];
5264 assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
5267 QUnit.test('should use `undefined` for `value` if not given', function(assert) {
5270 var array = [1, 2, 3],
5271 actual = _.fill(array);
5273 assert.deepEqual(actual, Array(3));
5274 assert.ok(lodashStable.every(actual, function(value, index) {
5275 return index in actual;
5279 QUnit.test('should work with a positive `start`', function(assert) {
5282 var array = [1, 2, 3];
5283 assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
5286 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
5289 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
5290 var array = [1, 2, 3];
5291 assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
5295 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
5298 var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
5300 var actual = lodashStable.map(falsey, function(start) {
5301 var array = [1, 2, 3];
5302 return _.fill(array, 'a', start);
5305 assert.deepEqual(actual, expected);
5308 QUnit.test('should work with a negative `start`', function(assert) {
5311 var array = [1, 2, 3];
5312 assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
5315 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
5318 lodashStable.each([-3, -4, -Infinity], function(start) {
5319 var array = [1, 2, 3];
5320 assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
5324 QUnit.test('should work with `start` >= `end`', function(assert) {
5327 lodashStable.each([2, 3], function(start) {
5328 var array = [1, 2, 3];
5329 assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
5333 QUnit.test('should work with a positive `end`', function(assert) {
5336 var array = [1, 2, 3];
5337 assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
5340 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
5343 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
5344 var array = [1, 2, 3];
5345 assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
5349 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
5352 var expected = lodashStable.map(falsey, function(value) {
5353 return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
5356 var actual = lodashStable.map(falsey, function(end) {
5357 var array = [1, 2, 3];
5358 return _.fill(array, 'a', 0, end);
5361 assert.deepEqual(actual, expected);
5364 QUnit.test('should work with a negative `end`', function(assert) {
5367 var array = [1, 2, 3];
5368 assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
5371 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
5374 lodashStable.each([-3, -4, -Infinity], function(end) {
5375 var array = [1, 2, 3];
5376 assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
5380 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
5383 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
5385 var actual = lodashStable.map(positions, function(pos) {
5386 var array = [1, 2, 3];
5387 return _.fill.apply(_, [array, 'a'].concat(pos));
5390 assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
5393 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5396 var array = [[1, 2], [3, 4]],
5397 actual = lodashStable.map(array, _.fill);
5399 assert.deepEqual(actual, [[0, 0], [1, 1]]);
5402 QUnit.test('should return a wrapped value when chaining', function(assert) {
5406 var array = [1, 2, 3],
5407 wrapped = _(array).fill('a'),
5408 actual = wrapped.value();
5410 assert.ok(wrapped instanceof _);
5411 assert.deepEqual(actual, ['a', 'a', 'a']);
5412 assert.strictEqual(actual, array);
5415 skipAssert(assert, 3);
5420 /*--------------------------------------------------------------------------*/
5422 QUnit.module('lodash.filter');
5425 var array = [1, 2, 3];
5427 QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
5430 assert.deepEqual(_.filter(array, isEven), [2]);
5433 QUnit.test('should iterate over an object with numeric keys (test in Mobile Safari 8)', function(assert) {
5436 // Trigger a Mobile Safari 8 JIT bug.
5437 // See https://github.com/lodash/lodash/issues/799.
5439 object = { '1': 'foo', '8': 'bar', '50': 'baz' };
5441 lodashStable.times(1000, function(assert) {
5442 _.filter([], alwaysTrue);
5445 _.filter(object, function() {
5450 assert.strictEqual(counter, 3);
5454 /*--------------------------------------------------------------------------*/
5456 lodashStable.each(['find', 'findLast', 'findIndex', 'findLastIndex', 'findKey', 'findLastKey'], function(methodName) {
5457 QUnit.module('lodash.' + methodName);
5459 var func = _[methodName],
5460 isFindKey = /Key$/.test(methodName);
5470 'find': [objects[1], undefined, objects[2], objects[1]],
5471 'findLast': [objects[2], undefined, objects[2], objects[2]],
5472 'findIndex': [1, -1, 2, 1],
5473 'findLastIndex': [2, -1, 2, 2],
5474 'findKey': ['1', undefined, '2', '1'],
5475 'findLastKey': ['2', undefined, '2', '2']
5478 QUnit.test('should return the found value', function(assert) {
5481 assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
5484 QUnit.test('should return `' + expected[1] + '` if value is not found', function(assert) {
5487 assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
5490 QUnit.test('should work with "_.matches" shorthands', function(assert) {
5493 assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
5496 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
5499 assert.strictEqual(func(objects, ['b', 2]), expected[2]);
5502 QUnit.test('should work with "_.property" shorthands', function(assert) {
5505 assert.strictEqual(func(objects, 'b'), expected[3]);
5508 QUnit.test('should return `' + expected[1] + '` for empty collections', function(assert) {
5511 var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
5512 expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
5514 var actual = lodashStable.map(emptyValues, function(value) {
5516 return func(value, { 'a': 3 });
5520 assert.deepEqual(actual, expecting);
5525 var array = [1, 2, 3, 4];
5536 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
5540 assert.strictEqual(_(array)[methodName](), expected);
5547 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
5551 assert.ok(_(array).chain()[methodName]() instanceof _);
5558 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
5562 var wrapped = _(array).chain()[methodName]();
5563 assert.strictEqual(wrapped.__wrapped__, array);
5570 QUnit.test('should work in a lazy sequence', function(assert) {
5574 var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5577 lodashStable.times(2, function(index) {
5578 var array = index ? largeArray : smallArray,
5579 wrapped = _(array).filter(isEven);
5581 assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
5585 skipAssert(assert, 2);
5598 if (expected != null) {
5599 QUnit.test('should work with an object for `collection`', function(assert) {
5602 var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(n) {
5606 assert.strictEqual(actual, expected);
5612 /*--------------------------------------------------------------------------*/
5614 QUnit.module('lodash.find and lodash.findLast');
5616 lodashStable.each(['find', 'findLast'], function(methodName) {
5617 var isFind = methodName == 'find';
5619 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5625 array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5626 iteratee = function(value) { mapCount++; return square(value); },
5627 predicate = function(value) { findCount++; return isEven(value); },
5628 actual = _(array).map(iteratee)[methodName](predicate);
5630 assert.strictEqual(findCount, isFind ? 2 : 1);
5631 assert.strictEqual(mapCount, isFind ? 2 : 1);
5632 assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
5635 skipAssert(assert, 3);
5640 /*--------------------------------------------------------------------------*/
5642 QUnit.module('lodash.flip');
5646 return slice.call(arguments);
5649 QUnit.test('should flip arguments provided to `func`', function(assert) {
5652 var flipped = _.flip(fn);
5653 assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
5657 /*--------------------------------------------------------------------------*/
5659 QUnit.module('lodash.flatMap');
5662 var array = [1, 2, 3, 4];
5664 function duplicate(n) {
5668 QUnit.test('should map values in `array` to a new flattened array', function(assert) {
5671 var actual = _.flatMap(array, duplicate),
5672 expected = lodashStable.flatten(lodashStable.map(array, duplicate));
5674 assert.deepEqual(actual, expected);
5677 QUnit.test('should work with "_.property" shorthands', function(assert) {
5680 var objects = [{ 'a': [1, 2] }, { 'a': [3, 4] }];
5681 assert.deepEqual(_.flatMap(objects, 'a'), array);
5684 QUnit.test('should iterate over own properties of objects', function(assert) {
5687 function Foo() { this.a = [1, 2]; }
5688 Foo.prototype.b = [3, 4];
5690 var actual = _.flatMap(new Foo, identity);
5691 assert.deepEqual(actual, [1, 2]);
5694 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
5697 var array = [[1, 2], [3, 4]],
5698 values = [, null, undefined],
5699 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
5701 var actual = lodashStable.map(values, function(value, index) {
5702 return index ? _.flatMap(array, value) : _.flatMap(array);
5705 assert.deepEqual(actual, expected);
5708 QUnit.test('should work on an object with no `iteratee`', function(assert) {
5711 var actual = _.flatMap({ 'a': [1, 2], 'b': [3, 4] });
5712 assert.deepEqual(actual, array);
5715 QUnit.test('should handle object arguments with non-number length properties', function(assert) {
5718 var object = { 'length': [1, 2] };
5719 assert.deepEqual(_.flatMap(object, identity), [1, 2]);
5722 QUnit.test('should accept a falsey `collection` argument', function(assert) {
5725 var expected = lodashStable.map(falsey, alwaysEmptyArray);
5727 var actual = lodashStable.map(falsey, function(collection, index) {
5729 return index ? _.flatMap(collection) : _.flatMap();
5733 assert.deepEqual(actual, expected);
5736 QUnit.test('should treat number values for `collection` as empty', function(assert) {
5739 assert.deepEqual(_.flatMap(1), []);
5742 QUnit.test('should work in a lazy sequence', function(assert) {
5746 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
5749 lodashStable.times(2, function(index) {
5750 var array = index ? largeArray : smallArray,
5751 actual = _(array).filter(isEven).flatMap(duplicate).take(2).value();
5753 assert.deepEqual(actual, _.take(_.flatMap(_.filter(array, isEven), duplicate), 2));
5757 skipAssert(assert, 2);
5762 /*--------------------------------------------------------------------------*/
5764 QUnit.module('lodash.flattenDepth');
5767 var array = [1, [2, [3, [4]], 5]];
5769 QUnit.test('should use a default `depth` of `1`', function(assert) {
5772 assert.deepEqual(_.flattenDepth(array), [1, 2, [3, [4]], 5]);
5775 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
5778 lodashStable.each([-1, 0], function(depth) {
5779 assert.deepEqual(_.flattenDepth(array, depth), [1, [2, [3, [4]], 5]]);
5783 QUnit.test('should coerce `depth` to an integer', function(assert) {
5786 assert.deepEqual(_.flattenDepth(array, 2.2), [1, 2, 3, [4], 5]);
5790 /*--------------------------------------------------------------------------*/
5792 QUnit.module('flatten methods');
5795 var args = arguments,
5796 array = [1, [2, [3, [4]], 5]];
5798 QUnit.test('should flatten `arguments` objects', function(assert) {
5801 var array = [args, [args]];
5803 assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
5804 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
5805 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);
5808 QUnit.test('should treat sparse arrays as dense', function(assert) {
5811 var array = [[1, 2, 3], Array(3)],
5812 expected = [1, 2, 3];
5814 expected.push(undefined, undefined, undefined);
5816 lodashStable.each([_.flatten(array), _.flattenDeep(array), _.flattenDepth(array)], function(actual) {
5817 assert.deepEqual(actual, expected);
5818 assert.ok('4' in actual);
5822 QUnit.test('should work with extremely large arrays', function(assert) {
5825 lodashStable.times(3, function(index) {
5826 var expected = Array(5e5);
5828 var func = _.flatten;
5830 func = _.flattenDeep;
5831 } else if (index == 2) {
5832 func = _.flattenDepth;
5834 assert.deepEqual(func([expected]), expected);
5836 assert.ok(false, e.message);
5841 QUnit.test('should work with empty arrays', function(assert) {
5844 var array = [[], [[]], [[], [[[]]]]];
5846 assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
5847 assert.deepEqual(_.flattenDeep(array), []);
5848 assert.deepEqual(_.flattenDepth(array, 2), [[[]]]);
5851 QUnit.test('should support flattening of nested arrays', function(assert) {
5854 assert.deepEqual(_.flatten(array), [1, 2, [3, [4]], 5]);
5855 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
5856 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, [4], 5]);
5859 QUnit.test('should return an empty array for non array-like objects', function(assert) {
5863 nonArray = { 'a': 1 };
5865 assert.deepEqual(_.flatten(nonArray), expected);
5866 assert.deepEqual(_.flattenDeep(nonArray), expected);
5867 assert.deepEqual(_.flattenDepth(nonArray, 2), expected);
5870 QUnit.test('should return a wrapped value when chaining', function(assert) {
5874 var wrapped = _(array),
5875 actual = wrapped.flatten();
5877 assert.ok(actual instanceof _);
5878 assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);
5880 actual = wrapped.flattenDeep();
5882 assert.ok(actual instanceof _);
5883 assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);
5885 actual = wrapped.flattenDepth(2);
5887 assert.ok(actual instanceof _);
5888 assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);
5891 skipAssert(assert, 6);
5896 /*--------------------------------------------------------------------------*/
5898 QUnit.module('flow methods');
5900 lodashStable.each(['flow', 'flowRight'], function(methodName) {
5901 var func = _[methodName],
5902 isFlow = methodName == 'flow';
5904 QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
5907 var fixed = function(n) { return n.toFixed(1); },
5908 combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
5910 assert.strictEqual(combined(1, 2), '9.0');
5913 QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
5916 assert.notStrictEqual(func(noop), noop);
5919 QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are given', function(assert) {
5922 var combined = func();
5925 assert.strictEqual(combined('a'), 'a');
5927 assert.ok(false, e.message);
5929 assert.strictEqual(combined.length, 0);
5930 assert.notStrictEqual(combined, identity);
5933 QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
5936 var curried = _.curry(identity);
5938 var combined = isFlow
5939 ? func(_.head, curried)
5940 : func(curried, _.head);
5942 assert.strictEqual(combined([1]), 1);
5945 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
5950 array = lodashStable.range(LARGE_ARRAY_SIZE),
5951 iteratee = function(value) { mapCount++; return square(value); },
5952 predicate = function(value) { filterCount++; return isEven(value); };
5954 lodashStable.times(2, function(index) {
5955 var filter1 = _.filter,
5956 filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
5957 filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
5960 map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
5961 map3 = (_.map = index ? map2 : map1, map2(iteratee));
5964 take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
5965 take3 = (_.take = index ? take2 : take1, take2(2));
5967 var combined = isFlow
5968 ? func(map3, filter3, _.compact, take3)
5969 : func(take3, _.compact, filter3, map3);
5971 filterCount = mapCount = 0;
5972 assert.deepEqual(combined(array), [4, 16]);
5974 if (!isNpm && WeakMap && WeakMap.name) {
5975 assert.strictEqual(filterCount, 5, 'filterCount');
5976 assert.strictEqual(mapCount, 5, 'mapCount');
5979 skipAssert(assert, 2);
5987 QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
5990 var curried = _.curry(_.ary(_.map, 2), 2),
5991 getProp = curried(curried.placeholder, 'a'),
5992 objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
5994 var combined = isFlow
5995 ? func(getProp, _.uniq)
5996 : func(_.uniq, getProp);
5998 assert.deepEqual(combined(objects), [1, 2]);
6001 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
6005 var wrapped = _(noop)[methodName]();
6006 assert.ok(wrapped instanceof _);
6014 /*--------------------------------------------------------------------------*/
6016 QUnit.module('lodash.forEach');
6019 QUnit.test('should be aliased', function(assert) {
6022 assert.strictEqual(_.each, _.forEach);
6026 /*--------------------------------------------------------------------------*/
6028 QUnit.module('lodash.forEachRight');
6031 QUnit.test('should be aliased', function(assert) {
6034 assert.strictEqual(_.eachRight, _.forEachRight);
6038 /*--------------------------------------------------------------------------*/
6040 QUnit.module('forIn methods');
6042 lodashStable.each(['forIn', 'forInRight'], function(methodName) {
6043 var func = _[methodName];
6045 QUnit.test('`_.' + methodName + '` iterates over inherited properties', function(assert) {
6048 function Foo() { this.a = 1; }
6049 Foo.prototype.b = 2;
6052 func(new Foo, function(value, key) { keys.push(key); });
6053 assert.deepEqual(keys.sort(), ['a', 'b']);
6057 /*--------------------------------------------------------------------------*/
6059 QUnit.module('forOwn methods');
6061 lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
6062 var func = _[methodName];
6064 QUnit.test('should iterate over `length` properties', function(assert) {
6067 var object = { '0': 'zero', '1': 'one', 'length': 2 },
6070 func(object, function(value, prop) { props.push(prop); });
6071 assert.deepEqual(props.sort(), ['0', '1', 'length']);
6075 /*--------------------------------------------------------------------------*/
6077 QUnit.module('iteration methods');
6111 var arrayMethods = [
6118 var collectionMethods = [
6137 var forInMethods = [
6144 var iterationMethods = [
6154 var objectMethods = [
6167 var rightMethods = [
6176 var unwrappedMethods = [
6199 lodashStable.each(methods, function(methodName) {
6200 var array = [1, 2, 3],
6201 func = _[methodName],
6202 isBy = /(^partition|By)$/.test(methodName),
6203 isFind = /^find/.test(methodName),
6204 isOmitPick = /^(?:omit|pick)By$/.test(methodName),
6205 isSome = methodName == 'some';
6207 QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
6212 expected = [1, 0, array];
6214 func(array, function() {
6215 args || (args = slice.call(arguments));
6218 if (lodashStable.includes(rightMethods, methodName)) {
6222 if (lodashStable.includes(objectMethods, methodName)) {
6226 expected.length = isOmitPick ? 2 : 1;
6228 assert.deepEqual(args, expected);
6235 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
6242 var expected = lodashStable.includes(objectMethods, methodName)
6243 ? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
6244 : [[1, 0, array], [undefined, 1, array], [3, 2, array]];
6247 expected = lodashStable.map(expected, function(args) {
6248 return args.slice(0, isOmitPick ? 2 : 1);
6251 else if (lodashStable.includes(objectMethods, methodName)) {
6252 expected = lodashStable.map(expected, function(args) {
6257 if (lodashStable.includes(rightMethods, methodName)) {
6261 func(array, function() {
6262 argsList.push(slice.call(arguments));
6263 return !(isFind || isSome);
6266 assert.deepEqual(argsList, expected);
6274 lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
6275 var array = [1, 2, 3],
6276 func = _[methodName],
6277 isEvery = methodName == 'every';
6281 QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
6286 func(array, function(value, key) {
6291 assert.notOk(lodashStable.includes(keys, 'a'));
6299 lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
6300 var array = [1, 2, 3],
6301 func = _[methodName],
6302 isBaseEach = methodName == '_baseEach';
6304 QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
6307 if (!(isBaseEach || isNpm)) {
6308 var wrapped = _(array)[methodName](noop);
6309 assert.ok(wrapped instanceof _);
6317 lodashStable.each(unwrappedMethods, function(methodName) {
6318 var array = [1, 2, 3],
6319 func = _[methodName];
6321 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
6325 var actual = _(array)[methodName](noop);
6326 assert.notOk(actual instanceof _);
6333 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
6337 var wrapped = _(array).chain(),
6338 actual = wrapped[methodName](noop);
6340 assert.ok(actual instanceof _);
6341 assert.notStrictEqual(actual, wrapped);
6344 skipAssert(assert, 2);
6349 lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
6350 var array = [1, 2, 3],
6351 func = _[methodName];
6353 QUnit.test('`_.' + methodName + '` iterates over own properties of objects', function(assert) {
6356 function Foo() { this.a = 1; }
6357 Foo.prototype.b = 2;
6361 func(new Foo, function(value) { values.push(value); });
6362 assert.deepEqual(values, [1]);
6370 lodashStable.each(iterationMethods, function(methodName) {
6371 var array = [1, 2, 3],
6372 func = _[methodName];
6374 QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
6378 assert.strictEqual(func(array, Boolean), array);
6386 lodashStable.each(collectionMethods, function(methodName) {
6387 var func = _[methodName];
6389 QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
6393 var isIteratedAsObject = function(object) {
6395 func(object, function() { result = true; }, 0);
6399 var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
6400 expected = lodashStable.map(values, alwaysTrue);
6402 var actual = lodashStable.map(values, function(length) {
6403 return isIteratedAsObject({ 'length': length });
6406 var Foo = function(a) {};
6409 assert.deepEqual(actual, expected);
6410 assert.ok(isIteratedAsObject(Foo));
6411 assert.notOk(isIteratedAsObject({ 'length': 0 }));
6414 skipAssert(assert, 3);
6419 lodashStable.each(methods, function(methodName) {
6420 var array = [1, 2, 3],
6421 func = _[methodName],
6422 isFind = /^find/.test(methodName),
6423 isSome = methodName == 'some',
6424 isReduce = /^reduce/.test(methodName);
6426 QUnit.test('`_.' + methodName + '` should ignore changes to `array.length`', function(assert) {
6433 func(array, function() {
6437 return !(isFind || isSome);
6438 }, isReduce ? array : null);
6440 assert.strictEqual(count, 1);
6448 lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
6449 var func = _[methodName],
6450 isFind = /^find/.test(methodName),
6451 isSome = methodName == 'some',
6452 isReduce = /^reduce/.test(methodName);
6454 QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
6459 object = { 'a': 1 };
6461 func(object, function() {
6465 return !(isFind || isSome);
6466 }, isReduce ? object : null);
6468 assert.strictEqual(count, 1);
6477 /*--------------------------------------------------------------------------*/
6479 QUnit.module('object assignments');
6481 lodashStable.each(['assign', 'assignIn', 'defaults', 'merge'], function(methodName) {
6482 var func = _[methodName],
6483 isAssign = methodName == 'assign',
6484 isDefaults = methodName == 'defaults';
6486 QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
6489 var expected = lodashStable.map(falsey, alwaysTrue);
6491 var actual = lodashStable.map(falsey, function(object, index) {
6492 var result = index ? func(object) : func();
6493 return lodashStable.isEqual(result, Object(object));
6496 assert.deepEqual(actual, expected);
6499 QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'source properties', function(assert) {
6502 function Foo() { this.a = 1; }
6503 Foo.prototype.b = 2;
6505 var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
6506 assert.deepEqual(func({}, new Foo), expected);
6509 QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
6513 assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
6515 assert.ok(false, e.message);
6519 QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
6522 var source = { 'a': 1 },
6523 values = [null, undefined],
6524 expected = lodashStable.map(values, alwaysTrue);
6526 var actual = lodashStable.map(values, function(value) {
6527 var object = func(value, source);
6528 return object !== source && lodashStable.isEqual(object, source);
6531 assert.deepEqual(actual, expected);
6533 actual = lodashStable.map(values, function(value) {
6534 return lodashStable.isEqual(func(value), {});
6537 assert.deepEqual(actual, expected);
6540 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
6543 var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
6544 expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
6546 assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
6548 var fn = function() {};
6553 assert.deepEqual(_.reduce(fn, func, { 'a': 0 }), expected);
6556 QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
6560 var wrapped = _({ 'a': 1 }),
6561 actual = wrapped[methodName]({ 'b': 2 });
6563 assert.notStrictEqual(actual, wrapped);
6571 lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
6572 var func = _[methodName];
6574 QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
6578 Foo.prototype.a = 1;
6580 var actual = func(new Foo, { 'b': 2 });
6581 assert.notOk(_.has(actual, 'a'));
6585 lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'merge', 'mergeWith'], function(methodName) {
6586 var func = _[methodName];
6588 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
6591 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
6592 if (defineProperty) {
6596 defineProperty(object, 'a', {
6598 'configurable': true,
6599 'get': lodashStable.constant(value),
6600 'set': function() { pass = false; }
6603 func(object, { 'a': value });
6613 lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
6614 var func = _[methodName],
6615 isMergeWith = methodName == 'mergeWith';
6617 QUnit.test('`_.' + methodName + '` should provide the correct `customizer` arguments', function(assert) {
6621 object = { 'a': 1 },
6622 source = { 'a': 2 },
6623 expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
6625 func(object, source, function() {
6626 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6629 assert.deepEqual(args, expected, 'primitive property values');
6632 object = { 'a': 1 };
6633 source = { 'b': 2 };
6634 expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
6636 func(object, source, function() {
6637 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6640 assert.deepEqual(args, expected, 'missing destination property');
6643 objectValue = [1, 2],
6644 sourceValue = { 'b': 2 };
6646 object = { 'a': objectValue };
6647 source = { 'a': sourceValue };
6648 expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
6651 expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
6653 func(object, source, function() {
6654 argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
6657 assert.deepEqual(argsList, expected, 'object property values');
6660 QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
6663 function callback() {}
6666 var actual = func({ 'a': 1 }, callback);
6667 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
6669 actual = func({ 'a': 1 }, callback, { 'c': 3 });
6670 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
6674 /*--------------------------------------------------------------------------*/
6676 QUnit.module('exit early');
6678 lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
6679 var func = _[methodName];
6681 QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
6685 var array = [1, 2, 3],
6688 func(array, function(value, other) {
6689 values.push(lodashStable.isArray(value) ? other : value);
6693 assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
6700 QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
6704 var object = { 'a': 1, 'b': 2, 'c': 3 },
6707 func(object, function(value, other) {
6708 values.push(lodashStable.isArray(value) ? other : value);
6712 assert.strictEqual(values.length, 1);
6720 /*--------------------------------------------------------------------------*/
6722 QUnit.module('`__proto__` property bugs');
6725 QUnit.test('internal data objects should work with the `__proto__` key', function(assert) {
6728 var stringLiteral = '__proto__',
6729 stringObject = Object(stringLiteral),
6730 expected = [stringLiteral, stringObject];
6732 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
6733 return isEven(count) ? stringLiteral : stringObject;
6736 assert.deepEqual(_.difference(largeArray, largeArray), []);
6737 assert.deepEqual(_.intersection(largeArray, largeArray), expected);
6738 assert.deepEqual(_.uniq(largeArray), expected);
6739 assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
6743 /*--------------------------------------------------------------------------*/
6745 QUnit.module('lodash.fromPairs');
6748 QUnit.test('should accept a two dimensional array', function(assert) {
6751 var array = [['a', 1], ['b', 2]],
6752 object = { 'a': 1, 'b': 2 },
6753 actual = _.fromPairs(array);
6755 assert.deepEqual(actual, object);
6758 QUnit.test('should accept a falsey `array` argument', function(assert) {
6761 var expected = lodashStable.map(falsey, alwaysEmptyObject);
6763 var actual = lodashStable.map(falsey, function(array, index) {
6765 return index ? _.fromPairs(array) : _.fromPairs();
6769 assert.deepEqual(actual, expected);
6772 QUnit.test('should not support deep paths', function(assert) {
6775 var actual = _.fromPairs([['a.b.c', 1]]);
6776 assert.deepEqual(actual, { 'a.b.c': 1 });
6779 QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
6782 var object = { 'a.b.c': 1 };
6783 assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
6786 QUnit.test('should work in a lazy sequence', function(assert) {
6790 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
6791 return ['key' + index, index];
6794 var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
6796 assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
6804 /*--------------------------------------------------------------------------*/
6806 QUnit.module('lodash.functions');
6809 QUnit.test('should return the function names of an object', function(assert) {
6812 var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': lodashStable.each };
6813 assert.deepEqual(_.functions(object).sort(), ['b', 'd']);
6816 QUnit.test('should not include inherited functions', function(assert) {
6823 Foo.prototype.c = noop;
6824 assert.deepEqual(_.functions(new Foo).sort(), ['a']);
6828 /*--------------------------------------------------------------------------*/
6830 QUnit.module('lodash.groupBy');
6833 var array = [6.1, 4.2, 6.3];
6835 QUnit.test('should transform keys by `iteratee`', function(assert) {
6838 var actual = _.groupBy(array, Math.floor);
6839 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
6842 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
6845 var array = [6, 4, 6],
6846 values = [, null, undefined],
6847 expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
6849 var actual = lodashStable.map(values, function(value, index) {
6850 return index ? _.groupBy(array, value) : _.groupBy(array);
6853 assert.deepEqual(actual, expected);
6856 QUnit.test('should work with "_.property" shorthands', function(assert) {
6859 var actual = _.groupBy(['one', 'two', 'three'], 'length');
6860 assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
6863 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
6866 var actual = _.groupBy(array, function(n) {
6867 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
6870 assert.deepEqual(actual.constructor, [4.2]);
6871 assert.deepEqual(actual.hasOwnProperty, [6.1, 6.3]);
6874 QUnit.test('should work with a number for `iteratee`', function(assert) {
6883 assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
6884 assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
6887 QUnit.test('should work with an object for `collection`', function(assert) {
6890 var actual = _.groupBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
6891 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
6894 QUnit.test('should work in a lazy sequence', function(assert) {
6898 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
6899 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
6900 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
6903 var iteratee = function(value) { value.push(value[0]); return value; },
6904 predicate = function(value) { return isEven(value[0]); },
6905 actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
6907 assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
6915 /*--------------------------------------------------------------------------*/
6917 QUnit.module('lodash.gt');
6920 QUnit.test('should return `true` if `value` > `other`', function(assert) {
6923 assert.strictEqual(_.gt(3, 1), true);
6924 assert.strictEqual(_.gt('def', 'abc'), true);
6927 QUnit.test('should return `false` if `value` is <= `other`', function(assert) {
6930 assert.strictEqual(_.gt(1, 3), false);
6931 assert.strictEqual(_.gt(3, 3), false);
6932 assert.strictEqual(_.gt('abc', 'def'), false);
6933 assert.strictEqual(_.gt('def', 'def'), false);
6937 /*--------------------------------------------------------------------------*/
6939 QUnit.module('lodash.gte');
6942 QUnit.test('should return `true` if `value` >= `other`', function(assert) {
6945 assert.strictEqual(_.gte(3, 1), true);
6946 assert.strictEqual(_.gte(3, 3), true);
6947 assert.strictEqual(_.gte('def', 'abc'), true);
6948 assert.strictEqual(_.gte('def', 'def'), true);
6951 QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
6954 assert.strictEqual(_.gte(1, 3), false);
6955 assert.strictEqual(_.gte('abc', 'def'), false);
6959 /*--------------------------------------------------------------------------*/
6961 QUnit.module('has methods');
6963 lodashStable.each(['has', 'hasIn'], function(methodName) {
6964 var args = (function() { return arguments; }(1, 2, 3)),
6965 func = _[methodName],
6966 isHas = methodName == 'has';
6968 QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
6971 var object = { 'a': 1 };
6973 lodashStable.each(['a', ['a']], function(path) {
6974 assert.strictEqual(func(object, path), true);
6978 QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
6981 var object = { 'hasOwnProperty': null, 'a': 1 };
6982 assert.strictEqual(func(object, 'a'), true);
6985 QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
6988 var object = { 'a': { 'b': { 'c': 3 } } };
6990 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
6991 assert.strictEqual(func(object, path), true);
6995 QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
6999 fn.toString = lodashStable.constant('fn');
7001 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
7002 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
7003 values = [null, undefined, fn, {}];
7005 var actual = lodashStable.transform(objects, function(result, object, index) {
7006 var key = values[index];
7007 lodashStable.each([key, [key]], function(path) {
7008 var prop = _.property(key);
7009 result.push(prop(object));
7013 assert.deepEqual(actual, expected);
7016 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7019 assert.strictEqual(func(args, 1), true);
7022 QUnit.test('`_.' + methodName + '` should work with non-string `path` arguments', function(assert) {
7025 var array = [1, 2, 3];
7027 lodashStable.each([1, [1]], function(path) {
7028 assert.strictEqual(func(array, path), true);
7032 QUnit.test('`_.' + methodName + '` should work for objects with a `[[Prototype]]` of `null`', function(assert) {
7036 var object = create(null);
7038 assert.strictEqual(func(object, 1), true);
7045 QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
7048 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
7050 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
7051 assert.strictEqual(func(object, path), true);
7055 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7059 Foo.prototype.a = 1;
7061 lodashStable.each(['a', ['a']], function(path) {
7062 assert.strictEqual(func(new Foo, path), !isHas);
7066 QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
7069 var string = Object('abc');
7073 var values = [Array(3), args, string],
7074 expected = lodashStable.map(values, alwaysTrue);
7076 var actual = lodashStable.map(values, function(value) {
7077 return func(value, 0);
7080 assert.deepEqual(actual, expected);
7084 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
7087 var values = [null, undefined],
7088 expected = lodashStable.map(values, alwaysFalse);
7090 lodashStable.each(['constructor', ['constructor']], function(path) {
7091 var actual = lodashStable.map(values, function(value) {
7092 return func(value, path);
7095 assert.deepEqual(actual, expected);
7099 QUnit.test('`_.' + methodName + '` should return `false` with deep paths when `object` is nullish', function(assert) {
7102 var values = [null, undefined],
7103 expected = lodashStable.map(values, alwaysFalse);
7105 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
7106 var actual = lodashStable.map(values, function(value) {
7107 return func(value, path);
7110 assert.deepEqual(actual, expected);
7114 QUnit.test('`_.' + methodName + '` should return `false` if parts of `path` are missing', function(assert) {
7119 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
7120 assert.strictEqual(func(object, path), false);
7125 /*--------------------------------------------------------------------------*/
7127 QUnit.module('lodash.head');
7130 var array = [1, 2, 3, 4];
7132 QUnit.test('should return the first element', function(assert) {
7135 assert.strictEqual(_.head(array), 1);
7138 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
7144 assert.strictEqual(_.head(array), undefined);
7147 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7150 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7151 actual = lodashStable.map(array, _.head);
7153 assert.deepEqual(actual, [1, 4, 7]);
7156 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7160 assert.strictEqual(_(array).head(), 1);
7167 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7171 assert.ok(_(array).chain().head() instanceof _);
7178 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
7182 var wrapped = _(array).chain().head();
7183 assert.strictEqual(wrapped.__wrapped__, array);
7190 QUnit.test('should work in a lazy sequence', function(assert) {
7194 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
7197 lodashStable.times(2, function(index) {
7198 var array = index ? largeArray : smallArray,
7199 wrapped = _(array).filter(isEven);
7201 assert.strictEqual(wrapped.head(), _.head(_.filter(array, isEven)));
7205 skipAssert(assert, 2);
7209 QUnit.test('should be aliased', function(assert) {
7212 assert.strictEqual(_.first, _.head);
7216 /*--------------------------------------------------------------------------*/
7218 QUnit.module('lodash.identity');
7221 QUnit.test('should return the first argument given', function(assert) {
7224 var object = { 'name': 'fred' };
7225 assert.strictEqual(_.identity(object), object);
7229 /*--------------------------------------------------------------------------*/
7231 QUnit.module('lodash.includes');
7235 'an `arguments` object': arguments,
7236 'an array': [1, 2, 3, 4],
7237 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
7240 function(collection, key) {
7241 var isStr = typeof collection == 'string',
7242 values = _.toArray(collection),
7243 length = values.length;
7245 QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
7248 assert.strictEqual(_.includes(collection, 3), true);
7251 QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
7254 assert.strictEqual(_.includes(collection, 5), false);
7257 QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
7260 assert.strictEqual(_.includes(collection, values[2], 2), true);
7261 assert.strictEqual(_.includes(collection, values[1], 2), false);
7264 QUnit.test('should work with ' + key + ' and a `fromIndex` >= `collection.length`', function(assert) {
7267 lodashStable.each([4, 6, Math.pow(2, 32), Infinity], function(fromIndex) {
7268 assert.strictEqual(_.includes(collection, 1, fromIndex), false);
7269 assert.strictEqual(_.includes(collection, undefined, fromIndex), false);
7270 assert.strictEqual(_.includes(collection, '', fromIndex), (isStr && fromIndex == length));
7274 QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
7277 var expected = lodashStable.map(falsey, alwaysTrue);
7279 var actual = lodashStable.map(falsey, function(fromIndex) {
7280 return _.includes(collection, values[0], fromIndex);
7283 assert.deepEqual(actual, expected);
7286 QUnit.test('should work with ' + key + ' and coerce non-integer `fromIndex` values to integers', function(assert) {
7289 assert.strictEqual(_.includes(collection, values[0], '1'), false);
7290 assert.strictEqual(_.includes(collection, values[0], 0.1), true);
7291 assert.strictEqual(_.includes(collection, values[0], NaN), true);
7294 QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
7297 assert.strictEqual(_.includes(collection, values[2], -2), true);
7298 assert.strictEqual(_.includes(collection, values[1], -2), false);
7301 QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= negative `collection.length`', function(assert) {
7304 lodashStable.each([-4, -6, -Infinity], function(fromIndex) {
7305 assert.strictEqual(_.includes(collection, values[0], fromIndex), true);
7309 QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
7312 assert.strictEqual(_.includes(collection, 2, 1.2), true);
7315 QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
7319 assert.strictEqual(_(collection).includes(3), true);
7326 QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
7330 assert.ok(_(collection).chain().includes(3) instanceof _);
7340 'object': Object('abc')
7342 function(collection, key) {
7343 QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
7346 assert.strictEqual(_.includes(collection, 'bc'), true);
7347 assert.strictEqual(_.includes(collection, 'd'), false);
7351 QUnit.test('should return `false` for empty collections', function(assert) {
7354 var expected = lodashStable.map(empties, alwaysFalse);
7356 var actual = lodashStable.map(empties, function(value) {
7358 return _.includes(value);
7362 assert.deepEqual(actual, expected);
7365 QUnit.test('should match `NaN`', function(assert) {
7368 assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
7371 QUnit.test('should match `-0` as `0`', function(assert) {
7374 assert.strictEqual(_.includes([-0], 0), true);
7375 assert.strictEqual(_.includes([0], -0), true);
7378 QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
7381 var array1 = [1, 2, 3],
7384 assert.ok(lodashStable.every(array1, lodashStable.partial(_.includes, array2)));
7388 /*--------------------------------------------------------------------------*/
7390 QUnit.module('lodash.indexOf');
7393 var array = [1, 2, 3, 1, 2, 3];
7395 QUnit.test('should return the index of the first matched value', function(assert) {
7398 assert.strictEqual(_.indexOf(array, 3), 2);
7401 QUnit.test('should work with a positive `fromIndex`', function(assert) {
7404 assert.strictEqual(_.indexOf(array, 1, 2), 3);
7407 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
7410 var values = [6, 8, Math.pow(2, 32), Infinity],
7411 expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
7413 var actual = lodashStable.map(values, function(fromIndex) {
7415 _.indexOf(array, undefined, fromIndex),
7416 _.indexOf(array, 1, fromIndex),
7417 _.indexOf(array, '', fromIndex)
7421 assert.deepEqual(actual, expected);
7424 QUnit.test('should work with a negative `fromIndex`', function(assert) {
7427 assert.strictEqual(_.indexOf(array, 2, -3), 4);
7430 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
7433 var values = [-6, -8, -Infinity],
7434 expected = lodashStable.map(values, alwaysZero);
7436 var actual = lodashStable.map(values, function(fromIndex) {
7437 return _.indexOf(array, 1, fromIndex);
7440 assert.deepEqual(actual, expected);
7443 QUnit.test('should treat falsey `fromIndex` values as `0`', function(assert) {
7446 var expected = lodashStable.map(falsey, alwaysZero);
7448 var actual = lodashStable.map(falsey, function(fromIndex) {
7449 return _.indexOf(array, 1, fromIndex);
7452 assert.deepEqual(actual, expected);
7455 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
7458 assert.strictEqual(_.indexOf(array, 2, 1.2), 1);
7462 /*--------------------------------------------------------------------------*/
7464 QUnit.module('lodash.initial');
7467 var array = [1, 2, 3];
7469 QUnit.test('should accept a falsey `array` argument', function(assert) {
7472 var expected = lodashStable.map(falsey, alwaysEmptyArray);
7474 var actual = lodashStable.map(falsey, function(array, index) {
7476 return index ? _.initial(array) : _.initial();
7480 assert.deepEqual(actual, expected);
7483 QUnit.test('should exclude last element', function(assert) {
7486 assert.deepEqual(_.initial(array), [1, 2]);
7489 QUnit.test('should return an empty when querying empty arrays', function(assert) {
7492 assert.deepEqual(_.initial([]), []);
7495 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
7498 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
7499 actual = lodashStable.map(array, _.initial);
7501 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
7504 QUnit.test('should work in a lazy sequence', function(assert) {
7508 var array = lodashStable.range(LARGE_ARRAY_SIZE),
7511 var actual = _(array).initial().filter(function(value) {
7517 assert.deepEqual(actual, []);
7518 assert.deepEqual(values, _.initial(array));
7522 actual = _(array).filter(function(value) {
7524 return isEven(value);
7529 assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
7530 assert.deepEqual(values, array);
7533 skipAssert(assert, 4);
7538 /*--------------------------------------------------------------------------*/
7540 QUnit.module('lodash.inRange');
7543 QUnit.test('should work with an `end` argument', function(assert) {
7546 assert.strictEqual(_.inRange(3, 5), true);
7547 assert.strictEqual(_.inRange(5, 5), false);
7548 assert.strictEqual(_.inRange(6, 5), false);
7551 QUnit.test('should work with `start` and `end` arguments', function(assert) {
7554 assert.strictEqual(_.inRange(1, 1, 5), true);
7555 assert.strictEqual(_.inRange(3, 1, 5), true);
7556 assert.strictEqual(_.inRange(0, 1, 5), false);
7557 assert.strictEqual(_.inRange(5, 1, 5), false);
7560 QUnit.test('should treat falsey `start` arguments as `0`', function(assert) {
7563 lodashStable.each(falsey, function(value, index) {
7565 assert.strictEqual(_.inRange(0, value), false);
7566 assert.strictEqual(_.inRange(0, value, 1), true);
7568 assert.strictEqual(_.inRange(0), false);
7573 QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
7576 assert.strictEqual(_.inRange(2, 5, 1), true);
7577 assert.strictEqual(_.inRange(-3, -2, -6), true);
7580 QUnit.test('should work with a floating point `n` value', function(assert) {
7583 assert.strictEqual(_.inRange(0.5, 5), true);
7584 assert.strictEqual(_.inRange(1.2, 1, 5), true);
7585 assert.strictEqual(_.inRange(5.2, 5), false);
7586 assert.strictEqual(_.inRange(0.5, 1, 5), false);
7589 QUnit.test('should coerce arguments to finite numbers', function(assert) {
7592 var actual = [_.inRange(0, '0', 1), _.inRange(0, '1'), _.inRange(0, 0, '1'), _.inRange(0, NaN, 1), _.inRange(-1, -1, NaN)],
7593 expected = lodashStable.map(actual, alwaysTrue);
7595 assert.deepEqual(actual, expected);
7599 /*--------------------------------------------------------------------------*/
7601 QUnit.module('intersection methods');
7603 lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
7604 var args = (function() { return arguments; }(1, 2, 3)),
7605 func = _[methodName];
7607 QUnit.test('`_.' + methodName + '` should return the intersection of two arrays', function(assert) {
7610 var actual = func([1, 3, 2], [5, 2, 1, 4]);
7611 assert.deepEqual(actual, [1, 2]);
7613 actual = func([5, 2, 1, 4], [1, 3, 2]);
7614 assert.deepEqual(actual, [2, 1]);
7617 QUnit.test('`_.' + methodName + '` should return the intersection of multiple arrays', function(assert) {
7620 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
7621 assert.deepEqual(actual, [1, 2]);
7623 actual = func([5, 2, 1, 4], [2, 1], [1, 3, 2]);
7624 assert.deepEqual(actual, [2, 1]);
7627 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
7630 var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
7631 assert.deepEqual(actual, [1, 2]);
7634 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
7637 var actual = func([1, NaN, 3], [NaN, 5, NaN]);
7638 assert.deepEqual(actual, [NaN]);
7641 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
7645 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
7647 assert.deepEqual(func([object], largeArray), [object]);
7648 assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
7651 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
7654 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysNaN);
7655 assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
7658 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7661 var array = [0, 1, null, 3],
7664 assert.deepEqual(func(array, args), expected);
7665 assert.deepEqual(func(args, array), expected);
7668 QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
7671 var actual = func([1, 1, 3, 2, 2]);
7672 assert.deepEqual(actual, [1, 3, 2]);
7675 QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
7678 var array = [0, 1, null, 3];
7679 assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
7680 assert.deepEqual(func(null, array, null, [2, 3]), []);
7681 assert.deepEqual(func(array, null, args, null), []);
7684 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
7688 var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
7689 assert.ok(wrapped instanceof _);
7690 assert.deepEqual(wrapped.value(), [1, 2]);
7693 skipAssert(assert, 2);
7698 /*--------------------------------------------------------------------------*/
7700 QUnit.module('lodash.intersectionBy');
7703 QUnit.test('should accept an `iteratee` argument', function(assert) {
7706 var actual = _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
7707 assert.deepEqual(actual, [2.1]);
7709 actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7710 assert.deepEqual(actual, [{ 'x': 1 }]);
7713 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
7718 _.intersectionBy([2.1, 1.2], [4.3, 2.4], function() {
7719 args || (args = slice.call(arguments));
7722 assert.deepEqual(args, [4.3]);
7726 /*--------------------------------------------------------------------------*/
7728 QUnit.module('lodash.intersectionWith');
7731 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7733 QUnit.test('should work with a `comparator` argument', function(assert) {
7736 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
7737 actual = _.intersectionWith(objects, others, lodashStable.isEqual);
7739 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }]);
7743 /*--------------------------------------------------------------------------*/
7745 QUnit.module('lodash.invert');
7748 QUnit.test('should invert an object', function(assert) {
7751 var object = { 'a': 1, 'b': 2 },
7752 actual = _.invert(object);
7754 assert.deepEqual(actual, { '1': 'a', '2': 'b' });
7755 assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
7758 QUnit.test('should work with values that shadow keys on `Object.prototype`', function(assert) {
7761 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
7762 assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
7765 QUnit.test('should work with an object that has a `length` property', function(assert) {
7768 var object = { '0': 'a', '1': 'b', 'length': 2 };
7769 assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
7772 QUnit.test('should return a wrapped value when chaining', function(assert) {
7776 var object = { 'a': 1, 'b': 2 },
7777 wrapped = _(object).invert();
7779 assert.ok(wrapped instanceof _);
7780 assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
7783 skipAssert(assert, 2);
7788 /*--------------------------------------------------------------------------*/
7790 QUnit.module('lodash.invertBy');
7793 var object = { 'a': 1, 'b': 2, 'c': 1 };
7795 QUnit.test('should transform keys by `iteratee`', function(assert) {
7798 var expected = { 'group1': ['a', 'c'], 'group2': ['b'] };
7800 var actual = _.invertBy(object, function(value) {
7801 return 'group' + value;
7804 assert.deepEqual(actual, expected);
7807 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
7810 var values = [, null, undefined],
7811 expected = lodashStable.map(values, lodashStable.constant({ '1': ['a', 'c'], '2': ['b'] }));
7813 var actual = lodashStable.map(values, function(value, index) {
7814 return index ? _.invertBy(object, value) : _.invertBy(object);
7817 assert.deepEqual(actual, expected);
7820 QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
7823 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' },
7824 expected = { 'hasOwnProperty': ['a'], 'constructor': ['b'] };
7826 assert.ok(lodashStable.isEqual(_.invertBy(object), expected));
7829 QUnit.test('should return a wrapped value when chaining', function(assert) {
7833 var wrapped = _(object).invertBy();
7835 assert.ok(wrapped instanceof _);
7836 assert.deepEqual(wrapped.value(), { '1': ['a', 'c'], '2': ['b'] });
7839 skipAssert(assert, 2);
7844 /*--------------------------------------------------------------------------*/
7846 QUnit.module('lodash.invoke');
7849 QUnit.test('should invoke a method on `object`', function(assert) {
7852 var object = { 'a': lodashStable.constant('A') },
7853 actual = _.invoke(object, 'a');
7855 assert.strictEqual(actual, 'A');
7858 QUnit.test('should support invoking with arguments', function(assert) {
7861 var object = { 'a': function(a, b) { return [a, b]; } },
7862 actual = _.invoke(object, 'a', 1, 2);
7864 assert.deepEqual(actual, [1, 2]);
7867 QUnit.test('should not error on nullish elements', function(assert) {
7870 var values = [null, undefined],
7871 expected = lodashStable.map(values, alwaysUndefined);
7873 var actual = lodashStable.map(values, function(value) {
7875 return _.invoke(value, 'a.b.c', 1, 2);
7879 assert.deepEqual(actual, expected);
7882 QUnit.test('should support deep paths', function(assert) {
7885 var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
7887 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7888 var actual = _.invoke(object, path, 1, 2);
7889 assert.deepEqual(actual, [1, 2]);
7893 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
7896 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
7898 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7899 assert.deepEqual(_.invoke(object, path), 1);
7903 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
7907 var object = { 'a': alwaysOne };
7908 assert.strictEqual(_(object).invoke('a'), 1);
7915 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
7919 var object = { 'a': alwaysOne };
7920 assert.ok(_(object).chain().invoke('a') instanceof _);
7928 /*--------------------------------------------------------------------------*/
7930 QUnit.module('lodash.invokeMap');
7933 QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
7936 var array = ['a', 'b', 'c'],
7937 actual = _.invokeMap(array, 'toUpperCase');
7939 assert.deepEqual(actual, ['A', 'B', 'C']);
7942 QUnit.test('should support invoking with arguments', function(assert) {
7945 var array = [function() { return slice.call(arguments); }],
7946 actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
7948 assert.deepEqual(actual, [['a', 'b', 'c']]);
7951 QUnit.test('should work with a function for `methodName`', function(assert) {
7954 var array = ['a', 'b', 'c'];
7956 var actual = _.invokeMap(array, function(left, right) {
7957 return left + this.toUpperCase() + right;
7960 assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
7963 QUnit.test('should work with an object for `collection`', function(assert) {
7966 var object = { 'a': 1, 'b': 2, 'c': 3 },
7967 actual = _.invokeMap(object, 'toFixed', 1);
7969 assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
7972 QUnit.test('should treat number values for `collection` as empty', function(assert) {
7975 assert.deepEqual(_.invokeMap(1), []);
7978 QUnit.test('should not error on nullish elements', function(assert) {
7981 var array = ['a', null, undefined, 'd'];
7984 var actual = _.invokeMap(array, 'toUpperCase');
7987 assert.deepEqual(_.invokeMap(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
7990 QUnit.test('should not error on elements with missing properties', function(assert) {
7993 var objects = lodashStable.map([null, undefined, alwaysOne], function(value) {
7994 return { 'a': value };
7997 var expected = lodashStable.map(objects, function(object) {
7998 return object.a ? object.a() : undefined;
8002 var actual = _.invokeMap(objects, 'a');
8005 assert.deepEqual(actual, expected);
8008 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8011 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8013 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8014 assert.deepEqual(_.invokeMap([object], path), [1]);
8018 QUnit.test('should return a wrapped value when chaining', function(assert) {
8022 var array = ['a', 'b', 'c'],
8024 actual = wrapped.invokeMap('toUpperCase');
8026 assert.ok(actual instanceof _);
8027 assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
8029 actual = wrapped.invokeMap(function(left, right) {
8030 return left + this.toUpperCase() + right;
8033 assert.ok(actual instanceof _);
8034 assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
8037 skipAssert(assert, 4);
8041 QUnit.test('should support shortcut fusion', function(assert) {
8046 method = function() { count++; return this.index; };
8048 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
8049 return { 'index': index, 'method': method };
8052 var actual = _(array).invokeMap('method').take(1).value();
8054 assert.strictEqual(count, 1);
8055 assert.deepEqual(actual, [0]);
8058 skipAssert(assert, 2);
8063 /*--------------------------------------------------------------------------*/
8065 QUnit.module('lodash.isArguments');
8068 var args = (function() { return arguments; }(1, 2, 3)),
8069 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
8071 QUnit.test('should return `true` for `arguments` objects', function(assert) {
8074 assert.strictEqual(_.isArguments(args), true);
8075 assert.strictEqual(_.isArguments(strictArgs), true);
8078 QUnit.test('should return `false` for non `arguments` objects', function(assert) {
8081 var expected = lodashStable.map(falsey, alwaysFalse);
8083 var actual = lodashStable.map(falsey, function(value, index) {
8084 return index ? _.isArguments(value) : _.isArguments();
8087 assert.deepEqual(actual, expected);
8089 assert.strictEqual(_.isArguments([1, 2, 3]), false);
8090 assert.strictEqual(_.isArguments(true), false);
8091 assert.strictEqual(_.isArguments(new Date), false);
8092 assert.strictEqual(_.isArguments(new Error), false);
8093 assert.strictEqual(_.isArguments(_), false);
8094 assert.strictEqual(_.isArguments(slice), false);
8095 assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
8096 assert.strictEqual(_.isArguments(1), false);
8097 assert.strictEqual(_.isArguments(/x/), false);
8098 assert.strictEqual(_.isArguments('a'), false);
8099 assert.strictEqual(_.isArguments(symbol), false);
8102 QUnit.test('should work with an `arguments` object from another realm', function(assert) {
8105 if (realm.arguments) {
8106 assert.strictEqual(_.isArguments(realm.arguments), true);
8114 /*--------------------------------------------------------------------------*/
8116 QUnit.module('lodash.isArray');
8119 var args = arguments;
8121 QUnit.test('should return `true` for arrays', function(assert) {
8124 assert.strictEqual(_.isArray([1, 2, 3]), true);
8127 QUnit.test('should return `false` for non-arrays', function(assert) {
8130 var expected = lodashStable.map(falsey, alwaysFalse);
8132 var actual = lodashStable.map(falsey, function(value, index) {
8133 return index ? _.isArray(value) : _.isArray();
8136 assert.deepEqual(actual, expected);
8138 assert.strictEqual(_.isArray(args), false);
8139 assert.strictEqual(_.isArray(true), false);
8140 assert.strictEqual(_.isArray(new Date), false);
8141 assert.strictEqual(_.isArray(new Error), false);
8142 assert.strictEqual(_.isArray(_), false);
8143 assert.strictEqual(_.isArray(slice), false);
8144 assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
8145 assert.strictEqual(_.isArray(1), false);
8146 assert.strictEqual(_.isArray(/x/), false);
8147 assert.strictEqual(_.isArray('a'), false);
8148 assert.strictEqual(_.isArray(symbol), false);
8151 QUnit.test('should work with an array from another realm', function(assert) {
8155 assert.strictEqual(_.isArray(realm.array), true);
8163 /*--------------------------------------------------------------------------*/
8165 QUnit.module('lodash.isArrayBuffer');
8168 var args = arguments;
8170 QUnit.test('should return `true` for array buffers', function(assert) {
8174 assert.strictEqual(_.isArrayBuffer(arrayBuffer), true);
8181 QUnit.test('should return `false` for non array buffers', function(assert) {
8184 var expected = lodashStable.map(falsey, alwaysFalse);
8186 var actual = lodashStable.map(falsey, function(value, index) {
8187 return index ? _.isArrayBuffer(value) : _.isArrayBuffer();
8190 assert.deepEqual(actual, expected);
8192 assert.strictEqual(_.isArrayBuffer(args), false);
8193 assert.strictEqual(_.isArrayBuffer([1, 2, 3]), false);
8194 assert.strictEqual(_.isArrayBuffer(true), false);
8195 assert.strictEqual(_.isArrayBuffer(new Date), false);
8196 assert.strictEqual(_.isArrayBuffer(new Error), false);
8197 assert.strictEqual(_.isArrayBuffer(_), false);
8198 assert.strictEqual(_.isArrayBuffer(slice), false);
8199 assert.strictEqual(_.isArrayBuffer({ 'a': 1 }), false);
8200 assert.strictEqual(_.isArrayBuffer(1), false);
8201 assert.strictEqual(_.isArrayBuffer(/x/), false);
8202 assert.strictEqual(_.isArrayBuffer('a'), false);
8203 assert.strictEqual(_.isArrayBuffer(symbol), false);
8206 QUnit.test('should work with array buffers from another realm', function(assert) {
8209 if (realm.arrayBuffer) {
8210 assert.strictEqual(_.isArrayBuffer(realm.arrayBuffer), true);
8218 /*--------------------------------------------------------------------------*/
8220 QUnit.module('lodash.isArrayLike');
8223 var args = arguments;
8225 QUnit.test('should return `true` for array-like values', function(assert) {
8228 var values = [args, [1, 2, 3], { '0': 1, 'length': 1 }, 'a'],
8229 expected = lodashStable.map(values, alwaysTrue),
8230 actual = lodashStable.map(values, _.isArrayLike);
8232 assert.deepEqual(actual, expected);
8235 QUnit.test('should return `false` for non-arrays', function(assert) {
8238 var expected = lodashStable.map(falsey, function(value) {
8239 return value === '';
8242 var actual = lodashStable.map(falsey, function(value, index) {
8243 return index ? _.isArrayLike(value) : _.isArrayLike();
8246 assert.deepEqual(actual, expected);
8248 assert.strictEqual(_.isArrayLike(true), false);
8249 assert.strictEqual(_.isArrayLike(new Date), false);
8250 assert.strictEqual(_.isArrayLike(new Error), false);
8251 assert.strictEqual(_.isArrayLike(_), false);
8252 assert.strictEqual(_.isArrayLike(generator), false);
8253 assert.strictEqual(_.isArrayLike(slice), false);
8254 assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
8255 assert.strictEqual(_.isArrayLike(1), false);
8256 assert.strictEqual(_.isArrayLike(/x/), false);
8257 assert.strictEqual(_.isArrayLike(symbol), false);
8260 QUnit.test('should work with an array from another realm', function(assert) {
8264 var values = [realm.arguments, realm.array, realm.string],
8265 expected = lodashStable.map(values, alwaysTrue),
8266 actual = lodashStable.map(values, _.isArrayLike);
8268 assert.deepEqual(actual, expected);
8276 /*--------------------------------------------------------------------------*/
8278 QUnit.module('lodash.isBoolean');
8281 var args = arguments;
8283 QUnit.test('should return `true` for booleans', function(assert) {
8286 assert.strictEqual(_.isBoolean(true), true);
8287 assert.strictEqual(_.isBoolean(false), true);
8288 assert.strictEqual(_.isBoolean(Object(true)), true);
8289 assert.strictEqual(_.isBoolean(Object(false)), true);
8292 QUnit.test('should return `false` for non-booleans', function(assert) {
8295 var expected = lodashStable.map(falsey, function(value) {
8296 return value === false;
8299 var actual = lodashStable.map(falsey, function(value, index) {
8300 return index ? _.isBoolean(value) : _.isBoolean();
8303 assert.deepEqual(actual, expected);
8305 assert.strictEqual(_.isBoolean(args), false);
8306 assert.strictEqual(_.isBoolean([1, 2, 3]), false);
8307 assert.strictEqual(_.isBoolean(new Date), false);
8308 assert.strictEqual(_.isBoolean(new Error), false);
8309 assert.strictEqual(_.isBoolean(_), false);
8310 assert.strictEqual(_.isBoolean(slice), false);
8311 assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
8312 assert.strictEqual(_.isBoolean(1), false);
8313 assert.strictEqual(_.isBoolean(/x/), false);
8314 assert.strictEqual(_.isBoolean('a'), false);
8315 assert.strictEqual(_.isBoolean(symbol), false);
8318 QUnit.test('should work with a boolean from another realm', function(assert) {
8321 if (realm.boolean) {
8322 assert.strictEqual(_.isBoolean(realm.boolean), true);
8330 /*--------------------------------------------------------------------------*/
8332 QUnit.module('lodash.isBuffer');
8335 var args = arguments;
8337 QUnit.test('should return `true` for buffers', function(assert) {
8341 assert.strictEqual(_.isBuffer(new Buffer(2)), true);
8348 QUnit.test('should return `false` for non buffers', function(assert) {
8351 var expected = lodashStable.map(falsey, alwaysFalse);
8353 var actual = lodashStable.map(falsey, function(value, index) {
8354 return index ? _.isBuffer(value) : _.isBuffer();
8357 assert.deepEqual(actual, expected);
8359 assert.strictEqual(_.isBuffer(args), false);
8360 assert.strictEqual(_.isBuffer([1, 2, 3]), false);
8361 assert.strictEqual(_.isBuffer(true), false);
8362 assert.strictEqual(_.isBuffer(new Date), false);
8363 assert.strictEqual(_.isBuffer(new Error), false);
8364 assert.strictEqual(_.isBuffer(_), false);
8365 assert.strictEqual(_.isBuffer(slice), false);
8366 assert.strictEqual(_.isBuffer({ 'a': 1 }), false);
8367 assert.strictEqual(_.isBuffer(1), false);
8368 assert.strictEqual(_.isBuffer(/x/), false);
8369 assert.strictEqual(_.isBuffer('a'), false);
8370 assert.strictEqual(_.isBuffer(symbol), false);
8373 QUnit.test('should return `false` if `Buffer` is not defined', function(assert) {
8376 if (!isStrict && Buffer && lodashBizarro) {
8377 assert.strictEqual(lodashBizarro.isBuffer(new Buffer(2)), false);
8385 /*--------------------------------------------------------------------------*/
8387 QUnit.module('lodash.isDate');
8390 var args = arguments;
8392 QUnit.test('should return `true` for dates', function(assert) {
8395 assert.strictEqual(_.isDate(new Date), true);
8398 QUnit.test('should return `false` for non-dates', function(assert) {
8401 var expected = lodashStable.map(falsey, alwaysFalse);
8403 var actual = lodashStable.map(falsey, function(value, index) {
8404 return index ? _.isDate(value) : _.isDate();
8407 assert.deepEqual(actual, expected);
8409 assert.strictEqual(_.isDate(args), false);
8410 assert.strictEqual(_.isDate([1, 2, 3]), false);
8411 assert.strictEqual(_.isDate(true), false);
8412 assert.strictEqual(_.isDate(new Error), false);
8413 assert.strictEqual(_.isDate(_), false);
8414 assert.strictEqual(_.isDate(slice), false);
8415 assert.strictEqual(_.isDate({ 'a': 1 }), false);
8416 assert.strictEqual(_.isDate(1), false);
8417 assert.strictEqual(_.isDate(/x/), false);
8418 assert.strictEqual(_.isDate('a'), false);
8419 assert.strictEqual(_.isDate(symbol), false);
8422 QUnit.test('should work with a date object from another realm', function(assert) {
8426 assert.strictEqual(_.isDate(realm.date), true);
8434 /*--------------------------------------------------------------------------*/
8436 QUnit.module('lodash.isElement');
8439 var args = arguments;
8441 function Element() {
8445 QUnit.test('should return `false` for plain objects', function(assert) {
8448 var element = body || new Element;
8450 assert.strictEqual(_.isElement(element), true);
8451 assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
8452 assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
8453 assert.strictEqual(_.isElement({ 'nodeType': true }), false);
8454 assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
8455 assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
8456 assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
8459 QUnit.test('should return `false` for non DOM elements', function(assert) {
8462 var expected = lodashStable.map(falsey, alwaysFalse);
8464 var actual = lodashStable.map(falsey, function(value, index) {
8465 return index ? _.isElement(value) : _.isElement();
8468 assert.deepEqual(actual, expected);
8470 assert.strictEqual(_.isElement(args), false);
8471 assert.strictEqual(_.isElement([1, 2, 3]), false);
8472 assert.strictEqual(_.isElement(true), false);
8473 assert.strictEqual(_.isElement(new Date), false);
8474 assert.strictEqual(_.isElement(new Error), false);
8475 assert.strictEqual(_.isElement(_), false);
8476 assert.strictEqual(_.isElement(slice), false);
8477 assert.strictEqual(_.isElement({ 'a': 1 }), false);
8478 assert.strictEqual(_.isElement(1), false);
8479 assert.strictEqual(_.isElement(/x/), false);
8480 assert.strictEqual(_.isElement('a'), false);
8481 assert.strictEqual(_.isElement(symbol), false);
8484 QUnit.test('should work with a DOM element from another realm', function(assert) {
8487 if (realm.element) {
8488 assert.strictEqual(_.isElement(realm.element), true);
8496 /*--------------------------------------------------------------------------*/
8498 QUnit.module('lodash.isEmpty');
8501 var args = arguments;
8503 QUnit.test('should return `true` for empty values', function(assert) {
8506 var expected = lodashStable.map(empties, alwaysTrue),
8507 actual = lodashStable.map(empties, _.isEmpty);
8509 assert.deepEqual(actual, expected);
8511 assert.strictEqual(_.isEmpty(true), true);
8512 assert.strictEqual(_.isEmpty(slice), true);
8513 assert.strictEqual(_.isEmpty(1), true);
8514 assert.strictEqual(_.isEmpty(NaN), true);
8515 assert.strictEqual(_.isEmpty(/x/), true);
8516 assert.strictEqual(_.isEmpty(symbol), true);
8517 assert.strictEqual(_.isEmpty(), true);
8520 QUnit.test('should return `false` for non-empty values', function(assert) {
8523 assert.strictEqual(_.isEmpty([0]), false);
8524 assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
8525 assert.strictEqual(_.isEmpty('a'), false);
8528 QUnit.test('should work with an object that has a `length` property', function(assert) {
8531 assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
8534 QUnit.test('should work with `arguments` objects', function(assert) {
8537 assert.strictEqual(_.isEmpty(args), false);
8540 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
8543 function Foo(elements) { push.apply(this, elements); }
8544 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
8546 assert.strictEqual(_.isEmpty(new Foo([])), true);
8549 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
8553 Foo.prototype.length = -1;
8555 assert.strictEqual(_.isEmpty(new Foo), true);
8558 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
8562 Foo.prototype.length = MAX_SAFE_INTEGER + 1;
8564 assert.strictEqual(_.isEmpty(new Foo), true);
8567 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
8570 assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
8573 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8577 assert.strictEqual(_({}).isEmpty(), true);
8584 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8588 assert.ok(_({}).chain().isEmpty() instanceof _);
8596 /*--------------------------------------------------------------------------*/
8598 QUnit.module('lodash.isEqual');
8601 var symbol1 = Symbol ? Symbol('a') : true,
8602 symbol2 = Symbol ? Symbol('b') : false;
8604 QUnit.test('should compare primitives', function(assert) {
8608 [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
8609 [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
8610 [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
8611 ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
8612 [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
8613 [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
8614 [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
8615 [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
8616 [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
8619 var expected = lodashStable.map(pairs, function(pair) {
8623 var actual = lodashStable.map(pairs, function(pair) {
8624 return _.isEqual(pair[0], pair[1]);
8627 assert.deepEqual(actual, expected);
8630 QUnit.test('should compare arrays', function(assert) {
8633 var array1 = [true, null, 1, 'a', undefined],
8634 array2 = [true, null, 1, 'a', undefined];
8636 assert.strictEqual(_.isEqual(array1, array2), true);
8638 array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
8639 array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
8641 assert.strictEqual(_.isEqual(array1, array2), true);
8647 array2[1] = undefined;
8650 assert.strictEqual(_.isEqual(array1, array2), true);
8652 array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
8653 array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
8655 assert.strictEqual(_.isEqual(array1, array2), true);
8660 assert.strictEqual(_.isEqual(array1, array2), false);
8665 assert.strictEqual(_.isEqual(array1, array2), false);
8668 QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
8671 var array1 = [1, 2, 3],
8674 array1.every = array1.filter = array1.forEach =
8675 array1.indexOf = array1.lastIndexOf = array1.map =
8676 array1.some = array1.reduce = array1.reduceRight = null;
8678 array2.concat = array2.join = array2.pop =
8679 array2.reverse = array2.shift = array2.slice =
8680 array2.sort = array2.splice = array2.unshift = null;
8682 assert.strictEqual(_.isEqual(array1, array2), true);
8690 assert.strictEqual(_.isEqual(array1, array2), true);
8692 array1 = /c/.exec('abcde');
8695 assert.strictEqual(_.isEqual(array1, array2), true);
8698 QUnit.test('should compare sparse arrays', function(assert) {
8701 var array = Array(1);
8703 assert.strictEqual(_.isEqual(array, Array(1)), true);
8704 assert.strictEqual(_.isEqual(array, [undefined]), true);
8705 assert.strictEqual(_.isEqual(array, Array(2)), false);
8708 QUnit.test('should compare plain objects', function(assert) {
8711 var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
8712 object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
8714 assert.strictEqual(_.isEqual(object1, object2), true);
8716 object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
8717 object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
8719 assert.strictEqual(_.isEqual(object1, object2), true);
8721 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8722 object2 = { 'a': 3, 'b': 2, 'c': 1 };
8724 assert.strictEqual(_.isEqual(object1, object2), false);
8726 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8727 object2 = { 'd': 1, 'e': 2, 'f': 3 };
8729 assert.strictEqual(_.isEqual(object1, object2), false);
8731 object1 = { 'a': 1, 'b': 2 };
8732 object2 = { 'a': 1, 'b': 2, 'c': 3 };
8734 assert.strictEqual(_.isEqual(object1, object2), false);
8737 QUnit.test('should compare objects regardless of key order', function(assert) {
8740 var object1 = { 'a': 1, 'b': 2, 'c': 3 },
8741 object2 = { 'c': 3, 'a': 1, 'b': 2 };
8743 assert.strictEqual(_.isEqual(object1, object2), true);
8746 QUnit.test('should compare nested objects', function(assert) {
8755 'f': ['a', Object('b'), 'c'],
8757 'h': new Date(2012, 4, 23),
8764 'a': [1, Object(2), 3],
8769 'f': ['a', 'b', 'c'],
8771 'h': new Date(2012, 4, 23),
8777 assert.strictEqual(_.isEqual(object1, object2), true);
8780 QUnit.test('should compare object instances', function(assert) {
8783 function Foo() { this.a = 1; }
8784 Foo.prototype.a = 1;
8786 function Bar() { this.a = 1; }
8787 Bar.prototype.a = 2;
8789 assert.strictEqual(_.isEqual(new Foo, new Foo), true);
8790 assert.strictEqual(_.isEqual(new Foo, new Bar), false);
8791 assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
8792 assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
8795 QUnit.test('should compare objects with constructor properties', function(assert) {
8798 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
8799 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
8800 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
8801 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
8802 assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
8805 QUnit.test('should compare arrays with circular references', function(assert) {
8811 array1.push(array1);
8812 array2.push(array2);
8814 assert.strictEqual(_.isEqual(array1, array2), true);
8819 assert.strictEqual(_.isEqual(array1, array2), true);
8824 assert.strictEqual(_.isEqual(array1, array2), false);
8826 array1 = ['a', 'b', 'c'];
8828 array2 = ['a', ['a', 'b', 'c'], 'c'];
8830 assert.strictEqual(_.isEqual(array1, array2), false);
8833 QUnit.test('should compare objects with circular references', function(assert) {
8839 object1.a = object1;
8840 object2.a = object2;
8842 assert.strictEqual(_.isEqual(object1, object2), true);
8845 object2.b = Object(0);
8847 assert.strictEqual(_.isEqual(object1, object2), true);
8849 object1.c = Object(1);
8850 object2.c = Object(2);
8852 assert.strictEqual(_.isEqual(object1, object2), false);
8854 object1 = { 'a': 1, 'b': 2, 'c': 3 };
8855 object1.b = object1;
8856 object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
8858 assert.strictEqual(_.isEqual(object1, object2), false);
8861 QUnit.test('should compare objects with multiple circular references', function(assert) {
8867 (array1[0].a = array1).push(array1);
8868 (array2[0].a = array2).push(array2);
8870 assert.strictEqual(_.isEqual(array1, array2), true);
8873 array2[0].b = Object(0);
8875 assert.strictEqual(_.isEqual(array1, array2), true);
8877 array1[0].c = Object(1);
8878 array2[0].c = Object(2);
8880 assert.strictEqual(_.isEqual(array1, array2), false);
8883 QUnit.test('should compare objects with complex circular references', function(assert) {
8887 'foo': { 'b': { 'c': { 'd': {} } } },
8892 'foo': { 'b': { 'c': { 'd': {} } } },
8896 object1.foo.b.c.d = object1;
8897 object1.bar.b = object1.foo.b;
8899 object2.foo.b.c.d = object2;
8900 object2.bar.b = object2.foo.b;
8902 assert.strictEqual(_.isEqual(object1, object2), true);
8905 QUnit.test('should compare objects with shared property values', function(assert) {
8917 object1.b = object1.a;
8919 assert.strictEqual(_.isEqual(object1, object2), true);
8922 QUnit.test('should treat objects created by `Object.create(null)` like a plain object', function(assert) {
8925 function Foo() { this.a = 1; }
8926 Foo.prototype.constructor = null;
8928 var object2 = { 'a': 1 };
8929 assert.strictEqual(_.isEqual(new Foo, object2), false);
8932 var object1 = create(null);
8934 assert.strictEqual(_.isEqual(object1, object2), true);
8941 QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
8945 object = { 'toString': function() { return primitive; } },
8946 values = [true, null, 1, 'a', undefined],
8947 expected = lodashStable.map(values, alwaysFalse);
8949 var actual = lodashStable.map(values, function(value) {
8951 return _.isEqual(object, value);
8954 assert.deepEqual(actual, expected);
8957 QUnit.test('should avoid common type coercions', function(assert) {
8960 assert.strictEqual(_.isEqual(true, Object(false)), false);
8961 assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
8962 assert.strictEqual(_.isEqual(false, Object('')), false);
8963 assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
8964 assert.strictEqual(_.isEqual(0, ''), false);
8965 assert.strictEqual(_.isEqual(1, true), false);
8966 assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
8967 assert.strictEqual(_.isEqual('36', 36), false);
8968 assert.strictEqual(_.isEqual(36, '36'), false);
8971 QUnit.test('should compare `arguments` objects', function(assert) {
8974 var args1 = (function() { return arguments; }(1, 2, 3)),
8975 args2 = (function() { return arguments; }(1, 2, 3)),
8976 args3 = (function() { return arguments; }(1, 2));
8978 assert.strictEqual(_.isEqual(args1, args2), true);
8979 assert.strictEqual(_.isEqual(args1, args3), false);
8982 QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
8985 var args = (function() { return arguments; }(1, 2, 3)),
8986 object = { '0': 1, '1': 2, '2': 3 };
8989 Foo.prototype = object;
8991 assert.strictEqual(_.isEqual(args, object), true);
8992 assert.strictEqual(_.isEqual(object, args), true);
8994 assert.strictEqual(_.isEqual(args, new Foo), false);
8995 assert.strictEqual(_.isEqual(new Foo, args), false);
8998 QUnit.test('should compare array buffers', function(assert) {
9002 var buffer1 = new ArrayBuffer(4),
9003 buffer2 = new ArrayBuffer(8);
9005 assert.strictEqual(_.isEqual(buffer1, buffer2), false);
9007 buffer1 = new Int8Array([-1]).buffer;
9008 buffer2 = new Uint8Array([255]).buffer;
9010 assert.strictEqual(_.isEqual(buffer1, buffer2), true);
9013 skipAssert(assert, 2);
9017 QUnit.test('should compare date objects', function(assert) {
9020 var date = new Date(2012, 4, 23);
9022 assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
9023 assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false);
9024 assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false);
9025 assert.strictEqual(_.isEqual(new Date('a'), new Date('a')), false);
9028 QUnit.test('should compare error objects', function(assert) {
9031 var pairs = lodashStable.map([
9039 ], function(type, index, errorTypes) {
9040 var otherType = errorTypes[++index % errorTypes.length],
9042 CtorB = root[otherType];
9044 return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
9047 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9049 var actual = lodashStable.map(pairs, function(pair) {
9050 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9053 assert.deepEqual(actual, expected);
9056 QUnit.test('should compare functions', function(assert) {
9059 function a() { return 1 + 2; }
9060 function b() { return 1 + 2; }
9062 assert.strictEqual(_.isEqual(a, a), true);
9063 assert.strictEqual(_.isEqual(a, b), false);
9066 QUnit.test('should compare maps', function(assert) {
9075 assert.strictEqual(_.isEqual(map1, map2), false);
9079 assert.strictEqual(_.isEqual(map1, map2), true);
9081 map1['delete']('a');
9083 assert.strictEqual(_.isEqual(map1, map2), true);
9085 map2['delete']('a');
9086 assert.strictEqual(_.isEqual(map1, map2), false);
9089 skipAssert(assert, 4);
9093 QUnit.test('should compare regexes', function(assert) {
9096 assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
9097 assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
9098 assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
9099 assert.strictEqual(_.isEqual(/x/, /y/), false);
9100 assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
9103 QUnit.test('should compare sets', function(assert) {
9112 assert.strictEqual(_.isEqual(set1, set2), false);
9116 assert.strictEqual(_.isEqual(set1, set2), true);
9120 assert.strictEqual(_.isEqual(set1, set2), true);
9123 assert.strictEqual(_.isEqual(set1, set2), false);
9126 skipAssert(assert, 4);
9130 QUnit.test('should compare typed arrays', function(assert) {
9133 var pairs = lodashStable.map(typedArrays, function(type, index) {
9134 var otherType = typedArrays[(index + 1) % typedArrays.length],
9135 CtorA = root[type] || function(n) { this.n = n; },
9136 CtorB = root[otherType] || function(n) { this.n = n; },
9137 bufferA = root[type] ? new ArrayBuffer(8) : 8,
9138 bufferB = root[otherType] ? new ArrayBuffer(8) : 8,
9139 bufferC = root[otherType] ? new ArrayBuffer(16) : 16;
9141 return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
9144 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9146 var actual = lodashStable.map(pairs, function(pair) {
9147 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9150 assert.deepEqual(actual, expected);
9153 QUnit.test('should work as an iteratee for `_.every`', function(assert) {
9156 var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
9160 QUnit.test('should return `true` for like-objects from different documents', function(assert) {
9164 assert.strictEqual(_.isEqual([1], realm.array), true);
9165 assert.strictEqual(_.isEqual([2], realm.array), false);
9166 assert.strictEqual(_.isEqual({ 'a': 1 }, realm.object), true);
9167 assert.strictEqual(_.isEqual({ 'a': 2 }, realm.object), false);
9170 skipAssert(assert, 4);
9174 QUnit.test('should not error on DOM elements', function(assert) {
9178 var element1 = document.createElement('div'),
9179 element2 = element1.cloneNode(true);
9182 assert.strictEqual(_.isEqual(element1, element2), false);
9184 assert.ok(false, e.message);
9192 QUnit.test('should compare wrapped values', function(assert) {
9195 var stamp = +new Date;
9198 [[1, 2], [1, 2], [1, 2, 3]],
9199 [true, true, false],
9200 [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
9201 [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
9203 [NaN, NaN, Infinity],
9208 lodashStable.each(values, function(vals) {
9210 var wrapped1 = _(vals[0]),
9211 wrapped2 = _(vals[1]),
9212 actual = wrapped1.isEqual(wrapped2);
9214 assert.strictEqual(actual, true);
9215 assert.strictEqual(_.isEqual(_(actual), _(true)), true);
9217 wrapped1 = _(vals[0]);
9218 wrapped2 = _(vals[2]);
9220 actual = wrapped1.isEqual(wrapped2);
9221 assert.strictEqual(actual, false);
9222 assert.strictEqual(_.isEqual(_(actual), _(false)), true);
9225 skipAssert(assert, 4);
9230 QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
9234 var object1 = _({ 'a': 1, 'b': 2 }),
9235 object2 = { 'a': 1, 'b': 2 };
9237 assert.strictEqual(object1.isEqual(object2), true);
9238 assert.strictEqual(_.isEqual(object1, object2), true);
9240 object1 = _({ 'a': 1, 'b': 2 });
9241 object2 = { 'a': 1, 'b': 1 };
9243 assert.strictEqual(object1.isEqual(object2), false);
9244 assert.strictEqual(_.isEqual(object1, object2), false);
9247 skipAssert(assert, 4);
9251 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
9255 assert.strictEqual(_('a').isEqual('a'), true);
9262 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
9266 assert.ok(_('a').chain().isEqual('a') instanceof _);
9274 /*--------------------------------------------------------------------------*/
9276 QUnit.module('lodash.isEqualWith');
9279 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
9283 object1 = { 'a': [1, 2], 'b': null },
9284 object2 = { 'a': [1, 2], 'b': null };
9286 object1.b = object2;
9287 object2.b = object1;
9291 [object1.a, object2.a, 'a', object1, object2],
9292 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
9293 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
9294 [object1.b, object2.b, 'b', object1.b, object2.b],
9295 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
9296 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
9297 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
9298 [object1.b.b, object2.b.b, 'b', object1.b.b, object2.b.b]
9301 _.isEqualWith(object1, object2, function(assert) {
9302 var length = arguments.length,
9303 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
9305 argsList.push(args);
9308 assert.deepEqual(argsList, expected);
9311 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
9314 assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
9315 assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
9316 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
9319 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
9322 var customizer = function(value) {
9323 return _.isString(value) || undefined;
9326 assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
9327 assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
9328 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
9331 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
9334 var customizer = function(value) {
9335 return _.isString(value) ? false : undefined;
9338 assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
9339 assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
9340 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
9343 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
9346 var actual = _.isEqualWith('a', 'b', alwaysC);
9347 assert.strictEqual(actual, true);
9349 var values = _.without(falsey, undefined),
9350 expected = lodashStable.map(values, alwaysFalse);
9353 lodashStable.each(values, function(value) {
9354 actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
9357 assert.deepEqual(actual, expected);
9360 QUnit.test('should ensure `customizer` is a function', function(assert) {
9363 var array = [1, 2, 3],
9364 eq = _.partial(_.isEqualWith, array),
9365 actual = lodashStable.map([array, [1, 0, 3]], eq);
9367 assert.deepEqual(actual, [true, false]);
9370 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
9373 var value = { 'a': { 'b': 2 } };
9377 map1.set('a', value);
9380 map2.set('a', value);
9389 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
9392 array = _.toArray(pair[0]);
9396 [array[0], array[0], 0, array, array],
9397 [array[0][0], array[0][0], 0, array[0], array[0]],
9398 [array[0][1], array[0][1], 1, array[0], array[0]]
9402 expected.length = 2;
9404 _.isEqualWith(pair[0], pair[1], function() {
9405 var length = arguments.length,
9406 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
9408 argsList.push(args);
9411 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
9420 /*--------------------------------------------------------------------------*/
9422 QUnit.module('lodash.isError');
9425 var args = arguments;
9427 QUnit.test('should return `true` for error objects', function(assert) {
9430 var expected = lodashStable.map(errors, alwaysTrue);
9432 var actual = lodashStable.map(errors, function(error) {
9433 return _.isError(error) === true;
9436 assert.deepEqual(actual, expected);
9439 QUnit.test('should return `true` for subclassed values', function(assert) {
9442 assert.strictEqual(_.isError(new CustomError('x')), true);
9445 QUnit.test('should return `false` for non error objects', function(assert) {
9448 var expected = lodashStable.map(falsey, alwaysFalse);
9450 var actual = lodashStable.map(falsey, function(value, index) {
9451 return index ? _.isError(value) : _.isError();
9454 assert.deepEqual(actual, expected);
9456 assert.strictEqual(_.isError(args), false);
9457 assert.strictEqual(_.isError([1, 2, 3]), false);
9458 assert.strictEqual(_.isError(true), false);
9459 assert.strictEqual(_.isError(new Date), false);
9460 assert.strictEqual(_.isError(_), false);
9461 assert.strictEqual(_.isError(slice), false);
9462 assert.strictEqual(_.isError({ 'a': 1 }), false);
9463 assert.strictEqual(_.isError(1), false);
9464 assert.strictEqual(_.isError(/x/), false);
9465 assert.strictEqual(_.isError('a'), false);
9466 assert.strictEqual(_.isError(symbol), false);
9469 QUnit.test('should work with an error object from another realm', function(assert) {
9473 var expected = lodashStable.map(realm.errors, alwaysTrue);
9475 var actual = lodashStable.map(realm.errors, function(error) {
9476 return _.isError(error) === true;
9479 assert.deepEqual(actual, expected);
9487 /*--------------------------------------------------------------------------*/
9489 QUnit.module('lodash.isFinite');
9492 var args = arguments;
9494 QUnit.test('should return `true` for finite values', function(assert) {
9497 var values = [0, 1, 3.14, -1],
9498 expected = lodashStable.map(values, alwaysTrue),
9499 actual = lodashStable.map(values, _.isFinite);
9501 assert.deepEqual(actual, expected);
9504 QUnit.test('should return `false` for non-finite values', function(assert) {
9507 var values = [NaN, Infinity, -Infinity, Object(1)],
9508 expected = lodashStable.map(values, alwaysFalse),
9509 actual = lodashStable.map(values, _.isFinite);
9511 assert.deepEqual(actual, expected);
9514 QUnit.test('should return `false` for non-numeric values', function(assert) {
9517 var values = [undefined, [], true, '', ' ', '2px'],
9518 expected = lodashStable.map(values, alwaysFalse),
9519 actual = lodashStable.map(values, _.isFinite);
9521 assert.deepEqual(actual, expected);
9523 assert.strictEqual(_.isFinite(args), false);
9524 assert.strictEqual(_.isFinite([1, 2, 3]), false);
9525 assert.strictEqual(_.isFinite(true), false);
9526 assert.strictEqual(_.isFinite(new Date), false);
9527 assert.strictEqual(_.isFinite(new Error), false);
9528 assert.strictEqual(_.isFinite({ 'a': 1 }), false);
9529 assert.strictEqual(_.isFinite(/x/), false);
9530 assert.strictEqual(_.isFinite('a'), false);
9531 assert.strictEqual(_.isFinite(symbol), false);
9534 QUnit.test('should return `false` for numeric string values', function(assert) {
9537 var values = ['2', '0', '08'],
9538 expected = lodashStable.map(values, alwaysFalse),
9539 actual = lodashStable.map(values, _.isFinite);
9541 assert.deepEqual(actual, expected);
9545 /*--------------------------------------------------------------------------*/
9547 QUnit.module('lodash.isFunction');
9550 var args = arguments;
9552 QUnit.test('should return `true` for functions', function(assert) {
9555 assert.strictEqual(_.isFunction(_), true);
9556 assert.strictEqual(_.isFunction(slice), true);
9559 QUnit.test('should return `true` for generator functions', function(assert) {
9562 assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
9565 QUnit.test('should return `true` for typed array constructors', function(assert) {
9568 var expected = lodashStable.map(typedArrays, function(type) {
9569 return objToString.call(root[type]) == funcTag;
9572 var actual = lodashStable.map(typedArrays, function(type) {
9573 return _.isFunction(root[type]);
9576 assert.deepEqual(actual, expected);
9579 QUnit.test('should return `false` for non-functions', function(assert) {
9582 var expected = lodashStable.map(falsey, alwaysFalse);
9584 var actual = lodashStable.map(falsey, function(value, index) {
9585 return index ? _.isFunction(value) : _.isFunction();
9588 assert.deepEqual(actual, expected);
9590 assert.strictEqual(_.isFunction(args), false);
9591 assert.strictEqual(_.isFunction([1, 2, 3]), false);
9592 assert.strictEqual(_.isFunction(true), false);
9593 assert.strictEqual(_.isFunction(new Date), false);
9594 assert.strictEqual(_.isFunction(new Error), false);
9595 assert.strictEqual(_.isFunction({ 'a': 1 }), false);
9596 assert.strictEqual(_.isFunction(1), false);
9597 assert.strictEqual(_.isFunction(/x/), false);
9598 assert.strictEqual(_.isFunction('a'), false);
9599 assert.strictEqual(_.isFunction(symbol), false);
9602 assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
9608 QUnit.test('should work with host objects in IE 8 document mode (test in IE 11)', function(assert) {
9611 // Trigger a Chakra JIT bug.
9612 // See https://github.com/jashkenas/underscore/issues/1621.
9613 lodashStable.each([body, xml], function(object) {
9615 lodashStable.times(100, _.isFunction);
9616 assert.strictEqual(_.isFunction(object), false);
9624 QUnit.test('should work with a function from another realm', function(assert) {
9627 if (realm.function) {
9628 assert.strictEqual(_.isFunction(realm.function), true);
9636 /*--------------------------------------------------------------------------*/
9638 QUnit.module('isInteger methods');
9640 lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
9641 var args = arguments,
9642 func = _[methodName],
9643 isSafe = methodName == 'isSafeInteger';
9645 QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
9648 var values = [-1, 0, 1],
9649 expected = lodashStable.map(values, alwaysTrue);
9651 var actual = lodashStable.map(values, function(value) {
9655 assert.deepEqual(actual, expected);
9656 assert.strictEqual(func(MAX_INTEGER), !isSafe);
9659 QUnit.test('should return `false` for non-integer number values', function(assert) {
9662 var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
9663 expected = lodashStable.map(values, alwaysFalse);
9665 var actual = lodashStable.map(values, function(value) {
9669 assert.deepEqual(actual, expected);
9672 QUnit.test('should return `false` for non-numeric values', function(assert) {
9675 var expected = lodashStable.map(falsey, function(value) {
9679 var actual = lodashStable.map(falsey, function(value, index) {
9680 return index ? func(value) : func();
9683 assert.deepEqual(actual, expected);
9685 assert.strictEqual(func(args), false);
9686 assert.strictEqual(func([1, 2, 3]), false);
9687 assert.strictEqual(func(true), false);
9688 assert.strictEqual(func(new Date), false);
9689 assert.strictEqual(func(new Error), false);
9690 assert.strictEqual(func({ 'a': 1 }), false);
9691 assert.strictEqual(func(/x/), false);
9692 assert.strictEqual(func('a'), false);
9693 assert.strictEqual(func(symbol), false);
9697 /*--------------------------------------------------------------------------*/
9699 QUnit.module('lodash.isLength');
9702 QUnit.test('should return `true` for lengths', function(assert) {
9705 var values = [0, 3, MAX_SAFE_INTEGER],
9706 expected = lodashStable.map(values, alwaysTrue),
9707 actual = lodashStable.map(values, _.isLength);
9709 assert.deepEqual(actual, expected);
9712 QUnit.test('should return `false` for non-lengths', function(assert) {
9715 var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
9716 expected = lodashStable.map(values, alwaysFalse),
9717 actual = lodashStable.map(values, _.isLength);
9719 assert.deepEqual(actual, expected);
9723 /*--------------------------------------------------------------------------*/
9725 QUnit.module('lodash.isMap');
9728 var args = arguments;
9730 QUnit.test('should return `true` for maps', function(assert) {
9734 assert.strictEqual(_.isMap(map), true);
9741 QUnit.test('should return `false` for non maps', function(assert) {
9744 var expected = lodashStable.map(falsey, alwaysFalse);
9746 var actual = lodashStable.map(falsey, function(value, index) {
9747 return index ? _.isMap(value) : _.isMap();
9750 assert.deepEqual(actual, expected);
9752 assert.strictEqual(_.isMap(args), false);
9753 assert.strictEqual(_.isMap([1, 2, 3]), false);
9754 assert.strictEqual(_.isMap(true), false);
9755 assert.strictEqual(_.isMap(new Date), false);
9756 assert.strictEqual(_.isMap(new Error), false);
9757 assert.strictEqual(_.isMap(_), false);
9758 assert.strictEqual(_.isMap(slice), false);
9759 assert.strictEqual(_.isMap({ 'a': 1 }), false);
9760 assert.strictEqual(_.isMap(1), false);
9761 assert.strictEqual(_.isMap(/x/), false);
9762 assert.strictEqual(_.isMap('a'), false);
9763 assert.strictEqual(_.isMap(symbol), false);
9764 assert.strictEqual(_.isMap(weakMap), false);
9767 QUnit.test('should work with maps from another realm', function(assert) {
9771 assert.strictEqual(_.isMap(realm.map), true);
9779 /*--------------------------------------------------------------------------*/
9781 QUnit.module('lodash.isMatch');
9784 QUnit.test('should perform a deep comparison between `object` and `source`', function(assert) {
9787 var object = { 'a': 1, 'b': 2, 'c': 3 };
9788 assert.strictEqual(_.isMatch(object, { 'a': 1 }), true);
9789 assert.strictEqual(_.isMatch(object, { 'b': 1 }), false);
9790 assert.strictEqual(_.isMatch(object, { 'a': 1, 'c': 3 }), true);
9791 assert.strictEqual(_.isMatch(object, { 'c': 3, 'd': 4 }), false);
9793 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
9794 assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true);
9797 QUnit.test('should match inherited `object` properties', function(assert) {
9800 function Foo() { this.a = 1; }
9801 Foo.prototype.b = 2;
9803 assert.strictEqual(_.isMatch({ 'a': new Foo }, { 'a': { 'b': 2 } }), true);
9806 QUnit.test('should not match by inherited `source` properties', function(assert) {
9809 function Foo() { this.a = 1; }
9810 Foo.prototype.b = 2;
9812 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
9814 expected = lodashStable.map(objects, alwaysTrue);
9816 var actual = lodashStable.map(objects, function(object) {
9817 return _.isMatch(object, source);
9820 assert.deepEqual(actual, expected);
9823 QUnit.test('should compare a variety of `source` property values', function(assert) {
9826 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
9827 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } };
9829 assert.strictEqual(_.isMatch(object1, object1), true);
9830 assert.strictEqual(_.isMatch(object1, object2), false);
9833 QUnit.test('should match `-0` as `0`', function(assert) {
9836 var object1 = { 'a': -0 },
9837 object2 = { 'a': 0 };
9839 assert.strictEqual(_.isMatch(object1, object2), true);
9840 assert.strictEqual(_.isMatch(object2, object1), true);
9843 QUnit.test('should compare functions by reference', function(assert) {
9846 var object1 = { 'a': lodashStable.noop },
9847 object2 = { 'a': noop },
9848 object3 = { 'a': {} };
9850 assert.strictEqual(_.isMatch(object1, object1), true);
9851 assert.strictEqual(_.isMatch(object2, object1), false);
9852 assert.strictEqual(_.isMatch(object3, object1), false);
9855 QUnit.test('should work with a function for `object`', function(assert) {
9859 Foo.a = { 'b': 1, 'c': 2 };
9861 assert.strictEqual(_.isMatch(Foo, { 'a': { 'b': 1 } }), true);
9864 QUnit.test('should work with a function for `source`', function(assert) {
9869 Foo.b = function() {};
9872 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }];
9874 var actual = lodashStable.map(objects, function(object) {
9875 return _.isMatch(object, Foo);
9878 assert.deepEqual(actual, [false, true]);
9881 QUnit.test('should work with a non-plain `object`', function(assert) {
9884 function Foo(object) { lodashStable.assign(this, object); }
9886 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) });
9887 assert.strictEqual(_.isMatch(object, { 'a': { 'b': 1 } }), true);
9890 QUnit.test('should partial match arrays', function(assert) {
9893 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
9894 source = { 'a': ['d'] },
9895 predicate = function(object) { return _.isMatch(object, source); },
9896 actual = lodashStable.filter(objects, predicate);
9898 assert.deepEqual(actual, [objects[1]]);
9900 source = { 'a': ['b', 'd'] };
9901 actual = lodashStable.filter(objects, predicate);
9903 assert.deepEqual(actual, []);
9905 source = { 'a': ['d', 'b'] };
9906 actual = lodashStable.filter(objects, predicate);
9907 assert.deepEqual(actual, []);
9910 QUnit.test('should partial match arrays of objects', function(assert) {
9913 var source = { 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] };
9916 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
9917 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
9920 var actual = lodashStable.filter(objects, function(object) {
9921 return _.isMatch(object, source);
9924 assert.deepEqual(actual, [objects[0]]);
9927 QUnit.test('should partial match maps', function(assert) {
9931 var objects = [{ 'a': new Map }, { 'a': new Map }];
9932 objects[0].a.set('a', 1);
9933 objects[1].a.set('a', 1);
9934 objects[1].a.set('b', 2);
9939 var source = { 'a': map },
9940 predicate = function(object) { return _.isMatch(object, source); },
9941 actual = lodashStable.filter(objects, predicate);
9943 assert.deepEqual(actual, [objects[1]]);
9946 actual = lodashStable.filter(objects, predicate);
9948 assert.deepEqual(actual, objects);
9951 actual = lodashStable.filter(objects, predicate);
9953 assert.deepEqual(actual, []);
9956 skipAssert(assert, 3);
9960 QUnit.test('should partial match sets', function(assert) {
9964 var objects = [{ 'a': new Set }, { 'a': new Set }];
9965 objects[0].a.add(1);
9966 objects[1].a.add(1);
9967 objects[1].a.add(2);
9972 var source = { 'a': set },
9973 predicate = function(object) { return _.isMatch(object, source); },
9974 actual = lodashStable.filter(objects, predicate);
9976 assert.deepEqual(actual, [objects[1]]);
9979 actual = lodashStable.filter(objects, predicate);
9981 assert.deepEqual(actual, objects);
9984 actual = lodashStable.filter(objects, predicate);
9986 assert.deepEqual(actual, []);
9989 skipAssert(assert, 3);
9993 QUnit.test('should match `undefined` values', function(assert) {
9996 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
9997 source = { 'b': undefined },
9998 predicate = function(object) { return _.isMatch(object, source); },
9999 actual = lodashStable.map(objects, predicate),
10000 expected = [false, false, true];
10002 assert.deepEqual(actual, expected);
10004 source = { 'a': 1, 'b': undefined };
10005 actual = lodashStable.map(objects, predicate);
10007 assert.deepEqual(actual, expected);
10009 objects = [{ 'a': { 'b': 1 } }, { 'a': { 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
10010 source = { 'a': { 'c': undefined } };
10011 actual = lodashStable.map(objects, predicate);
10013 assert.deepEqual(actual, expected);
10016 QUnit.test('should match `undefined` values on primitives', function(assert) {
10020 numberProto.b = undefined;
10023 assert.strictEqual(_.isMatch(1, { 'b': undefined }), true);
10025 assert.ok(false, e.message);
10028 assert.strictEqual(_.isMatch(1, { 'a': 1, 'b': undefined }), true);
10030 assert.ok(false, e.message);
10032 numberProto.a = { 'b': 1, 'c': undefined };
10034 assert.strictEqual(_.isMatch(1, { 'a': { 'c': undefined } }), true);
10036 assert.ok(false, e.message);
10038 delete numberProto.a;
10039 delete numberProto.b;
10042 QUnit.test('should return `false` when `object` is nullish', function(assert) {
10045 var values = [null, undefined],
10046 expected = lodashStable.map(values, alwaysFalse),
10047 source = { 'a': 1 };
10049 var actual = lodashStable.map(values, function(value) {
10051 return _.isMatch(value, source);
10055 assert.deepEqual(actual, expected);
10058 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
10061 var values = [null, undefined],
10062 expected = lodashStable.map(values, alwaysTrue),
10065 var actual = lodashStable.map(values, function(value) {
10067 return _.isMatch(value, source);
10071 assert.deepEqual(actual, expected);
10074 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
10077 var object = { 'a': 1 },
10078 expected = lodashStable.map(empties, alwaysTrue);
10080 var actual = lodashStable.map(empties, function(value) {
10081 return _.isMatch(object, value);
10084 assert.deepEqual(actual, expected);
10087 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
10090 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
10091 source = { 'a': [], 'b': {} };
10093 var actual = lodashStable.filter(objects, function(object) {
10094 return _.isMatch(object, source);
10097 assert.deepEqual(actual, objects);
10101 /*--------------------------------------------------------------------------*/
10103 QUnit.module('lodash.isMatchWith');
10106 QUnit.test('should provide the correct `customizer` arguments', function(assert) {
10110 object1 = { 'a': [1, 2], 'b': null },
10111 object2 = { 'a': [1, 2], 'b': null };
10113 object1.b = object2;
10114 object2.b = object1;
10117 [object1.a, object2.a, 'a', object1, object2],
10118 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10119 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10120 [object1.b, object2.b, 'b', object1, object2],
10121 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
10122 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
10123 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
10124 [object1.b.b, object2.b.b, 'b', object1.b, object2.b],
10125 [object1.b.b.a, object2.b.b.a, 'a', object1.b.b, object2.b.b],
10126 [object1.b.b.a[0], object2.b.b.a[0], 0, object1.b.b.a, object2.b.b.a],
10127 [object1.b.b.a[1], object2.b.b.a[1], 1, object1.b.b.a, object2.b.b.a],
10128 [object1.b.b.b, object2.b.b.b, 'b', object1.b.b, object2.b.b]
10131 _.isMatchWith(object1, object2, function(assert) {
10132 argsList.push(slice.call(arguments, 0, -1));
10135 assert.deepEqual(argsList, expected);
10138 QUnit.test('should handle comparisons if `customizer` returns `undefined`', function(assert) {
10141 assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
10144 QUnit.test('should not handle comparisons if `customizer` returns `true`', function(assert) {
10147 var customizer = function(value) {
10148 return _.isString(value) || undefined;
10151 assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
10152 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10155 QUnit.test('should not handle comparisons if `customizer` returns `false`', function(assert) {
10158 var customizer = function(value) {
10159 return _.isString(value) ? false : undefined;
10162 assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
10163 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10166 QUnit.test('should return a boolean value even if `customizer` does not', function(assert) {
10169 var object = { 'a': 1 },
10170 actual = _.isMatchWith(object, { 'a': 1 }, alwaysA);
10172 assert.strictEqual(actual, true);
10174 var expected = lodashStable.map(falsey, alwaysFalse);
10177 lodashStable.each(falsey, function(value) {
10178 actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
10181 assert.deepEqual(actual, expected);
10184 QUnit.test('should ensure `customizer` is a function', function(assert) {
10187 var object = { 'a': 1 },
10188 matches = _.partial(_.isMatchWith, object),
10189 actual = lodashStable.map([object, { 'a': 2 }], matches);
10191 assert.deepEqual(actual, [true, false]);
10194 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
10197 var value = { 'a': { 'b': 2 } };
10200 var map1 = new Map;
10201 map1.set('a', value);
10203 var map2 = new Map;
10204 map2.set('a', value);
10207 var set1 = new Set;
10210 var set2 = new Set;
10213 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
10216 array = _.toArray(pair[0]),
10217 object1 = { 'a': pair[0] },
10218 object2 = { 'a': pair[1] };
10221 [pair[0], pair[1], 'a', object1, object2],
10222 [array[0], array[0], 0, array, array],
10223 [array[0][0], array[0][0], 0, array[0], array[0]],
10224 [array[0][1], array[0][1], 1, array[0], array[0]]
10228 expected.length = 2;
10230 _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
10231 argsList.push(slice.call(arguments, 0, -1));
10234 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
10237 skipAssert(assert);
10243 /*--------------------------------------------------------------------------*/
10245 QUnit.module('lodash.isNaN');
10248 var args = arguments;
10250 QUnit.test('should return `true` for NaNs', function(assert) {
10253 assert.strictEqual(_.isNaN(NaN), true);
10254 assert.strictEqual(_.isNaN(Object(NaN)), true);
10257 QUnit.test('should return `false` for non-NaNs', function(assert) {
10260 var expected = lodashStable.map(falsey, function(value) {
10261 return value !== value;
10264 var actual = lodashStable.map(falsey, function(value, index) {
10265 return index ? _.isNaN(value) : _.isNaN();
10268 assert.deepEqual(actual, expected);
10270 assert.strictEqual(_.isNaN(args), false);
10271 assert.strictEqual(_.isNaN([1, 2, 3]), false);
10272 assert.strictEqual(_.isNaN(true), false);
10273 assert.strictEqual(_.isNaN(new Date), false);
10274 assert.strictEqual(_.isNaN(new Error), false);
10275 assert.strictEqual(_.isNaN(_), false);
10276 assert.strictEqual(_.isNaN(slice), false);
10277 assert.strictEqual(_.isNaN({ 'a': 1 }), false);
10278 assert.strictEqual(_.isNaN(1), false);
10279 assert.strictEqual(_.isNaN(Object(1)), false);
10280 assert.strictEqual(_.isNaN(/x/), false);
10281 assert.strictEqual(_.isNaN('a'), false);
10282 assert.strictEqual(_.isNaN(symbol), false);
10285 QUnit.test('should work with `NaN` from another realm', function(assert) {
10288 if (realm.object) {
10289 assert.strictEqual(_.isNaN(realm.nan), true);
10292 skipAssert(assert);
10297 /*--------------------------------------------------------------------------*/
10299 QUnit.module('lodash.isNative');
10302 var args = arguments;
10304 QUnit.test('should return `true` for native methods', function(assert) {
10307 lodashStable.each([Array, create, root.encodeURI, slice, Uint8Array], function(func) {
10309 assert.strictEqual(_.isNative(func), true);
10312 skipAssert(assert);
10317 assert.strictEqual(_.isNative(body.cloneNode), true);
10320 skipAssert(assert);
10324 QUnit.test('should return `false` for non-native methods', function(assert) {
10327 var expected = lodashStable.map(falsey, alwaysFalse);
10329 var actual = lodashStable.map(falsey, function(value, index) {
10330 return index ? _.isNative(value) : _.isNative();
10333 assert.deepEqual(actual, expected);
10335 assert.strictEqual(_.isNative(args), false);
10336 assert.strictEqual(_.isNative([1, 2, 3]), false);
10337 assert.strictEqual(_.isNative(true), false);
10338 assert.strictEqual(_.isNative(new Date), false);
10339 assert.strictEqual(_.isNative(new Error), false);
10340 assert.strictEqual(_.isNative(_), false);
10341 assert.strictEqual(_.isNative({ 'a': 1 }), false);
10342 assert.strictEqual(_.isNative(1), false);
10343 assert.strictEqual(_.isNative(/x/), false);
10344 assert.strictEqual(_.isNative('a'), false);
10345 assert.strictEqual(_.isNative(symbol), false);
10348 QUnit.test('should work with native functions from another realm', function(assert) {
10351 if (realm.element) {
10352 assert.strictEqual(_.isNative(realm.element.cloneNode), true);
10355 skipAssert(assert);
10357 if (realm.object) {
10358 assert.strictEqual(_.isNative(realm.object.valueOf), true);
10361 skipAssert(assert);
10366 /*--------------------------------------------------------------------------*/
10368 QUnit.module('lodash.isNil');
10371 var args = arguments;
10373 QUnit.test('should return `true` for nullish values', function(assert) {
10376 assert.strictEqual(_.isNil(null), true);
10377 assert.strictEqual(_.isNil(), true);
10378 assert.strictEqual(_.isNil(undefined), true);
10381 QUnit.test('should return `false` for non-nullish values', function(assert) {
10384 var expected = lodashStable.map(falsey, function(value) {
10385 return value == null;
10388 var actual = lodashStable.map(falsey, function(value, index) {
10389 return index ? _.isNil(value) : _.isNil();
10392 assert.deepEqual(actual, expected);
10394 assert.strictEqual(_.isNil(args), false);
10395 assert.strictEqual(_.isNil([1, 2, 3]), false);
10396 assert.strictEqual(_.isNil(true), false);
10397 assert.strictEqual(_.isNil(new Date), false);
10398 assert.strictEqual(_.isNil(new Error), false);
10399 assert.strictEqual(_.isNil(_), false);
10400 assert.strictEqual(_.isNil(slice), false);
10401 assert.strictEqual(_.isNil({ 'a': 1 }), false);
10402 assert.strictEqual(_.isNil(1), false);
10403 assert.strictEqual(_.isNil(/x/), false);
10404 assert.strictEqual(_.isNil('a'), false);
10407 assert.strictEqual(_.isNil(symbol), false);
10410 skipAssert(assert);
10414 QUnit.test('should work with nulls from another realm', function(assert) {
10417 if (realm.object) {
10418 assert.strictEqual(_.isNil(realm.null), true);
10419 assert.strictEqual(_.isNil(realm.undefined), true);
10422 skipAssert(assert, 2);
10427 /*--------------------------------------------------------------------------*/
10429 QUnit.module('lodash.isNull');
10432 var args = arguments;
10434 QUnit.test('should return `true` for `null` values', function(assert) {
10437 assert.strictEqual(_.isNull(null), true);
10440 QUnit.test('should return `false` for non `null` values', function(assert) {
10443 var expected = lodashStable.map(falsey, function(value) {
10444 return value === null;
10447 var actual = lodashStable.map(falsey, function(value, index) {
10448 return index ? _.isNull(value) : _.isNull();
10451 assert.deepEqual(actual, expected);
10453 assert.strictEqual(_.isNull(args), false);
10454 assert.strictEqual(_.isNull([1, 2, 3]), false);
10455 assert.strictEqual(_.isNull(true), false);
10456 assert.strictEqual(_.isNull(new Date), false);
10457 assert.strictEqual(_.isNull(new Error), false);
10458 assert.strictEqual(_.isNull(_), false);
10459 assert.strictEqual(_.isNull(slice), false);
10460 assert.strictEqual(_.isNull({ 'a': 1 }), false);
10461 assert.strictEqual(_.isNull(1), false);
10462 assert.strictEqual(_.isNull(/x/), false);
10463 assert.strictEqual(_.isNull('a'), false);
10464 assert.strictEqual(_.isNull(symbol), false);
10467 QUnit.test('should work with nulls from another realm', function(assert) {
10470 if (realm.object) {
10471 assert.strictEqual(_.isNull(realm.null), true);
10474 skipAssert(assert);
10479 /*--------------------------------------------------------------------------*/
10481 QUnit.module('lodash.isNumber');
10484 var args = arguments;
10486 QUnit.test('should return `true` for numbers', function(assert) {
10489 assert.strictEqual(_.isNumber(0), true);
10490 assert.strictEqual(_.isNumber(Object(0)), true);
10491 assert.strictEqual(_.isNumber(NaN), true);
10494 QUnit.test('should return `false` for non-numbers', function(assert) {
10497 var expected = lodashStable.map(falsey, function(value) {
10498 return typeof value == 'number';
10501 var actual = lodashStable.map(falsey, function(value, index) {
10502 return index ? _.isNumber(value) : _.isNumber();
10505 assert.deepEqual(actual, expected);
10507 assert.strictEqual(_.isNumber(args), false);
10508 assert.strictEqual(_.isNumber([1, 2, 3]), false);
10509 assert.strictEqual(_.isNumber(true), false);
10510 assert.strictEqual(_.isNumber(new Date), false);
10511 assert.strictEqual(_.isNumber(new Error), false);
10512 assert.strictEqual(_.isNumber(_), false);
10513 assert.strictEqual(_.isNumber(slice), false);
10514 assert.strictEqual(_.isNumber({ 'a': 1 }), false);
10515 assert.strictEqual(_.isNumber(/x/), false);
10516 assert.strictEqual(_.isNumber('a'), false);
10517 assert.strictEqual(_.isNumber(symbol), false);
10520 QUnit.test('should work with numbers from another realm', function(assert) {
10523 if (realm.number) {
10524 assert.strictEqual(_.isNumber(realm.number), true);
10527 skipAssert(assert);
10531 QUnit.test('should avoid `[xpconnect wrapped native prototype]` in Firefox', function(assert) {
10534 assert.strictEqual(_.isNumber(+'2'), true);
10538 /*--------------------------------------------------------------------------*/
10540 QUnit.module('lodash.isObject');
10543 var args = arguments;
10545 QUnit.test('should return `true` for objects', function(assert) {
10548 assert.strictEqual(_.isObject(args), true);
10549 assert.strictEqual(_.isObject([1, 2, 3]), true);
10550 assert.strictEqual(_.isObject(Object(false)), true);
10551 assert.strictEqual(_.isObject(new Date), true);
10552 assert.strictEqual(_.isObject(new Error), true);
10553 assert.strictEqual(_.isObject(_), true);
10554 assert.strictEqual(_.isObject(slice), true);
10555 assert.strictEqual(_.isObject({ 'a': 1 }), true);
10556 assert.strictEqual(_.isObject(Object(0)), true);
10557 assert.strictEqual(_.isObject(/x/), true);
10558 assert.strictEqual(_.isObject(Object('a')), true);
10561 assert.strictEqual(_.isObject(body), true);
10564 skipAssert(assert);
10567 assert.strictEqual(_.isObject(Object(symbol)), true);
10570 skipAssert(assert);
10574 QUnit.test('should return `false` for non-objects', function(assert) {
10577 var values = falsey.concat(true, 1, 'a', symbol),
10578 expected = lodashStable.map(values, alwaysFalse);
10580 var actual = lodashStable.map(values, function(value, index) {
10581 return index ? _.isObject(value) : _.isObject();
10584 assert.deepEqual(actual, expected);
10587 QUnit.test('should work with objects from another realm', function(assert) {
10590 if (realm.element) {
10591 assert.strictEqual(_.isObject(realm.element), true);
10594 skipAssert(assert);
10596 if (realm.object) {
10597 assert.strictEqual(_.isObject(realm.boolean), true);
10598 assert.strictEqual(_.isObject(realm.date), true);
10599 assert.strictEqual(_.isObject(realm.function), true);
10600 assert.strictEqual(_.isObject(realm.number), true);
10601 assert.strictEqual(_.isObject(realm.object), true);
10602 assert.strictEqual(_.isObject(realm.regexp), true);
10603 assert.strictEqual(_.isObject(realm.string), true);
10606 skipAssert(assert, 7);
10610 QUnit.test('should avoid V8 bug #2291 (test in Chrome 19-20)', function(assert) {
10613 // Trigger a V8 JIT bug.
10614 // See https://code.google.com/p/v8/issues/detail?id=2291.
10617 // 1: Useless comparison statement, this is half the trigger.
10620 // 2: Initial check with object, this is the other half of the trigger.
10621 _.isObject(object);
10623 assert.strictEqual(_.isObject('a'), false);
10627 /*--------------------------------------------------------------------------*/
10629 QUnit.module('lodash.isObjectLike');
10632 var args = arguments;
10634 QUnit.test('should return `true` for objects', function(assert) {
10637 assert.strictEqual(_.isObjectLike(args), true);
10638 assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
10639 assert.strictEqual(_.isObjectLike(Object(false)), true);
10640 assert.strictEqual(_.isObjectLike(new Date), true);
10641 assert.strictEqual(_.isObjectLike(new Error), true);
10642 assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
10643 assert.strictEqual(_.isObjectLike(Object(0)), true);
10644 assert.strictEqual(_.isObjectLike(/x/), true);
10645 assert.strictEqual(_.isObjectLike(Object('a')), true);
10648 QUnit.test('should return `false` for non-objects', function(assert) {
10651 var values = falsey.concat(true, _, slice, 1, 'a', symbol),
10652 expected = lodashStable.map(values, alwaysFalse);
10654 var actual = lodashStable.map(values, function(value, index) {
10655 return index ? _.isObjectLike(value) : _.isObjectLike();
10658 assert.deepEqual(actual, expected);
10661 QUnit.test('should work with objects from another realm', function(assert) {
10664 if (realm.object) {
10665 assert.strictEqual(_.isObjectLike(realm.boolean), true);
10666 assert.strictEqual(_.isObjectLike(realm.date), true);
10667 assert.strictEqual(_.isObjectLike(realm.number), true);
10668 assert.strictEqual(_.isObjectLike(realm.object), true);
10669 assert.strictEqual(_.isObjectLike(realm.regexp), true);
10670 assert.strictEqual(_.isObjectLike(realm.string), true);
10673 skipAssert(assert, 6);
10678 /*--------------------------------------------------------------------------*/
10680 QUnit.module('lodash.isPlainObject');
10683 var element = document && document.createElement('div');
10685 QUnit.test('should detect plain objects', function(assert) {
10692 assert.strictEqual(_.isPlainObject({}), true);
10693 assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
10694 assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
10695 assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
10696 assert.strictEqual(_.isPlainObject(new Foo(1)), false);
10699 QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
10703 var object = create(null);
10704 assert.strictEqual(_.isPlainObject(object), true);
10706 object.constructor = objectProto.constructor;
10707 assert.strictEqual(_.isPlainObject(object), true);
10710 skipAssert(assert, 2);
10714 QUnit.test('should return `true` for plain objects with a custom `valueOf` property', function(assert) {
10717 assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
10720 var valueOf = element.valueOf;
10721 element.valueOf = 0;
10723 assert.strictEqual(_.isPlainObject(element), false);
10724 element.valueOf = valueOf;
10727 skipAssert(assert);
10731 QUnit.test('should return `false` for DOM elements', function(assert) {
10735 assert.strictEqual(_.isPlainObject(element), false);
10737 skipAssert(assert);
10741 QUnit.test('should return `false` for Object objects without a `toStringTag` of "Object"', function(assert) {
10744 assert.strictEqual(_.isPlainObject(arguments), false);
10745 assert.strictEqual(_.isPlainObject(Error), false);
10746 assert.strictEqual(_.isPlainObject(Math), false);
10749 QUnit.test('should return `false` for non-objects', function(assert) {
10752 var expected = lodashStable.map(falsey, alwaysFalse);
10754 var actual = lodashStable.map(falsey, function(value, index) {
10755 return index ? _.isPlainObject(value) : _.isPlainObject();
10758 assert.deepEqual(actual, expected);
10760 assert.strictEqual(_.isPlainObject(true), false);
10761 assert.strictEqual(_.isPlainObject('a'), false);
10762 assert.strictEqual(_.isPlainObject(symbol), false);
10765 QUnit.test('should work with objects from another realm', function(assert) {
10768 if (realm.object) {
10769 assert.strictEqual(_.isPlainObject(realm.object), true);
10772 skipAssert(assert);
10777 /*--------------------------------------------------------------------------*/
10779 QUnit.module('lodash.isRegExp');
10782 var args = arguments;
10784 QUnit.test('should return `true` for regexes', function(assert) {
10787 assert.strictEqual(_.isRegExp(/x/), true);
10788 assert.strictEqual(_.isRegExp(RegExp('x')), true);
10791 QUnit.test('should return `false` for non-regexes', function(assert) {
10794 var expected = lodashStable.map(falsey, alwaysFalse);
10796 var actual = lodashStable.map(falsey, function(value, index) {
10797 return index ? _.isRegExp(value) : _.isRegExp();
10800 assert.deepEqual(actual, expected);
10802 assert.strictEqual(_.isRegExp(args), false);
10803 assert.strictEqual(_.isRegExp([1, 2, 3]), false);
10804 assert.strictEqual(_.isRegExp(true), false);
10805 assert.strictEqual(_.isRegExp(new Date), false);
10806 assert.strictEqual(_.isRegExp(new Error), false);
10807 assert.strictEqual(_.isRegExp(_), false);
10808 assert.strictEqual(_.isRegExp(slice), false);
10809 assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
10810 assert.strictEqual(_.isRegExp(1), false);
10811 assert.strictEqual(_.isRegExp('a'), false);
10812 assert.strictEqual(_.isRegExp(symbol), false);
10815 QUnit.test('should work with regexes from another realm', function(assert) {
10818 if (realm.regexp) {
10819 assert.strictEqual(_.isRegExp(realm.regexp), true);
10822 skipAssert(assert);
10827 /*--------------------------------------------------------------------------*/
10829 QUnit.module('lodash.isSet');
10832 var args = arguments;
10834 QUnit.test('should return `true` for sets', function(assert) {
10838 assert.strictEqual(_.isSet(set), true);
10841 skipAssert(assert);
10845 QUnit.test('should return `false` for non sets', function(assert) {
10848 var expected = lodashStable.map(falsey, alwaysFalse);
10850 var actual = lodashStable.map(falsey, function(value, index) {
10851 return index ? _.isSet(value) : _.isSet();
10854 assert.deepEqual(actual, expected);
10856 assert.strictEqual(_.isSet(args), false);
10857 assert.strictEqual(_.isSet([1, 2, 3]), false);
10858 assert.strictEqual(_.isSet(true), false);
10859 assert.strictEqual(_.isSet(new Date), false);
10860 assert.strictEqual(_.isSet(new Error), false);
10861 assert.strictEqual(_.isSet(_), false);
10862 assert.strictEqual(_.isSet(slice), false);
10863 assert.strictEqual(_.isSet({ 'a': 1 }), false);
10864 assert.strictEqual(_.isSet(1), false);
10865 assert.strictEqual(_.isSet(/x/), false);
10866 assert.strictEqual(_.isSet('a'), false);
10867 assert.strictEqual(_.isSet(symbol), false);
10868 assert.strictEqual(_.isSet(weakSet), false);
10871 QUnit.test('should work with weak sets from another realm', function(assert) {
10875 assert.strictEqual(_.isSet(realm.set), true);
10878 skipAssert(assert);
10883 /*--------------------------------------------------------------------------*/
10885 QUnit.module('lodash.isString');
10888 var args = arguments;
10890 QUnit.test('should return `true` for strings', function(assert) {
10893 assert.strictEqual(_.isString('a'), true);
10894 assert.strictEqual(_.isString(Object('a')), true);
10897 QUnit.test('should return `false` for non-strings', function(assert) {
10900 var expected = lodashStable.map(falsey, function(value) {
10901 return value === '';
10904 var actual = lodashStable.map(falsey, function(value, index) {
10905 return index ? _.isString(value) : _.isString();
10908 assert.deepEqual(actual, expected);
10910 assert.strictEqual(_.isString(args), false);
10911 assert.strictEqual(_.isString([1, 2, 3]), false);
10912 assert.strictEqual(_.isString(true), false);
10913 assert.strictEqual(_.isString(new Date), false);
10914 assert.strictEqual(_.isString(new Error), false);
10915 assert.strictEqual(_.isString(_), false);
10916 assert.strictEqual(_.isString(slice), false);
10917 assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
10918 assert.strictEqual(_.isString(1), false);
10919 assert.strictEqual(_.isString(/x/), false);
10920 assert.strictEqual(_.isString(symbol), false);
10923 QUnit.test('should work with strings from another realm', function(assert) {
10926 if (realm.string) {
10927 assert.strictEqual(_.isString(realm.string), true);
10930 skipAssert(assert);
10935 /*--------------------------------------------------------------------------*/
10937 QUnit.module('lodash.isSymbol');
10940 var args = arguments;
10942 QUnit.test('should return `true` for symbols', function(assert) {
10946 assert.strictEqual(_.isSymbol(symbol), true);
10947 assert.strictEqual(_.isSymbol(Object(symbol)), true);
10950 skipAssert(assert, 2);
10954 QUnit.test('should return `false` for non-symbols', function(assert) {
10957 var expected = lodashStable.map(falsey, alwaysFalse);
10959 var actual = lodashStable.map(falsey, function(value, index) {
10960 return index ? _.isSymbol(value) : _.isSymbol();
10963 assert.deepEqual(actual, expected);
10965 assert.strictEqual(_.isSymbol(args), false);
10966 assert.strictEqual(_.isSymbol([1, 2, 3]), false);
10967 assert.strictEqual(_.isSymbol(true), false);
10968 assert.strictEqual(_.isSymbol(new Date), false);
10969 assert.strictEqual(_.isSymbol(new Error), false);
10970 assert.strictEqual(_.isSymbol(_), false);
10971 assert.strictEqual(_.isSymbol(slice), false);
10972 assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
10973 assert.strictEqual(_.isSymbol(1), false);
10974 assert.strictEqual(_.isSymbol(/x/), false);
10975 assert.strictEqual(_.isSymbol('a'), false);
10978 QUnit.test('should work with symbols from another realm', function(assert) {
10981 if (Symbol && realm.symbol) {
10982 assert.strictEqual(_.isSymbol(realm.symbol), true);
10985 skipAssert(assert);
10990 /*--------------------------------------------------------------------------*/
10992 QUnit.module('lodash.isTypedArray');
10995 var args = arguments;
10997 QUnit.test('should return `true` for typed arrays', function(assert) {
11000 var expected = lodashStable.map(typedArrays, function(type) {
11001 return type in root;
11004 var actual = lodashStable.map(typedArrays, function(type) {
11005 var Ctor = root[type];
11006 return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
11009 assert.deepEqual(actual, expected);
11012 QUnit.test('should return `false` for non typed arrays', function(assert) {
11015 var expected = lodashStable.map(falsey, alwaysFalse);
11017 var actual = lodashStable.map(falsey, function(value, index) {
11018 return index ? _.isTypedArray(value) : _.isTypedArray();
11021 assert.deepEqual(actual, expected);
11023 assert.strictEqual(_.isTypedArray(args), false);
11024 assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
11025 assert.strictEqual(_.isTypedArray(true), false);
11026 assert.strictEqual(_.isTypedArray(new Date), false);
11027 assert.strictEqual(_.isTypedArray(new Error), false);
11028 assert.strictEqual(_.isTypedArray(_), false);
11029 assert.strictEqual(_.isTypedArray(slice), false);
11030 assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
11031 assert.strictEqual(_.isTypedArray(1), false);
11032 assert.strictEqual(_.isTypedArray(/x/), false);
11033 assert.strictEqual(_.isTypedArray('a'), false);
11034 assert.strictEqual(_.isTypedArray(symbol), false);
11037 QUnit.test('should work with typed arrays from another realm', function(assert) {
11040 if (realm.object) {
11041 var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
11043 var expected = lodashStable.map(props, function(key) {
11044 return realm[key] !== undefined;
11047 var actual = lodashStable.map(props, function(key) {
11048 var value = realm[key];
11049 return value ? _.isTypedArray(value) : false;
11052 assert.deepEqual(actual, expected);
11055 skipAssert(assert);
11060 /*--------------------------------------------------------------------------*/
11062 QUnit.module('lodash.isUndefined');
11065 var args = arguments;
11067 QUnit.test('should return `true` for `undefined` values', function(assert) {
11070 assert.strictEqual(_.isUndefined(), true);
11071 assert.strictEqual(_.isUndefined(undefined), true);
11074 QUnit.test('should return `false` for non `undefined` values', function(assert) {
11077 var expected = lodashStable.map(falsey, function(value) {
11078 return value === undefined;
11081 var actual = lodashStable.map(falsey, function(value, index) {
11082 return index ? _.isUndefined(value) : _.isUndefined();
11085 assert.deepEqual(actual, expected);
11087 assert.strictEqual(_.isUndefined(args), false);
11088 assert.strictEqual(_.isUndefined([1, 2, 3]), false);
11089 assert.strictEqual(_.isUndefined(true), false);
11090 assert.strictEqual(_.isUndefined(new Date), false);
11091 assert.strictEqual(_.isUndefined(new Error), false);
11092 assert.strictEqual(_.isUndefined(_), false);
11093 assert.strictEqual(_.isUndefined(slice), false);
11094 assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
11095 assert.strictEqual(_.isUndefined(1), false);
11096 assert.strictEqual(_.isUndefined(/x/), false);
11097 assert.strictEqual(_.isUndefined('a'), false);
11100 assert.strictEqual(_.isUndefined(symbol), false);
11103 skipAssert(assert);
11107 QUnit.test('should work with `undefined` from another realm', function(assert) {
11110 if (realm.object) {
11111 assert.strictEqual(_.isUndefined(realm.undefined), true);
11114 skipAssert(assert);
11119 /*--------------------------------------------------------------------------*/
11121 QUnit.module('lodash.isWeakMap');
11124 var args = arguments;
11126 QUnit.test('should return `true` for weak maps', function(assert) {
11130 assert.strictEqual(_.isWeakMap(weakMap), true);
11133 skipAssert(assert);
11137 QUnit.test('should return `false` for non weak maps', function(assert) {
11140 var expected = lodashStable.map(falsey, alwaysFalse);
11142 var actual = lodashStable.map(falsey, function(value, index) {
11143 return index ? _.isWeakMap(value) : _.isWeakMap();
11146 assert.deepEqual(actual, expected);
11148 assert.strictEqual(_.isWeakMap(args), false);
11149 assert.strictEqual(_.isWeakMap([1, 2, 3]), false);
11150 assert.strictEqual(_.isWeakMap(true), false);
11151 assert.strictEqual(_.isWeakMap(new Date), false);
11152 assert.strictEqual(_.isWeakMap(new Error), false);
11153 assert.strictEqual(_.isWeakMap(_), false);
11154 assert.strictEqual(_.isWeakMap(slice), false);
11155 assert.strictEqual(_.isWeakMap({ 'a': 1 }), false);
11156 assert.strictEqual(_.isWeakMap(map), false);
11157 assert.strictEqual(_.isWeakMap(1), false);
11158 assert.strictEqual(_.isWeakMap(/x/), false);
11159 assert.strictEqual(_.isWeakMap('a'), false);
11160 assert.strictEqual(_.isWeakMap(symbol), false);
11163 QUnit.test('should work with weak maps from another realm', function(assert) {
11166 if (realm.weakMap) {
11167 assert.strictEqual(_.isWeakMap(realm.weakMap), true);
11170 skipAssert(assert);
11175 /*--------------------------------------------------------------------------*/
11177 QUnit.module('lodash.isWeakSet');
11180 var args = arguments;
11182 QUnit.test('should return `true` for weak sets', function(assert) {
11186 assert.strictEqual(_.isWeakSet(weakSet), true);
11189 skipAssert(assert);
11193 QUnit.test('should return `false` for non weak sets', function(assert) {
11196 var expected = lodashStable.map(falsey, alwaysFalse);
11198 var actual = lodashStable.map(falsey, function(value, index) {
11199 return index ? _.isWeakSet(value) : _.isWeakSet();
11202 assert.deepEqual(actual, expected);
11204 assert.strictEqual(_.isWeakSet(args), false);
11205 assert.strictEqual(_.isWeakSet([1, 2, 3]), false);
11206 assert.strictEqual(_.isWeakSet(true), false);
11207 assert.strictEqual(_.isWeakSet(new Date), false);
11208 assert.strictEqual(_.isWeakSet(new Error), false);
11209 assert.strictEqual(_.isWeakSet(_), false);
11210 assert.strictEqual(_.isWeakSet(slice), false);
11211 assert.strictEqual(_.isWeakSet({ 'a': 1 }), false);
11212 assert.strictEqual(_.isWeakSet(1), false);
11213 assert.strictEqual(_.isWeakSet(/x/), false);
11214 assert.strictEqual(_.isWeakSet('a'), false);
11215 assert.strictEqual(_.isWeakSet(set), false);
11216 assert.strictEqual(_.isWeakSet(symbol), false);
11219 QUnit.test('should work with weak sets from another realm', function(assert) {
11222 if (realm.weakSet) {
11223 assert.strictEqual(_.isWeakSet(realm.weakSet), true);
11226 skipAssert(assert);
11231 /*--------------------------------------------------------------------------*/
11233 QUnit.module('isType checks');
11236 QUnit.test('should return `false` for subclassed values', function(assert) {
11240 'isArray', 'isBoolean', 'isDate', 'isFunction',
11241 'isNumber', 'isRegExp', 'isString'
11244 lodashStable.each(funcs, function(methodName) {
11246 Foo.prototype = root[methodName.slice(2)].prototype;
11248 var object = new Foo;
11249 if (objToString.call(object) == objectTag) {
11250 assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
11252 skipAssert(assert);
11257 QUnit.test('should not error on host objects (test in IE)', function(assert) {
11261 'isArguments', 'isArray', 'isArrayBuffer', 'isArrayLike', 'isBoolean',
11262 'isBuffer', 'isDate', 'isElement', 'isError', 'isFinite', 'isFunction',
11263 'isInteger', 'isMap', 'isNaN', 'isNil', 'isNull', 'isNumber', 'isObject',
11264 'isObjectLike', 'isRegExp', 'isSet', 'isSafeInteger', 'isString',
11265 'isUndefined', 'isWeakMap', 'isWeakSet'
11268 lodashStable.each(funcs, function(methodName) {
11273 _[methodName](xml);
11277 assert.ok(pass, '`_.' + methodName + '` should not error');
11280 skipAssert(assert);
11286 /*--------------------------------------------------------------------------*/
11288 QUnit.module('lodash.iteratee');
11291 QUnit.test('should provide arguments to `func`', function(assert) {
11294 var fn = function() { return slice.call(arguments); },
11295 iteratee = _.iteratee(fn),
11296 actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
11298 assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
11301 QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
11305 values = [, null, undefined],
11306 expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
11308 var actual = lodashStable.map(values, function(value, index) {
11309 var identity = index ? _.iteratee(value) : _.iteratee();
11310 return [!isNpm && identity, identity(object)];
11313 assert.deepEqual(actual, expected);
11316 QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
11319 var matches = _.iteratee({ 'a': 1, 'b': 2 });
11320 assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
11321 assert.strictEqual(matches({ 'b': 2 }), false);
11324 QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
11328 { 'a': { 'b': 2, 'c': 3 } },
11329 { 'a': 1, 'b': 2 },
11333 lodashStable.each(sources, function(source, index) {
11334 var object = lodashStable.cloneDeep(source),
11335 matches = _.iteratee(source);
11337 assert.strictEqual(matches(object), true);
11348 assert.strictEqual(matches(object), true);
11349 assert.strictEqual(matches(source), false);
11353 QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
11356 var array = ['a', undefined],
11357 matches = _.iteratee([0, 'a']);
11359 assert.strictEqual(matches(array), true);
11361 matches = _.iteratee(['0', 'a']);
11362 assert.strictEqual(matches(array), true);
11364 matches = _.iteratee([1, undefined]);
11365 assert.strictEqual(matches(array), true);
11368 QUnit.test('should support deep paths for "_.matchesProperty" shorthands', function(assert) {
11371 var object = { 'a': { 'b': { 'c': { 'd': 1, 'e': 2 } } } },
11372 matches = _.iteratee(['a.b.c', { 'e': 2 }]);
11374 assert.strictEqual(matches(object), true);
11377 QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
11381 { 'a': { 'b': 2, 'c': 3 } },
11382 { 'a': 1, 'b': 2 },
11386 lodashStable.each(sources, function(source, index) {
11387 var object = { 'a': lodashStable.cloneDeep(source) },
11388 matches = _.iteratee(['a', source]);
11390 assert.strictEqual(matches(object), true);
11401 assert.strictEqual(matches(object), true);
11402 assert.strictEqual(matches({ 'a': source }), false);
11406 QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
11410 prop = _.iteratee(0);
11412 assert.strictEqual(prop(array), 'a');
11414 prop = _.iteratee('0');
11415 assert.strictEqual(prop(array), 'a');
11418 QUnit.test('should support deep paths for "_.property" shorthands', function(assert) {
11421 var object = { 'a': { 'b': { 'c': 3 } } },
11422 prop = _.iteratee('a.b.c');
11424 assert.strictEqual(prop(object), 3);
11427 QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
11430 var fn = function() {
11431 var result = [this.a];
11432 push.apply(result, arguments);
11436 var expected = [1, 2, 3],
11437 object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
11439 assert.deepEqual(object.iteratee(3), expected);
11441 object.iteratee = _.iteratee(_.partialRight(fn, 3));
11442 assert.deepEqual(object.iteratee(2), expected);
11445 QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
11448 var iteratee = _.iteratee;
11451 assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
11453 _.iteratee = iteratee;
11456 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
11459 var fn = function() { return this instanceof Number; },
11460 array = [fn, fn, fn],
11461 iteratees = lodashStable.map(array, _.iteratee),
11462 expected = lodashStable.map(array, alwaysFalse);
11464 var actual = lodashStable.map(iteratees, function(iteratee) {
11468 assert.deepEqual(actual, expected);
11472 /*--------------------------------------------------------------------------*/
11474 QUnit.module('custom `_.iteratee` methods');
11477 var array = ['one', 'two', 'three'],
11478 getPropA = _.partial(_.property, 'a'),
11479 getPropB = _.partial(_.property, 'b'),
11480 getLength = _.partial(_.property, 'length'),
11481 iteratee = _.iteratee;
11483 var getSum = function() {
11484 return function(result, object) {
11485 return result + object.a;
11490 { 'a': 0, 'b': 0 },
11491 { 'a': 1, 'b': 0 },
11495 QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
11498 if (!isModularize) {
11499 _.iteratee = getLength;
11500 assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
11501 _.iteratee = iteratee;
11504 skipAssert(assert);
11508 QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
11511 if (!isModularize) {
11512 _.iteratee = getPropA;
11513 assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
11514 _.iteratee = iteratee;
11517 skipAssert(assert);
11521 QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
11524 if (!isModularize) {
11525 _.iteratee = getPropB;
11526 assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
11527 _.iteratee = iteratee;
11530 skipAssert(assert);
11534 QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
11537 if (!isModularize) {
11538 _.iteratee = getPropB;
11539 assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
11540 _.iteratee = iteratee;
11543 skipAssert(assert);
11547 QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
11550 if (!isModularize) {
11551 _.iteratee = getPropA;
11552 assert.strictEqual(_.every(objects.slice(1)), true);
11553 _.iteratee = iteratee;
11556 skipAssert(assert);
11560 QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
11563 if (!isModularize) {
11564 var objects = [{ 'a': 0 }, { 'a': 1 }];
11566 _.iteratee = getPropA;
11567 assert.deepEqual(_.filter(objects), [objects[1]]);
11568 _.iteratee = iteratee;
11571 skipAssert(assert);
11575 QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
11578 if (!isModularize) {
11579 _.iteratee = getPropA;
11580 assert.strictEqual(_.find(objects), objects[1]);
11581 _.iteratee = iteratee;
11584 skipAssert(assert);
11588 QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
11591 if (!isModularize) {
11592 _.iteratee = getPropA;
11593 assert.strictEqual(_.findIndex(objects), 1);
11594 _.iteratee = iteratee;
11597 skipAssert(assert);
11601 QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
11604 if (!isModularize) {
11605 _.iteratee = getPropA;
11606 assert.strictEqual(_.findLast(objects), objects[2]);
11607 _.iteratee = iteratee;
11610 skipAssert(assert);
11614 QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
11617 if (!isModularize) {
11618 _.iteratee = getPropA;
11619 assert.strictEqual(_.findLastIndex(objects), 2);
11620 _.iteratee = iteratee;
11623 skipAssert(assert);
11627 QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
11630 if (!isModularize) {
11631 _.iteratee = getPropB;
11632 assert.strictEqual(_.findKey(objects), '2');
11633 _.iteratee = iteratee;
11636 skipAssert(assert);
11640 QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
11643 if (!isModularize) {
11644 _.iteratee = getPropB;
11645 assert.strictEqual(_.findLastKey(objects), '2');
11646 _.iteratee = iteratee;
11649 skipAssert(assert);
11653 QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
11656 if (!isModularize) {
11657 _.iteratee = getLength;
11658 assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
11659 _.iteratee = iteratee;
11662 skipAssert(assert);
11666 QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
11669 if (!isModularize) {
11670 _.iteratee = getPropA;
11671 assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
11672 _.iteratee = iteratee;
11675 skipAssert(assert);
11679 QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
11682 if (!isModularize) {
11683 _.iteratee = getLength;
11684 assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
11685 _.iteratee = iteratee;
11688 skipAssert(assert);
11692 QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
11695 if (!isModularize) {
11696 _.iteratee = getPropA;
11697 assert.deepEqual(_.map(objects), [0, 1, 1]);
11698 _.iteratee = iteratee;
11701 skipAssert(assert);
11705 QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
11708 if (!isModularize) {
11709 _.iteratee = getPropB;
11710 assert.deepEqual(_.mapKeys({ 'a': { 'b': 1 } }), { '1': { 'b': 1 } });
11711 _.iteratee = iteratee;
11714 skipAssert(assert);
11718 QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
11721 if (!isModularize) {
11722 _.iteratee = getPropB;
11723 assert.deepEqual(_.mapValues({ 'a': { 'b': 1 } }), { 'a': 1 });
11724 _.iteratee = iteratee;
11727 skipAssert(assert);
11731 QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
11734 if (!isModularize) {
11735 _.iteratee = getPropB;
11736 assert.deepEqual(_.maxBy(objects), objects[2]);
11737 _.iteratee = iteratee;
11740 skipAssert(assert);
11744 QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
11747 if (!isModularize) {
11748 _.iteratee = getPropB;
11749 assert.deepEqual(_.minBy(objects), objects[0]);
11750 _.iteratee = iteratee;
11753 skipAssert(assert);
11757 QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
11760 if (!isModularize) {
11761 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
11763 _.iteratee = getPropA;
11764 assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
11765 _.iteratee = iteratee;
11768 skipAssert(assert);
11772 QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
11775 if (!isModularize) {
11776 _.iteratee = getPropA;
11777 assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
11778 _.iteratee = iteratee;
11781 skipAssert(assert);
11785 QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
11788 if (!isModularize) {
11789 _.iteratee = getSum;
11790 assert.strictEqual(_.reduce(objects, undefined, 0), 2);
11791 _.iteratee = iteratee;
11794 skipAssert(assert);
11798 QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
11801 if (!isModularize) {
11802 _.iteratee = getSum;
11803 assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
11804 _.iteratee = iteratee;
11807 skipAssert(assert);
11811 QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
11814 if (!isModularize) {
11815 var objects = [{ 'a': 0 }, { 'a': 1 }];
11817 _.iteratee = getPropA;
11818 assert.deepEqual(_.reject(objects), [objects[0]]);
11819 _.iteratee = iteratee;
11822 skipAssert(assert);
11826 QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
11829 if (!isModularize) {
11830 var objects = [{ 'a': 0 }, { 'a': 1 }];
11832 _.iteratee = getPropA;
11834 assert.deepEqual(objects, [{ 'a': 0 }]);
11835 _.iteratee = iteratee;
11838 skipAssert(assert);
11842 QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
11845 if (!isModularize) {
11846 _.iteratee = getPropB;
11847 assert.strictEqual(_.some(objects), true);
11848 _.iteratee = iteratee;
11851 skipAssert(assert);
11855 QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
11858 if (!isModularize) {
11859 _.iteratee = getPropA;
11860 assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
11861 _.iteratee = iteratee;
11864 skipAssert(assert);
11868 QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
11871 if (!isModularize) {
11872 var objects = [{ 'a': 30 }, { 'a': 50 }];
11874 _.iteratee = getPropA;
11875 assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
11876 _.iteratee = iteratee;
11879 skipAssert(assert);
11883 QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
11886 if (!isModularize) {
11887 var objects = [{ 'a': 30 }, { 'a': 50 }];
11889 _.iteratee = getPropA;
11890 assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
11891 _.iteratee = iteratee;
11894 skipAssert(assert);
11898 QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
11901 if (!isModularize) {
11902 _.iteratee = getPropB;
11903 assert.strictEqual(_.sumBy(objects), 1);
11904 _.iteratee = iteratee;
11907 skipAssert(assert);
11911 QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
11914 if (!isModularize) {
11915 _.iteratee = getPropB;
11916 assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
11917 _.iteratee = iteratee;
11920 skipAssert(assert);
11924 QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
11927 if (!isModularize) {
11928 _.iteratee = getPropB;
11929 assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
11930 _.iteratee = iteratee;
11933 skipAssert(assert);
11937 QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
11940 if (!isModularize) {
11941 _.iteratee = function() {
11942 return function(result, object) {
11943 result.sum += object.a;
11947 assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
11948 _.iteratee = iteratee;
11951 skipAssert(assert);
11955 QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
11958 if (!isModularize) {
11959 _.iteratee = getPropB;
11960 assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
11961 _.iteratee = iteratee;
11964 skipAssert(assert);
11968 QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
11971 if (!isModularize) {
11972 _.iteratee = getPropB;
11973 assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
11974 _.iteratee = iteratee;
11977 skipAssert(assert);
11981 QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
11984 if (!isModularize) {
11985 _.iteratee = getPropA;
11986 assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
11987 _.iteratee = iteratee;
11990 skipAssert(assert);
11995 /*--------------------------------------------------------------------------*/
11997 QUnit.module('lodash.join');
12000 var array = ['a', 'b', 'c'];
12002 QUnit.test('should return join all array elements into a string', function(assert) {
12005 assert.strictEqual(_.join(array, '~'), 'a~b~c');
12008 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12012 var wrapped = _(array);
12013 assert.strictEqual(wrapped.join('~'), 'a~b~c');
12014 assert.strictEqual(wrapped.value(), array);
12017 skipAssert(assert, 2);
12021 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12025 assert.ok(_(array).chain().join('~') instanceof _);
12028 skipAssert(assert);
12033 /*--------------------------------------------------------------------------*/
12035 QUnit.module('lodash.keyBy');
12039 { 'dir': 'left', 'code': 97 },
12040 { 'dir': 'right', 'code': 100 }
12043 QUnit.test('should transform keys by `iteratee`', function(assert) {
12046 var expected = { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } };
12048 var actual = _.keyBy(array, function(object) {
12049 return String.fromCharCode(object.code);
12052 assert.deepEqual(actual, expected);
12055 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
12058 var array = [4, 6, 6],
12059 values = [, null, undefined],
12060 expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
12062 var actual = lodashStable.map(values, function(value, index) {
12063 return index ? _.keyBy(array, value) : _.keyBy(array);
12066 assert.deepEqual(actual, expected);
12069 QUnit.test('should work with "_.property" shorthands', function(assert) {
12072 var expected = { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } },
12073 actual = _.keyBy(array, 'dir');
12075 assert.deepEqual(actual, expected);
12078 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
12081 var actual = _.keyBy([6.1, 4.2, 6.3], function(n) {
12082 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
12085 assert.deepEqual(actual.constructor, 4.2);
12086 assert.deepEqual(actual.hasOwnProperty, 6.3);
12089 QUnit.test('should work with a number for `iteratee`', function(assert) {
12098 assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
12099 assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
12102 QUnit.test('should work with an object for `collection`', function(assert) {
12105 var actual = _.keyBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
12106 assert.deepEqual(actual, { '4': 4.2, '6': 6.3 });
12109 QUnit.test('should work in a lazy sequence', function(assert) {
12113 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
12114 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
12115 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
12118 var actual = _(array).keyBy().map(square).filter(isEven).take().value();
12120 assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
12123 skipAssert(assert);
12128 /*--------------------------------------------------------------------------*/
12130 QUnit.module('keys methods');
12132 lodashStable.each(['keys', 'keysIn'], function(methodName) {
12133 var args = (function() { return arguments; }(1, 2, 3)),
12134 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
12135 func = _[methodName],
12136 isKeys = methodName == 'keys';
12138 QUnit.test('`_.' + methodName + '` should return the keys of an object', function(assert) {
12141 assert.deepEqual(func({ 'a': 1, 'b': 1 }).sort(), ['a', 'b']);
12144 QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
12147 assert.deepEqual(func('abc').sort(), ['0', '1', '2']);
12149 // IE 9 doesn't box numbers in for-in loops.
12151 assert.deepEqual(func(0), isKeys ? [] : ['a']);
12152 delete numberProto.a;
12155 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
12161 assert.deepEqual(func(array).sort(), ['0', '1', '2']);
12164 QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) {
12168 lodashStable.each([null, undefined], function(value) {
12169 assert.deepEqual(func(value), []);
12171 delete objectProto.a;
12174 QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
12180 assert.deepEqual(func(array).sort(), ['0', 'a']);
12183 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of arrays', function(assert) {
12186 var expected = isKeys ? ['0'] : ['0', 'a'];
12189 assert.deepEqual(func([1]).sort(), expected);
12190 delete arrayProto.a;
12193 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
12196 var values = [args, strictArgs],
12197 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2'])),
12198 actual = lodashStable.map(values, func);
12200 assert.deepEqual(actual, expected);
12203 QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
12206 var values = [args, strictArgs],
12207 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
12209 var actual = lodashStable.map(values, function(value) {
12211 var result = func(value).sort();
12216 assert.deepEqual(actual, expected);
12219 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of `arguments` objects', function(assert) {
12222 var values = [args, strictArgs],
12223 expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
12225 var actual = lodashStable.map(values, function(value) {
12227 var result = func(value).sort();
12228 delete objectProto.a;
12232 assert.deepEqual(actual, expected);
12235 QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
12238 assert.deepEqual(func(Object('abc')).sort(), ['0', '1', '2']);
12241 QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
12244 var object = Object('a');
12247 assert.deepEqual(func(object).sort(), ['0', 'a']);
12250 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of string objects', function(assert) {
12253 var expected = isKeys ? ['0'] : ['0', 'a'];
12256 assert.deepEqual(func(Object('a')).sort(), expected);
12257 delete stringProto.a;
12260 QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
12264 Foo.prototype.a = 1;
12266 var expected = ['a'];
12267 assert.deepEqual(func(Foo.prototype), expected);
12269 Foo.prototype = { 'constructor': Foo, 'a': 1 };
12270 assert.deepEqual(func(Foo.prototype), expected);
12272 var Fake = { 'prototype': {} };
12273 Fake.prototype.constructor = Fake;
12274 assert.deepEqual(func(Fake.prototype), ['constructor']);
12277 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties', function(assert) {
12280 function Foo() { this.a = 1; }
12281 Foo.prototype.b = 2;
12283 var expected = isKeys ? ['a'] : ['a', 'b'];
12284 assert.deepEqual(func(new Foo).sort(), expected);
12288 /*--------------------------------------------------------------------------*/
12290 QUnit.module('lodash.last');
12293 var array = [1, 2, 3, 4];
12295 QUnit.test('should return the last element', function(assert) {
12298 assert.strictEqual(_.last(array), 4);
12301 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
12307 assert.strictEqual(_.last([]), undefined);
12310 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
12313 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
12314 actual = lodashStable.map(array, _.last);
12316 assert.deepEqual(actual, [3, 6, 9]);
12319 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12323 assert.strictEqual(_(array).last(), 4);
12326 skipAssert(assert);
12330 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12334 assert.ok(_(array).chain().last() instanceof _);
12337 skipAssert(assert);
12341 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
12345 var wrapped = _(array).chain().last();
12346 assert.strictEqual(wrapped.__wrapped__, array);
12349 skipAssert(assert);
12353 QUnit.test('should work in a lazy sequence', function(assert) {
12357 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
12358 smallArray = array;
12360 lodashStable.times(2, function(index) {
12361 var array = index ? largeArray : smallArray,
12362 wrapped = _(array).filter(isEven);
12364 assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
12368 skipAssert(assert, 2);
12373 /*--------------------------------------------------------------------------*/
12375 QUnit.module('lodash.lowerCase');
12378 QUnit.test('should lowercase as space-separated words', function(assert) {
12381 assert.strictEqual(_.lowerCase('--Foo-Bar'), 'foo bar');
12382 assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
12383 assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
12387 /*--------------------------------------------------------------------------*/
12389 QUnit.module('lodash.lowerFirst');
12392 QUnit.test('should lowercase only the first character', function(assert) {
12395 assert.strictEqual(_.lowerFirst('fred'), 'fred');
12396 assert.strictEqual(_.lowerFirst('Fred'), 'fred');
12397 assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
12401 /*--------------------------------------------------------------------------*/
12403 QUnit.module('lodash.lt');
12406 QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
12409 assert.strictEqual(_.lt(1, 3), true);
12410 assert.strictEqual(_.lt('abc', 'def'), true);
12413 QUnit.test('should return `false` if `value` >= `other`', function(assert) {
12416 assert.strictEqual(_.lt(3, 1), false);
12417 assert.strictEqual(_.lt(3, 3), false);
12418 assert.strictEqual(_.lt('def', 'abc'), false);
12419 assert.strictEqual(_.lt('def', 'def'), false);
12423 /*--------------------------------------------------------------------------*/
12425 QUnit.module('lodash.lte');
12428 QUnit.test('should return `true` if `value` is <= `other`', function(assert) {
12431 assert.strictEqual(_.lte(1, 3), true);
12432 assert.strictEqual(_.lte(3, 3), true);
12433 assert.strictEqual(_.lte('abc', 'def'), true);
12434 assert.strictEqual(_.lte('def', 'def'), true);
12437 QUnit.test('should return `false` if `value` > `other`', function(assert) {
12440 assert.strictEqual(_.lt(3, 1), false);
12441 assert.strictEqual(_.lt('def', 'abc'), false);
12445 /*--------------------------------------------------------------------------*/
12447 QUnit.module('lodash.lastIndexOf');
12450 var array = [1, 2, 3, 1, 2, 3];
12452 QUnit.test('should return the index of the last matched value', function(assert) {
12455 assert.strictEqual(_.lastIndexOf(array, 3), 5);
12458 QUnit.test('should work with a positive `fromIndex`', function(assert) {
12461 assert.strictEqual(_.lastIndexOf(array, 1, 2), 0);
12464 QUnit.test('should work with `fromIndex` >= `array.length`', function(assert) {
12467 var values = [6, 8, Math.pow(2, 32), Infinity],
12468 expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
12470 var actual = lodashStable.map(values, function(fromIndex) {
12472 _.lastIndexOf(array, undefined, fromIndex),
12473 _.lastIndexOf(array, 1, fromIndex),
12474 _.lastIndexOf(array, '', fromIndex)
12478 assert.deepEqual(actual, expected);
12481 QUnit.test('should work with a negative `fromIndex`', function(assert) {
12484 assert.strictEqual(_.lastIndexOf(array, 2, -3), 1);
12487 QUnit.test('should work with a negative `fromIndex` <= `-array.length`', function(assert) {
12490 var values = [-6, -8, -Infinity],
12491 expected = lodashStable.map(values, alwaysZero);
12493 var actual = lodashStable.map(values, function(fromIndex) {
12494 return _.lastIndexOf(array, 1, fromIndex);
12497 assert.deepEqual(actual, expected);
12500 QUnit.test('should treat falsey `fromIndex` values correctly', function(assert) {
12503 var expected = lodashStable.map(falsey, function(value) {
12504 return value === undefined ? 5 : -1;
12507 var actual = lodashStable.map(falsey, function(fromIndex) {
12508 return _.lastIndexOf(array, 3, fromIndex);
12511 assert.deepEqual(actual, expected);
12514 QUnit.test('should coerce `fromIndex` to an integer', function(assert) {
12517 assert.strictEqual(_.lastIndexOf(array, 2, 4.2), 4);
12521 /*--------------------------------------------------------------------------*/
12523 QUnit.module('indexOf methods');
12525 lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
12526 var func = _[methodName],
12527 isIndexOf = !/last/i.test(methodName),
12528 isSorted = /^sorted/.test(methodName);
12530 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument', function(assert) {
12533 var expected = lodashStable.map(falsey, lodashStable.constant(-1));
12535 var actual = lodashStable.map(falsey, function(array, index) {
12537 return index ? func(array) : func();
12541 assert.deepEqual(actual, expected);
12544 QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
12547 var array = [1, 2, 3],
12550 assert.strictEqual(func(array, 4), -1);
12551 assert.strictEqual(func(array, 4, true), -1);
12552 assert.strictEqual(func(array, undefined, true), -1);
12554 assert.strictEqual(func(empty, undefined), -1);
12555 assert.strictEqual(func(empty, undefined, true), -1);
12558 QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
12564 assert.strictEqual(func(array, undefined), -1);
12565 assert.strictEqual(func(array, 0, true), -1);
12568 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
12571 var array = isSorted
12573 : [1, NaN, 3, NaN, 5, NaN];
12576 assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
12577 skipAssert(assert, 3);
12580 assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
12581 assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
12582 assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
12583 skipAssert(assert);
12587 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
12590 assert.strictEqual(func([-0], 0), 0);
12591 assert.strictEqual(func([0], -0), 0);
12595 /*--------------------------------------------------------------------------*/
12597 QUnit.module('lodash.map');
12600 var array = [1, 2];
12602 QUnit.test('should map values in `collection` to a new array', function(assert) {
12605 var object = { 'a': 1, 'b': 2 },
12606 expected = ['1', '2'];
12608 assert.deepEqual(_.map(array, String), expected);
12609 assert.deepEqual(_.map(object, String), expected);
12612 QUnit.test('should work with "_.property" shorthands', function(assert) {
12615 var objects = [{ 'a': 'x' }, { 'a': 'y' }];
12616 assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
12619 QUnit.test('should iterate over own properties of objects', function(assert) {
12622 function Foo() { this.a = 1; }
12623 Foo.prototype.b = 2;
12625 var actual = _.map(new Foo, identity);
12626 assert.deepEqual(actual, [1]);
12629 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
12632 var values = [, null, undefined],
12633 expected = lodashStable.map(values, lodashStable.constant([1, 2]));
12635 var actual = lodashStable.map(values, function(value, index) {
12636 return index ? _.map(array, value) : _.map(array);
12639 assert.deepEqual(actual, expected);
12642 QUnit.test('should work on an object with no `iteratee`', function(assert) {
12645 var actual = _.map({ 'a': 1, 'b': 2 });
12646 assert.deepEqual(actual, array);
12649 QUnit.test('should handle object arguments with non-number length properties', function(assert) {
12652 var value = { 'value': 'x' },
12653 object = { 'length': { 'value': 'x' } };
12655 assert.deepEqual(_.map(object, identity), [value]);
12658 QUnit.test('should treat a nodelist as an array-like object', function(assert) {
12662 var actual = _.map(document.getElementsByTagName('body'), function(element) {
12663 return element.nodeName.toLowerCase();
12666 assert.deepEqual(actual, ['body']);
12669 skipAssert(assert);
12673 QUnit.test('should accept a falsey `collection` argument', function(assert) {
12676 var expected = lodashStable.map(falsey, alwaysEmptyArray);
12678 var actual = lodashStable.map(falsey, function(collection, index) {
12680 return index ? _.map(collection) : _.map();
12684 assert.deepEqual(actual, expected);
12687 QUnit.test('should treat number values for `collection` as empty', function(assert) {
12690 assert.deepEqual(_.map(1), []);
12693 QUnit.test('should return a wrapped value when chaining', function(assert) {
12697 assert.ok(_(array).map(noop) instanceof _);
12700 skipAssert(assert);
12704 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
12709 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
12710 expected = [1, 0, _.map(array.slice(1), square)];
12712 _(array).slice(1).map(function(value, index, array) {
12713 args || (args = slice.call(arguments));
12716 assert.deepEqual(args, [1, 0, array.slice(1)]);
12719 _(array).slice(1).map(square).map(function(value, index, array) {
12720 args || (args = slice.call(arguments));
12723 assert.deepEqual(args, expected);
12726 _(array).slice(1).map(square).map(function(value, index) {
12727 args || (args = slice.call(arguments));
12730 assert.deepEqual(args, expected);
12733 _(array).slice(1).map(square).map(function(value) {
12734 args || (args = slice.call(arguments));
12737 assert.deepEqual(args, [1]);
12740 _(array).slice(1).map(square).map(function() {
12741 args || (args = slice.call(arguments));
12744 assert.deepEqual(args, expected);
12747 skipAssert(assert, 5);
12752 /*--------------------------------------------------------------------------*/
12754 QUnit.module('lodash.mapKeys');
12757 var array = [1, 2],
12758 object = { 'a': 1, 'b': 2 };
12760 QUnit.test('should map keys in `object` to a new object', function(assert) {
12763 var actual = _.mapKeys(object, String);
12764 assert.deepEqual(actual, { '1': 1, '2': 2 });
12767 QUnit.test('should treat arrays like objects', function(assert) {
12770 var actual = _.mapKeys(array, String);
12771 assert.deepEqual(actual, { '1': 1, '2': 2 });
12774 QUnit.test('should work with "_.property" shorthands', function(assert) {
12777 var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
12778 assert.deepEqual(actual, { 'c': { 'b': 'c' } });
12781 QUnit.test('should work on an object with no `iteratee`', function(assert) {
12784 var actual = _.mapKeys({ 'a': 1, 'b': 2 });
12785 assert.deepEqual(actual, { '1': 1, '2': 2 });
12789 /*--------------------------------------------------------------------------*/
12791 QUnit.module('lodash.mapValues');
12794 var array = [1, 2],
12795 object = { 'a': 1, 'b': 2 };
12797 QUnit.test('should map values in `object` to a new object', function(assert) {
12800 var actual = _.mapValues(object, String);
12801 assert.deepEqual(actual, { 'a': '1', 'b': '2' });
12804 QUnit.test('should treat arrays like objects', function(assert) {
12807 var actual = _.mapValues(array, String);
12808 assert.deepEqual(actual, { '0': '1', '1': '2' });
12811 QUnit.test('should work with "_.property" shorthands', function(assert) {
12814 var actual = _.mapValues({ 'a': { 'b': 1 } }, 'b');
12815 assert.deepEqual(actual, { 'a': 1 });
12818 QUnit.test('should work on an object with no `iteratee`', function(assert) {
12821 var actual = _.mapValues({ 'a': 1, 'b': 2 });
12822 assert.deepEqual(actual, object);
12823 assert.notStrictEqual(actual, object);
12827 /*--------------------------------------------------------------------------*/
12829 QUnit.module('lodash.mapKeys and lodash.mapValues');
12831 lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
12832 var array = [1, 2],
12833 func = _[methodName],
12834 object = { 'a': 1, 'b': 2 };
12836 QUnit.test('should iterate over own properties of objects', function(assert) {
12839 function Foo() { this.a = 'a'; }
12840 Foo.prototype.b = 'b';
12842 var actual = func(new Foo, function(value, key) { return key; });
12843 assert.deepEqual(actual, { 'a': 'a' });
12846 QUnit.test('should accept a falsey `object` argument', function(assert) {
12849 var expected = lodashStable.map(falsey, alwaysEmptyObject);
12851 var actual = lodashStable.map(falsey, function(object, index) {
12853 return index ? func(object) : func();
12857 assert.deepEqual(actual, expected);
12860 QUnit.test('should return a wrapped value when chaining', function(assert) {
12864 assert.ok(_(object)[methodName](noop) instanceof _);
12867 skipAssert(assert);
12872 /*--------------------------------------------------------------------------*/
12874 QUnit.module('lodash.matches');
12877 QUnit.test('should create a function that performs a deep comparison between `source` and a given object', function(assert) {
12880 var object = { 'a': 1, 'b': 2, 'c': 3 },
12881 matches = _.matches({ 'a': 1 });
12883 assert.strictEqual(matches.length, 1);
12884 assert.strictEqual(matches(object), true);
12886 matches = _.matches({ 'b': 1 });
12887 assert.strictEqual(matches(object), false);
12889 matches = _.matches({ 'a': 1, 'c': 3 });
12890 assert.strictEqual(matches(object), true);
12892 matches = _.matches({ 'c': 3, 'd': 4 });
12893 assert.strictEqual(matches(object), false);
12895 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
12896 matches = _.matches({ 'a': { 'b': { 'c': 1 } } });
12898 assert.strictEqual(matches(object), true);
12901 QUnit.test('should match inherited `object` properties', function(assert) {
12904 function Foo() { this.a = 1; }
12905 Foo.prototype.b = 2;
12907 var object = { 'a': new Foo },
12908 matches = _.matches({ 'a': { 'b': 2 } });
12910 assert.strictEqual(matches(object), true);
12913 QUnit.test('should not match by inherited `source` properties', function(assert) {
12916 function Foo() { this.a = 1; }
12917 Foo.prototype.b = 2;
12919 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
12921 actual = lodashStable.map(objects, _.matches(source)),
12922 expected = lodashStable.map(objects, alwaysTrue);
12924 assert.deepEqual(actual, expected);
12927 QUnit.test('should compare a variety of `source` property values', function(assert) {
12930 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
12931 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
12932 matches = _.matches(object1);
12934 assert.strictEqual(matches(object1), true);
12935 assert.strictEqual(matches(object2), false);
12938 QUnit.test('should match `-0` as `0`', function(assert) {
12941 var object1 = { 'a': -0 },
12942 object2 = { 'a': 0 },
12943 matches = _.matches(object1);
12945 assert.strictEqual(matches(object2), true);
12947 matches = _.matches(object2);
12948 assert.strictEqual(matches(object1), true);
12951 QUnit.test('should compare functions by reference', function(assert) {
12954 var object1 = { 'a': lodashStable.noop },
12955 object2 = { 'a': noop },
12956 object3 = { 'a': {} },
12957 matches = _.matches(object1);
12959 assert.strictEqual(matches(object1), true);
12960 assert.strictEqual(matches(object2), false);
12961 assert.strictEqual(matches(object3), false);
12964 QUnit.test('should work with a function for `object`', function(assert) {
12968 Foo.a = { 'b': 1, 'c': 2 };
12970 var matches = _.matches({ 'a': { 'b': 1 } });
12971 assert.strictEqual(matches(Foo), true);
12974 QUnit.test('should work with a function for `source`', function(assert) {
12979 Foo.b = function() {};
12982 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
12983 actual = lodashStable.map(objects, _.matches(Foo));
12985 assert.deepEqual(actual, [false, true]);
12988 QUnit.test('should work with a non-plain `object`', function(assert) {
12991 function Foo(object) { lodashStable.assign(this, object); }
12993 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
12994 matches = _.matches({ 'a': { 'b': 1 } });
12996 assert.strictEqual(matches(object), true);
12999 QUnit.test('should partial match arrays', function(assert) {
13002 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
13003 actual = lodashStable.filter(objects, _.matches({ 'a': ['d'] }));
13005 assert.deepEqual(actual, [objects[1]]);
13007 actual = lodashStable.filter(objects, _.matches({ 'a': ['b', 'd'] }));
13008 assert.deepEqual(actual, []);
13010 actual = lodashStable.filter(objects, _.matches({ 'a': ['d', 'b'] }));
13011 assert.deepEqual(actual, []);
13014 QUnit.test('should partial match arrays of objects', function(assert) {
13018 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
13019 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
13022 var actual = lodashStable.filter(objects, _.matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
13023 assert.deepEqual(actual, [objects[0]]);
13026 QUnit.test('should partial match maps', function(assert) {
13030 var objects = [{ 'a': new Map }, { 'a': new Map }];
13031 objects[0].a.set('a', 1);
13032 objects[1].a.set('a', 1);
13033 objects[1].a.set('b', 2);
13037 var actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13039 assert.deepEqual(actual, [objects[1]]);
13041 map['delete']('b');
13042 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13044 assert.deepEqual(actual, objects);
13047 actual = lodashStable.filter(objects, _.matches({ 'a': map }));
13049 assert.deepEqual(actual, []);
13052 skipAssert(assert, 3);
13056 QUnit.test('should partial match sets', function(assert) {
13060 var objects = [{ 'a': new Set }, { 'a': new Set }];
13061 objects[0].a.add(1);
13062 objects[1].a.add(1);
13063 objects[1].a.add(2);
13067 var actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13069 assert.deepEqual(actual, [objects[1]]);
13072 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13074 assert.deepEqual(actual, objects);
13077 actual = lodashStable.filter(objects, _.matches({ 'a': set }));
13079 assert.deepEqual(actual, []);
13082 skipAssert(assert, 3);
13086 QUnit.test('should match `undefined` values', function(assert) {
13089 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
13090 actual = lodashStable.map(objects, _.matches({ 'b': undefined })),
13091 expected = [false, false, true];
13093 assert.deepEqual(actual, expected);
13095 actual = lodashStable.map(objects, _.matches({ 'a': 1, 'b': undefined }));
13097 assert.deepEqual(actual, expected);
13099 objects = [{ 'a': { 'b': 1 } }, { 'a': { 'b': 1, 'c': 1 } }, { 'a': { 'b': 1, 'c': undefined } }];
13100 actual = lodashStable.map(objects, _.matches({ 'a': { 'c': undefined } }));
13102 assert.deepEqual(actual, expected);
13105 QUnit.test('should match `undefined` values on primitives', function(assert) {
13109 numberProto.b = undefined;
13112 var matches = _.matches({ 'b': undefined });
13113 assert.strictEqual(matches(1), true);
13115 assert.ok(false, e.message);
13118 matches = _.matches({ 'a': 1, 'b': undefined });
13119 assert.strictEqual(matches(1), true);
13121 assert.ok(false, e.message);
13123 numberProto.a = { 'b': 1, 'c': undefined };
13125 matches = _.matches({ 'a': { 'c': undefined } });
13126 assert.strictEqual(matches(1), true);
13128 assert.ok(false, e.message);
13130 delete numberProto.a;
13131 delete numberProto.b;
13134 QUnit.test('should return `false` when `object` is nullish', function(assert) {
13137 var values = [, null, undefined],
13138 expected = lodashStable.map(values, alwaysFalse),
13139 matches = _.matches({ 'a': 1 });
13141 var actual = lodashStable.map(values, function(value, index) {
13143 return index ? matches(value) : matches();
13147 assert.deepEqual(actual, expected);
13150 QUnit.test('should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
13153 var values = [, null, undefined],
13154 expected = lodashStable.map(values, alwaysTrue),
13155 matches = _.matches({});
13157 var actual = lodashStable.map(values, function(value, index) {
13159 return index ? matches(value) : matches();
13163 assert.deepEqual(actual, expected);
13166 QUnit.test('should return `true` when comparing an empty `source`', function(assert) {
13169 var object = { 'a': 1 },
13170 expected = lodashStable.map(empties, alwaysTrue);
13172 var actual = lodashStable.map(empties, function(value) {
13173 var matches = _.matches(value);
13174 return matches(object);
13177 assert.deepEqual(actual, expected);
13180 QUnit.test('should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
13183 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
13184 actual = lodashStable.filter(objects, _.matches({ 'a': [], 'b': {} }));
13186 assert.deepEqual(actual, objects);
13189 QUnit.test('should not change behavior if `source` is modified', function(assert) {
13193 { 'a': { 'b': 2, 'c': 3 } },
13194 { 'a': 1, 'b': 2 },
13198 lodashStable.each(sources, function(source, index) {
13199 var object = lodashStable.cloneDeep(source),
13200 matches = _.matches(source);
13202 assert.strictEqual(matches(object), true);
13213 assert.strictEqual(matches(object), true);
13214 assert.strictEqual(matches(source), false);
13219 /*--------------------------------------------------------------------------*/
13221 QUnit.module('lodash.matchesProperty');
13224 QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
13227 var object = { 'a': 1, 'b': 2, 'c': 3 },
13228 matches = _.matchesProperty('a', 1);
13230 assert.strictEqual(matches.length, 1);
13231 assert.strictEqual(matches(object), true);
13233 matches = _.matchesProperty('b', 3);
13234 assert.strictEqual(matches(object), false);
13236 matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
13237 assert.strictEqual(matches({ 'a': object }), true);
13239 matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
13240 assert.strictEqual(matches(object), false);
13242 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
13243 matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
13245 assert.strictEqual(matches(object), true);
13248 QUnit.test('should support deep paths', function(assert) {
13251 var object = { 'a': { 'b': { 'c': 3 } } };
13253 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
13254 var matches = _.matchesProperty(path, 3);
13255 assert.strictEqual(matches(object), true);
13259 QUnit.test('should coerce key to a string', function(assert) {
13263 fn.toString = lodashStable.constant('fn');
13265 var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
13266 values = [null, undefined, fn, {}];
13268 var expected = lodashStable.transform(values, function(result) {
13269 result.push(true, true);
13272 var actual = lodashStable.transform(objects, function(result, object, index) {
13273 var key = values[index];
13274 lodashStable.each([key, [key]], function(path) {
13275 var matches = _.matchesProperty(path, object[key]);
13276 result.push(matches(object));
13280 assert.deepEqual(actual, expected);
13283 QUnit.test('should match a key over a path', function(assert) {
13286 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
13288 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
13289 var matches = _.matchesProperty(path, 3);
13290 assert.strictEqual(matches(object), true);
13294 QUnit.test('should work with non-string `path` arguments', function(assert) {
13297 var array = [1, 2, 3];
13299 lodashStable.each([1, [1]], function(path) {
13300 var matches = _.matchesProperty(path, 2);
13301 assert.strictEqual(matches(array), true);
13305 QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
13310 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
13311 var matches = _.matchesProperty(path, 1);
13312 assert.strictEqual(matches(object), false);
13316 QUnit.test('should return `false` with deep paths when `object` is nullish', function(assert) {
13319 var values = [, null, undefined],
13320 expected = lodashStable.map(values, alwaysFalse);
13322 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
13323 var matches = _.matchesProperty(path, 1);
13325 var actual = lodashStable.map(values, function(value, index) {
13327 return index ? matches(value) : matches();
13331 assert.deepEqual(actual, expected);
13335 QUnit.test('should match inherited `srcValue` properties', function(assert) {
13339 Foo.prototype.b = 2;
13341 var object = { 'a': new Foo };
13343 lodashStable.each(['a', ['a']], function(path) {
13344 var matches = _.matchesProperty(path, { 'b': 2 });
13345 assert.strictEqual(matches(object), true);
13349 QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
13352 function Foo() { this.a = 1; }
13353 Foo.prototype.b = 2;
13355 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
13356 expected = lodashStable.map(objects, alwaysTrue);
13358 lodashStable.each(['a', ['a']], function(path) {
13359 assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
13363 QUnit.test('should compare a variety of values', function(assert) {
13366 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
13367 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
13368 matches = _.matchesProperty('a', object1);
13370 assert.strictEqual(matches({ 'a': object1 }), true);
13371 assert.strictEqual(matches({ 'a': object2 }), false);
13374 QUnit.test('should match `-0` as `0`', function(assert) {
13377 var matches = _.matchesProperty('a', -0);
13378 assert.strictEqual(matches({ 'a': 0 }), true);
13380 matches = _.matchesProperty('a', 0);
13381 assert.strictEqual(matches({ 'a': -0 }), true);
13384 QUnit.test('should compare functions by reference', function(assert) {
13387 var object1 = { 'a': lodashStable.noop },
13388 object2 = { 'a': noop },
13389 object3 = { 'a': {} },
13390 matches = _.matchesProperty('a', object1);
13392 assert.strictEqual(matches({ 'a': object1 }), true);
13393 assert.strictEqual(matches({ 'a': object2 }), false);
13394 assert.strictEqual(matches({ 'a': object3 }), false);
13397 QUnit.test('should work with a function for `srcValue`', function(assert) {
13402 Foo.b = function() {};
13405 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
13406 actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
13408 assert.deepEqual(actual, [false, true]);
13411 QUnit.test('should work with a non-plain `srcValue`', function(assert) {
13414 function Foo(object) { lodashStable.assign(this, object); }
13416 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
13417 matches = _.matchesProperty('a', { 'b': 1 });
13419 assert.strictEqual(matches(object), true);
13422 QUnit.test('should partial match arrays', function(assert) {
13425 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
13426 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
13428 assert.deepEqual(actual, [objects[1]]);
13430 actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
13431 assert.deepEqual(actual, []);
13433 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
13434 assert.deepEqual(actual, []);
13437 QUnit.test('should partial match arrays of objects', function(assert) {
13441 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
13442 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
13445 var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
13446 assert.deepEqual(actual, [objects[0]]);
13448 QUnit.test('should partial match maps', function(assert) {
13452 var objects = [{ 'a': new Map }, { 'a': new Map }];
13453 objects[0].a.set('a', 1);
13454 objects[1].a.set('a', 1);
13455 objects[1].a.set('b', 2);
13459 var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
13461 assert.deepEqual(actual, [objects[1]]);
13463 map['delete']('b');
13464 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
13466 assert.deepEqual(actual, objects);
13469 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
13471 assert.deepEqual(actual, []);
13474 skipAssert(assert, 3);
13478 QUnit.test('should partial match sets', function(assert) {
13482 var objects = [{ 'a': new Set }, { 'a': new Set }];
13483 objects[0].a.add(1);
13484 objects[1].a.add(1);
13485 objects[1].a.add(2);
13489 var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
13491 assert.deepEqual(actual, [objects[1]]);
13494 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
13496 assert.deepEqual(actual, objects);
13499 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
13501 assert.deepEqual(actual, []);
13504 skipAssert(assert, 3);
13508 QUnit.test('should match `undefined` values', function(assert) {
13511 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
13512 actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
13513 expected = [false, false, true];
13515 assert.deepEqual(actual, expected);
13517 objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
13518 actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
13520 assert.deepEqual(actual, expected);
13523 QUnit.test('should match `undefined` values on primitives', function(assert) {
13527 numberProto.b = undefined;
13530 var matches = _.matchesProperty('b', undefined);
13531 assert.strictEqual(matches(1), true);
13533 assert.ok(false, e.message);
13535 numberProto.a = { 'b': 1, 'c': undefined };
13537 matches = _.matchesProperty('a', { 'c': undefined });
13538 assert.strictEqual(matches(1), true);
13540 assert.ok(false, e.message);
13542 delete numberProto.a;
13543 delete numberProto.b;
13546 QUnit.test('should return `false` when `object` is nullish', function(assert) {
13549 var values = [, null, undefined],
13550 expected = lodashStable.map(values, alwaysFalse);
13552 lodashStable.each(['constructor', ['constructor']], function(path) {
13553 var matches = _.matchesProperty(path, 1);
13555 var actual = lodashStable.map(values, function(value, index) {
13557 return index ? matches(value) : matches();
13561 assert.deepEqual(actual, expected);
13565 QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
13568 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
13569 matches = _.matchesProperty('a', { 'a': [], 'b': {} });
13571 var actual = lodashStable.filter(objects, function(object) {
13572 return matches({ 'a': object });
13575 assert.deepEqual(actual, objects);
13578 QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
13581 lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
13582 var object = lodashStable.cloneDeep(source),
13583 matches = _.matchesProperty('a', source);
13585 assert.strictEqual(matches({ 'a': object }), true);
13596 assert.strictEqual(matches({ 'a': object }), true);
13597 assert.strictEqual(matches({ 'a': source }), false);
13602 /*--------------------------------------------------------------------------*/
13604 QUnit.module('lodash.max');
13607 QUnit.test('should return the largest value from a collection', function(assert) {
13610 assert.strictEqual(_.max([1, 2, 3]), 3);
13613 QUnit.test('should return `undefined` for empty collections', function(assert) {
13616 var values = falsey.concat([[]]),
13617 expected = lodashStable.map(values, alwaysUndefined);
13619 var actual = lodashStable.map(values, function(value, index) {
13621 return index ? _.max(value) : _.max();
13625 assert.deepEqual(actual, expected);
13628 QUnit.test('should work with non-numeric collection values', function(assert) {
13631 assert.strictEqual(_.max(['a', 'b']), 'b');
13635 /*--------------------------------------------------------------------------*/
13637 QUnit.module('lodash.mean');
13640 QUnit.test('should return the mean of an array of numbers', function(assert) {
13643 var array = [4, 2, 8, 6];
13644 assert.strictEqual(_.mean(array), 5);
13647 QUnit.test('should return `NaN` when passing empty `array` values', function(assert) {
13650 var expected = lodashStable.map(empties, alwaysNaN),
13651 actual = lodashStable.map(empties, _.mean);
13653 assert.deepEqual(actual, expected);
13657 /*--------------------------------------------------------------------------*/
13659 QUnit.module('lodash.memoize');
13662 QUnit.test('should memoize results based on the first argument given', function(assert) {
13665 var memoized = _.memoize(function(a, b, c) {
13669 assert.strictEqual(memoized(1, 2, 3), 6);
13670 assert.strictEqual(memoized(1, 3, 5), 6);
13673 QUnit.test('should support a `resolver` argument', function(assert) {
13676 var fn = function(a, b, c) { return a + b + c; },
13677 memoized = _.memoize(fn, fn);
13679 assert.strictEqual(memoized(1, 2, 3), 6);
13680 assert.strictEqual(memoized(1, 3, 5), 9);
13683 QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
13686 var fn = function(a, b, c) { return a + this.b + this.c; },
13687 memoized = _.memoize(fn, fn);
13689 var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
13690 assert.strictEqual(object.memoized(1), 6);
13694 assert.strictEqual(object.memoized(1), 9);
13697 QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
13700 assert.raises(function() { _.memoize(noop, true); }, TypeError);
13703 QUnit.test('should not error if `resolver` is falsey', function(assert) {
13706 var expected = lodashStable.map(falsey, alwaysTrue);
13708 var actual = lodashStable.map(falsey, function(resolver, index) {
13710 return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
13714 assert.deepEqual(actual, expected);
13717 QUnit.test('should check cache for own properties', function(assert) {
13724 'propertyIsEnumerable',
13730 var memoized = _.memoize(identity);
13732 var actual = lodashStable.map(props, function(value) {
13733 return memoized(value);
13736 assert.deepEqual(actual, props);
13739 QUnit.test('should cache the `__proto__` key', function(assert) {
13745 lodashStable.times(2, function(index) {
13747 resolver = index && identity;
13749 var memoized = _.memoize(function() {
13754 var cache = memoized.cache;
13759 assert.strictEqual(count, 1);
13760 assert.strictEqual(cache.get(key), array);
13761 assert.notOk(cache.__data__ instanceof Array);
13762 assert.strictEqual(cache['delete'](key), true);
13766 QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
13769 var oldCache = _.memoize.Cache;
13772 this.__data__ = [];
13775 Cache.prototype = {
13776 'get': function(key) {
13777 var entry = _.find(this.__data__, function(entry) {
13778 return key === entry.key;
13780 return entry && entry.value;
13782 'has': function(key) {
13783 return _.some(this.__data__, function(entry) {
13784 return key === entry.key;
13787 'set': function(key, value) {
13788 this.__data__.push({ 'key': key, 'value': value });
13793 _.memoize.Cache = Cache;
13795 var memoized = _.memoize(function(object) {
13796 return 'value:' + object.id;
13799 var cache = memoized.cache,
13800 key1 = { 'id': 'a' },
13801 key2 = { 'id': 'b' };
13803 assert.strictEqual(memoized(key1), 'value:a');
13804 assert.strictEqual(cache.has(key1), true);
13806 assert.strictEqual(memoized(key2), 'value:b');
13807 assert.strictEqual(cache.has(key2), true);
13809 _.memoize.Cache = oldCache;
13812 QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
13815 var oldCache = _.memoize.Cache;
13818 this.__data__ = [];
13821 Cache.prototype = {
13822 'get': function(key) {
13823 return _.find(this.__data__, function(entry) {
13824 return key === entry.key;
13827 'has': function(key) {
13828 return _.some(this.__data__, function(entry) {
13829 return key === entry.key;
13832 'set': function(key, value) {
13833 var result = new Cache;
13834 result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
13839 _.memoize.Cache = Cache;
13841 var memoized = _.memoize(function(object) {
13845 var key1 = { 'id': 'a' },
13846 key2 = { 'id': 'b' };
13851 var cache = memoized.cache;
13852 assert.strictEqual(cache.has(key1), true);
13853 assert.strictEqual(cache.has(key2), true);
13855 _.memoize.Cache = oldCache;
13858 QUnit.test('should implement a `Map` interface on the cache object', function(assert) {
13859 assert.expect(164);
13861 var keys = [true, false, 1, -Infinity, NaN, {}, null, 'a', symbol || {} , undefined];
13863 var pairs = lodashStable.map(keys, function(key, index) {
13864 var lastIndex = keys.length - 1;
13865 return [key, keys[lastIndex - index]];
13868 lodashStable.times(2, function(index) {
13869 var memoize = (index ? (lodashBizarro || {}) : _).memoize,
13870 Cache = memoize ? memoize.Cache : undefined,
13871 cache = Cache ? new Cache(pairs) : undefined;
13873 lodashStable.each(keys, function(key, index) {
13875 var value = pairs[index][1];
13877 assert.deepEqual(cache.get(key), value);
13878 assert.strictEqual(cache.has(key), true);
13879 assert.strictEqual(cache['delete'](key), true);
13880 assert.strictEqual(cache.has(key), false);
13881 assert.strictEqual(cache.get(key), undefined);
13882 assert.strictEqual(cache['delete'](key), false);
13883 assert.strictEqual(cache.set(key, value), cache);
13884 assert.strictEqual(cache.has(key), true);
13887 skipAssert(assert, 8);
13892 assert.strictEqual(cache.clear(), undefined);
13893 assert.ok(lodashStable.every(keys, function(key) {
13894 return !cache.has(key);
13898 skipAssert(assert, 2);
13904 /*--------------------------------------------------------------------------*/
13906 QUnit.module('lodash.merge');
13909 var args = arguments;
13911 QUnit.test('should merge `source` into `object`', function(assert) {
13916 { 'name': 'barney' },
13930 { 'height': '5\'4"' },
13931 { 'height': '5\'5"' }
13937 { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
13938 { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
13942 assert.deepEqual(_.merge(names, ages, heights), expected);
13945 QUnit.test('should merge sources containing circular references', function(assert) {
13954 'foo': { 'b': { 'c': { 'd': {} } } },
13958 source.foo.b.c.d = source;
13959 source.bar.b = source.foo.b;
13961 var actual = _.merge(object, source);
13962 assert.ok(actual.bar.b === actual.foo.b && actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
13965 QUnit.test('should work with four arguments', function(assert) {
13968 var expected = { 'a': 4 },
13969 actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
13971 assert.deepEqual(actual, expected);
13974 QUnit.test('should merge onto function `object` values', function(assert) {
13979 var source = { 'a': 1 },
13980 actual = _.merge(Foo, source);
13982 assert.strictEqual(actual, Foo);
13983 assert.strictEqual(Foo.a, 1);
13986 QUnit.test('should not merge onto nested function values', function(assert) {
13989 var source1 = { 'a': function() {} },
13990 source2 = { 'a': { 'b': 1 } },
13991 actual = _.merge({}, source1, source2),
13992 expected = { 'a': { 'b': 1 } };
13994 assert.deepEqual(actual, expected);
13996 source1 = { 'a': function() {} };
13997 source2 = { 'a': { 'b': 1 } };
13999 expected = { 'a': function() {} };
14002 actual = _.merge(source1, source2);
14003 assert.strictEqual(typeof actual.a, 'function');
14004 assert.strictEqual(actual.a.b, 1);
14007 QUnit.test('should merge onto non-plain `object` values', function(assert) {
14012 var object = new Foo,
14013 source = { 'a': 1 },
14014 actual = _.merge(object, source);
14016 assert.strictEqual(actual, object);
14017 assert.strictEqual(object.a, 1);
14020 QUnit.test('should pass thru primitive `object` values', function(assert) {
14023 var values = [true, 1, '1'];
14025 var actual = lodashStable.map(values, function(value) {
14026 return _.merge(value, { 'a': 1 });
14029 assert.deepEqual(actual, values);
14032 QUnit.test('should treat sparse array sources as dense', function(assert) {
14035 var array = Array(3);
14039 var actual = _.merge([], array),
14040 expected = array.slice();
14042 expected[1] = undefined;
14044 assert.ok('1' in actual);
14045 assert.deepEqual(actual, expected);
14048 QUnit.test('should merge `arguments` objects', function(assert) {
14051 var object1 = { 'value': args },
14052 object2 = { 'value': { '3': 4 } },
14053 expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
14054 actual = _.merge(object1, object2);
14056 assert.notOk('3' in args);
14057 assert.notOk(_.isArguments(actual.value));
14058 assert.deepEqual(actual.value, expected);
14059 object1.value = args;
14061 actual = _.merge(object2, object1);
14062 assert.notOk(_.isArguments(actual.value));
14063 assert.deepEqual(actual.value, expected);
14065 expected = { '0': 1, '1': 2, '2': 3 };
14067 actual = _.merge({}, object1);
14068 assert.notOk(_.isArguments(actual.value));
14069 assert.deepEqual(actual.value, expected);
14072 QUnit.test('should merge typed arrays', function(assert) {
14077 array3 = [0, 0, 0, 0],
14078 array4 = lodashStable.range(0, 8, 0);
14080 var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
14081 buffer = ArrayBuffer && new ArrayBuffer(8);
14083 // juggle for `Float64Array` shim
14084 if (root.Float64Array && (new Float64Array(buffer)).length == 8) {
14085 arrays[1] = array4;
14087 var expected = lodashStable.map(typedArrays, function(type, index) {
14088 var array = arrays[index].slice();
14090 return root[type] ? { 'value': array } : false;
14093 var actual = lodashStable.map(typedArrays, function(type) {
14094 var Ctor = root[type];
14095 return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
14098 assert.ok(lodashStable.isArray(actual));
14099 assert.deepEqual(actual, expected);
14101 expected = lodashStable.map(typedArrays, function(type, index) {
14102 var array = arrays[index].slice();
14104 return root[type] ? { 'value': array } : false;
14107 actual = lodashStable.map(typedArrays, function(type, index) {
14108 var Ctor = root[type],
14109 array = lodashStable.range(arrays[index].length);
14112 return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
14115 assert.ok(lodashStable.isArray(actual));
14116 assert.deepEqual(actual, expected);
14119 QUnit.test('should assign `null` values', function(assert) {
14122 var actual = _.merge({ 'a': 1 }, { 'a': null });
14123 assert.strictEqual(actual.a, null);
14126 QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) {
14131 var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
14132 expected = lodashStable.map(values, alwaysTrue);
14134 var actual = lodashStable.map(values, function(value) {
14135 var object = _.merge({}, { 'value': value });
14136 return object.value === value;
14139 assert.deepEqual(actual, expected);
14142 QUnit.test('should deep clone array/typed-array/plain-object sources', function(assert) {
14145 var typedArray = Uint8Array
14146 ? new Uint8Array(new ArrayBuffer(2))
14147 : { 'buffer': [0, 0] };
14149 var props = ['0', 'a', 'buffer'],
14150 values = [[{ 'a': 1 }], { 'a': [1] }, typedArray],
14151 expected = lodashStable.map(values, alwaysTrue);
14153 var actual = lodashStable.map(values, function(value, index) {
14154 var key = props[index],
14155 object = _.merge({}, { 'value': value }),
14156 newValue = object.value;
14159 newValue !== value &&
14160 newValue[key] !== value[key] &&
14161 lodashStable.isEqual(newValue, value)
14165 assert.deepEqual(actual, expected);
14168 QUnit.test('should not augment source objects', function(assert) {
14171 var source1 = { 'a': [{ 'a': 1 }] },
14172 source2 = { 'a': [{ 'b': 2 }] },
14173 actual = _.merge({}, source1, source2);
14175 assert.deepEqual(source1.a, [{ 'a': 1 }]);
14176 assert.deepEqual(source2.a, [{ 'b': 2 }]);
14177 assert.deepEqual(actual.a, [{ 'a': 1, 'b': 2 }]);
14179 var source1 = { 'a': [[1, 2, 3]] },
14180 source2 = { 'a': [[3, 4]] },
14181 actual = _.merge({}, source1, source2);
14183 assert.deepEqual(source1.a, [[1, 2, 3]]);
14184 assert.deepEqual(source2.a, [[3, 4]]);
14185 assert.deepEqual(actual.a, [[3, 4, 3]]);
14188 QUnit.test('should merge plain-objects onto non plain-objects', function(assert) {
14191 function Foo(object) {
14192 lodashStable.assign(this, object);
14195 var object = { 'a': 1 },
14196 actual = _.merge(new Foo, object);
14198 assert.ok(actual instanceof Foo);
14199 assert.deepEqual(actual, new Foo(object));
14201 actual = _.merge([new Foo], [object]);
14202 assert.ok(actual[0] instanceof Foo);
14203 assert.deepEqual(actual, [new Foo(object)]);
14206 QUnit.test('should not assign `undefined` values', function(assert) {
14209 var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
14210 assert.deepEqual(actual, { 'a': 1 });
14213 QUnit.test('should skip `undefined` values in array sources if a destination value exists', function(assert) {
14216 var array = Array(3);
14220 var actual = _.merge([4, 5, 6], array),
14221 expected = [1, 5, 3];
14223 assert.deepEqual(actual, expected);
14226 array[1] = undefined;
14228 actual = _.merge([4, 5, 6], array);
14229 assert.deepEqual(actual, expected);
14232 QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
14235 if (defineProperty) {
14239 defineProperty(object, 'a', {
14240 'enumerable': true,
14241 'configurable': true,
14242 'get': function() { pass = false; },
14243 'set': function() { pass = false; }
14246 _.merge(object, object);
14250 skipAssert(assert);
14254 QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
14257 var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
14258 actual = _.merge(object, { 'a': ['x'] });
14260 assert.deepEqual(actual, { 'a': ['x', 'y'] });
14262 actual = _.merge({ 'a': {} }, { 'a': [] });
14263 assert.deepEqual(actual, { 'a': [] });
14266 QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
14269 var object = { 'a': 'abcde' },
14270 actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
14272 assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
14275 QUnit.test('should not error on DOM elements', function(assert) {
14278 var object1 = { 'el': document && document.createElement('div') },
14279 object2 = { 'el': document && document.createElement('div') },
14280 pairs = [[{}, object1], [object1, object2]],
14281 expected = lodashStable.map(pairs, alwaysTrue);
14283 var actual = lodashStable.map(pairs, function(pair) {
14285 return _.merge(pair[0], pair[1]).el === pair[1].el;
14289 assert.deepEqual(actual, expected);
14293 /*--------------------------------------------------------------------------*/
14295 QUnit.module('lodash.mergeWith');
14298 QUnit.test('should handle merging if `customizer` returns `undefined`', function(assert) {
14301 var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
14302 assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
14304 actual = _.mergeWith([], [undefined], identity);
14305 assert.deepEqual(actual, [undefined]);
14308 QUnit.test('should defer to `customizer` when it returns a value other than `undefined`', function(assert) {
14311 var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
14312 return lodashStable.isArray(a) ? a.concat(b) : undefined;
14315 assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
14318 QUnit.test('should overwrite primitives with source object clones', function(assert) {
14321 var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) {
14322 return lodashStable.isArray(a) ? a.concat(b) : undefined;
14325 assert.deepEqual(actual, { 'a': { 'b': ['c'] } });
14329 /*--------------------------------------------------------------------------*/
14331 QUnit.module('lodash.method');
14334 QUnit.test('should create a function that calls a method of a given object', function(assert) {
14337 var object = { 'a': alwaysOne };
14339 lodashStable.each(['a', ['a']], function(path) {
14340 var method = _.method(path);
14341 assert.strictEqual(method.length, 1);
14342 assert.strictEqual(method(object), 1);
14346 QUnit.test('should work with deep property values', function(assert) {
14349 var object = { 'a': { 'b': { 'c': alwaysThree } } };
14351 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
14352 var method = _.method(path);
14353 assert.strictEqual(method(object), 3);
14357 QUnit.test('should work with non-string `path` arguments', function(assert) {
14360 var array = lodashStable.times(3, _.constant);
14362 lodashStable.each([1, [1]], function(path) {
14363 var method = _.method(path);
14364 assert.strictEqual(method(array), 1);
14368 QUnit.test('should coerce key to a string', function(assert) {
14372 fn.toString = lodashStable.constant('fn');
14374 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
14375 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
14376 values = [null, undefined, fn, {}];
14378 var actual = lodashStable.transform(objects, function(result, object, index) {
14379 var key = values[index];
14380 lodashStable.each([key, [key]], function(path) {
14381 var method = _.method(key);
14382 result.push(method(object));
14386 assert.deepEqual(actual, expected);
14389 QUnit.test('should work with inherited property values', function(assert) {
14393 Foo.prototype.a = alwaysOne;
14395 lodashStable.each(['a', ['a']], function(path) {
14396 var method = _.method(path);
14397 assert.strictEqual(method(new Foo), 1);
14401 QUnit.test('should use a key over a path', function(assert) {
14404 var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
14406 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
14407 var method = _.method(path);
14408 assert.strictEqual(method(object), 3);
14412 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
14415 var values = [, null, undefined],
14416 expected = lodashStable.map(values, alwaysUndefined);
14418 lodashStable.each(['constructor', ['constructor']], function(path) {
14419 var method = _.method(path);
14421 var actual = lodashStable.map(values, function(value, index) {
14422 return index ? method(value) : method();
14425 assert.deepEqual(actual, expected);
14429 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
14432 var values = [, null, undefined],
14433 expected = lodashStable.map(values, alwaysUndefined);
14435 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
14436 var method = _.method(path);
14438 var actual = lodashStable.map(values, function(value, index) {
14439 return index ? method(value) : method();
14442 assert.deepEqual(actual, expected);
14446 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
14451 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
14452 var method = _.method(path);
14453 assert.strictEqual(method(object), undefined);
14457 QUnit.test('should apply partial arguments to function', function(assert) {
14462 return slice.call(arguments);
14466 lodashStable.each(['fn', ['fn']], function(path) {
14467 var method = _.method(path, 1, 2, 3);
14468 assert.deepEqual(method(object), [1, 2, 3]);
14472 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
14475 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
14477 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14478 var method = _.method(path);
14479 assert.strictEqual(method(object), 1);
14484 /*--------------------------------------------------------------------------*/
14486 QUnit.module('lodash.methodOf');
14489 QUnit.test('should create a function that calls a method of a given key', function(assert) {
14492 var object = { 'a': alwaysOne };
14494 lodashStable.each(['a', ['a']], function(path) {
14495 var methodOf = _.methodOf(object);
14496 assert.strictEqual(methodOf.length, 1);
14497 assert.strictEqual(methodOf(path), 1);
14501 QUnit.test('should work with deep property values', function(assert) {
14504 var object = { 'a': { 'b': { 'c': alwaysThree } } };
14506 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
14507 var methodOf = _.methodOf(object);
14508 assert.strictEqual(methodOf(path), 3);
14512 QUnit.test('should work with non-string `path` arguments', function(assert) {
14515 var array = lodashStable.times(3, _.constant);
14517 lodashStable.each([1, [1]], function(path) {
14518 var methodOf = _.methodOf(array);
14519 assert.strictEqual(methodOf(path), 1);
14523 QUnit.test('should coerce key to a string', function(assert) {
14527 fn.toString = lodashStable.constant('fn');
14529 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
14530 objects = [{ 'null': alwaysOne }, { 'undefined': alwaysTwo }, { 'fn': alwaysThree }, { '[object Object]': alwaysFour }],
14531 values = [null, undefined, fn, {}];
14533 var actual = lodashStable.transform(objects, function(result, object, index) {
14534 var key = values[index];
14535 lodashStable.each([key, [key]], function(path) {
14536 var methodOf = _.methodOf(object);
14537 result.push(methodOf(key));
14541 assert.deepEqual(actual, expected);
14544 QUnit.test('should work with inherited property values', function(assert) {
14548 Foo.prototype.a = alwaysOne;
14550 lodashStable.each(['a', ['a']], function(path) {
14551 var methodOf = _.methodOf(new Foo);
14552 assert.strictEqual(methodOf(path), 1);
14556 QUnit.test('should use a key over a path', function(assert) {
14559 var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
14561 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
14562 var methodOf = _.methodOf(object);
14563 assert.strictEqual(methodOf(path), 3);
14567 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
14570 var values = [, null, undefined],
14571 expected = lodashStable.map(values, alwaysUndefined);
14573 lodashStable.each(['constructor', ['constructor']], function(path) {
14574 var actual = lodashStable.map(values, function(value, index) {
14575 var methodOf = index ? _.methodOf() : _.methodOf(value);
14576 return methodOf(path);
14579 assert.deepEqual(actual, expected);
14583 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
14586 var values = [, null, undefined],
14587 expected = lodashStable.map(values, alwaysUndefined);
14589 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
14590 var actual = lodashStable.map(values, function(value, index) {
14591 var methodOf = index ? _.methodOf() : _.methodOf(value);
14592 return methodOf(path);
14595 assert.deepEqual(actual, expected);
14599 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
14603 methodOf = _.methodOf(object);
14605 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
14606 assert.strictEqual(methodOf(path), undefined);
14610 QUnit.test('should apply partial arguments to function', function(assert) {
14615 return slice.call(arguments);
14619 var methodOf = _.methodOf(object, 1, 2, 3);
14621 lodashStable.each(['fn', ['fn']], function(path) {
14622 assert.deepEqual(methodOf(path), [1, 2, 3]);
14626 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
14629 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
14630 methodOf = _.methodOf(object);
14632 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14633 assert.strictEqual(methodOf(path), 1);
14638 /*--------------------------------------------------------------------------*/
14640 QUnit.module('lodash.min');
14643 QUnit.test('should return the smallest value from a collection', function(assert) {
14646 assert.strictEqual(_.min([1, 2, 3]), 1);
14649 QUnit.test('should return `undefined` for empty collections', function(assert) {
14652 var values = falsey.concat([[]]),
14653 expected = lodashStable.map(values, alwaysUndefined);
14655 var actual = lodashStable.map(values, function(value, index) {
14657 return index ? _.min(value) : _.min();
14661 assert.deepEqual(actual, expected);
14664 QUnit.test('should work with non-numeric collection values', function(assert) {
14667 assert.strictEqual(_.min(['a', 'b']), 'a');
14671 /*--------------------------------------------------------------------------*/
14673 QUnit.module('extremum methods');
14675 lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
14676 var array = [1, 2, 3],
14677 func = _[methodName],
14678 isMax = /^max/.test(methodName);
14680 QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
14683 var curr = new Date,
14684 past = new Date(0);
14686 assert.strictEqual(func([curr, past]), isMax ? curr : past);
14689 QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
14692 var array = lodashStable.range(0, 5e5);
14693 assert.strictEqual(func(array), isMax ? 499999 : 0);
14696 QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
14700 var actual = _([40])[methodName]();
14701 assert.strictEqual(actual, 40);
14704 skipAssert(assert);
14709 lodashStable.each(['maxBy', 'minBy'], function(methodName) {
14710 var array = [1, 2, 3],
14711 func = _[methodName],
14712 isMax = methodName == 'maxBy';
14714 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
14717 var actual = func(array, function(n) {
14721 assert.strictEqual(actual, isMax ? 1 : 3);
14724 QUnit.test('should work with "_.property" shorthands', function(assert) {
14727 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
14728 actual = func(objects, 'a');
14730 assert.deepEqual(actual, objects[isMax ? 1 : 2]);
14732 var arrays = [[2], [3], [1]];
14733 actual = func(arrays, 0);
14735 assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
14738 QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
14741 var value = isMax ? -Infinity : Infinity,
14742 object = { 'a': value };
14744 var actual = func([object, { 'a': value }], function(object) {
14748 assert.strictEqual(actual, object);
14752 /*--------------------------------------------------------------------------*/
14754 QUnit.module('lodash.mixin');
14757 function Wrapper(value) {
14758 if (!(this instanceof Wrapper)) {
14759 return new Wrapper(value);
14761 if (_.has(value, '__wrapped__')) {
14762 var actions = slice.call(value.__actions__),
14763 chain = value.__chain__;
14765 value = value.__wrapped__;
14767 this.__wrapped__ = value;
14768 this.__actions__ = actions || [];
14769 this.__chain__ = chain || false;
14772 Wrapper.prototype.value = function() {
14773 return getUnwrappedValue(this);
14777 source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
14779 QUnit.test('should mixin `source` methods into lodash', function(assert) {
14785 assert.strictEqual(_.a(array), 'a');
14786 assert.strictEqual(_(array).a().value(), 'a');
14789 delete _.prototype.a;
14791 assert.notOk('b' in _);
14792 assert.notOk('b' in _.prototype);
14795 delete _.prototype.b;
14798 skipAssert(assert, 4);
14802 QUnit.test('should mixin chaining methods by reference', function(assert) {
14809 assert.strictEqual(_.a(array), 'b');
14810 assert.strictEqual(_(array).a().value(), 'a');
14813 delete _.prototype.a;
14816 skipAssert(assert, 2);
14820 QUnit.test('should use a default `object` of `this`', function(assert) {
14823 var object = lodashStable.create(_);
14824 object.mixin(source);
14826 assert.strictEqual(object.a(array), 'a');
14828 assert.notOk('a' in _);
14829 assert.notOk('a' in _.prototype);
14832 delete Wrapper.prototype.a;
14834 delete Wrapper.prototype.b;
14837 QUnit.test('should accept an `object` argument', function(assert) {
14841 _.mixin(object, source);
14842 assert.strictEqual(object.a(array), 'a');
14845 QUnit.test('should return `object`', function(assert) {
14849 assert.strictEqual(_.mixin(object, source), object);
14850 assert.strictEqual(_.mixin(), _);
14853 QUnit.test('should work with a function for `object`', function(assert) {
14856 _.mixin(Wrapper, source);
14858 var wrapped = Wrapper(array),
14859 actual = wrapped.a();
14861 assert.strictEqual(actual.value(), 'a');
14862 assert.ok(actual instanceof Wrapper);
14865 delete Wrapper.prototype.a;
14867 delete Wrapper.prototype.b;
14870 QUnit.test('should not assign inherited `source` methods', function(assert) {
14874 Foo.prototype.a = noop;
14877 assert.strictEqual(_.mixin(object, new Foo), object);
14880 QUnit.test('should accept an `options` argument', function(assert) {
14883 function message(func, chain) {
14884 return (func === _ ? 'lodash' : 'given') + ' function should ' + (chain ? '' : 'not ') + 'chain';
14887 lodashStable.each([_, Wrapper], function(func) {
14888 lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
14891 _.mixin(source, options);
14893 _.mixin(func, source, options);
14895 var wrapped = func(array),
14896 actual = wrapped.a();
14898 if (options.chain) {
14899 assert.strictEqual(actual.value(), 'a', message(func, true));
14900 assert.ok(actual instanceof func, message(func, true));
14902 assert.strictEqual(actual, 'a', message(func, false));
14903 assert.notOk(actual instanceof func, message(func, false));
14906 delete func.prototype.a;
14908 delete func.prototype.b;
14911 skipAssert(assert, 2);
14917 QUnit.test('should not extend lodash when an `object` is given with an empty `options` object', function(assert) {
14920 _.mixin({ 'a': noop }, {});
14921 assert.notOk('a' in _);
14925 QUnit.test('should not error for non-object `options` values', function(assert) {
14931 _.mixin({}, source, 1);
14940 _.mixin(source, 1);
14945 delete _.prototype.a;
14947 delete _.prototype.b;
14952 QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
14955 lodashStable.each([_, Wrapper], function(func) {
14958 var wrapped = _(source),
14959 actual = wrapped.mixin();
14961 assert.strictEqual(actual.value(), _);
14965 actual = wrapped.mixin(source);
14966 assert.notStrictEqual(actual, wrapped);
14969 delete func.prototype.a;
14971 delete func.prototype.b;
14974 skipAssert(assert);
14979 QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
14983 _.mixin({ 'a': _.countBy, 'b': _.filter });
14985 var array = lodashStable.range(LARGE_ARRAY_SIZE),
14986 actual = _(array).a().map(square).b(isEven).take().value();
14988 assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
14991 delete _.prototype.a;
14993 delete _.prototype.b;
14996 skipAssert(assert);
15001 /*--------------------------------------------------------------------------*/
15003 QUnit.module('lodash.orderBy');
15007 { 'a': 'x', 'b': 3 },
15008 { 'a': 'y', 'b': 4 },
15009 { 'a': 'x', 'b': 1 },
15010 { 'a': 'y', 'b': 2 }
15013 QUnit.test('should sort by a single property by a specified order', function(assert) {
15016 var actual = _.orderBy(objects, 'a', 'desc');
15017 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15020 QUnit.test('should sort by multiple properties by specified orders', function(assert) {
15023 var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
15024 assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
15027 QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
15030 var expected = [objects[2], objects[0], objects[3], objects[1]],
15031 actual = _.orderBy(objects, ['a', 'b']);
15033 assert.deepEqual(actual, expected);
15035 expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
15037 actual = lodashStable.map(falsey, function(order, index) {
15038 return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
15041 assert.deepEqual(actual, expected);
15044 QUnit.test('should work with `orders` specified as string objects', function(assert) {
15047 var actual = _.orderBy(objects, ['a'], [Object('desc')]);
15048 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15052 /*--------------------------------------------------------------------------*/
15054 QUnit.module('lodash.overArgs');
15058 return slice.call(arguments);
15061 QUnit.test('should transform each argument', function(assert) {
15064 var over = _.overArgs(fn, doubled, square);
15065 assert.deepEqual(over(5, 10), [10, 100]);
15068 QUnit.test('should flatten `transforms`', function(assert) {
15071 var over = _.overArgs(fn, [doubled, square], String);
15072 assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
15075 QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
15078 var over = _.overArgs(fn, doubled, square);
15079 assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
15082 QUnit.test('should not transform any arguments if no transforms are given', function(assert) {
15085 var over = _.overArgs(fn);
15086 assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
15089 QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
15092 var over = _.overArgs(fn, doubled, identity);
15093 assert.deepEqual(over(5), [10]);
15096 QUnit.test('should provide the correct argument to each transform', function(assert) {
15100 transform = function() { argsList.push(slice.call(arguments)); },
15101 over = _.overArgs(noop, transform, transform, transform);
15104 assert.deepEqual(argsList, [['a'], ['b']]);
15107 QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
15110 var over = _.overArgs(function(x) {
15116 var object = { 'over': over, 'true': 1 };
15117 assert.strictEqual(object.over(object), 1);
15121 /*--------------------------------------------------------------------------*/
15123 QUnit.module('lodash.negate');
15126 QUnit.test('should create a function that negates the result of `func`', function(assert) {
15129 var negate = _.negate(isEven);
15131 assert.strictEqual(negate(1), true);
15132 assert.strictEqual(negate(2), false);
15136 /*--------------------------------------------------------------------------*/
15138 QUnit.module('lodash.noop');
15141 QUnit.test('should return `undefined`', function(assert) {
15144 var values = empties.concat(true, new Date, _, 1, /x/, 'a'),
15145 expected = lodashStable.map(values, alwaysUndefined);
15147 var actual = lodashStable.map(values, function(value, index) {
15148 return index ? _.noop(value) : _.noop();
15151 assert.deepEqual(actual, expected);
15155 /*--------------------------------------------------------------------------*/
15157 QUnit.module('lodash.noConflict');
15160 QUnit.test('should return the `lodash` function', function(assert) {
15163 if (!isModularize) {
15164 assert.strictEqual(_.noConflict(), oldDash);
15165 assert.notStrictEqual(root._, oldDash);
15169 skipAssert(assert, 2);
15173 QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) {
15176 if (!isModularize) {
15177 var object = root._ = {};
15178 assert.strictEqual(_.noConflict(), oldDash);
15179 assert.strictEqual(root._, object);
15183 skipAssert(assert, 2);
15187 QUnit.test('should work with a `root` of `this`', function(assert) {
15190 if (!isModularize && !coverage && (!document && realm.object)) {
15191 var fs = require('fs'),
15192 vm = require('vm'),
15194 context = vm.createContext({ '_': expected, 'console': console }),
15195 source = fs.readFileSync(filePath, 'utf8');
15197 vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
15199 assert.strictEqual(context._, expected);
15200 assert.ok(context.lodash);
15203 skipAssert(assert, 2);
15208 /*--------------------------------------------------------------------------*/
15210 QUnit.module('lodash.now');
15213 QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
15216 var done = assert.async();
15218 var stamp = +new Date,
15221 assert.ok(actual >= stamp);
15223 setTimeout(function() {
15224 assert.ok(_.now() > actual);
15230 /*--------------------------------------------------------------------------*/
15232 QUnit.module('lodash.nthArg');
15235 QUnit.test('should create a function that returns its nth argument', function(assert) {
15238 var expected = ['a', 'b', 'c'];
15240 var actual = lodashStable.times(expected.length, function(n) {
15241 var func = _.nthArg(n);
15242 return func.apply(undefined, expected);
15245 assert.deepEqual(actual, expected);
15248 QUnit.test('should coerce `n` to an integer', function(assert) {
15251 var values = falsey,
15252 expected = lodashStable.map(values, alwaysA);
15254 var actual = lodashStable.map(values, function(n) {
15255 var func = n ? _.nthArg(n) : _.nthArg();
15256 return func('a', 'b', 'c');
15259 assert.deepEqual(actual, expected);
15261 values = ['1', 1.6];
15262 expected = lodashStable.map(values, alwaysB);
15264 actual = lodashStable.map(values, function(n) {
15265 var func = _.nthArg(n);
15266 return func('a', 'b', 'c');
15269 assert.deepEqual(actual, expected);
15273 /*--------------------------------------------------------------------------*/
15275 QUnit.module('lodash.omit');
15278 var args = arguments,
15279 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
15281 QUnit.test('should flatten `props`', function(assert) {
15284 assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
15285 assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
15288 QUnit.test('should work with a primitive `object` argument', function(assert) {
15294 assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
15296 delete stringProto.a;
15297 delete stringProto.b;
15300 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
15304 lodashStable.each([null, undefined], function(value) {
15305 assert.deepEqual(_.omit(value, 'valueOf'), {});
15307 delete objectProto.a;
15310 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
15313 assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
15316 QUnit.test('should coerce property names to strings', function(assert) {
15319 assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
15323 /*--------------------------------------------------------------------------*/
15325 QUnit.module('lodash.omitBy');
15328 QUnit.test('should work with a predicate argument', function(assert) {
15331 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
15333 var actual = _.omitBy(object, function(n) {
15334 return n != 2 && n != 4;
15337 assert.deepEqual(actual, { 'b': 2, 'd': 4 });
15341 /*--------------------------------------------------------------------------*/
15343 QUnit.module('omit methods');
15345 lodashStable.each(['omit', 'omitBy'], function(methodName) {
15346 var expected = { 'b': 2, 'd': 4 },
15347 func = _[methodName],
15348 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
15349 prop = function(object, props) { return props; };
15351 if (methodName == 'omitBy') {
15352 prop = function(object, props) {
15353 props = typeof props == 'string' ? [props] : props;
15354 return function(value) {
15355 return _.some(props, function(key) { return object[key] === value; });
15359 QUnit.test('`_.' + methodName + '` should create an object with omitted properties', function(assert) {
15362 assert.deepEqual(func(object, prop(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
15363 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
15366 QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) {
15370 Foo.prototype = object;
15373 assert.deepEqual(func(foo, prop(object, ['a', 'c'])), expected);
15376 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
15379 var array = [1, 2, 3];
15380 assert.deepEqual(func(array, prop(array, ['0', '2'])), { '1': 2 });
15384 /*--------------------------------------------------------------------------*/
15386 QUnit.module('lodash.once');
15389 QUnit.test('should invoke `func` once', function(assert) {
15393 once = _.once(function() { return ++count; });
15396 assert.strictEqual(once(), 1);
15397 assert.strictEqual(count, 1);
15400 QUnit.test('should ignore recursive calls', function(assert) {
15405 var once = _.once(function() {
15410 assert.strictEqual(once(), 1);
15411 assert.strictEqual(count, 1);
15414 QUnit.test('should not throw more than once', function(assert) {
15419 var once = _.once(function() {
15423 assert.raises(once);
15434 /*--------------------------------------------------------------------------*/
15436 QUnit.module('lodash.over');
15439 QUnit.test('should create a function that invokes `iteratees`', function(assert) {
15442 var over = _.over(Math.max, Math.min);
15443 assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
15446 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
15449 var over = _.over(undefined, null);
15450 assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
15453 QUnit.test('should work with "_.property" shorthands', function(assert) {
15456 var object = { 'a': 1, 'b': 2 },
15457 over = _.over('b', 'a');
15459 assert.deepEqual(over(object), [2, 1]);
15462 QUnit.test('should work with "_.matches" shorthands', function(assert) {
15465 var object = { 'a': 1, 'b': 2 },
15466 over = _.over({ 'c': 3 }, { 'a': 1 });
15468 assert.deepEqual(over(object), [false, true]);
15471 QUnit.test('should provide arguments to predicates', function(assert) {
15474 var over = _.over(function() {
15475 return slice.call(arguments);
15478 assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
15481 QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
15484 var over = _.over(function() { return this.b; }, function() { return this.a; }),
15485 object = { 'over': over, 'a': 1, 'b': 2 };
15487 assert.deepEqual(object.over(), [2, 1]);
15491 /*--------------------------------------------------------------------------*/
15493 QUnit.module('lodash.overEvery');
15496 QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
15499 var over = _.overEvery(alwaysTrue, alwaysOne, alwaysA);
15500 assert.strictEqual(over(), true);
15503 QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
15507 countFalse = function() { count++; return false; },
15508 countTrue = function() { count++; return true; },
15509 over = _.overEvery(countTrue, countFalse, countTrue);
15511 assert.strictEqual(over(), false);
15512 assert.strictEqual(count, 2);
15515 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
15518 var over = _.overEvery(undefined, null);
15519 assert.strictEqual(over(true), true);
15520 assert.strictEqual(over(false), false);
15523 QUnit.test('should work with "_.property" shorthands', function(assert) {
15526 var object = { 'a': 1, 'b': 2 },
15527 over = _.overEvery('a', 'c');
15529 assert.strictEqual(over(object), false);
15531 over = _.overEvery('b', 'a');
15532 assert.strictEqual(over(object), true);
15535 QUnit.test('should work with "_.matches" shorthands', function(assert) {
15538 var object = { 'a': 1, 'b': 2 },
15539 over = _.overEvery({ 'b': 2 }, { 'a': 1 });
15541 assert.strictEqual(over(object), true);
15543 over = _.overEvery({ 'a': 1 }, { 'c': 3 });
15544 assert.strictEqual(over(object), false);
15547 QUnit.test('should flatten `predicates`', function(assert) {
15550 var over = _.overEvery(alwaysTrue, [alwaysFalse]);
15551 assert.strictEqual(over(), false);
15554 QUnit.test('should provide arguments to predicates', function(assert) {
15559 var over = _.overEvery(function() {
15560 args = slice.call(arguments);
15563 over('a', 'b', 'c');
15564 assert.deepEqual(args, ['a', 'b', 'c']);
15567 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
15570 var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
15571 object = { 'over': over, 'a': 1, 'b': 2 };
15573 assert.strictEqual(object.over(), true);
15576 assert.strictEqual(object.over(), false);
15580 /*--------------------------------------------------------------------------*/
15582 QUnit.module('lodash.overSome');
15585 QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
15588 var over = _.overSome(alwaysFalse, alwaysOne, alwaysEmptyString);
15589 assert.strictEqual(over(), true);
15591 over = _.overSome(alwaysNull, alwaysA, alwaysZero);
15592 assert.strictEqual(over(), true);
15595 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
15599 countFalse = function() { count++; return false; },
15600 countTrue = function() { count++; return true; },
15601 over = _.overSome(countFalse, countTrue, countFalse);
15603 assert.strictEqual(over(), true);
15604 assert.strictEqual(count, 2);
15607 QUnit.test('should return `false` if all predicates return falsey', function(assert) {
15610 var over = _.overSome(alwaysFalse, alwaysFalse, alwaysFalse);
15611 assert.strictEqual(over(), false);
15613 over = _.overSome(alwaysNull, alwaysZero, alwaysEmptyString);
15614 assert.strictEqual(over(), false);
15617 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
15620 var over = _.overSome(undefined, null);
15621 assert.strictEqual(over(true), true);
15622 assert.strictEqual(over(false), false);
15625 QUnit.test('should work with "_.property" shorthands', function(assert) {
15628 var object = { 'a': 1, 'b': 2 },
15629 over = _.overSome('c', 'a');
15631 assert.strictEqual(over(object), true);
15633 over = _.overSome('d', 'c');
15634 assert.strictEqual(over(object), false);
15637 QUnit.test('should work with "_.matches" shorthands', function(assert) {
15640 var object = { 'a': 1, 'b': 2 },
15641 over = _.overSome({ 'c': 3 }, { 'a': 1 });
15643 assert.strictEqual(over(object), true);
15645 over = _.overSome({ 'b': 1 }, { 'a': 2 });
15646 assert.strictEqual(over(object), false);
15649 QUnit.test('should flatten `predicates`', function(assert) {
15652 var over = _.overSome(alwaysFalse, [alwaysTrue]);
15653 assert.strictEqual(over(), true);
15656 QUnit.test('should provide arguments to predicates', function(assert) {
15661 var over = _.overSome(function() {
15662 args = slice.call(arguments);
15665 over('a', 'b', 'c');
15666 assert.deepEqual(args, ['a', 'b', 'c']);
15669 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
15672 var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
15673 object = { 'over': over, 'a': 1, 'b': 2 };
15675 assert.strictEqual(object.over(), true);
15677 object.a = object.b = 0;
15678 assert.strictEqual(object.over(), false);
15682 /*--------------------------------------------------------------------------*/
15684 QUnit.module('lodash.pad');
15687 QUnit.test('should pad a string to a given length', function(assert) {
15690 assert.strictEqual(_.pad('abc', 9), ' abc ');
15693 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
15696 assert.strictEqual(_.pad('abc', 8), ' abc ');
15697 assert.strictEqual(_.pad('abc', 8, '_-'), '_-abc_-_');
15700 QUnit.test('should coerce `string` to a string', function(assert) {
15703 assert.strictEqual(_.pad(Object('abc'), 4), 'abc ');
15704 assert.strictEqual(_.pad({ 'toString': lodashStable.constant('abc') }, 5), ' abc ');
15708 /*--------------------------------------------------------------------------*/
15710 QUnit.module('lodash.padEnd');
15713 QUnit.test('should pad a string to a given length', function(assert) {
15716 assert.strictEqual(_.padEnd('abc', 6), 'abc ');
15719 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
15722 assert.strictEqual(_.padEnd('abc', 6, '_-'), 'abc_-_');
15725 QUnit.test('should coerce `string` to a string', function(assert) {
15728 assert.strictEqual(_.padEnd(Object('abc'), 4), 'abc ');
15729 assert.strictEqual(_.padEnd({ 'toString': lodashStable.constant('abc') }, 5), 'abc ');
15733 /*--------------------------------------------------------------------------*/
15735 QUnit.module('lodash.padStart');
15738 QUnit.test('should pad a string to a given length', function(assert) {
15741 assert.strictEqual(_.padStart('abc', 6), ' abc');
15744 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
15747 assert.strictEqual(_.padStart('abc', 6, '_-'), '_-_abc');
15750 QUnit.test('should coerce `string` to a string', function(assert) {
15753 assert.strictEqual(_.padStart(Object('abc'), 4), ' abc');
15754 assert.strictEqual(_.padStart({ 'toString': lodashStable.constant('abc') }, 5), ' abc');
15758 /*--------------------------------------------------------------------------*/
15760 QUnit.module('pad methods');
15762 lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
15763 var func = _[methodName],
15764 isPad = methodName == 'pad',
15765 isStart = methodName == 'padStart';
15767 QUnit.test('`_.' + methodName + '` should not pad is string is >= `length`', function(assert) {
15770 assert.strictEqual(func('abc', 2), 'abc');
15771 assert.strictEqual(func('abc', 3), 'abc');
15774 QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
15777 lodashStable.each([0, -2], function(length) {
15778 assert.strictEqual(func('abc', length), 'abc');
15782 QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
15785 lodashStable.each(['', '4'], function(length) {
15786 var actual = length ? (isStart ? ' abc' : 'abc ') : 'abc';
15787 assert.strictEqual(func('abc', length), actual);
15791 QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
15794 lodashStable.each([undefined, '_-'], function(chars) {
15795 var expected = chars ? (isPad ? '__' : chars) : ' ';
15796 assert.strictEqual(func(null, 2, chars), expected);
15797 assert.strictEqual(func(undefined, 2, chars), expected);
15798 assert.strictEqual(func('', 2, chars), expected);
15802 QUnit.test('`_.' + methodName + '` should work with nullish or empty string values for `chars`', function(assert) {
15805 assert.notStrictEqual(func('abc', 6, null), 'abc');
15806 assert.notStrictEqual(func('abc', 6, undefined), 'abc');
15807 assert.strictEqual(func('abc', 6, ''), 'abc');
15811 /*--------------------------------------------------------------------------*/
15813 QUnit.module('lodash.parseInt');
15816 QUnit.test('should accept a `radix` argument', function(assert) {
15819 var expected = lodashStable.range(2, 37);
15821 var actual = lodashStable.map(expected, function(radix) {
15822 return _.parseInt('10', radix);
15825 assert.deepEqual(actual, expected);
15828 QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
15831 assert.strictEqual(_.parseInt('10'), 10);
15832 assert.strictEqual(_.parseInt('10', 0), 10);
15833 assert.strictEqual(_.parseInt('10', 10), 10);
15834 assert.strictEqual(_.parseInt('10', undefined), 10);
15837 QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
15840 lodashStable.each(['0x20', '0X20'], function(string) {
15841 assert.strictEqual(_.parseInt(string), 32);
15842 assert.strictEqual(_.parseInt(string, 0), 32);
15843 assert.strictEqual(_.parseInt(string, 16), 32);
15844 assert.strictEqual(_.parseInt(string, undefined), 32);
15848 QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
15851 assert.strictEqual(_.parseInt('08'), 8);
15852 assert.strictEqual(_.parseInt('08', 10), 8);
15855 QUnit.test('should parse strings with leading whitespace (test in Chrome and Firefox)', function(assert) {
15858 var expected = [8, 8, 10, 10, 32, 32, 32, 32];
15860 lodashStable.times(2, function(index) {
15862 func = (index ? (lodashBizarro || {}) : _).parseInt;
15865 lodashStable.times(2, function(otherIndex) {
15866 var string = otherIndex ? '10' : '08';
15868 func(whitespace + string, 10),
15869 func(whitespace + string)
15873 lodashStable.each(['0x20', '0X20'], function(string) {
15875 func(whitespace + string),
15876 func(whitespace + string, 16)
15880 assert.deepEqual(actual, expected);
15883 skipAssert(assert);
15888 QUnit.test('should coerce `radix` to a number', function(assert) {
15891 var object = { 'valueOf': alwaysZero };
15892 assert.strictEqual(_.parseInt('08', object), 8);
15893 assert.strictEqual(_.parseInt('0x20', object), 32);
15896 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
15899 var strings = lodashStable.map(['6', '08', '10'], Object),
15900 actual = lodashStable.map(strings, _.parseInt);
15902 assert.deepEqual(actual, [6, 8, 10]);
15904 actual = lodashStable.map('123', _.parseInt);
15905 assert.deepEqual(actual, [1, 2, 3]);
15909 /*--------------------------------------------------------------------------*/
15911 QUnit.module('partial methods');
15913 lodashStable.each(['partial', 'partialRight'], function(methodName) {
15914 var func = _[methodName],
15915 isPartial = methodName == 'partial',
15916 ph = func.placeholder;
15918 QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
15921 var par = func(identity, 'a');
15922 assert.strictEqual(par(), 'a');
15925 QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
15928 var fn = function(a, b) { return [a, b]; },
15929 par = func(fn, 'a'),
15930 expected = isPartial ? ['a', 'b'] : ['b', 'a'];
15932 assert.deepEqual(par('b'), expected);
15935 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
15938 var fn = function() { return arguments.length; },
15941 assert.strictEqual(par(), 0);
15944 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
15947 var par = func(identity);
15948 assert.strictEqual(par('a'), 'a');
15951 QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
15954 var fn = function() { return slice.call(arguments); },
15955 par = func(fn, ph, 'b', ph);
15957 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
15958 assert.deepEqual(par('a'), ['a', 'b', undefined]);
15959 assert.deepEqual(par(), [undefined, 'b', undefined]);
15962 assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
15964 par = func(fn, ph, 'c', ph);
15965 assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
15969 QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) {
15972 if (!isModularize) {
15973 var _ph = _.placeholder = {},
15974 fn = function() { return slice.call(arguments); },
15975 par = func(fn, _ph, 'b', ph),
15976 expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph];
15978 assert.deepEqual(par('a', 'c'), expected);
15979 delete _.placeholder;
15982 skipAssert(assert);
15986 QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
15989 var fn = function(a, b, c) {},
15990 par = func(fn, 'a');
15992 assert.strictEqual(par.length, 0);
15995 QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
15998 function Foo(value) {
15999 return value && object;
16005 assert.ok(new par instanceof Foo);
16006 assert.strictEqual(new par(true), object);
16009 QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
16012 function greet(greeting, name) {
16013 return greeting + ' ' + name;
16016 var par1 = func(greet, 'hi'),
16017 par2 = func(par1, 'barney'),
16018 par3 = func(par1, 'pebbles');
16020 assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
16021 assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
16022 assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
16025 QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
16028 var fn = function(a, b, c) { return a + b + c; },
16029 curried = _.curry(func(fn, 1), 2);
16031 assert.strictEqual(curried(2, 3), 6);
16032 assert.strictEqual(curried(2)(3), 6);
16035 QUnit.test('should work with placeholders and curried functions', function(assert) {
16038 var fn = function() { return slice.call(arguments); },
16039 curried = _.curry(fn),
16040 par = func(curried, ph, 'b', ph, 'd');
16042 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
16046 /*--------------------------------------------------------------------------*/
16048 QUnit.module('lodash.partialRight');
16051 QUnit.test('should work as a deep `_.defaults`', function(assert) {
16054 var object = { 'a': { 'b': 1 } },
16055 source = { 'a': { 'b': 2, 'c': 3 } },
16056 expected = { 'a': { 'b': 1, 'c': 3 } };
16058 var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
16059 return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
16062 assert.deepEqual(defaultsDeep(object, source), expected);
16066 /*--------------------------------------------------------------------------*/
16068 QUnit.module('methods using `createWrapper`');
16072 return slice.call(arguments);
16075 var ph1 = _.bind.placeholder,
16076 ph2 = _.bindKey.placeholder,
16077 ph3 = _.partial.placeholder,
16078 ph4 = _.partialRight.placeholder;
16080 QUnit.test('should work with combinations of partial functions', function(assert) {
16083 var a = _.partial(fn),
16084 b = _.partialRight(a, 3),
16085 c = _.partial(b, 1);
16087 assert.deepEqual(c(2), [1, 2, 3]);
16090 QUnit.test('should work with combinations of bound and partial functions', function(assert) {
16093 var fn = function() {
16094 var result = [this.a];
16095 push.apply(result, arguments);
16099 var expected = [1, 2, 3, 4],
16100 object = { 'a': 1, 'fn': fn };
16102 var a = _.bindKey(object, 'fn'),
16103 b = _.partialRight(a, 4),
16104 c = _.partial(b, 2);
16106 assert.deepEqual(c(3), expected);
16108 a = _.bind(fn, object);
16109 b = _.partialRight(a, 4);
16110 c = _.partial(b, 2);
16112 assert.deepEqual(c(3), expected);
16114 a = _.partial(fn, 2);
16115 b = _.bind(a, object);
16116 c = _.partialRight(b, 4);
16118 assert.deepEqual(c(3), expected);
16121 QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
16124 function Foo(a, b, c) {
16125 return b === 0 && object;
16128 var combo = _.partial(_.partialRight(Foo, 3), 1),
16131 assert.ok(new combo(2) instanceof Foo);
16132 assert.strictEqual(new combo(0), object);
16135 QUnit.test('should work with combinations of functions with placeholders', function(assert) {
16138 var expected = [1, 2, 3, 4, 5, 6],
16139 object = { 'fn': fn };
16141 var a = _.bindKey(object, 'fn', ph2, 2),
16142 b = _.partialRight(a, ph4, 6),
16143 c = _.partial(b, 1, ph3, 4);
16145 assert.deepEqual(c(3, 5), expected);
16147 a = _.bind(fn, object, ph1, 2);
16148 b = _.partialRight(a, ph4, 6);
16149 c = _.partial(b, 1, ph3, 4);
16151 assert.deepEqual(c(3, 5), expected);
16153 a = _.partial(fn, ph3, 2);
16154 b = _.bind(a, object, 1, ph1, 4);
16155 c = _.partialRight(b, ph4, 6);
16157 assert.deepEqual(c(3, 5), expected);
16160 QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
16163 var expected = [1, 2, 3, 4],
16164 object = { 'fn': fn };
16166 var a = _.bindKey(object, 'fn', ph2, 2),
16167 b = _.partialRight(a, ph4, 4),
16168 c = _.partial(b, ph3, 3);
16170 assert.deepEqual(c(1), expected);
16172 a = _.bind(fn, object, ph1, 2);
16173 b = _.partialRight(a, ph4, 4);
16174 c = _.partial(b, ph3, 3);
16176 assert.deepEqual(c(1), expected);
16178 a = _.partial(fn, ph3, 2);
16179 b = _.bind(a, object, ph1, 3);
16180 c = _.partialRight(b, ph4, 4);
16182 assert.deepEqual(c(1), expected);
16185 QUnit.test('should work with recursively bound functions', function(assert) {
16188 var fn = function() {
16192 var a = _.bind(fn, { 'a': 1 }),
16193 b = _.bind(a, { 'a': 2 }),
16194 c = _.bind(b, { 'a': 3 });
16196 assert.strictEqual(c(), 1);
16199 QUnit.test('should work when hot', function(assert) {
16202 lodashStable.times(2, function(index) {
16203 var fn = function() {
16204 var result = [this];
16205 push.apply(result, arguments);
16210 bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
16211 expected = [object, 1, 2, 3];
16213 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
16214 var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
16215 return index ? bound2(3) : bound2(1, 2, 3);
16218 assert.deepEqual(actual, expected);
16220 actual = _.last(lodashStable.times(HOT_COUNT, function() {
16221 var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
16222 bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
16224 return index ? bound2(3) : bound2(1, 2, 3);
16227 assert.deepEqual(actual, expected);
16230 lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
16231 var fn = function(a, b, c) { return [a, b, c]; },
16232 curried = _[methodName](fn),
16233 expected = index ? [3, 2, 1] : [1, 2, 3];
16235 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
16236 return curried(1)(2)(3);
16239 assert.deepEqual(actual, expected);
16241 actual = _.last(lodashStable.times(HOT_COUNT, function() {
16242 var curried = _[methodName](fn);
16243 return curried(1)(2)(3);
16246 assert.deepEqual(actual, expected);
16249 lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
16250 var func = _[methodName],
16251 fn = function() { return slice.call(arguments); },
16252 par1 = func(fn, 1),
16253 expected = index ? [3, 2, 1] : [1, 2, 3];
16255 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
16256 var par2 = func(par1, 2);
16260 assert.deepEqual(actual, expected);
16262 actual = _.last(lodashStable.times(HOT_COUNT, function() {
16263 var par1 = func(fn, 1),
16264 par2 = func(par1, 2);
16269 assert.deepEqual(actual, expected);
16274 /*--------------------------------------------------------------------------*/
16276 QUnit.module('lodash.partition');
16279 var array = [1, 0, 1];
16281 QUnit.test('should split elements into two groups by `predicate`', function(assert) {
16284 assert.deepEqual(_.partition([], identity), [[], []]);
16285 assert.deepEqual(_.partition(array, alwaysTrue), [array, []]);
16286 assert.deepEqual(_.partition(array, alwaysFalse), [[], array]);
16289 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
16292 var values = [, null, undefined],
16293 expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
16295 var actual = lodashStable.map(values, function(value, index) {
16296 return index ? _.partition(array, value) : _.partition(array);
16299 assert.deepEqual(actual, expected);
16302 QUnit.test('should work with "_.property" shorthands', function(assert) {
16305 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
16306 actual = _.partition(objects, 'a');
16308 assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
16311 QUnit.test('should work with a number for `predicate`', function(assert) {
16320 assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
16321 assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
16324 QUnit.test('should work with an object for `collection`', function(assert) {
16327 var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
16328 assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
16332 /*--------------------------------------------------------------------------*/
16334 QUnit.module('lodash.pick');
16337 var args = arguments,
16338 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16340 QUnit.test('should flatten `props`', function(assert) {
16343 assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
16344 assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
16347 QUnit.test('should work with a primitive `object` argument', function(assert) {
16350 assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
16353 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
16356 lodashStable.each([null, undefined], function(value) {
16357 assert.deepEqual(_.pick(value, 'valueOf'), {});
16361 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
16364 assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
16367 QUnit.test('should coerce property names to strings', function(assert) {
16370 assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
16374 /*--------------------------------------------------------------------------*/
16376 QUnit.module('lodash.pickBy');
16379 QUnit.test('should work with a predicate argument', function(assert) {
16382 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16384 var actual = _.pickBy(object, function(n) {
16385 return n == 1 || n == 3;
16388 assert.deepEqual(actual, { 'a': 1, 'c': 3 });
16392 /*--------------------------------------------------------------------------*/
16394 QUnit.module('pick methods');
16396 lodashStable.each(['pick', 'pickBy'], function(methodName) {
16397 var expected = { 'a': 1, 'c': 3 },
16398 func = _[methodName],
16399 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
16400 prop = function(object, props) { return props; };
16402 if (methodName == 'pickBy') {
16403 prop = function(object, props) {
16404 props = typeof props == 'string' ? [props] : props;
16405 return function(value) {
16406 return _.some(props, function(key) { return object[key] === value; });
16410 QUnit.test('`_.' + methodName + '` should create an object of picked properties', function(assert) {
16413 assert.deepEqual(func(object, prop(object, 'a')), { 'a': 1 });
16414 assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
16417 QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) {
16421 Foo.prototype = object;
16424 assert.deepEqual(func(foo, prop(foo, ['a', 'c'])), expected);
16427 QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
16430 var array = [1, 2, 3];
16431 assert.deepEqual(func(array, prop(array, '1')), { '1': 2 });
16435 /*--------------------------------------------------------------------------*/
16437 QUnit.module('lodash.property');
16440 QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
16443 var object = { 'a': 1 };
16445 lodashStable.each(['a', ['a']], function(path) {
16446 var prop = _.property(path);
16447 assert.strictEqual(prop.length, 1);
16448 assert.strictEqual(prop(object), 1);
16452 QUnit.test('should pluck deep property values', function(assert) {
16455 var object = { 'a': { 'b': { 'c': 3 } } };
16457 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
16458 var prop = _.property(path);
16459 assert.strictEqual(prop(object), 3);
16463 QUnit.test('should work with non-string `path` arguments', function(assert) {
16466 var array = [1, 2, 3];
16468 lodashStable.each([1, [1]], function(path) {
16469 var prop = _.property(path);
16470 assert.strictEqual(prop(array), 2);
16474 QUnit.test('should coerce key to a string', function(assert) {
16478 fn.toString = lodashStable.constant('fn');
16480 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
16481 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
16482 values = [null, undefined, fn, {}];
16484 var actual = lodashStable.transform(objects, function(result, object, index) {
16485 var key = values[index];
16486 lodashStable.each([key, [key]], function(path) {
16487 var prop = _.property(key);
16488 result.push(prop(object));
16492 assert.deepEqual(actual, expected);
16495 QUnit.test('should pluck inherited property values', function(assert) {
16499 Foo.prototype.a = 1;
16501 lodashStable.each(['a', ['a']], function(path) {
16502 var prop = _.property(path);
16503 assert.strictEqual(prop(new Foo), 1);
16507 QUnit.test('should pluck a key over a path', function(assert) {
16510 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
16512 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
16513 var prop = _.property(path);
16514 assert.strictEqual(prop(object), 3);
16518 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
16521 var values = [, null, undefined],
16522 expected = lodashStable.map(values, alwaysUndefined);
16524 lodashStable.each(['constructor', ['constructor']], function(path) {
16525 var prop = _.property(path);
16527 var actual = lodashStable.map(values, function(value, index) {
16528 return index ? prop(value) : prop();
16531 assert.deepEqual(actual, expected);
16535 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
16538 var values = [, null, undefined],
16539 expected = lodashStable.map(values, alwaysUndefined);
16541 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
16542 var prop = _.property(path);
16544 var actual = lodashStable.map(values, function(value, index) {
16545 return index ? prop(value) : prop();
16548 assert.deepEqual(actual, expected);
16552 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
16557 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
16558 var prop = _.property(path);
16559 assert.strictEqual(prop(object), undefined);
16564 /*--------------------------------------------------------------------------*/
16566 QUnit.module('lodash.propertyOf');
16569 QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
16572 var object = { 'a': 1 },
16573 propOf = _.propertyOf(object);
16575 assert.strictEqual(propOf.length, 1);
16576 lodashStable.each(['a', ['a']], function(path) {
16577 assert.strictEqual(propOf(path), 1);
16581 QUnit.test('should pluck deep property values', function(assert) {
16584 var object = { 'a': { 'b': { 'c': 3 } } },
16585 propOf = _.propertyOf(object);
16587 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
16588 assert.strictEqual(propOf(path), 3);
16592 QUnit.test('should work with non-string `path` arguments', function(assert) {
16595 var array = [1, 2, 3],
16596 propOf = _.propertyOf(array);
16598 lodashStable.each([1, [1]], function(path) {
16599 assert.strictEqual(propOf(path), 2);
16603 QUnit.test('should coerce key to a string', function(assert) {
16607 fn.toString = lodashStable.constant('fn');
16609 var expected = [1, 1, 2, 2, 3, 3, 4, 4],
16610 objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
16611 values = [null, undefined, fn, {}];
16613 var actual = lodashStable.transform(objects, function(result, object, index) {
16614 var key = values[index];
16615 lodashStable.each([key, [key]], function(path) {
16616 var propOf = _.propertyOf(object);
16617 result.push(propOf(key));
16621 assert.deepEqual(actual, expected);
16624 QUnit.test('should pluck inherited property values', function(assert) {
16627 function Foo() { this.a = 1; }
16628 Foo.prototype.b = 2;
16630 var propOf = _.propertyOf(new Foo);
16632 lodashStable.each(['b', ['b']], function(path) {
16633 assert.strictEqual(propOf(path), 2);
16637 QUnit.test('should pluck a key over a path', function(assert) {
16640 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } },
16641 propOf = _.propertyOf(object);
16643 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
16644 assert.strictEqual(propOf(path), 3);
16648 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
16651 var values = [, null, undefined],
16652 expected = lodashStable.map(values, alwaysUndefined);
16654 lodashStable.each(['constructor', ['constructor']], function(path) {
16655 var actual = lodashStable.map(values, function(value, index) {
16656 var propOf = index ? _.propertyOf(value) : _.propertyOf();
16657 return propOf(path);
16660 assert.deepEqual(actual, expected);
16664 QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
16667 var values = [, null, undefined],
16668 expected = lodashStable.map(values, alwaysUndefined);
16670 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
16671 var actual = lodashStable.map(values, function(value, index) {
16672 var propOf = index ? _.propertyOf(value) : _.propertyOf();
16673 return propOf(path);
16676 assert.deepEqual(actual, expected);
16680 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
16683 var propOf = _.propertyOf({});
16685 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
16686 assert.strictEqual(propOf(path), undefined);
16691 /*--------------------------------------------------------------------------*/
16693 QUnit.module('pull methods');
16695 lodashStable.each(['pull', 'pullAll'], function(methodName) {
16696 var func = _[methodName],
16697 isPull = methodName == 'pull';
16699 function pull(array, values) {
16701 ? func.apply(undefined, [array].concat(values))
16702 : func(array, values);
16705 QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
16708 var array = [1, 2, 3],
16709 actual = pull(array, [1, 3]);
16711 assert.deepEqual(array, [2]);
16712 assert.ok(actual === array);
16715 QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
16718 var array = [1, 2, 3, 4];
16723 assert.notOk('0' in array);
16724 assert.notOk('2' in array);
16727 QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
16730 var array = [1, 2, 3];
16733 pull(array, [undefined]);
16734 assert.deepEqual(array, [1, 3]);
16737 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
16740 var array = [1, NaN, 3, NaN];
16742 pull(array, [NaN]);
16743 assert.deepEqual(array, [1, 3]);
16747 /*--------------------------------------------------------------------------*/
16749 QUnit.module('lodash.pullAllBy');
16752 QUnit.test('should accept an `iteratee` argument', function(assert) {
16755 var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
16757 var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
16761 assert.deepEqual(actual, [{ 'x': 2 }]);
16764 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
16768 array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
16770 _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
16771 args || (args = slice.call(arguments));
16774 assert.deepEqual(args, [{ 'x': 1 }]);
16778 /*--------------------------------------------------------------------------*/
16780 QUnit.module('lodash.pullAt');
16783 QUnit.test('should modify the array and return removed elements', function(assert) {
16786 var array = [1, 2, 3],
16787 actual = _.pullAt(array, [0, 1]);
16789 assert.deepEqual(array, [3]);
16790 assert.deepEqual(actual, [1, 2]);
16793 QUnit.test('should work with unsorted indexes', function(assert) {
16796 var array = [1, 2, 3, 4],
16797 actual = _.pullAt(array, [1, 3, 0]);
16799 assert.deepEqual(array, [3]);
16800 assert.deepEqual(actual, [2, 4, 1]);
16803 QUnit.test('should work with repeated indexes', function(assert) {
16806 var array = [1, 2, 3, 4],
16807 actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
16809 assert.deepEqual(array, [4]);
16810 assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
16813 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
16816 var array = ['a', 'b', 'c'],
16817 actual = _.pullAt(array, [2, 4, 0]);
16819 assert.deepEqual(array, ['b']);
16820 assert.deepEqual(actual, ['c', undefined, 'a']);
16823 QUnit.test('should flatten `indexes`', function(assert) {
16826 var array = ['a', 'b', 'c'];
16827 assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
16828 assert.deepEqual(array, ['b']);
16830 array = ['a', 'b', 'c', 'd'];
16831 assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
16832 assert.deepEqual(array, ['b']);
16835 QUnit.test('should return an empty array when no indexes are given', function(assert) {
16838 var array = ['a', 'b', 'c'],
16839 actual = _.pullAt(array);
16841 assert.deepEqual(array, ['a', 'b', 'c']);
16842 assert.deepEqual(actual, []);
16844 actual = _.pullAt(array, [], []);
16846 assert.deepEqual(array, ['a', 'b', 'c']);
16847 assert.deepEqual(actual, []);
16850 QUnit.test('should work with non-index paths', function(assert) {
16853 var values = lodashStable.reject(empties, function(value) {
16854 return (value === 0) || lodashStable.isArray(value);
16855 }).concat(-1, 1.1);
16857 var array = lodashStable.transform(values, function(result, value) {
16861 var expected = lodashStable.map(values, alwaysOne),
16862 actual = _.pullAt(array, values);
16864 assert.deepEqual(actual, expected);
16866 expected = lodashStable.map(values, alwaysUndefined),
16867 actual = _.at(array, values);
16869 assert.deepEqual(actual, expected);
16872 QUnit.test('should work with deep paths', function(assert) {
16876 array.a = { 'b': { 'c': 3 } };
16878 var actual = _.pullAt(array, 'a.b.c');
16880 assert.deepEqual(actual, [3]);
16881 assert.deepEqual(array.a, { 'b': {} });
16884 actual = _.pullAt(array, 'a.b.c.d.e');
16887 assert.deepEqual(actual, [undefined]);
16890 QUnit.test('should work with a falsey `array` argument when keys are given', function(assert) {
16893 var values = falsey.slice(),
16894 expected = lodashStable.map(values, lodashStable.constant(Array(4)));
16896 var actual = lodashStable.map(values, function(array) {
16898 return _.pullAt(array, 0, 1, 'pop', 'push');
16902 assert.deepEqual(actual, expected);
16906 /*--------------------------------------------------------------------------*/
16908 QUnit.module('lodash.random');
16911 var array = Array(1000);
16913 QUnit.test('should return `0` or `1` when no arguments are given', function(assert) {
16916 var actual = lodashStable.map(array, function() {
16920 assert.deepEqual(_.uniq(actual).sort(), [0, 1]);
16923 QUnit.test('should support a `min` and `max` argument', function(assert) {
16929 assert.ok(_.some(array, function() {
16930 var result = _.random(min, max);
16931 return result >= min && result <= max;
16935 QUnit.test('should support not providing a `max` argument', function(assert) {
16941 assert.ok(_.some(array, function() {
16942 var result = _.random(max);
16943 return result >= min && result <= max;
16947 QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
16952 expected = [2, 3, 4];
16954 var actual = lodashStable.uniq(lodashStable.map(array, function() {
16955 return _.random(min, max);
16958 assert.deepEqual(actual, expected);
16961 QUnit.test('should support large integer values', function(assert) {
16964 var min = Math.pow(2, 31),
16965 max = Math.pow(2, 62);
16967 assert.ok(lodashStable.every(array, function() {
16968 var result = _.random(min, max);
16969 return result >= min && result <= max;
16972 assert.ok(_.some(array, function() {
16973 return _.random(MAX_INTEGER) > 0;
16977 QUnit.test('should coerce arguments to finite numbers', function(assert) {
16980 assert.strictEqual(_.random('1', '1'), 1);
16981 assert.strictEqual(_.random(NaN, NaN), 0);
16984 QUnit.test('should support floats', function(assert) {
16989 actual = _.random(min, max);
16991 assert.ok(actual % 1);
16992 assert.ok(actual >= min && actual <= max);
16995 QUnit.test('should support providing a `floating` argument', function(assert) {
16998 var actual = _.random(true);
16999 assert.ok(actual % 1 && actual >= 0 && actual <= 1);
17001 actual = _.random(2, true);
17002 assert.ok(actual % 1 && actual >= 0 && actual <= 2);
17004 actual = _.random(2, 4, true);
17005 assert.ok(actual % 1 && actual >= 2 && actual <= 4);
17008 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
17011 var array = [1, 2, 3],
17012 expected = lodashStable.map(array, alwaysTrue),
17013 randoms = lodashStable.map(array, _.random);
17015 var actual = lodashStable.map(randoms, function(result, index) {
17016 return result >= 0 && result <= array[index] && (result % 1) == 0;
17019 assert.deepEqual(actual, expected);
17023 /*--------------------------------------------------------------------------*/
17025 QUnit.module('range methods');
17027 lodashStable.each(['range', 'rangeRight'], function(methodName) {
17028 var func = _[methodName],
17029 isRange = methodName == 'range';
17031 function resolve(range) {
17032 return isRange ? range : range.reverse();
17035 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `end` is given', function(assert) {
17038 assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
17039 assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
17042 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `start` and `end` are given', function(assert) {
17045 assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
17046 assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
17049 QUnit.test('`_.' + methodName + '` should work with `start`, `end`, and `step` arguments', function(assert) {
17052 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
17053 assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
17054 assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
17057 QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
17060 assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
17063 QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
17066 assert.deepEqual(func(1, 5, 20), [1]);
17069 QUnit.test('`_.' + methodName + '` should work with a negative `step` argument', function(assert) {
17072 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
17073 assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
17076 QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
17079 var actual = func(-0, 1);
17080 assert.strictEqual(1 / actual[0], -Infinity);
17083 QUnit.test('`_.' + methodName + '` should treat falsey `start` arguments as `0`', function(assert) {
17086 lodashStable.each(falsey, function(value, index) {
17088 assert.deepEqual(func(value), []);
17089 assert.deepEqual(func(value, 1), [0]);
17091 assert.deepEqual(func(), []);
17096 QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
17099 var actual = [func('0', 1), func('1'), func(0, 1, '1'), func(NaN), func(NaN, NaN)];
17100 assert.deepEqual(actual, [[0], [0], [0], [], []]);
17103 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
17106 var array = [1, 2, 3],
17107 object = { 'a': 1, 'b': 2, 'c': 3 },
17108 expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
17110 lodashStable.each([array, object], function(collection) {
17111 var actual = lodashStable.map(collection, func);
17112 assert.deepEqual(actual, expected);
17117 /*--------------------------------------------------------------------------*/
17119 QUnit.module('lodash.rearg');
17123 return slice.call(arguments);
17126 QUnit.test('should reorder arguments provided to `func`', function(assert) {
17129 var rearged = _.rearg(fn, [2, 0, 1]);
17130 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
17133 QUnit.test('should work with repeated indexes', function(assert) {
17136 var rearged = _.rearg(fn, [1, 1, 1]);
17137 assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
17140 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
17143 var rearged = _.rearg(fn, [1, 4]);
17144 assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
17147 QUnit.test('should use `undefined` for non-index values', function(assert) {
17150 var values = lodashStable.reject(empties, function(value) {
17151 return (value === 0) || lodashStable.isArray(value);
17152 }).concat(-1, 1.1);
17154 var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
17156 var actual = lodashStable.map(values, function(value) {
17157 var rearged = _.rearg(fn, [value]);
17158 return rearged('a', 'b', 'c');
17161 assert.deepEqual(actual, expected);
17164 QUnit.test('should not rearrange arguments when no indexes are given', function(assert) {
17167 var rearged = _.rearg(fn);
17168 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
17170 rearged = _.rearg(fn, [], []);
17171 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
17174 QUnit.test('should accept multiple index arguments', function(assert) {
17177 var rearged = _.rearg(fn, 2, 0, 1);
17178 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
17181 QUnit.test('should accept multiple arrays of indexes', function(assert) {
17184 var rearged = _.rearg(fn, [2], [0, 1]);
17185 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
17188 QUnit.test('should work with fewer indexes than arguments', function(assert) {
17191 var rearged = _.rearg(fn, [1, 0]);
17192 assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
17195 QUnit.test('should work on functions that have been rearged', function(assert) {
17198 var rearged1 = _.rearg(fn, 2, 1, 0),
17199 rearged2 = _.rearg(rearged1, 1, 0, 2);
17201 assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
17205 /*--------------------------------------------------------------------------*/
17207 QUnit.module('lodash.reduce');
17210 var array = [1, 2, 3];
17212 QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
17215 assert.strictEqual(_.reduce(array), 1);
17218 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
17223 _.reduce(array, function() {
17224 args || (args = slice.call(arguments));
17227 assert.deepEqual(args, [0, 1, 0, array]);
17230 _.reduce(array, function() {
17231 args || (args = slice.call(arguments));
17234 assert.deepEqual(args, [1, 2, 1, array]);
17237 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
17241 object = { 'a': 1, 'b': 2 },
17242 firstKey = _.head(_.keys(object));
17244 var expected = firstKey == 'a'
17245 ? [0, 1, 'a', object]
17246 : [0, 2, 'b', object];
17248 _.reduce(object, function() {
17249 args || (args = slice.call(arguments));
17252 assert.deepEqual(args, expected);
17255 expected = firstKey == 'a'
17256 ? [1, 2, 'b', object]
17257 : [2, 1, 'a', object];
17259 _.reduce(object, function() {
17260 args || (args = slice.call(arguments));
17263 assert.deepEqual(args, expected);
17267 /*--------------------------------------------------------------------------*/
17269 QUnit.module('lodash.reduceRight');
17272 var array = [1, 2, 3];
17274 QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
17277 assert.strictEqual(_.reduceRight(array), 3);
17280 QUnit.test('should provide the correct `iteratee` arguments when iterating an array', function(assert) {
17285 _.reduceRight(array, function() {
17286 args || (args = slice.call(arguments));
17289 assert.deepEqual(args, [0, 3, 2, array]);
17292 _.reduceRight(array, function() {
17293 args || (args = slice.call(arguments));
17296 assert.deepEqual(args, [3, 2, 1, array]);
17299 QUnit.test('should provide the correct `iteratee` arguments when iterating an object', function(assert) {
17303 object = { 'a': 1, 'b': 2 },
17304 isFIFO = lodashStable.keys(object)[0] == 'a';
17306 var expected = isFIFO
17307 ? [0, 2, 'b', object]
17308 : [0, 1, 'a', object];
17310 _.reduceRight(object, function() {
17311 args || (args = slice.call(arguments));
17314 assert.deepEqual(args, expected);
17318 ? [2, 1, 'a', object]
17319 : [1, 2, 'b', object];
17321 _.reduceRight(object, function() {
17322 args || (args = slice.call(arguments));
17325 assert.deepEqual(args, expected);
17329 /*--------------------------------------------------------------------------*/
17331 QUnit.module('reduce methods');
17333 lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
17334 var func = _[methodName],
17336 isReduce = methodName == 'reduce';
17338 QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
17341 var actual = func(['a', 'b', 'c'], function(accumulator, value) {
17342 return accumulator + value;
17345 assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
17348 QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
17352 expected = lodashStable.map(empties, alwaysUndefined);
17354 lodashStable.each(empties, function(value) {
17356 actual.push(func(value, noop));
17360 assert.deepEqual(actual, expected);
17363 QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
17366 var expected = lodashStable.map(empties, lodashStable.constant('x'));
17368 var actual = lodashStable.map(empties, function(value) {
17370 return func(value, noop, 'x');
17374 assert.deepEqual(actual, expected);
17377 QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
17380 var actual = func([], noop, undefined);
17381 assert.strictEqual(actual, undefined);
17384 QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is given (test in IE > 9 and modern browsers)', function(assert) {
17388 object = { '0': 1, 'length': 0 };
17390 if ('__proto__' in array) {
17391 array.__proto__ = object;
17392 assert.strictEqual(func(array, noop), undefined);
17395 skipAssert(assert);
17397 assert.strictEqual(func(object, noop), undefined);
17400 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
17404 assert.strictEqual(_(array)[methodName](add), 6);
17407 skipAssert(assert);
17411 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
17415 assert.ok(_(array).chain()[methodName](add) instanceof _);
17418 skipAssert(assert);
17423 /*--------------------------------------------------------------------------*/
17425 QUnit.module('lodash.reject');
17428 var array = [1, 2, 3];
17430 QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
17433 assert.deepEqual(_.reject(array, isEven), [1, 3]);
17437 /*--------------------------------------------------------------------------*/
17439 QUnit.module('filter methods');
17441 lodashStable.each(['filter', 'reject'], function(methodName) {
17442 var array = [1, 2, 3, 4],
17443 func = _[methodName],
17444 isFilter = methodName == 'filter',
17445 objects = [{ 'a': 0 }, { 'a': 1 }];
17447 QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
17450 var actual = func([0], function(value, index, array) {
17455 assert.deepEqual(actual, [0]);
17458 QUnit.test('`_.' + methodName + '` should work with "_.property" shorthands', function(assert) {
17461 assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
17464 QUnit.test('`_.' + methodName + '` should work with "_.matches" shorthands', function(assert) {
17467 assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
17470 QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
17474 var wrapped = _(array);
17476 var actual = wrapped[methodName](function(n) {
17480 assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
17482 actual = wrapped[methodName](function(n) {
17486 assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
17489 skipAssert(assert, 2);
17493 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
17497 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
17498 predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); },
17499 actual = _(array).slice(1).map(square)[methodName](predicate).value();
17501 assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
17503 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
17504 return ['key' + index, index];
17507 actual = _(object).mapValues(square)[methodName](predicate).value();
17508 assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
17511 skipAssert(assert, 2);
17515 QUnit.test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
17520 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
17521 expected = [1, 0, lodashStable.map(array.slice(1), square)];
17523 _(array).slice(1)[methodName](function(value, index, array) {
17524 args || (args = slice.call(arguments));
17527 assert.deepEqual(args, [1, 0, array.slice(1)]);
17530 _(array).slice(1).map(square)[methodName](function(value, index, array) {
17531 args || (args = slice.call(arguments));
17534 assert.deepEqual(args, expected);
17537 _(array).slice(1).map(square)[methodName](function(value, index) {
17538 args || (args = slice.call(arguments));
17541 assert.deepEqual(args, expected);
17544 _(array).slice(1).map(square)[methodName](function(value) {
17545 args || (args = slice.call(arguments));
17548 assert.deepEqual(args, [1]);
17551 _(array).slice(1).map(square)[methodName](function() {
17552 args || (args = slice.call(arguments));
17555 assert.deepEqual(args, expected);
17558 skipAssert(assert, 5);
17563 /*--------------------------------------------------------------------------*/
17565 QUnit.module('lodash.remove');
17568 QUnit.test('should modify the array and return removed elements', function(assert) {
17571 var array = [1, 2, 3, 4];
17573 var actual = _.remove(array, function(n) {
17577 assert.deepEqual(array, [1, 3]);
17578 assert.deepEqual(actual, [2, 4]);
17581 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
17586 clone = array.slice();
17588 _.remove(array, function(n, index) {
17589 var args = slice.call(arguments);
17590 args[2] = args[2].slice();
17591 argsList.push(args);
17592 return isEven(index);
17595 assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
17598 QUnit.test('should work with "_.matches" shorthands', function(assert) {
17601 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
17602 _.remove(objects, { 'a': 1 });
17603 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
17606 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
17609 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
17610 _.remove(objects, ['a', 1]);
17611 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
17614 QUnit.test('should work with "_.property" shorthands', function(assert) {
17617 var objects = [{ 'a': 0 }, { 'a': 1 }];
17618 _.remove(objects, 'a');
17619 assert.deepEqual(objects, [{ 'a': 0 }]);
17622 QUnit.test('should preserve holes in arrays', function(assert) {
17625 var array = [1, 2, 3, 4];
17629 _.remove(array, function(n) {
17633 assert.notOk('0' in array);
17634 assert.notOk('2' in array);
17637 QUnit.test('should treat holes as `undefined`', function(assert) {
17640 var array = [1, 2, 3];
17643 _.remove(array, function(n) {
17647 assert.deepEqual(array, [1, 3]);
17650 QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
17653 var array = [1, 2, 3];
17655 _.remove(array, function(n, index) {
17656 return isEven(index);
17659 assert.deepEqual(array, [2]);
17663 /*--------------------------------------------------------------------------*/
17665 QUnit.module('lodash.repeat');
17668 QUnit.test('should repeat a string `n` times', function(assert) {
17671 assert.strictEqual(_.repeat('*', 3), '***');
17672 assert.strictEqual(_.repeat('abc', 2), 'abcabc');
17675 QUnit.test('should return an empty string for negative `n` or `n` of `0`', function(assert) {
17678 assert.strictEqual(_.repeat('abc', 0), '');
17679 assert.strictEqual(_.repeat('abc', -2), '');
17682 QUnit.test('should coerce `n` to an integer', function(assert) {
17685 assert.strictEqual(_.repeat('abc'), '');
17686 assert.strictEqual(_.repeat('abc', '2'), 'abcabc');
17687 assert.strictEqual(_.repeat('abc', 2.6), 'abcabc');
17688 assert.strictEqual(_.repeat('*', { 'valueOf': alwaysThree }), '***');
17691 QUnit.test('should coerce `string` to a string', function(assert) {
17694 assert.strictEqual(_.repeat(Object('abc'), 2), 'abcabc');
17695 assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
17699 /*--------------------------------------------------------------------------*/
17701 QUnit.module('lodash.replace');
17704 QUnit.test('should replace the matched pattern', function(assert) {
17707 var string = 'abcde';
17708 assert.strictEqual(_.replace(string, 'de', '123'), 'abc123');
17709 assert.strictEqual(_.replace(string, /[bd]/g, '-'), 'a-c-e');
17713 /*--------------------------------------------------------------------------*/
17715 QUnit.module('lodash.result');
17720 'b': function() { return this.a; }
17723 QUnit.test('should invoke function values', function(assert) {
17726 assert.strictEqual(_.result(object, 'b'), 1);
17729 QUnit.test('should invoke default function values', function(assert) {
17732 var actual = _.result(object, 'c', object.b);
17733 assert.strictEqual(actual, 1);
17736 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
17739 var value = { 'a': object };
17741 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17742 assert.strictEqual(_.result(value, path), 1);
17747 /*--------------------------------------------------------------------------*/
17749 QUnit.module('lodash.get and lodash.result');
17751 lodashStable.each(['get', 'result'], function(methodName) {
17752 var func = _[methodName];
17754 QUnit.test('`_.' + methodName + '` should get property values', function(assert) {
17757 var object = { 'a': 1 };
17759 lodashStable.each(['a', ['a']], function(path) {
17760 assert.strictEqual(func(object, path), 1);
17764 QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
17767 var object = { 'a': { 'b': { 'c': 3 } } };
17769 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
17770 assert.strictEqual(func(object, path), 3);
17774 QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
17777 var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
17779 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
17780 assert.strictEqual(func(object, path), 3);
17784 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
17787 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
17788 assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
17791 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
17794 var object = { 'a': 1 };
17795 assert.strictEqual(func(object, 'a[]'), 1);
17798 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
17801 lodashStable.each([['', ''], [[], ['']]], function(pair) {
17802 assert.strictEqual(func({}, pair[0]), undefined);
17803 assert.strictEqual(func({ '': 3 }, pair[1]), 3);
17807 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
17810 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
17813 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
17814 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
17817 lodashStable.each(paths, function(path) {
17818 assert.strictEqual(func(object, path), 8);
17822 QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
17825 lodashStable.each(['constructor', ['constructor']], function(path) {
17826 assert.strictEqual(func(null, path), undefined);
17827 assert.strictEqual(func(undefined, path), undefined);
17831 QUnit.test('`_.' + methodName + '` should return `undefined` with deep paths when `object` is nullish', function(assert) {
17834 var values = [null, undefined],
17835 expected = lodashStable.map(values, alwaysUndefined),
17836 paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
17838 lodashStable.each(paths, function(path) {
17839 var actual = lodashStable.map(values, function(value) {
17840 return func(value, path);
17843 assert.deepEqual(actual, expected);
17847 QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
17850 var object = { 'a': [, null] };
17852 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
17853 assert.strictEqual(func(object, path), undefined);
17857 QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
17860 var object = { 'a': { 'b': null } };
17862 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17863 assert.strictEqual(func(object, path), null);
17867 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
17870 var object = { 'a': '' },
17871 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
17873 lodashStable.each(paths, function(path) {
17876 var actual = func(0, path);
17877 assert.strictEqual(actual, 1);
17879 delete numberProto.a;
17882 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
17883 stringProto.replace.b = 1;
17885 var actual = func(object, path);
17886 assert.strictEqual(actual, 1);
17888 delete stringProto.replace.b;
17892 QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
17895 var object = { 'a': {} },
17896 values = empties.concat(true, new Date, 1, /x/, 'a');
17898 var expected = lodashStable.transform(values, function(result, value) {
17899 result.push(value, value, value, value);
17902 var actual = lodashStable.transform(values, function(result, value) {
17903 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
17905 func(object, path, value),
17906 func(null, path, value)
17911 assert.deepEqual(actual, expected);
17915 /*--------------------------------------------------------------------------*/
17917 QUnit.module('lodash.rest');
17920 function fn(a, b, c) {
17921 return slice.call(arguments);
17924 QUnit.test('should apply a rest parameter to `func`', function(assert) {
17927 var rest = _.rest(fn);
17928 assert.deepEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
17931 QUnit.test('should work with `start`', function(assert) {
17934 var rest = _.rest(fn, 1);
17935 assert.deepEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
17938 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
17941 var values = [-1, NaN, 'a'],
17942 expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
17944 var actual = lodashStable.map(values, function(value) {
17945 var rest = _.rest(fn, value);
17946 return rest(1, 2, 3, 4);
17949 assert.deepEqual(actual, expected);
17952 QUnit.test('should coerce `start` to an integer', function(assert) {
17955 var rest = _.rest(fn, 1.6);
17956 assert.deepEqual(rest(1, 2, 3), [1, [2, 3]]);
17959 QUnit.test('should use an empty array when `start` is not reached', function(assert) {
17962 var rest = _.rest(fn);
17963 assert.deepEqual(rest(1), [1, undefined, []]);
17966 QUnit.test('should work on functions with more than three parameters', function(assert) {
17969 var rest = _.rest(function(a, b, c, d) {
17970 return slice.call(arguments);
17973 assert.deepEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
17977 /*--------------------------------------------------------------------------*/
17979 QUnit.module('lodash.reverse');
17982 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
17983 smallArray = [0, 1, 2, null];
17985 QUnit.test('should reverse `array`', function(assert) {
17988 var array = [1, 2, 3],
17989 actual = _.reverse(array);
17991 assert.deepEqual(array, [3, 2, 1]);
17992 assert.strictEqual(actual, array);
17995 QUnit.test('should return the wrapped reversed `array`', function(assert) {
17999 lodashStable.times(2, function(index) {
18000 var array = (index ? largeArray : smallArray).slice(),
18001 clone = array.slice(),
18002 wrapped = _(array).reverse(),
18003 actual = wrapped.value();
18005 assert.ok(wrapped instanceof _);
18006 assert.strictEqual(actual, array);
18007 assert.deepEqual(actual, clone.slice().reverse());
18011 skipAssert(assert, 6);
18015 QUnit.test('should work in a lazy sequence', function(assert) {
18019 lodashStable.times(2, function(index) {
18020 var array = (index ? largeArray : smallArray).slice(),
18021 expected = array.slice(),
18022 actual = _(array).slice(1).reverse().value();
18024 assert.deepEqual(actual, expected.slice(1).reverse());
18025 assert.deepEqual(array, expected);
18029 skipAssert(assert, 4);
18033 QUnit.test('should be lazy when in a lazy sequence', function(assert) {
18038 'toString': function() {
18039 throw new Error('spy was revealed');
18043 var array = largeArray.concat(spy),
18044 expected = array.slice();
18047 var wrapped = _(array).slice(1).map(String).reverse(),
18048 actual = wrapped.last();
18051 assert.ok(wrapped instanceof _);
18052 assert.strictEqual(actual, '1');
18053 assert.deepEqual(array, expected);
18056 skipAssert(assert, 3);
18060 QUnit.test('should work in a hybrid sequence', function(assert) {
18064 lodashStable.times(2, function(index) {
18065 var clone = (index ? largeArray : smallArray).slice();
18067 lodashStable.each(['map', 'filter'], function(methodName) {
18068 var array = clone.slice(),
18069 expected = clone.slice(1, -1).reverse(),
18070 actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
18072 assert.deepEqual(actual, expected);
18074 array = clone.slice();
18075 actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
18077 assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
18082 skipAssert(assert, 8);
18086 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
18090 lodashStable.times(2, function(index) {
18091 var array = (index ? largeArray : smallArray).slice(),
18092 expected = array.slice().reverse(),
18093 wrapped = _(array).chain().reverse().head();
18095 assert.ok(wrapped instanceof _);
18096 assert.strictEqual(wrapped.value(), _.head(expected));
18097 assert.deepEqual(array, expected);
18101 skipAssert(assert, 6);
18106 /*--------------------------------------------------------------------------*/
18108 QUnit.module('round methods');
18110 lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
18111 var func = _[methodName],
18112 isCeil = methodName == 'ceil',
18113 isFloor = methodName == 'floor';
18115 QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
18118 var actual = func(4.006);
18119 assert.strictEqual(actual, isCeil ? 5 : 4);
18122 QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
18125 var actual = func(4.006, 0);
18126 assert.strictEqual(actual, isCeil ? 5 : 4);
18129 QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
18132 var actual = func(4.016, 2);
18133 assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
18135 actual = func(4.1, 2);
18136 assert.strictEqual(actual, 4.1);
18139 QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
18142 var actual = func(4160, -2);
18143 assert.strictEqual(actual, isFloor ? 4100 : 4200);
18146 QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
18149 var actual = func(4.006, NaN);
18150 assert.strictEqual(actual, isCeil ? 5 : 4);
18152 var expected = isFloor ? 4.01 : 4.02;
18154 actual = func(4.016, 2.6);
18155 assert.strictEqual(actual, expected);
18157 actual = func(4.016, '+2');
18158 assert.strictEqual(actual, expected);
18161 QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
18164 var actual = func(5e1, 2);
18165 assert.deepEqual(actual, 50);
18167 actual = func('5e', 1);
18168 assert.deepEqual(actual, NaN);
18170 actual = func('5e1e1', 1);
18171 assert.deepEqual(actual, NaN);
18174 QUnit.test('`_.' + methodName + '` should preserve sign of `0`', function(assert) {
18177 var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
18178 expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
18180 var actual = lodashStable.map(values, function(args) {
18181 return 1 / func.apply(undefined, args);
18184 assert.deepEqual(actual, expected);
18188 /*--------------------------------------------------------------------------*/
18190 QUnit.module('lodash.runInContext');
18193 QUnit.test('should not require a fully populated `context` object', function(assert) {
18196 if (!isModularize) {
18197 var lodash = _.runInContext({
18198 'setTimeout': function(callback) {
18204 lodash.delay(function() { pass = true; }, 32);
18208 skipAssert(assert);
18212 QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
18215 if (!isModularize) {
18216 lodashStable.times(2, _.uniqueId);
18218 var oldId = Number(_.uniqueId()),
18219 lodash = _.runInContext();
18221 assert.ok(_.uniqueId() > oldId);
18223 var id = lodash.uniqueId();
18224 assert.strictEqual(id, '1');
18225 assert.ok(id < oldId);
18228 skipAssert(assert, 3);
18233 /*--------------------------------------------------------------------------*/
18235 QUnit.module('lodash.sample');
18238 var array = [1, 2, 3];
18240 QUnit.test('should return a random element', function(assert) {
18243 var actual = _.sample(array);
18244 assert.ok(lodashStable.includes(array, actual));
18247 QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
18250 var expected = lodashStable.map(empties, alwaysUndefined);
18252 var actual = lodashStable.transform(empties, function(result, value) {
18254 result.push(_.sample(value));
18258 assert.deepEqual(actual, expected);
18261 QUnit.test('should sample an object', function(assert) {
18264 var object = { 'a': 1, 'b': 2, 'c': 3 },
18265 actual = _.sample(object);
18267 assert.ok(lodashStable.includes(array, actual));
18271 /*--------------------------------------------------------------------------*/
18273 QUnit.module('lodash.sampleSize');
18276 var array = [1, 2, 3];
18278 QUnit.test('should return an array of random elements', function(assert) {
18281 var actual = _.sampleSize(array, 2);
18282 assert.strictEqual(actual.length, 2);
18283 assert.deepEqual(lodashStable.difference(actual, array), []);
18286 QUnit.test('should contain elements of the collection', function(assert) {
18289 var actual = _.sampleSize(array, array.length);
18290 assert.deepEqual(actual.sort(), array);
18293 QUnit.test('should treat falsey `n` values as `0`', function(assert) {
18296 var expected = lodashStable.map(falsey, alwaysEmptyArray);
18298 var actual = lodashStable.map(falsey, function(n, index) {
18299 return index ? _.sampleSize([1], n) : _.sampleSize([1]);
18302 assert.deepEqual(actual, expected);
18305 QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
18308 lodashStable.each([0, -1, -Infinity], function(n) {
18309 assert.deepEqual(_.sampleSize(array, n), []);
18313 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
18316 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
18317 assert.deepEqual(_.sampleSize(array, n).sort(), array);
18321 QUnit.test('should coerce `n` to an integer', function(assert) {
18324 var actual = _.sampleSize(array, 1.6);
18325 assert.strictEqual(actual.length, 1);
18328 QUnit.test('should return an empty array for empty collections', function(assert) {
18331 var expected = lodashStable.map(empties, alwaysEmptyArray);
18333 var actual = lodashStable.transform(empties, function(result, value) {
18335 result.push(_.sampleSize(value, 1));
18339 assert.deepEqual(actual, expected);
18342 QUnit.test('should sample an object', function(assert) {
18345 var object = { 'a': 1, 'b': 2, 'c': 3 },
18346 actual = _.sampleSize(object, 2);
18348 assert.strictEqual(actual.length, 2);
18349 assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
18353 /*--------------------------------------------------------------------------*/
18355 QUnit.module('lodash.setWith');
18358 QUnit.test('should work with a `customizer` callback', function(assert) {
18361 var actual = _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, function(value) {
18362 if (!lodashStable.isObject(value)) {
18367 assert.deepEqual(actual, { '0': { '1': { '2': 3 }, 'length': 2 } });
18370 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
18373 var actual = _.setWith({}, 'a[0].b.c', 4, alwaysUndefined);
18374 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
18378 /*--------------------------------------------------------------------------*/
18380 QUnit.module('set methods');
18382 lodashStable.each(['set', 'setWith'], function(methodName) {
18383 var func = _[methodName];
18385 QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
18388 var object = { 'a': 1 };
18390 lodashStable.each(['a', ['a']], function(path) {
18391 var actual = func(object, path, 2);
18393 assert.strictEqual(actual, object);
18394 assert.strictEqual(object.a, 2);
18400 QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
18403 var object = { 'a': { 'b': { 'c': 3 } } };
18405 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
18406 var actual = func(object, path, 4);
18408 assert.strictEqual(actual, object);
18409 assert.strictEqual(object.a.b.c, 4);
18415 QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
18418 var object = { 'a.b.c': 3 };
18420 lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
18421 var actual = func(object, path, 4);
18423 assert.strictEqual(actual, object);
18424 assert.deepEqual(object, { 'a.b.c': 4 });
18426 object['a.b.c'] = 3;
18430 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
18433 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 3 } } };
18434 func(object, ['a', 'b', 'c'], 4);
18435 assert.strictEqual(object.a.b.c, 4);
18438 QUnit.test('`_.' + methodName + '` should ignore empty brackets', function(assert) {
18442 func(object, 'a[]', 1);
18443 assert.deepEqual(object, { 'a': 1 });
18446 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
18449 lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
18452 func(object, pair[0], 1);
18453 assert.deepEqual(object, index ? {} : { '': 1 });
18455 func(object, pair[1], 2);
18456 assert.deepEqual(object, { '': 2 });
18460 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
18463 var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
18466 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
18467 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
18470 lodashStable.each(paths, function(path) {
18471 func(object, path, 10);
18472 assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, 10);
18473 object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = 8;
18477 QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
18482 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
18483 var actual = func(object, path, 4);
18485 assert.strictEqual(actual, object);
18486 assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': 4 } }] });
18487 assert.notOk('0' in object.a);
18493 QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
18496 var values = [null, undefined],
18497 expected = [[null, null], [undefined, undefined]];
18499 var actual = lodashStable.map(values, function(value) {
18501 return [func(value, 'a.b', 1), func(value, ['a', 'b'], 1)];
18507 assert.deepEqual(actual, expected);
18510 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
18513 var object = { 'a': '' },
18514 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
18516 lodashStable.each(paths, function(path) {
18518 assert.strictEqual(0..a, 1);
18519 delete numberProto.a;
18522 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
18523 func(object, path, 1);
18524 assert.strictEqual(stringProto.replace.b, 1);
18525 delete stringProto.replace.b;
18529 QUnit.test('`_.' + methodName + '` should not error on paths over primitives in strict mode', function(assert) {
18536 lodashStable.each(['a', 'a.a.a'], function(path) {
18539 assert.strictEqual(0..a, 0);
18541 assert.ok(false, e.message);
18546 delete numberProto.a;
18549 QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
18554 func(object, ['1a', '2b', '3c'], 1);
18555 assert.deepEqual(object, { '1a': { '2b': { '3c': 1 } } });
18558 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
18561 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
18562 if (defineProperty) {
18566 defineProperty(object, 'a', {
18567 'enumerable': true,
18568 'configurable': true,
18569 'get': lodashStable.constant(value),
18570 'set': function() { pass = false; }
18573 func(object, 'a', value);
18577 skipAssert(assert);
18583 /*--------------------------------------------------------------------------*/
18585 QUnit.module('lodash.shuffle');
18588 var array = [1, 2, 3],
18589 object = { 'a': 1, 'b': 2, 'c': 3 };
18591 QUnit.test('should return a new array', function(assert) {
18594 assert.notStrictEqual(_.shuffle(array), array);
18597 QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
18600 assert.deepEqual(_.shuffle(array).sort(), array);
18601 assert.deepEqual(_.shuffle(object).sort(), array);
18604 QUnit.test('should shuffle small collections', function(assert) {
18607 var actual = lodashStable.times(1000, function(assert) {
18608 return _.shuffle([1, 2]);
18611 assert.deepEqual(lodashStable.sortBy(lodashStable.uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
18614 QUnit.test('should treat number values for `collection` as empty', function(assert) {
18617 assert.deepEqual(_.shuffle(1), []);
18621 /*--------------------------------------------------------------------------*/
18623 QUnit.module('lodash.size');
18626 var args = arguments,
18629 QUnit.test('should return the number of own enumerable properties of an object', function(assert) {
18632 assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
18635 QUnit.test('should return the length of an array', function(assert) {
18638 assert.strictEqual(_.size(array), 3);
18641 QUnit.test('should accept a falsey `object` argument', function(assert) {
18644 var expected = lodashStable.map(falsey, alwaysZero);
18646 var actual = lodashStable.map(falsey, function(object, index) {
18648 return index ? _.size(object) : _.size();
18652 assert.deepEqual(actual, expected);
18655 QUnit.test('should work with `arguments` objects', function(assert) {
18658 assert.strictEqual(_.size(args), 3);
18661 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
18664 function Foo(elements) { push.apply(this, elements); }
18665 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
18667 assert.strictEqual(_.size(new Foo(array)), 3);
18670 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
18673 assert.strictEqual(_.size({ 'length': -1 }), 1);
18676 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
18679 assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
18682 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
18685 assert.strictEqual(_.size({ 'length': '0' }), 1);
18689 /*--------------------------------------------------------------------------*/
18691 QUnit.module('lodash.slice');
18694 var array = [1, 2, 3];
18696 QUnit.test('should use a default `start` of `0` and a default `end` of `array.length`', function(assert) {
18699 var actual = _.slice(array);
18700 assert.deepEqual(actual, array);
18701 assert.notStrictEqual(actual, array);
18704 QUnit.test('should work with a positive `start`', function(assert) {
18707 assert.deepEqual(_.slice(array, 1), [2, 3]);
18708 assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
18711 QUnit.test('should work with a `start` >= `array.length`', function(assert) {
18714 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
18715 assert.deepEqual(_.slice(array, start), []);
18719 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
18722 var expected = lodashStable.map(falsey, lodashStable.constant(array));
18724 var actual = lodashStable.map(falsey, function(start) {
18725 return _.slice(array, start);
18728 assert.deepEqual(actual, expected);
18731 QUnit.test('should work with a negative `start`', function(assert) {
18734 assert.deepEqual(_.slice(array, -1), [3]);
18737 QUnit.test('should work with a negative `start` <= negative `array.length`', function(assert) {
18740 lodashStable.each([-3, -4, -Infinity], function(start) {
18741 assert.deepEqual(_.slice(array, start), array);
18745 QUnit.test('should work with `start` >= `end`', function(assert) {
18748 lodashStable.each([2, 3], function(start) {
18749 assert.deepEqual(_.slice(array, start, 2), []);
18753 QUnit.test('should work with a positive `end`', function(assert) {
18756 assert.deepEqual(_.slice(array, 0, 1), [1]);
18759 QUnit.test('should work with a `end` >= `array.length`', function(assert) {
18762 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
18763 assert.deepEqual(_.slice(array, 0, end), array);
18767 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
18770 var expected = lodashStable.map(falsey, function(value) {
18771 return value === undefined ? array : [];
18774 var actual = lodashStable.map(falsey, function(end) {
18775 return _.slice(array, 0, end);
18778 assert.deepEqual(actual, expected);
18781 QUnit.test('should work with a negative `end`', function(assert) {
18784 assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
18787 QUnit.test('should work with a negative `end` <= negative `array.length`', function(assert) {
18790 lodashStable.each([-3, -4, -Infinity], function(end) {
18791 assert.deepEqual(_.slice(array, 0, end), []);
18795 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
18798 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
18800 var actual = lodashStable.map(positions, function(pos) {
18801 return _.slice.apply(_, [array].concat(pos));
18804 assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
18807 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18810 var array = [[1], [2, 3]],
18811 actual = lodashStable.map(array, _.slice);
18813 assert.deepEqual(actual, array);
18814 assert.notStrictEqual(actual, array);
18817 QUnit.test('should work in a lazy sequence', function(assert) {
18821 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
18822 length = array.length,
18823 wrapped = _(array);
18825 lodashStable.each(['map', 'filter'], function(methodName) {
18826 assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
18827 assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
18828 assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
18829 assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
18831 assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
18832 assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
18833 assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
18834 assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
18836 assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
18837 assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
18838 assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
18840 assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
18841 assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
18843 assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
18844 assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
18845 assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
18846 assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
18847 assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
18848 assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
18852 skipAssert(assert, 38);
18857 /*--------------------------------------------------------------------------*/
18859 QUnit.module('lodash.some');
18862 QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
18865 assert.strictEqual(_.some([false, 1, ''], identity), true);
18866 assert.strictEqual(_.some([null, 'a', 0], identity), true);
18869 QUnit.test('should return `false` for empty collections', function(assert) {
18872 var expected = lodashStable.map(empties, alwaysFalse);
18874 var actual = lodashStable.map(empties, function(value) {
18876 return _.some(value, identity);
18880 assert.deepEqual(actual, expected);
18883 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
18888 assert.strictEqual(_.some([null, true, null], function(value) {
18893 assert.strictEqual(count, 2);
18896 QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
18899 assert.strictEqual(_.some([false, false, false], identity), false);
18900 assert.strictEqual(_.some([null, 0, ''], identity), false);
18903 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
18906 var values = [, null, undefined],
18907 expected = lodashStable.map(values, alwaysFalse);
18909 var actual = lodashStable.map(values, function(value, index) {
18910 var array = [0, 0];
18911 return index ? _.some(array, value) : _.some(array);
18914 assert.deepEqual(actual, expected);
18916 expected = lodashStable.map(values, alwaysTrue);
18917 actual = lodashStable.map(values, function(value, index) {
18918 var array = [0, 1];
18919 return index ? _.some(array, value) : _.some(array);
18922 assert.deepEqual(actual, expected);
18925 QUnit.test('should work with "_.property" shorthands', function(assert) {
18928 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
18929 assert.strictEqual(_.some(objects, 'a'), false);
18930 assert.strictEqual(_.some(objects, 'b'), true);
18933 QUnit.test('should work with "_.matches" shorthands', function(assert) {
18936 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
18937 assert.strictEqual(_.some(objects, { 'a': 0 }), true);
18938 assert.strictEqual(_.some(objects, { 'b': 2 }), false);
18941 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18944 var actual = lodashStable.map([[1]], _.some);
18945 assert.deepEqual(actual, [true]);
18949 /*--------------------------------------------------------------------------*/
18951 QUnit.module('lodash.sortBy');
18955 { 'a': 'x', 'b': 3 },
18956 { 'a': 'y', 'b': 4 },
18957 { 'a': 'x', 'b': 1 },
18958 { 'a': 'y', 'b': 2 }
18961 QUnit.test('should sort in ascending order by `iteratee`', function(assert) {
18964 var actual = lodashStable.map(_.sortBy(objects, function(object) {
18968 assert.deepEqual(actual, [1, 2, 3, 4]);
18971 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
18974 var array = [3, 2, 1],
18975 values = [, null, undefined],
18976 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
18978 var actual = lodashStable.map(values, function(value, index) {
18979 return index ? _.sortBy(array, value) : _.sortBy(array);
18982 assert.deepEqual(actual, expected);
18985 QUnit.test('should work with "_.property" shorthands', function(assert) {
18988 var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
18989 assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
18992 QUnit.test('should work with an object for `collection`', function(assert) {
18995 var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, Math.sin);
18996 assert.deepEqual(actual, [3, 1, 2]);
18999 QUnit.test('should move `null`, `undefined`, and `NaN` values to the end', function(assert) {
19002 var array = [NaN, undefined, null, 4, null, 1, undefined, 3, NaN, 2];
19003 assert.deepEqual(_.sortBy(array), [1, 2, 3, 4, null, null, undefined, undefined, NaN, NaN]);
19005 array = [NaN, undefined, null, 'd', null, 'a', undefined, 'c', NaN, 'b'];
19006 assert.deepEqual(_.sortBy(array), ['a', 'b', 'c', 'd', null, null, undefined, undefined, NaN, NaN]);
19009 QUnit.test('should treat number values for `collection` as empty', function(assert) {
19012 assert.deepEqual(_.sortBy(1), []);
19015 QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
19018 var actual = _.sortBy(objects, function(object) {
19019 var result = [object.a, object.b];
19020 result.toString = function() { return String(this[0]); };
19024 assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
19027 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19030 var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
19031 assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
19035 /*--------------------------------------------------------------------------*/
19037 QUnit.module('sortBy methods');
19039 lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
19040 var func = _[methodName];
19042 function Pair(a, b, c) {
19049 { 'a': 'x', 'b': 3 },
19050 { 'a': 'y', 'b': 4 },
19051 { 'a': 'x', 'b': 1 },
19052 { 'a': 'y', 'b': 2 }
19055 var stableArray = [
19056 new Pair(1, 1, 1), new Pair(1, 2, 1),
19057 new Pair(1, 1, 1), new Pair(1, 2, 1),
19058 new Pair(1, 3, 1), new Pair(1, 4, 1),
19059 new Pair(1, 5, 1), new Pair(1, 6, 1),
19060 new Pair(2, 1, 2), new Pair(2, 2, 2),
19061 new Pair(2, 3, 2), new Pair(2, 4, 2),
19062 new Pair(2, 5, 2), new Pair(2, 6, 2),
19063 new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
19064 new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
19065 new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
19068 var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
19070 QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
19073 var actual = func(objects, ['a', 'b']);
19074 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
19077 QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
19080 var actual = func(objects, ['a', function(object) { return object.b; }]);
19081 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
19084 QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
19087 lodashStable.each([stableArray, stableObject], function(value, index) {
19088 var actual = func(value, ['a', 'c']);
19089 assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
19093 QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
19097 var actual = func(objects.concat(null, undefined), ['a', 'b']);
19100 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
19103 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
19107 { 'a': 'x', '0': 3 },
19108 { 'a': 'y', '0': 4 },
19109 { 'a': 'x', '0': 1 },
19110 { 'a': 'y', '0': 2 }
19113 var funcs = [func, lodashStable.partialRight(func, 'bogus')];
19115 lodashStable.each(['a', 0, [0]], function(props, index) {
19116 var expected = lodashStable.map(funcs, lodashStable.constant(
19118 ? [objects[2], objects[3], objects[0], objects[1]]
19119 : [objects[0], objects[2], objects[1], objects[3]]
19122 var actual = lodashStable.map(funcs, function(func) {
19123 return lodashStable.reduce([props], func, objects);
19126 assert.deepEqual(actual, expected);
19131 /*--------------------------------------------------------------------------*/
19133 QUnit.module('sortedIndex methods');
19135 lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
19136 var func = _[methodName],
19137 isSortedIndex = methodName == 'sortedIndex';
19139 QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
19142 var array = [30, 50],
19143 values = [30, 40, 50],
19144 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
19146 var actual = lodashStable.map(values, function(value) {
19147 return func(array, value);
19150 assert.deepEqual(actual, expected);
19153 QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
19156 var array = ['a', 'c'],
19157 values = ['a', 'b', 'c'],
19158 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
19160 var actual = lodashStable.map(values, function(value) {
19161 return func(array, value);
19164 assert.deepEqual(actual, expected);
19167 QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument and a `value`', function(assert) {
19170 var expected = lodashStable.map(falsey, lodashStable.constant([0, 0, 0]));
19172 var actual = lodashStable.map(falsey, function(array) {
19173 return [func(array, 1), func(array, undefined), func(array, NaN)];
19176 assert.deepEqual(actual, expected);
19179 QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
19182 var expected = [1, '2', {}, null, undefined, NaN, NaN];
19184 lodashStable.each([
19185 [NaN, null, 1, '2', {}, NaN, undefined],
19186 ['2', null, 1, NaN, {}, NaN, undefined]
19187 ], function(array) {
19188 assert.deepEqual(_.sortBy(array), expected);
19189 assert.strictEqual(func(expected, 3), 2);
19190 assert.strictEqual(func(expected, null), isSortedIndex ? 3 : 4);
19191 assert.strictEqual(func(expected, undefined), isSortedIndex ? 4 : 5);
19192 assert.strictEqual(func(expected, NaN), isSortedIndex ? 5 : 7);
19197 /*--------------------------------------------------------------------------*/
19199 QUnit.module('sortedIndexBy methods');
19201 lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
19202 var func = _[methodName],
19203 isSortedIndexBy = methodName == 'sortedIndexBy';
19205 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
19210 func([30, 50], 40, function(assert) {
19211 args || (args = slice.call(arguments));
19214 assert.deepEqual(args, [40]);
19217 QUnit.test('`_.' + methodName + '` should work with "_.property" shorthands', function(assert) {
19220 var objects = [{ 'x': 30 }, { 'x': 50 }],
19221 actual = func(objects, { 'x': 40 }, 'x');
19223 assert.strictEqual(actual, 1);
19226 QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
19229 lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
19231 values = [MAX_ARRAY_LENGTH, NaN, undefined];
19233 array.length = length;
19235 lodashStable.each(values, function(value) {
19238 var actual = func(array, value, function(value) {
19243 var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
19245 : Math.min(length, MAX_ARRAY_INDEX);
19247 // Avoid false fails in older Firefox.
19248 if (array.length == length) {
19249 assert.ok(steps == 32 || steps == 33);
19250 assert.strictEqual(actual, expected);
19253 skipAssert(assert, 2);
19260 /*--------------------------------------------------------------------------*/
19262 QUnit.module('sortedIndexOf methods');
19264 lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
19265 var func = _[methodName],
19266 isSortedIndexOf = methodName == 'sortedIndexOf';
19268 QUnit.test('should perform a binary search', function(assert) {
19271 var sorted = [4, 4, 5, 5, 6, 6];
19272 assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
19276 /*--------------------------------------------------------------------------*/
19278 QUnit.module('lodash.sortedUniq');
19281 QUnit.test('should return unique values of a sorted array', function(assert) {
19284 var expected = [1, 2, 3];
19286 lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
19287 assert.deepEqual(_.sortedUniq(array), expected);
19292 /*--------------------------------------------------------------------------*/
19294 QUnit.module('lodash.split');
19297 QUnit.test('should support string split', function(assert) {
19300 var string = 'abcde';
19301 assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
19302 assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
19303 assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
19306 QUnit.test('should allow mixed string and array prototype methods', function(assert) {
19310 var wrapped = _('abc');
19311 assert.strictEqual(wrapped.split('b').join(','), 'a,c');
19314 skipAssert(assert);
19319 /*--------------------------------------------------------------------------*/
19321 QUnit.module('lodash.spread');
19324 function fn(a, b, c) {
19325 return slice.call(arguments);
19328 QUnit.test('should spread arguments to `func`', function(assert) {
19331 var spread = _.spread(fn);
19332 assert.deepEqual(spread([4, 2]), [4, 2]);
19335 QUnit.test('should accept a falsey `array` argument', function(assert) {
19338 var spread = _.spread(alwaysTrue),
19339 expected = lodashStable.map(falsey, alwaysTrue);
19341 var actual = lodashStable.map(falsey, function(array, index) {
19343 return index ? spread(array) : spread();
19347 assert.deepEqual(actual, expected);
19350 QUnit.test('should provide the correct `func` arguments', function(assert) {
19355 var spread = _.spread(function() {
19356 args = slice.call(arguments);
19359 spread([4, 2], 'ignored');
19360 assert.deepEqual(args, [4, 2]);
19363 QUnit.test('should work with `start`', function(assert) {
19366 var spread = _.spread(fn, 1);
19367 assert.deepEqual(spread(1, [2, 3, 4]), [1, 2, 3, 4]);
19370 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
19373 var values = [-1, NaN, 'a'],
19374 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
19376 var actual = lodashStable.map(values, function(value) {
19377 var spread = _.spread(fn, value);
19378 return spread([1, 2, 3, 4]);
19381 assert.deepEqual(actual, expected);
19384 QUnit.test('should coerce `start` to an integer', function(assert) {
19387 var spread = _.spread(fn, 1.6);
19388 assert.deepEqual(spread(1, [2, 3]), [1, 2, 3]);
19392 /*--------------------------------------------------------------------------*/
19394 QUnit.module('lodash.startsWith');
19397 var string = 'abc';
19399 QUnit.test('should return `true` if a string starts with `target`', function(assert) {
19402 assert.strictEqual(_.startsWith(string, 'a'), true);
19405 QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
19408 assert.strictEqual(_.startsWith(string, 'b'), false);
19411 QUnit.test('should work with a `position` argument', function(assert) {
19414 assert.strictEqual(_.startsWith(string, 'b', 1), true);
19417 QUnit.test('should work with `position` >= `string.length`', function(assert) {
19420 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
19421 assert.strictEqual(_.startsWith(string, 'a', position), false);
19425 QUnit.test('should treat falsey `position` values as `0`', function(assert) {
19428 var expected = lodashStable.map(falsey, alwaysTrue);
19430 var actual = lodashStable.map(falsey, function(position) {
19431 return _.startsWith(string, 'a', position);
19434 assert.deepEqual(actual, expected);
19437 QUnit.test('should treat a negative `position` as `0`', function(assert) {
19440 lodashStable.each([-1, -3, -Infinity], function(position) {
19441 assert.strictEqual(_.startsWith(string, 'a', position), true);
19442 assert.strictEqual(_.startsWith(string, 'b', position), false);
19446 QUnit.test('should coerce `position` to an integer', function(assert) {
19449 assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
19452 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
19455 assert.ok(lodashStable.every([-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
19456 return _.startsWith(string, '', position, true);
19461 /*--------------------------------------------------------------------------*/
19463 QUnit.module('lodash.startsWith and lodash.endsWith');
19465 lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
19466 var func = _[methodName],
19467 isStartsWith = methodName == 'startsWith';
19469 var string = 'abc',
19470 chr = isStartsWith ? 'a' : 'c';
19472 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
19475 assert.strictEqual(func(Object(string), chr), true);
19476 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
19479 QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
19482 assert.strictEqual(func(string, Object(chr)), true);
19483 assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
19486 QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
19489 var position = isStartsWith ? 1 : 2;
19490 assert.strictEqual(func(string, 'b', Object(position)), true);
19491 assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
19495 /*--------------------------------------------------------------------------*/
19497 QUnit.module('lodash.subtract');
19500 QUnit.test('should subtract two numbers', function(assert) {
19503 assert.strictEqual(_.subtract(6, 4), 2);
19504 assert.strictEqual(_.subtract(-6, 4), -10);
19505 assert.strictEqual(_.subtract(-6, -4), -2);
19508 QUnit.test('should return `0` when no arguments are given', function(assert) {
19511 assert.strictEqual(_.subtract(), 0);
19514 QUnit.test('should coerce arguments only numbers', function(assert) {
19517 assert.strictEqual(_.subtract('6', '4'), 2);
19518 assert.deepEqual(_.subtract('x', 'y'), NaN);
19521 QUnit.test('should work with only a `minuend` or `subtrahend`', function(assert) {
19524 assert.strictEqual(_.subtract(6), 6);
19525 assert.strictEqual(_.subtract(6, undefined), 6);
19526 assert.strictEqual(_.subtract(undefined, 4), 4);
19529 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
19533 assert.strictEqual(_(1).subtract(2), -1);
19536 skipAssert(assert);
19540 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
19544 assert.ok(_(1).chain().subtract(2) instanceof _);
19547 skipAssert(assert);
19552 /*--------------------------------------------------------------------------*/
19554 QUnit.module('lodash.sum');
19557 var array = [6, 4, 2];
19559 QUnit.test('should return the sum of an array of numbers', function(assert) {
19562 assert.strictEqual(_.sum(array), 12);
19565 QUnit.test('should return `0` when passing empty `array` values', function(assert) {
19568 var expected = lodashStable.map(empties, alwaysZero),
19569 actual = lodashStable.map(empties, _.sum);
19571 assert.deepEqual(actual, expected);
19574 QUnit.test('should skip `undefined` values', function(assert) {
19577 assert.strictEqual(_.sum([1, undefined]), 1);
19580 QUnit.test('should not skip `NaN` values', function(assert) {
19583 assert.deepEqual(_.sum([1, NaN]), NaN);
19586 QUnit.test('should not coerce values to numbers', function(assert) {
19589 assert.strictEqual(_.sum(['1', '2']), '12');
19593 /*--------------------------------------------------------------------------*/
19595 QUnit.module('lodash.sumBy');
19598 var array = [6, 4, 2],
19599 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
19601 QUnit.test('should work with an `iteratee` argument', function(assert) {
19604 var actual = _.sumBy(objects, function(object) {
19608 assert.deepEqual(actual, 6);
19611 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
19616 _.sumBy(array, function() {
19617 args || (args = slice.call(arguments));
19620 assert.deepEqual(args, [6]);
19623 QUnit.test('should work with "_.property" shorthands', function(assert) {
19626 var arrays = [[2], [3], [1]];
19627 assert.strictEqual(_.sumBy(arrays, 0), 6);
19628 assert.strictEqual(_.sumBy(objects, 'a'), 6);
19632 /*--------------------------------------------------------------------------*/
19634 QUnit.module('lodash.tail');
19637 var array = [1, 2, 3];
19639 QUnit.test('should accept a falsey `array` argument', function(assert) {
19642 var expected = lodashStable.map(falsey, alwaysEmptyArray);
19644 var actual = lodashStable.map(falsey, function(array, index) {
19646 return index ? _.tail(array) : _.tail();
19650 assert.deepEqual(actual, expected);
19653 QUnit.test('should exclude the first element', function(assert) {
19656 assert.deepEqual(_.tail(array), [2, 3]);
19659 QUnit.test('should return an empty when querying empty arrays', function(assert) {
19662 assert.deepEqual(_.tail([]), []);
19665 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19668 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
19669 actual = lodashStable.map(array, _.tail);
19671 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
19674 QUnit.test('should work in a lazy sequence', function(assert) {
19678 var array = lodashStable.range(LARGE_ARRAY_SIZE),
19681 var actual = _(array).tail().filter(function(value) {
19682 values.push(value);
19687 assert.deepEqual(actual, []);
19688 assert.deepEqual(values, array.slice(1));
19692 actual = _(array).filter(function(value) {
19693 values.push(value);
19694 return isEven(value);
19699 assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
19700 assert.deepEqual(values, array);
19703 skipAssert(assert, 4);
19707 QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
19711 var array = lodashStable.range(LARGE_ARRAY_SIZE),
19712 iteratee = function() { pass = false; },
19714 actual = _(array).slice(0, 1).tail().map(iteratee).value();
19717 assert.deepEqual(actual, []);
19720 actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
19723 assert.deepEqual(actual, []);
19726 skipAssert(assert, 4);
19731 /*--------------------------------------------------------------------------*/
19733 QUnit.module('lodash.take');
19736 var array = [1, 2, 3];
19738 QUnit.test('should take the first two elements', function(assert) {
19741 assert.deepEqual(_.take(array, 2), [1, 2]);
19744 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
19747 var expected = lodashStable.map(falsey, function(value) {
19748 return value === undefined ? [1] : [];
19751 var actual = lodashStable.map(falsey, function(n) {
19752 return _.take(array, n);
19755 assert.deepEqual(actual, expected);
19758 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
19761 lodashStable.each([0, -1, -Infinity], function(n) {
19762 assert.deepEqual(_.take(array, n), []);
19766 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
19769 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
19770 assert.deepEqual(_.take(array, n), array);
19774 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19777 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
19778 actual = lodashStable.map(array, _.take);
19780 assert.deepEqual(actual, [[1], [4], [7]]);
19783 QUnit.test('should work in a lazy sequence', function(assert) {
19787 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
19788 predicate = function(value) { values.push(value); return isEven(value); },
19790 actual = _(array).take(2).take().value();
19792 assert.deepEqual(actual, _.take(_.take(array, 2)));
19794 actual = _(array).filter(predicate).take(2).take().value();
19795 assert.deepEqual(values, [1, 2]);
19796 assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
19798 actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
19799 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
19803 actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
19804 assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
19805 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
19808 skipAssert(assert, 6);
19813 /*--------------------------------------------------------------------------*/
19815 QUnit.module('lodash.takeRight');
19818 var array = [1, 2, 3];
19820 QUnit.test('should take the last two elements', function(assert) {
19823 assert.deepEqual(_.takeRight(array, 2), [2, 3]);
19826 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
19829 var expected = lodashStable.map(falsey, function(value) {
19830 return value === undefined ? [3] : [];
19833 var actual = lodashStable.map(falsey, function(n) {
19834 return _.takeRight(array, n);
19837 assert.deepEqual(actual, expected);
19840 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
19843 lodashStable.each([0, -1, -Infinity], function(n) {
19844 assert.deepEqual(_.takeRight(array, n), []);
19848 QUnit.test('should return all elements when `n` >= `array.length`', function(assert) {
19851 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
19852 assert.deepEqual(_.takeRight(array, n), array);
19856 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19859 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
19860 actual = lodashStable.map(array, _.takeRight);
19862 assert.deepEqual(actual, [[3], [6], [9]]);
19865 QUnit.test('should work in a lazy sequence', function(assert) {
19869 var array = lodashStable.range(LARGE_ARRAY_SIZE),
19870 predicate = function(value) { values.push(value); return isEven(value); },
19872 actual = _(array).takeRight(2).takeRight().value();
19874 assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
19876 actual = _(array).filter(predicate).takeRight(2).takeRight().value();
19877 assert.deepEqual(values, array);
19878 assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
19880 actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
19881 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
19885 actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
19886 assert.deepEqual(values, array);
19887 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
19890 skipAssert(assert, 6);
19895 /*--------------------------------------------------------------------------*/
19897 QUnit.module('lodash.takeRightWhile');
19900 var array = [1, 2, 3, 4];
19903 { 'a': 0, 'b': 0 },
19904 { 'a': 1, 'b': 1 },
19908 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
19911 var actual = _.takeRightWhile(array, function(n) {
19915 assert.deepEqual(actual, [3, 4]);
19918 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
19923 _.takeRightWhile(array, function() {
19924 args = slice.call(arguments);
19927 assert.deepEqual(args, [4, 3, array]);
19930 QUnit.test('should work with "_.matches" shorthands', function(assert) {
19933 assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
19936 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
19939 assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
19942 QUnit.test('should work with "_.property" shorthands', function(assert) {
19945 assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
19948 QUnit.test('should work in a lazy sequence', function(assert) {
19952 var array = lodashStable.range(LARGE_ARRAY_SIZE),
19953 predicate = function(n) { return n > 2; },
19954 expected = _.takeRightWhile(array, predicate),
19955 wrapped = _(array).takeRightWhile(predicate);
19957 assert.deepEqual(wrapped.value(), expected);
19958 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
19959 assert.strictEqual(wrapped.last(), _.last(expected));
19962 skipAssert(assert, 3);
19966 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
19971 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
19972 expected = [square(LARGE_ARRAY_SIZE), LARGE_ARRAY_SIZE - 1, lodashStable.map(array.slice(1), square)];
19974 _(array).slice(1).takeRightWhile(function(value, index, array) {
19975 args = slice.call(arguments);
19978 assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
19980 _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
19981 args = slice.call(arguments);
19984 assert.deepEqual(args, expected);
19986 _(array).slice(1).map(square).takeRightWhile(function(value, index) {
19987 args = slice.call(arguments);
19990 assert.deepEqual(args, expected);
19992 _(array).slice(1).map(square).takeRightWhile(function(index) {
19993 args = slice.call(arguments);
19996 assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
19998 _(array).slice(1).map(square).takeRightWhile(function() {
19999 args = slice.call(arguments);
20002 assert.deepEqual(args, expected);
20005 skipAssert(assert, 5);
20010 /*--------------------------------------------------------------------------*/
20012 QUnit.module('lodash.takeWhile');
20015 var array = [1, 2, 3, 4];
20018 { 'a': 2, 'b': 2 },
20019 { 'a': 1, 'b': 1 },
20023 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
20026 var actual = _.takeWhile(array, function(n) {
20030 assert.deepEqual(actual, [1, 2]);
20033 QUnit.test('should provide the correct `predicate` arguments', function(assert) {
20038 _.takeWhile(array, function() {
20039 args = slice.call(arguments);
20042 assert.deepEqual(args, [1, 0, array]);
20045 QUnit.test('should work with "_.matches" shorthands', function(assert) {
20048 assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
20051 QUnit.test('should work with "_.matchesProperty" shorthands', function(assert) {
20054 assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
20056 QUnit.test('should work with "_.property" shorthands', function(assert) {
20059 assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
20062 QUnit.test('should work in a lazy sequence', function(assert) {
20066 var array = lodashStable.range(LARGE_ARRAY_SIZE),
20067 predicate = function(n) { return n < 3; },
20068 expected = _.takeWhile(array, predicate),
20069 wrapped = _(array).takeWhile(predicate);
20071 assert.deepEqual(wrapped.value(), expected);
20072 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
20073 assert.strictEqual(wrapped.last(), _.last(expected));
20076 skipAssert(assert, 3);
20080 QUnit.test('should work in a lazy sequence with `take`', function(assert) {
20084 var array = lodashStable.range(LARGE_ARRAY_SIZE);
20086 var actual = _(array)
20087 .takeWhile(function(n) { return n < 4; })
20089 .takeWhile(function(n) { return n == 0; })
20092 assert.deepEqual(actual, [0]);
20095 skipAssert(assert);
20099 QUnit.test('should provide the correct `predicate` arguments in a lazy sequence', function(assert) {
20104 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
20105 expected = [1, 0, lodashStable.map(array.slice(1), square)];
20107 _(array).slice(1).takeWhile(function(value, index, array) {
20108 args = slice.call(arguments);
20111 assert.deepEqual(args, [1, 0, array.slice(1)]);
20113 _(array).slice(1).map(square).takeWhile(function(value, index, array) {
20114 args = slice.call(arguments);
20117 assert.deepEqual(args, expected);
20119 _(array).slice(1).map(square).takeWhile(function(value, index) {
20120 args = slice.call(arguments);
20123 assert.deepEqual(args, expected);
20125 _(array).slice(1).map(square).takeWhile(function(value) {
20126 args = slice.call(arguments);
20129 assert.deepEqual(args, [1]);
20131 _(array).slice(1).map(square).takeWhile(function() {
20132 args = slice.call(arguments);
20135 assert.deepEqual(args, expected);
20138 skipAssert(assert, 5);
20143 /*--------------------------------------------------------------------------*/
20145 QUnit.module('lodash.tap');
20148 QUnit.test('should intercept and return the given value', function(assert) {
20155 var actual = _.tap(array, function(value) {
20156 intercepted = value;
20159 assert.strictEqual(actual, array);
20160 assert.strictEqual(intercepted, array);
20163 skipAssert(assert, 2);
20167 QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
20174 var wrapped = _(array).tap(function(value) {
20175 intercepted = value;
20179 assert.ok(wrapped instanceof _);
20182 assert.strictEqual(intercepted, array);
20185 skipAssert(assert, 2);
20190 /*--------------------------------------------------------------------------*/
20192 QUnit.module('lodash.template');
20195 QUnit.test('should escape values in "escape" delimiters', function(assert) {
20198 var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
20199 expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'`\/</p>')),
20200 data = { 'value': '&<>"\'`\/' };
20202 var actual = lodashStable.map(strings, function(string) {
20203 return _.template(string)(data);
20206 assert.deepEqual(actual, expected);
20209 QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
20212 var compiled = _.template('<%= typeof __e %>');
20213 assert.strictEqual(compiled({}), 'undefined');
20216 QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
20219 var compiled = _.template(
20221 for (var key in collection) {\
20222 %><li><%= collection[key] %></li><%\
20226 var data = { 'collection': { 'a': 'A', 'b': 'B' } },
20227 actual = compiled(data);
20229 assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
20232 QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
20235 var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
20236 data = { 'value': true };
20238 assert.strictEqual(compiled(data), 'yap');
20241 QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
20244 var compiled = _.template('<% var b = a; %><%= b.value %>'),
20245 data = { 'a': { 'value': 1 } };
20247 assert.strictEqual(compiled(data), '1');
20250 QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
20253 var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
20254 expected = lodashStable.map(strings, lodashStable.constant('ABC')),
20255 data = { 'a': 'A' };
20257 var actual = lodashStable.map(strings, function(string) {
20258 return _.template(string)(data);
20261 assert.deepEqual(actual, expected);
20264 QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
20267 var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
20268 data = { 'a': true };
20270 assert.strictEqual(compiled(data), 'a="A"');
20273 QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
20276 var compiled = _.template('<%= value ? value : "b" %>'),
20277 data = { 'value': 'a' };
20279 assert.strictEqual(compiled(data), 'a');
20282 QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
20285 var compiled = _.template('<%= typeof Math.abs %>');
20288 var actual = compiled();
20291 assert.strictEqual(actual, 'function');
20294 QUnit.test('should support complex "interpolate" delimiters', function(assert) {
20297 lodashStable.forOwn({
20298 '<%= a + b %>': '3',
20299 '<%= b - a %>': '1',
20300 '<%= a = b %>': '2',
20301 '<%= !a %>': 'false',
20303 '<%= a * b %>': '2',
20304 '<%= a / b %>': '0.5',
20305 '<%= a % b %>': '1',
20306 '<%= a >> b %>': '0',
20307 '<%= a << b %>': '4',
20308 '<%= a & b %>': '0',
20309 '<%= a ^ b %>': '3',
20310 '<%= a | b %>': '3',
20311 '<%= {}.toString.call(0) %>': numberTag,
20312 '<%= a.toFixed(2) %>': '1.00',
20313 '<%= obj["a"] %>': '1',
20314 '<%= delete a %>': 'true',
20315 '<%= "a" in obj %>': 'true',
20316 '<%= obj instanceof Object %>': 'true',
20317 '<%= new Boolean %>': 'false',
20318 '<%= typeof a %>': 'number',
20319 '<%= void a %>': ''
20321 function(value, key) {
20322 var compiled = _.template(key),
20323 data = { 'a': 1, 'b': 2 };
20325 assert.strictEqual(compiled(data), value, key);
20329 QUnit.test('should support ES6 template delimiters', function(assert) {
20332 var data = { 'value': 2 };
20333 assert.strictEqual(_.template('1${value}3')(data), '123');
20334 assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
20337 QUnit.test('should support the "imports" option', function(assert) {
20340 var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
20341 assert.strictEqual(compiled({}), '1');
20344 QUnit.test('should support the "variable" options', function(assert) {
20347 var compiled = _.template(
20348 '<% _.each( data.a, function( value ) { %>' +
20349 '<%= value.valueOf() %>' +
20350 '<% }) %>', { 'variable': 'data' }
20353 var data = { 'a': [1, 2, 3] };
20356 assert.strictEqual(compiled(data), '123');
20358 assert.ok(false, e.message);
20362 QUnit.test('should support custom delimiters', function(assert) {
20365 lodashStable.times(2, function(index) {
20366 var settingsClone = lodashStable.clone(_.templateSettings);
20368 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
20369 'escape': /\{\{-([\s\S]+?)\}\}/g,
20370 'evaluate': /\{\{([\s\S]+?)\}\}/g,
20371 'interpolate': /\{\{=([\s\S]+?)\}\}/g
20374 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
20375 compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
20376 data = { 'collection': ['a & A', 'b & B'] };
20378 assert.strictEqual(compiled(data), expected);
20379 lodashStable.assign(_.templateSettings, settingsClone);
20383 QUnit.test('should support custom delimiters containing special characters', function(assert) {
20386 lodashStable.times(2, function(index) {
20387 var settingsClone = lodashStable.clone(_.templateSettings);
20389 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
20390 'escape': /<\?-([\s\S]+?)\?>/g,
20391 'evaluate': /<\?([\s\S]+?)\?>/g,
20392 'interpolate': /<\?=([\s\S]+?)\?>/g
20395 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
20396 compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
20397 data = { 'collection': ['a & A', 'b & B'] };
20399 assert.strictEqual(compiled(data), expected);
20400 lodashStable.assign(_.templateSettings, settingsClone);
20404 QUnit.test('should use a `with` statement by default', function(assert) {
20407 var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
20408 actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
20410 assert.strictEqual(actual, '1b012');
20413 QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
20416 var lodash = _.templateSettings.imports._,
20417 settingsClone = lodashStable.clone(lodash.templateSettings);
20419 lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
20420 'interpolate': /\{\{=([\s\S]+?)\}\}/g
20423 var compiled = _.template('{{= a }}');
20424 assert.strictEqual(compiled({ 'a': 1 }), '1');
20426 if (settingsClone) {
20427 lodashStable.assign(lodash.templateSettings, settingsClone);
20429 delete lodash.templateSettings;
20433 QUnit.test('should fallback to `_.templateSettings`', function(assert) {
20436 var lodash = _.templateSettings.imports._,
20437 delimiter = _.templateSettings.interpolate;
20439 _.templateSettings.imports._ = { 'escape': lodashStable.escape };
20440 _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
20442 var compiled = _.template('{{= a }}');
20443 assert.strictEqual(compiled({ 'a': 1 }), '1');
20445 _.templateSettings.imports._ = lodash;
20446 _.templateSettings.interpolate = delimiter;
20449 QUnit.test('should ignore `null` delimiters', function(assert) {
20453 'escape': /\{\{-([\s\S]+?)\}\}/g,
20454 'evaluate': /\{\{([\s\S]+?)\}\}/g,
20455 'interpolate': /\{\{=([\s\S]+?)\}\}/g
20458 lodashStable.forOwn({
20459 'escape': '{{- a }}',
20460 'evaluate': '{{ print(a) }}',
20461 'interpolate': '{{= a }}'
20463 function(value, key) {
20464 var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
20465 settings[key] = delimiter[key];
20467 var expected = '1 <%- a %> <% print(a) %> <%= a %>',
20468 compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
20471 assert.strictEqual(compiled(data), expected);
20475 QUnit.test('should work without delimiters', function(assert) {
20478 var expected = 'abc';
20479 assert.strictEqual(_.template(expected)({}), expected);
20482 QUnit.test('should work with `this` references', function(assert) {
20485 var compiled = _.template('a<%= this.String("b") %>c');
20486 assert.strictEqual(compiled(), 'abc');
20488 var object = { 'b': 'B' };
20489 object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
20490 assert.strictEqual(object.compiled(), 'ABC');
20493 QUnit.test('should work with backslashes', function(assert) {
20496 var compiled = _.template('<%= a %> \\b'),
20497 data = { 'a': 'A' };
20499 assert.strictEqual(compiled(data), 'A \\b');
20502 QUnit.test('should work with escaped characters in string literals', function(assert) {
20505 var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
20506 assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
20508 var data = { 'a': 'A' };
20509 compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
20510 assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
20513 QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
20516 var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
20517 assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
20520 QUnit.test('should work with statements containing quotes', function(assert) {
20523 var compiled = _.template("<%\
20524 if (a == 'A' || a == \"a\") {\
20529 var data = { 'a': 'A' };
20530 assert.strictEqual(compiled(data), "'a',\"A\"");
20533 QUnit.test('should work with templates containing newlines and comments', function(assert) {
20536 var compiled = _.template('<%\n\
20537 // A code comment.\n\
20538 if (value) { value += 3; }\n\
20539 %><p><%= value %></p>'
20542 assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
20545 QUnit.test('should not error with IE conditional comments enabled (test with development build)', function(assert) {
20548 var compiled = _.template(''),
20560 QUnit.test('should tokenize delimiters', function(assert) {
20563 var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
20564 data = { 'type': 1 };
20566 assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
20569 QUnit.test('should evaluate delimiters once', function(assert) {
20573 compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
20574 data = { 'func': function(value) { actual.push(value); } };
20577 assert.deepEqual(actual, ['a', 'b', 'c']);
20580 QUnit.test('should match delimiters before escaping text', function(assert) {
20583 var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
20584 assert.strictEqual(compiled(), '<<\n a \n>>');
20587 QUnit.test('should resolve nullish values to an empty string', function(assert) {
20590 var compiled = _.template('<%= a %><%- a %>'),
20591 data = { 'a': null };
20593 assert.strictEqual(compiled(data), '');
20595 data = { 'a': undefined };
20596 assert.strictEqual(compiled(data), '');
20598 data = { 'a': {} };
20599 compiled = _.template('<%= a.b %><%- a.b %>');
20600 assert.strictEqual(compiled(data), '');
20603 QUnit.test('should return an empty string for empty values', function(assert) {
20606 var values = [, null, undefined, ''],
20607 expected = lodashStable.map(values, alwaysEmptyString),
20610 var actual = lodashStable.map(values, function(value, index) {
20611 var compiled = index ? _.template(value) : _.template();
20612 return compiled(data);
20615 assert.deepEqual(actual, expected);
20618 QUnit.test('should parse delimiters without newlines', function(assert) {
20621 var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
20622 compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
20623 data = { 'value': true };
20625 assert.strictEqual(compiled(data), expected);
20628 QUnit.test('should support recursive calls', function(assert) {
20631 var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
20632 data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
20634 assert.strictEqual(compiled(data), 'AB');
20637 QUnit.test('should coerce `text` argument to a string', function(assert) {
20640 var object = { 'toString': lodashStable.constant('<%= a %>') },
20643 assert.strictEqual(_.template(object)(data), '1');
20646 QUnit.test('should not modify the `options` object', function(assert) {
20650 _.template('', options);
20651 assert.deepEqual(options, {});
20654 QUnit.test('should not modify `_.templateSettings` when `options` are given', function(assert) {
20657 var data = { 'a': 1 };
20659 assert.notOk('a' in _.templateSettings);
20660 _.template('', {}, data);
20661 assert.notOk('a' in _.templateSettings);
20663 delete _.templateSettings.a;
20666 QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
20676 assert.ok(pass, '`data` value');
20681 _.template('', 1)(1);
20685 assert.ok(pass, '`options` value');
20688 QUnit.test('should expose the source on compiled templates', function(assert) {
20691 var compiled = _.template('x'),
20692 values = [String(compiled), compiled.source],
20693 expected = lodashStable.map(values, alwaysTrue);
20695 var actual = lodashStable.map(values, function(value) {
20696 return lodashStable.includes(value, '__p');
20699 assert.deepEqual(actual, expected);
20702 QUnit.test('should expose the source on SyntaxErrors', function(assert) {
20706 _.template('<% if x %>');
20708 var source = e.source;
20710 assert.ok(lodashStable.includes(source, '__p'));
20713 QUnit.test('should not include sourceURLs in the source', function(assert) {
20716 var options = { 'sourceURL': '/a/b/c' },
20717 compiled = _.template('x', options),
20718 values = [compiled.source, undefined];
20721 _.template('<% if x %>', options);
20723 values[1] = e.source;
20725 var expected = lodashStable.map(values, alwaysFalse);
20727 var actual = lodashStable.map(values, function(value) {
20728 return lodashStable.includes(value, 'sourceURL');
20731 assert.deepEqual(actual, expected);
20734 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20737 var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
20738 compiles = lodashStable.map(array, _.template),
20739 data = { 'a': 'one', 'b': '`two`', 'c': 'three' };
20741 var actual = lodashStable.map(compiles, function(compiled) {
20742 return compiled(data);
20745 assert.deepEqual(actual, ['one', '`two`', 'three']);
20749 /*--------------------------------------------------------------------------*/
20751 QUnit.module('lodash.truncate');
20754 var string = 'hi-diddly-ho there, neighborino';
20756 QUnit.test('should use a default `length` of `30`', function(assert) {
20759 assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
20762 QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
20765 assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
20766 assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
20769 QUnit.test('should truncate string the given length', function(assert) {
20772 assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
20775 QUnit.test('should support a `omission` option', function(assert) {
20778 assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
20781 QUnit.test('should support a `length` option', function(assert) {
20784 assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
20787 QUnit.test('should support a `separator` option', function(assert) {
20790 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
20791 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
20792 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
20795 QUnit.test('should treat negative `length` as `0`', function(assert) {
20798 lodashStable.each([0, -2], function(length) {
20799 assert.strictEqual(_.truncate(string, { 'length': length }), '...');
20803 QUnit.test('should coerce `length` to an integer', function(assert) {
20806 lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
20807 var actual = index > 1 ? 'h...' : '...';
20808 assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
20812 QUnit.test('should coerce `string` to a string', function(assert) {
20815 assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
20816 assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
20819 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20822 var actual = lodashStable.map([string, string, string], _.truncate),
20823 truncated = 'hi-diddly-ho there, neighbo...';
20825 assert.deepEqual(actual, [truncated, truncated, truncated]);
20829 /*--------------------------------------------------------------------------*/
20831 QUnit.module('lodash.throttle');
20834 QUnit.test('should throttle a function', function(assert) {
20837 var done = assert.async();
20840 throttled = _.throttle(function() { callCount++; }, 32);
20846 var lastCount = callCount;
20847 assert.ok(callCount > 0);
20849 setTimeout(function() {
20850 assert.ok(callCount > lastCount);
20855 QUnit.test('subsequent calls should return the result of the first call', function(assert) {
20858 var done = assert.async();
20860 var throttled = _.throttle(identity, 32),
20861 result = [throttled('a'), throttled('b')];
20863 assert.deepEqual(result, ['a', 'a']);
20865 setTimeout(function() {
20866 var result = [throttled('x'), throttled('y')];
20867 assert.notEqual(result[0], 'a');
20868 assert.notStrictEqual(result[0], undefined);
20870 assert.notEqual(result[1], 'y');
20871 assert.notStrictEqual(result[1], undefined);
20876 QUnit.test('should clear timeout when `func` is called', function(assert) {
20879 var done = assert.async();
20881 if (!isModularize) {
20885 var getTime = function() {
20886 return ++dateCount == 5
20891 var lodash = _.runInContext(lodashStable.assign({}, root, {
20892 'Date': lodashStable.assign(function() {
20893 return { 'getTime': getTime };
20899 var throttled = lodash.throttle(function() {
20907 setTimeout(function() {
20908 assert.strictEqual(callCount, 2);
20913 skipAssert(assert);
20918 QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
20921 var done = assert.async();
20924 throttled = _.throttle(function() { callCount++; }, 32);
20927 assert.strictEqual(callCount, 1);
20929 setTimeout(function() {
20930 assert.strictEqual(callCount, 1);
20935 lodashStable.times(2, function(index) {
20936 QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
20939 var done = assert.async();
20942 limit = (argv || isPhantom) ? 1000 : 320,
20943 options = index ? { 'leading': false } : {};
20945 var throttled = _.throttle(function() {
20949 var start = +new Date;
20950 while ((new Date - start) < limit) {
20953 var actual = callCount > 1;
20955 setTimeout(function() {
20962 QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
20965 var done = assert.async();
20969 var throttled = _.throttle(function() {
20971 }, 128, { 'leading': false });
20975 setTimeout(function() {
20976 assert.strictEqual(callCount, 1);
20980 setTimeout(function() {
20981 assert.strictEqual(callCount, 2);
20986 QUnit.test('should apply default options', function(assert) {
20989 var done = assert.async();
20993 var throttled = _.throttle(function(value) {
20998 assert.strictEqual(throttled('a'), 'a');
20999 assert.strictEqual(throttled('b'), 'a');
21001 setTimeout(function() {
21002 assert.strictEqual(callCount, 2);
21007 QUnit.test('should support a `leading` option', function(assert) {
21010 var withLeading = _.throttle(identity, 32, { 'leading': true });
21011 assert.strictEqual(withLeading('a'), 'a');
21013 var withoutLeading = _.throttle(identity, 32, { 'leading': false });
21014 assert.strictEqual(withoutLeading('a'), undefined);
21017 QUnit.test('should support a `trailing` option', function(assert) {
21020 var done = assert.async();
21025 var withTrailing = _.throttle(function(value) {
21028 }, 64, { 'trailing': true });
21030 var withoutTrailing = _.throttle(function(value) {
21033 }, 64, { 'trailing': false });
21035 assert.strictEqual(withTrailing('a'), 'a');
21036 assert.strictEqual(withTrailing('b'), 'a');
21038 assert.strictEqual(withoutTrailing('a'), 'a');
21039 assert.strictEqual(withoutTrailing('b'), 'a');
21041 setTimeout(function() {
21042 assert.strictEqual(withCount, 2);
21043 assert.strictEqual(withoutCount, 1);
21048 QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
21051 var done = assert.async();
21055 var throttled = _.throttle(function() {
21057 }, 64, { 'trailing': false });
21062 setTimeout(function() {
21067 setTimeout(function() {
21068 assert.ok(callCount > 1);
21074 /*--------------------------------------------------------------------------*/
21076 QUnit.module('lodash.debounce and lodash.throttle');
21078 lodashStable.each(['debounce', 'throttle'], function(methodName) {
21079 var func = _[methodName],
21080 isDebounce = methodName == 'debounce';
21082 QUnit.test('_.' + methodName + ' should not error for non-object `options` values', function(assert) {
21095 QUnit.test('_.' + methodName + ' should use a default `wait` of `0`', function(assert) {
21098 var done = assert.async();
21102 var funced = func(function() {
21108 setTimeout(function() {
21110 assert.strictEqual(callCount, isDebounce ? 1 : 2);
21115 QUnit.test('_.' + methodName + ' should invoke `func` with the correct `this` binding', function(assert) {
21118 var done = assert.async();
21121 'funced': func(function() { actual.push(this); }, 32)
21125 expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
21131 setTimeout(function() {
21132 assert.deepEqual(actual, expected);
21137 QUnit.test('_.' + methodName + ' supports recursive calls', function(assert) {
21140 var done = assert.async();
21143 args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
21144 expected = args.slice(),
21145 queue = args.slice();
21147 var funced = func(function() {
21148 var current = [this];
21149 push.apply(current, arguments);
21150 actual.push(current);
21152 var next = queue.shift();
21154 funced.call(next[0], next[1]);
21158 var next = queue.shift();
21159 funced.call(next[0], next[1]);
21160 assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
21162 setTimeout(function() {
21163 assert.deepEqual(actual, expected.slice(0, actual.length));
21168 QUnit.test('_.' + methodName + ' should work if the system time is set backwards', function(assert) {
21171 var done = assert.async();
21173 if (!isModularize) {
21177 var getTime = function() {
21178 return ++dateCount === 4
21179 ? +new Date(2012, 3, 23, 23, 27, 18)
21183 var lodash = _.runInContext(lodashStable.assign({}, root, {
21184 'Date': lodashStable.assign(function() {
21185 return { 'getTime': getTime, 'valueOf': getTime };
21191 var funced = lodash[methodName](function() {
21197 setTimeout(function() {
21199 assert.strictEqual(callCount, isDebounce ? 1 : 2);
21204 skipAssert(assert);
21209 QUnit.test('_.' + methodName + ' should support cancelling delayed calls', function(assert) {
21212 var done = assert.async();
21216 var funced = func(function() {
21218 }, 32, { 'leading': false });
21223 setTimeout(function() {
21224 assert.strictEqual(callCount, 0);
21229 QUnit.test('_.' + methodName + ' should reset `lastCalled` after cancelling', function(assert) {
21232 var done = assert.async();
21236 var funced = func(function() {
21237 return ++callCount;
21238 }, 32, { 'leading': true });
21240 assert.strictEqual(funced(), 1);
21242 assert.strictEqual(funced(), 2);
21244 setTimeout(function() {
21245 assert.strictEqual(callCount, 2);
21250 QUnit.test('_.' + methodName + ' should support flushing delayed calls', function(assert) {
21253 var done = assert.async();
21257 var funced = func(function() {
21258 return ++callCount;
21259 }, 32, { 'leading': false });
21262 var actual = funced.flush();
21264 setTimeout(function() {
21265 assert.strictEqual(actual, 1);
21266 assert.strictEqual(callCount, 1);
21272 /*--------------------------------------------------------------------------*/
21274 QUnit.module('lodash.times');
21277 QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
21280 lodashStable.each([-Infinity, NaN, Infinity], function(n) {
21281 assert.deepEqual(_.times(n), []);
21285 QUnit.test('should coerce `n` to an integer', function(assert) {
21288 var actual = _.times(2.6, _.indentify);
21289 assert.deepEqual(actual, [0, 1]);
21292 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
21297 _.times(1, function(assert) {
21298 args || (args = slice.call(arguments));
21301 assert.deepEqual(args, [0]);
21304 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
21307 var values = [, null, undefined],
21308 expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
21310 var actual = lodashStable.map(values, function(value, index) {
21311 return index ? _.times(3, value) : _.times(3);
21314 assert.deepEqual(actual, expected);
21317 QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
21320 assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
21323 QUnit.test('should return an empty array for falsey and negative `n` arguments', function(assert) {
21326 var values = falsey.concat(-1, -Infinity),
21327 expected = lodashStable.map(values, alwaysEmptyArray);
21329 var actual = lodashStable.map(values, function(value, index) {
21330 return index ? _.times(value) : _.times();
21333 assert.deepEqual(actual, expected);
21336 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
21340 assert.deepEqual(_(3).times(), [0, 1, 2]);
21343 skipAssert(assert);
21347 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
21351 assert.ok(_(3).chain().times() instanceof _);
21354 skipAssert(assert);
21359 /*--------------------------------------------------------------------------*/
21361 QUnit.module('lodash.toArray');
21364 QUnit.test('should convert objects to arrays', function(assert) {
21367 assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
21370 QUnit.test('should convert strings to arrays', function(assert) {
21373 assert.deepEqual(_.toArray(''), []);
21374 assert.deepEqual(_.toArray('ab'), ['a', 'b']);
21375 assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
21378 QUnit.test('should convert iterables to arrays', function(assert) {
21381 if (!isNpm && Symbol && Symbol.iterator) {
21382 var object = { '0': 'a', 'length': 1 };
21383 object[Symbol.iterator] = arrayProto[Symbol.iterator];
21385 assert.deepEqual(_.toArray(object), ['a']);
21388 skipAssert(assert);
21392 QUnit.test('should work in a lazy sequence', function(assert) {
21396 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21397 actual = _(array).slice(1).map(String).toArray().value();
21399 assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
21401 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
21402 return ['key' + index, index];
21405 actual = _(object).toArray().slice(1).map(String).value();
21406 assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
21409 skipAssert(assert, 2);
21414 /*--------------------------------------------------------------------------*/
21416 QUnit.module('lodash.toLower');
21419 QUnit.test('should convert whole string to lower case', function(assert) {
21422 assert.deepEqual(_.toLower('--Foo-Bar'), '--foo-bar');
21423 assert.deepEqual(_.toLower('fooBar'), 'foobar');
21424 assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
21428 /*--------------------------------------------------------------------------*/
21430 QUnit.module('lodash.toUpper');
21433 QUnit.test('should convert whole string to upper case', function(assert) {
21436 assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
21437 assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
21438 assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
21442 /*--------------------------------------------------------------------------*/
21444 QUnit.module('lodash.slice and lodash.toArray');
21446 lodashStable.each(['slice', 'toArray'], function(methodName) {
21447 var args = (function() { return arguments; }(1, 2, 3)),
21449 func = _[methodName];
21451 QUnit.test('should return a dense array', function(assert) {
21454 var sparse = Array(3);
21457 var actual = func(sparse);
21459 assert.ok('0' in actual);
21460 assert.ok('2' in actual);
21461 assert.deepEqual(actual, sparse);
21464 QUnit.test('should treat array-like objects like arrays', function(assert) {
21467 var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 };
21468 assert.deepEqual(func(object), ['a', 'b', 'c']);
21469 assert.deepEqual(func(args), array);
21472 QUnit.test('should return a shallow clone of arrays', function(assert) {
21475 var actual = func(array);
21476 assert.deepEqual(actual, array);
21477 assert.notStrictEqual(actual, array);
21480 QUnit.test('should work with a node list for `collection`', function(assert) {
21485 var actual = func(document.getElementsByTagName('body'));
21488 assert.deepEqual(actual, [body]);
21491 skipAssert(assert);
21496 /*--------------------------------------------------------------------------*/
21498 QUnit.module('toInteger methods');
21500 lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
21501 var func = _[methodName],
21502 isSafe = methodName == 'toSafeInteger';
21504 QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
21507 assert.strictEqual(func(-5.6), -5);
21508 assert.strictEqual(func('5.6'), 5);
21509 assert.strictEqual(func(), 0);
21510 assert.strictEqual(func(NaN), 0);
21512 var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
21513 assert.strictEqual(func(Infinity), expected);
21514 assert.strictEqual(func(-Infinity), -expected);
21517 QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
21520 assert.strictEqual(1 / func(-0), -Infinity);
21524 /*--------------------------------------------------------------------------*/
21526 QUnit.module('lodash.toLength');
21529 QUnit.test('should return a valid length', function(assert) {
21532 assert.strictEqual(_.toLength(-1), 0);
21533 assert.strictEqual(_.toLength('1'), 1);
21534 assert.strictEqual(_.toLength(1.1), 1);
21535 assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
21538 QUnit.test('should return `value` if a valid length', function(assert) {
21541 assert.strictEqual(_.toLength(0), 0);
21542 assert.strictEqual(_.toLength(3), 3);
21543 assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
21546 QUnit.test('should convert `-0` to `0`', function(assert) {
21549 assert.strictEqual(1 / _.toLength(-0), Infinity);
21553 /*--------------------------------------------------------------------------*/
21555 QUnit.module('lodash.toInteger and lodash.toNumber');
21557 lodashStable.each(['toInteger', 'toNumber'], function(methodName) {
21558 var func = _[methodName],
21559 isInt = methodName == 'toInteger';
21561 function negative(string) {
21562 return '-' + string;
21565 function pad(string) {
21566 return whitespace + string + whitespace;
21569 function positive(string) {
21570 return '+' + string;
21573 QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
21576 var values = falsey.concat(whitespace);
21578 var expected = lodashStable.map(values, function(value) {
21579 return (isInt || (value === whitespace)) ? 0 : Number(value);
21582 var actual = lodashStable.map(values, function(value, index) {
21583 return index ? func(value) : func();
21586 assert.deepEqual(actual, expected);
21589 QUnit.test('`_.' + methodName + '` should preserve sign of `0`', function(assert) {
21592 var values = [0, '0', -0, '-0'],
21593 expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
21595 var actual = lodashStable.map(values, function(value) {
21596 var result = func(value);
21597 return [result, 1 / result];
21600 assert.deepEqual(actual, expected);
21603 QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
21606 var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
21608 var expected = lodashStable.map(values, function(value) {
21610 if (value == 1.2) {
21613 else if (value == Infinity) {
21614 value = MAX_INTEGER;
21616 else if (value !== value) {
21620 return [value, value, -value, -value];
21623 var actual = lodashStable.map(values, function(value) {
21624 return lodashStable.flattenDeep(
21625 lodashStable.times(2, function(index) {
21626 var other = index ? -value : value;
21629 func(Object(other))
21635 assert.deepEqual(actual, expected);
21638 QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
21641 var transforms = [identity, pad, positive, negative];
21644 '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
21645 '1e+308', '1e308', '1E+308', '1E308',
21646 '5e-324', '5E-324',
21650 var expected = lodashStable.map(values, function(value) {
21653 if (n == 1.234567890) {
21656 else if (n == Infinity) {
21659 else if (n == Number.MIN_VALUE || n !== n) {
21663 return [n, n, n, n, n, n, -n, -n];
21666 var actual = lodashStable.map(values, function(value) {
21667 return lodashStable.flattenDeep(
21668 lodashStable.map(transforms, function(mod) {
21671 func(Object(mod(value)))
21677 assert.deepEqual(actual, expected);
21680 QUnit.test('`_.' + methodName + '` should convert binary and octal strings to numbers', function(assert) {
21683 var numbers = [42, 5349, 1715004],
21684 transforms = [identity, pad],
21685 values = ['0b101010', '0o12345', '0x1a2b3c'];
21687 var expected = lodashStable.map(numbers, function(n) {
21688 return lodashStable.times(8, lodashStable.constant(n));
21691 var actual = lodashStable.map(values, function(value) {
21692 return lodashStable.flattenDeep(
21693 lodashStable.times(2, function(index) {
21694 var other = index ? value.toUpperCase() : value;
21695 return lodashStable.map(transforms, function(mod) {
21698 func(Object(mod(other)))
21705 assert.deepEqual(actual, expected);
21708 QUnit.test('`_.' + methodName + '` should convert invalid binary and octal strings to `NaN`', function(assert) {
21711 var transforms = [identity, pad, positive, negative],
21712 values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
21714 var expected = lodashStable.map(values, function(n) {
21715 return lodashStable.times(16, lodashStable.constant(isInt ? 0 : NaN));
21718 var actual = lodashStable.map(values, function(value) {
21719 return lodashStable.flattenDeep(
21720 lodashStable.times(2, function(index) {
21721 var other = index ? value.toUpperCase() : value;
21722 return lodashStable.map(transforms, function(mod) {
21725 func(Object(mod(value)))
21732 assert.deepEqual(actual, expected);
21735 QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
21743 { 'valueOf': '1.1' },
21744 { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
21745 { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
21746 { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
21747 { 'valueOf': lodashStable.constant('-0x1a2b3c') },
21748 { 'toString': lodashStable.constant('-0x1a2b3c') },
21749 { 'valueOf': lodashStable.constant('0o12345') },
21750 { 'toString': lodashStable.constant('0o12345') },
21751 { 'valueOf': lodashStable.constant('0b101010') },
21752 { 'toString': lodashStable.constant('0b101010') }
21757 NaN, 2.2, 1.1, 1.1,
21772 var actual = lodashStable.map(values, func);
21774 assert.deepEqual(actual, expected);
21778 /*--------------------------------------------------------------------------*/
21780 QUnit.module('lodash.toPairs');
21783 QUnit.test('should create a two dimensional array of key-value pairs', function(assert) {
21786 var object = { 'a': 1, 'b': 2 };
21787 assert.deepEqual(_.toPairs(object), [['a', 1], ['b', 2]]);
21790 QUnit.test('should work with an object that has a `length` property', function(assert) {
21793 var object = { '0': 'a', '1': 'b', 'length': 2 };
21794 assert.deepEqual(_.toPairs(object), [['0', 'a'], ['1', 'b'], ['length', 2]]);
21797 QUnit.test('should work with strings', function(assert) {
21800 lodashStable.each(['xo', Object('xo')], function(string) {
21801 assert.deepEqual(_.toPairs(string), [['0', 'x'], ['1', 'o']]);
21806 /*--------------------------------------------------------------------------*/
21808 QUnit.module('lodash.toPath');
21811 QUnit.test('should convert a string to a path', function(assert) {
21814 assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
21815 assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
21818 QUnit.test('should coerce array elements to strings', function(assert) {
21821 var array = ['a', 'b', 'c'];
21823 lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
21824 var actual = _.toPath(value);
21825 assert.deepEqual(actual, array);
21826 assert.notStrictEqual(actual, array);
21830 QUnit.test('should handle complex paths', function(assert) {
21833 var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
21834 assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
21837 QUnit.test('should ignore consecutive brackets and dots', function(assert) {
21840 var expected = ['a'];
21841 assert.deepEqual(_.toPath('a.'), expected);
21842 assert.deepEqual(_.toPath('a[]'), expected);
21844 expected = ['a', 'b'];
21845 assert.deepEqual(_.toPath('a..b'), expected);
21846 assert.deepEqual(_.toPath('a[][]b'), expected);
21850 /*--------------------------------------------------------------------------*/
21852 QUnit.module('lodash.toPlainObject');
21855 var args = arguments;
21857 QUnit.test('should flatten inherited properties', function(assert) {
21860 function Foo() { this.b = 2; }
21861 Foo.prototype.c = 3;
21863 var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
21864 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
21867 QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
21870 var actual = _.toPlainObject(args),
21871 expected = { '0': 1, '1': 2, '2': 3 };
21873 assert.deepEqual(actual, expected);
21876 QUnit.test('should convert arrays to plain objects', function(assert) {
21879 var actual = _.toPlainObject(['a', 'b', 'c']),
21880 expected = { '0': 'a', '1': 'b', '2': 'c' };
21882 assert.deepEqual(actual, expected);
21886 /*--------------------------------------------------------------------------*/
21888 QUnit.module('lodash.toString');
21891 QUnit.test('should treat nullish values as empty strings', function(assert) {
21894 var values = [, null, undefined],
21895 expected = lodashStable.map(values, alwaysEmptyString);
21897 var actual = lodashStable.map(values, function(value, index) {
21898 return index ? _.toString(value) : _.toString();
21901 assert.deepEqual(actual, expected);
21904 QUnit.test('should preserve sign of `0`', function(assert) {
21907 var values = [0, Object(0), -0, Object(-0)],
21908 expected = ['0', '0', '-0', '-0'],
21909 actual = lodashStable.map(values, _.toString);
21911 assert.deepEqual(actual, expected);
21914 QUnit.test('should not error on symbols', function(assert) {
21919 assert.strictEqual(_.toString(symbol), 'Symbol(a)');
21921 assert.ok(false, e.message);
21925 skipAssert(assert);
21929 QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
21933 var wrapped = _([1, 2, 3]);
21934 assert.strictEqual(wrapped.toString(), '1,2,3');
21937 skipAssert(assert);
21942 /*--------------------------------------------------------------------------*/
21944 QUnit.module('lodash.transform');
21953 QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
21956 var accumulators = [, null, undefined],
21957 expected = lodashStable.map(accumulators, alwaysTrue),
21960 var iteratee = function(result, value, key) {
21961 result[key] = square(value);
21964 var mapper = function(accumulator, index) {
21965 return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
21968 var results = lodashStable.map(accumulators, mapper);
21970 var actual = lodashStable.map(results, function(result) {
21971 return result instanceof Foo;
21974 assert.deepEqual(actual, expected);
21976 expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
21977 actual = lodashStable.map(results, lodashStable.toPlainObject);
21979 assert.deepEqual(actual, expected);
21981 object = { 'a': 1, 'b': 2, 'c': 3 };
21982 actual = lodashStable.map(accumulators, mapper);
21984 assert.deepEqual(actual, expected);
21986 object = [1, 2, 3];
21987 expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
21988 actual = lodashStable.map(accumulators, mapper);
21990 assert.deepEqual(actual, expected);
21993 QUnit.test('should create regular arrays from typed arrays', function(assert) {
21996 var expected = lodashStable.map(typedArrays, alwaysTrue);
21998 var actual = lodashStable.map(typedArrays, function(type) {
21999 var Ctor = root[type],
22000 array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
22002 return lodashStable.isArray(_.transform(array, noop));
22005 assert.deepEqual(actual, expected);
22008 QUnit.test('should support an `accumulator` value', function(assert) {
22011 var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
22012 expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
22014 var actual = lodashStable.map(values, function(value) {
22015 return _.transform(value, function(result, value) {
22016 result.push(square(value));
22020 assert.deepEqual(actual, expected);
22022 var object = { 'a': 1, 'b': 4, 'c': 9 },
22023 expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
22025 actual = lodashStable.map(values, function(value) {
22026 return _.transform(value, function(result, value, key) {
22027 result[key] = square(value);
22031 assert.deepEqual(actual, expected);
22033 lodashStable.each([[], {}], function(accumulator) {
22034 var actual = lodashStable.map(values, function(value) {
22035 return _.transform(value, noop, accumulator);
22038 assert.ok(lodashStable.every(actual, function(result) {
22039 return result === accumulator;
22042 assert.strictEqual(_.transform(null, null, accumulator), accumulator);
22046 QUnit.test('should treat sparse arrays as dense', function(assert) {
22049 var actual = _.transform(Array(1), function(result, value, index) {
22050 result[index] = String(value);
22053 assert.deepEqual(actual, ['undefined']);
22056 QUnit.test('should work without an `iteratee` argument', function(assert) {
22059 assert.ok(_.transform(new Foo) instanceof Foo);
22062 QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
22065 var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
22066 values = [true, false, 0, 1, NaN, '', 'a'],
22067 expected = lodashStable.map(values, alwaysEmptyObject);
22069 var results = lodashStable.map(values, function(value) {
22070 return _.transform(value);
22073 assert.deepEqual(results, expected);
22075 expected = lodashStable.map(values, alwaysFalse);
22077 var actual = lodashStable.map(results, function(value, index) {
22078 return value instanceof Ctors[index];
22081 assert.deepEqual(actual, expected);
22084 QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
22087 Foo.prototype.constructor = null;
22088 assert.notOk(_.transform(new Foo) instanceof Foo);
22089 Foo.prototype.constructor = Foo;
22092 QUnit.test('should create an empty object when given a falsey `object` argument', function(assert) {
22095 var expected = lodashStable.map(falsey, alwaysEmptyObject);
22097 var actual = lodashStable.map(falsey, function(object, index) {
22098 return index ? _.transform(object) : _.transform();
22101 assert.deepEqual(actual, expected);
22104 lodashStable.each({
22105 'array': [1, 2, 3],
22106 'object': { 'a': 1, 'b': 2, 'c': 3 }
22108 function(object, key) {
22109 QUnit.test('should provide the correct `iteratee` arguments when transforming an ' + key, function(assert) {
22114 _.transform(object, function() {
22115 args || (args = slice.call(arguments));
22118 var first = args[0];
22119 if (key == 'array') {
22120 assert.ok(first !== object && lodashStable.isArray(first));
22121 assert.deepEqual(args, [first, 1, 0, object]);
22123 assert.ok(first !== object && lodashStable.isPlainObject(first));
22124 assert.deepEqual(args, [first, 1, 'a', object]);
22129 QUnit.test('should create an object from the same realm as `object`', function(assert) {
22132 var objects = lodashStable.filter(realm, function(value) {
22133 return lodashStable.isObject(value) && !lodashStable.isElement(value);
22136 var expected = lodashStable.map(objects, alwaysTrue);
22138 var actual = lodashStable.map(objects, function(object) {
22139 var Ctor = object.constructor,
22140 result = _.transform(object);
22142 if (result === object) {
22145 if (lodashStable.isTypedArray(object)) {
22146 return result instanceof Array;
22148 return result instanceof Ctor || !(new Ctor instanceof Ctor);
22151 assert.deepEqual(actual, expected);
22155 /*--------------------------------------------------------------------------*/
22157 QUnit.module('trim methods');
22159 lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
22160 var func = _[methodName],
22164 parts.push('leading');
22167 parts.push('trailing');
22169 parts = parts.join(' and ');
22171 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
22174 var string = whitespace + 'a b c' + whitespace,
22175 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
22177 assert.strictEqual(func(string), expected);
22180 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
22183 var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
22184 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
22186 assert.strictEqual(func(object), expected);
22189 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
22192 var string = '-_-a-b-c-_-',
22193 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
22195 assert.strictEqual(func(string, '_-'), expected);
22198 QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
22201 var object = { 'toString': lodashStable.constant('_-') },
22202 string = '-_-a-b-c-_-',
22203 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
22205 assert.strictEqual(func(string, object), expected);
22208 QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
22211 lodashStable.each([null, '_-'], function(chars) {
22212 assert.strictEqual(func(null, chars), '');
22213 assert.strictEqual(func(undefined, chars), '');
22214 assert.strictEqual(func('', chars), '');
22218 QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
22221 var string = whitespace + 'a b c' + whitespace,
22222 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
22224 assert.strictEqual(func(string, undefined), expected);
22225 assert.strictEqual(func(string, ''), string);
22228 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
22231 var string = Object(whitespace + 'a b c' + whitespace),
22232 trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
22233 actual = lodashStable.map([string, string, string], func);
22235 assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
22238 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
22242 var string = whitespace + 'a b c' + whitespace,
22243 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
22245 assert.strictEqual(_(string)[methodName](), expected);
22248 skipAssert(assert);
22252 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
22256 var string = whitespace + 'a b c' + whitespace;
22257 assert.ok(_(string).chain()[methodName]() instanceof _);
22260 skipAssert(assert);
22265 /*--------------------------------------------------------------------------*/
22267 QUnit.module('uncommon symbols');
22270 var flag = '\ud83c\uddfa\ud83c\uddf8',
22271 heart = '\u2764' + emojiVar,
22272 hearts = '\ud83d\udc95',
22273 comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68',
22274 hashKeycap = '#' + emojiVar + '\u20e3',
22275 leafs = '\ud83c\udf42',
22276 noMic = '\ud83c\udf99\u20e0',
22277 raisedHand = '\u270B' + emojiVar,
22278 rocket = '\ud83d\ude80',
22279 thumbsUp = '\ud83d\udc4d';
22281 QUnit.test('should account for astral symbols', function(assert) {
22284 var allHearts = _.repeat(hearts, 10),
22285 chars = hearts + comboGlyph,
22286 string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
22287 trimChars = comboGlyph + hearts,
22288 trimString = trimChars + string + trimChars;
22290 assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
22291 assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
22292 assert.strictEqual(_.capitalize(rocket), rocket);
22294 assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
22295 assert.strictEqual(_.padStart(string, 16), ' ' + string);
22296 assert.strictEqual(_.padEnd(string, 16), string + ' ');
22298 assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
22299 assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
22300 assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
22302 assert.strictEqual(_.size(string), 13);
22303 assert.deepEqual(_.toArray(string), ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket]);
22305 assert.strictEqual(_.trim(trimString, chars), string);
22306 assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
22307 assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
22309 assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
22310 assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
22312 assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
22313 assert.deepEqual(_.toArray(hashKeycap), [hashKeycap]);
22315 lodashStable.times(2, function(index) {
22316 var separator = index ? RegExp(hearts) : hearts,
22317 options = { 'length': 4, 'separator': separator },
22318 actual = _.truncate(string, options);
22320 assert.strictEqual(actual, 'A...');
22321 assert.strictEqual(actual.length, 4);
22323 actual = _.truncate(allHearts, options);
22324 assert.strictEqual(actual, hearts + '...');
22325 assert.strictEqual(actual.length, 5);
22329 QUnit.test('should account for combining diacritical marks', function(assert) {
22332 var values = lodashStable.map(comboMarks, function(mark) {
22336 var expected = lodashStable.map(values, function(value) {
22337 return [1, [value], [value]];
22340 var actual = lodashStable.map(values, function(value) {
22341 return [_.size(value), _.toArray(value), _.words(value)];
22344 assert.deepEqual(actual, expected);
22347 QUnit.test('should account for fitzpatrick modifiers', function(assert) {
22350 var values = lodashStable.map(fitzModifiers, function(modifier) {
22351 return thumbsUp + modifier;
22354 var expected = lodashStable.map(values, function(value) {
22355 return [1, [value], [value]];
22358 var actual = lodashStable.map(values, function(value) {
22359 return [_.size(value), _.toArray(value), _.words(value)];
22362 assert.deepEqual(actual, expected);
22365 QUnit.test('should account for regional symbols', function(assert) {
22368 var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
22369 regionals = pair.join(' ');
22371 assert.strictEqual(_.size(flag), 1);
22372 assert.strictEqual(_.size(regionals), 3);
22374 assert.deepEqual(_.toArray(flag), [flag]);
22375 assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
22377 assert.deepEqual(_.words(flag), [flag]);
22378 assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
22381 QUnit.test('should account for variation selectors', function(assert) {
22384 assert.strictEqual(_.size(heart), 1);
22385 assert.deepEqual(_.toArray(heart), [heart]);
22386 assert.deepEqual(_.words(heart), [heart]);
22389 QUnit.test('should account for variation selectors with fitzpatrick modifiers', function(assert) {
22392 var values = lodashStable.map(fitzModifiers, function(modifier) {
22393 return raisedHand + modifier;
22396 var expected = lodashStable.map(values, function(value) {
22397 return [1, [value], [value]];
22400 var actual = lodashStable.map(values, function(value) {
22401 return [_.size(value), _.toArray(value), _.words(value)];
22404 assert.deepEqual(actual, expected);
22407 QUnit.test('should match lone surrogates', function(assert) {
22410 var pair = hearts.split(''),
22411 surrogates = pair[0] + ' ' + pair[1];
22413 assert.strictEqual(_.size(surrogates), 3);
22414 assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
22415 assert.deepEqual(_.words(surrogates), []);
22418 QUnit.test('should match side by side fitzpatrick modifiers separately ', function(assert) {
22421 var string = fitzModifiers[0] + fitzModifiers[0];
22422 assert.deepEqual(_.toArray(string), [fitzModifiers[0], fitzModifiers[0]]);
22426 /*--------------------------------------------------------------------------*/
22428 QUnit.module('lodash.unescape');
22431 var escaped = '&<>"'\/',
22432 unescaped = '&<>"\'\/';
22434 escaped += escaped;
22435 unescaped += unescaped;
22437 QUnit.test('should unescape entities in order', function(assert) {
22440 assert.strictEqual(_.unescape('&lt;'), '<');
22443 QUnit.test('should unescape the proper entities', function(assert) {
22446 assert.strictEqual(_.unescape(escaped), unescaped);
22449 QUnit.test('should not unescape the "/" entity', function(assert) {
22452 assert.strictEqual(_.unescape('/'), '/');
22455 QUnit.test('should handle strings with nothing to unescape', function(assert) {
22458 assert.strictEqual(_.unescape('abc'), 'abc');
22461 QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
22464 assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
22468 /*--------------------------------------------------------------------------*/
22470 QUnit.module('lodash.upperCase');
22473 QUnit.test('should uppercase as space-separated words', function(assert) {
22476 assert.strictEqual(_.upperCase('--foo-bar'), 'FOO BAR');
22477 assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
22478 assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
22482 /*--------------------------------------------------------------------------*/
22484 QUnit.module('lodash.upperFirst');
22487 QUnit.test('should uppercase only the first character', function(assert) {
22490 assert.strictEqual(_.upperFirst('fred'), 'Fred');
22491 assert.strictEqual(_.upperFirst('Fred'), 'Fred');
22492 assert.strictEqual(_.upperFirst('FRED'), 'FRED');
22496 /*--------------------------------------------------------------------------*/
22498 QUnit.module('lodash.unary');
22502 return slice.call(arguments);
22505 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
22508 var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
22509 assert.deepEqual(actual, [6, 8, 10]);
22512 QUnit.test('should work when provided less than the capped number of arguments', function(assert) {
22515 var capped = _.unary(fn);
22516 assert.deepEqual(capped(), []);
22520 /*--------------------------------------------------------------------------*/
22522 QUnit.module('union methods');
22524 lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
22525 var args = (function() { return arguments; }(1, 2, 3)),
22526 func = _[methodName];
22528 QUnit.test('`_.' + methodName + '` should return the union of the given arrays', function(assert) {
22531 var actual = func([1, 3, 2], [5, 2, 1, 4], [2, 1]);
22532 assert.deepEqual(actual, [1, 3, 2, 5, 4]);
22535 QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
22538 var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
22539 assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
22542 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
22546 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
22547 assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
22548 assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
22552 /*--------------------------------------------------------------------------*/
22554 QUnit.module('lodash.unionBy');
22557 QUnit.test('should accept an `iteratee` argument', function(assert) {
22560 var actual = _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
22561 assert.deepEqual(actual, [2.1, 1.2, 4.3]);
22563 actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
22564 assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
22567 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
22572 _.unionBy([2.1, 1.2], [4.3, 2.4], function() {
22573 args || (args = slice.call(arguments));
22576 assert.deepEqual(args, [2.1]);
22580 /*--------------------------------------------------------------------------*/
22582 QUnit.module('lodash.unionWith');
22585 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
22587 QUnit.test('should work with a `comparator` argument', function(assert) {
22590 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
22591 actual = _.unionWith(objects, others, lodashStable.isEqual);
22593 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]);
22597 /*--------------------------------------------------------------------------*/
22599 QUnit.module('lodash.uniq');
22602 QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
22605 var array = [[2, 1, 2], [1, 2, 1]],
22606 actual = lodashStable.map(array, lodashStable.uniq);
22608 assert.deepEqual(actual, [[2, 1], [1, 2]]);
22612 /*--------------------------------------------------------------------------*/
22614 QUnit.module('uniq methods');
22616 lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
22617 var func = _[methodName],
22618 isSorted = /^sorted/.test(methodName),
22619 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
22622 objects = _.sortBy(objects, 'a');
22625 QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
22628 var array = [2, 3, 1, 2, 3, 1];
22629 assert.deepEqual(func(array), [2, 3, 1]);
22632 QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
22635 var array = [1, 1, 2, 2, 3];
22636 assert.deepEqual(func(array), [1, 2, 3]);
22639 QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
22642 assert.deepEqual(func(objects), objects);
22645 QUnit.test('`_.' + methodName + '` should not treat `NaN` as unique', function(assert) {
22648 assert.deepEqual(func([1, 3, NaN, NaN]), [1, 3, NaN]);
22651 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
22654 var largeArray = [],
22655 expected = [0, {}, 'a'],
22656 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
22658 lodashStable.each(expected, function(value) {
22659 lodashStable.times(count, function() {
22660 largeArray.push(value);
22664 assert.deepEqual(func(largeArray), expected);
22667 QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
22670 var largeArray = [],
22671 expected = [false, true, null, undefined, NaN],
22672 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
22674 lodashStable.each(expected, function(value) {
22675 lodashStable.times(count, function() {
22676 largeArray.push(value);
22680 assert.deepEqual(func(largeArray), expected);
22683 QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
22687 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
22688 assert.deepEqual(func(largeArray), largeArray);
22691 skipAssert(assert);
22695 QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
22698 // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
22701 Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
22702 Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
22703 Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
22706 var largeArray = [],
22707 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
22709 expected = lodashStable.map(expected, function(symbol) {
22710 return symbol || {};
22713 lodashStable.each(expected, function(value) {
22714 lodashStable.times(count, function() {
22715 largeArray.push(value);
22719 assert.deepEqual(func(largeArray), expected);
22722 skipAssert(assert);
22726 QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
22729 var largeArray = [],
22730 expected = ['2', 2, Object('2'), Object(2)],
22731 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
22733 lodashStable.each(expected, function(value) {
22734 lodashStable.times(count, function() {
22735 largeArray.push(value);
22739 assert.deepEqual(func(largeArray), expected);
22743 /*--------------------------------------------------------------------------*/
22745 QUnit.module('uniqBy methods');
22747 lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
22748 var func = _[methodName],
22749 isSorted = methodName == 'sortedUniqBy',
22750 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
22753 objects = _.sortBy(objects, 'a');
22755 QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
22758 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
22760 var actual = func(objects, function(object) {
22764 assert.deepEqual(actual, expected);
22767 QUnit.test('should work with large arrays', function(assert) {
22770 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
22774 var actual = func(largeArray, String);
22776 assert.deepEqual(actual, [[1, 2]]);
22777 assert.strictEqual(actual[0], largeArray[0]);
22780 QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
22785 func(objects, function() {
22786 args || (args = slice.call(arguments));
22789 assert.deepEqual(args, [objects[0]]);
22792 QUnit.test('`_.' + methodName + '` should work with "_.property" shorthands', function(assert) {
22795 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
22796 actual = func(objects, 'a');
22798 assert.deepEqual(actual, expected);
22800 var arrays = [[2], [3], [1], [2], [3], [1]];
22802 arrays = lodashStable.sortBy(arrays, 0);
22804 expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
22805 actual = func(arrays, 0);
22807 assert.deepEqual(actual, expected);
22810 lodashStable.each({
22811 'an array': [0, 'a'],
22812 'an object': { '0': 'a' },
22816 function(iteratee, key) {
22817 QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
22820 var actual = func([['a'], ['a'], ['b']], iteratee);
22821 assert.deepEqual(actual, [['a'], ['b']]);
22826 /*--------------------------------------------------------------------------*/
22828 QUnit.module('lodash.uniqWith');
22831 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
22833 QUnit.test('should work with a `comparator` argument', function(assert) {
22836 var actual = _.uniqWith(objects, lodashStable.isEqual);
22837 assert.deepEqual(actual, [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]);
22841 /*--------------------------------------------------------------------------*/
22843 QUnit.module('lodash.uniqueId');
22846 QUnit.test('should generate unique ids', function(assert) {
22849 var actual = lodashStable.times(1000, function(assert) {
22850 return _.uniqueId();
22853 assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
22856 QUnit.test('should return a string value when not providing a prefix argument', function(assert) {
22859 assert.strictEqual(typeof _.uniqueId(), 'string');
22862 QUnit.test('should coerce the prefix argument to a string', function(assert) {
22865 var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
22866 assert.ok(/3\d+,2\d+,1\d+/.test(actual));
22870 /*--------------------------------------------------------------------------*/
22872 QUnit.module('lodash.unset');
22875 QUnit.test('should unset property values', function(assert) {
22878 lodashStable.each(['a', ['a']], function(path) {
22879 var object = { 'a': 1, 'c': 2 };
22880 assert.strictEqual(_.unset(object, path), true);
22881 assert.deepEqual(object, { 'c': 2 });
22885 QUnit.test('should unset deep property values', function(assert) {
22888 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
22889 var object = { 'a': { 'b': { 'c': null } } };
22890 assert.strictEqual(_.unset(object, path), true);
22891 assert.deepEqual(object, { 'a': { 'b': {} } });
22895 QUnit.test('should handle complex paths', function(assert) {
22899 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
22900 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
22903 lodashStable.each(paths, function(path) {
22904 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
22905 assert.strictEqual(_.unset(object, path), true);
22906 assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
22910 QUnit.test('should return `true` for nonexistent paths', function(assert) {
22913 var object = { 'a': { 'b': { 'c': null } } };
22915 lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
22916 assert.strictEqual(_.unset(object, path), true);
22919 assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
22922 QUnit.test('should not error when `object` is nullish', function(assert) {
22925 var values = [null, undefined],
22926 expected = [[true, true], [true, true]];
22928 var actual = lodashStable.map(values, function(value) {
22930 return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
22936 assert.deepEqual(actual, expected);
22939 QUnit.test('should follow `path` over non-plain objects', function(assert) {
22942 var object = { 'a': '' },
22943 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
22945 lodashStable.each(paths, function(path) {
22948 var actual = _.unset(0, path);
22949 assert.strictEqual(actual, true);
22950 assert.notOk('a' in numberProto);
22952 delete numberProto.a;
22955 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
22956 stringProto.replace.b = 1;
22958 var actual = _.unset(object, path);
22959 assert.strictEqual(actual, true);
22960 assert.notOk('a' in stringProto.replace);
22962 delete stringProto.replace.b;
22966 QUnit.test('should return `false` for non-configurable properties', function(assert) {
22971 if (!isStrict && defineProperty) {
22972 defineProperty(object, 'a', {
22973 'configurable': false,
22974 'enumerable': true,
22978 assert.strictEqual(_.unset(object, 'a'), false);
22981 skipAssert(assert);
22986 /*--------------------------------------------------------------------------*/
22988 QUnit.module('lodash.unzipWith');
22991 QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
22994 var array = [[1, 4], [2, 5], [3, 6]];
22996 var actual = _.unzipWith(array, function(a, b, c) {
23000 assert.deepEqual(actual, [6, 15]);
23003 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
23008 _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
23009 args || (args = slice.call(arguments));
23012 assert.deepEqual(args, [1, 2]);
23015 QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
23018 var array = [[1, 3], [2, 4]],
23019 values = [, null, undefined],
23020 expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
23022 var actual = lodashStable.map(values, function(value, index) {
23023 return index ? _.unzipWith(array, value) : _.unzipWith(array);
23026 assert.deepEqual(actual, expected);
23030 /*--------------------------------------------------------------------------*/
23032 QUnit.module('values methods');
23034 lodashStable.each(['values', 'valuesIn'], function(methodName) {
23035 var args = (function() { return arguments; }(1, 2, 3)),
23036 func = _[methodName],
23037 isValues = methodName == 'values';
23039 QUnit.test('`_.' + methodName + '` should get the values of an object', function(assert) {
23042 var object = { 'a': 1, 'b': 2 };
23043 assert.deepEqual(func(object), [1, 2]);
23046 QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
23049 var object = { '0': 'a', '1': 'b', 'length': 2 };
23050 assert.deepEqual(func(object), ['a', 'b', 2]);
23053 QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + ' include inherited property values', function(assert) {
23056 function Foo() { this.a = 1; }
23057 Foo.prototype.b = 2;
23059 var expected = isValues ? [1] : [1, 2];
23060 assert.deepEqual(func(new Foo).sort(), expected);
23064 /*--------------------------------------------------------------------------*/
23066 QUnit.module('lodash.without');
23069 QUnit.test('should use strict equality to determine the values to reject', function(assert) {
23072 var object1 = { 'a': 1 },
23073 object2 = { 'b': 2 },
23074 array = [object1, object2];
23076 assert.deepEqual(_.without(array, { 'a': 1 }), array);
23077 assert.deepEqual(_.without(array, object1), [object2]);
23080 QUnit.test('should remove all occurrences of each value from an array', function(assert) {
23083 var array = [1, 2, 3, 1, 2, 3];
23084 assert.deepEqual(_.without(array, 1, 2), [3, 3]);
23088 /*--------------------------------------------------------------------------*/
23090 QUnit.module('lodash.words');
23093 QUnit.test('should treat latin-1 supplementary letters as words', function(assert) {
23096 var expected = lodashStable.map(burredLetters, function(letter) {
23100 var actual = lodashStable.map(burredLetters, function(letter) {
23101 return _.words(letter);
23104 assert.deepEqual(actual, expected);
23107 QUnit.test('should not treat mathematical operators as words', function(assert) {
23110 var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
23111 expected = lodashStable.map(operators, alwaysEmptyArray),
23112 actual = lodashStable.map(operators, _.words);
23114 assert.deepEqual(actual, expected);
23117 QUnit.test('should support a `pattern` argument', function(assert) {
23120 assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
23121 assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
23124 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
23127 var strings = lodashStable.map(['a', 'b', 'c'], Object),
23128 actual = lodashStable.map(strings, _.words);
23130 assert.deepEqual(actual, [['a'], ['b'], ['c']]);
23133 QUnit.test('should work with compound words', function(assert) {
23136 assert.deepEqual(_.words('12Feet'), ['12', 'Feet']);
23137 assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']);
23138 assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']);
23139 assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']);
23140 assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
23141 assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
23142 assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
23143 assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
23144 assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
23147 QUnit.test('should work with compound words containing diacritical marks', function(assert) {
23150 assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
23151 assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
23152 assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
23156 /*--------------------------------------------------------------------------*/
23158 QUnit.module('lodash.wrap');
23161 QUnit.test('should create a wrapped function', function(assert) {
23164 var p = _.wrap(_.escape, function(func, text) {
23165 return '<p>' + func(text) + '</p>';
23168 assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
23171 QUnit.test('should provide the correct `wrapper` arguments', function(assert) {
23176 var wrapped = _.wrap(noop, function() {
23177 args || (args = slice.call(arguments));
23181 assert.deepEqual(args, [noop, 1, 2, 3]);
23184 QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
23187 var values = [, null, undefined],
23188 expected = lodashStable.map(values, alwaysA);
23190 var actual = lodashStable.map(values, function(value, index) {
23191 var wrapped = index ? _.wrap('a', value) : _.wrap('a');
23192 return wrapped('b', 'c');
23195 assert.deepEqual(actual, expected);
23198 QUnit.test('should not set a `this` binding', function(assert) {
23201 var p = _.wrap(_.escape, function(func) {
23202 return '<p>' + func(this.text) + '</p>';
23205 var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
23206 assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
23210 /*--------------------------------------------------------------------------*/
23212 QUnit.module('xor methods');
23214 lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
23215 var args = (function() { return arguments; }(1, 2, 3)),
23216 func = _[methodName];
23218 QUnit.test('`_.' + methodName + '` should return the symmetric difference of the given arrays', function(assert) {
23221 var actual = func([1, 2, 5], [2, 3, 5], [3, 4, 5]);
23222 assert.deepEqual(actual, [1, 4, 5]);
23225 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
23228 var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
23229 assert.deepEqual(actual, [1, 4, 5]);
23231 actual = func([1, 1]);
23232 assert.deepEqual(actual, [1]);
23235 QUnit.test('`_.' + methodName + '` should return a new array when a single array is given', function(assert) {
23239 assert.notStrictEqual(func(array), array);
23242 QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
23246 assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
23249 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
23252 var array = [1, 2];
23253 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
23254 assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
23255 assert.deepEqual(func(array, null, args, null), [3]);
23258 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
23262 var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
23263 assert.ok(wrapped instanceof _);
23266 skipAssert(assert);
23270 QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
23274 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
23275 wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
23277 var actual = lodashStable.map(['head', 'last'], function(methodName) {
23278 return wrapped[methodName]();
23281 assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
23284 skipAssert(assert);
23289 /*--------------------------------------------------------------------------*/
23291 QUnit.module('lodash.xorBy');
23294 QUnit.test('should accept an `iteratee` argument', function(assert) {
23297 var actual = _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
23298 assert.deepEqual(actual, [1.2, 4.3]);
23300 actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
23301 assert.deepEqual(actual, [{ 'x': 2 }]);
23304 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
23309 _.xorBy([2.1, 1.2], [4.3, 2.4], function() {
23310 args || (args = slice.call(arguments));
23313 assert.deepEqual(args, [4.3]);
23317 /*--------------------------------------------------------------------------*/
23319 QUnit.module('lodash.xorWith');
23322 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
23324 QUnit.test('should work with a `comparator` argument', function(assert) {
23327 var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
23328 actual = _.xorWith(objects, others, lodashStable.isEqual);
23330 assert.deepEqual(actual, [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]);
23334 /*--------------------------------------------------------------------------*/
23336 QUnit.module('zipObject methods');
23338 lodashStable.each(['zipObject', 'zipObjectDeep'], function(methodName) {
23339 var func = _[methodName],
23340 array = [['barney', 36], ['fred', 40]],
23341 object = { 'barney': 36, 'fred': 40 },
23342 isDeep = methodName == 'zipObjectDeep';
23344 QUnit.test('`_.' + methodName + '` should zip together key/value arrays into an object', function(assert) {
23347 var actual = func(['barney', 'fred'], [36, 40]);
23348 assert.deepEqual(actual, object);
23351 QUnit.test('`_.' + methodName + '` should ignore extra `values`', function(assert) {
23354 assert.deepEqual(func(['a'], [1, 2]), { 'a': 1 });
23357 QUnit.test('`_.' + methodName + '` should assign `undefined` values for extra `keys`', function(assert) {
23360 assert.deepEqual(func(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
23363 QUnit.test('`_.' + methodName + '` should ' + (isDeep ? '' : 'not ') + 'support deep paths', function(assert) {
23366 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path, index) {
23367 var expected = isDeep ? ({ 'a': { 'b': { 'c': 1 } } }) : (index ? { 'a,b,c': 1 } : { 'a.b.c': 1 });
23368 assert.deepEqual(func([path], [1]), expected);
23372 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
23376 var values = lodashStable.range(LARGE_ARRAY_SIZE),
23377 props = lodashStable.map(values, function(value) { return 'key' + value; }),
23378 actual = _(props)[methodName](values).map(square).filter(isEven).take().value();
23380 assert.deepEqual(actual, _.take(_.filter(_.map(func(props, values), square), isEven)));
23383 skipAssert(assert);
23388 /*--------------------------------------------------------------------------*/
23390 QUnit.module('lodash.zipWith');
23393 QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
23396 var array1 = [1, 2, 3],
23397 array2 = [4, 5, 6],
23398 array3 = [7, 8, 9];
23400 var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
23404 assert.deepEqual(actual, [12, 15, 18]);
23406 var actual = _.zipWith(array1, [], function(a, b) {
23407 return a + (b || 0);
23410 assert.deepEqual(actual, [1, 2, 3]);
23413 QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
23418 _.zipWith([1, 2], [3, 4], [5, 6], function() {
23419 args || (args = slice.call(arguments));
23422 assert.deepEqual(args, [1, 3, 5]);
23425 QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
23428 var array1 = [1, 2],
23430 values = [, null, undefined],
23431 expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
23433 var actual = lodashStable.map(values, function(value, index) {
23434 return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
23437 assert.deepEqual(actual, expected);
23441 /*--------------------------------------------------------------------------*/
23443 QUnit.module('lodash.unzip and lodash.zip');
23445 lodashStable.each(['unzip', 'zip'], function(methodName, index) {
23446 var func = _[methodName];
23447 func = lodashStable.bind(index ? func.apply : func.call, func, null);
23450 'an empty array': [
23459 [['barney', 'fred'], [36, 40]],
23460 [['barney', 36], ['fred', 40]]
23463 [['barney', 'fred'], [36, 40], [true, false]],
23464 [['barney', 36, true], ['fred', 40, false]]
23468 lodashStable.forOwn(object, function(pair, key) {
23469 QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
23472 var actual = func(pair[0]);
23473 assert.deepEqual(actual, pair[1]);
23474 assert.deepEqual(func(actual), actual.length ? pair[0] : []);
23478 QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
23482 [['barney', 36], ['fred', 40, false]],
23483 [['barney', 'fred'], [36, 40], [undefined, false]]
23486 var actual = func(pair[0]);
23487 assert.ok('0' in actual[2]);
23488 assert.deepEqual(actual, pair[1]);
23490 actual = func(actual);
23491 assert.ok('2' in actual[0]);
23492 assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
23495 QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
23498 var expected = lodashStable.map(falsey, alwaysEmptyArray);
23500 var actual = lodashStable.map(falsey, function(value) {
23501 return func([value, value, value]);
23504 assert.deepEqual(actual, expected);
23507 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
23510 var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
23511 assert.deepEqual(func(array), [[1, 3], [2, 4]]);
23514 QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
23517 var expected = [['barney', 'fred'], [36, 40]];
23518 assert.deepEqual(func(func(func(func(expected)))), expected);
23522 /*--------------------------------------------------------------------------*/
23524 QUnit.module('lodash(...).commit');
23527 QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
23532 wrapped = _(array).push(2).push(3);
23534 assert.deepEqual(array, [1]);
23536 var otherWrapper = wrapped.commit();
23537 assert.ok(otherWrapper instanceof _);
23538 assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
23539 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
23542 skipAssert(assert, 4);
23546 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
23550 var wrapped = _([1]).chain().commit().head();
23551 assert.ok(wrapped instanceof _);
23552 assert.strictEqual(wrapped.value(), 1);
23555 skipAssert(assert, 2);
23560 /*--------------------------------------------------------------------------*/
23562 QUnit.module('lodash(...).next');
23564 lodashStable.each([true, false], function(implict) {
23565 function chain(value) {
23566 return implict ? _(value) : _.chain(value);
23569 var chainType = 'in an ' + (implict ? 'implict' : 'explict') + ' chain';
23571 QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
23575 var wrapped = chain([1, 2]);
23577 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
23578 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
23579 assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
23582 skipAssert(assert, 3);
23586 QUnit.test('should act as an iterable ' + chainType, function(assert) {
23589 if (!isNpm && Symbol && Symbol.iterator) {
23590 var array = [1, 2],
23591 wrapped = chain(array);
23593 assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
23594 assert.deepEqual(_.toArray(wrapped), array);
23597 skipAssert(assert, 2);
23601 QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
23604 if (!isNpm && Array.from) {
23605 var hearts = '\ud83d\udc95',
23606 values = [[1], { 'a': 1 }, hearts];
23608 lodashStable.each(values, function(value) {
23609 var wrapped = chain(value);
23610 assert.deepEqual(Array.from(wrapped), _.toArray(value));
23614 skipAssert(assert, 3);
23618 QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
23621 if (!isNpm && Symbol && Symbol.iterator) {
23622 var array = [1, 2],
23623 wrapped = chain(array);
23625 assert.deepEqual(_.toArray(wrapped), array);
23626 assert.deepEqual(_.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
23628 var other = wrapped.filter();
23629 assert.deepEqual(_.toArray(other), array, 'reset for new chain segments');
23630 assert.deepEqual(_.toArray(wrapped), [], 'iterator is still exhausted');
23633 skipAssert(assert, 4);
23637 QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
23640 if (!isNpm && Symbol && Symbol.iterator) {
23641 var array = lodashStable.range(LARGE_ARRAY_SIZE),
23642 predicate = function(value) { values.push(value); return isEven(value); },
23644 wrapped = chain(array);
23646 assert.deepEqual(_.toArray(wrapped), array);
23648 wrapped = wrapped.filter(predicate);
23649 assert.deepEqual(_.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
23650 assert.deepEqual(values, array, 'memoizes iterator values');
23653 skipAssert(assert, 3);
23658 /*--------------------------------------------------------------------------*/
23660 QUnit.module('lodash(...).plant');
23663 QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
23667 var array1 = [5, null, 3, null, 1],
23668 array2 = [10, null, 8, null, 6],
23669 wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
23670 wrapped2 = wrapped1.plant(array2);
23672 assert.deepEqual(wrapped2.value(), [36, 64]);
23673 assert.deepEqual(wrapped1.value(), [1, 9]);
23676 skipAssert(assert, 2);
23680 QUnit.test('should clone `chainAll` settings', function(assert) {
23684 var array1 = [2, 4],
23686 wrapped1 = _(array1).chain().map(square),
23687 wrapped2 = wrapped1.plant(array2);
23689 assert.deepEqual(wrapped2.head().value(), 36);
23692 skipAssert(assert);
23696 QUnit.test('should reset iterator data on cloned sequences', function(assert) {
23699 if (!isNpm && Symbol && Symbol.iterator) {
23700 var array1 = [2, 4],
23702 wrapped1 = _(array1).map(square);
23704 assert.deepEqual(_.toArray(wrapped1), [4, 16]);
23705 assert.deepEqual(_.toArray(wrapped1), []);
23707 var wrapped2 = wrapped1.plant(array2);
23708 assert.deepEqual(_.toArray(wrapped2), [36, 64]);
23711 skipAssert(assert, 3);
23716 /*--------------------------------------------------------------------------*/
23718 QUnit.module('lodash(...).pop');
23721 QUnit.test('should remove elements from the end of `array`', function(assert) {
23725 var array = [1, 2],
23726 wrapped = _(array);
23728 assert.strictEqual(wrapped.pop(), 2);
23729 assert.deepEqual(wrapped.value(), [1]);
23730 assert.strictEqual(wrapped.pop(), 1);
23732 var actual = wrapped.value();
23733 assert.deepEqual(actual, []);
23734 assert.strictEqual(actual, array);
23737 skipAssert(assert, 5);
23742 /*--------------------------------------------------------------------------*/
23744 QUnit.module('lodash(...).push');
23747 QUnit.test('should append elements to `array`', function(assert) {
23752 wrapped = _(array).push(2, 3),
23753 actual = wrapped.value();
23755 assert.strictEqual(actual, array);
23756 assert.deepEqual(actual, [1, 2, 3]);
23759 skipAssert(assert, 2);
23764 /*--------------------------------------------------------------------------*/
23766 QUnit.module('lodash(...).shift');
23769 QUnit.test('should remove elements from the front of `array`', function(assert) {
23773 var array = [1, 2],
23774 wrapped = _(array);
23776 assert.strictEqual(wrapped.shift(), 1);
23777 assert.deepEqual(wrapped.value(), [2]);
23778 assert.strictEqual(wrapped.shift(), 2);
23780 var actual = wrapped.value();
23781 assert.deepEqual(actual, []);
23782 assert.strictEqual(actual, array);
23785 skipAssert(assert, 5);
23790 /*--------------------------------------------------------------------------*/
23792 QUnit.module('lodash(...).sort');
23795 QUnit.test('should return the wrapped sorted `array`', function(assert) {
23799 var array = [3, 1, 2],
23800 wrapped = _(array).sort(),
23801 actual = wrapped.value();
23803 assert.strictEqual(actual, array);
23804 assert.deepEqual(actual, [1, 2, 3]);
23807 skipAssert(assert, 2);
23812 /*--------------------------------------------------------------------------*/
23814 QUnit.module('lodash(...).splice');
23817 QUnit.test('should support removing and inserting elements', function(assert) {
23821 var array = [1, 2],
23822 wrapped = _(array);
23824 assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
23825 assert.deepEqual(wrapped.value(), [1, 3]);
23826 assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
23828 var actual = wrapped.value();
23829 assert.deepEqual(actual, []);
23830 assert.strictEqual(actual, array);
23833 skipAssert(assert, 5);
23838 /*--------------------------------------------------------------------------*/
23840 QUnit.module('lodash(...).unshift');
23843 QUnit.test('should prepend elements to `array`', function(assert) {
23848 wrapped = _(array).unshift(1, 2),
23849 actual = wrapped.value();
23851 assert.strictEqual(actual, array);
23852 assert.deepEqual(actual, [1, 2, 3]);
23855 skipAssert(assert, 2);
23860 /*--------------------------------------------------------------------------*/
23862 QUnit.module('lodash(...).value');
23865 QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
23870 wrapped = _(array).push(2).push(3);
23872 assert.deepEqual(array, [1]);
23873 assert.deepEqual(wrapped.value(), [1, 2, 3]);
23874 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
23875 assert.deepEqual(array, [1, 2, 3, 2, 3]);
23878 skipAssert(assert, 4);
23882 QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
23886 var wrapped = _(123);
23887 assert.strictEqual(Number(wrapped), 123);
23890 skipAssert(assert);
23894 QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
23897 if (!isNpm && JSON) {
23898 var wrapped = _([1, 2, 3]);
23899 assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
23902 skipAssert(assert);
23906 QUnit.test('should be aliased', function(assert) {
23910 var expected = _.prototype.value;
23911 assert.strictEqual(_.prototype.toJSON, expected);
23912 assert.strictEqual(_.prototype.valueOf, expected);
23915 skipAssert(assert, 2);
23920 /*--------------------------------------------------------------------------*/
23922 QUnit.module('lodash(...) methods that return the wrapped modified array');
23932 lodashStable.each(funcs, function(methodName) {
23933 QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
23937 var array = [1, 2, 3],
23938 wrapped = _(array),
23939 actual = wrapped[methodName]();
23941 assert.ok(actual instanceof _);
23942 assert.notStrictEqual(actual, wrapped);
23945 skipAssert(assert, 2);
23951 /*--------------------------------------------------------------------------*/
23953 QUnit.module('lodash(...) methods that return new wrapped values');
23971 lodashStable.each(funcs, function(methodName) {
23972 QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
23976 var value = methodName == 'split' ? 'abc' : [1, 2, 3],
23977 wrapped = _(value),
23978 actual = wrapped[methodName]();
23980 assert.ok(actual instanceof _);
23981 assert.notStrictEqual(actual, wrapped);
23984 skipAssert(assert, 2);
23990 /*--------------------------------------------------------------------------*/
23992 QUnit.module('lodash(...) methods that return unwrapped values');
24084 lodashStable.each(funcs, function(methodName) {
24085 QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
24089 var array = [1, 2, 3],
24090 actual = _(array)[methodName]();
24092 assert.notOk(actual instanceof _);
24095 skipAssert(assert);
24099 QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
24103 var array = [1, 2, 3],
24104 actual = _(array).chain()[methodName]();
24106 assert.ok(actual instanceof _);
24109 skipAssert(assert);
24115 /*--------------------------------------------------------------------------*/
24117 QUnit.module('"Arrays" category methods');
24120 var args = (function() { return arguments; }(1, null, [3], null, 5)),
24121 sortedArgs = (function() { return arguments; }(1, [3], 5, null, null)),
24122 array = [1, 2, 3, 4, 5, 6];
24124 QUnit.test('should work with `arguments` objects', function(assert) {
24127 function message(methodName) {
24128 return '`_.' + methodName + '` should work with `arguments` objects';
24131 assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
24132 assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
24134 assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
24135 assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
24137 assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
24138 assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
24139 assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
24140 assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
24141 assert.deepEqual(_.dropWhile(args,identity), [null, [3], null, 5], message('dropWhile'));
24142 assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
24143 assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
24144 assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
24145 assert.deepEqual(_.head(args), 1, message('head'));
24146 assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
24147 assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
24148 assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
24149 assert.deepEqual(_.last(args), 5, message('last'));
24150 assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
24151 assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
24152 assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
24153 assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
24154 assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
24155 assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
24156 assert.deepEqual(_.take(args, 2), [1, null], message('take'));
24157 assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
24158 assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
24159 assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
24160 assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
24161 assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
24162 assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
24165 QUnit.test('should accept falsey primary arguments', function(assert) {
24168 function message(methodName) {
24169 return '`_.' + methodName + '` should accept falsey primary arguments';
24172 assert.deepEqual(_.difference(null, array), [], message('difference'));
24173 assert.deepEqual(_.intersection(null, array), [], message('intersection'));
24174 assert.deepEqual(_.union(null, array), array, message('union'));
24175 assert.deepEqual(_.xor(null, array), array, message('xor'));
24178 QUnit.test('should accept falsey secondary arguments', function(assert) {
24181 function message(methodName) {
24182 return '`_.' + methodName + '` should accept falsey secondary arguments';
24185 assert.deepEqual(_.difference(array, null), array, message('difference'));
24186 assert.deepEqual(_.intersection(array, null), [], message('intersection'));
24187 assert.deepEqual(_.union(array, null), array, message('union'));
24191 /*--------------------------------------------------------------------------*/
24193 QUnit.module('"Strings" category methods');
24196 var stringMethods = [
24219 lodashStable.each(stringMethods, function(methodName) {
24220 var func = _[methodName];
24222 QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
24225 var values = [, null, undefined, ''],
24226 expected = lodashStable.map(values, alwaysEmptyString);
24228 var actual = lodashStable.map(values, function(value, index) {
24229 return index ? func(value) : func();
24232 assert.deepEqual(actual, expected);
24237 /*--------------------------------------------------------------------------*/
24239 QUnit.module('lodash methods');
24242 var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
24243 return lodashStable.startsWith(methodName, '_');
24284 var rejectFalsey = [
24287 ].concat(checkFuncs);
24289 var returnArrays = [
24327 var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
24329 QUnit.test('should accept falsey arguments', function(assert) {
24330 assert.expect(297);
24332 var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
24334 lodashStable.each(acceptFalsey, function(methodName) {
24335 var expected = emptyArrays,
24336 func = _[methodName],
24339 var actual = lodashStable.map(falsey, function(value, index) {
24341 return index ? func(value) : func();
24347 if (methodName == 'noConflict') {
24350 else if (methodName == 'pull' || methodName == 'pullAll') {
24353 if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
24354 assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
24356 assert.ok(pass, '`_.' + methodName + '` accepts falsey arguments');
24359 // Skip tests for missing methods of modularized builds.
24360 lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
24361 if (!_[methodName]) {
24362 skipAssert(assert);
24367 QUnit.test('should return an array', function(assert) {
24370 var array = [1, 2, 3];
24372 lodashStable.each(returnArrays, function(methodName) {
24374 func = _[methodName];
24376 switch (methodName) {
24378 actual = func(array, 'toFixed');
24381 actual = func(array, 1);
24384 actual = func(array);
24386 assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
24388 var isPull = methodName == 'pull' || methodName == 'pullAll';
24389 assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the given array');
24393 QUnit.test('should throw an error for falsey arguments', function(assert) {
24396 lodashStable.each(rejectFalsey, function(methodName) {
24397 var expected = lodashStable.map(falsey, alwaysTrue),
24398 func = _[methodName];
24400 var actual = lodashStable.map(falsey, function(value, index) {
24401 var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
24404 index ? func(value) : func();
24406 pass = !pass && (e instanceof TypeError) &&
24407 (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
24412 assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
24416 QUnit.test('should not set a `this` binding', function(assert) {
24419 lodashStable.each(noBinding, function(methodName) {
24420 var fn = function() { return this.a; },
24421 func = _[methodName],
24422 isNegate = methodName == 'negate',
24423 object = { 'a': 1 },
24424 expected = isNegate ? false : 1;
24426 var wrapper = func(_.bind(fn, object));
24427 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
24429 wrapper = _.bind(func(fn), object);
24430 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
24432 object.wrapper = func(fn);
24433 assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
24437 QUnit.test('should not contain minified method names (test production builds)', function(assert) {
24440 var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
24441 assert.ok(lodashStable.every(_.functions(_), function(methodName) {
24442 return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
24447 /*--------------------------------------------------------------------------*/
24449 QUnit.config.asyncRetries = 10;
24450 QUnit.config.hidepassed = true;
24453 QUnit.config.noglobals = true;