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 the maximum memoize cache size. */
16 var MAX_MEMOIZE_SIZE = 500;
18 /** Used as references for various `Number` constants. */
19 var MAX_SAFE_INTEGER = 9007199254740991,
20 MAX_INTEGER = 1.7976931348623157e+308;
22 /** Used as references for the maximum length and index of an array. */
23 var MAX_ARRAY_LENGTH = 4294967295,
24 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
26 /** `Object#toString` result references. */
27 var funcTag = '[object Function]',
28 numberTag = '[object Number]',
29 objectTag = '[object Object]';
31 /** Used as a reference to the global object. */
32 var root = (typeof global == 'object' && global) || this;
34 /** Used to store lodash to test for bad extensions/shims. */
35 var lodashBizarro = root.lodashBizarro;
37 /** Used for native method references. */
38 var arrayProto = Array.prototype,
39 funcProto = Function.prototype,
40 objectProto = Object.prototype,
41 numberProto = Number.prototype,
42 stringProto = String.prototype;
44 /** Method and object shortcuts. */
45 var phantom = root.phantom,
46 process = root.process,
47 amd = root.define ? define.amd : undefined,
48 args = toArgs([1, 2, 3]),
49 argv = process ? process.argv : undefined,
50 defineProperty = Object.defineProperty,
51 document = phantom ? undefined : root.document,
52 body = root.document ? root.document.body : undefined,
53 create = Object.create,
54 fnToString = funcProto.toString,
55 freeze = Object.freeze,
56 getSymbols = Object.getOwnPropertySymbols,
57 identity = function(value) { return value; },
59 objToString = objectProto.toString,
61 push = arrayProto.push,
63 slice = arrayProto.slice,
64 strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
66 var ArrayBuffer = root.ArrayBuffer,
69 Promise = root.Promise,
73 Uint8Array = root.Uint8Array,
74 WeakMap = root.WeakMap,
75 WeakSet = root.WeakSet;
77 var arrayBuffer = ArrayBuffer ? new ArrayBuffer(2) : undefined,
78 map = Map ? new Map : undefined,
79 promise = Promise ? Promise.resolve(1) : undefined,
80 set = Set ? new Set : undefined,
81 symbol = Symbol ? Symbol('a') : undefined,
82 weakMap = WeakMap ? new WeakMap : undefined,
83 weakSet = WeakSet ? new WeakSet : undefined;
86 var add = function(x, y) { return x + y; },
87 doubled = function(n) { return n * 2; },
88 isEven = function(n) { return n % 2 == 0; },
89 square = function(n) { return n * n; };
91 /** Stub functions. */
92 var stubA = function() { return 'a'; },
93 stubB = function() { return 'b'; },
94 stubC = function() { return 'c'; };
96 var stubTrue = function() { return true; },
97 stubFalse = function() { return false; };
99 var stubNaN = function() { return NaN; },
100 stubNull = function() { return null; };
102 var stubZero = function() { return 0; },
103 stubOne = function() { return 1; },
104 stubTwo = function() { return 2; },
105 stubThree = function() { return 3; },
106 stubFour = function() { return 4; };
108 var stubArray = function() { return []; },
109 stubObject = function() { return {}; },
110 stubString = function() { return ''; };
112 /** List of Latin Unicode letters. */
113 var burredLetters = [
114 // Latin-1 Supplement letters.
115 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
116 '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
117 '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
118 '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff',
119 // Latin Extended-A letters.
120 '\u0100', '\u0101', '\u0102', '\u0103', '\u0104', '\u0105', '\u0106', '\u0107', '\u0108', '\u0109', '\u010a', '\u010b', '\u010c', '\u010d', '\u010e', '\u010f',
121 '\u0110', '\u0111', '\u0112', '\u0113', '\u0114', '\u0115', '\u0116', '\u0117', '\u0118', '\u0119', '\u011a', '\u011b', '\u011c', '\u011d', '\u011e', '\u011f',
122 '\u0120', '\u0121', '\u0122', '\u0123', '\u0124', '\u0125', '\u0126', '\u0127', '\u0128', '\u0129', '\u012a', '\u012b', '\u012c', '\u012d', '\u012e', '\u012f',
123 '\u0130', '\u0131', '\u0132', '\u0133', '\u0134', '\u0135', '\u0136', '\u0137', '\u0138', '\u0139', '\u013a', '\u013b', '\u013c', '\u013d', '\u013e', '\u013f',
124 '\u0140', '\u0141', '\u0142', '\u0143', '\u0144', '\u0145', '\u0146', '\u0147', '\u0148', '\u0149', '\u014a', '\u014b', '\u014c', '\u014d', '\u014e', '\u014f',
125 '\u0150', '\u0151', '\u0152', '\u0153', '\u0154', '\u0155', '\u0156', '\u0157', '\u0158', '\u0159', '\u015a', '\u015b', '\u015c', '\u015d', '\u015e', '\u015f',
126 '\u0160', '\u0161', '\u0162', '\u0163', '\u0164', '\u0165', '\u0166', '\u0167', '\u0168', '\u0169', '\u016a', '\u016b', '\u016c', '\u016d', '\u016e', '\u016f',
127 '\u0170', '\u0171', '\u0172', '\u0173', '\u0174', '\u0175', '\u0176', '\u0177', '\u0178', '\u0179', '\u017a', '\u017b', '\u017c', '\u017d', '\u017e', '\u017f'
130 /** List of combining diacritical marks. */
132 '\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305', '\u0306', '\u0307', '\u0308', '\u0309', '\u030a', '\u030b', '\u030c', '\u030d', '\u030e', '\u030f',
133 '\u0310', '\u0311', '\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317', '\u0318', '\u0319', '\u031a', '\u031b', '\u031c', '\u031d', '\u031e', '\u031f',
134 '\u0320', '\u0321', '\u0322', '\u0323', '\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329', '\u032a', '\u032b', '\u032c', '\u032d', '\u032e', '\u032f',
135 '\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339', '\u033a', '\u033b', '\u033c', '\u033d', '\u033e', '\u033f',
136 '\u0340', '\u0341', '\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347', '\u0348', '\u0349', '\u034a', '\u034b', '\u034c', '\u034d', '\u034e', '\u034f',
137 '\u0350', '\u0351', '\u0352', '\u0353', '\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359', '\u035a', '\u035b', '\u035c', '\u035d', '\u035e', '\u035f',
138 '\u0360', '\u0361', '\u0362', '\u0363', '\u0364', '\u0365', '\u0366', '\u0367', '\u0368', '\u0369', '\u036a', '\u036b', '\u036c', '\u036d', '\u036e', '\u036f',
139 '\ufe20', '\ufe21', '\ufe22', '\ufe23'
142 /** List of converted Latin Unicode letters. */
143 var deburredLetters = [
144 // Converted Latin-1 Supplement letters.
145 'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
146 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th',
147 'ss', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
148 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y',
149 // Converted Latin Extended-A letters.
150 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c',
151 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e',
152 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h',
153 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j',
154 'K', 'k', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l',
155 'N', 'n', 'N', 'n', 'N', 'n', "'n", 'N', 'n',
156 'O', 'o', 'O', 'o', 'O', 'o', 'Oe', 'oe',
157 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's',
158 'T', 't', 'T', 't', 'T', 't',
159 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u',
160 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's'
163 /** Used to provide falsey values to methods. */
164 var falsey = [, null, undefined, false, 0, NaN, ''];
166 /** Used to specify the emoji style glyph variant of characters. */
167 var emojiVar = '\ufe0f';
169 /** Used to provide empty values to methods. */
170 var empties = [[], {}].concat(falsey.slice(1));
172 /** Used to test error objects. */
183 /** List of fitzpatrick modifiers. */
184 var fitzModifiers = [
192 /** Used to provide primitive values to methods. */
193 var primitives = [null, undefined, false, true, 1, NaN, 'a'];
195 /** Used to check whether methods support typed arrays. */
208 /** Used to check whether methods support array views. */
209 var arrayViews = typedArrays.concat('DataView');
211 /** The file path of the lodash file to test. */
212 var filePath = (function() {
214 result = params || [];
218 result = params = phantom.args || require('system').args;
220 var last = result[result.length - 1];
221 result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js';
225 result = require('fs').realpathSync(result);
229 result = require.resolve(result);
235 /** The `ui` object. */
236 var ui = root.ui || (root.ui = {
237 'buildPath': filePath,
239 'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
240 'isStrict': /\bes\b/.test(filePath) || 'default' in require(filePath),
244 /** The basename of the lodash file to test. */
245 var basename = /[\w.-]+$/.exec(filePath)[0];
247 /** Used to indicate testing a modularized build. */
248 var isModularize = ui.isModularize;
250 /** Detect if testing `npm` modules. */
251 var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
253 /** Detect if running in PhantomJS. */
254 var isPhantom = phantom || (typeof callPhantom == 'function');
256 /** Detect if lodash is in strict mode. */
257 var isStrict = ui.isStrict;
259 /*--------------------------------------------------------------------------*/
261 // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
262 root.msWDfn = undefined;
264 // Assign `setTimeout` to itself to avoid being flagged as a leak.
265 setProperty(root, 'setTimeout', setTimeout);
267 // Exit early if going to run tests in a PhantomJS web page.
268 if (phantom && isModularize) {
269 var page = require('webpage').create();
271 page.onCallback = function(details) {
272 var coverage = details.coverage;
274 var fs = require('fs'),
275 cwd = fs.workingDirectory,
278 fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
280 phantom.exit(details.failed ? 1 : 0);
283 page.onConsoleMessage = function(message) {
284 console.log(message);
287 page.onInitialized = function() {
288 page.evaluate(function() {
289 document.addEventListener('DOMContentLoaded', function() {
290 QUnit.done(function(details) {
291 details.coverage = window.__coverage__;
292 callPhantom(details);
298 page.open(filePath, function(status) {
299 if (status != 'success') {
300 console.log('PhantomJS failed to load page: ' + filePath);
305 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
309 /*--------------------------------------------------------------------------*/
311 /** Used to test Web Workers. */
312 var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
313 (document && document.origin != 'null') && root.Worker;
315 /** Used to test host objects in IE. */
317 var xml = new ActiveXObject('Microsoft.XMLDOM');
320 /** Poison the free variable `root` in Node.js */
322 defineProperty(global.root, 'root', {
323 'configurable': false,
325 'get': function() { throw new ReferenceError; }
329 /** Load QUnit and extras. */
330 var QUnit = root.QUnit || require('qunit-extras');
332 /** Load stable Lodash. */
333 var lodashStable = root.lodashStable;
336 lodashStable = interopRequire('../node_modules/lodash/lodash.js');
338 console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
341 lodashStable = lodashStable.noConflict();
344 /** The `lodash` function to test. */
345 var _ = root._ || (root._ = interopRequire(filePath));
347 /** Used to test pseudo private map caches. */
348 var mapCaches = (function() {
349 var MapCache = _.memoize.Cache;
351 'Hash': new MapCache().__data__.hash.constructor,
354 _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
355 var stack = lodashStable.last(arguments);
356 result.ListCache = stack.__data__.constructor;
357 result.Stack = stack.constructor;
362 /** Used to detect instrumented istanbul code coverage runs. */
363 var coverage = root.__coverage__ || root[lodashStable.find(lodashStable.keys(root), function(key) {
364 return /^(?:\$\$cov_\d+\$\$)$/.test(key);
367 /** Used to test async functions. */
368 var asyncFunc = lodashStable.attempt(function() {
369 return Function('return async () => {}');
372 /** Used to test generator functions. */
373 var genFunc = lodashStable.attempt(function() {
374 return Function('return function*(){}');
377 /** Used to restore the `_` reference. */
378 var oldDash = root._;
381 * Used to check for problems removing whitespace. For a whitespace reference,
382 * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
384 var whitespace = lodashStable.filter([
385 // Basic whitespace characters.
386 ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
389 '\n', '\r', '\u2028', '\u2029',
391 // Unicode category "Zs" space separators.
392 '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
393 '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
395 function(chr) { return /\s/.exec(chr); })
399 * Creates a custom error object.
403 * @param {string} message The error message.
405 function CustomError(message) {
406 this.name = 'CustomError';
407 this.message = message;
410 CustomError.prototype = lodashStable.create(Error.prototype, {
411 'constructor': CustomError
415 * Removes all own enumerable string keyed properties from a given object.
418 * @param {Object} object The object to empty.
420 function emptyObject(object) {
421 lodashStable.forOwn(object, function(value, key, object) {
427 * Extracts the unwrapped value from its wrapper.
430 * @param {Object} wrapper The wrapper to unwrap.
431 * @returns {*} Returns the unwrapped value.
433 function getUnwrappedValue(wrapper) {
435 actions = wrapper.__actions__,
436 length = actions.length,
437 result = wrapper.__wrapped__;
439 while (++index < length) {
441 action = actions[index];
443 push.apply(args, action.args);
444 result = action.func.apply(action.thisArg, args);
450 * Loads the module of `id`. If the module has an `exports.default`, the
451 * exported default value is returned as the resolved module.
454 * @param {string} id The identifier of the module to resolve.
455 * @returns {*} Returns the resolved module.
457 function interopRequire(id) {
458 var result = require(id);
459 return 'default' in result ? result['default'] : result;
463 * Sets a non-enumerable property value on `object`.
465 * Note: This function is used to avoid a bug in older versions of V8 where
466 * overwriting non-enumerable built-ins makes them enumerable.
467 * See https://code.google.com/p/v8/issues/detail?id=1623
470 * @param {Object} object The object modify.
471 * @param {string} key The name of the property to set.
472 * @param {*} value The property value.
474 function setProperty(object, key, value) {
476 defineProperty(object, key, {
477 'configurable': true,
489 * Skips a given number of tests with a passing result.
492 * @param {Object} assert The QUnit assert object.
493 * @param {number} [count=1] The number of tests to skip.
495 function skipAssert(assert, count) {
496 count || (count = 1);
498 assert.ok(true, 'test skipped');
503 * Converts `array` to an `arguments` object.
506 * @param {Array} array The array to convert.
507 * @returns {Object} Returns the converted `arguments` object.
509 function toArgs(array) {
510 return (function() { return arguments; }.apply(undefined, array));
513 /*--------------------------------------------------------------------------*/
515 // Add bizarro values.
517 if (document || (typeof require != 'function')) {
520 var nativeString = fnToString.call(toString),
521 reToString = /toString/g;
523 function createToString(funcName) {
524 return lodashStable.constant(nativeString.replace(reToString, funcName));
527 // Allow bypassing native checks.
528 setProperty(funcProto, 'toString', function wrapper() {
529 setProperty(funcProto, 'toString', fnToString);
530 var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
531 setProperty(funcProto, 'toString', wrapper);
535 // Add prototype extensions.
536 funcProto._method = noop;
539 setProperty(Object, 'create', undefined);
540 setProperty(Object, 'getOwnPropertySymbols', undefined);
542 var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
543 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
544 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
548 defineProperty(root, 'Buffer', {
549 'configurable': true,
551 'get': function get() {
552 var caller = get.caller,
553 name = caller ? caller.name : '';
555 if (!(name == 'runInContext' || name.length == 1 || /\b_\.isBuffer\b/.test(caller))) {
562 setProperty(root, 'Map', (function() {
568 setProperty(root, 'Map', Map);
573 setProperty(root.Map, 'toString', createToString('Map'));
575 setProperty(root, 'Promise', noop);
576 setProperty(root, 'Set', noop);
577 setProperty(root, 'Symbol', undefined);
578 setProperty(root, 'WeakMap', noop);
580 // Fake `WinRTError`.
581 setProperty(root, 'WinRTError', Error);
583 // Clear cache so lodash can be reloaded.
584 emptyObject(require.cache);
586 // Load lodash and expose it to the bad extensions/shims.
587 lodashBizarro = interopRequire(filePath);
590 // Restore built-in methods.
591 setProperty(Object, 'create', create);
592 setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
593 setProperty(root, 'Buffer', Buffer);
596 Object.getOwnPropertySymbols = getSymbols;
598 delete Object.getOwnPropertySymbols;
601 setProperty(root, 'Map', Map);
606 setProperty(root, 'Promise', Promise);
611 setProperty(root, 'Set', Set);
616 setProperty(root, 'Symbol', Symbol);
621 setProperty(root, 'WeakMap', WeakMap);
625 delete root.WinRTError;
626 delete funcProto._method;
629 // Add other realm values from the `vm` module.
630 lodashStable.attempt(function() {
631 lodashStable.assign(realm, require('vm').runInNewContext([
633 ' var noop = function() {},',
637 " 'ArrayBuffer': root.ArrayBuffer,",
638 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
640 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
641 " 'boolean': Object(false),",
642 " 'date': new Date,",
643 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
644 " 'function': noop,",
645 " 'map': root.Map ? new root.Map : undefined,",
648 " 'number': Object(0),",
649 " 'object': { 'a': 1 },",
650 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
652 " 'set': root.Set ? new root.Set : undefined,",
653 " 'string': Object('a'),",
654 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
655 " 'undefined': undefined,",
656 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
657 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
660 " ['" + arrayViews.join("', '") + "'].forEach(function(type) {",
661 ' var Ctor = root[type]',
662 ' object[type] = Ctor;',
663 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
671 // Add other realm values from an iframe.
672 lodashStable.attempt(function() {
675 var iframe = document.createElement('iframe');
676 iframe.frameBorder = iframe.height = iframe.width = 0;
677 body.appendChild(iframe);
679 var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
685 ' noop = function() {},',
689 " 'ArrayBuffer': root.ArrayBuffer,",
690 " 'arguments': (function() { return arguments; }(1, 2, 3)),",
692 " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
693 " 'boolean': Object(false),",
694 " 'date': new Date,",
695 " 'element': document.body,",
696 " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
697 " 'function': noop,",
698 " 'map': root.Map ? new root.Map : undefined,",
701 " 'number': Object(0),",
702 " 'object': { 'a': 1 },",
703 " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
705 " 'set': root.Set ? new root.Set : undefined,",
706 " 'string': Object('a'),",
707 " 'symbol': root.Symbol ? root.Symbol() : undefined,",
708 " 'undefined': undefined,",
709 " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
710 " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
713 "_.each(['" + arrayViews.join("', '") + "'], function(type) {",
714 ' var Ctor = root[type];',
715 ' object[type] = Ctor;',
716 ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
719 '_.assign(_._realm, object);',
730 lodashStable.attempt(function() {
731 var worker = new Worker('./asset/worker.js?t=' + (+new Date));
732 worker.addEventListener('message', function(e) {
733 _._VERSION = e.data || '';
736 worker.postMessage(ui.buildPath);
739 // Expose internal modules for better code coverage.
740 lodashStable.attempt(function() {
741 var path = require('path'),
742 basePath = path.dirname(filePath);
744 if (isModularize && !(amd || isNpm)) {
750 ], function(funcName) {
751 _['_' + funcName] = interopRequire(path.join(basePath, '_' + funcName));
756 /*--------------------------------------------------------------------------*/
759 console.log('Running lodash tests.');
760 console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
763 QUnit.module(basename);
766 QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
770 assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
777 QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
780 if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
781 assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
787 QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
791 assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
798 QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
801 var done = assert.async();
804 var limit = 30000 / QUnit.config.asyncRetries,
807 var attempt = function() {
808 var actual = _._VERSION;
809 if ((new Date - start) < limit && typeof actual != 'string') {
810 setTimeout(attempt, 16);
813 assert.strictEqual(actual, _.VERSION);
825 QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
829 assert.notOk('_method' in lodashBizarro);
836 QUnit.test('should avoid non-native built-ins', function(assert) {
839 function message(lodashMethod, nativeMethod) {
840 return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
848 var object = { 'a': 1 },
849 otherObject = { 'b': 2 },
850 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
854 var actual = lodashBizarro.create(Foo.prototype);
858 var label = message('_.create', 'Object.create');
859 assert.ok(actual instanceof Foo, label);
863 lodashBizarro.difference([object, otherObject], largeArray),
864 lodashBizarro.intersection(largeArray, [object]),
865 lodashBizarro.uniq(largeArray)
870 label = message('_.difference`, `_.intersection`, and `_.uniq', 'Map');
871 assert.deepEqual(actual, [[otherObject], [object], [object]], label);
878 lodashBizarro.clone(object),
879 lodashBizarro.cloneDeep(object)
884 label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
885 assert.deepEqual(actual, [object, object], label);
888 // Avoid buggy symbol detection in Babel's `_typeof` helper.
889 var symObject = setProperty(Object(symbol), 'constructor', Object);
891 Symbol ? lodashBizarro.clone(symObject) : {},
892 Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
893 Symbol ? lodashBizarro.toString(symObject) : ''
898 label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
899 assert.deepEqual(actual, [{}, false, ''], label);
902 var map = new lodashBizarro.memoize.Cache;
903 actual = map.set('a', 1).get('a');
907 label = message('_.memoize.Cache', 'Map');
908 assert.deepEqual(actual, 1, label);
911 map = new (Map || Object);
912 if (Symbol && Symbol.iterator) {
913 map[Symbol.iterator] = null;
915 actual = lodashBizarro.toArray(map);
919 label = message('_.toArray', 'Map');
920 assert.deepEqual(actual, [], label);
923 skipAssert(assert, 6);
928 /*--------------------------------------------------------------------------*/
930 QUnit.module('isIndex');
933 var func = _._isIndex;
935 QUnit.test('should return `true` for indexes', function(assert) {
939 var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
940 expected = lodashStable.map(values, stubTrue);
942 var actual = lodashStable.map(values, function(args) {
943 return func.apply(undefined, args);
946 assert.deepEqual(actual, expected);
953 QUnit.test('should return `false` for non-indexes', function(assert) {
957 var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
958 expected = lodashStable.map(values, stubFalse);
960 var actual = lodashStable.map(values, function(args) {
961 return func.apply(undefined, args);
964 assert.deepEqual(actual, expected);
972 /*--------------------------------------------------------------------------*/
974 QUnit.module('isIterateeCall');
978 func = _._isIterateeCall,
981 QUnit.test('should return `true` for iteratee calls', function(assert) {
988 assert.strictEqual(func(1, 0, array), true);
989 assert.strictEqual(func(1, 'a', object), true);
990 assert.strictEqual(func(1, 'a', new Foo), true);
993 skipAssert(assert, 3);
997 QUnit.test('should return `false` for non-iteratee calls', function(assert) {
1001 assert.strictEqual(func(2, 0, array), false);
1002 assert.strictEqual(func(1, 1.1, array), false);
1003 assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
1004 assert.strictEqual(func(1, 'b', object), false);
1007 skipAssert(assert, 4);
1011 QUnit.test('should work with `NaN` values', function(assert) {
1015 assert.strictEqual(func(NaN, 0, [NaN]), true);
1016 assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
1019 skipAssert(assert, 2);
1023 QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
1028 var actual = func(1, { 'toString': null }, [1]);
1030 var message = e.message;
1032 assert.strictEqual(actual, false, message || '');
1040 /*--------------------------------------------------------------------------*/
1042 QUnit.module('map caches');
1045 var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop];
1047 var pairs = lodashStable.map(keys, function(key, index) {
1048 var lastIndex = keys.length - 1;
1049 return [key, keys[lastIndex - index]];
1052 function createCaches(pairs) {
1053 var largeStack = new mapCaches.Stack(pairs),
1054 length = pairs ? pairs.length : 0;
1056 lodashStable.times(LARGE_ARRAY_SIZE - length, function() {
1057 largeStack.set({}, {});
1061 'hashes': new mapCaches.Hash(pairs),
1062 'list caches': new mapCaches.ListCache(pairs),
1063 'map caches': new mapCaches.MapCache(pairs),
1064 'stack caches': new mapCaches.Stack(pairs),
1065 'large stacks': largeStack
1069 lodashStable.forOwn(createCaches(pairs), function(cache, kind) {
1070 var isLarge = /^large/.test(kind);
1072 QUnit.test('should implement a `Map` interface for ' + kind, function(assert) {
1075 lodashStable.each(keys, function(key, index) {
1076 var value = pairs[index][1];
1078 assert.deepEqual(cache.get(key), value);
1079 assert.strictEqual(cache.has(key), true);
1080 assert.strictEqual(cache.delete(key), true);
1081 assert.strictEqual(cache.has(key), false);
1082 assert.strictEqual(cache.get(key), undefined);
1083 assert.strictEqual(cache.delete(key), false);
1084 assert.strictEqual(cache.set(key, value), cache);
1085 assert.strictEqual(cache.has(key), true);
1088 assert.strictEqual(cache.size, isLarge ? LARGE_ARRAY_SIZE : keys.length);
1089 assert.strictEqual(cache.clear(), undefined);
1090 assert.ok(lodashStable.every(keys, function(key) {
1091 return !cache.has(key);
1096 lodashStable.forOwn(createCaches(), function(cache, kind) {
1097 QUnit.test('should support changing values of ' + kind, function(assert) {
1100 lodashStable.each(keys, function(key) {
1101 cache.set(key, 1).set(key, 2);
1102 assert.strictEqual(cache.get(key), 2);
1108 /*--------------------------------------------------------------------------*/
1110 QUnit.module('lodash constructor');
1113 var values = empties.concat(true, 1, 'a'),
1114 expected = lodashStable.map(values, stubTrue);
1116 QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
1120 var actual = lodashStable.map(values, function(value) {
1121 return _(value) instanceof _;
1124 assert.deepEqual(actual, expected);
1131 QUnit.test('should return the given `lodash` instances', function(assert) {
1135 var actual = lodashStable.map(values, function(value) {
1136 var wrapped = _(value);
1137 return _(wrapped) === wrapped;
1140 assert.deepEqual(actual, expected);
1147 QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
1150 if (!isNpm && lodashBizarro) {
1151 var actual = lodashStable.map(values, function(value) {
1152 var wrapped = _(lodashBizarro(value)),
1153 unwrapped = wrapped.value();
1155 return wrapped instanceof _ &&
1156 ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
1159 assert.deepEqual(actual, expected);
1167 /*--------------------------------------------------------------------------*/
1169 QUnit.module('lodash.add');
1172 QUnit.test('should add two numbers', function(assert) {
1175 assert.strictEqual(_.add(6, 4), 10);
1176 assert.strictEqual(_.add(-6, 4), -2);
1177 assert.strictEqual(_.add(-6, -4), -10);
1180 QUnit.test('should not coerce arguments to numbers', function(assert) {
1183 assert.strictEqual(_.add('6', '4'), '64');
1184 assert.strictEqual(_.add('x', 'y'), 'xy');
1188 /*--------------------------------------------------------------------------*/
1190 QUnit.module('lodash.after');
1193 function after(n, times) {
1195 lodashStable.times(times, _.after(n, function() { count++; }));
1199 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1202 assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
1203 assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
1204 assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
1205 assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
1208 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1211 assert.strictEqual(after(NaN, 1), 1);
1214 QUnit.test('should use `this` binding of function', function(assert) {
1217 var after = _.after(1, function(assert) { return ++this.count; }),
1218 object = { 'after': after, 'count': 0 };
1221 assert.strictEqual(object.after(), 2);
1222 assert.strictEqual(object.count, 2);
1226 /*--------------------------------------------------------------------------*/
1228 QUnit.module('lodash.ary');
1231 function fn(a, b, c) {
1232 return slice.call(arguments);
1235 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
1238 var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
1239 assert.deepEqual(actual, [6, 8, 10]);
1241 var capped = _.ary(fn, 2);
1242 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
1245 QUnit.test('should use `func.length` if `n` is not given', function(assert) {
1248 var capped = _.ary(fn);
1249 assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
1252 QUnit.test('should treat a negative `n` as `0`', function(assert) {
1255 var capped = _.ary(fn, -1);
1258 var actual = capped('a');
1261 assert.deepEqual(actual, []);
1264 QUnit.test('should coerce `n` to an integer', function(assert) {
1267 var values = ['1', 1.6, 'xyz'],
1268 expected = [['a'], ['a'], []];
1270 var actual = lodashStable.map(values, function(n) {
1271 var capped = _.ary(fn, n);
1272 return capped('a', 'b');
1275 assert.deepEqual(actual, expected);
1278 QUnit.test('should not force a minimum argument count', function(assert) {
1281 var args = ['a', 'b', 'c'],
1282 capped = _.ary(fn, 3);
1284 var expected = lodashStable.map(args, function(arg, index) {
1285 return args.slice(0, index);
1288 var actual = lodashStable.map(expected, function(array) {
1289 return capped.apply(undefined, array);
1292 assert.deepEqual(actual, expected);
1295 QUnit.test('should use `this` binding of function', function(assert) {
1298 var capped = _.ary(function(a, b) { return this; }, 1),
1299 object = { 'capped': capped };
1301 assert.strictEqual(object.capped(), object);
1304 QUnit.test('should use the existing `ary` if smaller', function(assert) {
1307 var capped = _.ary(_.ary(fn, 1), 2);
1308 assert.deepEqual(capped('a', 'b', 'c'), ['a']);
1311 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
1314 var funcs = lodashStable.map([fn], _.ary),
1315 actual = funcs[0]('a', 'b', 'c');
1317 assert.deepEqual(actual, ['a', 'b', 'c']);
1320 QUnit.test('should work when combined with other methods that use metadata', function(assert) {
1323 var array = ['a', 'b', 'c'],
1324 includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
1326 assert.strictEqual(includes('b')(array, 2), true);
1329 includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
1330 assert.strictEqual(includes('b')(array, 2), true);
1338 /*--------------------------------------------------------------------------*/
1340 QUnit.module('lodash.assignIn');
1343 QUnit.test('should be aliased', function(assert) {
1346 assert.strictEqual(_.extend, _.assignIn);
1350 /*--------------------------------------------------------------------------*/
1352 QUnit.module('lodash.assign and lodash.assignIn');
1354 lodashStable.each(['assign', 'assignIn'], function(methodName) {
1355 var func = _[methodName];
1357 QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
1360 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
1363 QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
1366 var expected = { 'a': 1, 'b': 2, 'c': 3 };
1367 assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
1368 assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
1371 QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
1374 var expected = { 'a': 3, 'b': 2, 'c': 1 };
1375 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1378 QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
1381 var expected = { 'a': null, 'b': undefined, 'c': null };
1382 assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
1385 QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
1391 'configurable': true,
1393 'set': function() { throw new Error; }
1401 'constructor': Object,
1402 'toString': lodashStable.constant('source')
1405 defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
1409 defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
1413 defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
1417 defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
1418 'get': lodashStable.constant(Object)
1422 var actual = func(object, source);
1425 assert.deepEqual(actual, source);
1428 QUnit.test('`_.' + methodName + '` should treat sparse array sources as dense', function(assert) {
1434 assert.deepEqual(func({}, array), { '0': 1, '1': undefined, '2': 3 });
1437 QUnit.test('`_.' + methodName + '` should assign values of prototype objects', function(assert) {
1441 Foo.prototype.a = 1;
1443 assert.deepEqual(func({}, Foo.prototype), { 'a': 1 });
1446 QUnit.test('`_.' + methodName + '` should coerce string sources to objects', function(assert) {
1449 assert.deepEqual(func({}, 'a'), { '0': 'a' });
1453 /*--------------------------------------------------------------------------*/
1455 QUnit.module('lodash.assignInWith');
1458 QUnit.test('should be aliased', function(assert) {
1461 assert.strictEqual(_.extendWith, _.assignInWith);
1465 /*--------------------------------------------------------------------------*/
1467 QUnit.module('lodash.assignWith and lodash.assignInWith');
1469 lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
1470 var func = _[methodName];
1472 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
1475 var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
1476 return a === undefined ? b : a;
1479 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
1482 QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
1485 var expected = { 'a': 1 };
1486 assert.deepEqual(func({}, expected, noop), expected);
1490 /*--------------------------------------------------------------------------*/
1492 QUnit.module('lodash.at');
1495 var array = ['a', 'b', 'c'],
1496 object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
1498 QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
1501 var actual = _.at(array, [0, 2]);
1502 assert.deepEqual(actual, ['a', 'c']);
1505 QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
1508 var actual = _.at(array, [2, 4, 0]);
1509 assert.deepEqual(actual, ['c', undefined, 'a']);
1512 QUnit.test('should work with non-index keys on array values', function(assert) {
1515 var values = lodashStable.reject(empties, function(value) {
1516 return (value === 0) || lodashStable.isArray(value);
1519 var array = lodashStable.transform(values, function(result, value) {
1523 var expected = lodashStable.map(values, stubOne),
1524 actual = _.at(array, values);
1526 assert.deepEqual(actual, expected);
1529 QUnit.test('should return an empty array when no keys are given', function(assert) {
1532 assert.deepEqual(_.at(array), []);
1533 assert.deepEqual(_.at(array, [], []), []);
1536 QUnit.test('should accept multiple key arguments', function(assert) {
1539 var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
1540 assert.deepEqual(actual, ['d', 'a', 'c']);
1543 QUnit.test('should work with a falsey `object` when keys are given', function(assert) {
1546 var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
1548 var actual = lodashStable.map(falsey, function(object) {
1550 return _.at(object, 0, 1, 'pop', 'push');
1554 assert.deepEqual(actual, expected);
1557 QUnit.test('should work with an `arguments` object for `object`', function(assert) {
1560 var actual = _.at(args, [2, 0]);
1561 assert.deepEqual(actual, [3, 1]);
1564 QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
1567 var actual = _.at([1, 2, 3, 4, 5], args);
1568 assert.deepEqual(actual, [2, 3, 4]);
1571 QUnit.test('should work with an object for `object`', function(assert) {
1574 var actual = _.at(object, ['a[0].b.c', 'a[1]']);
1575 assert.deepEqual(actual, [3, 4]);
1578 QUnit.test('should pluck inherited property values', function(assert) {
1584 Foo.prototype.b = 2;
1586 var actual = _.at(new Foo, 'b');
1587 assert.deepEqual(actual, [2]);
1590 QUnit.test('should work in a lazy sequence', function(assert) {
1594 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
1597 lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
1598 lodashStable.times(2, function(index) {
1599 var array = index ? largeArray : smallArray,
1600 wrapped = _(array).map(identity).at(paths);
1602 assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
1607 skipAssert(assert, 6);
1611 QUnit.test('should support shortcut fusion', function(assert) {
1615 var array = lodashStable.range(LARGE_ARRAY_SIZE),
1617 iteratee = function(value) { count++; return square(value); },
1618 lastIndex = LARGE_ARRAY_SIZE - 1;
1620 lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
1622 var actual = _(array).map(iteratee).at(n).value(),
1623 expected = index < 2 ? 1 : 0;
1625 assert.strictEqual(count, expected);
1627 expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
1628 assert.deepEqual(actual, expected);
1632 skipAssert(assert, 8);
1636 QUnit.test('work with an object for `object` when chaining', function(assert) {
1640 var paths = ['a[0].b.c', 'a[1]'],
1641 actual = _(object).map(identity).at(paths).value();
1643 assert.deepEqual(actual, _.at(_.map(object, identity), paths));
1645 var indexObject = { '0': 1 };
1646 actual = _(indexObject).at(0).value();
1647 assert.deepEqual(actual, _.at(indexObject, 0));
1650 skipAssert(assert, 2);
1655 /*--------------------------------------------------------------------------*/
1657 QUnit.module('lodash.attempt');
1660 QUnit.test('should return the result of `func`', function(assert) {
1663 assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
1666 QUnit.test('should provide additional arguments to `func`', function(assert) {
1669 var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
1670 assert.deepEqual(actual, [1, 2]);
1673 QUnit.test('should return the caught error', function(assert) {
1676 var expected = lodashStable.map(errors, stubTrue);
1678 var actual = lodashStable.map(errors, function(error) {
1679 return _.attempt(function() { throw error; }) === error;
1682 assert.deepEqual(actual, expected);
1685 QUnit.test('should coerce errors to error objects', function(assert) {
1688 var actual = _.attempt(function() { throw 'x'; });
1689 assert.ok(lodashStable.isEqual(actual, Error('x')));
1692 QUnit.test('should preserve custom errors', function(assert) {
1695 var actual = _.attempt(function() { throw new CustomError('x'); });
1696 assert.ok(actual instanceof CustomError);
1699 QUnit.test('should work with an error object from another realm', function(assert) {
1703 var expected = lodashStable.map(realm.errors, stubTrue);
1705 var actual = lodashStable.map(realm.errors, function(error) {
1706 return _.attempt(function() { throw error; }) === error;
1709 assert.deepEqual(actual, expected);
1716 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
1720 assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
1727 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
1731 assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
1739 /*--------------------------------------------------------------------------*/
1741 QUnit.module('lodash.before');
1744 function before(n, times) {
1746 lodashStable.times(times, _.before(n, function() { count++; }));
1750 QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
1753 assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
1754 assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
1755 assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
1756 assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
1759 QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
1762 assert.strictEqual(before(NaN, 1), 0);
1765 QUnit.test('should use `this` binding of function', function(assert) {
1768 var before = _.before(2, function(assert) { return ++this.count; }),
1769 object = { 'before': before, 'count': 0 };
1772 assert.strictEqual(object.before(), 1);
1773 assert.strictEqual(object.count, 1);
1777 /*--------------------------------------------------------------------------*/
1779 QUnit.module('lodash.bind');
1783 var result = [this];
1784 push.apply(result, arguments);
1788 QUnit.test('should bind a function to an object', function(assert) {
1792 bound = _.bind(fn, object);
1794 assert.deepEqual(bound('a'), [object, 'a']);
1797 QUnit.test('should accept a falsey `thisArg`', function(assert) {
1800 var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
1801 expected = lodashStable.map(values, function(value) { return [value]; });
1803 var actual = lodashStable.map(values, function(value) {
1805 var bound = _.bind(fn, value);
1810 assert.ok(lodashStable.every(actual, function(value, index) {
1811 return lodashStable.isEqual(value, expected[index]);
1815 QUnit.test('should bind a function to nullish values', function(assert) {
1818 var bound = _.bind(fn, null),
1819 actual = bound('a');
1821 assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
1822 assert.strictEqual(actual[1], 'a');
1824 lodashStable.times(2, function(index) {
1825 bound = index ? _.bind(fn, undefined) : _.bind(fn);
1826 actual = bound('b');
1828 assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
1829 assert.strictEqual(actual[1], 'b');
1833 QUnit.test('should partially apply arguments ', function(assert) {
1837 bound = _.bind(fn, object, 'a');
1839 assert.deepEqual(bound(), [object, 'a']);
1841 bound = _.bind(fn, object, 'a');
1842 assert.deepEqual(bound('b'), [object, 'a', 'b']);
1844 bound = _.bind(fn, object, 'a', 'b');
1845 assert.deepEqual(bound(), [object, 'a', 'b']);
1846 assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
1849 QUnit.test('should support placeholders', function(assert) {
1853 ph = _.bind.placeholder,
1854 bound = _.bind(fn, object, ph, 'b', ph);
1856 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
1857 assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
1858 assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
1859 assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
1862 QUnit.test('should use `_.placeholder` when set', function(assert) {
1865 if (!isModularize) {
1866 var _ph = _.placeholder = {},
1867 ph = _.bind.placeholder,
1869 bound = _.bind(fn, object, _ph, 'b', ph);
1871 assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']);
1872 delete _.placeholder;
1879 QUnit.test('should create a function with a `length` of `0`', function(assert) {
1882 var fn = function(a, b, c) {},
1883 bound = _.bind(fn, {});
1885 assert.strictEqual(bound.length, 0);
1887 bound = _.bind(fn, {}, 1);
1888 assert.strictEqual(bound.length, 0);
1891 QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
1898 var bound = _.bind(Foo, { 'a': 1 }),
1899 newBound = new bound;
1901 assert.strictEqual(bound().a, 1);
1902 assert.strictEqual(newBound.a, undefined);
1903 assert.ok(newBound instanceof Foo);
1906 QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
1915 var thisArg = { 'a': 1 },
1916 boundFoo = _.bind(Foo, thisArg),
1917 boundBar = _.bind(Bar, thisArg),
1919 expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
1921 var actual = lodashStable.times(count, function(index) {
1924 case 0: return [new boundFoo().a, new boundBar().a];
1925 case 1: return [new boundFoo(1).a, new boundBar(1).a];
1926 case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
1927 case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
1928 case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
1929 case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
1930 case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
1931 case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
1932 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];
1937 assert.deepEqual(actual, expected);
1940 QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
1943 function Foo(value) {
1944 return value && object;
1947 var bound = _.bind(Foo),
1950 assert.ok(new bound instanceof Foo);
1951 assert.strictEqual(new bound(true), object);
1954 QUnit.test('should append array arguments to partially applied arguments', function(assert) {
1958 bound = _.bind(fn, object, 'a');
1960 assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
1963 QUnit.test('should not rebind functions', function(assert) {
1970 var bound1 = _.bind(fn, object1),
1971 bound2 = _.bind(bound1, object2, 'a'),
1972 bound3 = _.bind(bound1, object3, 'b');
1974 assert.deepEqual(bound1(), [object1]);
1975 assert.deepEqual(bound2(), [object1, 'a']);
1976 assert.deepEqual(bound3(), [object1, 'b']);
1979 QUnit.test('should not error when instantiating bound built-ins', function(assert) {
1982 var Ctor = _.bind(Date, null),
1983 expected = new Date(2012, 4, 23, 0, 0, 0, 0);
1986 var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
1989 assert.deepEqual(actual, expected);
1991 Ctor = _.bind(Date, null, 2012, 4, 23);
1994 actual = new Ctor(0, 0, 0, 0);
1997 assert.deepEqual(actual, expected);
2000 QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
2003 var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
2005 if (typeof createCtor == 'function') {
2006 var bound = _.bind(createCtor()),
2008 expected = lodashStable.times(count, stubTrue);
2010 var actual = lodashStable.times(count, function(index) {
2013 case 0: return !!(new bound);
2014 case 1: return !!(new bound(1));
2015 case 2: return !!(new bound(1, 2));
2016 case 3: return !!(new bound(1, 2, 3));
2017 case 4: return !!(new bound(1, 2, 3, 4));
2018 case 5: return !!(new bound(1, 2, 3, 4, 5));
2019 case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
2020 case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
2025 assert.deepEqual(actual, expected);
2032 QUnit.test('should return a wrapped value when chaining', function(assert) {
2037 bound = _(fn).bind({}, 'a', 'b');
2039 assert.ok(bound instanceof _);
2041 var actual = bound.value()('c');
2042 assert.deepEqual(actual, [object, 'a', 'b', 'c']);
2045 skipAssert(assert, 2);
2050 /*--------------------------------------------------------------------------*/
2052 QUnit.module('lodash.bindAll');
2055 var args = toArgs(['a']);
2064 '-0': function() { return this._n0; },
2065 '0': function() { return this._p0; },
2066 'a': function() { return this._a; },
2067 'b': function() { return this._b; },
2068 'c': function() { return this._c; },
2069 'd': function() { return this._d; }
2072 QUnit.test('should accept individual method names', function(assert) {
2075 var object = lodashStable.cloneDeep(source);
2076 _.bindAll(object, 'a', 'b');
2078 var actual = lodashStable.map(['a', 'b', 'c'], function(key) {
2079 return object[key].call({});
2082 assert.deepEqual(actual, [1, 2, undefined]);
2085 QUnit.test('should accept arrays of method names', function(assert) {
2088 var object = lodashStable.cloneDeep(source);
2089 _.bindAll(object, ['a', 'b'], ['c']);
2091 var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(key) {
2092 return object[key].call({});
2095 assert.deepEqual(actual, [1, 2, 3, undefined]);
2098 QUnit.test('should preserve the sign of `0`', function(assert) {
2101 var props = [-0, Object(-0), 0, Object(0)];
2103 var actual = lodashStable.map(props, function(key) {
2104 var object = lodashStable.cloneDeep(source);
2105 _.bindAll(object, key);
2106 return object[lodashStable.toString(key)].call({});
2109 assert.deepEqual(actual, [-2, -2, -1, -1]);
2112 QUnit.test('should work with an array `object`', function(assert) {
2115 var array = ['push', 'pop'];
2117 assert.strictEqual(array.pop, arrayProto.pop);
2120 QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
2123 var object = lodashStable.cloneDeep(source);
2124 _.bindAll(object, args);
2126 var actual = lodashStable.map(args, function(key) {
2127 return object[key].call({});
2130 assert.deepEqual(actual, [1]);
2134 /*--------------------------------------------------------------------------*/
2136 QUnit.module('lodash.bindKey');
2139 QUnit.test('should work when the target function is overwritten', function(assert) {
2144 'greet': function(greeting) {
2145 return this.user + ' says: ' + greeting;
2149 var bound = _.bindKey(object, 'greet', 'hi');
2150 assert.strictEqual(bound(), 'fred says: hi');
2152 object.greet = function(greeting) {
2153 return this.user + ' says: ' + greeting + '!';
2156 assert.strictEqual(bound(), 'fred says: hi!');
2159 QUnit.test('should support placeholders', function(assert) {
2164 return slice.call(arguments);
2168 var ph = _.bindKey.placeholder,
2169 bound = _.bindKey(object, 'fn', ph, 'b', ph);
2171 assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
2172 assert.deepEqual(bound('a'), ['a', 'b', undefined]);
2173 assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
2174 assert.deepEqual(bound(), [undefined, 'b', undefined]);
2177 QUnit.test('should use `_.placeholder` when set', function(assert) {
2180 if (!isModularize) {
2183 return slice.call(arguments);
2187 var _ph = _.placeholder = {},
2188 ph = _.bindKey.placeholder,
2189 bound = _.bindKey(object, 'fn', _ph, 'b', ph);
2191 assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']);
2192 delete _.placeholder;
2199 QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
2202 function Foo(value) {
2203 return value && object;
2206 var object = { 'Foo': Foo },
2207 bound = _.bindKey(object, 'Foo');
2209 assert.ok(new bound instanceof Foo);
2210 assert.strictEqual(new bound(true), object);
2214 /*--------------------------------------------------------------------------*/
2216 QUnit.module('case methods');
2218 lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
2219 var methodName = caseName + 'Case',
2220 func = _[methodName];
2223 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
2224 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__'
2227 var converted = (function() {
2229 case 'camel': return 'fooBar';
2230 case 'kebab': return 'foo-bar';
2231 case 'lower': return 'foo bar';
2232 case 'snake': return 'foo_bar';
2233 case 'start': return 'Foo Bar';
2234 case 'upper': return 'FOO BAR';
2238 QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
2241 var actual = lodashStable.map(strings, function(string) {
2242 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2243 return func(string) === expected;
2246 assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
2249 QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
2252 var actual = lodashStable.map(strings, function(string) {
2253 var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
2254 return func(func(string)) === expected;
2257 assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
2260 QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
2263 var actual = lodashStable.map(burredLetters, function(burred, index) {
2264 var letter = deburredLetters[index].replace(/['\u2019]/g, '');
2265 if (caseName == 'start') {
2266 letter = letter == 'IJ' ? letter : lodashStable.capitalize(letter);
2267 } else if (caseName == 'upper') {
2268 letter = letter.toUpperCase();
2270 letter = letter.toLowerCase();
2272 return func(burred) === letter;
2275 assert.deepEqual(actual, lodashStable.map(burredLetters, stubTrue));
2278 QUnit.test('`_.' + methodName + '` should remove contraction apostrophes', function(assert) {
2281 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
2283 lodashStable.each(["'", '\u2019'], function(apos) {
2284 var actual = lodashStable.map(postfixes, function(postfix) {
2285 return func('a b' + apos + postfix + ' c');
2288 var expected = lodashStable.map(postfixes, function(postfix) {
2290 case 'camel': return 'aB' + postfix + 'C';
2291 case 'kebab': return 'a-b' + postfix + '-c';
2292 case 'lower': return 'a b' + postfix + ' c';
2293 case 'snake': return 'a_b' + postfix + '_c';
2294 case 'start': return 'A B' + postfix + ' C';
2295 case 'upper': return 'A B' + postfix.toUpperCase() + ' C';
2299 assert.deepEqual(actual, expected);
2303 QUnit.test('`_.' + methodName + '` should remove Latin mathematical operators', function(assert) {
2306 var actual = lodashStable.map(['\xd7', '\xf7'], func);
2307 assert.deepEqual(actual, ['', '']);
2310 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
2313 var string = 'foo bar';
2314 assert.strictEqual(func(Object(string)), converted);
2315 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
2318 QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
2322 assert.strictEqual(_('foo bar')[methodName](), converted);
2329 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
2333 assert.ok(_('foo bar').chain()[methodName]() instanceof _);
2342 QUnit.test('should get the original value after cycling through all case methods', function(assert) {
2345 var funcs = [_.camelCase, _.kebabCase, _.lowerCase, _.snakeCase, _.startCase, _.lowerCase, _.camelCase];
2347 var actual = lodashStable.reduce(funcs, function(result, func) {
2348 return func(result);
2349 }, 'enable 6h format');
2351 assert.strictEqual(actual, 'enable6HFormat');
2355 /*--------------------------------------------------------------------------*/
2357 QUnit.module('lodash.camelCase');
2360 QUnit.test('should work with numbers', function(assert) {
2363 assert.strictEqual(_.camelCase('12 feet'), '12Feet');
2364 assert.strictEqual(_.camelCase('enable 6h format'), 'enable6HFormat');
2365 assert.strictEqual(_.camelCase('enable 24H format'), 'enable24HFormat');
2366 assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
2367 assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
2368 assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
2371 QUnit.test('should handle acronyms', function(assert) {
2374 lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
2375 assert.strictEqual(_.camelCase(string), 'safeHtml');
2378 lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
2379 assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
2382 lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
2383 assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
2388 /*--------------------------------------------------------------------------*/
2390 QUnit.module('lodash.capitalize');
2393 QUnit.test('should capitalize the first character of a string', function(assert) {
2396 assert.strictEqual(_.capitalize('fred'), 'Fred');
2397 assert.strictEqual(_.capitalize('Fred'), 'Fred');
2398 assert.strictEqual(_.capitalize(' fred'), ' fred');
2402 /*--------------------------------------------------------------------------*/
2404 QUnit.module('lodash.castArray');
2407 QUnit.test('should wrap non-array items in an array', function(assert) {
2410 var values = falsey.concat(true, 1, 'a', { 'a': 1 }),
2411 expected = lodashStable.map(values, function(value) { return [value]; }),
2412 actual = lodashStable.map(values, _.castArray);
2414 assert.deepEqual(actual, expected);
2417 QUnit.test('should return array values by reference', function(assert) {
2421 assert.strictEqual(_.castArray(array), array);
2424 QUnit.test('should return an empty array when no arguments are given', function(assert) {
2427 assert.deepEqual(_.castArray(), []);
2431 /*--------------------------------------------------------------------------*/
2433 QUnit.module('lodash.chain');
2436 QUnit.test('should return a wrapped value', function(assert) {
2440 var actual = _.chain({ 'a': 0 });
2441 assert.ok(actual instanceof _);
2448 QUnit.test('should return existing wrapped values', function(assert) {
2452 var wrapped = _({ 'a': 0 });
2453 assert.strictEqual(_.chain(wrapped), wrapped);
2454 assert.strictEqual(wrapped.chain(), wrapped);
2457 skipAssert(assert, 2);
2461 QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
2465 var array = ['c', 'b', 'a'];
2467 assert.ok(_.chain(array).head() instanceof _);
2468 assert.ok(_(array).chain().head() instanceof _);
2470 assert.ok(_.chain(array).isArray() instanceof _);
2471 assert.ok(_(array).chain().isArray() instanceof _);
2473 assert.ok(_.chain(array).sortBy().head() instanceof _);
2474 assert.ok(_(array).chain().sortBy().head() instanceof _);
2477 skipAssert(assert, 6);
2481 QUnit.test('should chain multiple methods', function(assert) {
2485 lodashStable.times(2, function(index) {
2486 var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
2487 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 },
2488 wrapped = index ? _(array).chain() : _.chain(array);
2490 var actual = wrapped
2492 .map(function(value) { return value.split(''); })
2494 .reduce(function(object, chr) {
2495 object[chr] || (object[chr] = 0);
2501 assert.deepEqual(actual, expected);
2503 array = [1, 2, 3, 4, 5, 6];
2504 wrapped = index ? _(array).chain() : _.chain(array);
2507 .filter(function(n) { return n % 2 != 0; })
2508 .reject(function(n) { return n % 3 == 0; })
2509 .sortBy(function(n) { return -n; })
2512 assert.deepEqual(actual, [5, 1]);
2515 wrapped = index ? _(array).chain() : _.chain(array);
2520 .tap(function(value) { value.pop(); })
2524 assert.deepEqual(actual, [25, 16, 9, 4]);
2528 skipAssert(assert, 6);
2533 /*--------------------------------------------------------------------------*/
2535 QUnit.module('lodash.chunk');
2538 var array = [0, 1, 2, 3, 4, 5];
2540 QUnit.test('should return chunked arrays', function(assert) {
2543 var actual = _.chunk(array, 3);
2544 assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
2547 QUnit.test('should return the last chunk as remaining elements', function(assert) {
2550 var actual = _.chunk(array, 4);
2551 assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
2554 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
2557 var expected = lodashStable.map(falsey, function(value) {
2558 return value === undefined ? [[0], [1], [2], [3], [4], [5]] : [];
2561 var actual = lodashStable.map(falsey, function(size, index) {
2562 return index ? _.chunk(array, size) : _.chunk(array);
2565 assert.deepEqual(actual, expected);
2568 QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
2571 var values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity),
2572 expected = lodashStable.map(values, stubArray);
2574 var actual = lodashStable.map(values, function(n) {
2575 return _.chunk(array, n);
2578 assert.deepEqual(actual, expected);
2581 QUnit.test('should coerce `size` to an integer', function(assert) {
2584 assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
2587 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
2590 var actual = lodashStable.map([[1, 2], [3, 4]], _.chunk);
2591 assert.deepEqual(actual, [[[1], [2]], [[3], [4]]]);
2595 /*--------------------------------------------------------------------------*/
2597 QUnit.module('lodash.clamp');
2600 QUnit.test('should work with a `max`', function(assert) {
2603 assert.strictEqual(_.clamp(5, 3), 3);
2604 assert.strictEqual(_.clamp(1, 3), 1);
2607 QUnit.test('should clamp negative numbers', function(assert) {
2610 assert.strictEqual(_.clamp(-10, -5, 5), -5);
2611 assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
2612 assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
2615 QUnit.test('should clamp positive numbers', function(assert) {
2618 assert.strictEqual(_.clamp(10, -5, 5), 5);
2619 assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
2620 assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
2623 QUnit.test('should not alter negative numbers in range', function(assert) {
2626 assert.strictEqual(_.clamp(-4, -5, 5), -4);
2627 assert.strictEqual(_.clamp(-5, -5, 5), -5);
2628 assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
2631 QUnit.test('should not alter positive numbers in range', function(assert) {
2634 assert.strictEqual(_.clamp(4, -5, 5), 4);
2635 assert.strictEqual(_.clamp(5, -5, 5), 5);
2636 assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
2639 QUnit.test('should not alter `0` in range', function(assert) {
2642 assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
2645 QUnit.test('should clamp to `0`', function(assert) {
2648 assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
2651 QUnit.test('should not alter `-0` in range', function(assert) {
2654 assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
2657 QUnit.test('should clamp to `-0`', function(assert) {
2660 assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
2663 QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
2666 assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
2669 QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
2672 assert.deepEqual(_.clamp(1, -5, NaN), 0);
2673 assert.deepEqual(_.clamp(-1, NaN, 5), 0);
2677 /*--------------------------------------------------------------------------*/
2679 QUnit.module('clone methods');
2685 Foo.prototype.b = 1;
2686 Foo.c = function() {};
2699 '`arguments` objects': arguments,
2700 'arrays': ['a', ''],
2701 'array-like objects': { '0': 'a', 'length': 1 },
2703 'boolean objects': Object(false),
2704 'date objects': new Date,
2705 'Foo instances': new Foo,
2706 'objects': { 'a': 0, 'b': 1, 'c': 2 },
2707 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
2708 'objects from another document': realm.object || {},
2710 'null values': null,
2712 'number objects': Object(0),
2716 'string objects': Object('a'),
2717 'undefined values': undefined
2720 objects.arrays.length = 3;
2723 'DOM elements': body,
2725 'async functions': asyncFunc,
2726 'generator functions': genFunc,
2727 'the `Proxy` constructor': Proxy
2730 lodashStable.each(errors, function(error) {
2731 uncloneable[error.name + 's'] = error;
2734 QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
2737 var array = [{ 'a': 0 }, { 'b': 1 }],
2738 actual = _.clone(array);
2740 assert.deepEqual(actual, array);
2741 assert.ok(actual !== array && actual[0] === array[0]);
2744 QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
2748 'foo': { 'b': { 'c': { 'd': {} } } },
2752 object.foo.b.c.d = object;
2753 object.bar.b = object.foo.b;
2755 var actual = _.cloneDeep(object);
2756 assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
2759 QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
2763 lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
2764 cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
2767 var clone = _.cloneDeep(cyclical),
2768 actual = clone['v' + LARGE_ARRAY_SIZE][0];
2770 assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
2771 assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
2774 QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
2779 _.cloneDeepWith({ 'a': 1 }, function() {
2780 actual = _.last(arguments);
2784 ? actual.constructor.name == 'Stack'
2785 : actual instanceof mapCaches.Stack
2789 lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
2790 var func = _[methodName],
2791 isDeep = methodName == 'cloneDeep';
2793 lodashStable.forOwn(objects, function(object, kind) {
2794 QUnit.test('`_.' + methodName + '` should clone ' + kind, function(assert) {
2797 var actual = func(object);
2798 assert.ok(lodashStable.isEqual(actual, object));
2800 if (lodashStable.isObject(object)) {
2801 assert.notStrictEqual(actual, object);
2803 assert.strictEqual(actual, object);
2808 QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
2812 var actual = func(arrayBuffer);
2813 assert.strictEqual(actual.byteLength, arrayBuffer.byteLength);
2814 assert.notStrictEqual(actual, arrayBuffer);
2817 skipAssert(assert, 2);
2821 QUnit.test('`_.' + methodName + '` should clone buffers', function(assert) {
2825 var buffer = new Buffer([1, 2]),
2826 actual = func(buffer);
2828 assert.strictEqual(actual.byteLength, buffer.byteLength);
2829 assert.strictEqual(actual.inspect(), buffer.inspect());
2830 assert.notStrictEqual(actual, buffer);
2833 assert.strictEqual(actual[0], isDeep ? 2 : 1);
2836 skipAssert(assert, 4);
2840 QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
2843 var array = /c/.exec('abcde'),
2844 actual = func(array);
2846 assert.strictEqual(actual.index, 2);
2847 assert.strictEqual(actual.input, 'abcde');
2850 QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
2854 regexp.exec('abcde');
2856 assert.strictEqual(func(regexp).lastIndex, 3);
2859 QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
2862 var values = lodashStable.map([false, true, 1, 'a'], function(value) {
2863 var object = Object(value);
2868 var expected = lodashStable.map(values, stubTrue);
2870 var actual = lodashStable.map(values, function(value) {
2871 return func(value).a === 1;
2874 assert.deepEqual(actual, expected);
2877 QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
2880 var actual = func(Foo.prototype);
2882 assert.notOk(actual instanceof Foo);
2883 assert.deepEqual(actual, { 'b': 1 });
2886 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone', function(assert) {
2889 assert.ok(func(new Foo) instanceof Foo);
2892 QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone even when the `constructor` is incorrect', function(assert) {
2895 Foo.prototype.constructor = Object;
2896 assert.ok(func(new Foo) instanceof Foo);
2897 Foo.prototype.constructor = Foo;
2900 QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
2903 Foo.prototype.constructor = null;
2904 assert.notOk(func(new Foo) instanceof Foo);
2905 Foo.prototype.constructor = Foo;
2908 QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
2912 'constructor': objectProto.constructor,
2913 'hasOwnProperty': objectProto.hasOwnProperty,
2914 'isPrototypeOf': objectProto.isPrototypeOf,
2915 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
2916 'toLocaleString': objectProto.toLocaleString,
2917 'toString': objectProto.toString,
2918 'valueOf': objectProto.valueOf
2921 var actual = func(object);
2923 assert.deepEqual(actual, object);
2924 assert.notStrictEqual(actual, object);
2927 QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
2931 this[symbol] = { 'c': 1 };
2935 var symbol2 = Symbol('b');
2936 Foo.prototype[symbol2] = 2;
2938 var symbol3 = Symbol('c');
2939 defineProperty(Foo.prototype, symbol3, {
2940 'configurable': true,
2941 'enumerable': false,
2946 var object = { 'a': { 'b': new Foo } };
2947 object[symbol] = { 'b': 1 };
2949 var actual = func(object);
2951 assert.notStrictEqual(actual[symbol], object[symbol]);
2952 assert.notStrictEqual(actual.a, object.a);
2954 assert.strictEqual(actual[symbol], object[symbol]);
2955 assert.strictEqual(actual.a, object.a);
2957 assert.deepEqual(actual[symbol], object[symbol]);
2958 assert.deepEqual(getSymbols(actual.a.b), [symbol]);
2959 assert.deepEqual(actual.a.b[symbol], object.a.b[symbol]);
2960 assert.deepEqual(actual.a.b[symbol2], object.a.b[symbol2]);
2961 assert.deepEqual(actual.a.b[symbol3], object.a.b[symbol3])
2964 skipAssert(assert, 7);
2968 QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
2972 assert.strictEqual(func(symbol), symbol);
2974 var object = Object(symbol),
2975 actual = func(object);
2977 assert.strictEqual(typeof actual, 'object');
2978 assert.strictEqual(typeof actual.valueOf(), 'symbol');
2979 assert.notStrictEqual(actual, object);
2982 skipAssert(assert, 4);
2986 QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
2990 assert.strictEqual(func(symbol), symbol);
2997 QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
3001 var element = document.createElement('div');
3004 assert.deepEqual(func(element), {});
3006 assert.ok(false, e.message);
3014 QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
3019 var objects = lodashStable.transform(_, function(result, value, key) {
3020 if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) &&
3021 !lodashStable.isArguments(value) && !lodashStable.isElement(value) &&
3022 !lodashStable.isFunction(value)) {
3023 props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
3028 var expected = lodashStable.map(objects, stubTrue);
3030 var actual = lodashStable.map(objects, function(object) {
3031 var Ctor = object.constructor,
3032 result = func(object);
3034 return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
3037 assert.deepEqual(actual, expected, props.join(', '));
3040 QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
3043 var expected = [{ 'a': [0] }, { 'b': [1] }],
3044 actual = lodashStable.map(expected, func);
3046 assert.deepEqual(actual, expected);
3049 assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
3051 assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
3055 QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
3059 var object = objects.objects,
3060 actual = _(object)[methodName]();
3062 assert.deepEqual(actual, object);
3063 assert.notStrictEqual(actual, object);
3066 skipAssert(assert, 2);
3070 lodashStable.each(arrayViews, function(type) {
3071 QUnit.test('`_.' + methodName + '` should clone ' + type + ' values', function(assert) {
3074 var Ctor = root[type];
3076 lodashStable.times(2, function(index) {
3078 var buffer = new ArrayBuffer(24),
3079 view = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
3080 actual = func(view);
3082 assert.deepEqual(actual, view);
3083 assert.notStrictEqual(actual, view);
3084 assert.strictEqual(actual.buffer === view.buffer, !isDeep);
3085 assert.strictEqual(actual.byteOffset, view.byteOffset);
3086 assert.strictEqual(actual.length, view.length);
3089 skipAssert(assert, 5);
3095 lodashStable.forOwn(uncloneable, function(value, key) {
3096 QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
3100 var object = { 'a': value, 'b': { 'c': value } },
3101 actual = func(object),
3102 expected = value === Foo ? { 'c': Foo.c } : {};
3104 assert.deepEqual(actual, object);
3105 assert.notStrictEqual(actual, object);
3106 assert.deepEqual(func(value), expected);
3109 skipAssert(assert, 3);
3115 lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
3116 var func = _[methodName],
3117 isDeep = methodName == 'cloneDeepWith';
3119 QUnit.test('`_.' + methodName + '` should provide correct `customizer` arguments', function(assert) {
3125 func(object, function() {
3126 var length = arguments.length,
3127 args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
3129 argsList.push(args);
3132 assert.deepEqual(argsList, isDeep ? [[object], [1, 'a', object]] : [[object]]);
3135 QUnit.test('`_.' + methodName + '` should handle cloning when `customizer` returns `undefined`', function(assert) {
3138 var actual = func({ 'a': { 'b': 'c' } }, noop);
3139 assert.deepEqual(actual, { 'a': { 'b': 'c' } });
3142 lodashStable.forOwn(uncloneable, function(value, key) {
3143 QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
3146 var customizer = function(value) {
3147 return lodashStable.isPlainObject(value) ? undefined : value;
3150 var actual = func(value, customizer);
3151 assert.strictEqual(actual, value);
3153 var object = { 'a': value, 'b': { 'c': value } };
3154 actual = func(object, customizer);
3156 assert.deepEqual(actual, object);
3157 assert.notStrictEqual(actual, object);
3163 /*--------------------------------------------------------------------------*/
3165 QUnit.module('lodash.compact');
3168 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
3170 QUnit.test('should filter falsey values', function(assert) {
3173 var array = ['0', '1', '2'];
3174 assert.deepEqual(_.compact(falsey.concat(array)), array);
3177 QUnit.test('should work when in-between lazy operators', function(assert) {
3181 var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
3182 assert.deepEqual(actual, []);
3184 actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
3185 assert.deepEqual(actual, [true, 1, 'a']);
3188 skipAssert(assert, 2);
3192 QUnit.test('should work in a lazy sequence', function(assert) {
3196 var actual = _(largeArray).slice(1).compact().reverse().take().value();
3197 assert.deepEqual(actual, _.take(_.compact(_.slice(largeArray, 1)).reverse()));
3204 QUnit.test('should work in a lazy sequence with a custom `_.iteratee`', function(assert) {
3207 if (!isModularize) {
3208 var iteratee = _.iteratee,
3211 _.iteratee = identity;
3214 var actual = _(largeArray).slice(1).compact().value();
3215 pass = lodashStable.isEqual(actual, _.compact(_.slice(largeArray, 1)));
3216 } catch (e) {console.log(e);}
3219 _.iteratee = iteratee;
3227 /*--------------------------------------------------------------------------*/
3229 QUnit.module('lodash.concat');
3232 QUnit.test('should shallow clone `array`', function(assert) {
3235 var array = [1, 2, 3],
3236 actual = _.concat(array);
3238 assert.deepEqual(actual, array);
3239 assert.notStrictEqual(actual, array);
3242 QUnit.test('should concat arrays and values', function(assert) {
3246 actual = _.concat(array, 2, [3], [[4]]);
3248 assert.deepEqual(actual, [1, 2, 3, [4]]);
3249 assert.deepEqual(array, [1]);
3252 QUnit.test('should cast non-array `array` values to arrays', function(assert) {
3255 var values = [, null, undefined, false, true, 1, NaN, 'a'];
3257 var expected = lodashStable.map(values, function(value, index) {
3258 return index ? [value] : [];
3261 var actual = lodashStable.map(values, function(value, index) {
3262 return index ? _.concat(value) : _.concat();
3265 assert.deepEqual(actual, expected);
3267 expected = lodashStable.map(values, function(value) {
3268 return [value, 2, [3]];
3271 actual = lodashStable.map(values, function(value) {
3272 return _.concat(value, [2], [[3]]);
3275 assert.deepEqual(actual, expected);
3278 QUnit.test('should treat sparse arrays as dense', function(assert) {
3282 actual = _.concat(Array(1), Array(1));
3284 expected.push(undefined, undefined);
3286 assert.ok('0'in actual);
3287 assert.ok('1' in actual);
3288 assert.deepEqual(actual, expected);
3291 QUnit.test('should return a new wrapped array', function(assert) {
3296 wrapped = _(array).concat([2, 3]),
3297 actual = wrapped.value();
3299 assert.deepEqual(array, [1]);
3300 assert.deepEqual(actual, [1, 2, 3]);
3303 skipAssert(assert, 2);
3308 /*--------------------------------------------------------------------------*/
3310 QUnit.module('lodash.cond');
3313 QUnit.test('should create a conditional function', function(assert) {
3317 [lodashStable.matches({ 'a': 1 }), stubA],
3318 [lodashStable.matchesProperty('b', 1), stubB],
3319 [lodashStable.property('c'), stubC]
3322 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3323 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3324 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3327 QUnit.test('should provide arguments to functions', function(assert) {
3332 expected = ['a', 'b', 'c'];
3334 var cond = _.cond([[
3335 function() { args1 || (args1 = slice.call(arguments)); return true; },
3336 function() { args2 || (args2 = slice.call(arguments)); }
3339 cond('a', 'b', 'c');
3341 assert.deepEqual(args1, expected);
3342 assert.deepEqual(args2, expected);
3345 QUnit.test('should work with predicate shorthands', function(assert) {
3349 [{ 'a': 1 }, stubA],
3354 assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
3355 assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
3356 assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
3359 QUnit.test('should return `undefined` when no condition is met', function(assert) {
3362 var cond = _.cond([[stubFalse, stubA]]);
3363 assert.strictEqual(cond({ 'a': 1 }), undefined);
3366 QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
3369 lodashStable.each([false, true], function(value) {
3370 assert.raises(function() { _.cond([[stubTrue, value]])(); }, TypeError);
3374 QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
3378 [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
3381 var object = { 'cond': cond, 'a': 1, 'b': 2 };
3382 assert.strictEqual(object.cond('a', 'b'), 2);
3386 /*--------------------------------------------------------------------------*/
3388 QUnit.module('lodash.conforms');
3391 QUnit.test('should not change behavior if `source` is modified', function(assert) {
3394 var object = { 'a': 2 },
3395 source = { 'a': function(value) { return value > 1; } },
3396 par = _.conforms(source);
3398 assert.strictEqual(par(object), true);
3400 source.a = function(value) { return value < 2; };
3401 assert.strictEqual(par(object), true);
3405 /*--------------------------------------------------------------------------*/
3407 QUnit.module('conforms methods');
3409 lodashStable.each(['conforms', 'conformsTo'], function(methodName) {
3410 var isConforms = methodName == 'conforms';
3412 function conforms(source) {
3413 return isConforms ? _.conforms(source) : function(object) {
3414 return _.conformsTo(object, source);
3418 QUnit.test('`_.' + methodName + '` should check if `object` conforms to `source`', function(assert) {
3427 var par = conforms({
3428 'b': function(value) { return value > 4; }
3431 var actual = lodashStable.filter(objects, par);
3432 assert.deepEqual(actual, [objects[0], objects[2]]);
3435 'b': function(value) { return value > 8; },
3436 'a': function(value) { return value > 1; }
3439 actual = lodashStable.filter(objects, par);
3440 assert.deepEqual(actual, [objects[2]]);
3443 QUnit.test('`_.' + methodName + '` should not match by inherited `source` properties', function(assert) {
3447 this.a = function(value) {
3451 Foo.prototype.b = function(value) {
3461 var par = conforms(new Foo),
3462 actual = lodashStable.filter(objects, par);
3464 assert.deepEqual(actual, [objects[1], objects[2]]);
3467 QUnit.test('`_.' + methodName + '` should not invoke `source` predicates for missing `object` properties', function(assert) {
3472 var par = conforms({
3473 'a': function() { count++; return true; }
3476 assert.strictEqual(par({}), false);
3477 assert.strictEqual(count, 0);
3480 QUnit.test('`_.' + methodName + '` should work with a function for `object`', function(assert) {
3489 var par = conforms({
3490 'a': function(value) { return value > 1; }
3493 assert.strictEqual(par(Foo), false);
3494 assert.strictEqual(par(Bar), true);
3497 QUnit.test('`_.' + methodName + '` should work with a function for `source`', function(assert) {
3501 Foo.a = function(value) { return value > 1; };
3503 var objects = [{ 'a': 1 }, { 'a': 2 }],
3504 actual = lodashStable.filter(objects, conforms(Foo));
3506 assert.deepEqual(actual, [objects[1]]);
3509 QUnit.test('`_.' + methodName + '` should work with a non-plain `object`', function(assert) {
3515 Foo.prototype.b = 2;
3517 var par = conforms({
3518 'b': function(value) { return value > 1; }
3521 assert.strictEqual(par(new Foo), true);
3524 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
3527 var values = [, null, undefined],
3528 expected = lodashStable.map(values, stubFalse);
3530 var par = conforms({
3531 'a': function(value) { return value > 1; }
3534 var actual = lodashStable.map(values, function(value, index) {
3536 return index ? par(value) : par();
3540 assert.deepEqual(actual, expected);
3543 QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
3546 var values = [, null, undefined],
3547 expected = lodashStable.map(values, stubTrue),
3550 var actual = lodashStable.map(values, function(value, index) {
3552 return index ? par(value) : par();
3556 assert.deepEqual(actual, expected);
3559 QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source`', function(assert) {
3562 var object = { 'a': 1 },
3563 expected = lodashStable.map(empties, stubTrue);
3565 var actual = lodashStable.map(empties, function(value) {
3566 var par = conforms(value);
3570 assert.deepEqual(actual, expected);
3574 /*--------------------------------------------------------------------------*/
3576 QUnit.module('lodash.constant');
3579 QUnit.test('should create a function that returns `value`', function(assert) {
3582 var object = { 'a': 1 },
3583 values = Array(2).concat(empties, true, 1, 'a'),
3584 constant = _.constant(object);
3586 var results = lodashStable.map(values, function(value, index) {
3588 return index ? constant.call({}) : constant();
3590 return constant(value);
3593 assert.ok(lodashStable.every(results, function(result) {
3594 return result === object;
3598 QUnit.test('should work with falsey values', function(assert) {
3601 var expected = lodashStable.map(falsey, stubTrue);
3603 var actual = lodashStable.map(falsey, function(value, index) {
3604 var constant = index ? _.constant(value) : _.constant(),
3605 result = constant();
3607 return (result === value) || (result !== result && value !== value);
3610 assert.deepEqual(actual, expected);
3613 QUnit.test('should return a wrapped value when chaining', function(assert) {
3617 var wrapped = _(true).constant();
3618 assert.ok(wrapped instanceof _);
3626 /*--------------------------------------------------------------------------*/
3628 QUnit.module('lodash.countBy');
3631 var array = [6.1, 4.2, 6.3];
3633 QUnit.test('should transform keys by `iteratee`', function(assert) {
3636 var actual = _.countBy(array, Math.floor);
3637 assert.deepEqual(actual, { '4': 1, '6': 2 });
3640 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
3643 var array = [4, 6, 6],
3644 values = [, null, undefined],
3645 expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
3647 var actual = lodashStable.map(values, function(value, index) {
3648 return index ? _.countBy(array, value) : _.countBy(array);
3651 assert.deepEqual(actual, expected);
3654 QUnit.test('should work with `_.property` shorthands', function(assert) {
3657 var actual = _.countBy(['one', 'two', 'three'], 'length');
3658 assert.deepEqual(actual, { '3': 2, '5': 1 });
3661 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
3664 var actual = _.countBy(array, function(n) {
3665 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
3668 assert.deepEqual(actual.constructor, 1);
3669 assert.deepEqual(actual.hasOwnProperty, 2);
3672 QUnit.test('should work with a number for `iteratee`', function(assert) {
3681 assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
3682 assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
3685 QUnit.test('should work with an object for `collection`', function(assert) {
3688 var actual = _.countBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
3689 assert.deepEqual(actual, { '4': 1, '6': 2 });
3692 QUnit.test('should work in a lazy sequence', function(assert) {
3696 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
3697 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
3698 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
3701 var actual = _(array).countBy().map(square).filter(isEven).take().value();
3703 assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
3711 /*--------------------------------------------------------------------------*/
3713 QUnit.module('lodash.create');
3725 QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
3728 Circle.prototype = _.create(Shape.prototype);
3729 Circle.prototype.constructor = Circle;
3731 var actual = new Circle;
3733 assert.ok(actual instanceof Circle);
3734 assert.ok(actual instanceof Shape);
3735 assert.notStrictEqual(Circle.prototype, Shape.prototype);
3738 QUnit.test('should assign `properties` to the created object', function(assert) {
3741 var expected = { 'constructor': Circle, 'radius': 0 };
3742 Circle.prototype = _.create(Shape.prototype, expected);
3744 var actual = new Circle;
3746 assert.ok(actual instanceof Circle);
3747 assert.ok(actual instanceof Shape);
3748 assert.deepEqual(Circle.prototype, expected);
3751 QUnit.test('should assign own properties', function(assert) {
3758 Foo.prototype.b = 2;
3760 assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
3763 QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
3769 var object = _.create(new Foo, { 'a': 1 });
3770 assert.deepEqual(lodashStable.keys(object), ['a']);
3773 QUnit.test('should accept a falsey `prototype`', function(assert) {
3776 var expected = lodashStable.map(falsey, stubObject);
3778 var actual = lodashStable.map(falsey, function(prototype, index) {
3779 return index ? _.create(prototype) : _.create();
3782 assert.deepEqual(actual, expected);
3785 QUnit.test('should ignore a primitive `prototype` and use an empty object instead', function(assert) {
3788 var expected = lodashStable.map(primitives, stubTrue);
3790 var actual = lodashStable.map(primitives, function(value, index) {
3791 return lodashStable.isPlainObject(index ? _.create(value) : _.create());
3794 assert.deepEqual(actual, expected);
3797 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
3800 var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
3801 expected = lodashStable.map(array, stubTrue),
3802 objects = lodashStable.map(array, _.create);
3804 var actual = lodashStable.map(objects, function(object) {
3805 return object.a === 1 && !_.keys(object).length;
3808 assert.deepEqual(actual, expected);
3812 /*--------------------------------------------------------------------------*/
3814 QUnit.module('lodash.curry');
3817 function fn(a, b, c, d) {
3818 return slice.call(arguments);
3821 QUnit.test('should curry based on the number of arguments given', function(assert) {
3824 var curried = _.curry(fn),
3825 expected = [1, 2, 3, 4];
3827 assert.deepEqual(curried(1)(2)(3)(4), expected);
3828 assert.deepEqual(curried(1, 2)(3, 4), expected);
3829 assert.deepEqual(curried(1, 2, 3, 4), expected);
3832 QUnit.test('should allow specifying `arity`', function(assert) {
3835 var curried = _.curry(fn, 3),
3836 expected = [1, 2, 3];
3838 assert.deepEqual(curried(1)(2, 3), expected);
3839 assert.deepEqual(curried(1, 2)(3), expected);
3840 assert.deepEqual(curried(1, 2, 3), expected);
3843 QUnit.test('should coerce `arity` to an integer', function(assert) {
3846 var values = ['0', 0.6, 'xyz'],
3847 expected = lodashStable.map(values, stubArray);
3849 var actual = lodashStable.map(values, function(arity) {
3850 return _.curry(fn, arity)();
3853 assert.deepEqual(actual, expected);
3854 assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
3857 QUnit.test('should support placeholders', function(assert) {
3860 var curried = _.curry(fn),
3861 ph = curried.placeholder;
3863 assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
3864 assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
3865 assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
3866 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
3869 QUnit.test('should persist placeholders', function(assert) {
3872 var curried = _.curry(fn),
3873 ph = curried.placeholder,
3874 actual = curried(ph, ph, ph, 'd')('a')(ph)('b')('c');
3876 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
3879 QUnit.test('should use `_.placeholder` when set', function(assert) {
3882 if (!isModularize) {
3883 var curried = _.curry(fn),
3884 _ph = _.placeholder = {},
3885 ph = curried.placeholder;
3887 assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]);
3888 delete _.placeholder;
3895 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
3898 var curried = _.curry(fn, 3);
3899 assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
3900 assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
3901 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
3904 QUnit.test('should create a function with a `length` of `0`', function(assert) {
3907 lodashStable.times(2, function(index) {
3908 var curried = index ? _.curry(fn, 4) : _.curry(fn);
3909 assert.strictEqual(curried.length, 0);
3910 assert.strictEqual(curried(1).length, 0);
3911 assert.strictEqual(curried(1, 2).length, 0);
3915 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
3918 function Foo(value) {
3919 return value && object;
3922 var curried = _.curry(Foo),
3925 assert.ok(new curried(false) instanceof Foo);
3926 assert.strictEqual(new curried(true), object);
3929 QUnit.test('should use `this` binding of function', function(assert) {
3932 var fn = function(a, b, c) {
3933 var value = this || {};
3934 return [value[a], value[b], value[c]];
3937 var object = { 'a': 1, 'b': 2, 'c': 3 },
3938 expected = [1, 2, 3];
3940 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
3941 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
3942 assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
3944 assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
3945 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
3946 assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
3948 object.curried = _.curry(fn);
3949 assert.deepEqual(object.curried('a')('b')('c'), Array(3));
3950 assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
3951 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
3954 QUnit.test('should work with partialed methods', function(assert) {
3957 var curried = _.curry(fn),
3958 expected = [1, 2, 3, 4];
3960 var a = _.partial(curried, 1),
3961 b = _.bind(a, null, 2),
3962 c = _.partialRight(b, 4),
3963 d = _.partialRight(b(3), 4);
3965 assert.deepEqual(c(3), expected);
3966 assert.deepEqual(d(), expected);
3970 /*--------------------------------------------------------------------------*/
3972 QUnit.module('lodash.curryRight');
3975 function fn(a, b, c, d) {
3976 return slice.call(arguments);
3979 QUnit.test('should curry based on the number of arguments given', function(assert) {
3982 var curried = _.curryRight(fn),
3983 expected = [1, 2, 3, 4];
3985 assert.deepEqual(curried(4)(3)(2)(1), expected);
3986 assert.deepEqual(curried(3, 4)(1, 2), expected);
3987 assert.deepEqual(curried(1, 2, 3, 4), expected);
3990 QUnit.test('should allow specifying `arity`', function(assert) {
3993 var curried = _.curryRight(fn, 3),
3994 expected = [1, 2, 3];
3996 assert.deepEqual(curried(3)(1, 2), expected);
3997 assert.deepEqual(curried(2, 3)(1), expected);
3998 assert.deepEqual(curried(1, 2, 3), expected);
4001 QUnit.test('should coerce `arity` to an integer', function(assert) {
4004 var values = ['0', 0.6, 'xyz'],
4005 expected = lodashStable.map(values, stubArray);
4007 var actual = lodashStable.map(values, function(arity) {
4008 return _.curryRight(fn, arity)();
4011 assert.deepEqual(actual, expected);
4012 assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
4015 QUnit.test('should support placeholders', function(assert) {
4018 var curried = _.curryRight(fn),
4019 expected = [1, 2, 3, 4],
4020 ph = curried.placeholder;
4022 assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
4023 assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
4024 assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
4025 assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
4028 QUnit.test('should persist placeholders', function(assert) {
4031 var curried = _.curryRight(fn),
4032 ph = curried.placeholder,
4033 actual = curried('a', ph, ph, ph)('b')(ph)('c')('d');
4035 assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
4038 QUnit.test('should use `_.placeholder` when set', function(assert) {
4041 if (!isModularize) {
4042 var curried = _.curryRight(fn),
4043 _ph = _.placeholder = {},
4044 ph = curried.placeholder;
4046 assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]);
4047 delete _.placeholder;
4054 QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
4057 var curried = _.curryRight(fn, 3);
4058 assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
4059 assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
4060 assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
4063 QUnit.test('should create a function with a `length` of `0`', function(assert) {
4066 lodashStable.times(2, function(index) {
4067 var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
4068 assert.strictEqual(curried.length, 0);
4069 assert.strictEqual(curried(4).length, 0);
4070 assert.strictEqual(curried(3, 4).length, 0);
4074 QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
4077 function Foo(value) {
4078 return value && object;
4081 var curried = _.curryRight(Foo),
4084 assert.ok(new curried(false) instanceof Foo);
4085 assert.strictEqual(new curried(true), object);
4088 QUnit.test('should use `this` binding of function', function(assert) {
4091 var fn = function(a, b, c) {
4092 var value = this || {};
4093 return [value[a], value[b], value[c]];
4096 var object = { 'a': 1, 'b': 2, 'c': 3 },
4097 expected = [1, 2, 3];
4099 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
4100 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
4101 assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
4103 assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
4104 assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
4105 assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
4107 object.curried = _.curryRight(fn);
4108 assert.deepEqual(object.curried('c')('b')('a'), Array(3));
4109 assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
4110 assert.deepEqual(object.curried('a', 'b', 'c'), expected);
4113 QUnit.test('should work with partialed methods', function(assert) {
4116 var curried = _.curryRight(fn),
4117 expected = [1, 2, 3, 4];
4119 var a = _.partialRight(curried, 4),
4120 b = _.partialRight(a, 3),
4121 c = _.bind(b, null, 1),
4122 d = _.partial(b(2), 1);
4124 assert.deepEqual(c(2), expected);
4125 assert.deepEqual(d(), expected);
4129 /*--------------------------------------------------------------------------*/
4131 QUnit.module('curry methods');
4133 lodashStable.each(['curry', 'curryRight'], function(methodName) {
4134 var func = _[methodName],
4135 fn = function(a, b) { return slice.call(arguments); },
4136 isCurry = methodName == 'curry';
4138 QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
4141 function run(a, b) {
4145 var curried = func(run);
4148 var actual = curried(1)(2);
4151 assert.strictEqual(actual, 3);
4154 QUnit.test('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function(assert) {
4157 var curried = _.curry(function hasOwnProperty(a, b, c) {
4161 var expected = [1, 2, 3];
4163 assert.deepEqual(curried(1)(2)(3), expected);
4166 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
4169 var array = [fn, fn, fn],
4170 object = { 'a': fn, 'b': fn, 'c': fn };
4172 lodashStable.each([array, object], function(collection) {
4173 var curries = lodashStable.map(collection, func),
4174 expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
4176 var actual = lodashStable.map(curries, function(curried) {
4177 return curried('a')('b');
4180 assert.deepEqual(actual, expected);
4185 /*--------------------------------------------------------------------------*/
4187 QUnit.module('lodash.debounce');
4190 QUnit.test('should debounce a function', function(assert) {
4193 var done = assert.async();
4197 var debounced = _.debounce(function(value) {
4202 var results = [debounced('a'), debounced('b'), debounced('c')];
4203 assert.deepEqual(results, [undefined, undefined, undefined]);
4204 assert.strictEqual(callCount, 0);
4206 setTimeout(function() {
4207 assert.strictEqual(callCount, 1);
4209 var results = [debounced('d'), debounced('e'), debounced('f')];
4210 assert.deepEqual(results, ['c', 'c', 'c']);
4211 assert.strictEqual(callCount, 1);
4214 setTimeout(function() {
4215 assert.strictEqual(callCount, 2);
4220 QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
4223 var done = assert.async();
4225 var debounced = _.debounce(identity, 32);
4228 setTimeout(function() {
4229 assert.notEqual(debounced('b'), 'b');
4232 setTimeout(function() {
4233 assert.notEqual(debounced('c'), 'c');
4238 QUnit.test('should not immediately call `func` when `wait` is `0`', function(assert) {
4241 var done = assert.async();
4244 debounced = _.debounce(function() { ++callCount; }, 0);
4248 assert.strictEqual(callCount, 0);
4250 setTimeout(function() {
4251 assert.strictEqual(callCount, 1);
4256 QUnit.test('should apply default options', function(assert) {
4259 var done = assert.async();
4262 debounced = _.debounce(function() { callCount++; }, 32, {});
4265 assert.strictEqual(callCount, 0);
4267 setTimeout(function() {
4268 assert.strictEqual(callCount, 1);
4273 QUnit.test('should support a `leading` option', function(assert) {
4276 var done = assert.async();
4278 var callCounts = [0, 0];
4280 var withLeading = _.debounce(function() {
4282 }, 32, { 'leading': true });
4284 var withLeadingAndTrailing = _.debounce(function() {
4286 }, 32, { 'leading': true });
4289 assert.strictEqual(callCounts[0], 1);
4291 withLeadingAndTrailing();
4292 withLeadingAndTrailing();
4293 assert.strictEqual(callCounts[1], 1);
4295 setTimeout(function() {
4296 assert.deepEqual(callCounts, [1, 2]);
4299 assert.strictEqual(callCounts[0], 2);
4305 QUnit.test('subsequent leading debounced calls return the last `func` result', function(assert) {
4308 var done = assert.async();
4310 var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
4311 results = [debounced('a'), debounced('b')];
4313 assert.deepEqual(results, ['a', 'a']);
4315 setTimeout(function() {
4316 var results = [debounced('c'), debounced('d')];
4317 assert.deepEqual(results, ['c', 'c']);
4322 QUnit.test('should support a `trailing` option', function(assert) {
4325 var done = assert.async();
4330 var withTrailing = _.debounce(function() {
4332 }, 32, { 'trailing': true });
4334 var withoutTrailing = _.debounce(function() {
4336 }, 32, { 'trailing': false });
4339 assert.strictEqual(withCount, 0);
4342 assert.strictEqual(withoutCount, 0);
4344 setTimeout(function() {
4345 assert.strictEqual(withCount, 1);
4346 assert.strictEqual(withoutCount, 0);
4351 QUnit.test('should support a `maxWait` option', function(assert) {
4354 var done = assert.async();
4358 var debounced = _.debounce(function(value) {
4361 }, 32, { 'maxWait': 64 });
4365 assert.strictEqual(callCount, 0);
4367 setTimeout(function() {
4368 assert.strictEqual(callCount, 1);
4371 assert.strictEqual(callCount, 1);
4374 setTimeout(function() {
4375 assert.strictEqual(callCount, 2);
4380 QUnit.test('should support `maxWait` in a tight loop', function(assert) {
4383 var done = assert.async();
4385 var limit = (argv || isPhantom) ? 1000 : 320,
4389 var withMaxWait = _.debounce(function() {
4391 }, 64, { 'maxWait': 128 });
4393 var withoutMaxWait = _.debounce(function() {
4397 var start = +new Date;
4398 while ((new Date - start) < limit) {
4402 var actual = [Boolean(withoutCount), Boolean(withCount)];
4403 setTimeout(function() {
4404 assert.deepEqual(actual, [false, true]);
4409 QUnit.test('should queue a trailing call for subsequent debounced calls after `maxWait`', function(assert) {
4412 var done = assert.async();
4416 var debounced = _.debounce(function() {
4418 }, 200, { 'maxWait': 200 });
4422 setTimeout(debounced, 190);
4423 setTimeout(debounced, 200);
4424 setTimeout(debounced, 210);
4426 setTimeout(function() {
4427 assert.strictEqual(callCount, 2);
4432 QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
4435 var done = assert.async();
4439 var debounced = _.debounce(function() {
4441 }, 32, { 'maxWait': 64 });
4445 setTimeout(function() {
4447 assert.strictEqual(callCount, 1);
4450 setTimeout(function() {
4451 assert.strictEqual(callCount, 2);
4456 QUnit.test('should invoke the trailing call with the correct arguments and `this` binding', function(assert) {
4459 var done = assert.async();
4465 var debounced = _.debounce(function(value) {
4467 push.apply(actual, arguments);
4468 return ++callCount != 2;
4469 }, 32, { 'leading': true, 'maxWait': 64 });
4472 if (!debounced.call(object, 'a')) {
4476 setTimeout(function() {
4477 assert.strictEqual(callCount, 2);
4478 assert.deepEqual(actual, [object, 'a']);
4484 /*--------------------------------------------------------------------------*/
4486 QUnit.module('lodash.deburr');
4489 QUnit.test('should convert Latin Unicode letters to basic Latin', function(assert) {
4492 var actual = lodashStable.map(burredLetters, _.deburr);
4493 assert.deepEqual(actual, deburredLetters);
4496 QUnit.test('should not deburr Latin mathematical operators', function(assert) {
4499 var operators = ['\xd7', '\xf7'],
4500 actual = lodashStable.map(operators, _.deburr);
4502 assert.deepEqual(actual, operators);
4505 QUnit.test('should deburr combining diacritical marks', function(assert) {
4508 var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
4510 var actual = lodashStable.map(comboMarks, function(chr) {
4511 return _.deburr('e' + chr + 'i');
4514 assert.deepEqual(actual, expected);
4518 /*--------------------------------------------------------------------------*/
4520 QUnit.module('lodash.defaults');
4523 QUnit.test('should assign source properties if missing on `object`', function(assert) {
4526 var actual = _.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 });
4527 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
4530 QUnit.test('should accept multiple sources', function(assert) {
4533 var expected = { 'a': 1, 'b': 2, 'c': 3 },
4534 actual = _.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 });
4536 assert.deepEqual(actual, expected);
4538 actual = _.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 });
4539 assert.deepEqual(actual, expected);
4542 QUnit.test('should not overwrite `null` values', function(assert) {
4545 var actual = _.defaults({ 'a': null }, { 'a': 1 });
4546 assert.strictEqual(actual.a, null);
4549 QUnit.test('should overwrite `undefined` values', function(assert) {
4552 var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
4553 assert.strictEqual(actual.a, 1);
4556 QUnit.test('should assign `undefined` values', function(assert) {
4559 var source = { 'a': undefined, 'b': 1 },
4560 actual = _.defaults({}, source);
4562 assert.deepEqual(actual, { 'a': undefined, 'b': 1 });
4565 QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
4569 'constructor': objectProto.constructor,
4570 'hasOwnProperty': objectProto.hasOwnProperty,
4571 'isPrototypeOf': objectProto.isPrototypeOf,
4572 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
4573 'toLocaleString': objectProto.toLocaleString,
4574 'toString': objectProto.toString,
4575 'valueOf': objectProto.valueOf
4580 'hasOwnProperty': 2,
4582 'propertyIsEnumerable': 4,
4583 'toLocaleString': 5,
4588 var expected = lodashStable.clone(source);
4589 assert.deepEqual(_.defaults({}, source), expected);
4591 expected = lodashStable.clone(object);
4592 assert.deepEqual(_.defaults({}, object, source), expected);
4596 /*--------------------------------------------------------------------------*/
4598 QUnit.module('lodash.defaultsDeep');
4601 QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
4604 var object = { 'a': { 'b': 2 }, 'd': 4 },
4605 source = { 'a': { 'b': 3, 'c': 3 }, 'e': 5 },
4606 expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
4608 assert.deepEqual(_.defaultsDeep(object, source), expected);
4611 QUnit.test('should accept multiple sources', function(assert) {
4614 var source1 = { 'a': { 'b': 3 } },
4615 source2 = { 'a': { 'c': 3 } },
4616 source3 = { 'a': { 'b': 3, 'c': 3 } },
4617 source4 = { 'a': { 'c': 4 } },
4618 expected = { 'a': { 'b': 2, 'c': 3 } };
4620 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
4621 assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
4624 QUnit.test('should not overwrite `null` values', function(assert) {
4627 var object = { 'a': { 'b': null } },
4628 source = { 'a': { 'b': 2 } },
4629 actual = _.defaultsDeep(object, source);
4631 assert.strictEqual(actual.a.b, null);
4634 QUnit.test('should not overwrite regexp values', function(assert) {
4637 var object = { 'a': { 'b': /x/ } },
4638 source = { 'a': { 'b': /y/ } },
4639 actual = _.defaultsDeep(object, source);
4641 assert.deepEqual(actual.a.b, /x/);
4644 QUnit.test('should not convert function properties to objects', function(assert) {
4647 var actual = _.defaultsDeep({}, { 'a': noop });
4648 assert.strictEqual(actual.a, noop);
4650 actual = _.defaultsDeep({}, { 'a': { 'b': noop } });
4651 assert.strictEqual(actual.a.b, noop);
4654 QUnit.test('should overwrite `undefined` values', function(assert) {
4657 var object = { 'a': { 'b': undefined } },
4658 source = { 'a': { 'b': 2 } },
4659 actual = _.defaultsDeep(object, source);
4661 assert.strictEqual(actual.a.b, 2);
4664 QUnit.test('should assign `undefined` values', function(assert) {
4667 var source = { 'a': undefined, 'b': { 'c': undefined, 'd': 1 } },
4668 expected = lodashStable.cloneDeep(source),
4669 actual = _.defaultsDeep({}, source);
4671 assert.deepEqual(actual, expected);
4674 QUnit.test('should merge sources containing circular references', function(assert) {
4678 'foo': { 'b': { 'c': { 'd': {} } } },
4683 'foo': { 'b': { 'c': { 'd': {} } } },
4687 object.foo.b.c.d = object;
4688 source.foo.b.c.d = source;
4689 source.bar.b = source.foo.b;
4691 var actual = _.defaultsDeep(object, source);
4693 assert.strictEqual(actual.bar.b, actual.foo.b);
4694 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
4697 QUnit.test('should not modify sources', function(assert) {
4700 var source1 = { 'a': 1, 'b': { 'c': 2 } },
4701 source2 = { 'b': { 'c': 3, 'd': 3 } },
4702 actual = _.defaultsDeep({}, source1, source2);
4704 assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
4705 assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
4706 assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
4709 QUnit.test('should not attempt a merge of a string into an array', function(assert) {
4712 var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
4713 assert.deepEqual(actual.a, ['abc']);
4717 /*--------------------------------------------------------------------------*/
4719 QUnit.module('lodash.defaultTo');
4722 QUnit.test('should return a default value if `value` is `NaN` or nullish', function(assert) {
4725 var expected = lodashStable.map(falsey, function(value) {
4726 return (value == null || value !== value) ? 1 : value;
4729 var actual = lodashStable.map(falsey, function(value) {
4730 return _.defaultTo(value, 1);
4733 assert.deepEqual(actual, expected);
4737 /*--------------------------------------------------------------------------*/
4739 QUnit.module('lodash.defer');
4742 QUnit.test('should defer `func` execution', function(assert) {
4745 var done = assert.async();
4748 _.defer(function() { pass = true; });
4750 setTimeout(function() {
4756 QUnit.test('should provide additional arguments to `func`', function(assert) {
4759 var done = assert.async();
4763 _.defer(function() {
4764 args = slice.call(arguments);
4767 setTimeout(function() {
4768 assert.deepEqual(args, [1, 2]);
4773 QUnit.test('should be cancelable', function(assert) {
4776 var done = assert.async();
4779 timerId = _.defer(function() { pass = false; });
4781 clearTimeout(timerId);
4783 setTimeout(function() {
4790 /*--------------------------------------------------------------------------*/
4792 QUnit.module('lodash.delay');
4795 QUnit.test('should delay `func` execution', function(assert) {
4798 var done = assert.async();
4801 _.delay(function() { pass = true; }, 32);
4803 setTimeout(function() {
4807 setTimeout(function() {
4813 QUnit.test('should provide additional arguments to `func`', function(assert) {
4816 var done = assert.async();
4820 _.delay(function() {
4821 args = slice.call(arguments);
4824 setTimeout(function() {
4825 assert.deepEqual(args, [1, 2]);
4830 QUnit.test('should use a default `wait` of `0`', function(assert) {
4833 var done = assert.async();
4836 _.delay(function() { pass = true; });
4840 setTimeout(function() {
4846 QUnit.test('should be cancelable', function(assert) {
4849 var done = assert.async();
4852 timerId = _.delay(function() { pass = false; }, 32);
4854 clearTimeout(timerId);
4856 setTimeout(function() {
4862 QUnit.test('should work with mocked `setTimeout`', function(assert) {
4867 setTimeout = root.setTimeout;
4869 setProperty(root, 'setTimeout', function(func) { func(); });
4870 _.delay(function() { pass = true; }, 32);
4871 setProperty(root, 'setTimeout', setTimeout);
4881 /*--------------------------------------------------------------------------*/
4883 QUnit.module('difference methods');
4885 lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
4886 var func = _[methodName];
4888 QUnit.test('`_.' + methodName + '` should return the difference of two arrays', function(assert) {
4891 var actual = func([2, 1], [2, 3]);
4892 assert.deepEqual(actual, [1]);
4895 QUnit.test('`_.' + methodName + '` should return the difference of multiple arrays', function(assert) {
4898 var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
4899 assert.deepEqual(actual, [1]);
4902 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
4905 var array = [-0, 0];
4907 var actual = lodashStable.map(array, function(value) {
4908 return func(array, [value]);
4911 assert.deepEqual(actual, [[], []]);
4913 actual = lodashStable.map(func([-0, 1], [1]), lodashStable.toString);
4914 assert.deepEqual(actual, ['0']);
4917 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
4920 assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
4923 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
4926 var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
4927 array2 = lodashStable.range(LARGE_ARRAY_SIZE),
4932 array1.push(a, b, c);
4933 array2.push(b, c, a);
4935 assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
4938 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
4941 var array = [-0, 0];
4943 var actual = lodashStable.map(array, function(value) {
4944 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
4945 return func(array, largeArray);
4948 assert.deepEqual(actual, [[], []]);
4950 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne);
4951 actual = lodashStable.map(func([-0, 1], largeArray), lodashStable.toString);
4952 assert.deepEqual(actual, ['0']);
4955 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
4958 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
4959 assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
4962 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
4967 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
4969 assert.deepEqual(func([object1, object2], largeArray), [object2]);
4972 QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
4975 var array = [1, null, 3];
4977 assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
4978 assert.deepEqual(func(null, array, 1), []);
4979 assert.deepEqual(func(array, args, null), [null]);
4983 /*--------------------------------------------------------------------------*/
4985 QUnit.module('lodash.differenceBy');
4988 QUnit.test('should accept an `iteratee`', function(assert) {
4991 var actual = _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
4992 assert.deepEqual(actual, [1.2]);
4994 actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
4995 assert.deepEqual(actual, [{ 'x': 2 }]);
4998 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
5003 _.differenceBy([2.1, 1.2], [2.3, 3.4], function() {
5004 args || (args = slice.call(arguments));
5007 assert.deepEqual(args, [2.3]);
5011 /*--------------------------------------------------------------------------*/
5013 QUnit.module('lodash.differenceWith');
5016 QUnit.test('should work with a `comparator`', function(assert) {
5019 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
5020 actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
5022 assert.deepEqual(actual, [objects[1]]);
5025 QUnit.test('should preserve the sign of `0`', function(assert) {
5028 var array = [-0, 1],
5029 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne),
5030 others = [[1], largeArray],
5031 expected = lodashStable.map(others, lodashStable.constant(['-0']));
5033 var actual = lodashStable.map(others, function(other) {
5034 return lodashStable.map(_.differenceWith(array, other, lodashStable.eq), lodashStable.toString);
5037 assert.deepEqual(actual, expected);
5041 /*--------------------------------------------------------------------------*/
5043 QUnit.module('lodash.divide');
5046 QUnit.test('should divide two numbers', function(assert) {
5049 assert.strictEqual(_.divide(6, 4), 1.5);
5050 assert.strictEqual(_.divide(-6, 4), -1.5);
5051 assert.strictEqual(_.divide(-6, -4), 1.5);
5054 QUnit.test('should coerce arguments to numbers', function(assert) {
5057 assert.strictEqual(_.divide('6', '4'), 1.5);
5058 assert.deepEqual(_.divide('x', 'y'), NaN);
5062 /*--------------------------------------------------------------------------*/
5064 QUnit.module('lodash.drop');
5067 var array = [1, 2, 3];
5069 QUnit.test('should drop the first two elements', function(assert) {
5072 assert.deepEqual(_.drop(array, 2), [3]);
5075 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
5078 var expected = lodashStable.map(falsey, function(value) {
5079 return value === undefined ? [2, 3] : array;
5082 var actual = lodashStable.map(falsey, function(n) {
5083 return _.drop(array, n);
5086 assert.deepEqual(actual, expected);
5089 QUnit.test('should return all elements when `n` < `1`', function(assert) {
5092 lodashStable.each([0, -1, -Infinity], function(n) {
5093 assert.deepEqual(_.drop(array, n), array);
5097 QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
5100 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
5101 assert.deepEqual(_.drop(array, n), []);
5105 QUnit.test('should coerce `n` to an integer', function(assert) {
5108 assert.deepEqual(_.drop(array, 1.6), [2, 3]);
5111 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5114 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
5115 actual = lodashStable.map(array, _.drop);
5117 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
5120 QUnit.test('should work in a lazy sequence', function(assert) {
5124 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5125 predicate = function(value) { values.push(value); return isEven(value); },
5127 actual = _(array).drop(2).drop().value();
5129 assert.deepEqual(actual, array.slice(3));
5131 actual = _(array).filter(predicate).drop(2).drop().value();
5132 assert.deepEqual(values, array);
5133 assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
5135 actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
5136 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
5140 actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
5141 assert.deepEqual(values, array.slice(1));
5142 assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
5145 skipAssert(assert, 6);
5150 /*--------------------------------------------------------------------------*/
5152 QUnit.module('lodash.dropRight');
5155 var array = [1, 2, 3];
5157 QUnit.test('should drop the last two elements', function(assert) {
5160 assert.deepEqual(_.dropRight(array, 2), [1]);
5163 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
5166 var expected = lodashStable.map(falsey, function(value) {
5167 return value === undefined ? [1, 2] : array;
5170 var actual = lodashStable.map(falsey, function(n) {
5171 return _.dropRight(array, n);
5174 assert.deepEqual(actual, expected);
5177 QUnit.test('should return all elements when `n` < `1`', function(assert) {
5180 lodashStable.each([0, -1, -Infinity], function(n) {
5181 assert.deepEqual(_.dropRight(array, n), array);
5185 QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
5188 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
5189 assert.deepEqual(_.dropRight(array, n), []);
5193 QUnit.test('should coerce `n` to an integer', function(assert) {
5196 assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
5199 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5202 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
5203 actual = lodashStable.map(array, _.dropRight);
5205 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
5208 QUnit.test('should work in a lazy sequence', function(assert) {
5212 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5213 predicate = function(value) { values.push(value); return isEven(value); },
5215 actual = _(array).dropRight(2).dropRight().value();
5217 assert.deepEqual(actual, array.slice(0, -3));
5219 actual = _(array).filter(predicate).dropRight(2).dropRight().value();
5220 assert.deepEqual(values, array);
5221 assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
5223 actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
5224 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
5228 actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
5229 assert.deepEqual(values, array.slice(0, -1));
5230 assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
5233 skipAssert(assert, 6);
5238 /*--------------------------------------------------------------------------*/
5240 QUnit.module('lodash.dropRightWhile');
5243 var array = [1, 2, 3, 4];
5251 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5254 var actual = _.dropRightWhile(array, function(n) {
5258 assert.deepEqual(actual, [1, 2]);
5261 QUnit.test('should provide correct `predicate` arguments', function(assert) {
5266 _.dropRightWhile(array, function() {
5267 args = slice.call(arguments);
5270 assert.deepEqual(args, [4, 3, array]);
5273 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5276 assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
5279 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5282 assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
5285 QUnit.test('should work with `_.property` shorthands', function(assert) {
5288 assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
5291 QUnit.test('should return a wrapped value when chaining', function(assert) {
5295 var wrapped = _(array).dropRightWhile(function(n) {
5299 assert.ok(wrapped instanceof _);
5300 assert.deepEqual(wrapped.value(), [1, 2]);
5303 skipAssert(assert, 2);
5308 /*--------------------------------------------------------------------------*/
5310 QUnit.module('lodash.dropWhile');
5313 var array = [1, 2, 3, 4];
5321 QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
5324 var actual = _.dropWhile(array, function(n) {
5328 assert.deepEqual(actual, [3, 4]);
5331 QUnit.test('should provide correct `predicate` arguments', function(assert) {
5336 _.dropWhile(array, function() {
5337 args = slice.call(arguments);
5340 assert.deepEqual(args, [1, 0, array]);
5343 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5346 assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
5349 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
5352 assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
5355 QUnit.test('should work with `_.property` shorthands', function(assert) {
5358 assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
5361 QUnit.test('should work in a lazy sequence', function(assert) {
5365 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
5366 predicate = function(n) { return n < 3; },
5367 expected = _.dropWhile(array, predicate),
5368 wrapped = _(array).dropWhile(predicate);
5370 assert.deepEqual(wrapped.value(), expected);
5371 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
5372 assert.strictEqual(wrapped.last(), _.last(expected));
5375 skipAssert(assert, 3);
5379 QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
5383 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
5385 var actual = _(array)
5386 .dropWhile(function(n) { return n == 1; })
5388 .dropWhile(function(n) { return n == 3; })
5391 assert.deepEqual(actual, array.slice(3));
5399 /*--------------------------------------------------------------------------*/
5401 QUnit.module('lodash.endsWith');
5406 QUnit.test('should return `true` if a string ends with `target`', function(assert) {
5409 assert.strictEqual(_.endsWith(string, 'c'), true);
5412 QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
5415 assert.strictEqual(_.endsWith(string, 'b'), false);
5418 QUnit.test('should work with a `position`', function(assert) {
5421 assert.strictEqual(_.endsWith(string, 'b', 2), true);
5424 QUnit.test('should work with `position` >= `length`', function(assert) {
5427 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
5428 assert.strictEqual(_.endsWith(string, 'c', position), true);
5432 QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
5435 var expected = lodashStable.map(falsey, stubTrue);
5437 var actual = lodashStable.map(falsey, function(position) {
5438 return _.endsWith(string, position === undefined ? 'c' : '', position);
5441 assert.deepEqual(actual, expected);
5444 QUnit.test('should treat a negative `position` as `0`', function(assert) {
5447 lodashStable.each([-1, -3, -Infinity], function(position) {
5448 assert.ok(lodashStable.every(string, function(chr) {
5449 return !_.endsWith(string, chr, position);
5451 assert.strictEqual(_.endsWith(string, '', position), true);
5455 QUnit.test('should coerce `position` to an integer', function(assert) {
5458 assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
5462 /*--------------------------------------------------------------------------*/
5464 QUnit.module('lodash.eq');
5467 QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
5470 assert.strictEqual(_.eq(), true);
5471 assert.strictEqual(_.eq(undefined), true);
5472 assert.strictEqual(_.eq(0, -0), true);
5473 assert.strictEqual(_.eq(NaN, NaN), true);
5474 assert.strictEqual(_.eq(1, 1), true);
5476 assert.strictEqual(_.eq(null, undefined), false);
5477 assert.strictEqual(_.eq(1, Object(1)), false);
5478 assert.strictEqual(_.eq(1, '1'), false);
5479 assert.strictEqual(_.eq(1, '1'), false);
5481 var object = { 'a': 1 };
5482 assert.strictEqual(_.eq(object, object), true);
5483 assert.strictEqual(_.eq(object, { 'a': 1 }), false);
5487 /*--------------------------------------------------------------------------*/
5489 QUnit.module('lodash.escape');
5492 var escaped = '&<>"'/',
5493 unescaped = '&<>"\'/';
5496 unescaped += unescaped;
5498 QUnit.test('should escape values', function(assert) {
5501 assert.strictEqual(_.escape(unescaped), escaped);
5504 QUnit.test('should handle strings with nothing to escape', function(assert) {
5507 assert.strictEqual(_.escape('abc'), 'abc');
5510 QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
5513 assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
5516 lodashStable.each(['`', '/'], function(chr) {
5517 QUnit.test('should not escape the "' + chr + '" character', function(assert) {
5520 assert.strictEqual(_.escape(chr), chr);
5525 /*--------------------------------------------------------------------------*/
5527 QUnit.module('lodash.escapeRegExp');
5530 var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
5531 unescaped = '^$.*+?()[]{}|\\';
5533 QUnit.test('should escape values', function(assert) {
5536 assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
5539 QUnit.test('should handle strings with nothing to escape', function(assert) {
5542 assert.strictEqual(_.escapeRegExp('abc'), 'abc');
5545 QUnit.test('should return an empty string for empty values', function(assert) {
5548 var values = [, null, undefined, ''],
5549 expected = lodashStable.map(values, stubString);
5551 var actual = lodashStable.map(values, function(value, index) {
5552 return index ? _.escapeRegExp(value) : _.escapeRegExp();
5555 assert.deepEqual(actual, expected);
5559 /*--------------------------------------------------------------------------*/
5561 QUnit.module('lodash.every');
5564 QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
5567 assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
5570 QUnit.test('should return `true` for empty collections', function(assert) {
5573 var expected = lodashStable.map(empties, stubTrue);
5575 var actual = lodashStable.map(empties, function(value) {
5577 return _.every(value, identity);
5581 assert.deepEqual(actual, expected);
5584 QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
5589 assert.strictEqual(_.every([true, null, true], function(value) {
5594 assert.strictEqual(count, 2);
5597 QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
5600 assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
5603 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
5606 var values = [, null, undefined],
5607 expected = lodashStable.map(values, stubFalse);
5609 var actual = lodashStable.map(values, function(value, index) {
5611 return index ? _.every(array, value) : _.every(array);
5614 assert.deepEqual(actual, expected);
5616 expected = lodashStable.map(values, stubTrue);
5617 actual = lodashStable.map(values, function(value, index) {
5619 return index ? _.every(array, value) : _.every(array);
5622 assert.deepEqual(actual, expected);
5625 QUnit.test('should work with `_.property` shorthands', function(assert) {
5628 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
5629 assert.strictEqual(_.every(objects, 'a'), false);
5630 assert.strictEqual(_.every(objects, 'b'), true);
5633 QUnit.test('should work with `_.matches` shorthands', function(assert) {
5636 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
5637 assert.strictEqual(_.every(objects, { 'a': 0 }), true);
5638 assert.strictEqual(_.every(objects, { 'b': 1 }), false);
5641 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5644 var actual = lodashStable.map([[1]], _.every);
5645 assert.deepEqual(actual, [true]);
5649 /*--------------------------------------------------------------------------*/
5651 QUnit.module('strict mode checks');
5653 lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults', 'defaultsDeep', 'merge'], function(methodName) {
5654 var func = _[methodName],
5655 isBindAll = methodName == 'bindAll';
5657 QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
5660 var object = freeze({ 'a': undefined, 'b': function() {} }),
5664 func(object, isBindAll ? 'b' : { 'a': 1 });
5672 /*--------------------------------------------------------------------------*/
5674 QUnit.module('lodash.fill');
5677 QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
5680 var array = [1, 2, 3];
5681 assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
5684 QUnit.test('should use `undefined` for `value` if not given', function(assert) {
5687 var array = [1, 2, 3],
5688 actual = _.fill(array);
5690 assert.deepEqual(actual, Array(3));
5691 assert.ok(lodashStable.every(actual, function(value, index) {
5692 return index in actual;
5696 QUnit.test('should work with a positive `start`', function(assert) {
5699 var array = [1, 2, 3];
5700 assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
5703 QUnit.test('should work with a `start` >= `length`', function(assert) {
5706 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
5707 var array = [1, 2, 3];
5708 assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
5712 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
5715 var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
5717 var actual = lodashStable.map(falsey, function(start) {
5718 var array = [1, 2, 3];
5719 return _.fill(array, 'a', start);
5722 assert.deepEqual(actual, expected);
5725 QUnit.test('should work with a negative `start`', function(assert) {
5728 var array = [1, 2, 3];
5729 assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
5732 QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
5735 lodashStable.each([-3, -4, -Infinity], function(start) {
5736 var array = [1, 2, 3];
5737 assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
5741 QUnit.test('should work with `start` >= `end`', function(assert) {
5744 lodashStable.each([2, 3], function(start) {
5745 var array = [1, 2, 3];
5746 assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
5750 QUnit.test('should work with a positive `end`', function(assert) {
5753 var array = [1, 2, 3];
5754 assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
5757 QUnit.test('should work with a `end` >= `length`', function(assert) {
5760 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
5761 var array = [1, 2, 3];
5762 assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
5766 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
5769 var expected = lodashStable.map(falsey, function(value) {
5770 return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
5773 var actual = lodashStable.map(falsey, function(end) {
5774 var array = [1, 2, 3];
5775 return _.fill(array, 'a', 0, end);
5778 assert.deepEqual(actual, expected);
5781 QUnit.test('should work with a negative `end`', function(assert) {
5784 var array = [1, 2, 3];
5785 assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
5788 QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
5791 lodashStable.each([-3, -4, -Infinity], function(end) {
5792 var array = [1, 2, 3];
5793 assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
5797 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
5800 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
5802 var actual = lodashStable.map(positions, function(pos) {
5803 var array = [1, 2, 3];
5804 return _.fill.apply(_, [array, 'a'].concat(pos));
5807 assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
5810 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
5813 var array = [[1, 2], [3, 4]],
5814 actual = lodashStable.map(array, _.fill);
5816 assert.deepEqual(actual, [[0, 0], [1, 1]]);
5819 QUnit.test('should return a wrapped value when chaining', function(assert) {
5823 var array = [1, 2, 3],
5824 wrapped = _(array).fill('a'),
5825 actual = wrapped.value();
5827 assert.ok(wrapped instanceof _);
5828 assert.strictEqual(actual, array);
5829 assert.deepEqual(actual, ['a', 'a', 'a']);
5832 skipAssert(assert, 3);
5837 /*--------------------------------------------------------------------------*/
5839 QUnit.module('lodash.filter');
5842 var array = [1, 2, 3];
5844 QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
5847 assert.deepEqual(_.filter(array, isEven), [2]);
5851 /*--------------------------------------------------------------------------*/
5853 lodashStable.each(['find', 'findIndex', 'findKey', 'findLast', 'findLastIndex', 'findLastKey'], function(methodName) {
5854 QUnit.module('lodash.' + methodName);
5856 var array = [1, 2, 3, 4],
5857 func = _[methodName];
5866 'find': [objects[1], undefined, objects[2]],
5867 'findIndex': [1, -1, 2],
5868 'findKey': ['1', undefined, '2'],
5869 'findLast': [objects[2], undefined, objects[2]],
5870 'findLastIndex': [2, -1, 2],
5871 'findLastKey': ['2', undefined, '2']
5874 QUnit.test('`_.' + methodName + '` should return the found value', function(assert) {
5877 assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
5880 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` if value is not found', function(assert) {
5883 assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
5886 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
5889 assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
5892 QUnit.test('`_.' + methodName + '` should work with `_.matchesProperty` shorthands', function(assert) {
5895 assert.strictEqual(func(objects, ['b', 2]), expected[2]);
5898 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
5901 assert.strictEqual(func(objects, 'b'), expected[0]);
5904 QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` for empty collections', function(assert) {
5907 var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
5908 expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
5910 var actual = lodashStable.map(emptyValues, function(value) {
5912 return func(value, { 'a': 3 });
5916 assert.deepEqual(actual, expecting);
5919 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
5932 assert.strictEqual(_(array)[methodName](), expected);
5939 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
5943 assert.ok(_(array).chain()[methodName]() instanceof _);
5950 QUnit.test('`_.' + methodName + '` should not execute immediately when explicitly chaining', function(assert) {
5954 var wrapped = _(array).chain()[methodName]();
5955 assert.strictEqual(wrapped.__wrapped__, array);
5962 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
5966 var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
5969 lodashStable.times(2, function(index) {
5970 var array = index ? largeArray : smallArray,
5971 wrapped = _(array).filter(isEven);
5973 assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
5977 skipAssert(assert, 2);
5982 _.each(['find', 'findIndex', 'findLast', 'findLastIndex'], function(methodName) {
5983 var func = _[methodName];
5985 QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for arrays', function(assert) {
5991 func(array, function() {
5992 args || (args = slice.call(arguments));
5995 assert.deepEqual(args, ['a', 0, array]);
5999 _.each(['find', 'findKey', 'findLast', 'findLastKey'], function(methodName) {
6000 var func = _[methodName];
6002 QUnit.test('`_.' + methodName + '` should work with an object for `collection`', function(assert) {
6005 var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(n) {
6016 assert.strictEqual(actual, expected);
6019 QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for objects', function(assert) {
6023 object = { 'a': 1 };
6025 func(object, function() {
6026 args || (args = slice.call(arguments));
6029 assert.deepEqual(args, [1, 'a', object]);
6033 /*--------------------------------------------------------------------------*/
6035 QUnit.module('lodash.find and lodash.findLast');
6037 lodashStable.each(['find', 'findLast'], function(methodName) {
6038 var isFind = methodName == 'find';
6040 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
6046 array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
6047 iteratee = function(value) { mapCount++; return square(value); },
6048 predicate = function(value) { findCount++; return isEven(value); },
6049 actual = _(array).map(iteratee)[methodName](predicate);
6051 assert.strictEqual(findCount, isFind ? 2 : 1);
6052 assert.strictEqual(mapCount, isFind ? 2 : 1);
6053 assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
6056 skipAssert(assert, 3);
6061 /*--------------------------------------------------------------------------*/
6063 QUnit.module('lodash.find and lodash.includes');
6065 lodashStable.each(['includes', 'find'], function(methodName) {
6066 var func = _[methodName],
6067 isIncludes = methodName == 'includes',
6068 resolve = methodName == 'find' ? lodashStable.curry(lodashStable.eq) : identity;
6071 'an `arguments` object': args,
6072 'an array': [1, 2, 3]
6074 function(collection, key) {
6075 var values = lodashStable.toArray(collection);
6077 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a positive `fromIndex`', function(assert) {
6081 isIncludes || values[2],
6082 isIncludes ? false : undefined
6086 func(collection, resolve(values[2]), 2),
6087 func(collection, resolve(values[1]), 2)
6090 assert.deepEqual(actual, expected);
6093 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
6096 var indexes = [4, 6, Math.pow(2, 32), Infinity];
6098 var expected = lodashStable.map(indexes, function() {
6099 var result = isIncludes ? false : undefined;
6100 return [result, result, result];
6103 var actual = lodashStable.map(indexes, function(fromIndex) {
6105 func(collection, resolve(1), fromIndex),
6106 func(collection, resolve(undefined), fromIndex),
6107 func(collection, resolve(''), fromIndex)
6111 assert.deepEqual(actual, expected);
6114 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
6117 var expected = lodashStable.map(falsey, lodashStable.constant(isIncludes || values[0]));
6119 var actual = lodashStable.map(falsey, function(fromIndex) {
6120 return func(collection, resolve(values[0]), fromIndex);
6123 assert.deepEqual(actual, expected);
6126 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
6130 isIncludes || values[0],
6131 isIncludes || values[0],
6132 isIncludes ? false : undefined
6136 func(collection, resolve(values[0]), 0.1),
6137 func(collection, resolve(values[0]), NaN),
6138 func(collection, resolve(values[0]), '1')
6141 assert.deepEqual(actual, expected);
6144 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex`', function(assert) {
6148 isIncludes || values[2],
6149 isIncludes ? false : undefined
6153 func(collection, resolve(values[2]), -1),
6154 func(collection, resolve(values[1]), -1)
6157 assert.deepEqual(actual, expected);
6160 QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
6163 var indexes = [-4, -6, -Infinity],
6164 expected = lodashStable.map(indexes, lodashStable.constant(isIncludes || values[0]));
6166 var actual = lodashStable.map(indexes, function(fromIndex) {
6167 return func(collection, resolve(values[0]), fromIndex);
6170 assert.deepEqual(actual, expected);
6175 /*--------------------------------------------------------------------------*/
6177 QUnit.module('lodash.findIndex and lodash.indexOf');
6179 lodashStable.each(['findIndex', 'indexOf'], function(methodName) {
6180 var array = [1, 2, 3, 1, 2, 3],
6181 func = _[methodName],
6182 resolve = methodName == 'findIndex' ? lodashStable.curry(lodashStable.eq) : identity;
6184 QUnit.test('`_.' + methodName + '` should return the index of the first matched value', function(assert) {
6187 assert.strictEqual(func(array, resolve(3)), 2);
6190 QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
6193 assert.strictEqual(func(array, resolve(1), 2), 3);
6196 QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
6199 var values = [6, 8, Math.pow(2, 32), Infinity],
6200 expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
6202 var actual = lodashStable.map(values, function(fromIndex) {
6204 func(array, resolve(undefined), fromIndex),
6205 func(array, resolve(1), fromIndex),
6206 func(array, resolve(''), fromIndex)
6210 assert.deepEqual(actual, expected);
6213 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
6216 assert.strictEqual(func(array, resolve(2), -3), 4);
6219 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
6222 var values = [-6, -8, -Infinity],
6223 expected = lodashStable.map(values, stubZero);
6225 var actual = lodashStable.map(values, function(fromIndex) {
6226 return func(array, resolve(1), fromIndex);
6229 assert.deepEqual(actual, expected);
6232 QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values as `0`', function(assert) {
6235 var expected = lodashStable.map(falsey, stubZero);
6237 var actual = lodashStable.map(falsey, function(fromIndex) {
6238 return func(array, resolve(1), fromIndex);
6241 assert.deepEqual(actual, expected);
6244 QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
6247 assert.strictEqual(func(array, resolve(2), 1.2), 1);
6251 /*--------------------------------------------------------------------------*/
6253 QUnit.module('lodash.findLast');
6256 var resolve = lodashStable.curry(lodashStable.eq);
6259 'an `arguments` object': args,
6260 'an array': [1, 2, 3]
6262 function(collection, key) {
6263 var values = lodashStable.toArray(collection);
6265 QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
6274 _.findLast(collection, resolve(values[1]), 1),
6275 _.findLast(collection, resolve(values[2]), 1)
6278 assert.deepEqual(actual, expected);
6281 QUnit.test('should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
6284 var indexes = [4, 6, Math.pow(2, 32), Infinity];
6286 var expected = lodashStable.map(indexes, lodashStable.constant([values[0], undefined, undefined]));
6288 var actual = lodashStable.map(indexes, function(fromIndex) {
6290 _.findLast(collection, resolve(1), fromIndex),
6291 _.findLast(collection, resolve(undefined), fromIndex),
6292 _.findLast(collection, resolve(''), fromIndex)
6296 assert.deepEqual(actual, expected);
6299 QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values correctly', function(assert) {
6302 var expected = lodashStable.map(falsey, function(value) {
6303 return value === undefined ? values[3] : undefined;
6306 var actual = lodashStable.map(falsey, function(fromIndex) {
6307 return _.findLast(collection, resolve(values[3]), fromIndex);
6310 assert.deepEqual(actual, expected);
6313 QUnit.test('should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
6323 _.findLast(collection, resolve(values[0]), 0.1),
6324 _.findLast(collection, resolve(values[0]), NaN),
6325 _.findLast(collection, resolve(values[2]), '1')
6328 assert.deepEqual(actual, expected);
6331 QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
6340 _.findLast(collection, resolve(values[1]), -2),
6341 _.findLast(collection, resolve(values[2]), -2)
6344 assert.deepEqual(actual, expected);
6347 QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
6350 var indexes = [-4, -6, -Infinity],
6351 expected = lodashStable.map(indexes, lodashStable.constant(values[0]));
6353 var actual = lodashStable.map(indexes, function(fromIndex) {
6354 return _.findLast(collection, resolve(values[0]), fromIndex);
6357 assert.deepEqual(actual, expected);
6362 /*--------------------------------------------------------------------------*/
6364 QUnit.module('lodash.flip');
6368 return slice.call(arguments);
6371 QUnit.test('should flip arguments provided to `func`', function(assert) {
6374 var flipped = _.flip(fn);
6375 assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
6379 /*--------------------------------------------------------------------------*/
6381 QUnit.module('lodash.flatMapDepth');
6384 var array = [1, [2, [3, [4]], 5]];
6386 QUnit.test('should use a default `depth` of `1`', function(assert) {
6389 assert.deepEqual(_.flatMapDepth(array, identity), [1, 2, [3, [4]], 5]);
6392 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
6395 var values = [, null, undefined],
6396 expected = lodashStable.map(values, lodashStable.constant([1, 2, [3, [4]], 5]));
6398 var actual = lodashStable.map(values, function(value, index) {
6399 return index ? _.flatMapDepth(array, value) : _.flatMapDepth(array);
6402 assert.deepEqual(actual, expected);
6405 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
6408 lodashStable.each([-1, 0], function(depth) {
6409 assert.deepEqual(_.flatMapDepth(array, identity, depth), [1, [2, [3, [4]], 5]]);
6413 QUnit.test('should coerce `depth` to an integer', function(assert) {
6416 assert.deepEqual(_.flatMapDepth(array, identity, 2.2), [1, 2, 3, [4], 5]);
6420 /*--------------------------------------------------------------------------*/
6422 QUnit.module('flatMap methods');
6424 lodashStable.each(['flatMap', 'flatMapDeep', 'flatMapDepth'], function(methodName) {
6425 var func = _[methodName],
6426 array = [1, 2, 3, 4];
6428 function duplicate(n) {
6432 QUnit.test('`_.' + methodName + '` should map values in `array` to a new flattened array', function(assert) {
6435 var actual = func(array, duplicate),
6436 expected = lodashStable.flatten(lodashStable.map(array, duplicate));
6438 assert.deepEqual(actual, expected);
6441 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
6444 var objects = [{ 'a': [1, 2] }, { 'a': [3, 4] }];
6445 assert.deepEqual(func(objects, 'a'), array);
6448 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
6454 Foo.prototype.b = [3, 4];
6456 var actual = func(new Foo, identity);
6457 assert.deepEqual(actual, [1, 2]);
6460 QUnit.test('`_.' + methodName + '` should use `_.identity` when `iteratee` is nullish', function(assert) {
6463 var array = [[1, 2], [3, 4]],
6464 object = { 'a': [1, 2], 'b': [3, 4] },
6465 values = [, null, undefined],
6466 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
6468 lodashStable.each([array, object], function(collection) {
6469 var actual = lodashStable.map(values, function(value, index) {
6470 return index ? func(collection, value) : func(collection);
6473 assert.deepEqual(actual, expected);
6477 QUnit.test('`_.' + methodName + '` should accept a falsey `collection`', function(assert) {
6480 var expected = lodashStable.map(falsey, stubArray);
6482 var actual = lodashStable.map(falsey, function(collection, index) {
6484 return index ? func(collection) : func();
6488 assert.deepEqual(actual, expected);
6491 QUnit.test('`_.' + methodName + '` should treat number values for `collection` as empty', function(assert) {
6494 assert.deepEqual(func(1), []);
6497 QUnit.test('`_.' + methodName + '` should work with objects with non-number length properties', function(assert) {
6500 var object = { 'length': [1, 2] };
6501 assert.deepEqual(func(object, identity), [1, 2]);
6505 /*--------------------------------------------------------------------------*/
6507 QUnit.module('lodash.flattenDepth');
6510 var array = [1, [2, [3, [4]], 5]];
6512 QUnit.test('should use a default `depth` of `1`', function(assert) {
6515 assert.deepEqual(_.flattenDepth(array), [1, 2, [3, [4]], 5]);
6518 QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
6521 lodashStable.each([-1, 0], function(depth) {
6522 assert.deepEqual(_.flattenDepth(array, depth), [1, [2, [3, [4]], 5]]);
6526 QUnit.test('should coerce `depth` to an integer', function(assert) {
6529 assert.deepEqual(_.flattenDepth(array, 2.2), [1, 2, 3, [4], 5]);
6533 /*--------------------------------------------------------------------------*/
6535 QUnit.module('flatten methods');
6538 var array = [1, [2, [3, [4]], 5]],
6539 methodNames = ['flatten', 'flattenDeep', 'flattenDepth'];
6541 QUnit.test('should flatten `arguments` objects', function(assert) {
6544 var array = [args, [args]];
6546 assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
6547 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
6548 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);
6551 QUnit.test('should treat sparse arrays as dense', function(assert) {
6554 var array = [[1, 2, 3], Array(3)],
6555 expected = [1, 2, 3];
6557 expected.push(undefined, undefined, undefined);
6559 lodashStable.each(methodNames, function(methodName) {
6560 var actual = _[methodName](array);
6561 assert.deepEqual(actual, expected);
6562 assert.ok('4' in actual);
6566 QUnit.test('should flatten objects with a truthy `Symbol.isConcatSpreadable` value', function(assert) {
6569 if (Symbol && Symbol.isConcatSpreadable) {
6570 var object = { '0': 'a', 'length': 1 },
6572 expected = lodashStable.map(methodNames, lodashStable.constant(['a']));
6574 object[Symbol.isConcatSpreadable] = true;
6576 var actual = lodashStable.map(methodNames, function(methodName) {
6577 return _[methodName](array);
6580 assert.deepEqual(actual, expected);
6587 QUnit.test('should work with extremely large arrays', function(assert) {
6590 lodashStable.times(3, function(index) {
6591 var expected = Array(5e5);
6593 var func = _.flatten;
6595 func = _.flattenDeep;
6596 } else if (index == 2) {
6597 func = _.flattenDepth;
6599 assert.deepEqual(func([expected]), expected);
6601 assert.ok(false, e.message);
6606 QUnit.test('should work with empty arrays', function(assert) {
6609 var array = [[], [[]], [[], [[[]]]]];
6611 assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
6612 assert.deepEqual(_.flattenDeep(array), []);
6613 assert.deepEqual(_.flattenDepth(array, 2), [[[]]]);
6616 QUnit.test('should support flattening of nested arrays', function(assert) {
6619 assert.deepEqual(_.flatten(array), [1, 2, [3, [4]], 5]);
6620 assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
6621 assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, [4], 5]);
6624 QUnit.test('should return an empty array for non array-like objects', function(assert) {
6628 nonArray = { '0': 'a' };
6630 assert.deepEqual(_.flatten(nonArray), expected);
6631 assert.deepEqual(_.flattenDeep(nonArray), expected);
6632 assert.deepEqual(_.flattenDepth(nonArray, 2), expected);
6635 QUnit.test('should return a wrapped value when chaining', function(assert) {
6639 var wrapped = _(array),
6640 actual = wrapped.flatten();
6642 assert.ok(actual instanceof _);
6643 assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);
6645 actual = wrapped.flattenDeep();
6647 assert.ok(actual instanceof _);
6648 assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);
6650 actual = wrapped.flattenDepth(2);
6652 assert.ok(actual instanceof _);
6653 assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);
6656 skipAssert(assert, 6);
6661 /*--------------------------------------------------------------------------*/
6663 QUnit.module('flow methods');
6665 lodashStable.each(['flow', 'flowRight'], function(methodName) {
6666 var func = _[methodName],
6667 isFlow = methodName == 'flow';
6669 QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
6672 var fixed = function(n) { return n.toFixed(1); },
6673 combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
6675 assert.strictEqual(combined(1, 2), '9.0');
6678 QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
6681 assert.notStrictEqual(func(noop), noop);
6684 QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are given', function(assert) {
6687 _.times(2, function(index) {
6689 var combined = index ? func([]) : func();
6690 assert.strictEqual(combined('a'), 'a');
6692 assert.ok(false, e.message);
6694 assert.strictEqual(combined.length, 0);
6695 assert.notStrictEqual(combined, identity);
6699 QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
6702 var curried = _.curry(identity);
6704 var combined = isFlow
6705 ? func(_.head, curried)
6706 : func(curried, _.head);
6708 assert.strictEqual(combined([1]), 1);
6711 QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
6716 array = lodashStable.range(LARGE_ARRAY_SIZE),
6717 iteratee = function(value) { mapCount++; return square(value); },
6718 predicate = function(value) { filterCount++; return isEven(value); };
6720 lodashStable.times(2, function(index) {
6721 var filter1 = _.filter,
6722 filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
6723 filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
6726 map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
6727 map3 = (_.map = index ? map2 : map1, map2(iteratee));
6730 take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
6731 take3 = (_.take = index ? take2 : take1, take2(2));
6733 var combined = isFlow
6734 ? func(map3, filter3, _.compact, take3)
6735 : func(take3, _.compact, filter3, map3);
6737 filterCount = mapCount = 0;
6738 assert.deepEqual(combined(array), [4, 16]);
6740 if (!isNpm && WeakMap && WeakMap.name) {
6741 assert.strictEqual(filterCount, 5, 'filterCount');
6742 assert.strictEqual(mapCount, 5, 'mapCount');
6745 skipAssert(assert, 2);
6753 QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
6756 var curried = _.curry(_.ary(_.map, 2), 2),
6757 getProp = curried(curried.placeholder, 'a'),
6758 objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
6760 var combined = isFlow
6761 ? func(getProp, _.uniq)
6762 : func(_.uniq, getProp);
6764 assert.deepEqual(combined(objects), [1, 2]);
6767 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
6771 var wrapped = _(noop)[methodName]();
6772 assert.ok(wrapped instanceof _);
6780 /*--------------------------------------------------------------------------*/
6782 QUnit.module('lodash.forEach');
6785 QUnit.test('should be aliased', function(assert) {
6788 assert.strictEqual(_.each, _.forEach);
6792 /*--------------------------------------------------------------------------*/
6794 QUnit.module('lodash.forEachRight');
6797 QUnit.test('should be aliased', function(assert) {
6800 assert.strictEqual(_.eachRight, _.forEachRight);
6804 /*--------------------------------------------------------------------------*/
6806 QUnit.module('forIn methods');
6808 lodashStable.each(['forIn', 'forInRight'], function(methodName) {
6809 var func = _[methodName];
6811 QUnit.test('`_.' + methodName + '` iterates over inherited string keyed properties', function(assert) {
6817 Foo.prototype.b = 2;
6820 func(new Foo, function(value, key) { keys.push(key); });
6821 assert.deepEqual(keys.sort(), ['a', 'b']);
6825 /*--------------------------------------------------------------------------*/
6827 QUnit.module('forOwn methods');
6829 lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
6830 var func = _[methodName];
6832 QUnit.test('`_.' + methodName + '` should iterate over `length` properties', function(assert) {
6835 var object = { '0': 'zero', '1': 'one', 'length': 2 },
6838 func(object, function(value, prop) { props.push(prop); });
6839 assert.deepEqual(props.sort(), ['0', '1', 'length']);
6843 /*--------------------------------------------------------------------------*/
6845 QUnit.module('iteration methods');
6879 var arrayMethods = [
6886 var collectionMethods = [
6905 var forInMethods = [
6912 var iterationMethods = [
6922 var objectMethods = [
6935 var rightMethods = [
6944 var unwrappedMethods = [
6967 lodashStable.each(methods, function(methodName) {
6968 var array = [1, 2, 3],
6969 func = _[methodName],
6970 isBy = /(^partition|By)$/.test(methodName),
6971 isFind = /^find/.test(methodName),
6972 isOmitPick = /^(?:omit|pick)By$/.test(methodName),
6973 isSome = methodName == 'some';
6975 QUnit.test('`_.' + methodName + '` should provide correct iteratee arguments', function(assert) {
6980 expected = [1, 0, array];
6982 func(array, function() {
6983 args || (args = slice.call(arguments));
6986 if (lodashStable.includes(rightMethods, methodName)) {
6990 if (lodashStable.includes(objectMethods, methodName)) {
6994 expected.length = isOmitPick ? 2 : 1;
6996 assert.deepEqual(args, expected);
7003 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
7010 var expected = lodashStable.includes(objectMethods, methodName)
7011 ? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
7012 : [[1, 0, array], [undefined, 1, array], [3, 2, array]];
7015 expected = lodashStable.map(expected, function(args) {
7016 return args.slice(0, isOmitPick ? 2 : 1);
7019 else if (lodashStable.includes(objectMethods, methodName)) {
7020 expected = lodashStable.map(expected, function(args) {
7025 if (lodashStable.includes(rightMethods, methodName)) {
7029 func(array, function() {
7030 argsList.push(slice.call(arguments));
7031 return !(isFind || isSome);
7034 assert.deepEqual(argsList, expected);
7042 lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
7043 var array = [1, 2, 3],
7044 func = _[methodName],
7045 isEvery = methodName == 'every';
7049 QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
7054 func(array, function(value, key) {
7059 assert.notOk(lodashStable.includes(keys, 'a'));
7067 lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
7068 var array = [1, 2, 3],
7069 isBaseEach = methodName == '_baseEach';
7071 QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
7074 if (!(isBaseEach || isNpm)) {
7075 var wrapped = _(array)[methodName](noop);
7076 assert.ok(wrapped instanceof _);
7084 lodashStable.each(unwrappedMethods, function(methodName) {
7085 var array = [1, 2, 3];
7087 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
7091 var actual = _(array)[methodName](noop);
7092 assert.notOk(actual instanceof _);
7099 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
7103 var wrapped = _(array).chain(),
7104 actual = wrapped[methodName](noop);
7106 assert.ok(actual instanceof _);
7107 assert.notStrictEqual(actual, wrapped);
7110 skipAssert(assert, 2);
7115 lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
7116 var func = _[methodName];
7118 QUnit.test('`_.' + methodName + '` iterates over own string keyed properties of objects', function(assert) {
7124 Foo.prototype.b = 2;
7128 func(new Foo, function(value) { values.push(value); });
7129 assert.deepEqual(values, [1]);
7137 lodashStable.each(iterationMethods, function(methodName) {
7138 var array = [1, 2, 3],
7139 func = _[methodName];
7141 QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
7145 assert.strictEqual(func(array, Boolean), array);
7153 lodashStable.each(collectionMethods, function(methodName) {
7154 var func = _[methodName];
7156 QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
7160 var isIteratedAsObject = function(object) {
7162 func(object, function() { result = true; }, 0);
7166 var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
7167 expected = lodashStable.map(values, stubTrue);
7169 var actual = lodashStable.map(values, function(length) {
7170 return isIteratedAsObject({ 'length': length });
7173 var Foo = function(a) {};
7176 assert.deepEqual(actual, expected);
7177 assert.ok(isIteratedAsObject(Foo));
7178 assert.notOk(isIteratedAsObject({ 'length': 0 }));
7181 skipAssert(assert, 3);
7186 lodashStable.each(methods, function(methodName) {
7187 var func = _[methodName],
7188 isFind = /^find/.test(methodName),
7189 isSome = methodName == 'some',
7190 isReduce = /^reduce/.test(methodName);
7192 QUnit.test('`_.' + methodName + '` should ignore changes to `length`', function(assert) {
7199 func(array, function() {
7203 return !(isFind || isSome);
7204 }, isReduce ? array : null);
7206 assert.strictEqual(count, 1);
7214 lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
7215 var func = _[methodName],
7216 isFind = /^find/.test(methodName),
7217 isSome = methodName == 'some',
7218 isReduce = /^reduce/.test(methodName);
7220 QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
7225 object = { 'a': 1 };
7227 func(object, function() {
7231 return !(isFind || isSome);
7232 }, isReduce ? object : null);
7234 assert.strictEqual(count, 1);
7243 /*--------------------------------------------------------------------------*/
7245 QUnit.module('object assignments');
7247 lodashStable.each(['assign', 'assignIn', 'defaults', 'defaultsDeep', 'merge'], function(methodName) {
7248 var func = _[methodName],
7249 isAssign = methodName == 'assign',
7250 isDefaults = /^defaults/.test(methodName);
7252 QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
7255 var expected = lodashStable.map(primitives, function(value) {
7256 var object = Object(value);
7261 var actual = lodashStable.map(primitives, function(value) {
7262 return func(value, { 'a': 1 });
7265 assert.deepEqual(actual, expected);
7268 QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'string keyed source properties', function(assert) {
7274 Foo.prototype.b = 2;
7276 var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
7277 assert.deepEqual(func({}, new Foo), expected);
7280 QUnit.test('`_.' + methodName + '` should not skip a trailing function source', function(assert) {
7286 assert.deepEqual(func({}, { 'a': 1 }, fn), { 'a': 1, 'b': 2 });
7289 QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
7293 assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
7295 assert.ok(false, e.message);
7299 QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
7302 var source = { 'a': 1 },
7303 values = [null, undefined],
7304 expected = lodashStable.map(values, stubTrue);
7306 var actual = lodashStable.map(values, function(value) {
7307 var object = func(value, source);
7308 return object !== source && lodashStable.isEqual(object, source);
7311 assert.deepEqual(actual, expected);
7313 actual = lodashStable.map(values, function(value) {
7314 return lodashStable.isEqual(func(value), {});
7317 assert.deepEqual(actual, expected);
7320 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
7323 var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
7324 expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
7331 assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
7332 assert.deepEqual(lodashStable.reduce(fn, func, { 'a': 0 }), expected);
7335 QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
7339 var wrapped = _({ 'a': 1 }),
7340 actual = wrapped[methodName]({ 'b': 2 });
7342 assert.notStrictEqual(actual, wrapped);
7350 lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
7351 var func = _[methodName];
7353 QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
7357 Foo.prototype.a = 1;
7359 var actual = func(new Foo, { 'b': 2 });
7360 assert.notOk(_.has(actual, 'a'));
7364 lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'defaultsDeep', 'merge', 'mergeWith'], function(methodName) {
7365 var func = _[methodName];
7367 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
7370 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
7374 defineProperty(object, 'a', {
7375 'configurable': true,
7377 'get': lodashStable.constant(value),
7378 'set': function() { pass = false; }
7381 func(object, { 'a': value });
7387 lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
7388 var func = _[methodName],
7389 isMergeWith = methodName == 'mergeWith';
7391 QUnit.test('`_.' + methodName + '` should provide correct `customizer` arguments', function(assert) {
7395 object = { 'a': 1 },
7396 source = { 'a': 2 },
7397 expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
7399 func(object, source, function() {
7400 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7403 assert.deepEqual(args, expected, 'primitive values');
7406 objectValue = [1, 2],
7407 sourceValue = { 'b': 2 };
7409 object = { 'a': objectValue };
7410 source = { 'a': sourceValue };
7411 expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
7414 expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
7416 func(object, source, function() {
7417 argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7420 assert.deepEqual(argsList, expected, 'object values');
7423 object = { 'a': 1 };
7424 source = { 'b': 2 };
7425 expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
7427 func(object, source, function() {
7428 args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
7431 assert.deepEqual(args, expected, 'undefined properties');
7434 QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
7437 function callback() {}
7440 var actual = func({ 'a': 1 }, callback);
7441 assert.deepEqual(actual, { 'a': 1, 'b': 2 });
7443 actual = func({ 'a': 1 }, callback, { 'c': 3 });
7444 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
7448 /*--------------------------------------------------------------------------*/
7450 QUnit.module('exit early');
7452 lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
7453 var func = _[methodName];
7455 QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
7459 var array = [1, 2, 3],
7462 func(array, function(value, other) {
7463 values.push(lodashStable.isArray(value) ? other : value);
7467 assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
7474 QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
7478 var object = { 'a': 1, 'b': 2, 'c': 3 },
7481 func(object, function(value, other) {
7482 values.push(lodashStable.isArray(value) ? other : value);
7486 assert.strictEqual(values.length, 1);
7494 /*--------------------------------------------------------------------------*/
7496 QUnit.module('`__proto__` property bugs');
7499 QUnit.test('should work with the "__proto__" key in internal data objects', function(assert) {
7502 var stringLiteral = '__proto__',
7503 stringObject = Object(stringLiteral),
7504 expected = [stringLiteral, stringObject];
7506 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
7507 return isEven(count) ? stringLiteral : stringObject;
7510 assert.deepEqual(_.difference(largeArray, largeArray), []);
7511 assert.deepEqual(_.intersection(largeArray, largeArray), expected);
7512 assert.deepEqual(_.uniq(largeArray), expected);
7513 assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
7516 QUnit.test('should treat "__proto__" as a regular key in assignments', function(assert) {
7527 var source = create(null);
7528 source.__proto__ = [];
7530 var expected = lodashStable.map(methods, stubFalse);
7532 var actual = lodashStable.map(methods, function(methodName) {
7533 var result = _[methodName]({}, source);
7534 return result instanceof Array;
7537 assert.deepEqual(actual, expected);
7539 actual = _.groupBy([{ 'a': '__proto__' }], 'a');
7540 assert.notOk(actual instanceof Array);
7544 /*--------------------------------------------------------------------------*/
7546 QUnit.module('lodash.fromPairs');
7549 QUnit.test('should accept a two dimensional array', function(assert) {
7552 var array = [['a', 1], ['b', 2]],
7553 object = { 'a': 1, 'b': 2 },
7554 actual = _.fromPairs(array);
7556 assert.deepEqual(actual, object);
7559 QUnit.test('should accept a falsey `array`', function(assert) {
7562 var expected = lodashStable.map(falsey, stubObject);
7564 var actual = lodashStable.map(falsey, function(array, index) {
7566 return index ? _.fromPairs(array) : _.fromPairs();
7570 assert.deepEqual(actual, expected);
7573 QUnit.test('should not support deep paths', function(assert) {
7576 var actual = _.fromPairs([['a.b', 1]]);
7577 assert.deepEqual(actual, { 'a.b': 1 });
7580 QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
7583 var object = { 'a.b': 1 };
7584 assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
7587 QUnit.test('should work in a lazy sequence', function(assert) {
7591 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
7592 return ['key' + index, index];
7595 var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
7597 assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
7605 /*--------------------------------------------------------------------------*/
7607 QUnit.module('lodash.functions');
7610 QUnit.test('should return the function names of an object', function(assert) {
7613 var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': noop },
7614 actual = _.functions(object).sort();
7616 assert.deepEqual(actual, ['b', 'd']);
7619 QUnit.test('should not include inherited functions', function(assert) {
7626 Foo.prototype.c = noop;
7628 assert.deepEqual(_.functions(new Foo), ['a']);
7632 /*--------------------------------------------------------------------------*/
7634 QUnit.module('lodash.groupBy');
7637 var array = [6.1, 4.2, 6.3];
7639 QUnit.test('should transform keys by `iteratee`', function(assert) {
7642 var actual = _.groupBy(array, Math.floor);
7643 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7646 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
7649 var array = [6, 4, 6],
7650 values = [, null, undefined],
7651 expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
7653 var actual = lodashStable.map(values, function(value, index) {
7654 return index ? _.groupBy(array, value) : _.groupBy(array);
7657 assert.deepEqual(actual, expected);
7660 QUnit.test('should work with `_.property` shorthands', function(assert) {
7663 var actual = _.groupBy(['one', 'two', 'three'], 'length');
7664 assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
7667 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
7670 var actual = _.groupBy(array, function(n) {
7671 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
7674 assert.deepEqual(actual.constructor, [4.2]);
7675 assert.deepEqual(actual.hasOwnProperty, [6.1, 6.3]);
7678 QUnit.test('should work with a number for `iteratee`', function(assert) {
7687 assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
7688 assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
7691 QUnit.test('should work with an object for `collection`', function(assert) {
7694 var actual = _.groupBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
7695 assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
7698 QUnit.test('should work in a lazy sequence', function(assert) {
7702 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
7703 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
7704 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
7707 var iteratee = function(value) { value.push(value[0]); return value; },
7708 predicate = function(value) { return isEven(value[0]); },
7709 actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
7711 assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
7719 /*--------------------------------------------------------------------------*/
7721 QUnit.module('lodash.gt');
7724 QUnit.test('should return `true` if `value` > `other`', function(assert) {
7727 assert.strictEqual(_.gt(3, 1), true);
7728 assert.strictEqual(_.gt('def', 'abc'), true);
7731 QUnit.test('should return `false` if `value` is <= `other`', function(assert) {
7734 assert.strictEqual(_.gt(1, 3), false);
7735 assert.strictEqual(_.gt(3, 3), false);
7736 assert.strictEqual(_.gt('abc', 'def'), false);
7737 assert.strictEqual(_.gt('def', 'def'), false);
7741 /*--------------------------------------------------------------------------*/
7743 QUnit.module('lodash.gte');
7746 QUnit.test('should return `true` if `value` >= `other`', function(assert) {
7749 assert.strictEqual(_.gte(3, 1), true);
7750 assert.strictEqual(_.gte(3, 3), true);
7751 assert.strictEqual(_.gte('def', 'abc'), true);
7752 assert.strictEqual(_.gte('def', 'def'), true);
7755 QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
7758 assert.strictEqual(_.gte(1, 3), false);
7759 assert.strictEqual(_.gte('abc', 'def'), false);
7763 /*--------------------------------------------------------------------------*/
7765 QUnit.module('has methods');
7767 lodashStable.each(['has', 'hasIn'], function(methodName) {
7768 var func = _[methodName],
7769 isHas = methodName == 'has',
7770 sparseArgs = toArgs([1]),
7771 sparseArray = Array(1),
7772 sparseString = Object('a');
7774 delete sparseArgs[0];
7775 delete sparseString[0];
7777 QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
7780 var object = { 'a': 1 };
7782 lodashStable.each(['a', ['a']], function(path) {
7783 assert.strictEqual(func(object, path), true);
7787 QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of `object`', function(assert) {
7790 var object = { 'hasOwnProperty': null, 'a': 1 };
7791 assert.strictEqual(func(object, 'a'), true);
7794 QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
7797 var object = { 'a': { 'b': 2 } };
7799 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7800 assert.strictEqual(func(object, path), true);
7803 lodashStable.each(['a.a', ['a', 'a']], function(path) {
7804 assert.strictEqual(func(object, path), false);
7808 QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
7812 fn.toString = lodashStable.constant('fn');
7814 var object = { 'null': 1 , 'undefined': 2, 'fn': 3, '[object Object]': 4 },
7815 paths = [null, undefined, fn, {}],
7816 expected = lodashStable.map(paths, stubTrue);
7818 lodashStable.times(2, function(index) {
7819 var actual = lodashStable.map(paths, function(path) {
7820 return func(object, index ? [path] : path);
7823 assert.deepEqual(actual, expected);
7827 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
7830 assert.strictEqual(func(args, 1), true);
7833 QUnit.test('`_.' + methodName + '` should work with a non-string `path`', function(assert) {
7836 var array = [1, 2, 3];
7838 lodashStable.each([1, [1]], function(path) {
7839 assert.strictEqual(func(array, path), true);
7843 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
7846 var object = { '-0': 'a', '0': 'b' },
7847 props = [-0, Object(-0), 0, Object(0)],
7848 expected = lodashStable.map(props, stubTrue);
7850 var actual = lodashStable.map(props, function(key) {
7851 return func(object, key);
7854 assert.deepEqual(actual, expected);
7857 QUnit.test('`_.' + methodName + '` should work with a symbol `path`', function(assert) {
7863 Foo.prototype[symbol] = 1;
7865 var symbol2 = Symbol('b');
7866 defineProperty(Foo.prototype, symbol2, {
7867 'configurable': true,
7868 'enumerable': false,
7873 var object = isHas ? Foo.prototype : new Foo;
7874 assert.strictEqual(func(object, symbol), true);
7875 assert.strictEqual(func(object, symbol2), true);
7878 skipAssert(assert, 2);
7882 QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
7885 var object = { 'a.b': 1 };
7887 lodashStable.each(['a.b', ['a.b']], function(path) {
7888 assert.strictEqual(func(object, path), true);
7892 QUnit.test('`_.' + methodName + '` should return `true` for indexes of sparse values', function(assert) {
7895 var values = [sparseArgs, sparseArray, sparseString],
7896 expected = lodashStable.map(values, stubTrue);
7898 var actual = lodashStable.map(values, function(value) {
7899 return func(value, 0);
7902 assert.deepEqual(actual, expected);
7905 QUnit.test('`_.' + methodName + '` should return `true` for indexes of sparse values with deep paths', function(assert) {
7908 var values = [sparseArgs, sparseArray, sparseString],
7909 expected = lodashStable.map(values, lodashStable.constant([true, true]));
7911 var actual = lodashStable.map(values, function(value) {
7912 return lodashStable.map(['a[0]', ['a', '0']], function(path) {
7913 return func({ 'a': value }, path);
7917 assert.deepEqual(actual, expected);
7920 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7924 Foo.prototype.a = 1;
7926 lodashStable.each(['a', ['a']], function(path) {
7927 assert.strictEqual(func(new Foo, path), !isHas);
7931 QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
7935 Foo.prototype.a = { 'b': 1 };
7937 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7938 assert.strictEqual(func(new Foo, path), !isHas);
7942 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
7945 var values = [null, undefined],
7946 expected = lodashStable.map(values, stubFalse);
7948 lodashStable.each(['constructor', ['constructor']], function(path) {
7949 var actual = lodashStable.map(values, function(value) {
7950 return func(value, path);
7953 assert.deepEqual(actual, expected);
7957 QUnit.test('`_.' + methodName + '` should return `false` for deep paths when `object` is nullish', function(assert) {
7960 var values = [null, undefined],
7961 expected = lodashStable.map(values, stubFalse);
7963 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
7964 var actual = lodashStable.map(values, function(value) {
7965 return func(value, path);
7968 assert.deepEqual(actual, expected);
7972 QUnit.test('`_.' + methodName + '` should return `false` for nullish values of nested objects', function(assert) {
7975 var values = [, null, undefined],
7976 expected = lodashStable.map(values, stubFalse);
7978 lodashStable.each(['a.b', ['a', 'b']], function(path) {
7979 var actual = lodashStable.map(values, function(value, index) {
7980 var object = index ? { 'a': value } : {};
7981 return func(object, path);
7984 assert.deepEqual(actual, expected);
7988 QUnit.test('`_.' + methodName + '` should return `false` over sparse values of deep paths', function(assert) {
7991 var values = [sparseArgs, sparseArray, sparseString],
7992 expected = lodashStable.map(values, lodashStable.constant([false, false]));
7994 var actual = lodashStable.map(values, function(value) {
7995 return lodashStable.map(['a[0].b', ['a', '0', 'b']], function(path) {
7996 return func({ 'a': value }, path);
8000 assert.deepEqual(actual, expected);
8004 /*--------------------------------------------------------------------------*/
8006 QUnit.module('lodash.head');
8009 var array = [1, 2, 3, 4];
8011 QUnit.test('should return the first element', function(assert) {
8014 assert.strictEqual(_.head(array), 1);
8017 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
8021 assert.strictEqual(_.head([]), undefined);
8022 arrayProto.length = 0;
8025 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
8028 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
8029 actual = lodashStable.map(array, _.head);
8031 assert.deepEqual(actual, [1, 4, 7]);
8034 QUnit.test('should be aliased', function(assert) {
8037 assert.strictEqual(_.first, _.head);
8040 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8044 var wrapped = _(array);
8045 assert.strictEqual(wrapped.head(), 1);
8046 assert.strictEqual(wrapped.first(), 1);
8049 skipAssert(assert, 2);
8053 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8057 var wrapped = _(array).chain();
8058 assert.ok(wrapped.head() instanceof _);
8059 assert.ok(wrapped.first() instanceof _);
8062 skipAssert(assert, 2);
8066 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
8070 var wrapped = _(array).chain();
8071 assert.strictEqual(wrapped.head().__wrapped__, array);
8072 assert.strictEqual(wrapped.first().__wrapped__, array);
8075 skipAssert(assert, 2);
8079 QUnit.test('should work in a lazy sequence', function(assert) {
8083 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
8086 lodashStable.each(['head', 'first'], function(methodName) {
8087 lodashStable.times(2, function(index) {
8088 var array = index ? largeArray : smallArray,
8089 actual = _(array).filter(isEven)[methodName]();
8091 assert.strictEqual(actual, _[methodName](_.filter(array, isEven)));
8096 skipAssert(assert, 4);
8101 /*--------------------------------------------------------------------------*/
8103 QUnit.module('lodash.identity');
8106 QUnit.test('should return the first argument given', function(assert) {
8109 var object = { 'name': 'fred' };
8110 assert.strictEqual(_.identity(object), object);
8114 /*--------------------------------------------------------------------------*/
8116 QUnit.module('lodash.includes');
8120 'an `arguments` object': arguments,
8121 'an array': [1, 2, 3, 4],
8122 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
8125 function(collection, key) {
8126 QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
8129 assert.strictEqual(_.includes(collection, 3), true);
8132 QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
8135 assert.strictEqual(_.includes(collection, 5), false);
8138 QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
8141 assert.strictEqual(_.includes(collection, 2, 1.2), true);
8144 QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
8148 assert.strictEqual(_(collection).includes(3), true);
8155 QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
8159 assert.ok(_(collection).chain().includes(3) instanceof _);
8169 'object': Object('abc')
8171 function(collection, key) {
8172 QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
8175 assert.strictEqual(_.includes(collection, 'bc'), true);
8176 assert.strictEqual(_.includes(collection, 'd'), false);
8180 QUnit.test('should return `false` for empty collections', function(assert) {
8183 var expected = lodashStable.map(empties, stubFalse);
8185 var actual = lodashStable.map(empties, function(value) {
8187 return _.includes(value);
8191 assert.deepEqual(actual, expected);
8194 QUnit.test('should work with a string and a `fromIndex` >= `length`', function(assert) {
8197 var string = '1234',
8198 length = string.length,
8199 indexes = [4, 6, Math.pow(2, 32), Infinity];
8201 var expected = lodashStable.map(indexes, function(index) {
8202 return [false, false, index == length];
8205 var actual = lodashStable.map(indexes, function(fromIndex) {
8207 _.includes(string, 1, fromIndex),
8208 _.includes(string, undefined, fromIndex),
8209 _.includes(string, '', fromIndex)
8213 assert.deepEqual(actual, expected);
8216 QUnit.test('should match `NaN`', function(assert) {
8219 assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
8222 QUnit.test('should match `-0` as `0`', function(assert) {
8225 assert.strictEqual(_.includes([-0], 0), true);
8226 assert.strictEqual(_.includes([0], -0), true);
8229 QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
8232 var array = [2, 3, 1],
8235 assert.ok(lodashStable.every(values, lodashStable.partial(_.includes, array)));
8239 /*--------------------------------------------------------------------------*/
8241 QUnit.module('lodash.initial');
8244 var array = [1, 2, 3];
8246 QUnit.test('should accept a falsey `array`', function(assert) {
8249 var expected = lodashStable.map(falsey, stubArray);
8251 var actual = lodashStable.map(falsey, function(array, index) {
8253 return index ? _.initial(array) : _.initial();
8257 assert.deepEqual(actual, expected);
8260 QUnit.test('should exclude last element', function(assert) {
8263 assert.deepEqual(_.initial(array), [1, 2]);
8266 QUnit.test('should return an empty when querying empty arrays', function(assert) {
8269 assert.deepEqual(_.initial([]), []);
8272 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
8275 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
8276 actual = lodashStable.map(array, _.initial);
8278 assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
8281 QUnit.test('should work in a lazy sequence', function(assert) {
8285 var array = lodashStable.range(LARGE_ARRAY_SIZE),
8288 var actual = _(array).initial().filter(function(value) {
8294 assert.deepEqual(actual, []);
8295 assert.deepEqual(values, _.initial(array));
8299 actual = _(array).filter(function(value) {
8301 return isEven(value);
8306 assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
8307 assert.deepEqual(values, array);
8310 skipAssert(assert, 4);
8315 /*--------------------------------------------------------------------------*/
8317 QUnit.module('lodash.inRange');
8320 QUnit.test('should work with an `end`', function(assert) {
8323 assert.strictEqual(_.inRange(3, 5), true);
8324 assert.strictEqual(_.inRange(5, 5), false);
8325 assert.strictEqual(_.inRange(6, 5), false);
8328 QUnit.test('should work with a `start` and `end`', function(assert) {
8331 assert.strictEqual(_.inRange(1, 1, 5), true);
8332 assert.strictEqual(_.inRange(3, 1, 5), true);
8333 assert.strictEqual(_.inRange(0, 1, 5), false);
8334 assert.strictEqual(_.inRange(5, 1, 5), false);
8337 QUnit.test('should treat falsey `start` as `0`', function(assert) {
8340 lodashStable.each(falsey, function(value, index) {
8342 assert.strictEqual(_.inRange(0, value), false);
8343 assert.strictEqual(_.inRange(0, value, 1), true);
8345 assert.strictEqual(_.inRange(0), false);
8350 QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
8353 assert.strictEqual(_.inRange(2, 5, 1), true);
8354 assert.strictEqual(_.inRange(-3, -2, -6), true);
8357 QUnit.test('should work with a floating point `n` value', function(assert) {
8360 assert.strictEqual(_.inRange(0.5, 5), true);
8361 assert.strictEqual(_.inRange(1.2, 1, 5), true);
8362 assert.strictEqual(_.inRange(5.2, 5), false);
8363 assert.strictEqual(_.inRange(0.5, 1, 5), false);
8366 QUnit.test('should coerce arguments to finite numbers', function(assert) {
8371 _.inRange(0, '0', 1),
8372 _.inRange(0, 0, '1'),
8373 _.inRange(0, NaN, 1),
8374 _.inRange(-1, -1, NaN)
8377 assert.deepEqual(actual, lodashStable.map(actual, stubTrue));
8381 /*--------------------------------------------------------------------------*/
8383 QUnit.module('intersection methods');
8385 lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
8386 var func = _[methodName];
8388 QUnit.test('`_.' + methodName + '` should return the intersection of two arrays', function(assert) {
8391 var actual = func([2, 1], [2, 3]);
8392 assert.deepEqual(actual, [2]);
8395 QUnit.test('`_.' + methodName + '` should return the intersection of multiple arrays', function(assert) {
8398 var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
8399 assert.deepEqual(actual, [3]);
8402 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
8405 var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
8406 assert.deepEqual(actual, [1, 2]);
8409 QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
8412 var actual = func([1, 1, 3, 2, 2]);
8413 assert.deepEqual(actual, [1, 3, 2]);
8416 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
8419 var array = [0, 1, null, 3],
8422 assert.deepEqual(func(array, args), expected);
8423 assert.deepEqual(func(args, array), expected);
8426 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
8429 var values = [-0, 0],
8430 expected = lodashStable.map(values, lodashStable.constant(['0']));
8432 var actual = lodashStable.map(values, function(value) {
8433 return lodashStable.map(func(values, [value]), lodashStable.toString);
8436 assert.deepEqual(actual, expected);
8439 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
8442 var actual = func([1, NaN, 3], [NaN, 5, NaN]);
8443 assert.deepEqual(actual, [NaN]);
8446 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
8449 var values = [-0, 0],
8450 expected = lodashStable.map(values, lodashStable.constant(['0']));
8452 var actual = lodashStable.map(values, function(value) {
8453 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
8454 return lodashStable.map(func(values, largeArray), lodashStable.toString);
8457 assert.deepEqual(actual, expected);
8460 QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
8463 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
8464 assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
8467 QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
8471 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
8473 assert.deepEqual(func([object], largeArray), [object]);
8474 assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
8477 QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
8480 var array = [0, 1, null, 3];
8481 assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
8482 assert.deepEqual(func(null, array, null, [2, 3]), []);
8483 assert.deepEqual(func(array, null, args, null), []);
8486 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
8490 var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
8491 assert.ok(wrapped instanceof _);
8492 assert.deepEqual(wrapped.value(), [1, 2]);
8495 skipAssert(assert, 2);
8500 /*--------------------------------------------------------------------------*/
8502 QUnit.module('lodash.intersectionBy');
8505 QUnit.test('should accept an `iteratee`', function(assert) {
8508 var actual = _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8509 assert.deepEqual(actual, [2.1]);
8511 actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8512 assert.deepEqual(actual, [{ 'x': 1 }]);
8515 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
8520 _.intersectionBy([2.1, 1.2], [2.3, 3.4], function() {
8521 args || (args = slice.call(arguments));
8524 assert.deepEqual(args, [2.3]);
8528 /*--------------------------------------------------------------------------*/
8530 QUnit.module('lodash.intersectionWith');
8533 QUnit.test('should work with a `comparator`', function(assert) {
8536 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
8537 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
8538 actual = _.intersectionWith(objects, others, lodashStable.isEqual);
8540 assert.deepEqual(actual, [objects[0]]);
8543 QUnit.test('should preserve the sign of `0`', function(assert) {
8547 largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubZero),
8548 others = [[0], largeArray],
8549 expected = lodashStable.map(others, lodashStable.constant(['-0']));
8551 var actual = lodashStable.map(others, function(other) {
8552 return lodashStable.map(_.intersectionWith(array, other, lodashStable.eq), lodashStable.toString);
8555 assert.deepEqual(actual, expected);
8559 /*--------------------------------------------------------------------------*/
8561 QUnit.module('lodash.invert');
8564 QUnit.test('should invert an object', function(assert) {
8567 var object = { 'a': 1, 'b': 2 },
8568 actual = _.invert(object);
8570 assert.deepEqual(actual, { '1': 'a', '2': 'b' });
8571 assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
8574 QUnit.test('should work with values that shadow keys on `Object.prototype`', function(assert) {
8577 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
8578 assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
8581 QUnit.test('should work with an object that has a `length` property', function(assert) {
8584 var object = { '0': 'a', '1': 'b', 'length': 2 };
8585 assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
8588 QUnit.test('should return a wrapped value when chaining', function(assert) {
8592 var object = { 'a': 1, 'b': 2 },
8593 wrapped = _(object).invert();
8595 assert.ok(wrapped instanceof _);
8596 assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
8599 skipAssert(assert, 2);
8604 /*--------------------------------------------------------------------------*/
8606 QUnit.module('lodash.invertBy');
8609 var object = { 'a': 1, 'b': 2, 'c': 1 };
8611 QUnit.test('should transform keys by `iteratee`', function(assert) {
8614 var expected = { 'group1': ['a', 'c'], 'group2': ['b'] };
8616 var actual = _.invertBy(object, function(value) {
8617 return 'group' + value;
8620 assert.deepEqual(actual, expected);
8623 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
8626 var values = [, null, undefined],
8627 expected = lodashStable.map(values, lodashStable.constant({ '1': ['a', 'c'], '2': ['b'] }));
8629 var actual = lodashStable.map(values, function(value, index) {
8630 return index ? _.invertBy(object, value) : _.invertBy(object);
8633 assert.deepEqual(actual, expected);
8636 QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
8639 var object = { 'a': 'hasOwnProperty', 'b': 'constructor' },
8640 expected = { 'hasOwnProperty': ['a'], 'constructor': ['b'] };
8642 assert.ok(lodashStable.isEqual(_.invertBy(object), expected));
8645 QUnit.test('should return a wrapped value when chaining', function(assert) {
8649 var wrapped = _(object).invertBy();
8651 assert.ok(wrapped instanceof _);
8652 assert.deepEqual(wrapped.value(), { '1': ['a', 'c'], '2': ['b'] });
8655 skipAssert(assert, 2);
8660 /*--------------------------------------------------------------------------*/
8662 QUnit.module('lodash.invoke');
8665 QUnit.test('should invoke a method on `object`', function(assert) {
8668 var object = { 'a': lodashStable.constant('A') },
8669 actual = _.invoke(object, 'a');
8671 assert.strictEqual(actual, 'A');
8674 QUnit.test('should support invoking with arguments', function(assert) {
8677 var object = { 'a': function(a, b) { return [a, b]; } },
8678 actual = _.invoke(object, 'a', 1, 2);
8680 assert.deepEqual(actual, [1, 2]);
8683 QUnit.test('should not error on nullish elements', function(assert) {
8686 var values = [null, undefined],
8687 expected = lodashStable.map(values, noop);
8689 var actual = lodashStable.map(values, function(value) {
8691 return _.invoke(value, 'a.b', 1, 2);
8695 assert.deepEqual(actual, expected);
8698 QUnit.test('should preserve the sign of `0`', function(assert) {
8701 var object = { '-0': stubA, '0': stubB },
8702 props = [-0, Object(-0), 0, Object(0)];
8704 var actual = lodashStable.map(props, function(key) {
8705 return _.invoke(object, key);
8708 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
8711 QUnit.test('should support deep paths', function(assert) {
8714 var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
8716 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8717 var actual = _.invoke(object, path, 1, 2);
8718 assert.deepEqual(actual, [1, 2]);
8722 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8725 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8727 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8728 assert.deepEqual(_.invoke(object, path), 1);
8732 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
8736 var object = { 'a': stubOne };
8737 assert.strictEqual(_(object).invoke('a'), 1);
8744 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
8748 var object = { 'a': stubOne };
8749 assert.ok(_(object).chain().invoke('a') instanceof _);
8757 /*--------------------------------------------------------------------------*/
8759 QUnit.module('lodash.invokeMap');
8762 QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
8765 var array = ['a', 'b', 'c'],
8766 actual = _.invokeMap(array, 'toUpperCase');
8768 assert.deepEqual(actual, ['A', 'B', 'C']);
8771 QUnit.test('should support invoking with arguments', function(assert) {
8774 var array = [function() { return slice.call(arguments); }],
8775 actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
8777 assert.deepEqual(actual, [['a', 'b', 'c']]);
8780 QUnit.test('should work with a function for `methodName`', function(assert) {
8783 var array = ['a', 'b', 'c'];
8785 var actual = _.invokeMap(array, function(left, right) {
8786 return left + this.toUpperCase() + right;
8789 assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
8792 QUnit.test('should work with an object for `collection`', function(assert) {
8795 var object = { 'a': 1, 'b': 2, 'c': 3 },
8796 actual = _.invokeMap(object, 'toFixed', 1);
8798 assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
8801 QUnit.test('should treat number values for `collection` as empty', function(assert) {
8804 assert.deepEqual(_.invokeMap(1), []);
8807 QUnit.test('should not error on nullish elements', function(assert) {
8810 var array = ['a', null, undefined, 'd'];
8813 var actual = _.invokeMap(array, 'toUpperCase');
8816 assert.deepEqual(actual, ['A', undefined, undefined, 'D']);
8819 QUnit.test('should not error on elements with missing properties', function(assert) {
8822 var objects = lodashStable.map([null, undefined, stubOne], function(value) {
8823 return { 'a': value };
8826 var expected = lodashStable.map(objects, function(object) {
8827 return object.a ? object.a() : undefined;
8831 var actual = _.invokeMap(objects, 'a');
8834 assert.deepEqual(actual, expected);
8837 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
8840 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
8842 lodashStable.each(['a.b', ['a', 'b']], function(path) {
8843 assert.deepEqual(_.invokeMap([object], path), [1]);
8847 QUnit.test('should return a wrapped value when chaining', function(assert) {
8851 var array = ['a', 'b', 'c'],
8853 actual = wrapped.invokeMap('toUpperCase');
8855 assert.ok(actual instanceof _);
8856 assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
8858 actual = wrapped.invokeMap(function(left, right) {
8859 return left + this.toUpperCase() + right;
8862 assert.ok(actual instanceof _);
8863 assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
8866 skipAssert(assert, 4);
8870 QUnit.test('should support shortcut fusion', function(assert) {
8875 method = function() { count++; return this.index; };
8877 var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
8878 return { 'index': index, 'method': method };
8881 var actual = _(array).invokeMap('method').take(1).value();
8883 assert.strictEqual(count, 1);
8884 assert.deepEqual(actual, [0]);
8887 skipAssert(assert, 2);
8892 /*--------------------------------------------------------------------------*/
8894 QUnit.module('lodash.isArguments');
8897 QUnit.test('should return `true` for `arguments` objects', function(assert) {
8900 assert.strictEqual(_.isArguments(args), true);
8901 assert.strictEqual(_.isArguments(strictArgs), true);
8904 QUnit.test('should return `false` for non `arguments` objects', function(assert) {
8907 var expected = lodashStable.map(falsey, stubFalse);
8909 var actual = lodashStable.map(falsey, function(value, index) {
8910 return index ? _.isArguments(value) : _.isArguments();
8913 assert.deepEqual(actual, expected);
8915 assert.strictEqual(_.isArguments([1, 2, 3]), false);
8916 assert.strictEqual(_.isArguments(true), false);
8917 assert.strictEqual(_.isArguments(new Date), false);
8918 assert.strictEqual(_.isArguments(new Error), false);
8919 assert.strictEqual(_.isArguments(_), false);
8920 assert.strictEqual(_.isArguments(slice), false);
8921 assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
8922 assert.strictEqual(_.isArguments(1), false);
8923 assert.strictEqual(_.isArguments(/x/), false);
8924 assert.strictEqual(_.isArguments('a'), false);
8925 assert.strictEqual(_.isArguments(symbol), false);
8928 QUnit.test('should work with an `arguments` object from another realm', function(assert) {
8931 if (realm.arguments) {
8932 assert.strictEqual(_.isArguments(realm.arguments), true);
8940 /*--------------------------------------------------------------------------*/
8942 QUnit.module('lodash.isArray');
8945 QUnit.test('should return `true` for arrays', function(assert) {
8948 assert.strictEqual(_.isArray([1, 2, 3]), true);
8951 QUnit.test('should return `false` for non-arrays', function(assert) {
8954 var expected = lodashStable.map(falsey, stubFalse);
8956 var actual = lodashStable.map(falsey, function(value, index) {
8957 return index ? _.isArray(value) : _.isArray();
8960 assert.deepEqual(actual, expected);
8962 assert.strictEqual(_.isArray(args), false);
8963 assert.strictEqual(_.isArray(true), false);
8964 assert.strictEqual(_.isArray(new Date), false);
8965 assert.strictEqual(_.isArray(new Error), false);
8966 assert.strictEqual(_.isArray(_), false);
8967 assert.strictEqual(_.isArray(slice), false);
8968 assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
8969 assert.strictEqual(_.isArray(1), false);
8970 assert.strictEqual(_.isArray(/x/), false);
8971 assert.strictEqual(_.isArray('a'), false);
8972 assert.strictEqual(_.isArray(symbol), false);
8975 QUnit.test('should work with an array from another realm', function(assert) {
8979 assert.strictEqual(_.isArray(realm.array), true);
8987 /*--------------------------------------------------------------------------*/
8989 QUnit.module('lodash.isArrayBuffer');
8992 QUnit.test('should return `true` for array buffers', function(assert) {
8996 assert.strictEqual(_.isArrayBuffer(arrayBuffer), true);
9003 QUnit.test('should return `false` for non array buffers', function(assert) {
9006 var expected = lodashStable.map(falsey, stubFalse);
9008 var actual = lodashStable.map(falsey, function(value, index) {
9009 return index ? _.isArrayBuffer(value) : _.isArrayBuffer();
9012 assert.deepEqual(actual, expected);
9014 assert.strictEqual(_.isArrayBuffer(args), false);
9015 assert.strictEqual(_.isArrayBuffer([1]), false);
9016 assert.strictEqual(_.isArrayBuffer(true), false);
9017 assert.strictEqual(_.isArrayBuffer(new Date), false);
9018 assert.strictEqual(_.isArrayBuffer(new Error), false);
9019 assert.strictEqual(_.isArrayBuffer(_), false);
9020 assert.strictEqual(_.isArrayBuffer(slice), false);
9021 assert.strictEqual(_.isArrayBuffer({ 'a': 1 }), false);
9022 assert.strictEqual(_.isArrayBuffer(1), false);
9023 assert.strictEqual(_.isArrayBuffer(/x/), false);
9024 assert.strictEqual(_.isArrayBuffer('a'), false);
9025 assert.strictEqual(_.isArrayBuffer(symbol), false);
9028 QUnit.test('should work with array buffers from another realm', function(assert) {
9031 if (realm.arrayBuffer) {
9032 assert.strictEqual(_.isArrayBuffer(realm.arrayBuffer), true);
9040 /*--------------------------------------------------------------------------*/
9042 QUnit.module('lodash.isArrayLike');
9045 QUnit.test('should return `true` for array-like values', function(assert) {
9048 var values = [args, [1, 2, 3], { '0': 'a', 'length': 1 }, 'a'],
9049 expected = lodashStable.map(values, stubTrue),
9050 actual = lodashStable.map(values, _.isArrayLike);
9052 assert.deepEqual(actual, expected);
9055 QUnit.test('should return `false` for non-arrays', function(assert) {
9058 var expected = lodashStable.map(falsey, function(value) {
9059 return value === '';
9062 var actual = lodashStable.map(falsey, function(value, index) {
9063 return index ? _.isArrayLike(value) : _.isArrayLike();
9066 assert.deepEqual(actual, expected);
9068 assert.strictEqual(_.isArrayLike(true), false);
9069 assert.strictEqual(_.isArrayLike(new Date), false);
9070 assert.strictEqual(_.isArrayLike(new Error), false);
9071 assert.strictEqual(_.isArrayLike(_), false);
9072 assert.strictEqual(_.isArrayLike(asyncFunc), false);
9073 assert.strictEqual(_.isArrayLike(genFunc), false);
9074 assert.strictEqual(_.isArrayLike(slice), false);
9075 assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
9076 assert.strictEqual(_.isArrayLike(1), false);
9077 assert.strictEqual(_.isArrayLike(/x/), false);
9078 assert.strictEqual(_.isArrayLike(symbol), false);
9081 QUnit.test('should work with an array from another realm', function(assert) {
9085 var values = [realm.arguments, realm.array, realm.string],
9086 expected = lodashStable.map(values, stubTrue),
9087 actual = lodashStable.map(values, _.isArrayLike);
9089 assert.deepEqual(actual, expected);
9097 /*--------------------------------------------------------------------------*/
9099 QUnit.module('lodash.isBoolean');
9102 QUnit.test('should return `true` for booleans', function(assert) {
9105 assert.strictEqual(_.isBoolean(true), true);
9106 assert.strictEqual(_.isBoolean(false), true);
9107 assert.strictEqual(_.isBoolean(Object(true)), true);
9108 assert.strictEqual(_.isBoolean(Object(false)), true);
9111 QUnit.test('should return `false` for non-booleans', function(assert) {
9114 var expected = lodashStable.map(falsey, function(value) {
9115 return value === false;
9118 var actual = lodashStable.map(falsey, function(value, index) {
9119 return index ? _.isBoolean(value) : _.isBoolean();
9122 assert.deepEqual(actual, expected);
9124 assert.strictEqual(_.isBoolean(args), false);
9125 assert.strictEqual(_.isBoolean([1, 2, 3]), false);
9126 assert.strictEqual(_.isBoolean(new Date), false);
9127 assert.strictEqual(_.isBoolean(new Error), false);
9128 assert.strictEqual(_.isBoolean(_), false);
9129 assert.strictEqual(_.isBoolean(slice), false);
9130 assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
9131 assert.strictEqual(_.isBoolean(1), false);
9132 assert.strictEqual(_.isBoolean(/x/), false);
9133 assert.strictEqual(_.isBoolean('a'), false);
9134 assert.strictEqual(_.isBoolean(symbol), false);
9137 QUnit.test('should work with a boolean from another realm', function(assert) {
9140 if (realm.boolean) {
9141 assert.strictEqual(_.isBoolean(realm.boolean), true);
9149 /*--------------------------------------------------------------------------*/
9151 QUnit.module('lodash.isBuffer');
9154 QUnit.test('should return `true` for buffers', function(assert) {
9158 assert.strictEqual(_.isBuffer(new Buffer(2)), true);
9165 QUnit.test('should return `false` for non-buffers', function(assert) {
9168 var expected = lodashStable.map(falsey, stubFalse);
9170 var actual = lodashStable.map(falsey, function(value, index) {
9171 return index ? _.isBuffer(value) : _.isBuffer();
9174 assert.deepEqual(actual, expected);
9176 assert.strictEqual(_.isBuffer(args), false);
9177 assert.strictEqual(_.isBuffer([1]), false);
9178 assert.strictEqual(_.isBuffer(true), false);
9179 assert.strictEqual(_.isBuffer(new Date), false);
9180 assert.strictEqual(_.isBuffer(new Error), false);
9181 assert.strictEqual(_.isBuffer(_), false);
9182 assert.strictEqual(_.isBuffer(slice), false);
9183 assert.strictEqual(_.isBuffer({ 'a': 1 }), false);
9184 assert.strictEqual(_.isBuffer(1), false);
9185 assert.strictEqual(_.isBuffer(/x/), false);
9186 assert.strictEqual(_.isBuffer('a'), false);
9187 assert.strictEqual(_.isBuffer(symbol), false);
9190 QUnit.test('should return `false` if `Buffer` is not defined', function(assert) {
9193 if (!isStrict && Buffer && lodashBizarro) {
9194 assert.strictEqual(lodashBizarro.isBuffer(new Buffer(2)), false);
9202 /*--------------------------------------------------------------------------*/
9204 QUnit.module('lodash.isDate');
9207 QUnit.test('should return `true` for dates', function(assert) {
9210 assert.strictEqual(_.isDate(new Date), true);
9213 QUnit.test('should return `false` for non-dates', function(assert) {
9216 var expected = lodashStable.map(falsey, stubFalse);
9218 var actual = lodashStable.map(falsey, function(value, index) {
9219 return index ? _.isDate(value) : _.isDate();
9222 assert.deepEqual(actual, expected);
9224 assert.strictEqual(_.isDate(args), false);
9225 assert.strictEqual(_.isDate([1, 2, 3]), false);
9226 assert.strictEqual(_.isDate(true), false);
9227 assert.strictEqual(_.isDate(new Error), false);
9228 assert.strictEqual(_.isDate(_), false);
9229 assert.strictEqual(_.isDate(slice), false);
9230 assert.strictEqual(_.isDate({ 'a': 1 }), false);
9231 assert.strictEqual(_.isDate(1), false);
9232 assert.strictEqual(_.isDate(/x/), false);
9233 assert.strictEqual(_.isDate('a'), false);
9234 assert.strictEqual(_.isDate(symbol), false);
9237 QUnit.test('should work with a date object from another realm', function(assert) {
9241 assert.strictEqual(_.isDate(realm.date), true);
9249 /*--------------------------------------------------------------------------*/
9251 QUnit.module('lodash.isElement');
9254 QUnit.test('should return `true` for elements', function(assert) {
9258 assert.strictEqual(_.isElement(body), true);
9265 QUnit.test('should return `true` for non-plain objects', function(assert) {
9272 assert.strictEqual(_.isElement(new Foo), true);
9275 QUnit.test('should return `false` for non DOM elements', function(assert) {
9278 var expected = lodashStable.map(falsey, stubFalse);
9280 var actual = lodashStable.map(falsey, function(value, index) {
9281 return index ? _.isElement(value) : _.isElement();
9284 assert.deepEqual(actual, expected);
9286 assert.strictEqual(_.isElement(args), false);
9287 assert.strictEqual(_.isElement([1, 2, 3]), false);
9288 assert.strictEqual(_.isElement(true), false);
9289 assert.strictEqual(_.isElement(new Date), false);
9290 assert.strictEqual(_.isElement(new Error), false);
9291 assert.strictEqual(_.isElement(_), false);
9292 assert.strictEqual(_.isElement(slice), false);
9293 assert.strictEqual(_.isElement({ 'a': 1 }), false);
9294 assert.strictEqual(_.isElement(1), false);
9295 assert.strictEqual(_.isElement(/x/), false);
9296 assert.strictEqual(_.isElement('a'), false);
9297 assert.strictEqual(_.isElement(symbol), false);
9300 QUnit.test('should return `false` for plain objects', function(assert) {
9303 assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
9304 assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
9305 assert.strictEqual(_.isElement({ 'nodeType': true }), false);
9306 assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
9307 assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
9308 assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
9311 QUnit.test('should work with a DOM element from another realm', function(assert) {
9314 if (realm.element) {
9315 assert.strictEqual(_.isElement(realm.element), true);
9323 /*--------------------------------------------------------------------------*/
9325 QUnit.module('lodash.isEmpty');
9328 QUnit.test('should return `true` for empty values', function(assert) {
9331 var expected = lodashStable.map(empties, stubTrue),
9332 actual = lodashStable.map(empties, _.isEmpty);
9334 assert.deepEqual(actual, expected);
9336 assert.strictEqual(_.isEmpty(true), true);
9337 assert.strictEqual(_.isEmpty(slice), true);
9338 assert.strictEqual(_.isEmpty(1), true);
9339 assert.strictEqual(_.isEmpty(NaN), true);
9340 assert.strictEqual(_.isEmpty(/x/), true);
9341 assert.strictEqual(_.isEmpty(symbol), true);
9342 assert.strictEqual(_.isEmpty(), true);
9345 assert.strictEqual(_.isEmpty(new Buffer(0)), true);
9346 assert.strictEqual(_.isEmpty(new Buffer(1)), false);
9349 skipAssert(assert, 2);
9353 QUnit.test('should return `false` for non-empty values', function(assert) {
9356 assert.strictEqual(_.isEmpty([0]), false);
9357 assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
9358 assert.strictEqual(_.isEmpty('a'), false);
9361 QUnit.test('should work with an object that has a `length` property', function(assert) {
9364 assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
9367 QUnit.test('should work with `arguments` objects', function(assert) {
9370 assert.strictEqual(_.isEmpty(args), false);
9373 QUnit.test('should work with prototytpe objects', function(assert) {
9377 Foo.prototype = { 'constructor': Foo };
9379 assert.strictEqual(_.isEmpty(Foo.prototype), true);
9381 Foo.prototype.a = 1;
9382 assert.strictEqual(_.isEmpty(Foo.prototype), false);
9385 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
9388 function Foo(elements) {
9389 push.apply(this, elements);
9391 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
9393 assert.strictEqual(_.isEmpty(new Foo([])), true);
9396 QUnit.test('should work with maps', function(assert) {
9400 lodashStable.each([new Map, realm.map], function(map) {
9401 assert.strictEqual(_.isEmpty(map), true);
9403 assert.strictEqual(_.isEmpty(map), false);
9408 skipAssert(assert, 4);
9412 QUnit.test('should work with sets', function(assert) {
9416 lodashStable.each([new Set, realm.set], function(set) {
9417 assert.strictEqual(_.isEmpty(set), true);
9419 assert.strictEqual(_.isEmpty(set), false);
9424 skipAssert(assert, 4);
9428 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
9432 Foo.prototype.length = -1;
9434 assert.strictEqual(_.isEmpty(new Foo), true);
9437 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
9441 Foo.prototype.length = MAX_SAFE_INTEGER + 1;
9443 assert.strictEqual(_.isEmpty(new Foo), true);
9446 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
9449 assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
9452 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
9456 assert.strictEqual(_({}).isEmpty(), true);
9463 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
9467 assert.ok(_({}).chain().isEmpty() instanceof _);
9475 /*--------------------------------------------------------------------------*/
9477 QUnit.module('lodash.isEqual');
9480 var symbol1 = Symbol ? Symbol('a') : true,
9481 symbol2 = Symbol ? Symbol('b') : false;
9483 QUnit.test('should compare primitives', function(assert) {
9487 [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
9488 [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
9489 [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
9490 ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
9491 [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
9492 [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
9493 [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
9494 [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
9495 [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
9498 var expected = lodashStable.map(pairs, function(pair) {
9502 var actual = lodashStable.map(pairs, function(pair) {
9503 return _.isEqual(pair[0], pair[1]);
9506 assert.deepEqual(actual, expected);
9509 QUnit.test('should compare arrays', function(assert) {
9512 var array1 = [true, null, 1, 'a', undefined],
9513 array2 = [true, null, 1, 'a', undefined];
9515 assert.strictEqual(_.isEqual(array1, array2), true);
9517 array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9518 array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
9520 assert.strictEqual(_.isEqual(array1, array2), true);
9526 array2[1] = undefined;
9529 assert.strictEqual(_.isEqual(array1, array2), true);
9531 array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
9532 array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
9534 assert.strictEqual(_.isEqual(array1, array2), true);
9539 assert.strictEqual(_.isEqual(array1, array2), false);
9544 assert.strictEqual(_.isEqual(array1, array2), false);
9547 QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
9550 var array1 = [1, 2, 3],
9553 array1.every = array1.filter = array1.forEach =
9554 array1.indexOf = array1.lastIndexOf = array1.map =
9555 array1.some = array1.reduce = array1.reduceRight = null;
9557 array2.concat = array2.join = array2.pop =
9558 array2.reverse = array2.shift = array2.slice =
9559 array2.sort = array2.splice = array2.unshift = null;
9561 assert.strictEqual(_.isEqual(array1, array2), true);
9569 assert.strictEqual(_.isEqual(array1, array2), true);
9571 array1 = /c/.exec('abcde');
9574 assert.strictEqual(_.isEqual(array1, array2), true);
9577 QUnit.test('should compare sparse arrays', function(assert) {
9580 var array = Array(1);
9582 assert.strictEqual(_.isEqual(array, Array(1)), true);
9583 assert.strictEqual(_.isEqual(array, [undefined]), true);
9584 assert.strictEqual(_.isEqual(array, Array(2)), false);
9587 QUnit.test('should compare plain objects', function(assert) {
9590 var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
9591 object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
9593 assert.strictEqual(_.isEqual(object1, object2), true);
9595 object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9596 object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
9598 assert.strictEqual(_.isEqual(object1, object2), true);
9600 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9601 object2 = { 'a': 3, 'b': 2, 'c': 1 };
9603 assert.strictEqual(_.isEqual(object1, object2), false);
9605 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9606 object2 = { 'd': 1, 'e': 2, 'f': 3 };
9608 assert.strictEqual(_.isEqual(object1, object2), false);
9610 object1 = { 'a': 1, 'b': 2 };
9611 object2 = { 'a': 1, 'b': 2, 'c': 3 };
9613 assert.strictEqual(_.isEqual(object1, object2), false);
9616 QUnit.test('should compare objects regardless of key order', function(assert) {
9619 var object1 = { 'a': 1, 'b': 2, 'c': 3 },
9620 object2 = { 'c': 3, 'a': 1, 'b': 2 };
9622 assert.strictEqual(_.isEqual(object1, object2), true);
9625 QUnit.test('should compare nested objects', function(assert) {
9634 'f': ['a', Object('b'), 'c'],
9636 'h': new Date(2012, 4, 23),
9643 'a': [1, Object(2), 3],
9648 'f': ['a', 'b', 'c'],
9650 'h': new Date(2012, 4, 23),
9656 assert.strictEqual(_.isEqual(object1, object2), true);
9659 QUnit.test('should compare object instances', function(assert) {
9665 Foo.prototype.a = 1;
9670 Bar.prototype.a = 2;
9672 assert.strictEqual(_.isEqual(new Foo, new Foo), true);
9673 assert.strictEqual(_.isEqual(new Foo, new Bar), false);
9674 assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
9675 assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
9678 QUnit.test('should compare objects with constructor properties', function(assert) {
9681 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
9682 assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
9683 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
9684 assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
9685 assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
9688 QUnit.test('should compare arrays with circular references', function(assert) {
9694 array1.push(array1);
9695 array2.push(array2);
9697 assert.strictEqual(_.isEqual(array1, array2), true);
9702 assert.strictEqual(_.isEqual(array1, array2), true);
9707 assert.strictEqual(_.isEqual(array1, array2), false);
9709 array1 = ['a', 'b', 'c'];
9711 array2 = ['a', ['a', 'b', 'c'], 'c'];
9713 assert.strictEqual(_.isEqual(array1, array2), false);
9716 QUnit.test('should have transitive equivalence for circular references of arrays', function(assert) {
9725 assert.strictEqual(_.isEqual(array1, array2), true);
9726 assert.strictEqual(_.isEqual(array2, array3), true);
9727 assert.strictEqual(_.isEqual(array1, array3), true);
9730 QUnit.test('should compare objects with circular references', function(assert) {
9736 object1.a = object1;
9737 object2.a = object2;
9739 assert.strictEqual(_.isEqual(object1, object2), true);
9742 object2.b = Object(0);
9744 assert.strictEqual(_.isEqual(object1, object2), true);
9746 object1.c = Object(1);
9747 object2.c = Object(2);
9749 assert.strictEqual(_.isEqual(object1, object2), false);
9751 object1 = { 'a': 1, 'b': 2, 'c': 3 };
9752 object1.b = object1;
9753 object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
9755 assert.strictEqual(_.isEqual(object1, object2), false);
9758 QUnit.test('should have transitive equivalence for circular references of objects', function(assert) {
9762 object2 = { 'a': object1 },
9763 object3 = { 'a': object2 };
9765 object1.a = object1;
9767 assert.strictEqual(_.isEqual(object1, object2), true);
9768 assert.strictEqual(_.isEqual(object2, object3), true);
9769 assert.strictEqual(_.isEqual(object1, object3), true);
9772 QUnit.test('should compare objects with multiple circular references', function(assert) {
9778 (array1[0].a = array1).push(array1);
9779 (array2[0].a = array2).push(array2);
9781 assert.strictEqual(_.isEqual(array1, array2), true);
9784 array2[0].b = Object(0);
9786 assert.strictEqual(_.isEqual(array1, array2), true);
9788 array1[0].c = Object(1);
9789 array2[0].c = Object(2);
9791 assert.strictEqual(_.isEqual(array1, array2), false);
9794 QUnit.test('should compare objects with complex circular references', function(assert) {
9798 'foo': { 'b': { 'c': { 'd': {} } } },
9803 'foo': { 'b': { 'c': { 'd': {} } } },
9807 object1.foo.b.c.d = object1;
9808 object1.bar.b = object1.foo.b;
9810 object2.foo.b.c.d = object2;
9811 object2.bar.b = object2.foo.b;
9813 assert.strictEqual(_.isEqual(object1, object2), true);
9816 QUnit.test('should compare objects with shared property values', function(assert) {
9828 object1.b = object1.a;
9830 assert.strictEqual(_.isEqual(object1, object2), true);
9833 QUnit.test('should treat objects created by `Object.create(null)` like plain objects', function(assert) {
9839 Foo.prototype.constructor = null;
9841 var object1 = create(null);
9844 var object2 = { 'a': 1 };
9846 assert.strictEqual(_.isEqual(object1, object2), true);
9847 assert.strictEqual(_.isEqual(new Foo, object2), false);
9850 QUnit.test('should avoid common type coercions', function(assert) {
9853 assert.strictEqual(_.isEqual(true, Object(false)), false);
9854 assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
9855 assert.strictEqual(_.isEqual(false, Object('')), false);
9856 assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
9857 assert.strictEqual(_.isEqual(0, ''), false);
9858 assert.strictEqual(_.isEqual(1, true), false);
9859 assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
9860 assert.strictEqual(_.isEqual('36', 36), false);
9861 assert.strictEqual(_.isEqual(36, '36'), false);
9864 QUnit.test('should compare `arguments` objects', function(assert) {
9867 var args1 = (function() { return arguments; }()),
9868 args2 = (function() { return arguments; }()),
9869 args3 = (function() { return arguments; }(1, 2));
9871 assert.strictEqual(_.isEqual(args1, args2), true);
9872 assert.strictEqual(_.isEqual(args1, args3), false);
9875 QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
9878 var object = { '0': 1, '1': 2, '2': 3 };
9881 Foo.prototype = object;
9883 assert.strictEqual(_.isEqual(args, object), true);
9884 assert.strictEqual(_.isEqual(object, args), true);
9885 assert.strictEqual(_.isEqual(args, new Foo), false);
9886 assert.strictEqual(_.isEqual(new Foo, args), false);
9889 QUnit.test('should compare array buffers', function(assert) {
9893 var buffer = new Int8Array([-1]).buffer;
9895 assert.strictEqual(_.isEqual(buffer, new Uint8Array([255]).buffer), true);
9896 assert.strictEqual(_.isEqual(buffer, new ArrayBuffer(1)), false);
9899 skipAssert(assert, 2);
9903 QUnit.test('should compare array views', function(assert) {
9906 lodashStable.times(2, function(index) {
9907 var ns = index ? realm : root;
9909 var pairs = lodashStable.map(arrayViews, function(type, viewIndex) {
9910 var otherType = arrayViews[(viewIndex + 1) % arrayViews.length],
9911 CtorA = ns[type] || function(n) { this.n = n; },
9912 CtorB = ns[otherType] || function(n) { this.n = n; },
9913 bufferA = ns[type] ? new ns.ArrayBuffer(8) : 8,
9914 bufferB = ns[otherType] ? new ns.ArrayBuffer(8) : 8,
9915 bufferC = ns[otherType] ? new ns.ArrayBuffer(16) : 16;
9917 return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
9920 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9922 var actual = lodashStable.map(pairs, function(pair) {
9923 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9926 assert.deepEqual(actual, expected);
9930 QUnit.test('should compare buffers', function(assert) {
9934 var buffer = new Buffer([1]);
9936 assert.strictEqual(_.isEqual(buffer, new Buffer([1])), true);
9937 assert.strictEqual(_.isEqual(buffer, new Buffer([2])), false);
9938 assert.strictEqual(_.isEqual(buffer, new Uint8Array([1])), false);
9941 skipAssert(assert, 3);
9945 QUnit.test('should compare date objects', function(assert) {
9948 var date = new Date(2012, 4, 23);
9950 assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
9951 assert.strictEqual(_.isEqual(new Date('a'), new Date('b')), true);
9952 assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false);
9953 assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false);
9956 QUnit.test('should compare error objects', function(assert) {
9959 var pairs = lodashStable.map([
9967 ], function(type, index, errorTypes) {
9968 var otherType = errorTypes[++index % errorTypes.length],
9970 CtorB = root[otherType];
9972 return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
9975 var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
9977 var actual = lodashStable.map(pairs, function(pair) {
9978 return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
9981 assert.deepEqual(actual, expected);
9984 QUnit.test('should compare functions', function(assert) {
9987 function a() { return 1 + 2; }
9988 function b() { return 1 + 2; }
9990 assert.strictEqual(_.isEqual(a, a), true);
9991 assert.strictEqual(_.isEqual(a, b), false);
9994 QUnit.test('should compare maps', function(assert) {
9998 lodashStable.each([[map, new Map], [map, realm.map]], function(maps) {
10004 assert.strictEqual(_.isEqual(map1, map2), false);
10008 assert.strictEqual(_.isEqual(map1, map2), true);
10012 assert.strictEqual(_.isEqual(map1, map2), true);
10015 assert.strictEqual(_.isEqual(map1, map2), false);
10022 skipAssert(assert, 8);
10026 QUnit.test('should compare maps with circular references', function(assert) {
10030 var map1 = new Map,
10033 map1.set('a', map1);
10034 map2.set('a', map2);
10035 assert.strictEqual(_.isEqual(map1, map2), true);
10039 assert.strictEqual(_.isEqual(map1, map2), false);
10042 skipAssert(assert, 2);
10046 QUnit.test('should compare promises by reference', function(assert) {
10050 lodashStable.each([[promise, Promise.resolve(1)], [promise, realm.promise]], function(promises) {
10051 var promise1 = promises[0],
10052 promise2 = promises[1];
10054 assert.strictEqual(_.isEqual(promise1, promise2), false);
10055 assert.strictEqual(_.isEqual(promise1, promise1), true);
10059 skipAssert(assert, 4);
10063 QUnit.test('should compare regexes', function(assert) {
10066 assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
10067 assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
10068 assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
10069 assert.strictEqual(_.isEqual(/x/, /y/), false);
10070 assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
10073 QUnit.test('should compare sets', function(assert) {
10077 lodashStable.each([[set, new Set], [set, realm.set]], function(sets) {
10078 var set1 = sets[0],
10083 assert.strictEqual(_.isEqual(set1, set2), false);
10087 assert.strictEqual(_.isEqual(set1, set2), true);
10091 assert.strictEqual(_.isEqual(set1, set2), true);
10094 assert.strictEqual(_.isEqual(set1, set2), false);
10101 skipAssert(assert, 8);
10105 QUnit.test('should compare sets with circular references', function(assert) {
10109 var set1 = new Set,
10114 assert.strictEqual(_.isEqual(set1, set2), true);
10118 assert.strictEqual(_.isEqual(set1, set2), false);
10121 skipAssert(assert, 2);
10125 QUnit.test('should compare symbol properties', function(assert) {
10129 var object1 = { 'a': 1 },
10130 object2 = { 'a': 1 };
10132 object1[symbol1] = { 'a': { 'b': 2 } };
10133 object2[symbol1] = { 'a': { 'b': 2 } };
10135 defineProperty(object2, symbol2, {
10136 'configurable': true,
10137 'enumerable': false,
10142 assert.strictEqual(_.isEqual(object1, object2), true);
10144 object2[symbol1] = { 'a': 1 };
10145 assert.strictEqual(_.isEqual(object1, object2), false);
10147 delete object2[symbol1];
10148 object2[Symbol('a')] = { 'a': { 'b': 2 } };
10149 assert.strictEqual(_.isEqual(object1, object2), false);
10152 skipAssert(assert, 3);
10156 QUnit.test('should compare wrapped values', function(assert) {
10159 var stamp = +new Date;
10162 [[1, 2], [1, 2], [1, 2, 3]],
10163 [true, true, false],
10164 [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
10165 [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
10167 [NaN, NaN, Infinity],
10172 lodashStable.each(values, function(vals) {
10174 var wrapped1 = _(vals[0]),
10175 wrapped2 = _(vals[1]),
10176 actual = wrapped1.isEqual(wrapped2);
10178 assert.strictEqual(actual, true);
10179 assert.strictEqual(_.isEqual(_(actual), _(true)), true);
10181 wrapped1 = _(vals[0]);
10182 wrapped2 = _(vals[2]);
10184 actual = wrapped1.isEqual(wrapped2);
10185 assert.strictEqual(actual, false);
10186 assert.strictEqual(_.isEqual(_(actual), _(false)), true);
10189 skipAssert(assert, 4);
10194 QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
10198 var object1 = _({ 'a': 1, 'b': 2 }),
10199 object2 = { 'a': 1, 'b': 2 };
10201 assert.strictEqual(object1.isEqual(object2), true);
10202 assert.strictEqual(_.isEqual(object1, object2), true);
10204 object1 = _({ 'a': 1, 'b': 2 });
10205 object2 = { 'a': 1, 'b': 1 };
10207 assert.strictEqual(object1.isEqual(object2), false);
10208 assert.strictEqual(_.isEqual(object1, object2), false);
10211 skipAssert(assert, 4);
10215 QUnit.test('should work as an iteratee for `_.every`', function(assert) {
10218 var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
10222 QUnit.test('should not error on DOM elements', function(assert) {
10226 var element1 = document.createElement('div'),
10227 element2 = element1.cloneNode(true);
10230 assert.strictEqual(_.isEqual(element1, element2), false);
10232 assert.ok(false, e.message);
10236 skipAssert(assert);
10240 QUnit.test('should return `true` for like-objects from different documents', function(assert) {
10243 if (realm.object) {
10244 assert.strictEqual(_.isEqual([1], realm.array), true);
10245 assert.strictEqual(_.isEqual([2], realm.array), false);
10246 assert.strictEqual(_.isEqual({ 'a': 1 }, realm.object), true);
10247 assert.strictEqual(_.isEqual({ 'a': 2 }, realm.object), false);
10250 skipAssert(assert, 4);
10254 QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
10258 object = { 'toString': function() { return primitive; } },
10259 values = [true, null, 1, 'a', undefined],
10260 expected = lodashStable.map(values, stubFalse);
10262 var actual = lodashStable.map(values, function(value) {
10264 return _.isEqual(object, value);
10267 assert.deepEqual(actual, expected);
10270 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
10274 assert.strictEqual(_('a').isEqual('a'), true);
10277 skipAssert(assert);
10281 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
10285 assert.ok(_('a').chain().isEqual('a') instanceof _);
10288 skipAssert(assert);
10293 /*--------------------------------------------------------------------------*/
10295 QUnit.module('lodash.isEqualWith');
10298 QUnit.test('should provide correct `customizer` arguments', function(assert) {
10302 object1 = { 'a': [1, 2], 'b': null },
10303 object2 = { 'a': [1, 2], 'b': null };
10305 object1.b = object2;
10306 object2.b = object1;
10309 [object1, object2],
10310 [object1.a, object2.a, 'a', object1, object2],
10311 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10312 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10313 [object1.b, object2.b, 'b', object1.b, object2.b]
10316 _.isEqualWith(object1, object2, function(assert) {
10317 var length = arguments.length,
10318 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
10320 argsList.push(args);
10323 assert.deepEqual(argsList, expected);
10326 QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
10329 assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
10330 assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
10331 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
10334 QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
10337 var customizer = function(value) {
10338 return _.isString(value) || undefined;
10341 assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
10342 assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
10343 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10346 QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
10349 var customizer = function(value) {
10350 return _.isString(value) ? false : undefined;
10353 assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
10354 assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
10355 assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10358 QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
10361 var actual = _.isEqualWith('a', 'b', stubC);
10362 assert.strictEqual(actual, true);
10364 var values = _.without(falsey, undefined),
10365 expected = lodashStable.map(values, stubFalse);
10368 lodashStable.each(values, function(value) {
10369 actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
10372 assert.deepEqual(actual, expected);
10375 QUnit.test('should ensure `customizer` is a function', function(assert) {
10378 var array = [1, 2, 3],
10379 eq = _.partial(_.isEqualWith, array),
10380 actual = lodashStable.map([array, [1, 0, 3]], eq);
10382 assert.deepEqual(actual, [true, false]);
10385 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
10388 var value = { 'a': { 'b': 2 } };
10391 var map1 = new Map;
10392 map1.set('a', value);
10394 var map2 = new Map;
10395 map2.set('a', value);
10398 var set1 = new Set;
10401 var set2 = new Set;
10404 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
10407 array = lodashStable.toArray(pair[0]);
10410 [pair[0], pair[1]],
10411 [array[0], array[0], 0, array, array],
10412 [array[0][0], array[0][0], 0, array[0], array[0]],
10413 [array[0][1], array[0][1], 1, array[0], array[0]]
10417 expected.length = 2;
10419 _.isEqualWith(pair[0], pair[1], function() {
10420 var length = arguments.length,
10421 args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
10423 argsList.push(args);
10426 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
10429 skipAssert(assert);
10435 /*--------------------------------------------------------------------------*/
10437 QUnit.module('lodash.isError');
10440 QUnit.test('should return `true` for error objects', function(assert) {
10443 var expected = lodashStable.map(errors, stubTrue);
10445 var actual = lodashStable.map(errors, function(error) {
10446 return _.isError(error) === true;
10449 assert.deepEqual(actual, expected);
10452 QUnit.test('should return `true` for subclassed values', function(assert) {
10455 assert.strictEqual(_.isError(new CustomError('x')), true);
10458 QUnit.test('should return `false` for non error objects', function(assert) {
10461 var expected = lodashStable.map(falsey, stubFalse);
10463 var actual = lodashStable.map(falsey, function(value, index) {
10464 return index ? _.isError(value) : _.isError();
10467 assert.deepEqual(actual, expected);
10469 assert.strictEqual(_.isError(args), false);
10470 assert.strictEqual(_.isError([1, 2, 3]), false);
10471 assert.strictEqual(_.isError(true), false);
10472 assert.strictEqual(_.isError(new Date), false);
10473 assert.strictEqual(_.isError(_), false);
10474 assert.strictEqual(_.isError(slice), false);
10475 assert.strictEqual(_.isError({ 'a': 1 }), false);
10476 assert.strictEqual(_.isError(1), false);
10477 assert.strictEqual(_.isError(/x/), false);
10478 assert.strictEqual(_.isError('a'), false);
10479 assert.strictEqual(_.isError(symbol), false);
10482 QUnit.test('should return `false` for plain objects', function(assert) {
10485 assert.strictEqual(_.isError({ 'name': 'Error', 'message': '' }), false);
10488 QUnit.test('should work with an error object from another realm', function(assert) {
10491 if (realm.errors) {
10492 var expected = lodashStable.map(realm.errors, stubTrue);
10494 var actual = lodashStable.map(realm.errors, function(error) {
10495 return _.isError(error) === true;
10498 assert.deepEqual(actual, expected);
10501 skipAssert(assert);
10506 /*--------------------------------------------------------------------------*/
10508 QUnit.module('lodash.isFinite');
10511 QUnit.test('should return `true` for finite values', function(assert) {
10514 var values = [0, 1, 3.14, -1],
10515 expected = lodashStable.map(values, stubTrue),
10516 actual = lodashStable.map(values, _.isFinite);
10518 assert.deepEqual(actual, expected);
10521 QUnit.test('should return `false` for non-finite values', function(assert) {
10524 var values = [NaN, Infinity, -Infinity, Object(1)],
10525 expected = lodashStable.map(values, stubFalse),
10526 actual = lodashStable.map(values, _.isFinite);
10528 assert.deepEqual(actual, expected);
10531 QUnit.test('should return `false` for non-numeric values', function(assert) {
10534 var values = [undefined, [], true, '', ' ', '2px'],
10535 expected = lodashStable.map(values, stubFalse),
10536 actual = lodashStable.map(values, _.isFinite);
10538 assert.deepEqual(actual, expected);
10540 assert.strictEqual(_.isFinite(args), false);
10541 assert.strictEqual(_.isFinite([1, 2, 3]), false);
10542 assert.strictEqual(_.isFinite(true), false);
10543 assert.strictEqual(_.isFinite(new Date), false);
10544 assert.strictEqual(_.isFinite(new Error), false);
10545 assert.strictEqual(_.isFinite({ 'a': 1 }), false);
10546 assert.strictEqual(_.isFinite(/x/), false);
10547 assert.strictEqual(_.isFinite('a'), false);
10548 assert.strictEqual(_.isFinite(symbol), false);
10551 QUnit.test('should return `false` for numeric string values', function(assert) {
10554 var values = ['2', '0', '08'],
10555 expected = lodashStable.map(values, stubFalse),
10556 actual = lodashStable.map(values, _.isFinite);
10558 assert.deepEqual(actual, expected);
10562 /*--------------------------------------------------------------------------*/
10564 QUnit.module('lodash.isFunction');
10567 QUnit.test('should return `true` for functions', function(assert) {
10570 assert.strictEqual(_.isFunction(_), true);
10571 assert.strictEqual(_.isFunction(slice), true);
10574 QUnit.test('should return `true` for async functions', function(assert) {
10577 assert.strictEqual(_.isFunction(asyncFunc), typeof asyncFunc == 'function');
10580 QUnit.test('should return `true` for generator functions', function(assert) {
10583 assert.strictEqual(_.isFunction(genFunc), typeof genFunc == 'function');
10586 QUnit.test('should return `true` for the `Proxy` constructor', function(assert) {
10590 assert.strictEqual(_.isFunction(Proxy), true);
10593 skipAssert(assert);
10597 QUnit.test('should return `true` for array view constructors', function(assert) {
10600 var expected = lodashStable.map(arrayViews, function(type) {
10601 return objToString.call(root[type]) == funcTag;
10604 var actual = lodashStable.map(arrayViews, function(type) {
10605 return _.isFunction(root[type]);
10608 assert.deepEqual(actual, expected);
10611 QUnit.test('should return `false` for non-functions', function(assert) {
10614 var expected = lodashStable.map(falsey, stubFalse);
10616 var actual = lodashStable.map(falsey, function(value, index) {
10617 return index ? _.isFunction(value) : _.isFunction();
10620 assert.deepEqual(actual, expected);
10622 assert.strictEqual(_.isFunction(args), false);
10623 assert.strictEqual(_.isFunction([1, 2, 3]), false);
10624 assert.strictEqual(_.isFunction(true), false);
10625 assert.strictEqual(_.isFunction(new Date), false);
10626 assert.strictEqual(_.isFunction(new Error), false);
10627 assert.strictEqual(_.isFunction({ 'a': 1 }), false);
10628 assert.strictEqual(_.isFunction(1), false);
10629 assert.strictEqual(_.isFunction(/x/), false);
10630 assert.strictEqual(_.isFunction('a'), false);
10631 assert.strictEqual(_.isFunction(symbol), false);
10634 assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
10637 skipAssert(assert);
10641 QUnit.test('should work with a function from another realm', function(assert) {
10644 if (realm.function) {
10645 assert.strictEqual(_.isFunction(realm.function), true);
10648 skipAssert(assert);
10653 /*--------------------------------------------------------------------------*/
10655 QUnit.module('isInteger methods');
10657 lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
10658 var func = _[methodName],
10659 isSafe = methodName == 'isSafeInteger';
10661 QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
10664 var values = [-1, 0, 1],
10665 expected = lodashStable.map(values, stubTrue);
10667 var actual = lodashStable.map(values, function(value) {
10668 return func(value);
10671 assert.deepEqual(actual, expected);
10672 assert.strictEqual(func(MAX_INTEGER), !isSafe);
10675 QUnit.test('should return `false` for non-integer number values', function(assert) {
10678 var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
10679 expected = lodashStable.map(values, stubFalse);
10681 var actual = lodashStable.map(values, function(value) {
10682 return func(value);
10685 assert.deepEqual(actual, expected);
10688 QUnit.test('should return `false` for non-numeric values', function(assert) {
10691 var expected = lodashStable.map(falsey, function(value) {
10692 return value === 0;
10695 var actual = lodashStable.map(falsey, function(value, index) {
10696 return index ? func(value) : func();
10699 assert.deepEqual(actual, expected);
10701 assert.strictEqual(func(args), false);
10702 assert.strictEqual(func([1, 2, 3]), false);
10703 assert.strictEqual(func(true), false);
10704 assert.strictEqual(func(new Date), false);
10705 assert.strictEqual(func(new Error), false);
10706 assert.strictEqual(func({ 'a': 1 }), false);
10707 assert.strictEqual(func(/x/), false);
10708 assert.strictEqual(func('a'), false);
10709 assert.strictEqual(func(symbol), false);
10713 /*--------------------------------------------------------------------------*/
10715 QUnit.module('lodash.isLength');
10718 QUnit.test('should return `true` for lengths', function(assert) {
10721 var values = [0, 3, MAX_SAFE_INTEGER],
10722 expected = lodashStable.map(values, stubTrue),
10723 actual = lodashStable.map(values, _.isLength);
10725 assert.deepEqual(actual, expected);
10728 QUnit.test('should return `false` for non-lengths', function(assert) {
10731 var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
10732 expected = lodashStable.map(values, stubFalse),
10733 actual = lodashStable.map(values, _.isLength);
10735 assert.deepEqual(actual, expected);
10739 /*--------------------------------------------------------------------------*/
10741 QUnit.module('lodash.isMap');
10744 QUnit.test('should return `true` for maps', function(assert) {
10748 assert.strictEqual(_.isMap(map), true);
10751 skipAssert(assert);
10755 QUnit.test('should return `false` for non-maps', function(assert) {
10758 var expected = lodashStable.map(falsey, stubFalse);
10760 var actual = lodashStable.map(falsey, function(value, index) {
10761 return index ? _.isMap(value) : _.isMap();
10764 assert.deepEqual(actual, expected);
10766 assert.strictEqual(_.isMap(args), false);
10767 assert.strictEqual(_.isMap([1, 2, 3]), false);
10768 assert.strictEqual(_.isMap(true), false);
10769 assert.strictEqual(_.isMap(new Date), false);
10770 assert.strictEqual(_.isMap(new Error), false);
10771 assert.strictEqual(_.isMap(_), false);
10772 assert.strictEqual(_.isMap(slice), false);
10773 assert.strictEqual(_.isMap({ 'a': 1 }), false);
10774 assert.strictEqual(_.isMap(1), false);
10775 assert.strictEqual(_.isMap(/x/), false);
10776 assert.strictEqual(_.isMap('a'), false);
10777 assert.strictEqual(_.isMap(symbol), false);
10778 assert.strictEqual(_.isMap(weakMap), false);
10781 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
10784 var values = [false, true],
10785 expected = lodashStable.map(values, stubFalse);
10787 var actual = lodashStable.map(values, function(value) {
10788 return _.isMap({ 'constructor': value });
10791 assert.deepEqual(actual, expected);
10794 QUnit.test('should work with maps from another realm', function(assert) {
10798 assert.strictEqual(_.isMap(realm.map), true);
10801 skipAssert(assert);
10806 /*--------------------------------------------------------------------------*/
10808 QUnit.module('lodash.isMatchWith');
10811 QUnit.test('should provide correct `customizer` arguments', function(assert) {
10815 object1 = { 'a': [1, 2], 'b': null },
10816 object2 = { 'a': [1, 2], 'b': null };
10818 object1.b = object2;
10819 object2.b = object1;
10822 [object1.a, object2.a, 'a', object1, object2],
10823 [object1.a[0], object2.a[0], 0, object1.a, object2.a],
10824 [object1.a[1], object2.a[1], 1, object1.a, object2.a],
10825 [object1.b, object2.b, 'b', object1, object2],
10826 [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
10827 [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
10828 [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
10829 [object1.b.b, object2.b.b, 'b', object1.b, object2.b]
10832 _.isMatchWith(object1, object2, function(assert) {
10833 argsList.push(slice.call(arguments, 0, -1));
10836 assert.deepEqual(argsList, expected);
10839 QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
10842 assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
10845 QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
10848 var customizer = function(value) {
10849 return _.isString(value) || undefined;
10852 assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
10853 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
10856 QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
10859 var customizer = function(value) {
10860 return _.isString(value) ? false : undefined;
10863 assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
10864 assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
10867 QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
10870 var object = { 'a': 1 },
10871 actual = _.isMatchWith(object, { 'a': 1 }, stubA);
10873 assert.strictEqual(actual, true);
10875 var expected = lodashStable.map(falsey, stubFalse);
10878 lodashStable.each(falsey, function(value) {
10879 actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
10882 assert.deepEqual(actual, expected);
10885 QUnit.test('should provide `stack` to `customizer`', function(assert) {
10890 _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
10891 actual = _.last(arguments);
10895 ? actual.constructor.name == 'Stack'
10896 : actual instanceof mapCaches.Stack
10900 QUnit.test('should ensure `customizer` is a function', function(assert) {
10903 var object = { 'a': 1 },
10904 matches = _.partial(_.isMatchWith, object),
10905 actual = lodashStable.map([object, { 'a': 2 }], matches);
10907 assert.deepEqual(actual, [true, false]);
10910 QUnit.test('should call `customizer` for values maps and sets', function(assert) {
10913 var value = { 'a': { 'b': 2 } };
10916 var map1 = new Map;
10917 map1.set('a', value);
10919 var map2 = new Map;
10920 map2.set('a', value);
10923 var set1 = new Set;
10926 var set2 = new Set;
10929 lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
10932 array = lodashStable.toArray(pair[0]),
10933 object1 = { 'a': pair[0] },
10934 object2 = { 'a': pair[1] };
10937 [pair[0], pair[1], 'a', object1, object2],
10938 [array[0], array[0], 0, array, array],
10939 [array[0][0], array[0][0], 0, array[0], array[0]],
10940 [array[0][1], array[0][1], 1, array[0], array[0]]
10944 expected.length = 2;
10946 _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
10947 argsList.push(slice.call(arguments, 0, -1));
10950 assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
10953 skipAssert(assert);
10959 /*--------------------------------------------------------------------------*/
10961 QUnit.module('lodash.isNaN');
10964 QUnit.test('should return `true` for NaNs', function(assert) {
10967 assert.strictEqual(_.isNaN(NaN), true);
10968 assert.strictEqual(_.isNaN(Object(NaN)), true);
10971 QUnit.test('should return `false` for non-NaNs', function(assert) {
10974 var expected = lodashStable.map(falsey, function(value) {
10975 return value !== value;
10978 var actual = lodashStable.map(falsey, function(value, index) {
10979 return index ? _.isNaN(value) : _.isNaN();
10982 assert.deepEqual(actual, expected);
10984 assert.strictEqual(_.isNaN(args), false);
10985 assert.strictEqual(_.isNaN([1, 2, 3]), false);
10986 assert.strictEqual(_.isNaN(true), false);
10987 assert.strictEqual(_.isNaN(new Date), false);
10988 assert.strictEqual(_.isNaN(new Error), false);
10989 assert.strictEqual(_.isNaN(_), false);
10990 assert.strictEqual(_.isNaN(slice), false);
10991 assert.strictEqual(_.isNaN({ 'a': 1 }), false);
10992 assert.strictEqual(_.isNaN(1), false);
10993 assert.strictEqual(_.isNaN(Object(1)), false);
10994 assert.strictEqual(_.isNaN(/x/), false);
10995 assert.strictEqual(_.isNaN('a'), false);
10996 assert.strictEqual(_.isNaN(symbol), false);
10999 QUnit.test('should work with `NaN` from another realm', function(assert) {
11002 if (realm.object) {
11003 assert.strictEqual(_.isNaN(realm.nan), true);
11006 skipAssert(assert);
11011 /*--------------------------------------------------------------------------*/
11013 QUnit.module('lodash.isNative');
11016 QUnit.test('should return `true` for native methods', function(assert) {
11019 var values = [Array, body && body.cloneNode, create, root.encodeURI, Promise, slice, Uint8Array],
11020 expected = lodashStable.map(values, Boolean),
11021 actual = lodashStable.map(values, _.isNative);
11023 assert.deepEqual(actual, expected);
11026 QUnit.test('should return `false` for non-native methods', function(assert) {
11029 var expected = lodashStable.map(falsey, stubFalse);
11031 var actual = lodashStable.map(falsey, function(value, index) {
11032 return index ? _.isNative(value) : _.isNative();
11035 assert.deepEqual(actual, expected);
11037 assert.strictEqual(_.isNative(args), false);
11038 assert.strictEqual(_.isNative([1, 2, 3]), false);
11039 assert.strictEqual(_.isNative(true), false);
11040 assert.strictEqual(_.isNative(new Date), false);
11041 assert.strictEqual(_.isNative(new Error), false);
11042 assert.strictEqual(_.isNative(_), false);
11043 assert.strictEqual(_.isNative({ 'a': 1 }), false);
11044 assert.strictEqual(_.isNative(1), false);
11045 assert.strictEqual(_.isNative(/x/), false);
11046 assert.strictEqual(_.isNative('a'), false);
11047 assert.strictEqual(_.isNative(symbol), false);
11050 QUnit.test('should work with native functions from another realm', function(assert) {
11053 if (realm.element) {
11054 assert.strictEqual(_.isNative(realm.element.cloneNode), true);
11057 skipAssert(assert);
11059 if (realm.object) {
11060 assert.strictEqual(_.isNative(realm.object.valueOf), true);
11063 skipAssert(assert);
11067 QUnit.test('should throw an error if core-js is detected', function(assert) {
11070 if (!isModularize) {
11071 var lodash = _.runInContext({
11072 '__core-js_shared__': {}
11075 assert.raises(function() { lodash.isNative(noop); });
11078 skipAssert(assert);
11082 QUnit.test('should detect methods masquerading as native (test in Node.js)', function(assert) {
11085 if (!amd && _._baseEach) {
11086 var path = require('path'),
11087 basePath = path.dirname(filePath),
11088 uid = 'e0gvgyrad1jor',
11089 coreKey = '__core-js_shared__',
11090 fakeSrcKey = 'Symbol(src)_1.' + uid;
11092 root[coreKey] = { 'keys': { 'IE_PROTO': 'Symbol(IE_PROTO)_3.' + uid } };
11093 emptyObject(require.cache);
11095 var baseIsNative = interopRequire(path.join(basePath, '_baseIsNative'));
11096 assert.strictEqual(baseIsNative(slice), true);
11098 slice[fakeSrcKey] = slice + '';
11099 assert.strictEqual(baseIsNative(slice), false);
11101 delete slice[fakeSrcKey];
11102 delete root[coreKey];
11105 skipAssert(assert, 2);
11110 /*--------------------------------------------------------------------------*/
11112 QUnit.module('lodash.isNil');
11115 QUnit.test('should return `true` for nullish values', function(assert) {
11118 assert.strictEqual(_.isNil(null), true);
11119 assert.strictEqual(_.isNil(), true);
11120 assert.strictEqual(_.isNil(undefined), true);
11123 QUnit.test('should return `false` for non-nullish values', function(assert) {
11126 var expected = lodashStable.map(falsey, function(value) {
11127 return value == null;
11130 var actual = lodashStable.map(falsey, function(value, index) {
11131 return index ? _.isNil(value) : _.isNil();
11134 assert.deepEqual(actual, expected);
11136 assert.strictEqual(_.isNil(args), false);
11137 assert.strictEqual(_.isNil([1, 2, 3]), false);
11138 assert.strictEqual(_.isNil(true), false);
11139 assert.strictEqual(_.isNil(new Date), false);
11140 assert.strictEqual(_.isNil(new Error), false);
11141 assert.strictEqual(_.isNil(_), false);
11142 assert.strictEqual(_.isNil(slice), false);
11143 assert.strictEqual(_.isNil({ 'a': 1 }), false);
11144 assert.strictEqual(_.isNil(1), false);
11145 assert.strictEqual(_.isNil(/x/), false);
11146 assert.strictEqual(_.isNil('a'), false);
11149 assert.strictEqual(_.isNil(symbol), false);
11152 skipAssert(assert);
11156 QUnit.test('should work with nils from another realm', function(assert) {
11159 if (realm.object) {
11160 assert.strictEqual(_.isNil(realm.null), true);
11161 assert.strictEqual(_.isNil(realm.undefined), true);
11164 skipAssert(assert, 2);
11169 /*--------------------------------------------------------------------------*/
11171 QUnit.module('lodash.isNull');
11174 QUnit.test('should return `true` for `null` values', function(assert) {
11177 assert.strictEqual(_.isNull(null), true);
11180 QUnit.test('should return `false` for non `null` values', function(assert) {
11183 var expected = lodashStable.map(falsey, function(value) {
11184 return value === null;
11187 var actual = lodashStable.map(falsey, function(value, index) {
11188 return index ? _.isNull(value) : _.isNull();
11191 assert.deepEqual(actual, expected);
11193 assert.strictEqual(_.isNull(args), false);
11194 assert.strictEqual(_.isNull([1, 2, 3]), false);
11195 assert.strictEqual(_.isNull(true), false);
11196 assert.strictEqual(_.isNull(new Date), false);
11197 assert.strictEqual(_.isNull(new Error), false);
11198 assert.strictEqual(_.isNull(_), false);
11199 assert.strictEqual(_.isNull(slice), false);
11200 assert.strictEqual(_.isNull({ 'a': 1 }), false);
11201 assert.strictEqual(_.isNull(1), false);
11202 assert.strictEqual(_.isNull(/x/), false);
11203 assert.strictEqual(_.isNull('a'), false);
11204 assert.strictEqual(_.isNull(symbol), false);
11207 QUnit.test('should work with nulls from another realm', function(assert) {
11210 if (realm.object) {
11211 assert.strictEqual(_.isNull(realm.null), true);
11214 skipAssert(assert);
11219 /*--------------------------------------------------------------------------*/
11221 QUnit.module('lodash.isNumber');
11224 QUnit.test('should return `true` for numbers', function(assert) {
11227 assert.strictEqual(_.isNumber(0), true);
11228 assert.strictEqual(_.isNumber(Object(0)), true);
11229 assert.strictEqual(_.isNumber(NaN), true);
11232 QUnit.test('should return `false` for non-numbers', function(assert) {
11235 var expected = lodashStable.map(falsey, function(value) {
11236 return typeof value == 'number';
11239 var actual = lodashStable.map(falsey, function(value, index) {
11240 return index ? _.isNumber(value) : _.isNumber();
11243 assert.deepEqual(actual, expected);
11245 assert.strictEqual(_.isNumber(args), false);
11246 assert.strictEqual(_.isNumber([1, 2, 3]), false);
11247 assert.strictEqual(_.isNumber(true), false);
11248 assert.strictEqual(_.isNumber(new Date), false);
11249 assert.strictEqual(_.isNumber(new Error), false);
11250 assert.strictEqual(_.isNumber(_), false);
11251 assert.strictEqual(_.isNumber(slice), false);
11252 assert.strictEqual(_.isNumber({ 'a': 1 }), false);
11253 assert.strictEqual(_.isNumber(/x/), false);
11254 assert.strictEqual(_.isNumber('a'), false);
11255 assert.strictEqual(_.isNumber(symbol), false);
11258 QUnit.test('should work with numbers from another realm', function(assert) {
11261 if (realm.number) {
11262 assert.strictEqual(_.isNumber(realm.number), true);
11265 skipAssert(assert);
11270 /*--------------------------------------------------------------------------*/
11272 QUnit.module('lodash.isObject');
11275 QUnit.test('should return `true` for objects', function(assert) {
11278 assert.strictEqual(_.isObject(args), true);
11279 assert.strictEqual(_.isObject([1, 2, 3]), true);
11280 assert.strictEqual(_.isObject(Object(false)), true);
11281 assert.strictEqual(_.isObject(new Date), true);
11282 assert.strictEqual(_.isObject(new Error), true);
11283 assert.strictEqual(_.isObject(_), true);
11284 assert.strictEqual(_.isObject(slice), true);
11285 assert.strictEqual(_.isObject({ 'a': 1 }), true);
11286 assert.strictEqual(_.isObject(Object(0)), true);
11287 assert.strictEqual(_.isObject(/x/), true);
11288 assert.strictEqual(_.isObject(Object('a')), true);
11291 assert.strictEqual(_.isObject(body), true);
11294 skipAssert(assert);
11297 assert.strictEqual(_.isObject(Object(symbol)), true);
11300 skipAssert(assert);
11304 QUnit.test('should return `false` for non-objects', function(assert) {
11307 var values = falsey.concat(true, 1, 'a', symbol),
11308 expected = lodashStable.map(values, stubFalse);
11310 var actual = lodashStable.map(values, function(value, index) {
11311 return index ? _.isObject(value) : _.isObject();
11314 assert.deepEqual(actual, expected);
11317 QUnit.test('should work with objects from another realm', function(assert) {
11320 if (realm.element) {
11321 assert.strictEqual(_.isObject(realm.element), true);
11324 skipAssert(assert);
11326 if (realm.object) {
11327 assert.strictEqual(_.isObject(realm.boolean), true);
11328 assert.strictEqual(_.isObject(realm.date), true);
11329 assert.strictEqual(_.isObject(realm.function), true);
11330 assert.strictEqual(_.isObject(realm.number), true);
11331 assert.strictEqual(_.isObject(realm.object), true);
11332 assert.strictEqual(_.isObject(realm.regexp), true);
11333 assert.strictEqual(_.isObject(realm.string), true);
11336 skipAssert(assert, 7);
11341 /*--------------------------------------------------------------------------*/
11343 QUnit.module('lodash.isObjectLike');
11346 QUnit.test('should return `true` for objects', function(assert) {
11349 assert.strictEqual(_.isObjectLike(args), true);
11350 assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
11351 assert.strictEqual(_.isObjectLike(Object(false)), true);
11352 assert.strictEqual(_.isObjectLike(new Date), true);
11353 assert.strictEqual(_.isObjectLike(new Error), true);
11354 assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
11355 assert.strictEqual(_.isObjectLike(Object(0)), true);
11356 assert.strictEqual(_.isObjectLike(/x/), true);
11357 assert.strictEqual(_.isObjectLike(Object('a')), true);
11360 QUnit.test('should return `false` for non-objects', function(assert) {
11363 var values = falsey.concat(true, _, slice, 1, 'a', symbol),
11364 expected = lodashStable.map(values, stubFalse);
11366 var actual = lodashStable.map(values, function(value, index) {
11367 return index ? _.isObjectLike(value) : _.isObjectLike();
11370 assert.deepEqual(actual, expected);
11373 QUnit.test('should work with objects from another realm', function(assert) {
11376 if (realm.object) {
11377 assert.strictEqual(_.isObjectLike(realm.boolean), true);
11378 assert.strictEqual(_.isObjectLike(realm.date), true);
11379 assert.strictEqual(_.isObjectLike(realm.number), true);
11380 assert.strictEqual(_.isObjectLike(realm.object), true);
11381 assert.strictEqual(_.isObjectLike(realm.regexp), true);
11382 assert.strictEqual(_.isObjectLike(realm.string), true);
11385 skipAssert(assert, 6);
11390 /*--------------------------------------------------------------------------*/
11392 QUnit.module('lodash.isPlainObject');
11395 var element = document && document.createElement('div');
11397 QUnit.test('should detect plain objects', function(assert) {
11404 assert.strictEqual(_.isPlainObject({}), true);
11405 assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
11406 assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
11407 assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
11408 assert.strictEqual(_.isPlainObject(new Foo(1)), false);
11411 QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
11414 var object = create(null);
11415 assert.strictEqual(_.isPlainObject(object), true);
11417 object.constructor = objectProto.constructor;
11418 assert.strictEqual(_.isPlainObject(object), true);
11421 QUnit.test('should return `true` for objects with a `valueOf` property', function(assert) {
11424 assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
11427 QUnit.test('should return `true` for objects with a writable `Symbol.toStringTag` property', function(assert) {
11430 if (Symbol && Symbol.toStringTag) {
11432 object[Symbol.toStringTag] = 'X';
11434 assert.deepEqual(_.isPlainObject(object), true);
11437 skipAssert(assert);
11441 QUnit.test('should return `false` for objects with a custom `[[Prototype]]`', function(assert) {
11444 var object = create({ 'a': 1 });
11445 assert.strictEqual(_.isPlainObject(object), false);
11448 QUnit.test('should return `false` for DOM elements', function(assert) {
11452 assert.strictEqual(_.isPlainObject(element), false);
11454 skipAssert(assert);
11458 QUnit.test('should return `false` for non-Object objects', function(assert) {
11461 assert.strictEqual(_.isPlainObject(arguments), false);
11462 assert.strictEqual(_.isPlainObject(Error), false);
11463 assert.strictEqual(_.isPlainObject(Math), false);
11466 QUnit.test('should return `false` for non-objects', function(assert) {
11469 var expected = lodashStable.map(falsey, stubFalse);
11471 var actual = lodashStable.map(falsey, function(value, index) {
11472 return index ? _.isPlainObject(value) : _.isPlainObject();
11475 assert.deepEqual(actual, expected);
11477 assert.strictEqual(_.isPlainObject(true), false);
11478 assert.strictEqual(_.isPlainObject('a'), false);
11479 assert.strictEqual(_.isPlainObject(symbol), false);
11482 QUnit.test('should return `false` for objects with a read-only `Symbol.toStringTag` property', function(assert) {
11485 if (Symbol && Symbol.toStringTag) {
11487 defineProperty(object, Symbol.toStringTag, {
11488 'configurable': true,
11489 'enumerable': false,
11494 assert.deepEqual(_.isPlainObject(object), false);
11497 skipAssert(assert);
11501 QUnit.test('should not mutate `value`', function(assert) {
11504 if (Symbol && Symbol.toStringTag) {
11506 proto[Symbol.toStringTag] = undefined;
11507 var object = create(proto);
11509 assert.strictEqual(_.isPlainObject(object), false);
11510 assert.notOk(lodashStable.has(object, Symbol.toStringTag));
11513 skipAssert(assert, 2);
11517 QUnit.test('should work with objects from another realm', function(assert) {
11520 if (realm.object) {
11521 assert.strictEqual(_.isPlainObject(realm.object), true);
11524 skipAssert(assert);
11529 /*--------------------------------------------------------------------------*/
11531 QUnit.module('lodash.isRegExp');
11534 QUnit.test('should return `true` for regexes', function(assert) {
11537 assert.strictEqual(_.isRegExp(/x/), true);
11538 assert.strictEqual(_.isRegExp(RegExp('x')), true);
11541 QUnit.test('should return `false` for non-regexes', function(assert) {
11544 var expected = lodashStable.map(falsey, stubFalse);
11546 var actual = lodashStable.map(falsey, function(value, index) {
11547 return index ? _.isRegExp(value) : _.isRegExp();
11550 assert.deepEqual(actual, expected);
11552 assert.strictEqual(_.isRegExp(args), false);
11553 assert.strictEqual(_.isRegExp([1, 2, 3]), false);
11554 assert.strictEqual(_.isRegExp(true), false);
11555 assert.strictEqual(_.isRegExp(new Date), false);
11556 assert.strictEqual(_.isRegExp(new Error), false);
11557 assert.strictEqual(_.isRegExp(_), false);
11558 assert.strictEqual(_.isRegExp(slice), false);
11559 assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
11560 assert.strictEqual(_.isRegExp(1), false);
11561 assert.strictEqual(_.isRegExp('a'), false);
11562 assert.strictEqual(_.isRegExp(symbol), false);
11565 QUnit.test('should work with regexes from another realm', function(assert) {
11568 if (realm.regexp) {
11569 assert.strictEqual(_.isRegExp(realm.regexp), true);
11572 skipAssert(assert);
11577 /*--------------------------------------------------------------------------*/
11579 QUnit.module('lodash.isSet');
11582 QUnit.test('should return `true` for sets', function(assert) {
11586 assert.strictEqual(_.isSet(set), true);
11589 skipAssert(assert);
11593 QUnit.test('should return `false` for non-sets', function(assert) {
11596 var expected = lodashStable.map(falsey, stubFalse);
11598 var actual = lodashStable.map(falsey, function(value, index) {
11599 return index ? _.isSet(value) : _.isSet();
11602 assert.deepEqual(actual, expected);
11604 assert.strictEqual(_.isSet(args), false);
11605 assert.strictEqual(_.isSet([1, 2, 3]), false);
11606 assert.strictEqual(_.isSet(true), false);
11607 assert.strictEqual(_.isSet(new Date), false);
11608 assert.strictEqual(_.isSet(new Error), false);
11609 assert.strictEqual(_.isSet(_), false);
11610 assert.strictEqual(_.isSet(slice), false);
11611 assert.strictEqual(_.isSet({ 'a': 1 }), false);
11612 assert.strictEqual(_.isSet(1), false);
11613 assert.strictEqual(_.isSet(/x/), false);
11614 assert.strictEqual(_.isSet('a'), false);
11615 assert.strictEqual(_.isSet(symbol), false);
11616 assert.strictEqual(_.isSet(weakSet), false);
11619 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
11622 var values = [false, true],
11623 expected = lodashStable.map(values, stubFalse);
11625 var actual = lodashStable.map(values, function(value) {
11626 return _.isSet({ 'constructor': value });
11629 assert.deepEqual(actual, expected);
11632 QUnit.test('should work with weak sets from another realm', function(assert) {
11636 assert.strictEqual(_.isSet(realm.set), true);
11639 skipAssert(assert);
11644 /*--------------------------------------------------------------------------*/
11646 QUnit.module('lodash.isString');
11649 QUnit.test('should return `true` for strings', function(assert) {
11652 assert.strictEqual(_.isString('a'), true);
11653 assert.strictEqual(_.isString(Object('a')), true);
11656 QUnit.test('should return `false` for non-strings', function(assert) {
11659 var expected = lodashStable.map(falsey, function(value) {
11660 return value === '';
11663 var actual = lodashStable.map(falsey, function(value, index) {
11664 return index ? _.isString(value) : _.isString();
11667 assert.deepEqual(actual, expected);
11669 assert.strictEqual(_.isString(args), false);
11670 assert.strictEqual(_.isString([1, 2, 3]), false);
11671 assert.strictEqual(_.isString(true), false);
11672 assert.strictEqual(_.isString(new Date), false);
11673 assert.strictEqual(_.isString(new Error), false);
11674 assert.strictEqual(_.isString(_), false);
11675 assert.strictEqual(_.isString(slice), false);
11676 assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
11677 assert.strictEqual(_.isString(1), false);
11678 assert.strictEqual(_.isString(/x/), false);
11679 assert.strictEqual(_.isString(symbol), false);
11682 QUnit.test('should work with strings from another realm', function(assert) {
11685 if (realm.string) {
11686 assert.strictEqual(_.isString(realm.string), true);
11689 skipAssert(assert);
11694 /*--------------------------------------------------------------------------*/
11696 QUnit.module('lodash.isSymbol');
11699 QUnit.test('should return `true` for symbols', function(assert) {
11703 assert.strictEqual(_.isSymbol(symbol), true);
11704 assert.strictEqual(_.isSymbol(Object(symbol)), true);
11707 skipAssert(assert, 2);
11711 QUnit.test('should return `false` for non-symbols', function(assert) {
11714 var expected = lodashStable.map(falsey, stubFalse);
11716 var actual = lodashStable.map(falsey, function(value, index) {
11717 return index ? _.isSymbol(value) : _.isSymbol();
11720 assert.deepEqual(actual, expected);
11722 assert.strictEqual(_.isSymbol(args), false);
11723 assert.strictEqual(_.isSymbol([1, 2, 3]), false);
11724 assert.strictEqual(_.isSymbol(true), false);
11725 assert.strictEqual(_.isSymbol(new Date), false);
11726 assert.strictEqual(_.isSymbol(new Error), false);
11727 assert.strictEqual(_.isSymbol(_), false);
11728 assert.strictEqual(_.isSymbol(slice), false);
11729 assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
11730 assert.strictEqual(_.isSymbol(1), false);
11731 assert.strictEqual(_.isSymbol(/x/), false);
11732 assert.strictEqual(_.isSymbol('a'), false);
11735 QUnit.test('should work with symbols from another realm', function(assert) {
11738 if (Symbol && realm.symbol) {
11739 assert.strictEqual(_.isSymbol(realm.symbol), true);
11742 skipAssert(assert);
11747 /*--------------------------------------------------------------------------*/
11749 QUnit.module('lodash.isTypedArray');
11752 QUnit.test('should return `true` for typed arrays', function(assert) {
11755 var expected = lodashStable.map(typedArrays, function(type) {
11756 return type in root;
11759 var actual = lodashStable.map(typedArrays, function(type) {
11760 var Ctor = root[type];
11761 return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
11764 assert.deepEqual(actual, expected);
11767 QUnit.test('should return `false` for non typed arrays', function(assert) {
11770 var expected = lodashStable.map(falsey, stubFalse);
11772 var actual = lodashStable.map(falsey, function(value, index) {
11773 return index ? _.isTypedArray(value) : _.isTypedArray();
11776 assert.deepEqual(actual, expected);
11778 assert.strictEqual(_.isTypedArray(args), false);
11779 assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
11780 assert.strictEqual(_.isTypedArray(true), false);
11781 assert.strictEqual(_.isTypedArray(new Date), false);
11782 assert.strictEqual(_.isTypedArray(new Error), false);
11783 assert.strictEqual(_.isTypedArray(_), false);
11784 assert.strictEqual(_.isTypedArray(slice), false);
11785 assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
11786 assert.strictEqual(_.isTypedArray(1), false);
11787 assert.strictEqual(_.isTypedArray(/x/), false);
11788 assert.strictEqual(_.isTypedArray('a'), false);
11789 assert.strictEqual(_.isTypedArray(symbol), false);
11792 QUnit.test('should work with typed arrays from another realm', function(assert) {
11795 if (realm.object) {
11796 var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
11798 var expected = lodashStable.map(props, function(key) {
11799 return realm[key] !== undefined;
11802 var actual = lodashStable.map(props, function(key) {
11803 var value = realm[key];
11804 return value ? _.isTypedArray(value) : false;
11807 assert.deepEqual(actual, expected);
11810 skipAssert(assert);
11815 /*--------------------------------------------------------------------------*/
11817 QUnit.module('lodash.isUndefined');
11820 QUnit.test('should return `true` for `undefined` values', function(assert) {
11823 assert.strictEqual(_.isUndefined(), true);
11824 assert.strictEqual(_.isUndefined(undefined), true);
11827 QUnit.test('should return `false` for non `undefined` values', function(assert) {
11830 var expected = lodashStable.map(falsey, function(value) {
11831 return value === undefined;
11834 var actual = lodashStable.map(falsey, function(value, index) {
11835 return index ? _.isUndefined(value) : _.isUndefined();
11838 assert.deepEqual(actual, expected);
11840 assert.strictEqual(_.isUndefined(args), false);
11841 assert.strictEqual(_.isUndefined([1, 2, 3]), false);
11842 assert.strictEqual(_.isUndefined(true), false);
11843 assert.strictEqual(_.isUndefined(new Date), false);
11844 assert.strictEqual(_.isUndefined(new Error), false);
11845 assert.strictEqual(_.isUndefined(_), false);
11846 assert.strictEqual(_.isUndefined(slice), false);
11847 assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
11848 assert.strictEqual(_.isUndefined(1), false);
11849 assert.strictEqual(_.isUndefined(/x/), false);
11850 assert.strictEqual(_.isUndefined('a'), false);
11853 assert.strictEqual(_.isUndefined(symbol), false);
11856 skipAssert(assert);
11860 QUnit.test('should work with `undefined` from another realm', function(assert) {
11863 if (realm.object) {
11864 assert.strictEqual(_.isUndefined(realm.undefined), true);
11867 skipAssert(assert);
11872 /*--------------------------------------------------------------------------*/
11874 QUnit.module('lodash.isWeakMap');
11877 QUnit.test('should return `true` for weak maps', function(assert) {
11881 assert.strictEqual(_.isWeakMap(weakMap), true);
11884 skipAssert(assert);
11888 QUnit.test('should return `false` for non weak maps', function(assert) {
11891 var expected = lodashStable.map(falsey, stubFalse);
11893 var actual = lodashStable.map(falsey, function(value, index) {
11894 return index ? _.isWeakMap(value) : _.isWeakMap();
11897 assert.deepEqual(actual, expected);
11899 assert.strictEqual(_.isWeakMap(args), false);
11900 assert.strictEqual(_.isWeakMap([1, 2, 3]), false);
11901 assert.strictEqual(_.isWeakMap(true), false);
11902 assert.strictEqual(_.isWeakMap(new Date), false);
11903 assert.strictEqual(_.isWeakMap(new Error), false);
11904 assert.strictEqual(_.isWeakMap(_), false);
11905 assert.strictEqual(_.isWeakMap(slice), false);
11906 assert.strictEqual(_.isWeakMap({ 'a': 1 }), false);
11907 assert.strictEqual(_.isWeakMap(map), false);
11908 assert.strictEqual(_.isWeakMap(1), false);
11909 assert.strictEqual(_.isWeakMap(/x/), false);
11910 assert.strictEqual(_.isWeakMap('a'), false);
11911 assert.strictEqual(_.isWeakMap(symbol), false);
11914 QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
11917 var values = [false, true],
11918 expected = lodashStable.map(values, stubFalse);
11920 var actual = lodashStable.map(values, function(value) {
11921 return _.isWeakMap({ 'constructor': value });
11924 assert.deepEqual(actual, expected);
11927 QUnit.test('should work with weak maps from another realm', function(assert) {
11930 if (realm.weakMap) {
11931 assert.strictEqual(_.isWeakMap(realm.weakMap), true);
11934 skipAssert(assert);
11939 /*--------------------------------------------------------------------------*/
11941 QUnit.module('lodash.isWeakSet');
11944 QUnit.test('should return `true` for weak sets', function(assert) {
11948 assert.strictEqual(_.isWeakSet(weakSet), true);
11951 skipAssert(assert);
11955 QUnit.test('should return `false` for non weak sets', function(assert) {
11958 var expected = lodashStable.map(falsey, stubFalse);
11960 var actual = lodashStable.map(falsey, function(value, index) {
11961 return index ? _.isWeakSet(value) : _.isWeakSet();
11964 assert.deepEqual(actual, expected);
11966 assert.strictEqual(_.isWeakSet(args), false);
11967 assert.strictEqual(_.isWeakSet([1, 2, 3]), false);
11968 assert.strictEqual(_.isWeakSet(true), false);
11969 assert.strictEqual(_.isWeakSet(new Date), false);
11970 assert.strictEqual(_.isWeakSet(new Error), false);
11971 assert.strictEqual(_.isWeakSet(_), false);
11972 assert.strictEqual(_.isWeakSet(slice), false);
11973 assert.strictEqual(_.isWeakSet({ 'a': 1 }), false);
11974 assert.strictEqual(_.isWeakSet(1), false);
11975 assert.strictEqual(_.isWeakSet(/x/), false);
11976 assert.strictEqual(_.isWeakSet('a'), false);
11977 assert.strictEqual(_.isWeakSet(set), false);
11978 assert.strictEqual(_.isWeakSet(symbol), false);
11981 QUnit.test('should work with weak sets from another realm', function(assert) {
11984 if (realm.weakSet) {
11985 assert.strictEqual(_.isWeakSet(realm.weakSet), true);
11988 skipAssert(assert);
11993 /*--------------------------------------------------------------------------*/
11995 QUnit.module('isType checks');
11998 QUnit.test('should return `false` for subclassed values', function(assert) {
12002 'isArray', 'isBoolean', 'isDate', 'isFunction',
12003 'isNumber', 'isRegExp', 'isString'
12006 lodashStable.each(funcs, function(methodName) {
12008 Foo.prototype = root[methodName.slice(2)].prototype;
12010 var object = new Foo;
12011 if (objToString.call(object) == objectTag) {
12012 assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
12015 skipAssert(assert);
12020 QUnit.test('should not error on host objects (test in IE)', function(assert) {
12024 'isArguments', 'isArray', 'isArrayBuffer', 'isArrayLike', 'isBoolean',
12025 'isBuffer', 'isDate', 'isElement', 'isError', 'isFinite', 'isFunction',
12026 'isInteger', 'isMap', 'isNaN', 'isNil', 'isNull', 'isNumber', 'isObject',
12027 'isObjectLike', 'isRegExp', 'isSet', 'isSafeInteger', 'isString',
12028 'isUndefined', 'isWeakMap', 'isWeakSet'
12031 lodashStable.each(funcs, function(methodName) {
12033 _[methodName](xml);
12034 assert.ok(true, '`_.' + methodName + '` should not error');
12037 skipAssert(assert);
12043 /*--------------------------------------------------------------------------*/
12045 QUnit.module('lodash.iteratee');
12048 QUnit.test('should provide arguments to `func`', function(assert) {
12051 var fn = function() { return slice.call(arguments); },
12052 iteratee = _.iteratee(fn),
12053 actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
12055 assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
12058 QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
12062 values = [, null, undefined],
12063 expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
12065 var actual = lodashStable.map(values, function(value, index) {
12066 var identity = index ? _.iteratee(value) : _.iteratee();
12067 return [!isNpm && identity, identity(object)];
12070 assert.deepEqual(actual, expected);
12073 QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
12076 var matches = _.iteratee({ 'a': 1, 'b': 2 });
12077 assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
12078 assert.strictEqual(matches({ 'b': 2 }), false);
12081 QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
12085 { 'a': { 'b': 2, 'c': 3 } },
12086 { 'a': 1, 'b': 2 },
12090 lodashStable.each(sources, function(source, index) {
12091 var object = lodashStable.cloneDeep(source),
12092 matches = _.iteratee(source);
12094 assert.strictEqual(matches(object), true);
12105 assert.strictEqual(matches(object), true);
12106 assert.strictEqual(matches(source), false);
12110 QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
12113 var array = ['a', undefined],
12114 matches = _.iteratee([0, 'a']);
12116 assert.strictEqual(matches(array), true);
12118 matches = _.iteratee(['0', 'a']);
12119 assert.strictEqual(matches(array), true);
12121 matches = _.iteratee([1, undefined]);
12122 assert.strictEqual(matches(array), true);
12125 QUnit.test('should support deep paths for `_.matchesProperty` shorthands', function(assert) {
12128 var object = { 'a': { 'b': { 'c': 1, 'd': 2 } } },
12129 matches = _.iteratee(['a.b', { 'c': 1 }]);
12131 assert.strictEqual(matches(object), true);
12134 QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
12138 { 'a': { 'b': 2, 'c': 3 } },
12139 { 'a': 1, 'b': 2 },
12143 lodashStable.each(sources, function(source, index) {
12144 var object = { 'a': lodashStable.cloneDeep(source) },
12145 matches = _.iteratee(['a', source]);
12147 assert.strictEqual(matches(object), true);
12158 assert.strictEqual(matches(object), true);
12159 assert.strictEqual(matches({ 'a': source }), false);
12163 QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
12167 prop = _.iteratee(0);
12169 assert.strictEqual(prop(array), 'a');
12171 prop = _.iteratee('0');
12172 assert.strictEqual(prop(array), 'a');
12175 QUnit.test('should support deep paths for `_.property` shorthands', function(assert) {
12178 var object = { 'a': { 'b': 2 } },
12179 prop = _.iteratee('a.b');
12181 assert.strictEqual(prop(object), 2);
12184 QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
12187 var fn = function() {
12188 var result = [this.a];
12189 push.apply(result, arguments);
12193 var expected = [1, 2, 3],
12194 object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
12196 assert.deepEqual(object.iteratee(3), expected);
12198 object.iteratee = _.iteratee(_.partialRight(fn, 3));
12199 assert.deepEqual(object.iteratee(2), expected);
12202 QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
12205 var iteratee = _.iteratee;
12208 assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
12210 _.iteratee = iteratee;
12213 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
12216 var fn = function() { return this instanceof Number; },
12217 array = [fn, fn, fn],
12218 iteratees = lodashStable.map(array, _.iteratee),
12219 expected = lodashStable.map(array, stubFalse);
12221 var actual = lodashStable.map(iteratees, function(iteratee) {
12225 assert.deepEqual(actual, expected);
12229 /*--------------------------------------------------------------------------*/
12231 QUnit.module('custom `_.iteratee` methods');
12234 var array = ['one', 'two', 'three'],
12235 getPropA = _.partial(_.property, 'a'),
12236 getPropB = _.partial(_.property, 'b'),
12237 getLength = _.partial(_.property, 'length'),
12238 iteratee = _.iteratee;
12240 var getSum = function() {
12241 return function(result, object) {
12242 return result + object.a;
12247 { 'a': 0, 'b': 0 },
12248 { 'a': 1, 'b': 0 },
12252 QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
12255 if (!isModularize) {
12256 _.iteratee = getLength;
12257 assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
12258 _.iteratee = iteratee;
12261 skipAssert(assert);
12265 QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
12268 if (!isModularize) {
12269 _.iteratee = getPropA;
12270 assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
12271 _.iteratee = iteratee;
12274 skipAssert(assert);
12278 QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
12281 if (!isModularize) {
12282 _.iteratee = getPropB;
12283 assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
12284 _.iteratee = iteratee;
12287 skipAssert(assert);
12291 QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
12294 if (!isModularize) {
12295 _.iteratee = getPropB;
12296 assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
12297 _.iteratee = iteratee;
12300 skipAssert(assert);
12304 QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
12307 if (!isModularize) {
12308 _.iteratee = getPropA;
12309 assert.strictEqual(_.every(objects.slice(1)), true);
12310 _.iteratee = iteratee;
12313 skipAssert(assert);
12317 QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
12320 if (!isModularize) {
12321 var objects = [{ 'a': 0 }, { 'a': 1 }];
12323 _.iteratee = getPropA;
12324 assert.deepEqual(_.filter(objects), [objects[1]]);
12325 _.iteratee = iteratee;
12328 skipAssert(assert);
12332 QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
12335 if (!isModularize) {
12336 _.iteratee = getPropA;
12337 assert.strictEqual(_.find(objects), objects[1]);
12338 _.iteratee = iteratee;
12341 skipAssert(assert);
12345 QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
12348 if (!isModularize) {
12349 _.iteratee = getPropA;
12350 assert.strictEqual(_.findIndex(objects), 1);
12351 _.iteratee = iteratee;
12354 skipAssert(assert);
12358 QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
12361 if (!isModularize) {
12362 _.iteratee = getPropA;
12363 assert.strictEqual(_.findLast(objects), objects[2]);
12364 _.iteratee = iteratee;
12367 skipAssert(assert);
12371 QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
12374 if (!isModularize) {
12375 _.iteratee = getPropA;
12376 assert.strictEqual(_.findLastIndex(objects), 2);
12377 _.iteratee = iteratee;
12380 skipAssert(assert);
12384 QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
12387 if (!isModularize) {
12388 _.iteratee = getPropB;
12389 assert.strictEqual(_.findKey(objects), '2');
12390 _.iteratee = iteratee;
12393 skipAssert(assert);
12397 QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
12400 if (!isModularize) {
12401 _.iteratee = getPropB;
12402 assert.strictEqual(_.findLastKey(objects), '2');
12403 _.iteratee = iteratee;
12406 skipAssert(assert);
12410 QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
12413 if (!isModularize) {
12414 _.iteratee = getLength;
12415 assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
12416 _.iteratee = iteratee;
12419 skipAssert(assert);
12423 QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
12426 if (!isModularize) {
12427 _.iteratee = getPropA;
12428 assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
12429 _.iteratee = iteratee;
12432 skipAssert(assert);
12436 QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
12439 if (!isModularize) {
12440 _.iteratee = getLength;
12441 assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
12442 _.iteratee = iteratee;
12445 skipAssert(assert);
12449 QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
12452 if (!isModularize) {
12453 _.iteratee = getPropA;
12454 assert.deepEqual(_.map(objects), [0, 1, 1]);
12455 _.iteratee = iteratee;
12458 skipAssert(assert);
12462 QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
12465 if (!isModularize) {
12466 _.iteratee = getPropB;
12467 assert.deepEqual(_.mapKeys({ 'a': { 'b': 2 } }), { '2': { 'b': 2 } });
12468 _.iteratee = iteratee;
12471 skipAssert(assert);
12475 QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
12478 if (!isModularize) {
12479 _.iteratee = getPropB;
12480 assert.deepEqual(_.mapValues({ 'a': { 'b': 2 } }), { 'a': 2 });
12481 _.iteratee = iteratee;
12484 skipAssert(assert);
12488 QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
12491 if (!isModularize) {
12492 _.iteratee = getPropB;
12493 assert.deepEqual(_.maxBy(objects), objects[2]);
12494 _.iteratee = iteratee;
12497 skipAssert(assert);
12501 QUnit.test('`_.meanBy` should use `_.iteratee` internally', function(assert) {
12504 if (!isModularize) {
12505 _.iteratee = getPropA;
12506 assert.strictEqual(_.meanBy(objects), 2 / 3);
12507 _.iteratee = iteratee;
12510 skipAssert(assert);
12514 QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
12517 if (!isModularize) {
12518 _.iteratee = getPropB;
12519 assert.deepEqual(_.minBy(objects), objects[0]);
12520 _.iteratee = iteratee;
12523 skipAssert(assert);
12527 QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
12530 if (!isModularize) {
12531 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
12533 _.iteratee = getPropA;
12534 assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
12535 _.iteratee = iteratee;
12538 skipAssert(assert);
12542 QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
12545 if (!isModularize) {
12546 _.iteratee = getPropA;
12547 assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
12548 _.iteratee = iteratee;
12551 skipAssert(assert);
12555 QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
12558 if (!isModularize) {
12559 _.iteratee = getSum;
12560 assert.strictEqual(_.reduce(objects, undefined, 0), 2);
12561 _.iteratee = iteratee;
12564 skipAssert(assert);
12568 QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
12571 if (!isModularize) {
12572 _.iteratee = getSum;
12573 assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
12574 _.iteratee = iteratee;
12577 skipAssert(assert);
12581 QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
12584 if (!isModularize) {
12585 var objects = [{ 'a': 0 }, { 'a': 1 }];
12587 _.iteratee = getPropA;
12588 assert.deepEqual(_.reject(objects), [objects[0]]);
12589 _.iteratee = iteratee;
12592 skipAssert(assert);
12596 QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
12599 if (!isModularize) {
12600 var objects = [{ 'a': 0 }, { 'a': 1 }];
12602 _.iteratee = getPropA;
12604 assert.deepEqual(objects, [{ 'a': 0 }]);
12605 _.iteratee = iteratee;
12608 skipAssert(assert);
12612 QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
12615 if (!isModularize) {
12616 _.iteratee = getPropB;
12617 assert.strictEqual(_.some(objects), true);
12618 _.iteratee = iteratee;
12621 skipAssert(assert);
12625 QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
12628 if (!isModularize) {
12629 _.iteratee = getPropA;
12630 assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
12631 _.iteratee = iteratee;
12634 skipAssert(assert);
12638 QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
12641 if (!isModularize) {
12642 var objects = [{ 'a': 30 }, { 'a': 50 }];
12644 _.iteratee = getPropA;
12645 assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
12646 _.iteratee = iteratee;
12649 skipAssert(assert);
12653 QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
12656 if (!isModularize) {
12657 var objects = [{ 'a': 30 }, { 'a': 50 }];
12659 _.iteratee = getPropA;
12660 assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
12661 _.iteratee = iteratee;
12664 skipAssert(assert);
12668 QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
12671 if (!isModularize) {
12672 _.iteratee = getPropB;
12673 assert.strictEqual(_.sumBy(objects), 1);
12674 _.iteratee = iteratee;
12677 skipAssert(assert);
12681 QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
12684 if (!isModularize) {
12685 _.iteratee = getPropB;
12686 assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
12687 _.iteratee = iteratee;
12690 skipAssert(assert);
12694 QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
12697 if (!isModularize) {
12698 _.iteratee = getPropB;
12699 assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
12700 _.iteratee = iteratee;
12703 skipAssert(assert);
12707 QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
12710 if (!isModularize) {
12711 _.iteratee = function() {
12712 return function(result, object) {
12713 result.sum += object.a;
12717 assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
12718 _.iteratee = iteratee;
12721 skipAssert(assert);
12725 QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
12728 if (!isModularize) {
12729 _.iteratee = getPropB;
12730 assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
12731 _.iteratee = iteratee;
12734 skipAssert(assert);
12738 QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
12741 if (!isModularize) {
12742 _.iteratee = getPropB;
12743 assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
12744 _.iteratee = iteratee;
12747 skipAssert(assert);
12751 QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
12754 if (!isModularize) {
12755 _.iteratee = getPropA;
12756 assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
12757 _.iteratee = iteratee;
12760 skipAssert(assert);
12765 /*--------------------------------------------------------------------------*/
12767 QUnit.module('lodash.join');
12770 var array = ['a', 'b', 'c'];
12772 QUnit.test('should return join all array elements into a string', function(assert) {
12775 assert.strictEqual(_.join(array, '~'), 'a~b~c');
12778 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
12782 var wrapped = _(array);
12783 assert.strictEqual(wrapped.join('~'), 'a~b~c');
12784 assert.strictEqual(wrapped.value(), array);
12787 skipAssert(assert, 2);
12791 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
12795 assert.ok(_(array).chain().join('~') instanceof _);
12798 skipAssert(assert);
12803 /*--------------------------------------------------------------------------*/
12805 QUnit.module('lodash.keyBy');
12809 { 'dir': 'left', 'code': 97 },
12810 { 'dir': 'right', 'code': 100 }
12813 QUnit.test('should transform keys by `iteratee`', function(assert) {
12816 var expected = { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } };
12818 var actual = _.keyBy(array, function(object) {
12819 return String.fromCharCode(object.code);
12822 assert.deepEqual(actual, expected);
12825 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
12828 var array = [4, 6, 6],
12829 values = [, null, undefined],
12830 expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
12832 var actual = lodashStable.map(values, function(value, index) {
12833 return index ? _.keyBy(array, value) : _.keyBy(array);
12836 assert.deepEqual(actual, expected);
12839 QUnit.test('should work with `_.property` shorthands', function(assert) {
12842 var expected = { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } },
12843 actual = _.keyBy(array, 'dir');
12845 assert.deepEqual(actual, expected);
12848 QUnit.test('should only add values to own, not inherited, properties', function(assert) {
12851 var actual = _.keyBy([6.1, 4.2, 6.3], function(n) {
12852 return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
12855 assert.deepEqual(actual.constructor, 4.2);
12856 assert.deepEqual(actual.hasOwnProperty, 6.3);
12859 QUnit.test('should work with a number for `iteratee`', function(assert) {
12868 assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
12869 assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
12872 QUnit.test('should work with an object for `collection`', function(assert) {
12875 var actual = _.keyBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
12876 assert.deepEqual(actual, { '4': 4.2, '6': 6.3 });
12879 QUnit.test('should work in a lazy sequence', function(assert) {
12883 var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
12884 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
12885 lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
12888 var actual = _(array).keyBy().map(square).filter(isEven).take().value();
12890 assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
12893 skipAssert(assert);
12898 /*--------------------------------------------------------------------------*/
12900 QUnit.module('keys methods');
12902 lodashStable.each(['keys', 'keysIn'], function(methodName) {
12903 var func = _[methodName],
12904 isKeys = methodName == 'keys';
12906 QUnit.test('`_.' + methodName + '` should return the string keyed property names of `object`', function(assert) {
12909 var actual = func({ 'a': 1, 'b': 1 }).sort();
12911 assert.deepEqual(actual, ['a', 'b']);
12914 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties', function(assert) {
12920 Foo.prototype.b = 2;
12922 var expected = isKeys ? ['a'] : ['a', 'b'],
12923 actual = func(new Foo).sort();
12925 assert.deepEqual(actual, expected);
12928 QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
12934 var actual = func(array).sort();
12936 assert.deepEqual(actual, ['0', '1', '2']);
12939 QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
12945 var actual = func(array).sort();
12947 assert.deepEqual(actual, ['0', 'a']);
12950 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of arrays', function(assert) {
12955 var expected = isKeys ? ['0'] : ['0', 'a'],
12956 actual = func([1]).sort();
12958 assert.deepEqual(actual, expected);
12960 delete arrayProto.a;
12963 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
12966 var values = [args, strictArgs],
12967 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2']));
12969 var actual = lodashStable.map(values, function(value) {
12970 return func(value).sort();
12973 assert.deepEqual(actual, expected);
12976 QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
12979 var values = [args, strictArgs],
12980 expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
12982 var actual = lodashStable.map(values, function(value) {
12984 var result = func(value).sort();
12989 assert.deepEqual(actual, expected);
12992 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of `arguments` objects', function(assert) {
12995 var values = [args, strictArgs],
12996 expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
12998 var actual = lodashStable.map(values, function(value) {
13000 var result = func(value).sort();
13001 delete objectProto.a;
13005 assert.deepEqual(actual, expected);
13008 QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
13011 var actual = func(Object('abc')).sort();
13013 assert.deepEqual(actual, ['0', '1', '2']);
13016 QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
13019 var object = Object('a');
13022 var actual = func(object).sort();
13024 assert.deepEqual(actual, ['0', 'a']);
13027 QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of string objects', function(assert) {
13032 var expected = isKeys ? ['0'] : ['0', 'a'],
13033 actual = func(Object('a')).sort();
13035 assert.deepEqual(actual, expected);
13037 delete stringProto.a;
13040 QUnit.test('`_.' + methodName + '` should work with array-like objects', function(assert) {
13043 var object = { '0': 'a', 'length': 1 },
13044 actual = func(object).sort();
13046 assert.deepEqual(actual, ['0', 'length']);
13049 QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
13052 var expected = lodashStable.map(primitives, function(value) {
13053 return typeof value == 'string' ? ['0'] : [];
13056 var actual = lodashStable.map(primitives, func);
13057 assert.deepEqual(actual, expected);
13059 // IE 9 doesn't box numbers in for-in loops.
13061 assert.deepEqual(func(0), isKeys ? [] : ['a']);
13062 delete numberProto.a;
13065 QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
13069 Foo.prototype.a = 1;
13071 var expected = ['a'];
13072 assert.deepEqual(func(Foo.prototype), expected);
13074 Foo.prototype = { 'constructor': Foo, 'a': 1 };
13075 assert.deepEqual(func(Foo.prototype), expected);
13077 var Fake = { 'prototype': {} };
13078 Fake.prototype.constructor = Fake;
13079 assert.deepEqual(func(Fake.prototype), ['constructor']);
13082 QUnit.test('`_.' + methodName + '` should return an empty array when `object` is nullish', function(assert) {
13083 var values = [, null, undefined],
13084 expected = lodashStable.map(values, stubArray);
13086 var actual = lodashStable.map(values, function(value, index) {
13088 var result = index ? func(value) : func();
13089 delete objectProto.a;
13093 assert.deepEqual(actual, expected);
13097 /*--------------------------------------------------------------------------*/
13099 QUnit.module('lodash.last');
13102 var array = [1, 2, 3, 4];
13104 QUnit.test('should return the last element', function(assert) {
13107 assert.strictEqual(_.last(array), 4);
13110 QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
13116 assert.strictEqual(_.last([]), undefined);
13119 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
13122 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
13123 actual = lodashStable.map(array, _.last);
13125 assert.deepEqual(actual, [3, 6, 9]);
13128 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
13132 assert.strictEqual(_(array).last(), 4);
13135 skipAssert(assert);
13139 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
13143 assert.ok(_(array).chain().last() instanceof _);
13146 skipAssert(assert);
13150 QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
13154 var wrapped = _(array).chain().last();
13155 assert.strictEqual(wrapped.__wrapped__, array);
13158 skipAssert(assert);
13162 QUnit.test('should work in a lazy sequence', function(assert) {
13166 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
13167 smallArray = array;
13169 lodashStable.times(2, function(index) {
13170 var array = index ? largeArray : smallArray,
13171 wrapped = _(array).filter(isEven);
13173 assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
13177 skipAssert(assert, 2);
13182 /*--------------------------------------------------------------------------*/
13184 QUnit.module('lodash.lowerCase');
13187 QUnit.test('should lowercase as space-separated words', function(assert) {
13190 assert.strictEqual(_.lowerCase('--Foo-Bar--'), 'foo bar');
13191 assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
13192 assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
13196 /*--------------------------------------------------------------------------*/
13198 QUnit.module('lodash.lowerFirst');
13201 QUnit.test('should lowercase only the first character', function(assert) {
13204 assert.strictEqual(_.lowerFirst('fred'), 'fred');
13205 assert.strictEqual(_.lowerFirst('Fred'), 'fred');
13206 assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
13210 /*--------------------------------------------------------------------------*/
13212 QUnit.module('lodash.lt');
13215 QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
13218 assert.strictEqual(_.lt(1, 3), true);
13219 assert.strictEqual(_.lt('abc', 'def'), true);
13222 QUnit.test('should return `false` if `value` >= `other`', function(assert) {
13225 assert.strictEqual(_.lt(3, 1), false);
13226 assert.strictEqual(_.lt(3, 3), false);
13227 assert.strictEqual(_.lt('def', 'abc'), false);
13228 assert.strictEqual(_.lt('def', 'def'), false);
13232 /*--------------------------------------------------------------------------*/
13234 QUnit.module('lodash.lte');
13237 QUnit.test('should return `true` if `value` is <= `other`', function(assert) {
13240 assert.strictEqual(_.lte(1, 3), true);
13241 assert.strictEqual(_.lte(3, 3), true);
13242 assert.strictEqual(_.lte('abc', 'def'), true);
13243 assert.strictEqual(_.lte('def', 'def'), true);
13246 QUnit.test('should return `false` if `value` > `other`', function(assert) {
13249 assert.strictEqual(_.lt(3, 1), false);
13250 assert.strictEqual(_.lt('def', 'abc'), false);
13254 /*--------------------------------------------------------------------------*/
13256 QUnit.module('lodash.findLastIndex and lodash.lastIndexOf');
13258 lodashStable.each(['findLastIndex', 'lastIndexOf'], function(methodName) {
13259 var array = [1, 2, 3, 1, 2, 3],
13260 func = _[methodName],
13261 resolve = methodName == 'findLastIndex' ? lodashStable.curry(lodashStable.eq) : identity;
13263 QUnit.test('`_.' + methodName + '` should return the index of the last matched value', function(assert) {
13266 assert.strictEqual(func(array, resolve(3)), 5);
13269 QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
13272 assert.strictEqual(func(array, resolve(1), 2), 0);
13275 QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
13278 var values = [6, 8, Math.pow(2, 32), Infinity],
13279 expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
13281 var actual = lodashStable.map(values, function(fromIndex) {
13283 func(array, resolve(undefined), fromIndex),
13284 func(array, resolve(1), fromIndex),
13285 func(array, resolve(''), fromIndex)
13289 assert.deepEqual(actual, expected);
13292 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
13295 assert.strictEqual(func(array, resolve(2), -3), 1);
13298 QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
13301 var values = [-6, -8, -Infinity],
13302 expected = lodashStable.map(values, stubZero);
13304 var actual = lodashStable.map(values, function(fromIndex) {
13305 return func(array, resolve(1), fromIndex);
13308 assert.deepEqual(actual, expected);
13311 QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values correctly', function(assert) {
13314 var expected = lodashStable.map(falsey, function(value) {
13315 return value === undefined ? 5 : -1;
13318 var actual = lodashStable.map(falsey, function(fromIndex) {
13319 return func(array, resolve(3), fromIndex);
13322 assert.deepEqual(actual, expected);
13325 QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
13328 assert.strictEqual(func(array, resolve(2), 4.2), 4);
13332 /*--------------------------------------------------------------------------*/
13334 QUnit.module('indexOf methods');
13336 lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
13337 var func = _[methodName],
13338 isIndexOf = !/last/i.test(methodName),
13339 isSorted = /^sorted/.test(methodName);
13341 QUnit.test('`_.' + methodName + '` should accept a falsey `array`', function(assert) {
13344 var expected = lodashStable.map(falsey, lodashStable.constant(-1));
13346 var actual = lodashStable.map(falsey, function(array, index) {
13348 return index ? func(array) : func();
13352 assert.deepEqual(actual, expected);
13355 QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
13358 var array = [1, 2, 3],
13361 assert.strictEqual(func(array, 4), -1);
13362 assert.strictEqual(func(array, 4, true), -1);
13363 assert.strictEqual(func(array, undefined, true), -1);
13365 assert.strictEqual(func(empty, undefined), -1);
13366 assert.strictEqual(func(empty, undefined, true), -1);
13369 QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
13375 assert.strictEqual(func(array, undefined), -1);
13376 assert.strictEqual(func(array, 0, true), -1);
13379 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
13382 var array = isSorted
13384 : [1, NaN, 3, NaN, 5, NaN];
13387 assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
13388 skipAssert(assert, 2);
13391 assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
13392 assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
13393 assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
13397 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
13400 assert.strictEqual(func([-0], 0), 0);
13401 assert.strictEqual(func([0], -0), 0);
13405 /*--------------------------------------------------------------------------*/
13407 QUnit.module('lodash.map');
13410 var array = [1, 2];
13412 QUnit.test('should map values in `collection` to a new array', function(assert) {
13415 var object = { 'a': 1, 'b': 2 },
13416 expected = ['1', '2'];
13418 assert.deepEqual(_.map(array, String), expected);
13419 assert.deepEqual(_.map(object, String), expected);
13422 QUnit.test('should work with `_.property` shorthands', function(assert) {
13425 var objects = [{ 'a': 'x' }, { 'a': 'y' }];
13426 assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
13429 QUnit.test('should iterate over own string keyed properties of objects', function(assert) {
13435 Foo.prototype.b = 2;
13437 var actual = _.map(new Foo, identity);
13438 assert.deepEqual(actual, [1]);
13441 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13444 var object = { 'a': 1, 'b': 2 },
13445 values = [, null, undefined],
13446 expected = lodashStable.map(values, lodashStable.constant([1, 2]));
13448 lodashStable.each([array, object], function(collection) {
13449 var actual = lodashStable.map(values, function(value, index) {
13450 return index ? _.map(collection, value) : _.map(collection);
13453 assert.deepEqual(actual, expected);
13457 QUnit.test('should accept a falsey `collection`', function(assert) {
13460 var expected = lodashStable.map(falsey, stubArray);
13462 var actual = lodashStable.map(falsey, function(collection, index) {
13464 return index ? _.map(collection) : _.map();
13468 assert.deepEqual(actual, expected);
13471 QUnit.test('should treat number values for `collection` as empty', function(assert) {
13474 assert.deepEqual(_.map(1), []);
13477 QUnit.test('should treat a nodelist as an array-like object', function(assert) {
13481 var actual = _.map(document.getElementsByTagName('body'), function(element) {
13482 return element.nodeName.toLowerCase();
13485 assert.deepEqual(actual, ['body']);
13488 skipAssert(assert);
13492 QUnit.test('should work with objects with non-number length properties', function(assert) {
13495 var value = { 'value': 'x' },
13496 object = { 'length': { 'value': 'x' } };
13498 assert.deepEqual(_.map(object, identity), [value]);
13501 QUnit.test('should return a wrapped value when chaining', function(assert) {
13505 assert.ok(_(array).map(noop) instanceof _);
13508 skipAssert(assert);
13512 QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
13517 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
13518 expected = [1, 0, _.map(array.slice(1), square)];
13520 _(array).slice(1).map(function(value, index, array) {
13521 args || (args = slice.call(arguments));
13524 assert.deepEqual(args, [1, 0, array.slice(1)]);
13527 _(array).slice(1).map(square).map(function(value, index, array) {
13528 args || (args = slice.call(arguments));
13531 assert.deepEqual(args, expected);
13534 _(array).slice(1).map(square).map(function(value, index) {
13535 args || (args = slice.call(arguments));
13538 assert.deepEqual(args, expected);
13541 _(array).slice(1).map(square).map(function(value) {
13542 args || (args = slice.call(arguments));
13545 assert.deepEqual(args, [1]);
13548 _(array).slice(1).map(square).map(function() {
13549 args || (args = slice.call(arguments));
13552 assert.deepEqual(args, expected);
13555 skipAssert(assert, 5);
13560 /*--------------------------------------------------------------------------*/
13562 QUnit.module('lodash.mapKeys');
13565 var array = [1, 2],
13566 object = { 'a': 1, 'b': 2 };
13568 QUnit.test('should map keys in `object` to a new object', function(assert) {
13571 var actual = _.mapKeys(object, String);
13572 assert.deepEqual(actual, { '1': 1, '2': 2 });
13575 QUnit.test('should treat arrays like objects', function(assert) {
13578 var actual = _.mapKeys(array, String);
13579 assert.deepEqual(actual, { '1': 1, '2': 2 });
13582 QUnit.test('should work with `_.property` shorthands', function(assert) {
13585 var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
13586 assert.deepEqual(actual, { 'c': { 'b': 'c' } });
13589 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13592 var object = { 'a': 1, 'b': 2 },
13593 values = [, null, undefined],
13594 expected = lodashStable.map(values, lodashStable.constant({ '1': 1, '2': 2 }));
13596 var actual = lodashStable.map(values, function(value, index) {
13597 return index ? _.mapKeys(object, value) : _.mapKeys(object);
13600 assert.deepEqual(actual, expected);
13604 /*--------------------------------------------------------------------------*/
13606 QUnit.module('lodash.mapValues');
13609 var array = [1, 2],
13610 object = { 'a': 1, 'b': 2 };
13612 QUnit.test('should map values in `object` to a new object', function(assert) {
13615 var actual = _.mapValues(object, String);
13616 assert.deepEqual(actual, { 'a': '1', 'b': '2' });
13619 QUnit.test('should treat arrays like objects', function(assert) {
13622 var actual = _.mapValues(array, String);
13623 assert.deepEqual(actual, { '0': '1', '1': '2' });
13626 QUnit.test('should work with `_.property` shorthands', function(assert) {
13629 var actual = _.mapValues({ 'a': { 'b': 2 } }, 'b');
13630 assert.deepEqual(actual, { 'a': 2 });
13633 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
13636 var object = { 'a': 1, 'b': 2 },
13637 values = [, null, undefined],
13638 expected = lodashStable.map(values, lodashStable.constant([true, false]));
13640 var actual = lodashStable.map(values, function(value, index) {
13641 var result = index ? _.mapValues(object, value) : _.mapValues(object);
13642 return [lodashStable.isEqual(result, object), result === object];
13645 assert.deepEqual(actual, expected);
13649 /*--------------------------------------------------------------------------*/
13651 QUnit.module('lodash.mapKeys and lodash.mapValues');
13653 lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
13654 var func = _[methodName],
13655 object = { 'a': 1, 'b': 2 };
13657 QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
13663 Foo.prototype.b = 'b';
13665 var actual = func(new Foo, function(value, key) { return key; });
13666 assert.deepEqual(actual, { 'a': 'a' });
13669 QUnit.test('`_.' + methodName + '` should accept a falsey `object`', function(assert) {
13672 var expected = lodashStable.map(falsey, stubObject);
13674 var actual = lodashStable.map(falsey, function(object, index) {
13676 return index ? func(object) : func();
13680 assert.deepEqual(actual, expected);
13683 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
13687 assert.ok(_(object)[methodName](noop) instanceof _);
13690 skipAssert(assert);
13695 QUnit.module('lodash.matches');
13698 QUnit.test('should not change behavior if `source` is modified', function(assert) {
13702 { 'a': { 'b': 2, 'c': 3 } },
13703 { 'a': 1, 'b': 2 },
13707 lodashStable.each(sources, function(source, index) {
13708 var object = lodashStable.cloneDeep(source),
13709 par = _.matches(source);
13711 assert.strictEqual(par(object), true);
13722 assert.strictEqual(par(object), true);
13723 assert.strictEqual(par(source), false);
13728 /*--------------------------------------------------------------------------*/
13730 QUnit.module('matches methods');
13732 lodashStable.each(['matches', 'isMatch'], function(methodName) {
13733 var isMatches = methodName == 'matches';
13735 function matches(source) {
13736 return isMatches ? _.matches(source) : function(object) {
13737 return _.isMatch(object, source);
13741 QUnit.test('`_.' + methodName + '` should perform a deep comparison between `source` and `object`', function(assert) {
13744 var object = { 'a': 1, 'b': 2, 'c': 3 },
13745 par = matches({ 'a': 1 });
13747 assert.strictEqual(par(object), true);
13749 par = matches({ 'b': 1 });
13750 assert.strictEqual(par(object), false);
13752 par = matches({ 'a': 1, 'c': 3 });
13753 assert.strictEqual(par(object), true);
13755 par = matches({ 'c': 3, 'd': 4 });
13756 assert.strictEqual(par(object), false);
13758 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
13759 par = matches({ 'a': { 'b': { 'c': 1 } } });
13761 assert.strictEqual(par(object), true);
13764 QUnit.test('`_.' + methodName + '` should match inherited string keyed `object` properties', function(assert) {
13770 Foo.prototype.b = 2;
13772 var object = { 'a': new Foo },
13773 par = matches({ 'a': { 'b': 2 } });
13775 assert.strictEqual(par(object), true);
13778 QUnit.test('`_.' + methodName + '` should not match by inherited `source` properties', function(assert) {
13784 Foo.prototype.b = 2;
13786 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
13788 actual = lodashStable.map(objects, matches(source)),
13789 expected = lodashStable.map(objects, stubTrue);
13791 assert.deepEqual(actual, expected);
13794 QUnit.test('`_.' + methodName + '` should compare a variety of `source` property values', function(assert) {
13797 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
13798 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
13799 par = matches(object1);
13801 assert.strictEqual(par(object1), true);
13802 assert.strictEqual(par(object2), false);
13805 QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
13808 var object1 = { 'a': -0 },
13809 object2 = { 'a': 0 },
13810 par = matches(object1);
13812 assert.strictEqual(par(object2), true);
13814 par = matches(object2);
13815 assert.strictEqual(par(object1), true);
13818 QUnit.test('`_.' + methodName + '` should compare functions by reference', function(assert) {
13821 var object1 = { 'a': lodashStable.noop },
13822 object2 = { 'a': noop },
13823 object3 = { 'a': {} },
13824 par = matches(object1);
13826 assert.strictEqual(par(object1), true);
13827 assert.strictEqual(par(object2), false);
13828 assert.strictEqual(par(object3), false);
13831 QUnit.test('`_.' + methodName + '` should work with a function for `object`', function(assert) {
13835 Foo.a = { 'b': 2, 'c': 3 };
13837 var par = matches({ 'a': { 'b': 2 } });
13838 assert.strictEqual(par(Foo), true);
13841 QUnit.test('`_.' + methodName + '` should work with a function for `source`', function(assert) {
13846 Foo.b = function() {};
13849 var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
13850 actual = lodashStable.map(objects, matches(Foo));
13852 assert.deepEqual(actual, [false, true]);
13855 QUnit.test('`_.' + methodName + '` should work with a non-plain `object`', function(assert) {
13858 function Foo(object) { lodashStable.assign(this, object); }
13860 var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) }),
13861 par = matches({ 'a': { 'b': 2 } });
13863 assert.strictEqual(par(object), true);
13866 QUnit.test('`_.' + methodName + '` should partial match arrays', function(assert) {
13869 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
13870 actual = lodashStable.filter(objects, matches({ 'a': ['d'] }));
13872 assert.deepEqual(actual, [objects[1]]);
13874 actual = lodashStable.filter(objects, matches({ 'a': ['b', 'd'] }));
13875 assert.deepEqual(actual, []);
13877 actual = lodashStable.filter(objects, matches({ 'a': ['d', 'b'] }));
13878 assert.deepEqual(actual, []);
13881 QUnit.test('`_.' + methodName + '` should partial match arrays with duplicate values', function(assert) {
13884 var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
13885 actual = lodashStable.filter(objects, matches({ 'a': [2, 2] }));
13887 assert.deepEqual(actual, [objects[1]]);
13890 QUnit.test('should partial match arrays of objects', function(assert) {
13894 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
13895 { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
13898 var actual = lodashStable.filter(objects, matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
13899 assert.deepEqual(actual, [objects[0]]);
13902 QUnit.test('`_.' + methodName + '` should partial match maps', function(assert) {
13906 var objects = [{ 'a': new Map }, { 'a': new Map }];
13907 objects[0].a.set('a', 1);
13908 objects[1].a.set('a', 1);
13909 objects[1].a.set('b', 2);
13913 var actual = lodashStable.filter(objects, matches({ 'a': map }));
13915 assert.deepEqual(actual, [objects[1]]);
13918 actual = lodashStable.filter(objects, matches({ 'a': map }));
13920 assert.deepEqual(actual, objects);
13923 actual = lodashStable.filter(objects, matches({ 'a': map }));
13925 assert.deepEqual(actual, []);
13928 skipAssert(assert, 3);
13932 QUnit.test('`_.' + methodName + '` should partial match sets', function(assert) {
13936 var objects = [{ 'a': new Set }, { 'a': new Set }];
13937 objects[0].a.add(1);
13938 objects[1].a.add(1);
13939 objects[1].a.add(2);
13943 var actual = lodashStable.filter(objects, matches({ 'a': set }));
13945 assert.deepEqual(actual, [objects[1]]);
13948 actual = lodashStable.filter(objects, matches({ 'a': set }));
13950 assert.deepEqual(actual, objects);
13953 actual = lodashStable.filter(objects, matches({ 'a': set }));
13955 assert.deepEqual(actual, []);
13958 skipAssert(assert, 3);
13962 QUnit.test('`_.' + methodName + '` should match `undefined` values', function(assert) {
13965 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
13966 actual = lodashStable.map(objects, matches({ 'b': undefined })),
13967 expected = [false, false, true];
13969 assert.deepEqual(actual, expected);
13971 actual = lodashStable.map(objects, matches({ 'a': 1, 'b': undefined }));
13973 assert.deepEqual(actual, expected);
13975 objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }];
13976 actual = lodashStable.map(objects, matches({ 'a': { 'c': undefined } }));
13978 assert.deepEqual(actual, expected);
13981 QUnit.test('`_.' + methodName + '` should match `undefined` values on primitives', function(assert) {
13985 numberProto.b = undefined;
13988 var par = matches({ 'b': undefined });
13989 assert.strictEqual(par(1), true);
13991 assert.ok(false, e.message);
13994 par = matches({ 'a': 1, 'b': undefined });
13995 assert.strictEqual(par(1), true);
13997 assert.ok(false, e.message);
13999 numberProto.a = { 'b': 1, 'c': undefined };
14001 par = matches({ 'a': { 'c': undefined } });
14002 assert.strictEqual(par(1), true);
14004 assert.ok(false, e.message);
14006 delete numberProto.a;
14007 delete numberProto.b;
14010 QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
14013 var values = [, null, undefined],
14014 expected = lodashStable.map(values, stubFalse),
14015 par = matches({ 'a': 1 });
14017 var actual = lodashStable.map(values, function(value, index) {
14019 return index ? par(value) : par();
14023 assert.deepEqual(actual, expected);
14026 QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source`', function(assert) {
14029 var object = { 'a': 1 },
14030 expected = lodashStable.map(empties, stubTrue);
14032 var actual = lodashStable.map(empties, function(value) {
14033 var par = matches(value);
14034 return par(object);
14037 assert.deepEqual(actual, expected);
14040 QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
14043 var values = [, null, undefined],
14044 expected = lodashStable.map(values, stubTrue),
14047 var actual = lodashStable.map(values, function(value, index) {
14049 return index ? par(value) : par();
14053 assert.deepEqual(actual, expected);
14056 QUnit.test('`_.' + methodName + '` should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
14059 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
14060 actual = lodashStable.filter(objects, matches({ 'a': [], 'b': {} }));
14062 assert.deepEqual(actual, objects);
14066 /*--------------------------------------------------------------------------*/
14068 QUnit.module('lodash.matchesProperty');
14071 QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
14074 var object = { 'a': 1, 'b': 2, 'c': 3 },
14075 matches = _.matchesProperty('a', 1);
14077 assert.strictEqual(matches.length, 1);
14078 assert.strictEqual(matches(object), true);
14080 matches = _.matchesProperty('b', 3);
14081 assert.strictEqual(matches(object), false);
14083 matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
14084 assert.strictEqual(matches({ 'a': object }), true);
14086 matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
14087 assert.strictEqual(matches(object), false);
14089 object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
14090 matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
14092 assert.strictEqual(matches(object), true);
14095 QUnit.test('should support deep paths', function(assert) {
14098 var object = { 'a': { 'b': 2 } };
14100 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14101 var matches = _.matchesProperty(path, 2);
14102 assert.strictEqual(matches(object), true);
14106 QUnit.test('should work with a non-string `path`', function(assert) {
14109 var array = [1, 2, 3];
14111 lodashStable.each([1, [1]], function(path) {
14112 var matches = _.matchesProperty(path, 2);
14113 assert.strictEqual(matches(array), true);
14117 QUnit.test('should preserve the sign of `0`', function(assert) {
14120 var object1 = { '-0': 'a' },
14121 object2 = { '0': 'b' },
14122 pairs = [[object1, object2], [object1, object2], [object2, object1], [object2, object1]],
14123 props = [-0, Object(-0), 0, Object(0)],
14124 values = ['a', 'a', 'b', 'b'],
14125 expected = lodashStable.map(props, lodashStable.constant([true, false]));
14127 var actual = lodashStable.map(props, function(key, index) {
14128 var matches = _.matchesProperty(key, values[index]),
14129 pair = pairs[index];
14131 return [matches(pair[0]), matches(pair[1])];
14134 assert.deepEqual(actual, expected);
14137 QUnit.test('should coerce `path` to a string', function(assert) {
14141 fn.toString = lodashStable.constant('fn');
14143 var object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
14144 paths = [null, undefined, fn, {}],
14145 expected = lodashStable.map(paths, stubTrue);
14147 lodashStable.times(2, function(index) {
14148 var actual = lodashStable.map(paths, function(path) {
14149 var matches = _.matchesProperty(index ? [path] : path, object[path]);
14150 return matches(object);
14153 assert.deepEqual(actual, expected);
14157 QUnit.test('should match a key over a path', function(assert) {
14160 var object = { 'a.b': 1, 'a': { 'b': 2 } };
14162 lodashStable.each(['a.b', ['a.b']], function(path) {
14163 var matches = _.matchesProperty(path, 1);
14164 assert.strictEqual(matches(object), true);
14168 QUnit.test('should return `false` when `object` is nullish', function(assert) {
14171 var values = [, null, undefined],
14172 expected = lodashStable.map(values, stubFalse);
14174 lodashStable.each(['constructor', ['constructor']], function(path) {
14175 var matches = _.matchesProperty(path, 1);
14177 var actual = lodashStable.map(values, function(value, index) {
14179 return index ? matches(value) : matches();
14183 assert.deepEqual(actual, expected);
14187 QUnit.test('should return `false` for deep paths when `object` is nullish', function(assert) {
14190 var values = [, null, undefined],
14191 expected = lodashStable.map(values, stubFalse);
14193 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
14194 var matches = _.matchesProperty(path, 1);
14196 var actual = lodashStable.map(values, function(value, index) {
14198 return index ? matches(value) : matches();
14202 assert.deepEqual(actual, expected);
14206 QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
14211 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
14212 var matches = _.matchesProperty(path, 1);
14213 assert.strictEqual(matches(object), false);
14217 QUnit.test('should match inherited string keyed `srcValue` properties', function(assert) {
14221 Foo.prototype.b = 2;
14223 var object = { 'a': new Foo };
14225 lodashStable.each(['a', ['a']], function(path) {
14226 var matches = _.matchesProperty(path, { 'b': 2 });
14227 assert.strictEqual(matches(object), true);
14231 QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
14237 Foo.prototype.b = 2;
14239 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
14240 expected = lodashStable.map(objects, stubTrue);
14242 lodashStable.each(['a', ['a']], function(path) {
14243 assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
14247 QUnit.test('should compare a variety of values', function(assert) {
14250 var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
14251 object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
14252 matches = _.matchesProperty('a', object1);
14254 assert.strictEqual(matches({ 'a': object1 }), true);
14255 assert.strictEqual(matches({ 'a': object2 }), false);
14258 QUnit.test('should match `-0` as `0`', function(assert) {
14261 var matches = _.matchesProperty('a', -0);
14262 assert.strictEqual(matches({ 'a': 0 }), true);
14264 matches = _.matchesProperty('a', 0);
14265 assert.strictEqual(matches({ 'a': -0 }), true);
14268 QUnit.test('should compare functions by reference', function(assert) {
14271 var object1 = { 'a': lodashStable.noop },
14272 object2 = { 'a': noop },
14273 object3 = { 'a': {} },
14274 matches = _.matchesProperty('a', object1);
14276 assert.strictEqual(matches({ 'a': object1 }), true);
14277 assert.strictEqual(matches({ 'a': object2 }), false);
14278 assert.strictEqual(matches({ 'a': object3 }), false);
14281 QUnit.test('should work with a function for `srcValue`', function(assert) {
14286 Foo.b = function() {};
14289 var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
14290 actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
14292 assert.deepEqual(actual, [false, true]);
14295 QUnit.test('should work with a non-plain `srcValue`', function(assert) {
14298 function Foo(object) { lodashStable.assign(this, object); }
14300 var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
14301 matches = _.matchesProperty('a', { 'b': 1 });
14303 assert.strictEqual(matches(object), true);
14306 QUnit.test('should partial match arrays', function(assert) {
14309 var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
14310 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
14312 assert.deepEqual(actual, [objects[1]]);
14314 actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
14315 assert.deepEqual(actual, []);
14317 actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
14318 assert.deepEqual(actual, []);
14321 QUnit.test('should partial match arrays with duplicate values', function(assert) {
14324 var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
14325 actual = lodashStable.filter(objects, _.matchesProperty('a', [2, 2]));
14327 assert.deepEqual(actual, [objects[1]]);
14330 QUnit.test('should partial match arrays of objects', function(assert) {
14334 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
14335 { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
14338 var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
14339 assert.deepEqual(actual, [objects[0]]);
14341 QUnit.test('should partial match maps', function(assert) {
14345 var objects = [{ 'a': new Map }, { 'a': new Map }];
14346 objects[0].a.set('a', 1);
14347 objects[1].a.set('a', 1);
14348 objects[1].a.set('b', 2);
14352 var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14354 assert.deepEqual(actual, [objects[1]]);
14357 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14359 assert.deepEqual(actual, objects);
14362 actual = lodashStable.filter(objects, _.matchesProperty('a', map));
14364 assert.deepEqual(actual, []);
14367 skipAssert(assert, 3);
14371 QUnit.test('should partial match sets', function(assert) {
14375 var objects = [{ 'a': new Set }, { 'a': new Set }];
14376 objects[0].a.add(1);
14377 objects[1].a.add(1);
14378 objects[1].a.add(2);
14382 var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14384 assert.deepEqual(actual, [objects[1]]);
14387 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14389 assert.deepEqual(actual, objects);
14392 actual = lodashStable.filter(objects, _.matchesProperty('a', set));
14394 assert.deepEqual(actual, []);
14397 skipAssert(assert, 3);
14401 QUnit.test('should match `undefined` values', function(assert) {
14404 var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
14405 actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
14406 expected = [false, false, true];
14408 assert.deepEqual(actual, expected);
14410 objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
14411 actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
14413 assert.deepEqual(actual, expected);
14416 QUnit.test('should match `undefined` values of nested objects', function(assert) {
14419 var object = { 'a': { 'b': undefined } };
14421 lodashStable.each(['a.b', ['a', 'b']], function(path) {
14422 var matches = _.matchesProperty(path, undefined);
14423 assert.strictEqual(matches(object), true);
14426 lodashStable.each(['a.a', ['a', 'a']], function(path) {
14427 var matches = _.matchesProperty(path, undefined);
14428 assert.strictEqual(matches(object), false);
14432 QUnit.test('should match `undefined` values on primitives', function(assert) {
14436 numberProto.b = undefined;
14439 var matches = _.matchesProperty('b', undefined);
14440 assert.strictEqual(matches(1), true);
14442 assert.ok(false, e.message);
14444 numberProto.a = { 'b': 1, 'c': undefined };
14446 matches = _.matchesProperty('a', { 'c': undefined });
14447 assert.strictEqual(matches(1), true);
14449 assert.ok(false, e.message);
14451 delete numberProto.a;
14452 delete numberProto.b;
14455 QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
14458 var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
14459 matches = _.matchesProperty('a', { 'a': [], 'b': {} });
14461 var actual = lodashStable.filter(objects, function(object) {
14462 return matches({ 'a': object });
14465 assert.deepEqual(actual, objects);
14468 QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
14471 lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
14472 var object = lodashStable.cloneDeep(source),
14473 matches = _.matchesProperty('a', source);
14475 assert.strictEqual(matches({ 'a': object }), true);
14486 assert.strictEqual(matches({ 'a': object }), true);
14487 assert.strictEqual(matches({ 'a': source }), false);
14492 /*--------------------------------------------------------------------------*/
14494 QUnit.module('lodash.max');
14497 QUnit.test('should return the largest value from a collection', function(assert) {
14500 assert.strictEqual(_.max([1, 2, 3]), 3);
14503 QUnit.test('should return `undefined` for empty collections', function(assert) {
14506 var values = falsey.concat([[]]),
14507 expected = lodashStable.map(values, noop);
14509 var actual = lodashStable.map(values, function(value, index) {
14511 return index ? _.max(value) : _.max();
14515 assert.deepEqual(actual, expected);
14518 QUnit.test('should work with non-numeric collection values', function(assert) {
14521 assert.strictEqual(_.max(['a', 'b']), 'b');
14525 /*--------------------------------------------------------------------------*/
14527 QUnit.module('lodash.mean');
14530 QUnit.test('should return the mean of an array of numbers', function(assert) {
14533 var array = [4, 2, 8, 6];
14534 assert.strictEqual(_.mean(array), 5);
14537 QUnit.test('should return `NaN` when passing empty `array` values', function(assert) {
14540 var expected = lodashStable.map(empties, stubNaN),
14541 actual = lodashStable.map(empties, _.mean);
14543 assert.deepEqual(actual, expected);
14547 /*--------------------------------------------------------------------------*/
14549 QUnit.module('lodash.meanBy');
14552 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
14554 QUnit.test('should work with an `iteratee`', function(assert) {
14557 var actual = _.meanBy(objects, function(object) {
14561 assert.deepEqual(actual, 2);
14564 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
14569 _.meanBy(objects, function() {
14570 args || (args = slice.call(arguments));
14573 assert.deepEqual(args, [{ 'a': 2 }]);
14576 QUnit.test('should work with `_.property` shorthands', function(assert) {
14579 var arrays = [[2], [3], [1]];
14580 assert.strictEqual(_.meanBy(arrays, 0), 2);
14581 assert.strictEqual(_.meanBy(objects, 'a'), 2);
14585 /*--------------------------------------------------------------------------*/
14587 QUnit.module('lodash.memoize');
14590 function CustomCache() {
14594 CustomCache.prototype = {
14595 'clear': function() {
14596 this.__data__ = [];
14599 'get': function(key) {
14600 var entry = lodashStable.find(this.__data__, ['key', key]);
14601 return entry && entry.value;
14603 'has': function(key) {
14604 return lodashStable.some(this.__data__, ['key', key]);
14606 'set': function(key, value) {
14607 this.__data__.push({ 'key': key, 'value': value });
14612 function ImmutableCache() {
14613 this.__data__ = [];
14616 ImmutableCache.prototype = lodashStable.create(CustomCache.prototype, {
14617 'constructor': ImmutableCache,
14618 'clear': function() {
14619 return new ImmutableCache;
14621 'set': function(key, value) {
14622 var result = new ImmutableCache;
14623 result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
14628 QUnit.test('should memoize results based on the first argument given', function(assert) {
14631 var memoized = _.memoize(function(a, b, c) {
14635 assert.strictEqual(memoized(1, 2, 3), 6);
14636 assert.strictEqual(memoized(1, 3, 5), 6);
14639 QUnit.test('should support a `resolver`', function(assert) {
14642 var fn = function(a, b, c) { return a + b + c; },
14643 memoized = _.memoize(fn, fn);
14645 assert.strictEqual(memoized(1, 2, 3), 6);
14646 assert.strictEqual(memoized(1, 3, 5), 9);
14649 QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
14652 var fn = function(a, b, c) { return a + this.b + this.c; },
14653 memoized = _.memoize(fn, fn);
14655 var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
14656 assert.strictEqual(object.memoized(1), 6);
14660 assert.strictEqual(object.memoized(1), 9);
14663 QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
14666 assert.raises(function() { _.memoize(noop, true); }, TypeError);
14669 QUnit.test('should not error if `resolver` is nullish', function(assert) {
14672 var values = [, null, undefined],
14673 expected = lodashStable.map(values, stubTrue);
14675 var actual = lodashStable.map(values, function(resolver, index) {
14677 return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
14681 assert.deepEqual(actual, expected);
14684 QUnit.test('should check cache for own properties', function(assert) {
14691 'propertyIsEnumerable',
14697 var memoized = _.memoize(identity);
14699 var actual = lodashStable.map(props, function(value) {
14700 return memoized(value);
14703 assert.deepEqual(actual, props);
14706 QUnit.test('should cache the `__proto__` key', function(assert) {
14712 lodashStable.times(2, function(index) {
14714 resolver = index ? identity : undefined;
14716 var memoized = _.memoize(function() {
14721 var cache = memoized.cache;
14726 assert.strictEqual(count, 1);
14727 assert.strictEqual(cache.get(key), array);
14728 assert.notOk(cache.__data__ instanceof Array);
14729 assert.strictEqual(cache.delete(key), true);
14733 QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
14736 var oldCache = _.memoize.Cache;
14737 _.memoize.Cache = CustomCache;
14739 var memoized = _.memoize(function(object) {
14743 var cache = memoized.cache,
14744 key1 = { 'id': 'a' },
14745 key2 = { 'id': 'b' };
14747 assert.strictEqual(memoized(key1), 'a');
14748 assert.strictEqual(cache.has(key1), true);
14750 assert.strictEqual(memoized(key2), 'b');
14751 assert.strictEqual(cache.has(key2), true);
14753 _.memoize.Cache = oldCache;
14756 QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
14759 var oldCache = _.memoize.Cache;
14760 _.memoize.Cache = ImmutableCache;
14762 var memoized = _.memoize(function(object) {
14766 var key1 = { 'id': 'a' },
14767 key2 = { 'id': 'b' };
14772 var cache = memoized.cache;
14773 assert.strictEqual(cache.has(key1), true);
14774 assert.strictEqual(cache.has(key2), true);
14776 _.memoize.Cache = oldCache;
14780 /*--------------------------------------------------------------------------*/
14782 QUnit.module('memoizeCapped');
14785 var func = _._memoizeCapped;
14787 QUnit.test('should enforce a max cache size of `MAX_MEMOIZE_SIZE`', function(assert) {
14791 var memoized = func(identity),
14792 cache = memoized.cache;
14794 lodashStable.times(MAX_MEMOIZE_SIZE, memoized);
14795 assert.strictEqual(cache.size, MAX_MEMOIZE_SIZE);
14797 memoized(MAX_MEMOIZE_SIZE);
14798 assert.strictEqual(cache.size, 1);
14801 skipAssert(assert, 2);
14806 /*--------------------------------------------------------------------------*/
14808 QUnit.module('lodash.merge');
14811 QUnit.test('should merge `source` into `object`', function(assert) {
14816 { 'name': 'barney' },
14830 { 'height': '5\'4"' },
14831 { 'height': '5\'5"' }
14837 { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
14838 { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
14842 assert.deepEqual(_.merge(names, ages, heights), expected);
14845 QUnit.test('should merge sources containing circular references', function(assert) {
14854 'foo': { 'b': { 'c': { 'd': {} } } },
14858 source.foo.b.c.d = source;
14859 source.bar.b = source.foo.b;
14861 var actual = _.merge(object, source);
14863 assert.notStrictEqual(actual.bar.b, actual.foo.b);
14864 assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
14867 QUnit.test('should work with four arguments', function(assert) {
14870 var expected = { 'a': 4 },
14871 actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
14873 assert.deepEqual(actual, expected);
14876 QUnit.test('should merge onto function `object` values', function(assert) {
14881 var source = { 'a': 1 },
14882 actual = _.merge(Foo, source);
14884 assert.strictEqual(actual, Foo);
14885 assert.strictEqual(Foo.a, 1);
14888 QUnit.test('should not merge onto function values of sources', function(assert) {
14891 var source1 = { 'a': function() {} },
14892 source2 = { 'a': { 'b': 2 } },
14893 actual = _.merge({}, source1, source2);
14895 assert.deepEqual(actual, { 'a': { 'b': 2 } });
14897 actual = _.merge(source1, source2);
14899 assert.strictEqual(typeof actual.a, 'function');
14900 assert.strictEqual(actual.a.b, 2);
14903 QUnit.test('should merge onto non-plain `object` values', function(assert) {
14908 var object = new Foo,
14909 actual = _.merge(object, { 'a': 1 });
14911 assert.strictEqual(actual, object);
14912 assert.strictEqual(object.a, 1);
14915 QUnit.test('should treat sparse array sources as dense', function(assert) {
14921 var actual = _.merge([], array),
14922 expected = array.slice();
14924 expected[1] = undefined;
14926 assert.ok('1' in actual);
14927 assert.deepEqual(actual, expected);
14930 QUnit.test('should merge `arguments` objects', function(assert) {
14933 var object1 = { 'value': args },
14934 object2 = { 'value': { '3': 4 } },
14935 expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
14936 actual = _.merge(object1, object2);
14938 assert.notOk('3' in args);
14939 assert.notOk(_.isArguments(actual.value));
14940 assert.deepEqual(actual.value, expected);
14941 object1.value = args;
14943 actual = _.merge(object2, object1);
14944 assert.notOk(_.isArguments(actual.value));
14945 assert.deepEqual(actual.value, expected);
14947 expected = { '0': 1, '1': 2, '2': 3 };
14949 actual = _.merge({}, object1);
14950 assert.notOk(_.isArguments(actual.value));
14951 assert.deepEqual(actual.value, expected);
14954 QUnit.test('should merge typed arrays', function(assert) {
14959 array3 = [0, 0, 0, 0],
14960 array4 = [0, 0, 0, 0, 0, 0, 0, 0];
14962 var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
14963 buffer = ArrayBuffer && new ArrayBuffer(8);
14965 var expected = lodashStable.map(typedArrays, function(type, index) {
14966 var array = arrays[index].slice();
14968 return root[type] ? { 'value': array } : false;
14971 var actual = lodashStable.map(typedArrays, function(type) {
14972 var Ctor = root[type];
14973 return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
14976 assert.ok(lodashStable.isArray(actual));
14977 assert.deepEqual(actual, expected);
14979 expected = lodashStable.map(typedArrays, function(type, index) {
14980 var array = arrays[index].slice();
14982 return root[type] ? { 'value': array } : false;
14985 actual = lodashStable.map(typedArrays, function(type, index) {
14986 var Ctor = root[type],
14987 array = lodashStable.range(arrays[index].length);
14990 return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
14993 assert.ok(lodashStable.isArray(actual));
14994 assert.deepEqual(actual, expected);
14997 QUnit.test('should assign `null` values', function(assert) {
15000 var actual = _.merge({ 'a': 1 }, { 'a': null });
15001 assert.strictEqual(actual.a, null);
15004 QUnit.test('should assign non array/buffer/typed-array/plain-object source values directly', function(assert) {
15009 var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
15010 expected = lodashStable.map(values, stubTrue);
15012 var actual = lodashStable.map(values, function(value) {
15013 var object = _.merge({}, { 'a': value, 'b': { 'c': value } });
15014 return object.a === value && object.b.c === value;
15017 assert.deepEqual(actual, expected);
15020 QUnit.test('should clone buffer source values', function(assert) {
15024 var buffer = new Buffer([1]),
15025 actual = _.merge({}, { 'value': buffer }).value;
15027 assert.ok(lodashStable.isBuffer(actual));
15028 assert.strictEqual(actual[0], buffer[0]);
15029 assert.notStrictEqual(actual, buffer);
15032 skipAssert(assert, 3);
15036 QUnit.test('should deep clone array/typed-array/plain-object source values', function(assert) {
15039 var typedArray = Uint8Array
15040 ? new Uint8Array([1])
15041 : { 'buffer': [1] };
15043 var props = ['0', 'buffer', 'a'],
15044 values = [[{ 'a': 1 }], typedArray, { 'a': [1] }],
15045 expected = lodashStable.map(values, stubTrue);
15047 var actual = lodashStable.map(values, function(value, index) {
15048 var key = props[index],
15049 object = _.merge({}, { 'value': value }),
15050 subValue = value[key],
15051 newValue = object.value,
15052 newSubValue = newValue[key];
15055 newValue !== value &&
15056 newSubValue !== subValue &&
15057 lodashStable.isEqual(newValue, value)
15061 assert.deepEqual(actual, expected);
15064 QUnit.test('should not augment source objects', function(assert) {
15067 var source1 = { 'a': [{ 'a': 1 }] },
15068 source2 = { 'a': [{ 'b': 2 }] },
15069 actual = _.merge({}, source1, source2);
15071 assert.deepEqual(source1.a, [{ 'a': 1 }]);
15072 assert.deepEqual(source2.a, [{ 'b': 2 }]);
15073 assert.deepEqual(actual.a, [{ 'a': 1, 'b': 2 }]);
15075 var source1 = { 'a': [[1, 2, 3]] },
15076 source2 = { 'a': [[3, 4]] },
15077 actual = _.merge({}, source1, source2);
15079 assert.deepEqual(source1.a, [[1, 2, 3]]);
15080 assert.deepEqual(source2.a, [[3, 4]]);
15081 assert.deepEqual(actual.a, [[3, 4, 3]]);
15084 QUnit.test('should merge plain objects onto non-plain objects', function(assert) {
15087 function Foo(object) {
15088 lodashStable.assign(this, object);
15091 var object = { 'a': 1 },
15092 actual = _.merge(new Foo, object);
15094 assert.ok(actual instanceof Foo);
15095 assert.deepEqual(actual, new Foo(object));
15097 actual = _.merge([new Foo], [object]);
15098 assert.ok(actual[0] instanceof Foo);
15099 assert.deepEqual(actual, [new Foo(object)]);
15102 QUnit.test('should not overwrite existing values with `undefined` values of object sources', function(assert) {
15105 var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
15106 assert.deepEqual(actual, { 'a': 1, 'b': undefined });
15109 QUnit.test('should not overwrite existing values with `undefined` values of array sources', function(assert) {
15115 var actual = _.merge([4, 5, 6], array),
15116 expected = [1, 5, 3];
15118 assert.deepEqual(actual, expected);
15121 array[1] = undefined;
15123 actual = _.merge([4, 5, 6], array);
15124 assert.deepEqual(actual, expected);
15127 QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
15133 defineProperty(object, 'a', {
15134 'configurable': true,
15135 'enumerable': true,
15136 'get': function() { pass = false; },
15137 'set': function() { pass = false; }
15140 _.merge(object, object);
15144 QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
15147 var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
15148 actual = _.merge(object, { 'a': ['x'] });
15150 assert.deepEqual(actual, { 'a': ['x', 'y'] });
15152 actual = _.merge({ 'a': {} }, { 'a': [] });
15153 assert.deepEqual(actual, { 'a': [] });
15156 QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
15159 var object = { 'a': 'abcde' },
15160 actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
15162 assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
15165 QUnit.test('should not error on DOM elements', function(assert) {
15168 var object1 = { 'el': document && document.createElement('div') },
15169 object2 = { 'el': document && document.createElement('div') },
15170 pairs = [[{}, object1], [object1, object2]],
15171 expected = lodashStable.map(pairs, stubTrue);
15173 var actual = lodashStable.map(pairs, function(pair) {
15175 return _.merge(pair[0], pair[1]).el === pair[1].el;
15179 assert.deepEqual(actual, expected);
15183 /*--------------------------------------------------------------------------*/
15185 QUnit.module('lodash.mergeWith');
15188 QUnit.test('should handle merging when `customizer` returns `undefined`', function(assert) {
15191 var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
15192 assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
15194 actual = _.mergeWith([], [undefined], identity);
15195 assert.deepEqual(actual, [undefined]);
15198 QUnit.test('should clone sources when `customizer` returns `undefined`', function(assert) {
15201 var source1 = { 'a': { 'b': { 'c': 1 } } },
15202 source2 = { 'a': { 'b': { 'd': 2 } } };
15204 _.mergeWith({}, source1, source2, noop);
15205 assert.deepEqual(source1.a.b, { 'c': 1 });
15208 QUnit.test('should defer to `customizer` for non `undefined` results', function(assert) {
15211 var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
15212 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15215 assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
15218 QUnit.test('should provide `stack` to `customizer`', function(assert) {
15223 _.mergeWith({}, { 'a': { 'b': 2 } }, function() {
15224 actual = _.last(arguments);
15228 ? actual.constructor.name == 'Stack'
15229 : actual instanceof mapCaches.Stack
15233 QUnit.test('should overwrite primitives with source object clones', function(assert) {
15236 var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) {
15237 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15240 assert.deepEqual(actual, { 'a': { 'b': ['c'] } });
15243 QUnit.test('should pop the stack of sources for each sibling property', function(assert) {
15246 var array = ['b', 'c'],
15247 object = { 'a': ['a'] },
15248 source = { 'a': array, 'b': array };
15250 var actual = _.mergeWith(object, source, function(a, b) {
15251 return lodashStable.isArray(a) ? a.concat(b) : undefined;
15254 assert.deepEqual(actual, { 'a': ['a', 'b', 'c'], 'b': ['b', 'c'] });
15258 /*--------------------------------------------------------------------------*/
15260 QUnit.module('lodash.method');
15263 QUnit.test('should create a function that calls a method of a given object', function(assert) {
15266 var object = { 'a': stubOne };
15268 lodashStable.each(['a', ['a']], function(path) {
15269 var method = _.method(path);
15270 assert.strictEqual(method.length, 1);
15271 assert.strictEqual(method(object), 1);
15275 QUnit.test('should work with deep property values', function(assert) {
15278 var object = { 'a': { 'b': stubTwo } };
15280 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15281 var method = _.method(path);
15282 assert.strictEqual(method(object), 2);
15286 QUnit.test('should work with a non-string `path`', function(assert) {
15289 var array = lodashStable.times(3, _.constant);
15291 lodashStable.each([1, [1]], function(path) {
15292 var method = _.method(path);
15293 assert.strictEqual(method(array), 1);
15297 QUnit.test('should coerce `path` to a string', function(assert) {
15301 fn.toString = lodashStable.constant('fn');
15303 var expected = [1, 2, 3, 4],
15304 object = { 'null': stubOne, 'undefined': stubTwo, 'fn': stubThree, '[object Object]': stubFour },
15305 paths = [null, undefined, fn, {}];
15307 lodashStable.times(2, function(index) {
15308 var actual = lodashStable.map(paths, function(path) {
15309 var method = _.method(index ? [path] : path);
15310 return method(object);
15313 assert.deepEqual(actual, expected);
15317 QUnit.test('should work with inherited property values', function(assert) {
15321 Foo.prototype.a = stubOne;
15323 lodashStable.each(['a', ['a']], function(path) {
15324 var method = _.method(path);
15325 assert.strictEqual(method(new Foo), 1);
15329 QUnit.test('should use a key over a path', function(assert) {
15332 var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
15334 lodashStable.each(['a.b', ['a.b']], function(path) {
15335 var method = _.method(path);
15336 assert.strictEqual(method(object), 1);
15340 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15343 var values = [, null, undefined],
15344 expected = lodashStable.map(values, noop);
15346 lodashStable.each(['constructor', ['constructor']], function(path) {
15347 var method = _.method(path);
15349 var actual = lodashStable.map(values, function(value, index) {
15350 return index ? method(value) : method();
15353 assert.deepEqual(actual, expected);
15357 QUnit.test('should return `undefined` for deep paths when `object` is nullish', function(assert) {
15360 var values = [, null, undefined],
15361 expected = lodashStable.map(values, noop);
15363 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15364 var method = _.method(path);
15366 var actual = lodashStable.map(values, function(value, index) {
15367 return index ? method(value) : method();
15370 assert.deepEqual(actual, expected);
15374 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15379 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15380 var method = _.method(path);
15381 assert.strictEqual(method(object), undefined);
15385 QUnit.test('should apply partial arguments to function', function(assert) {
15390 return slice.call(arguments);
15394 lodashStable.each(['fn', ['fn']], function(path) {
15395 var method = _.method(path, 1, 2, 3);
15396 assert.deepEqual(method(object), [1, 2, 3]);
15400 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15403 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
15405 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15406 var method = _.method(path);
15407 assert.strictEqual(method(object), 1);
15412 /*--------------------------------------------------------------------------*/
15414 QUnit.module('lodash.methodOf');
15417 QUnit.test('should create a function that calls a method of a given key', function(assert) {
15420 var object = { 'a': stubOne };
15422 lodashStable.each(['a', ['a']], function(path) {
15423 var methodOf = _.methodOf(object);
15424 assert.strictEqual(methodOf.length, 1);
15425 assert.strictEqual(methodOf(path), 1);
15429 QUnit.test('should work with deep property values', function(assert) {
15432 var object = { 'a': { 'b': stubTwo } };
15434 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15435 var methodOf = _.methodOf(object);
15436 assert.strictEqual(methodOf(path), 2);
15440 QUnit.test('should work with a non-string `path`', function(assert) {
15443 var array = lodashStable.times(3, _.constant);
15445 lodashStable.each([1, [1]], function(path) {
15446 var methodOf = _.methodOf(array);
15447 assert.strictEqual(methodOf(path), 1);
15451 QUnit.test('should coerce `path` to a string', function(assert) {
15455 fn.toString = lodashStable.constant('fn');
15457 var expected = [1, 2, 3, 4],
15458 object = { 'null': stubOne, 'undefined': stubTwo, 'fn': stubThree, '[object Object]': stubFour },
15459 paths = [null, undefined, fn, {}];
15461 lodashStable.times(2, function(index) {
15462 var actual = lodashStable.map(paths, function(path) {
15463 var methodOf = _.methodOf(object);
15464 return methodOf(index ? [path] : path);
15467 assert.deepEqual(actual, expected);
15471 QUnit.test('should work with inherited property values', function(assert) {
15475 Foo.prototype.a = stubOne;
15477 lodashStable.each(['a', ['a']], function(path) {
15478 var methodOf = _.methodOf(new Foo);
15479 assert.strictEqual(methodOf(path), 1);
15483 QUnit.test('should use a key over a path', function(assert) {
15486 var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
15488 lodashStable.each(['a.b', ['a.b']], function(path) {
15489 var methodOf = _.methodOf(object);
15490 assert.strictEqual(methodOf(path), 1);
15494 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
15497 var values = [, null, undefined],
15498 expected = lodashStable.map(values, noop);
15500 lodashStable.each(['constructor', ['constructor']], function(path) {
15501 var actual = lodashStable.map(values, function(value, index) {
15502 var methodOf = index ? _.methodOf() : _.methodOf(value);
15503 return methodOf(path);
15506 assert.deepEqual(actual, expected);
15510 QUnit.test('should return `undefined` for deep paths when `object` is nullish', function(assert) {
15513 var values = [, null, undefined],
15514 expected = lodashStable.map(values, noop);
15516 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
15517 var actual = lodashStable.map(values, function(value, index) {
15518 var methodOf = index ? _.methodOf() : _.methodOf(value);
15519 return methodOf(path);
15522 assert.deepEqual(actual, expected);
15526 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
15530 methodOf = _.methodOf(object);
15532 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
15533 assert.strictEqual(methodOf(path), undefined);
15537 QUnit.test('should apply partial arguments to function', function(assert) {
15542 return slice.call(arguments);
15546 var methodOf = _.methodOf(object, 1, 2, 3);
15548 lodashStable.each(['fn', ['fn']], function(path) {
15549 assert.deepEqual(methodOf(path), [1, 2, 3]);
15553 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
15556 var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
15557 methodOf = _.methodOf(object);
15559 lodashStable.each(['a.b', ['a', 'b']], function(path) {
15560 assert.strictEqual(methodOf(path), 1);
15565 /*--------------------------------------------------------------------------*/
15567 QUnit.module('lodash.min');
15570 QUnit.test('should return the smallest value from a collection', function(assert) {
15573 assert.strictEqual(_.min([1, 2, 3]), 1);
15576 QUnit.test('should return `undefined` for empty collections', function(assert) {
15579 var values = falsey.concat([[]]),
15580 expected = lodashStable.map(values, noop);
15582 var actual = lodashStable.map(values, function(value, index) {
15584 return index ? _.min(value) : _.min();
15588 assert.deepEqual(actual, expected);
15591 QUnit.test('should work with non-numeric collection values', function(assert) {
15594 assert.strictEqual(_.min(['a', 'b']), 'a');
15598 /*--------------------------------------------------------------------------*/
15600 QUnit.module('extremum methods');
15602 lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
15603 var func = _[methodName],
15604 isMax = /^max/.test(methodName);
15606 QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
15609 var curr = new Date,
15610 past = new Date(0);
15612 assert.strictEqual(func([curr, past]), isMax ? curr : past);
15615 QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
15618 var array = lodashStable.range(0, 5e5);
15619 assert.strictEqual(func(array), isMax ? 499999 : 0);
15622 QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
15626 var actual = _([40])[methodName]();
15627 assert.strictEqual(actual, 40);
15630 skipAssert(assert);
15635 lodashStable.each(['maxBy', 'minBy'], function(methodName) {
15636 var array = [1, 2, 3],
15637 func = _[methodName],
15638 isMax = methodName == 'maxBy';
15640 QUnit.test('`_.' + methodName + '` should work with an `iteratee`', function(assert) {
15643 var actual = func(array, function(n) {
15647 assert.strictEqual(actual, isMax ? 1 : 3);
15650 QUnit.test('should work with `_.property` shorthands', function(assert) {
15653 var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
15654 actual = func(objects, 'a');
15656 assert.deepEqual(actual, objects[isMax ? 1 : 2]);
15658 var arrays = [[2], [3], [1]];
15659 actual = func(arrays, 0);
15661 assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
15664 QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
15667 var value = isMax ? -Infinity : Infinity,
15668 object = { 'a': value };
15670 var actual = func([object, { 'a': value }], function(object) {
15674 assert.strictEqual(actual, object);
15678 /*--------------------------------------------------------------------------*/
15680 QUnit.module('lodash.mixin');
15683 function reset(wrapper) {
15685 delete wrapper.prototype.a;
15687 delete wrapper.prototype.b;
15690 function Wrapper(value) {
15691 if (!(this instanceof Wrapper)) {
15692 return new Wrapper(value);
15694 if (_.has(value, '__wrapped__')) {
15695 var actions = slice.call(value.__actions__),
15696 chain = value.__chain__;
15698 value = value.__wrapped__;
15700 this.__wrapped__ = value;
15701 this.__actions__ = actions || [];
15702 this.__chain__ = chain || false;
15705 Wrapper.prototype.value = function() {
15706 return getUnwrappedValue(this);
15710 source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
15712 QUnit.test('should mixin `source` methods into lodash', function(assert) {
15718 assert.strictEqual(_.a(array), 'a');
15719 assert.strictEqual(_(array).a().value(), 'a');
15720 assert.notOk('b' in _);
15721 assert.notOk('b' in _.prototype);
15726 skipAssert(assert, 4);
15730 QUnit.test('should mixin chaining methods by reference', function(assert) {
15737 assert.strictEqual(_.a(array), 'b');
15738 assert.strictEqual(_(array).a().value(), 'a');
15743 skipAssert(assert, 2);
15747 QUnit.test('should use a default `object` of `this`', function(assert) {
15750 var object = lodashStable.create(_);
15751 object.mixin(source);
15753 assert.strictEqual(object.a(array), 'a');
15754 assert.notOk('a' in _);
15755 assert.notOk('a' in _.prototype);
15760 QUnit.test('should accept an `object`', function(assert) {
15764 _.mixin(object, source);
15765 assert.strictEqual(object.a(array), 'a');
15768 QUnit.test('should accept a function `object`', function(assert) {
15771 _.mixin(Wrapper, source);
15773 var wrapped = Wrapper(array),
15774 actual = wrapped.a();
15776 assert.strictEqual(actual.value(), 'a');
15777 assert.ok(actual instanceof Wrapper);
15782 QUnit.test('should return `object`', function(assert) {
15786 assert.strictEqual(_.mixin(object, source), object);
15787 assert.strictEqual(_.mixin(Wrapper, source), Wrapper);
15788 assert.strictEqual(_.mixin(), _);
15793 QUnit.test('should not assign inherited `source` methods', function(assert) {
15797 Foo.prototype.a = noop;
15800 assert.strictEqual(_.mixin(object, new Foo), object);
15803 QUnit.test('should accept an `options`', function(assert) {
15806 function message(func, chain) {
15807 return (func === _ ? 'lodash' : 'given') + ' function should ' + (chain ? '' : 'not ') + 'chain';
15810 lodashStable.each([_, Wrapper], function(func) {
15811 lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
15814 _.mixin(source, options);
15816 _.mixin(func, source, options);
15818 var wrapped = func(array),
15819 actual = wrapped.a();
15821 if (options.chain) {
15822 assert.strictEqual(actual.value(), 'a', message(func, true));
15823 assert.ok(actual instanceof func, message(func, true));
15825 assert.strictEqual(actual, 'a', message(func, false));
15826 assert.notOk(actual instanceof func, message(func, false));
15831 skipAssert(assert, 2);
15837 QUnit.test('should not extend lodash when an `object` is given with an empty `options` object', function(assert) {
15840 _.mixin({ 'a': noop }, {});
15841 assert.notOk('a' in _);
15845 QUnit.test('should not error for non-object `options` values', function(assert) {
15851 _.mixin({}, source, 1);
15860 _.mixin(source, 1);
15869 QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
15872 lodashStable.each([_, Wrapper], function(func) {
15875 var wrapped = _(source),
15876 actual = wrapped.mixin();
15878 assert.strictEqual(actual.value(), _);
15882 actual = wrapped.mixin(source);
15883 assert.notStrictEqual(actual, wrapped);
15888 skipAssert(assert);
15893 QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
15897 _.mixin({ 'a': _.countBy, 'b': _.filter });
15899 var array = lodashStable.range(LARGE_ARRAY_SIZE),
15900 actual = _(array).a().map(square).b(isEven).take().value();
15902 assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
15907 skipAssert(assert);
15912 /*--------------------------------------------------------------------------*/
15914 QUnit.module('lodash.multiply');
15917 QUnit.test('should multiply two numbers', function(assert) {
15920 assert.strictEqual(_.multiply(6, 4), 24);
15921 assert.strictEqual(_.multiply(-6, 4), -24);
15922 assert.strictEqual(_.multiply(-6, -4), 24);
15925 QUnit.test('should coerce arguments to numbers', function(assert) {
15928 assert.strictEqual(_.multiply('6', '4'), 24);
15929 assert.deepEqual(_.multiply('x', 'y'), NaN);
15933 /*--------------------------------------------------------------------------*/
15935 QUnit.module('lodash.orderBy');
15939 { 'a': 'x', 'b': 3 },
15940 { 'a': 'y', 'b': 4 },
15941 { 'a': 'x', 'b': 1 },
15942 { 'a': 'y', 'b': 2 }
15945 QUnit.test('should sort by a single property by a specified order', function(assert) {
15948 var actual = _.orderBy(objects, 'a', 'desc');
15949 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15952 QUnit.test('should sort by multiple properties by specified orders', function(assert) {
15955 var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
15956 assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
15959 QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
15962 var expected = [objects[2], objects[0], objects[3], objects[1]],
15963 actual = _.orderBy(objects, ['a', 'b']);
15965 assert.deepEqual(actual, expected);
15967 expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
15969 actual = lodashStable.map(falsey, function(order, index) {
15970 return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
15973 assert.deepEqual(actual, expected);
15976 QUnit.test('should work with `orders` specified as string objects', function(assert) {
15979 var actual = _.orderBy(objects, ['a'], [Object('desc')]);
15980 assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
15984 /*--------------------------------------------------------------------------*/
15986 QUnit.module('lodash.overArgs');
15990 return slice.call(arguments);
15993 QUnit.test('should transform each argument', function(assert) {
15996 var over = _.overArgs(fn, doubled, square);
15997 assert.deepEqual(over(5, 10), [10, 100]);
16000 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16003 var over = _.overArgs(fn, undefined, null);
16004 assert.deepEqual(over('a', 'b'), ['a', 'b']);
16007 QUnit.test('should work with `_.property` shorthands', function(assert) {
16010 var over = _.overArgs(fn, 'b', 'a');
16011 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [2, 1]);
16014 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16017 var over = _.overArgs(fn, { 'b': 1 }, { 'a': 1 });
16018 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
16021 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16024 var over = _.overArgs(fn, [['b', 1], ['a', 1]]);
16025 assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
16028 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16031 var over = _.overArgs(fn, ['a', 1]);
16032 assert.deepEqual(over({ 'a': 1 }, { '1': 2 }), [1, 2]);
16034 over = _.overArgs(fn, [['a', 1]]);
16035 assert.deepEqual(over({ 'a': 1 }), [true]);
16038 QUnit.test('should flatten `transforms`', function(assert) {
16041 var over = _.overArgs(fn, [doubled, square], String);
16042 assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
16045 QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
16048 var over = _.overArgs(fn, doubled, square);
16049 assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
16052 QUnit.test('should not transform any arguments if no transforms are given', function(assert) {
16055 var over = _.overArgs(fn);
16056 assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
16059 QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
16062 var over = _.overArgs(fn, doubled, identity);
16063 assert.deepEqual(over(5), [10]);
16066 QUnit.test('should provide the correct argument to each transform', function(assert) {
16070 transform = function() { argsList.push(slice.call(arguments)); },
16071 over = _.overArgs(noop, transform, transform, transform);
16074 assert.deepEqual(argsList, [['a'], ['b']]);
16077 QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
16080 var over = _.overArgs(function(x) {
16086 var object = { 'over': over, 'true': 1 };
16087 assert.strictEqual(object.over(object), 1);
16091 /*--------------------------------------------------------------------------*/
16093 QUnit.module('lodash.negate');
16096 QUnit.test('should create a function that negates the result of `func`', function(assert) {
16099 var negate = _.negate(isEven);
16101 assert.strictEqual(negate(1), true);
16102 assert.strictEqual(negate(2), false);
16105 QUnit.test('should create a function that negates the result of `func`', function(assert) {
16108 var negate = _.negate(isEven);
16110 assert.strictEqual(negate(1), true);
16111 assert.strictEqual(negate(2), false);
16114 QUnit.test('should create a function that accepts multiple arguments', function(assert) {
16119 negate = _.negate(function() { argCount = arguments.length; }),
16120 expected = lodashStable.times(count, stubTrue);
16122 var actual = lodashStable.times(count, function(index) {
16124 case 0: negate(); break;
16125 case 1: negate(1); break;
16126 case 2: negate(1, 2); break;
16127 case 3: negate(1, 2, 3); break;
16128 case 4: negate(1, 2, 3, 4);
16130 return argCount == index;
16133 assert.deepEqual(actual, expected);
16137 /*--------------------------------------------------------------------------*/
16139 QUnit.module('lodash.noConflict');
16142 QUnit.test('should return the `lodash` function', function(assert) {
16145 if (!isModularize) {
16146 assert.strictEqual(_.noConflict(), oldDash);
16147 assert.notStrictEqual(root._, oldDash);
16151 skipAssert(assert, 2);
16155 QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) {
16158 if (!isModularize) {
16159 var object = root._ = {};
16160 assert.strictEqual(_.noConflict(), oldDash);
16161 assert.strictEqual(root._, object);
16165 skipAssert(assert, 2);
16169 QUnit.test('should work with a `root` of `this`', function(assert) {
16172 if (!coverage && !document && !isModularize && realm.object) {
16173 var fs = require('fs'),
16174 vm = require('vm'),
16176 context = vm.createContext({ '_': expected, 'console': console }),
16177 source = fs.readFileSync(filePath, 'utf8');
16179 vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
16181 assert.strictEqual(context._, expected);
16182 assert.ok(context.lodash);
16185 skipAssert(assert, 2);
16190 /*--------------------------------------------------------------------------*/
16192 QUnit.module('lodash.now');
16195 QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
16198 var done = assert.async();
16200 var stamp = +new Date,
16203 assert.ok(actual >= stamp);
16205 setTimeout(function() {
16206 assert.ok(_.now() > actual);
16211 QUnit.test('should work with mocked `Date.now`', function(assert) {
16214 var now = Date.now;
16217 var actual = _.now();
16220 assert.strictEqual(actual, 'a');
16224 /*--------------------------------------------------------------------------*/
16226 QUnit.module('lodash.nth');
16229 var array = ['a', 'b', 'c', 'd'];
16231 QUnit.test('should get the nth element of `array`', function(assert) {
16234 var actual = lodashStable.map(array, function(value, index) {
16235 return _.nth(array, index);
16238 assert.deepEqual(actual, array);
16241 QUnit.test('should work with a negative `n`', function(assert) {
16244 var actual = lodashStable.map(lodashStable.range(1, array.length + 1), function(n) {
16245 return _.nth(array, -n);
16248 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16251 QUnit.test('should coerce `n` to an integer', function(assert) {
16254 var values = falsey,
16255 expected = lodashStable.map(values, stubA);
16257 var actual = lodashStable.map(values, function(n) {
16258 return n ? _.nth(array, n) : _.nth(array);
16261 assert.deepEqual(actual, expected);
16263 values = ['1', 1.6];
16264 expected = lodashStable.map(values, stubB);
16266 actual = lodashStable.map(values, function(n) {
16267 return _.nth(array, n);
16270 assert.deepEqual(actual, expected);
16273 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16276 var values = [null, undefined, []],
16277 expected = lodashStable.map(values, noop);
16279 var actual = lodashStable.map(values, function(array) {
16280 return _.nth(array, 1);
16283 assert.deepEqual(actual, expected);
16286 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16289 var array = [1, 2],
16290 values = [Infinity, array.length],
16291 expected = lodashStable.map(values, noop);
16295 var actual = lodashStable.map(values, function(n) {
16296 return _.nth(array, n);
16299 assert.deepEqual(actual, expected);
16303 /*--------------------------------------------------------------------------*/
16305 QUnit.module('lodash.nthArg');
16308 var args = ['a', 'b', 'c', 'd'];
16310 QUnit.test('should create a function that returns its nth argument', function(assert) {
16313 var actual = lodashStable.map(args, function(value, index) {
16314 var func = _.nthArg(index);
16315 return func.apply(undefined, args);
16318 assert.deepEqual(actual, args);
16321 QUnit.test('should work with a negative `n`', function(assert) {
16324 var actual = lodashStable.map(lodashStable.range(1, args.length + 1), function(n) {
16325 var func = _.nthArg(-n);
16326 return func.apply(undefined, args);
16329 assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
16332 QUnit.test('should coerce `n` to an integer', function(assert) {
16335 var values = falsey,
16336 expected = lodashStable.map(values, stubA);
16338 var actual = lodashStable.map(values, function(n) {
16339 var func = n ? _.nthArg(n) : _.nthArg();
16340 return func.apply(undefined, args);
16343 assert.deepEqual(actual, expected);
16345 values = ['1', 1.6];
16346 expected = lodashStable.map(values, stubB);
16348 actual = lodashStable.map(values, function(n) {
16349 var func = _.nthArg(n);
16350 return func.apply(undefined, args);
16353 assert.deepEqual(actual, expected);
16356 QUnit.test('should return `undefined` for empty arrays', function(assert) {
16359 var func = _.nthArg(1);
16360 assert.strictEqual(func(), undefined);
16363 QUnit.test('should return `undefined` for non-indexes', function(assert) {
16366 var values = [Infinity, args.length],
16367 expected = lodashStable.map(values, noop);
16369 var actual = lodashStable.map(values, function(n) {
16370 var func = _.nthArg(n);
16371 return func.apply(undefined, args);
16374 assert.deepEqual(actual, expected);
16378 /*--------------------------------------------------------------------------*/
16380 QUnit.module('lodash.omit');
16383 var args = toArgs(['a', 'c']),
16384 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
16385 nested = { 'a': 1, 'b': { 'c': 2, 'd': 3 } };
16387 QUnit.test('should flatten `paths`', function(assert) {
16390 assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
16391 assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
16394 QUnit.test('should support deep paths', function(assert) {
16397 assert.deepEqual(_.omit(nested, 'b.c'), { 'a': 1, 'b': { 'd': 3} });
16400 QUnit.test('should support path arrays', function(assert) {
16403 var object = { 'a.b': 1, 'a': { 'b': 2 } },
16404 actual = _.omit(object, [['a.b']]);
16406 assert.deepEqual(actual, { 'a': { 'b': 2 } });
16409 QUnit.test('should omit a key over a path', function(assert) {
16412 var object = { 'a.b': 1, 'a': { 'b': 2 } };
16414 lodashStable.each(['a.b', ['a.b']], function(path) {
16415 assert.deepEqual(_.omit(object, path), { 'a': { 'b': 2 } });
16419 QUnit.test('should coerce `paths` to strings', function(assert) {
16422 assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
16425 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
16428 lodashStable.each([null, undefined], function(value) {
16430 var actual = _.omit(value, 'valueOf');
16431 delete objectProto.a;
16432 assert.deepEqual(actual, {});
16436 QUnit.test('should work with a primitive `object`', function(assert) {
16442 assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
16444 delete stringProto.a;
16445 delete stringProto.b;
16448 QUnit.test('should work with `arguments` object `paths`', function(assert) {
16451 assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
16454 QUnit.test('should not mutate `object`', function(assert) {
16457 lodashStable.each(['a', ['a'], 'a.b', ['a.b']], function(path) {
16458 var object = { 'a': { 'b': 2 } };
16459 _.omit(object, path);
16460 assert.deepEqual(object, { 'a': { 'b': 2 } });
16465 /*--------------------------------------------------------------------------*/
16467 QUnit.module('lodash.omitBy');
16470 QUnit.test('should work with a predicate argument', function(assert) {
16473 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
16475 var actual = _.omitBy(object, function(n) {
16476 return n != 2 && n != 4;
16479 assert.deepEqual(actual, { 'b': 2, 'd': 4 });
16483 /*--------------------------------------------------------------------------*/
16485 QUnit.module('omit methods');
16487 lodashStable.each(['omit', 'omitBy'], function(methodName) {
16488 var expected = { 'b': 2, 'd': 4 },
16489 func = _[methodName],
16490 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
16491 resolve = lodashStable.nthArg(1);
16493 if (methodName == 'omitBy') {
16494 resolve = function(object, props) {
16495 props = lodashStable.castArray(props);
16496 return function(value) {
16497 return lodashStable.some(props, function(key) {
16498 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
16499 return object[key] === value;
16504 QUnit.test('`_.' + methodName + '` should create an object with omitted string keyed properties', function(assert) {
16507 assert.deepEqual(func(object, resolve(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
16508 assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
16511 QUnit.test('`_.' + methodName + '` should include inherited string keyed properties', function(assert) {
16515 Foo.prototype = object;
16517 assert.deepEqual(func(new Foo, resolve(object, ['a', 'c'])), expected);
16520 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
16523 var object = { '-0': 'a', '0': 'b' },
16524 props = [-0, Object(-0), 0, Object(0)],
16525 expected = [{ '0': 'b' }, { '0': 'b' }, { '-0': 'a' }, { '-0': 'a' }];
16527 var actual = lodashStable.map(props, function(key) {
16528 return func(object, resolve(object, key));
16531 assert.deepEqual(actual, expected);
16534 QUnit.test('`_.' + methodName + '` should include symbols', function(assert) {
16543 var symbol2 = Symbol('b');
16544 Foo.prototype[symbol2] = 2;
16546 var symbol3 = Symbol('c');
16547 defineProperty(Foo.prototype, symbol3, {
16548 'configurable': true,
16549 'enumerable': false,
16555 actual = func(foo, resolve(foo, 'a'));
16557 assert.strictEqual(actual[symbol], 1);
16558 assert.strictEqual(actual[symbol2], 2);
16559 assert.notOk(symbol3 in actual);
16562 skipAssert(assert, 3);
16566 QUnit.test('`_.' + methodName + '` should create an object with omitted symbols', function(assert) {
16575 var symbol2 = Symbol('b');
16576 Foo.prototype[symbol2] = 2;
16578 var symbol3 = Symbol('c');
16579 defineProperty(Foo.prototype, symbol3, {
16580 'configurable': true,
16581 'enumerable': false,
16587 actual = func(foo, resolve(foo, symbol));
16589 assert.strictEqual(actual.a, 0);
16590 assert.notOk(symbol in actual);
16591 assert.strictEqual(actual[symbol2], 2);
16592 assert.notOk(symbol3 in actual);
16594 actual = func(foo, resolve(foo, symbol2));
16596 assert.strictEqual(actual.a, 0);
16597 assert.strictEqual(actual[symbol], 1);
16598 assert.notOk(symbol2 in actual);
16599 assert.notOk(symbol3 in actual);
16602 skipAssert(assert, 8);
16606 QUnit.test('`_.' + methodName + '` should work with an array `object`', function(assert) {
16609 var array = [1, 2, 3];
16610 assert.deepEqual(func(array, resolve(array, ['0', '2'])), { '1': 2 });
16614 /*--------------------------------------------------------------------------*/
16616 QUnit.module('lodash.once');
16619 QUnit.test('should invoke `func` once', function(assert) {
16623 once = _.once(function() { return ++count; });
16626 assert.strictEqual(once(), 1);
16627 assert.strictEqual(count, 1);
16630 QUnit.test('should ignore recursive calls', function(assert) {
16635 var once = _.once(function() {
16640 assert.strictEqual(once(), 1);
16641 assert.strictEqual(count, 1);
16644 QUnit.test('should not throw more than once', function(assert) {
16647 var once = _.once(function() {
16651 assert.raises(once);
16658 /*--------------------------------------------------------------------------*/
16660 QUnit.module('lodash.over');
16663 QUnit.test('should create a function that invokes `iteratees`', function(assert) {
16666 var over = _.over(Math.max, Math.min);
16667 assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
16670 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16673 var over = _.over(undefined, null);
16674 assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
16677 QUnit.test('should work with `_.property` shorthands', function(assert) {
16680 var over = _.over('b', 'a');
16681 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [2, 1]);
16684 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16687 var over = _.over({ 'b': 1 }, { 'a': 1 });
16688 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [false, true]);
16691 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16694 var over = _.over([['b', 2], ['a', 2]]);
16696 assert.deepEqual(over({ 'a': 1, 'b': 2 }), [true, false]);
16697 assert.deepEqual(over({ 'a': 2, 'b': 1 }), [false, true]);
16700 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16703 var over = _.over(['a', 1]);
16705 assert.deepEqual(over({ 'a': 1, '1': 2 }), [1, 2]);
16706 assert.deepEqual(over({ 'a': 2, '1': 1 }), [2, 1]);
16708 over = _.over([['a', 1]]);
16710 assert.deepEqual(over({ 'a': 1 }), [true]);
16711 assert.deepEqual(over({ 'a': 2 }), [false]);
16714 QUnit.test('should provide arguments to predicates', function(assert) {
16717 var over = _.over(function() {
16718 return slice.call(arguments);
16721 assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
16724 QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
16727 var over = _.over(function() { return this.b; }, function() { return this.a; }),
16728 object = { 'over': over, 'a': 1, 'b': 2 };
16730 assert.deepEqual(object.over(), [2, 1]);
16734 /*--------------------------------------------------------------------------*/
16736 QUnit.module('lodash.overEvery');
16739 QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
16742 var over = _.overEvery(stubTrue, stubOne, stubA);
16743 assert.strictEqual(over(), true);
16746 QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
16750 countFalse = function() { count++; return false; },
16751 countTrue = function() { count++; return true; },
16752 over = _.overEvery(countTrue, countFalse, countTrue);
16754 assert.strictEqual(over(), false);
16755 assert.strictEqual(count, 2);
16758 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16761 var over = _.overEvery(undefined, null);
16763 assert.strictEqual(over(true), true);
16764 assert.strictEqual(over(false), false);
16767 QUnit.test('should work with `_.property` shorthands', function(assert) {
16770 var over = _.overEvery('b', 'a');
16772 assert.strictEqual(over({ 'a': 1, 'b': 1 }), true);
16773 assert.strictEqual(over({ 'a': 0, 'b': 1 }), false);
16776 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16779 var over = _.overEvery({ 'b': 2 }, { 'a': 1 });
16781 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16782 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16785 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16788 var over = _.overEvery([['b', 2], ['a', 1]]);
16790 assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
16791 assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
16794 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16797 var over = _.overEvery(['a', 1]);
16799 assert.strictEqual(over({ 'a': 1, '1': 1 }), true);
16800 assert.strictEqual(over({ 'a': 1, '1': 0 }), false);
16801 assert.strictEqual(over({ 'a': 0, '1': 1 }), false);
16803 over = _.overEvery([['a', 1]]);
16805 assert.strictEqual(over({ 'a': 1 }), true);
16806 assert.strictEqual(over({ 'a': 2 }), false);
16809 QUnit.test('should flatten `predicates`', function(assert) {
16812 var over = _.overEvery(stubTrue, [stubFalse]);
16813 assert.strictEqual(over(), false);
16816 QUnit.test('should provide arguments to predicates', function(assert) {
16821 var over = _.overEvery(function() {
16822 args = slice.call(arguments);
16825 over('a', 'b', 'c');
16826 assert.deepEqual(args, ['a', 'b', 'c']);
16829 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16832 var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
16833 object = { 'over': over, 'a': 1, 'b': 2 };
16835 assert.strictEqual(object.over(), true);
16838 assert.strictEqual(object.over(), false);
16842 /*--------------------------------------------------------------------------*/
16844 QUnit.module('lodash.overSome');
16847 QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
16850 var over = _.overSome(stubFalse, stubOne, stubString);
16851 assert.strictEqual(over(), true);
16853 over = _.overSome(stubNull, stubA, stubZero);
16854 assert.strictEqual(over(), true);
16857 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
16861 countFalse = function() { count++; return false; },
16862 countTrue = function() { count++; return true; },
16863 over = _.overSome(countFalse, countTrue, countFalse);
16865 assert.strictEqual(over(), true);
16866 assert.strictEqual(count, 2);
16869 QUnit.test('should return `false` if all predicates return falsey', function(assert) {
16872 var over = _.overSome(stubFalse, stubFalse, stubFalse);
16873 assert.strictEqual(over(), false);
16875 over = _.overSome(stubNull, stubZero, stubString);
16876 assert.strictEqual(over(), false);
16879 QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
16882 var over = _.overSome(undefined, null);
16884 assert.strictEqual(over(true), true);
16885 assert.strictEqual(over(false), false);
16888 QUnit.test('should work with `_.property` shorthands', function(assert) {
16891 var over = _.overSome('b', 'a');
16893 assert.strictEqual(over({ 'a': 1, 'b': 0 }), true);
16894 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16897 QUnit.test('should work with `_.matches` shorthands', function(assert) {
16900 var over = _.overSome({ 'b': 2 }, { 'a': 1 });
16902 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16903 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16906 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
16909 var over = _.overSome([['b', 2], ['a', 1]]);
16911 assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
16912 assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
16915 QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
16918 var over = _.overSome(['a', 1]);
16920 assert.strictEqual(over({ 'a': 0, '1': 0 }), false);
16921 assert.strictEqual(over({ 'a': 1, '1': 0 }), true);
16922 assert.strictEqual(over({ 'a': 0, '1': 1 }), true);
16924 over = _.overSome([['a', 1]]);
16926 assert.strictEqual(over({ 'a': 1 }), true);
16927 assert.strictEqual(over({ 'a': 2 }), false);
16930 QUnit.test('should flatten `predicates`', function(assert) {
16933 var over = _.overSome(stubFalse, [stubTrue]);
16934 assert.strictEqual(over(), true);
16937 QUnit.test('should provide arguments to predicates', function(assert) {
16942 var over = _.overSome(function() {
16943 args = slice.call(arguments);
16946 over('a', 'b', 'c');
16947 assert.deepEqual(args, ['a', 'b', 'c']);
16950 QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
16953 var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
16954 object = { 'over': over, 'a': 1, 'b': 2 };
16956 assert.strictEqual(object.over(), true);
16958 object.a = object.b = 0;
16959 assert.strictEqual(object.over(), false);
16963 /*--------------------------------------------------------------------------*/
16965 QUnit.module('lodash.pad');
16968 var string = 'abc';
16970 QUnit.test('should pad a string to a given length', function(assert) {
16973 var values = [, undefined],
16974 expected = lodashStable.map(values, lodashStable.constant(' abc '));
16976 var actual = lodashStable.map(values, function(value, index) {
16977 return index ? _.pad(string, 6, value) : _.pad(string, 6);
16980 assert.deepEqual(actual, expected);
16983 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
16986 assert.strictEqual(_.pad(string, 8), ' abc ');
16987 assert.strictEqual(_.pad(string, 8, '_-'), '_-abc_-_');
16990 QUnit.test('should coerce `string` to a string', function(assert) {
16993 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
16994 expected = lodashStable.map(values, stubTrue);
16996 var actual = lodashStable.map(values, function(value) {
16997 return _.pad(value, 6) === ' abc ';
17000 assert.deepEqual(actual, expected);
17004 /*--------------------------------------------------------------------------*/
17006 QUnit.module('lodash.padEnd');
17009 var string = 'abc';
17011 QUnit.test('should pad a string to a given length', function(assert) {
17014 var values = [, undefined],
17015 expected = lodashStable.map(values, lodashStable.constant('abc '));
17017 var actual = lodashStable.map(values, function(value, index) {
17018 return index ? _.padEnd(string, 6, value) : _.padEnd(string, 6);
17021 assert.deepEqual(actual, expected);
17024 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
17027 assert.strictEqual(_.padEnd(string, 6, '_-'), 'abc_-_');
17030 QUnit.test('should coerce `string` to a string', function(assert) {
17033 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
17034 expected = lodashStable.map(values, stubTrue);
17036 var actual = lodashStable.map(values, function(value) {
17037 return _.padEnd(value, 6) === 'abc ';
17040 assert.deepEqual(actual, expected);
17044 /*--------------------------------------------------------------------------*/
17046 QUnit.module('lodash.padStart');
17049 var string = 'abc';
17051 QUnit.test('should pad a string to a given length', function(assert) {
17054 var values = [, undefined],
17055 expected = lodashStable.map(values, lodashStable.constant(' abc'));
17057 var actual = lodashStable.map(values, function(value, index) {
17058 return index ? _.padStart(string, 6, value) : _.padStart(string, 6);
17061 assert.deepEqual(actual, expected);
17064 QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
17067 assert.strictEqual(_.padStart(string, 6, '_-'), '_-_abc');
17070 QUnit.test('should coerce `string` to a string', function(assert) {
17073 var values = [Object(string), { 'toString': lodashStable.constant(string) }],
17074 expected = lodashStable.map(values, stubTrue);
17076 var actual = lodashStable.map(values, function(value) {
17077 return _.padStart(value, 6) === ' abc';
17080 assert.deepEqual(actual, expected);
17084 /*--------------------------------------------------------------------------*/
17086 QUnit.module('pad methods');
17088 lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
17089 var func = _[methodName],
17090 isPad = methodName == 'pad',
17091 isStart = methodName == 'padStart',
17094 QUnit.test('`_.' + methodName + '` should not pad if string is >= `length`', function(assert) {
17097 assert.strictEqual(func(string, 2), string);
17098 assert.strictEqual(func(string, 3), string);
17101 QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
17104 lodashStable.each([0, -2], function(length) {
17105 assert.strictEqual(func(string, length), string);
17109 QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
17112 lodashStable.each(['', '4'], function(length) {
17113 var actual = length ? (isStart ? ' abc' : 'abc ') : string;
17114 assert.strictEqual(func(string, length), actual);
17118 QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
17121 lodashStable.each([undefined, '_-'], function(chars) {
17122 var expected = chars ? (isPad ? '__' : chars) : ' ';
17123 assert.strictEqual(func(null, 2, chars), expected);
17124 assert.strictEqual(func(undefined, 2, chars), expected);
17125 assert.strictEqual(func('', 2, chars), expected);
17129 QUnit.test('`_.' + methodName + '` should return `string` when `chars` coerces to an empty string', function(assert) {
17132 var values = ['', Object('')],
17133 expected = lodashStable.map(values, lodashStable.constant(string));
17135 var actual = lodashStable.map(values, function(value) {
17136 return _.pad(string, 6, value);
17139 assert.deepEqual(actual, expected);
17143 /*--------------------------------------------------------------------------*/
17145 QUnit.module('lodash.parseInt');
17148 QUnit.test('should accept a `radix`', function(assert) {
17151 var expected = lodashStable.range(2, 37);
17153 var actual = lodashStable.map(expected, function(radix) {
17154 return _.parseInt('10', radix);
17157 assert.deepEqual(actual, expected);
17160 QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
17163 assert.strictEqual(_.parseInt('10'), 10);
17164 assert.strictEqual(_.parseInt('10', 0), 10);
17165 assert.strictEqual(_.parseInt('10', 10), 10);
17166 assert.strictEqual(_.parseInt('10', undefined), 10);
17169 QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
17172 lodashStable.each(['0x20', '0X20'], function(string) {
17173 assert.strictEqual(_.parseInt(string), 32);
17174 assert.strictEqual(_.parseInt(string, 0), 32);
17175 assert.strictEqual(_.parseInt(string, 16), 32);
17176 assert.strictEqual(_.parseInt(string, undefined), 32);
17180 QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
17183 assert.strictEqual(_.parseInt('08'), 8);
17184 assert.strictEqual(_.parseInt('08', 10), 8);
17187 QUnit.test('should parse strings with leading whitespace', function(assert) {
17190 var expected = [8, 8, 10, 10, 32, 32, 32, 32];
17192 lodashStable.times(2, function(index) {
17194 func = (index ? (lodashBizarro || {}) : _).parseInt;
17197 lodashStable.times(2, function(otherIndex) {
17198 var string = otherIndex ? '10' : '08';
17200 func(whitespace + string, 10),
17201 func(whitespace + string)
17205 lodashStable.each(['0x20', '0X20'], function(string) {
17207 func(whitespace + string),
17208 func(whitespace + string, 16)
17212 assert.deepEqual(actual, expected);
17215 skipAssert(assert);
17220 QUnit.test('should coerce `radix` to a number', function(assert) {
17223 var object = { 'valueOf': stubZero };
17224 assert.strictEqual(_.parseInt('08', object), 8);
17225 assert.strictEqual(_.parseInt('0x20', object), 32);
17228 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
17231 var strings = lodashStable.map(['6', '08', '10'], Object),
17232 actual = lodashStable.map(strings, _.parseInt);
17234 assert.deepEqual(actual, [6, 8, 10]);
17236 actual = lodashStable.map('123', _.parseInt);
17237 assert.deepEqual(actual, [1, 2, 3]);
17241 /*--------------------------------------------------------------------------*/
17243 QUnit.module('partial methods');
17245 lodashStable.each(['partial', 'partialRight'], function(methodName) {
17246 var func = _[methodName],
17247 isPartial = methodName == 'partial',
17248 ph = func.placeholder;
17250 QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
17253 var par = func(identity, 'a');
17254 assert.strictEqual(par(), 'a');
17257 QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
17260 var fn = function(a, b) { return [a, b]; },
17261 par = func(fn, 'a'),
17262 expected = isPartial ? ['a', 'b'] : ['b', 'a'];
17264 assert.deepEqual(par('b'), expected);
17267 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
17270 var fn = function() { return arguments.length; },
17273 assert.strictEqual(par(), 0);
17276 QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
17279 var par = func(identity);
17280 assert.strictEqual(par('a'), 'a');
17283 QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
17286 var fn = function() { return slice.call(arguments); },
17287 par = func(fn, ph, 'b', ph);
17289 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
17290 assert.deepEqual(par('a'), ['a', 'b', undefined]);
17291 assert.deepEqual(par(), [undefined, 'b', undefined]);
17294 assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
17296 par = func(fn, ph, 'c', ph);
17297 assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
17301 QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) {
17304 if (!isModularize) {
17305 var _ph = _.placeholder = {},
17306 fn = function() { return slice.call(arguments); },
17307 par = func(fn, _ph, 'b', ph),
17308 expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph];
17310 assert.deepEqual(par('a', 'c'), expected);
17311 delete _.placeholder;
17314 skipAssert(assert);
17318 QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
17321 var fn = function(a, b, c) {},
17322 par = func(fn, 'a');
17324 assert.strictEqual(par.length, 0);
17327 QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
17330 function Foo(value) {
17331 return value && object;
17337 assert.ok(new par instanceof Foo);
17338 assert.strictEqual(new par(true), object);
17341 QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
17344 function greet(greeting, name) {
17345 return greeting + ' ' + name;
17348 var par1 = func(greet, 'hi'),
17349 par2 = func(par1, 'barney'),
17350 par3 = func(par1, 'pebbles');
17352 assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
17353 assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
17354 assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
17357 QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
17360 var fn = function(a, b, c) { return a + b + c; },
17361 curried = _.curry(func(fn, 1), 2);
17363 assert.strictEqual(curried(2, 3), 6);
17364 assert.strictEqual(curried(2)(3), 6);
17367 QUnit.test('should work with placeholders and curried functions', function(assert) {
17370 var fn = function() { return slice.call(arguments); },
17371 curried = _.curry(fn),
17372 par = func(curried, ph, 'b', ph, 'd');
17374 assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
17378 /*--------------------------------------------------------------------------*/
17380 QUnit.module('lodash.partialRight');
17383 QUnit.test('should work as a deep `_.defaults`', function(assert) {
17386 var object = { 'a': { 'b': 2 } },
17387 source = { 'a': { 'b': 3, 'c': 3 } },
17388 expected = { 'a': { 'b': 2, 'c': 3 } };
17390 var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
17391 return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
17394 assert.deepEqual(defaultsDeep(object, source), expected);
17398 /*--------------------------------------------------------------------------*/
17400 QUnit.module('methods using `createWrapper`');
17404 return slice.call(arguments);
17407 var ph1 = _.bind.placeholder,
17408 ph2 = _.bindKey.placeholder,
17409 ph3 = _.partial.placeholder,
17410 ph4 = _.partialRight.placeholder;
17412 QUnit.test('should work with combinations of partial functions', function(assert) {
17415 var a = _.partial(fn),
17416 b = _.partialRight(a, 3),
17417 c = _.partial(b, 1);
17419 assert.deepEqual(c(2), [1, 2, 3]);
17422 QUnit.test('should work with combinations of bound and partial functions', function(assert) {
17425 var fn = function() {
17426 var result = [this.a];
17427 push.apply(result, arguments);
17431 var expected = [1, 2, 3, 4],
17432 object = { 'a': 1, 'fn': fn };
17434 var a = _.bindKey(object, 'fn'),
17435 b = _.partialRight(a, 4),
17436 c = _.partial(b, 2);
17438 assert.deepEqual(c(3), expected);
17440 a = _.bind(fn, object);
17441 b = _.partialRight(a, 4);
17442 c = _.partial(b, 2);
17444 assert.deepEqual(c(3), expected);
17446 a = _.partial(fn, 2);
17447 b = _.bind(a, object);
17448 c = _.partialRight(b, 4);
17450 assert.deepEqual(c(3), expected);
17453 QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
17456 function Foo(a, b, c) {
17457 return b === 0 && object;
17460 var combo = _.partial(_.partialRight(Foo, 3), 1),
17463 assert.ok(new combo(2) instanceof Foo);
17464 assert.strictEqual(new combo(0), object);
17467 QUnit.test('should work with combinations of functions with placeholders', function(assert) {
17470 var expected = [1, 2, 3, 4, 5, 6],
17471 object = { 'fn': fn };
17473 var a = _.bindKey(object, 'fn', ph2, 2),
17474 b = _.partialRight(a, ph4, 6),
17475 c = _.partial(b, 1, ph3, 4);
17477 assert.deepEqual(c(3, 5), expected);
17479 a = _.bind(fn, object, ph1, 2);
17480 b = _.partialRight(a, ph4, 6);
17481 c = _.partial(b, 1, ph3, 4);
17483 assert.deepEqual(c(3, 5), expected);
17485 a = _.partial(fn, ph3, 2);
17486 b = _.bind(a, object, 1, ph1, 4);
17487 c = _.partialRight(b, ph4, 6);
17489 assert.deepEqual(c(3, 5), expected);
17492 QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
17495 var expected = [1, 2, 3, 4],
17496 object = { 'fn': fn };
17498 var a = _.bindKey(object, 'fn', ph2, 2),
17499 b = _.partialRight(a, ph4, 4),
17500 c = _.partial(b, ph3, 3);
17502 assert.deepEqual(c(1), expected);
17504 a = _.bind(fn, object, ph1, 2);
17505 b = _.partialRight(a, ph4, 4);
17506 c = _.partial(b, ph3, 3);
17508 assert.deepEqual(c(1), expected);
17510 a = _.partial(fn, ph3, 2);
17511 b = _.bind(a, object, ph1, 3);
17512 c = _.partialRight(b, ph4, 4);
17514 assert.deepEqual(c(1), expected);
17517 QUnit.test('should work with recursively bound functions', function(assert) {
17520 var fn = function() {
17524 var a = _.bind(fn, { 'a': 1 }),
17525 b = _.bind(a, { 'a': 2 }),
17526 c = _.bind(b, { 'a': 3 });
17528 assert.strictEqual(c(), 1);
17531 QUnit.test('should work when hot', function(assert) {
17534 lodashStable.times(2, function(index) {
17535 var fn = function() {
17536 var result = [this];
17537 push.apply(result, arguments);
17542 bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17543 expected = [object, 1, 2, 3];
17545 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17546 var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17547 return index ? bound2(3) : bound2(1, 2, 3);
17550 assert.deepEqual(actual, expected);
17552 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17553 var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
17554 bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
17556 return index ? bound2(3) : bound2(1, 2, 3);
17559 assert.deepEqual(actual, expected);
17562 lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
17563 var fn = function(a, b, c) { return [a, b, c]; },
17564 curried = _[methodName](fn),
17565 expected = index ? [3, 2, 1] : [1, 2, 3];
17567 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17568 return curried(1)(2)(3);
17571 assert.deepEqual(actual, expected);
17573 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17574 var curried = _[methodName](fn);
17575 return curried(1)(2)(3);
17578 assert.deepEqual(actual, expected);
17581 lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
17582 var func = _[methodName],
17583 fn = function() { return slice.call(arguments); },
17584 par1 = func(fn, 1),
17585 expected = index ? [3, 2, 1] : [1, 2, 3];
17587 var actual = _.last(lodashStable.times(HOT_COUNT, function() {
17588 var par2 = func(par1, 2);
17592 assert.deepEqual(actual, expected);
17594 actual = _.last(lodashStable.times(HOT_COUNT, function() {
17595 var par1 = func(fn, 1),
17596 par2 = func(par1, 2);
17601 assert.deepEqual(actual, expected);
17606 /*--------------------------------------------------------------------------*/
17608 QUnit.module('lodash.partition');
17611 var array = [1, 0, 1];
17613 QUnit.test('should split elements into two groups by `predicate`', function(assert) {
17616 assert.deepEqual(_.partition([], identity), [[], []]);
17617 assert.deepEqual(_.partition(array, stubTrue), [array, []]);
17618 assert.deepEqual(_.partition(array, stubFalse), [[], array]);
17621 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
17624 var values = [, null, undefined],
17625 expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
17627 var actual = lodashStable.map(values, function(value, index) {
17628 return index ? _.partition(array, value) : _.partition(array);
17631 assert.deepEqual(actual, expected);
17634 QUnit.test('should work with `_.property` shorthands', function(assert) {
17637 var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
17638 actual = _.partition(objects, 'a');
17640 assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
17643 QUnit.test('should work with a number for `predicate`', function(assert) {
17652 assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
17653 assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
17656 QUnit.test('should work with an object for `collection`', function(assert) {
17659 var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
17660 assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
17664 /*--------------------------------------------------------------------------*/
17666 QUnit.module('lodash.pick');
17669 var args = toArgs(['a', 'c']),
17670 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
17671 nested = { 'a': 1, 'b': { 'c': 2, 'd': 3 } };
17673 QUnit.test('should flatten `paths`', function(assert) {
17676 assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
17677 assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
17680 QUnit.test('should support deep paths', function(assert) {
17683 assert.deepEqual(_.pick(nested, 'b.c'), { 'b': { 'c': 2 } });
17686 QUnit.test('should support path arrays', function(assert) {
17689 var object = { 'a.b': 1, 'a': { 'b': 2 } },
17690 actual = _.pick(object, [['a.b']]);
17692 assert.deepEqual(actual, { 'a.b': 1 });
17695 QUnit.test('should pick a key over a path', function(assert) {
17698 var object = { 'a.b': 1, 'a': { 'b': 2 } };
17700 lodashStable.each(['a.b', ['a.b']], function(path) {
17701 assert.deepEqual(_.pick(object, path), { 'a.b': 1 });
17705 QUnit.test('should coerce `paths` to strings', function(assert) {
17708 assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
17711 QUnit.test('should return an empty object when `object` is nullish', function(assert) {
17714 lodashStable.each([null, undefined], function(value) {
17715 assert.deepEqual(_.pick(value, 'valueOf'), {});
17719 QUnit.test('should work with a primitive `object`', function(assert) {
17722 assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
17725 QUnit.test('should work with `arguments` object `paths`', function(assert) {
17728 assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
17732 /*--------------------------------------------------------------------------*/
17734 QUnit.module('lodash.pickBy');
17737 QUnit.test('should work with a predicate argument', function(assert) {
17740 var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
17742 var actual = _.pickBy(object, function(n) {
17743 return n == 1 || n == 3;
17746 assert.deepEqual(actual, { 'a': 1, 'c': 3 });
17749 QUnit.test('should not treat keys with dots as deep paths', function(assert) {
17752 var object = { 'a.b.c': 1 },
17753 actual = _.pickBy(object, stubTrue);
17755 assert.deepEqual(actual, { 'a.b.c': 1 });
17759 /*--------------------------------------------------------------------------*/
17761 QUnit.module('pick methods');
17763 lodashStable.each(['pick', 'pickBy'], function(methodName) {
17764 var expected = { 'a': 1, 'c': 3 },
17765 func = _[methodName],
17766 isPick = methodName == 'pick',
17767 object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
17768 resolve = lodashStable.nthArg(1);
17770 if (methodName == 'pickBy') {
17771 resolve = function(object, props) {
17772 props = lodashStable.castArray(props);
17773 return function(value) {
17774 return lodashStable.some(props, function(key) {
17775 key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
17776 return object[key] === value;
17781 QUnit.test('`_.' + methodName + '` should create an object of picked string keyed properties', function(assert) {
17784 assert.deepEqual(func(object, resolve(object, 'a')), { 'a': 1 });
17785 assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
17788 QUnit.test('`_.' + methodName + '` should pick inherited string keyed properties', function(assert) {
17792 Foo.prototype = object;
17795 assert.deepEqual(func(foo, resolve(foo, ['a', 'c'])), expected);
17798 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
17801 var object = { '-0': 'a', '0': 'b' },
17802 props = [-0, Object(-0), 0, Object(0)],
17803 expected = [{ '-0': 'a' }, { '-0': 'a' }, { '0': 'b' }, { '0': 'b' }];
17805 var actual = lodashStable.map(props, function(key) {
17806 return func(object, resolve(object, key));
17809 assert.deepEqual(actual, expected);
17812 QUnit.test('`_.' + methodName + '` should pick symbols', function(assert) {
17820 var symbol2 = Symbol('b');
17821 Foo.prototype[symbol2] = 2;
17823 var symbol3 = Symbol('c');
17824 defineProperty(Foo.prototype, symbol3, {
17825 'configurable': true,
17826 'enumerable': false,
17832 actual = func(foo, resolve(foo, [symbol, symbol2, symbol3]));
17834 assert.strictEqual(actual[symbol], 1);
17835 assert.strictEqual(actual[symbol2], 2);
17838 assert.strictEqual(actual[symbol3], 3);
17840 assert.notOk(symbol3 in actual);
17844 skipAssert(assert, 3);
17848 QUnit.test('`_.' + methodName + '` should work with an array `object`', function(assert) {
17851 var array = [1, 2, 3];
17852 assert.deepEqual(func(array, resolve(array, '1')), { '1': 2 });
17856 /*--------------------------------------------------------------------------*/
17858 QUnit.module('lodash.property');
17861 QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
17864 var object = { 'a': 1 };
17866 lodashStable.each(['a', ['a']], function(path) {
17867 var prop = _.property(path);
17868 assert.strictEqual(prop.length, 1);
17869 assert.strictEqual(prop(object), 1);
17873 QUnit.test('should pluck deep property values', function(assert) {
17876 var object = { 'a': { 'b': 2 } };
17878 lodashStable.each(['a.b', ['a', 'b']], function(path) {
17879 var prop = _.property(path);
17880 assert.strictEqual(prop(object), 2);
17884 QUnit.test('should pluck inherited property values', function(assert) {
17888 Foo.prototype.a = 1;
17890 lodashStable.each(['a', ['a']], function(path) {
17891 var prop = _.property(path);
17892 assert.strictEqual(prop(new Foo), 1);
17896 QUnit.test('should work with a non-string `path`', function(assert) {
17899 var array = [1, 2, 3];
17901 lodashStable.each([1, [1]], function(path) {
17902 var prop = _.property(path);
17903 assert.strictEqual(prop(array), 2);
17907 QUnit.test('should preserve the sign of `0`', function(assert) {
17910 var object = { '-0': 'a', '0': 'b' },
17911 props = [-0, Object(-0), 0, Object(0)];
17913 var actual = lodashStable.map(props, function(key) {
17914 var prop = _.property(key);
17915 return prop(object);
17918 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
17921 QUnit.test('should coerce `path` to a string', function(assert) {
17925 fn.toString = lodashStable.constant('fn');
17927 var expected = [1, 2, 3, 4],
17928 object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
17929 paths = [null, undefined, fn, {}];
17931 lodashStable.times(2, function(index) {
17932 var actual = lodashStable.map(paths, function(path) {
17933 var prop = _.property(index ? [path] : path);
17934 return prop(object);
17937 assert.deepEqual(actual, expected);
17941 QUnit.test('should pluck a key over a path', function(assert) {
17944 var object = { 'a.b': 1, 'a': { 'b': 2 } };
17946 lodashStable.each(['a.b', ['a.b']], function(path) {
17947 var prop = _.property(path);
17948 assert.strictEqual(prop(object), 1);
17952 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
17955 var values = [, null, undefined],
17956 expected = lodashStable.map(values, noop);
17958 lodashStable.each(['constructor', ['constructor']], function(path) {
17959 var prop = _.property(path);
17961 var actual = lodashStable.map(values, function(value, index) {
17962 return index ? prop(value) : prop();
17965 assert.deepEqual(actual, expected);
17969 QUnit.test('should return `undefined` for deep paths when `object` is nullish', function(assert) {
17972 var values = [, null, undefined],
17973 expected = lodashStable.map(values, noop);
17975 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
17976 var prop = _.property(path);
17978 var actual = lodashStable.map(values, function(value, index) {
17979 return index ? prop(value) : prop();
17982 assert.deepEqual(actual, expected);
17986 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
17991 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
17992 var prop = _.property(path);
17993 assert.strictEqual(prop(object), undefined);
17998 /*--------------------------------------------------------------------------*/
18000 QUnit.module('lodash.propertyOf');
18003 QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
18006 var object = { 'a': 1 },
18007 propOf = _.propertyOf(object);
18009 assert.strictEqual(propOf.length, 1);
18010 lodashStable.each(['a', ['a']], function(path) {
18011 assert.strictEqual(propOf(path), 1);
18015 QUnit.test('should pluck deep property values', function(assert) {
18018 var object = { 'a': { 'b': 2 } },
18019 propOf = _.propertyOf(object);
18021 lodashStable.each(['a.b', ['a', 'b']], function(path) {
18022 assert.strictEqual(propOf(path), 2);
18026 QUnit.test('should pluck inherited property values', function(assert) {
18032 Foo.prototype.b = 2;
18034 var propOf = _.propertyOf(new Foo);
18036 lodashStable.each(['b', ['b']], function(path) {
18037 assert.strictEqual(propOf(path), 2);
18041 QUnit.test('should work with a non-string `path`', function(assert) {
18044 var array = [1, 2, 3],
18045 propOf = _.propertyOf(array);
18047 lodashStable.each([1, [1]], function(path) {
18048 assert.strictEqual(propOf(path), 2);
18052 QUnit.test('should preserve the sign of `0`', function(assert) {
18055 var object = { '-0': 'a', '0': 'b' },
18056 props = [-0, Object(-0), 0, Object(0)];
18058 var actual = lodashStable.map(props, function(key) {
18059 var propOf = _.propertyOf(object);
18060 return propOf(key);
18063 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
18066 QUnit.test('should coerce `path` to a string', function(assert) {
18070 fn.toString = lodashStable.constant('fn');
18072 var expected = [1, 2, 3, 4],
18073 object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
18074 paths = [null, undefined, fn, {}];
18076 lodashStable.times(2, function(index) {
18077 var actual = lodashStable.map(paths, function(path) {
18078 var propOf = _.propertyOf(object);
18079 return propOf(index ? [path] : path);
18082 assert.deepEqual(actual, expected);
18086 QUnit.test('should pluck a key over a path', function(assert) {
18089 var object = { 'a.b': 1, 'a': { 'b': 2 } },
18090 propOf = _.propertyOf(object);
18092 lodashStable.each(['a.b', ['a.b']], function(path) {
18093 assert.strictEqual(propOf(path), 1);
18097 QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
18100 var values = [, null, undefined],
18101 expected = lodashStable.map(values, noop);
18103 lodashStable.each(['constructor', ['constructor']], function(path) {
18104 var actual = lodashStable.map(values, function(value, index) {
18105 var propOf = index ? _.propertyOf(value) : _.propertyOf();
18106 return propOf(path);
18109 assert.deepEqual(actual, expected);
18113 QUnit.test('should return `undefined` for deep paths when `object` is nullish', function(assert) {
18116 var values = [, null, undefined],
18117 expected = lodashStable.map(values, noop);
18119 lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
18120 var actual = lodashStable.map(values, function(value, index) {
18121 var propOf = index ? _.propertyOf(value) : _.propertyOf();
18122 return propOf(path);
18125 assert.deepEqual(actual, expected);
18129 QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
18132 var propOf = _.propertyOf({});
18134 lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
18135 assert.strictEqual(propOf(path), undefined);
18140 /*--------------------------------------------------------------------------*/
18142 QUnit.module('lodash.pullAll');
18145 QUnit.test('should work with the same value for `array` and `values`', function(assert) {
18148 var array = [{ 'a': 1 }, { 'b': 2 }],
18149 actual = _.pullAll(array, array);
18151 assert.deepEqual(actual, []);
18155 /*--------------------------------------------------------------------------*/
18157 QUnit.module('lodash.pullAllBy');
18160 QUnit.test('should accept an `iteratee`', function(assert) {
18163 var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
18165 var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
18169 assert.deepEqual(actual, [{ 'x': 2 }]);
18172 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
18176 array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
18178 _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
18179 args || (args = slice.call(arguments));
18182 assert.deepEqual(args, [{ 'x': 1 }]);
18186 /*--------------------------------------------------------------------------*/
18188 QUnit.module('lodash.pullAllWith');
18191 QUnit.test('should work with a `comparator`', function(assert) {
18194 var objects = [{ 'x': 1, 'y': 1 }, { 'x': 2, 'y': 2 }, { 'x': 3, 'y': 3 }],
18195 expected = [objects[0], objects[2]],
18196 actual = _.pullAllWith(objects, [{ 'x': 2, 'y': 2 }], lodashStable.isEqual);
18198 assert.deepEqual(actual, expected);
18202 /*--------------------------------------------------------------------------*/
18204 QUnit.module('pull methods');
18206 lodashStable.each(['pull', 'pullAll', 'pullAllWith'], function(methodName) {
18207 var func = _[methodName],
18208 isPull = methodName == 'pull';
18210 function pull(array, values) {
18212 ? func.apply(undefined, [array].concat(values))
18213 : func(array, values);
18216 QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
18219 var array = [1, 2, 3],
18220 actual = pull(array, [1, 3]);
18222 assert.strictEqual(actual, array);
18223 assert.deepEqual(array, [2]);
18226 QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
18229 var array = [1, 2, 3, 4];
18234 assert.notOk('0' in array);
18235 assert.notOk('2' in array);
18238 QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
18241 var array = [1, 2, 3];
18244 pull(array, [undefined]);
18245 assert.deepEqual(array, [1, 3]);
18248 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
18251 var array = [1, NaN, 3, NaN];
18253 pull(array, [NaN]);
18254 assert.deepEqual(array, [1, 3]);
18258 /*--------------------------------------------------------------------------*/
18260 QUnit.module('lodash.pullAt');
18263 QUnit.test('should modify the array and return removed elements', function(assert) {
18266 var array = [1, 2, 3],
18267 actual = _.pullAt(array, [0, 1]);
18269 assert.deepEqual(array, [3]);
18270 assert.deepEqual(actual, [1, 2]);
18273 QUnit.test('should work with unsorted indexes', function(assert) {
18276 var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
18277 actual = _.pullAt(array, [1, 3, 11, 7, 5, 9]);
18279 assert.deepEqual(array, [1, 3, 5, 7, 9, 11]);
18280 assert.deepEqual(actual, [2, 4, 12, 8, 6, 10]);
18283 QUnit.test('should work with repeated indexes', function(assert) {
18286 var array = [1, 2, 3, 4],
18287 actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
18289 assert.deepEqual(array, [4]);
18290 assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
18293 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
18296 var array = ['a', 'b', 'c'],
18297 actual = _.pullAt(array, [2, 4, 0]);
18299 assert.deepEqual(array, ['b']);
18300 assert.deepEqual(actual, ['c', undefined, 'a']);
18303 QUnit.test('should flatten `indexes`', function(assert) {
18306 var array = ['a', 'b', 'c'];
18307 assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
18308 assert.deepEqual(array, ['b']);
18310 array = ['a', 'b', 'c', 'd'];
18311 assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
18312 assert.deepEqual(array, ['b']);
18315 QUnit.test('should return an empty array when no indexes are given', function(assert) {
18318 var array = ['a', 'b', 'c'],
18319 actual = _.pullAt(array);
18321 assert.deepEqual(array, ['a', 'b', 'c']);
18322 assert.deepEqual(actual, []);
18324 actual = _.pullAt(array, [], []);
18326 assert.deepEqual(array, ['a', 'b', 'c']);
18327 assert.deepEqual(actual, []);
18330 QUnit.test('should work with non-index paths', function(assert) {
18333 var values = lodashStable.reject(empties, function(value) {
18334 return (value === 0) || lodashStable.isArray(value);
18335 }).concat(-1, 1.1);
18337 var array = lodashStable.transform(values, function(result, value) {
18341 var expected = lodashStable.map(values, stubOne),
18342 actual = _.pullAt(array, values);
18344 assert.deepEqual(actual, expected);
18346 expected = lodashStable.map(values, noop);
18347 actual = lodashStable.at(array, values);
18349 assert.deepEqual(actual, expected);
18352 QUnit.test('should preserve the sign of `0`', function(assert) {
18355 var props = [-0, Object(-0), 0, Object(0)];
18357 var actual = lodashStable.map(props, function(key) {
18360 return _.pullAt(array, key);
18363 assert.deepEqual(actual, [[-2], [-2], [-1], [-1]]);
18366 QUnit.test('should support deep paths', function(assert) {
18370 array.a = { 'b': 2 };
18372 var actual = _.pullAt(array, 'a.b');
18374 assert.deepEqual(actual, [2]);
18375 assert.deepEqual(array.a, {});
18378 actual = _.pullAt(array, 'a.b.c');
18381 assert.deepEqual(actual, [undefined]);
18384 QUnit.test('should work with a falsey `array` when keys are given', function(assert) {
18387 var values = falsey.slice(),
18388 expected = lodashStable.map(values, lodashStable.constant(Array(4)));
18390 var actual = lodashStable.map(values, function(array) {
18392 return _.pullAt(array, 0, 1, 'pop', 'push');
18396 assert.deepEqual(actual, expected);
18400 /*--------------------------------------------------------------------------*/
18402 QUnit.module('lodash.random');
18405 var array = Array(1000);
18407 QUnit.test('should return `0` or `1` when no arguments are given', function(assert) {
18410 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18414 assert.deepEqual(actual, [0, 1]);
18417 QUnit.test('should support a `min` and `max`', function(assert) {
18423 assert.ok(lodashStable.some(array, function() {
18424 var result = _.random(min, max);
18425 return result >= min && result <= max;
18429 QUnit.test('should support not providing a `max`', function(assert) {
18435 assert.ok(lodashStable.some(array, function() {
18436 var result = _.random(max);
18437 return result >= min && result <= max;
18441 QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
18446 expected = [2, 3, 4];
18448 var actual = lodashStable.uniq(lodashStable.map(array, function() {
18449 return _.random(min, max);
18452 assert.deepEqual(actual, expected);
18455 QUnit.test('should support large integer values', function(assert) {
18458 var min = Math.pow(2, 31),
18459 max = Math.pow(2, 62);
18461 assert.ok(lodashStable.every(array, function() {
18462 var result = _.random(min, max);
18463 return result >= min && result <= max;
18466 assert.ok(lodashStable.some(array, function() {
18467 return _.random(MAX_INTEGER);
18471 QUnit.test('should coerce arguments to finite numbers', function(assert) {
18475 _.random(NaN, NaN),
18476 _.random('1', '1'),
18477 _.random(Infinity, Infinity)
18480 assert.deepEqual(actual, [0, 1, MAX_INTEGER]);
18483 QUnit.test('should support floats', function(assert) {
18488 actual = _.random(min, max);
18490 assert.ok(actual % 1);
18491 assert.ok(actual >= min && actual <= max);
18494 QUnit.test('should support providing a `floating`', function(assert) {
18497 var actual = _.random(true);
18498 assert.ok(actual % 1 && actual >= 0 && actual <= 1);
18500 actual = _.random(2, true);
18501 assert.ok(actual % 1 && actual >= 0 && actual <= 2);
18503 actual = _.random(2, 4, true);
18504 assert.ok(actual % 1 && actual >= 2 && actual <= 4);
18507 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
18510 var array = [1, 2, 3],
18511 expected = lodashStable.map(array, stubTrue),
18512 randoms = lodashStable.map(array, _.random);
18514 var actual = lodashStable.map(randoms, function(result, index) {
18515 return result >= 0 && result <= array[index] && (result % 1) == 0;
18518 assert.deepEqual(actual, expected);
18522 /*--------------------------------------------------------------------------*/
18524 QUnit.module('range methods');
18526 lodashStable.each(['range', 'rangeRight'], function(methodName) {
18527 var func = _[methodName],
18528 isRange = methodName == 'range';
18530 function resolve(range) {
18531 return isRange ? range : range.reverse();
18534 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `end` is given', function(assert) {
18537 assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
18538 assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
18541 QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `start` and `end` are given', function(assert) {
18544 assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
18545 assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
18548 QUnit.test('`_.' + methodName + '` should work with a `start`, `end`, and `step`', function(assert) {
18551 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18552 assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
18553 assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
18556 QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
18559 assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
18562 QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
18565 assert.deepEqual(func(1, 5, 20), [1]);
18568 QUnit.test('`_.' + methodName + '` should work with a negative `step`', function(assert) {
18571 assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
18572 assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
18575 QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
18578 var actual = func(-0, 1);
18579 assert.strictEqual(1 / actual[0], -Infinity);
18582 QUnit.test('`_.' + methodName + '` should treat falsey `start` as `0`', function(assert) {
18585 lodashStable.each(falsey, function(value, index) {
18587 assert.deepEqual(func(value), []);
18588 assert.deepEqual(func(value, 1), [0]);
18590 assert.deepEqual(func(), []);
18595 QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
18606 assert.deepEqual(actual, [[0], [0], [0], [], []]);
18609 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
18612 var array = [1, 2, 3],
18613 object = { 'a': 1, 'b': 2, 'c': 3 },
18614 expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
18616 lodashStable.each([array, object], function(collection) {
18617 var actual = lodashStable.map(collection, func);
18618 assert.deepEqual(actual, expected);
18623 /*--------------------------------------------------------------------------*/
18625 QUnit.module('lodash.rearg');
18629 return slice.call(arguments);
18632 QUnit.test('should reorder arguments provided to `func`', function(assert) {
18635 var rearged = _.rearg(fn, [2, 0, 1]);
18636 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18639 QUnit.test('should work with repeated indexes', function(assert) {
18642 var rearged = _.rearg(fn, [1, 1, 1]);
18643 assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
18646 QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
18649 var rearged = _.rearg(fn, [1, 4]);
18650 assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
18653 QUnit.test('should use `undefined` for non-index values', function(assert) {
18656 var values = lodashStable.reject(empties, function(value) {
18657 return (value === 0) || lodashStable.isArray(value);
18658 }).concat(-1, 1.1);
18660 var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
18662 var actual = lodashStable.map(values, function(value) {
18663 var rearged = _.rearg(fn, [value]);
18664 return rearged('a', 'b', 'c');
18667 assert.deepEqual(actual, expected);
18670 QUnit.test('should not rearrange arguments when no indexes are given', function(assert) {
18673 var rearged = _.rearg(fn);
18674 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18676 rearged = _.rearg(fn, [], []);
18677 assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
18680 QUnit.test('should accept multiple index arguments', function(assert) {
18683 var rearged = _.rearg(fn, 2, 0, 1);
18684 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18687 QUnit.test('should accept multiple arrays of indexes', function(assert) {
18690 var rearged = _.rearg(fn, [2], [0, 1]);
18691 assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
18694 QUnit.test('should work with fewer indexes than arguments', function(assert) {
18697 var rearged = _.rearg(fn, [1, 0]);
18698 assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
18701 QUnit.test('should work on functions that have been rearged', function(assert) {
18704 var rearged1 = _.rearg(fn, 2, 1, 0),
18705 rearged2 = _.rearg(rearged1, 1, 0, 2);
18707 assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
18711 /*--------------------------------------------------------------------------*/
18713 QUnit.module('lodash.reduce');
18716 var array = [1, 2, 3];
18718 QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
18721 assert.strictEqual(_.reduce(array), 1);
18724 QUnit.test('should provide correct `iteratee` arguments when iterating an array', function(assert) {
18729 _.reduce(array, function() {
18730 args || (args = slice.call(arguments));
18733 assert.deepEqual(args, [0, 1, 0, array]);
18736 _.reduce(array, function() {
18737 args || (args = slice.call(arguments));
18740 assert.deepEqual(args, [1, 2, 1, array]);
18743 QUnit.test('should provide correct `iteratee` arguments when iterating an object', function(assert) {
18747 object = { 'a': 1, 'b': 2 },
18748 firstKey = _.head(_.keys(object));
18750 var expected = firstKey == 'a'
18751 ? [0, 1, 'a', object]
18752 : [0, 2, 'b', object];
18754 _.reduce(object, function() {
18755 args || (args = slice.call(arguments));
18758 assert.deepEqual(args, expected);
18761 expected = firstKey == 'a'
18762 ? [1, 2, 'b', object]
18763 : [2, 1, 'a', object];
18765 _.reduce(object, function() {
18766 args || (args = slice.call(arguments));
18769 assert.deepEqual(args, expected);
18773 /*--------------------------------------------------------------------------*/
18775 QUnit.module('lodash.reduceRight');
18778 var array = [1, 2, 3];
18780 QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
18783 assert.strictEqual(_.reduceRight(array), 3);
18786 QUnit.test('should provide correct `iteratee` arguments when iterating an array', function(assert) {
18791 _.reduceRight(array, function() {
18792 args || (args = slice.call(arguments));
18795 assert.deepEqual(args, [0, 3, 2, array]);
18798 _.reduceRight(array, function() {
18799 args || (args = slice.call(arguments));
18802 assert.deepEqual(args, [3, 2, 1, array]);
18805 QUnit.test('should provide correct `iteratee` arguments when iterating an object', function(assert) {
18809 object = { 'a': 1, 'b': 2 },
18810 isFIFO = lodashStable.keys(object)[0] == 'a';
18812 var expected = isFIFO
18813 ? [0, 2, 'b', object]
18814 : [0, 1, 'a', object];
18816 _.reduceRight(object, function() {
18817 args || (args = slice.call(arguments));
18820 assert.deepEqual(args, expected);
18824 ? [2, 1, 'a', object]
18825 : [1, 2, 'b', object];
18827 _.reduceRight(object, function() {
18828 args || (args = slice.call(arguments));
18831 assert.deepEqual(args, expected);
18835 /*--------------------------------------------------------------------------*/
18837 QUnit.module('reduce methods');
18839 lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
18840 var func = _[methodName],
18842 isReduce = methodName == 'reduce';
18844 QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
18847 var actual = func(['a', 'b', 'c'], function(accumulator, value) {
18848 return accumulator + value;
18851 assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
18854 QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
18858 expected = lodashStable.map(empties, noop);
18860 lodashStable.each(empties, function(value) {
18862 actual.push(func(value, noop));
18866 assert.deepEqual(actual, expected);
18869 QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
18872 var expected = lodashStable.map(empties, lodashStable.constant('x'));
18874 var actual = lodashStable.map(empties, function(value) {
18876 return func(value, noop, 'x');
18880 assert.deepEqual(actual, expected);
18883 QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
18886 var actual = func([], noop, undefined);
18887 assert.strictEqual(actual, undefined);
18890 QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is given (test in IE > 9 and modern browsers)', function(assert) {
18894 object = { '0': 1, 'length': 0 };
18896 if ('__proto__' in array) {
18897 array.__proto__ = object;
18898 assert.strictEqual(func(array, noop), undefined);
18901 skipAssert(assert);
18903 assert.strictEqual(func(object, noop), undefined);
18906 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
18910 assert.strictEqual(_(array)[methodName](add), 6);
18913 skipAssert(assert);
18917 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
18921 assert.ok(_(array).chain()[methodName](add) instanceof _);
18924 skipAssert(assert);
18929 /*--------------------------------------------------------------------------*/
18931 QUnit.module('lodash.reject');
18934 var array = [1, 2, 3];
18936 QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
18939 assert.deepEqual(_.reject(array, isEven), [1, 3]);
18943 /*--------------------------------------------------------------------------*/
18945 QUnit.module('filter methods');
18947 lodashStable.each(['filter', 'reject'], function(methodName) {
18948 var array = [1, 2, 3, 4],
18949 func = _[methodName],
18950 isFilter = methodName == 'filter',
18951 objects = [{ 'a': 0 }, { 'a': 1 }];
18953 QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
18956 var actual = func([0], function(value, index, array) {
18961 assert.deepEqual(actual, [0]);
18964 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
18967 assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
18970 QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
18973 assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
18976 QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
18980 var wrapped = _(array);
18982 var actual = wrapped[methodName](function(n) {
18986 assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
18988 actual = wrapped[methodName](function(n) {
18992 assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
18995 skipAssert(assert, 2);
18999 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
19003 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
19004 predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); };
19006 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
19007 return ['key' + index, index];
19010 var actual = _(array).slice(1).map(square)[methodName](predicate).value();
19011 assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
19013 actual = _(object).mapValues(square)[methodName](predicate).value();
19014 assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
19017 skipAssert(assert, 2);
19021 QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments in a lazy sequence', function(assert) {
19026 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
19027 expected = [1, 0, lodashStable.map(array.slice(1), square)];
19029 _(array).slice(1)[methodName](function(value, index, array) {
19030 args || (args = slice.call(arguments));
19033 assert.deepEqual(args, [1, 0, array.slice(1)]);
19036 _(array).slice(1).map(square)[methodName](function(value, index, array) {
19037 args || (args = slice.call(arguments));
19040 assert.deepEqual(args, expected);
19043 _(array).slice(1).map(square)[methodName](function(value, index) {
19044 args || (args = slice.call(arguments));
19047 assert.deepEqual(args, expected);
19050 _(array).slice(1).map(square)[methodName](function(value) {
19051 args || (args = slice.call(arguments));
19054 assert.deepEqual(args, [1]);
19057 _(array).slice(1).map(square)[methodName](function() {
19058 args || (args = slice.call(arguments));
19061 assert.deepEqual(args, expected);
19064 skipAssert(assert, 5);
19069 /*--------------------------------------------------------------------------*/
19071 QUnit.module('lodash.remove');
19074 QUnit.test('should modify the array and return removed elements', function(assert) {
19077 var array = [1, 2, 3, 4],
19078 actual = _.remove(array, isEven);
19080 assert.deepEqual(array, [1, 3]);
19081 assert.deepEqual(actual, [2, 4]);
19084 QUnit.test('should provide correct `predicate` arguments', function(assert) {
19089 clone = array.slice();
19091 _.remove(array, function(n, index) {
19092 var args = slice.call(arguments);
19093 args[2] = args[2].slice();
19094 argsList.push(args);
19095 return isEven(index);
19098 assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
19101 QUnit.test('should work with `_.matches` shorthands', function(assert) {
19104 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
19105 _.remove(objects, { 'a': 1 });
19106 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
19109 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
19112 var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
19113 _.remove(objects, ['a', 1]);
19114 assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
19117 QUnit.test('should work with `_.property` shorthands', function(assert) {
19120 var objects = [{ 'a': 0 }, { 'a': 1 }];
19121 _.remove(objects, 'a');
19122 assert.deepEqual(objects, [{ 'a': 0 }]);
19125 QUnit.test('should preserve holes in arrays', function(assert) {
19128 var array = [1, 2, 3, 4];
19132 _.remove(array, function(n) {
19136 assert.notOk('0' in array);
19137 assert.notOk('2' in array);
19140 QUnit.test('should treat holes as `undefined`', function(assert) {
19143 var array = [1, 2, 3];
19146 _.remove(array, function(n) {
19150 assert.deepEqual(array, [1, 3]);
19153 QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
19156 var array = [1, 2, 3];
19158 _.remove(array, function(n, index) {
19159 return isEven(index);
19162 assert.deepEqual(array, [2]);
19166 /*--------------------------------------------------------------------------*/
19168 QUnit.module('lodash.repeat');
19171 var string = 'abc';
19173 QUnit.test('should repeat a string `n` times', function(assert) {
19176 assert.strictEqual(_.repeat('*', 3), '***');
19177 assert.strictEqual(_.repeat(string, 2), 'abcabc');
19180 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
19183 var expected = lodashStable.map(falsey, function(value) {
19184 return value === undefined ? string : '';
19187 var actual = lodashStable.map(falsey, function(n, index) {
19188 return index ? _.repeat(string, n) : _.repeat(string);
19191 assert.deepEqual(actual, expected);
19194 QUnit.test('should return an empty string if `n` is <= `0`', function(assert) {
19197 assert.strictEqual(_.repeat(string, 0), '');
19198 assert.strictEqual(_.repeat(string, -2), '');
19201 QUnit.test('should coerce `n` to an integer', function(assert) {
19204 assert.strictEqual(_.repeat(string, '2'), 'abcabc');
19205 assert.strictEqual(_.repeat(string, 2.6), 'abcabc');
19206 assert.strictEqual(_.repeat('*', { 'valueOf': stubThree }), '***');
19209 QUnit.test('should coerce `string` to a string', function(assert) {
19212 assert.strictEqual(_.repeat(Object(string), 2), 'abcabc');
19213 assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
19216 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19219 var actual = lodashStable.map(['a', 'b', 'c'], _.repeat);
19220 assert.deepEqual(actual, ['a', 'b', 'c']);
19224 /*--------------------------------------------------------------------------*/
19226 QUnit.module('lodash.replace');
19229 QUnit.test('should replace the matched pattern', function(assert) {
19232 var string = 'abcde';
19233 assert.strictEqual(_.replace(string, 'de', '123'), 'abc123');
19234 assert.strictEqual(_.replace(string, /[bd]/g, '-'), 'a-c-e');
19238 /*--------------------------------------------------------------------------*/
19240 QUnit.module('lodash.result');
19243 var object = { 'a': 1, 'b': stubB };
19245 QUnit.test('should invoke function values', function(assert) {
19248 assert.strictEqual(_.result(object, 'b'), 'b');
19251 QUnit.test('should invoke default function values', function(assert) {
19254 var actual = _.result(object, 'c', object.b);
19255 assert.strictEqual(actual, 'b');
19258 QUnit.test('should invoke nested function values', function(assert) {
19261 var value = { 'a': lodashStable.constant({ 'b': stubB }) };
19263 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19264 assert.strictEqual(_.result(value, path), 'b');
19268 QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
19271 var value = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
19273 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19274 assert.strictEqual(_.result(value, path), 1);
19279 /*--------------------------------------------------------------------------*/
19281 QUnit.module('lodash.get and lodash.result');
19283 lodashStable.each(['get', 'result'], function(methodName) {
19284 var func = _[methodName];
19286 QUnit.test('`_.' + methodName + '` should get string keyed property values', function(assert) {
19289 var object = { 'a': 1 };
19291 lodashStable.each(['a', ['a']], function(path) {
19292 assert.strictEqual(func(object, path), 1);
19296 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19299 var object = { '-0': 'a', '0': 'b' },
19300 props = [-0, Object(-0), 0, Object(0)];
19302 var actual = lodashStable.map(props, function(key) {
19303 return func(object, key);
19306 assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
19309 QUnit.test('`_.' + methodName + '` should get symbol keyed property values', function(assert) {
19314 object[symbol] = 1;
19316 assert.strictEqual(func(object, symbol), 1);
19319 skipAssert(assert);
19323 QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
19326 var object = { 'a': { 'b': 2 } };
19328 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19329 assert.strictEqual(func(object, path), 2);
19333 QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
19336 var object = { 'a.b': 1, 'a': { 'b': 2 } };
19338 lodashStable.each(['a.b', ['a.b']], function(path) {
19339 assert.strictEqual(func(object, path), 1);
19343 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
19346 var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
19347 assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
19350 QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
19353 var object = { 'a': { '': 1 } };
19354 assert.strictEqual(func(object, 'a[]'), 1);
19357 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
19360 lodashStable.each([['', ''], [[], ['']]], function(pair) {
19361 assert.strictEqual(func({}, pair[0]), undefined);
19362 assert.strictEqual(func({ '': 3 }, pair[1]), 3);
19366 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
19369 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
19372 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
19373 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
19376 lodashStable.each(paths, function(path) {
19377 assert.strictEqual(func(object, path), 8);
19381 QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
19384 lodashStable.each(['constructor', ['constructor']], function(path) {
19385 assert.strictEqual(func(null, path), undefined);
19386 assert.strictEqual(func(undefined, path), undefined);
19390 QUnit.test('`_.' + methodName + '` should return `undefined` for deep paths when `object` is nullish', function(assert) {
19393 var values = [null, undefined],
19394 expected = lodashStable.map(values, noop),
19395 paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
19397 lodashStable.each(paths, function(path) {
19398 var actual = lodashStable.map(values, function(value) {
19399 return func(value, path);
19402 assert.deepEqual(actual, expected);
19406 QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
19409 var object = { 'a': [, null] };
19411 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
19412 assert.strictEqual(func(object, path), undefined);
19416 QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
19419 var object = { 'a': { 'b': null } };
19421 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19422 assert.strictEqual(func(object, path), null);
19426 QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
19429 var paths = ['a.b', ['a', 'b']];
19431 lodashStable.each(paths, function(path) {
19432 numberProto.a = { 'b': 2 };
19433 assert.strictEqual(func(0, path), 2);
19434 delete numberProto.a;
19438 QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
19441 var object = { 'a': {} },
19442 values = empties.concat(true, new Date, 1, /x/, 'a'),
19443 expected = lodashStable.map(values, function(value) { return [value, value]; });
19445 lodashStable.each(['a.b', ['a', 'b']], function(path) {
19446 var actual = lodashStable.map(values, function(value) {
19447 return [func(object, path, value), func(null, path, value)];
19450 assert.deepEqual(actual, expected);
19454 QUnit.test('`_.' + methodName + '` should return the default value when `path` is empty', function(assert) {
19457 assert.strictEqual(func({}, [], 'a'), 'a');
19461 /*--------------------------------------------------------------------------*/
19463 QUnit.module('lodash.rest');
19466 function fn(a, b, c) {
19467 return slice.call(arguments);
19470 QUnit.test('should apply a rest parameter to `func`', function(assert) {
19473 var rest = _.rest(fn);
19474 assert.deepEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
19477 QUnit.test('should work with `start`', function(assert) {
19480 var rest = _.rest(fn, 1);
19481 assert.deepEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
19484 QUnit.test('should treat `start` as `0` for `NaN` or negative values', function(assert) {
19487 var values = [-1, NaN, 'a'],
19488 expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
19490 var actual = lodashStable.map(values, function(value) {
19491 var rest = _.rest(fn, value);
19492 return rest(1, 2, 3, 4);
19495 assert.deepEqual(actual, expected);
19498 QUnit.test('should coerce `start` to an integer', function(assert) {
19501 var rest = _.rest(fn, 1.6);
19502 assert.deepEqual(rest(1, 2, 3), [1, [2, 3]]);
19505 QUnit.test('should use an empty array when `start` is not reached', function(assert) {
19508 var rest = _.rest(fn);
19509 assert.deepEqual(rest(1), [1, undefined, []]);
19512 QUnit.test('should work on functions with more than three parameters', function(assert) {
19515 var rest = _.rest(function(a, b, c, d) {
19516 return slice.call(arguments);
19519 assert.deepEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
19523 /*--------------------------------------------------------------------------*/
19525 QUnit.module('lodash.reverse');
19528 var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
19529 smallArray = [0, 1, 2, null];
19531 QUnit.test('should reverse `array`', function(assert) {
19534 var array = [1, 2, 3],
19535 actual = _.reverse(array);
19537 assert.strictEqual(actual, array);
19538 assert.deepEqual(array, [3, 2, 1]);
19541 QUnit.test('should return the wrapped reversed `array`', function(assert) {
19545 lodashStable.times(2, function(index) {
19546 var array = (index ? largeArray : smallArray).slice(),
19547 clone = array.slice(),
19548 wrapped = _(array).reverse(),
19549 actual = wrapped.value();
19551 assert.ok(wrapped instanceof _);
19552 assert.strictEqual(actual, array);
19553 assert.deepEqual(actual, clone.slice().reverse());
19557 skipAssert(assert, 6);
19561 QUnit.test('should work in a lazy sequence', function(assert) {
19565 lodashStable.times(2, function(index) {
19566 var array = (index ? largeArray : smallArray).slice(),
19567 expected = array.slice(),
19568 actual = _(array).slice(1).reverse().value();
19570 assert.deepEqual(actual, expected.slice(1).reverse());
19571 assert.deepEqual(array, expected);
19575 skipAssert(assert, 4);
19579 QUnit.test('should be lazy when in a lazy sequence', function(assert) {
19584 'toString': function() {
19585 throw new Error('spy was revealed');
19589 var array = largeArray.concat(spy),
19590 expected = array.slice();
19593 var wrapped = _(array).slice(1).map(String).reverse(),
19594 actual = wrapped.last();
19597 assert.ok(wrapped instanceof _);
19598 assert.strictEqual(actual, '1');
19599 assert.deepEqual(array, expected);
19602 skipAssert(assert, 3);
19606 QUnit.test('should work in a hybrid sequence', function(assert) {
19610 lodashStable.times(2, function(index) {
19611 var clone = (index ? largeArray : smallArray).slice();
19613 lodashStable.each(['map', 'filter'], function(methodName) {
19614 var array = clone.slice(),
19615 expected = clone.slice(1, -1).reverse(),
19616 actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
19618 assert.deepEqual(actual, expected);
19620 array = clone.slice();
19621 actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
19623 assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
19628 skipAssert(assert, 8);
19632 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
19636 lodashStable.times(2, function(index) {
19637 var array = (index ? largeArray : smallArray).slice(),
19638 expected = array.slice().reverse(),
19639 wrapped = _(array).chain().reverse().head();
19641 assert.ok(wrapped instanceof _);
19642 assert.strictEqual(wrapped.value(), _.head(expected));
19643 assert.deepEqual(array, expected);
19647 skipAssert(assert, 6);
19652 /*--------------------------------------------------------------------------*/
19654 QUnit.module('round methods');
19656 lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
19657 var func = _[methodName],
19658 isCeil = methodName == 'ceil',
19659 isFloor = methodName == 'floor';
19661 QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
19664 var actual = func(4.006);
19665 assert.strictEqual(actual, isCeil ? 5 : 4);
19668 QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
19671 var actual = func(4.006, 0);
19672 assert.strictEqual(actual, isCeil ? 5 : 4);
19675 QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
19678 var actual = func(4.016, 2);
19679 assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
19681 actual = func(4.1, 2);
19682 assert.strictEqual(actual, 4.1);
19685 QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
19688 var actual = func(4160, -2);
19689 assert.strictEqual(actual, isFloor ? 4100 : 4200);
19692 QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
19695 var actual = func(4.006, NaN);
19696 assert.strictEqual(actual, isCeil ? 5 : 4);
19698 var expected = isFloor ? 4.01 : 4.02;
19700 actual = func(4.016, 2.6);
19701 assert.strictEqual(actual, expected);
19703 actual = func(4.016, '+2');
19704 assert.strictEqual(actual, expected);
19707 QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
19710 var actual = func(5e1, 2);
19711 assert.deepEqual(actual, 50);
19713 actual = func('5e', 1);
19714 assert.deepEqual(actual, NaN);
19716 actual = func('5e1e1', 1);
19717 assert.deepEqual(actual, NaN);
19720 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19723 var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
19724 expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
19726 var actual = lodashStable.map(values, function(args) {
19727 return 1 / func.apply(undefined, args);
19730 assert.deepEqual(actual, expected);
19733 QUnit.test('`_.' + methodName + '` should not return `NaN` for large `precision` values', function(assert) {
19737 _.round(10.0000001, 1000),
19738 _.round(MAX_SAFE_INTEGER, 293)
19741 var expected = lodashStable.map(results, stubFalse),
19742 actual = lodashStable.map(results, lodashStable.isNaN);
19744 assert.deepEqual(actual, expected);
19748 /*--------------------------------------------------------------------------*/
19750 QUnit.module('lodash.runInContext');
19753 QUnit.test('should not require a fully populated `context` object', function(assert) {
19756 if (!isModularize) {
19757 var lodash = _.runInContext({
19758 'setTimeout': function(func) { func(); }
19762 lodash.delay(function() { pass = true; }, 32);
19766 skipAssert(assert);
19770 QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
19773 if (!isModularize) {
19774 lodashStable.times(2, _.uniqueId);
19776 var oldId = Number(_.uniqueId()),
19777 lodash = _.runInContext();
19779 assert.ok(_.uniqueId() > oldId);
19781 var id = lodash.uniqueId();
19782 assert.strictEqual(id, '1');
19783 assert.ok(id < oldId);
19786 skipAssert(assert, 3);
19791 /*--------------------------------------------------------------------------*/
19793 QUnit.module('lodash.sample');
19796 var array = [1, 2, 3];
19798 QUnit.test('should return a random element', function(assert) {
19801 var actual = _.sample(array);
19802 assert.ok(lodashStable.includes(array, actual));
19805 QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
19808 var expected = lodashStable.map(empties, noop);
19810 var actual = lodashStable.transform(empties, function(result, value) {
19812 result.push(_.sample(value));
19816 assert.deepEqual(actual, expected);
19819 QUnit.test('should sample an object', function(assert) {
19822 var object = { 'a': 1, 'b': 2, 'c': 3 },
19823 actual = _.sample(object);
19825 assert.ok(lodashStable.includes(array, actual));
19829 /*--------------------------------------------------------------------------*/
19831 QUnit.module('lodash.sampleSize');
19834 var array = [1, 2, 3];
19836 QUnit.test('should return an array of random elements', function(assert) {
19839 var actual = _.sampleSize(array, 2);
19841 assert.strictEqual(actual.length, 2);
19842 assert.deepEqual(lodashStable.difference(actual, array), []);
19845 QUnit.test('should contain elements of the collection', function(assert) {
19848 var actual = _.sampleSize(array, array.length).sort();
19850 assert.deepEqual(actual, array);
19853 QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
19856 var expected = lodashStable.map(falsey, function(value) {
19857 return value === undefined ? ['a'] : [];
19860 var actual = lodashStable.map(falsey, function(size, index) {
19861 return index ? _.sampleSize(['a'], size) : _.sampleSize(['a']);
19864 assert.deepEqual(actual, expected);
19867 QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
19870 lodashStable.each([0, -1, -Infinity], function(n) {
19871 assert.deepEqual(_.sampleSize(array, n), []);
19875 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
19878 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
19879 var actual = _.sampleSize(array, n).sort();
19880 assert.deepEqual(actual, array);
19884 QUnit.test('should coerce `n` to an integer', function(assert) {
19887 var actual = _.sampleSize(array, 1.6);
19888 assert.strictEqual(actual.length, 1);
19891 QUnit.test('should return an empty array for empty collections', function(assert) {
19894 var expected = lodashStable.map(empties, stubArray);
19896 var actual = lodashStable.transform(empties, function(result, value) {
19898 result.push(_.sampleSize(value, 1));
19902 assert.deepEqual(actual, expected);
19905 QUnit.test('should sample an object', function(assert) {
19908 var object = { 'a': 1, 'b': 2, 'c': 3 },
19909 actual = _.sampleSize(object, 2);
19911 assert.strictEqual(actual.length, 2);
19912 assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
19915 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
19918 var actual = lodashStable.map([['a']], _.sampleSize);
19919 assert.deepEqual(actual, [['a']]);
19923 /*--------------------------------------------------------------------------*/
19925 QUnit.module('lodash.setWith');
19928 QUnit.test('should work with a `customizer` callback', function(assert) {
19931 var actual = _.setWith({ '0': {} }, '[0][1][2]', 3, function(value) {
19932 return lodashStable.isObject(value) ? undefined : {};
19935 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
19938 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
19941 var actual = _.setWith({}, 'a[0].b.c', 4, noop);
19942 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
19946 /*--------------------------------------------------------------------------*/
19948 QUnit.module('set methods');
19950 lodashStable.each(['update', 'updateWith', 'set', 'setWith'], function(methodName) {
19951 var func = _[methodName],
19952 isUpdate = /^update/.test(methodName);
19956 updater = isUpdate ? lodashStable.constant(value) : value;
19958 QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
19961 lodashStable.each(['a', ['a']], function(path) {
19962 var object = { 'a': oldValue },
19963 actual = func(object, path, updater);
19965 assert.strictEqual(actual, object);
19966 assert.strictEqual(object.a, value);
19970 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
19973 var props = [-0, Object(-0), 0, Object(0)],
19974 expected = lodashStable.map(props, lodashStable.constant(value));
19976 var actual = lodashStable.map(props, function(key) {
19977 var object = { '-0': 'a', '0': 'b' };
19978 func(object, key, updater);
19979 return object[lodashStable.toString(key)];
19982 assert.deepEqual(actual, expected);
19985 QUnit.test('`_.' + methodName + '` should unset symbol keyed property values', function(assert) {
19990 object[symbol] = 1;
19992 assert.strictEqual(_.unset(object, symbol), true);
19993 assert.notOk(symbol in object);
19996 skipAssert(assert, 2);
20000 QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
20003 lodashStable.each(['a.b', ['a', 'b']], function(path) {
20004 var object = { 'a': { 'b': oldValue } },
20005 actual = func(object, path, updater);
20007 assert.strictEqual(actual, object);
20008 assert.strictEqual(object.a.b, value);
20012 QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
20015 lodashStable.each(['a.b', ['a.b']], function(path) {
20016 var object = { 'a.b': oldValue },
20017 actual = func(object, path, updater);
20019 assert.strictEqual(actual, object);
20020 assert.deepEqual(object, { 'a.b': value });
20024 QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
20027 var object = { 'a,b,c': 1, 'a': { 'b': { 'c': 1 } } };
20029 func(object, ['a', 'b', 'c'], updater);
20030 assert.strictEqual(object.a.b.c, value);
20033 QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
20038 func(object, 'a[]', updater);
20039 assert.deepEqual(object, { 'a': { '': value } });
20042 QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
20045 lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
20048 func(object, pair[0], updater);
20049 assert.deepEqual(object, index ? {} : { '': value });
20051 func(object, pair[1], updater);
20052 assert.deepEqual(object, { '': value });
20056 QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
20059 var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': oldValue } } } } } } } };
20062 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
20063 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
20066 lodashStable.each(paths, function(path) {
20067 func(object, path, updater);
20068 assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, value);
20069 object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = oldValue;
20073 QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
20078 lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
20079 var actual = func(object, path, updater);
20081 assert.strictEqual(actual, object);
20082 assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': value } }] });
20083 assert.notOk('0' in object.a);
20089 QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
20092 var values = [null, undefined],
20093 expected = [[null, null], [undefined, undefined]];
20095 var actual = lodashStable.map(values, function(value) {
20097 return [func(value, 'a.b', updater), func(value, ['a', 'b'], updater)];
20103 assert.deepEqual(actual, expected);
20106 QUnit.test('`_.' + methodName + '` should overwrite primitives in the path', function(assert) {
20109 lodashStable.each(['a.b', ['a', 'b']], function(path) {
20110 var object = { 'a': '' };
20112 func(object, path, updater);
20113 assert.deepEqual(object, { 'a': { 'b': 2 } });
20117 QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
20122 func(object, ['1a', '2b', '3c'], updater);
20123 assert.deepEqual(object, { '1a': { '2b': { '3c': value } } });
20126 QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
20129 lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
20132 updater = isUpdate ? lodashStable.constant(value) : value;
20134 defineProperty(object, 'a', {
20135 'configurable': true,
20136 'enumerable': true,
20137 'get': lodashStable.constant(value),
20138 'set': function() { pass = false; }
20141 func(object, 'a', updater);
20147 /*--------------------------------------------------------------------------*/
20149 QUnit.module('lodash.shuffle');
20152 var array = [1, 2, 3],
20153 object = { 'a': 1, 'b': 2, 'c': 3 };
20155 QUnit.test('should return a new array', function(assert) {
20158 assert.notStrictEqual(_.shuffle(array), array);
20161 QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
20164 assert.deepEqual(_.shuffle(array).sort(), array);
20165 assert.deepEqual(_.shuffle(object).sort(), array);
20168 QUnit.test('should shuffle small collections', function(assert) {
20171 var actual = lodashStable.times(1000, function(assert) {
20172 return _.shuffle([1, 2]);
20175 assert.deepEqual(lodashStable.sortBy(lodashStable.uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
20178 QUnit.test('should treat number values for `collection` as empty', function(assert) {
20181 assert.deepEqual(_.shuffle(1), []);
20185 /*--------------------------------------------------------------------------*/
20187 QUnit.module('lodash.size');
20190 var array = [1, 2, 3];
20192 QUnit.test('should return the number of own enumerable string keyed properties of an object', function(assert) {
20195 assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
20198 QUnit.test('should return the length of an array', function(assert) {
20201 assert.strictEqual(_.size(array), 3);
20204 QUnit.test('should accept a falsey `object`', function(assert) {
20207 var expected = lodashStable.map(falsey, stubZero);
20209 var actual = lodashStable.map(falsey, function(object, index) {
20211 return index ? _.size(object) : _.size();
20215 assert.deepEqual(actual, expected);
20218 QUnit.test('should work with `arguments` objects', function(assert) {
20221 assert.strictEqual(_.size(args), 3);
20224 QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
20227 function Foo(elements) {
20228 push.apply(this, elements);
20230 Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
20232 assert.strictEqual(_.size(new Foo(array)), 3);
20235 QUnit.test('should work with maps', function(assert) {
20239 lodashStable.each([new Map, realm.map], function(map) {
20242 assert.strictEqual(_.size(map), 2);
20247 skipAssert(assert, 2);
20251 QUnit.test('should work with sets', function(assert) {
20255 lodashStable.each([new Set, realm.set], function(set) {
20258 assert.strictEqual(_.size(set), 2);
20263 skipAssert(assert, 2);
20267 QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
20270 assert.strictEqual(_.size({ 'length': -1 }), 1);
20273 QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
20276 assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
20279 QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
20282 assert.strictEqual(_.size({ 'length': '0' }), 1);
20286 /*--------------------------------------------------------------------------*/
20288 QUnit.module('lodash.slice');
20291 var array = [1, 2, 3];
20293 QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
20296 var actual = _.slice(array);
20297 assert.deepEqual(actual, array);
20298 assert.notStrictEqual(actual, array);
20301 QUnit.test('should work with a positive `start`', function(assert) {
20304 assert.deepEqual(_.slice(array, 1), [2, 3]);
20305 assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
20308 QUnit.test('should work with a `start` >= `length`', function(assert) {
20311 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
20312 assert.deepEqual(_.slice(array, start), []);
20316 QUnit.test('should treat falsey `start` values as `0`', function(assert) {
20319 var expected = lodashStable.map(falsey, lodashStable.constant(array));
20321 var actual = lodashStable.map(falsey, function(start) {
20322 return _.slice(array, start);
20325 assert.deepEqual(actual, expected);
20328 QUnit.test('should work with a negative `start`', function(assert) {
20331 assert.deepEqual(_.slice(array, -1), [3]);
20334 QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
20337 lodashStable.each([-3, -4, -Infinity], function(start) {
20338 assert.deepEqual(_.slice(array, start), array);
20342 QUnit.test('should work with `start` >= `end`', function(assert) {
20345 lodashStable.each([2, 3], function(start) {
20346 assert.deepEqual(_.slice(array, start, 2), []);
20350 QUnit.test('should work with a positive `end`', function(assert) {
20353 assert.deepEqual(_.slice(array, 0, 1), [1]);
20356 QUnit.test('should work with a `end` >= `length`', function(assert) {
20359 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
20360 assert.deepEqual(_.slice(array, 0, end), array);
20364 QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
20367 var expected = lodashStable.map(falsey, function(value) {
20368 return value === undefined ? array : [];
20371 var actual = lodashStable.map(falsey, function(end, index) {
20372 return index ? _.slice(array, 0, end) : _.slice(array, 0);
20375 assert.deepEqual(actual, expected);
20378 QUnit.test('should work with a negative `end`', function(assert) {
20381 assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
20384 QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
20387 lodashStable.each([-3, -4, -Infinity], function(end) {
20388 assert.deepEqual(_.slice(array, 0, end), []);
20392 QUnit.test('should coerce `start` and `end` to integers', function(assert) {
20395 var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
20397 var actual = lodashStable.map(positions, function(pos) {
20398 return _.slice.apply(_, [array].concat(pos));
20401 assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
20404 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20407 var array = [[1], [2, 3]],
20408 actual = lodashStable.map(array, _.slice);
20410 assert.deepEqual(actual, array);
20411 assert.notStrictEqual(actual, array);
20414 QUnit.test('should work in a lazy sequence', function(assert) {
20418 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
20419 length = array.length,
20420 wrapped = _(array);
20422 lodashStable.each(['map', 'filter'], function(methodName) {
20423 assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
20424 assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
20425 assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
20426 assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
20428 assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
20429 assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
20430 assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
20431 assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
20433 assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
20434 assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
20435 assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
20437 assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
20438 assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
20440 assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
20441 assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
20442 assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
20443 assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
20444 assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
20445 assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
20449 skipAssert(assert, 38);
20454 /*--------------------------------------------------------------------------*/
20456 QUnit.module('lodash.some');
20459 QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
20462 assert.strictEqual(_.some([false, 1, ''], identity), true);
20463 assert.strictEqual(_.some([null, 'a', 0], identity), true);
20466 QUnit.test('should return `false` for empty collections', function(assert) {
20469 var expected = lodashStable.map(empties, stubFalse);
20471 var actual = lodashStable.map(empties, function(value) {
20473 return _.some(value, identity);
20477 assert.deepEqual(actual, expected);
20480 QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
20485 assert.strictEqual(_.some([null, true, null], function(value) {
20490 assert.strictEqual(count, 2);
20493 QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
20496 assert.strictEqual(_.some([false, false, false], identity), false);
20497 assert.strictEqual(_.some([null, 0, ''], identity), false);
20500 QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
20503 var values = [, null, undefined],
20504 expected = lodashStable.map(values, stubFalse);
20506 var actual = lodashStable.map(values, function(value, index) {
20507 var array = [0, 0];
20508 return index ? _.some(array, value) : _.some(array);
20511 assert.deepEqual(actual, expected);
20513 expected = lodashStable.map(values, stubTrue);
20514 actual = lodashStable.map(values, function(value, index) {
20515 var array = [0, 1];
20516 return index ? _.some(array, value) : _.some(array);
20519 assert.deepEqual(actual, expected);
20522 QUnit.test('should work with `_.property` shorthands', function(assert) {
20525 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
20526 assert.strictEqual(_.some(objects, 'a'), false);
20527 assert.strictEqual(_.some(objects, 'b'), true);
20530 QUnit.test('should work with `_.matches` shorthands', function(assert) {
20533 var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
20534 assert.strictEqual(_.some(objects, { 'a': 0 }), true);
20535 assert.strictEqual(_.some(objects, { 'b': 2 }), false);
20538 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20541 var actual = lodashStable.map([[1]], _.some);
20542 assert.deepEqual(actual, [true]);
20546 /*--------------------------------------------------------------------------*/
20548 QUnit.module('lodash.sortBy');
20552 { 'a': 'x', 'b': 3 },
20553 { 'a': 'y', 'b': 4 },
20554 { 'a': 'x', 'b': 1 },
20555 { 'a': 'y', 'b': 2 }
20558 QUnit.test('should sort in ascending order by `iteratee`', function(assert) {
20561 var actual = lodashStable.map(_.sortBy(objects, function(object) {
20565 assert.deepEqual(actual, [1, 2, 3, 4]);
20568 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
20571 var array = [3, 2, 1],
20572 values = [, null, undefined],
20573 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
20575 var actual = lodashStable.map(values, function(value, index) {
20576 return index ? _.sortBy(array, value) : _.sortBy(array);
20579 assert.deepEqual(actual, expected);
20582 QUnit.test('should work with `_.property` shorthands', function(assert) {
20585 var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
20586 assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
20589 QUnit.test('should work with an object for `collection`', function(assert) {
20592 var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, Math.sin);
20593 assert.deepEqual(actual, [3, 1, 2]);
20596 QUnit.test('should move `NaN`, nullish, and symbol values to the end', function(assert) {
20599 var symbol1 = Symbol ? Symbol('a') : null,
20600 symbol2 = Symbol ? Symbol('b') : null,
20601 array = [NaN, undefined, null, 4, symbol1, null, 1, symbol2, undefined, 3, NaN, 2],
20602 expected = [1, 2, 3, 4, symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20604 assert.deepEqual(_.sortBy(array), expected);
20606 array = [NaN, undefined, symbol1, null, 'd', null, 'a', symbol2, undefined, 'c', NaN, 'b'];
20607 expected = ['a', 'b', 'c', 'd', symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
20609 assert.deepEqual(_.sortBy(array), expected);
20612 QUnit.test('should treat number values for `collection` as empty', function(assert) {
20615 assert.deepEqual(_.sortBy(1), []);
20618 QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
20621 var actual = _.sortBy(objects, function(object) {
20622 var result = [object.a, object.b];
20623 result.toString = function() { return String(this[0]); };
20627 assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
20630 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20633 var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
20634 assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
20638 /*--------------------------------------------------------------------------*/
20640 QUnit.module('sortBy methods');
20642 lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
20643 var func = _[methodName];
20645 function Pair(a, b, c) {
20652 { 'a': 'x', 'b': 3 },
20653 { 'a': 'y', 'b': 4 },
20654 { 'a': 'x', 'b': 1 },
20655 { 'a': 'y', 'b': 2 }
20658 var stableArray = [
20659 new Pair(1, 1, 1), new Pair(1, 2, 1),
20660 new Pair(1, 1, 1), new Pair(1, 2, 1),
20661 new Pair(1, 3, 1), new Pair(1, 4, 1),
20662 new Pair(1, 5, 1), new Pair(1, 6, 1),
20663 new Pair(2, 1, 2), new Pair(2, 2, 2),
20664 new Pair(2, 3, 2), new Pair(2, 4, 2),
20665 new Pair(2, 5, 2), new Pair(2, 6, 2),
20666 new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
20667 new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
20668 new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
20671 var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
20673 QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
20676 var actual = func(objects, ['a', 'b']);
20677 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20680 QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
20683 var actual = func(objects, ['a', function(object) { return object.b; }]);
20684 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
20687 QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
20690 lodashStable.each([stableArray, stableObject], function(value, index) {
20691 var actual = func(value, ['a', 'c']);
20692 assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
20696 QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
20700 var actual = func(objects.concat(null, undefined), ['a', 'b']);
20703 assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
20706 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
20710 { 'a': 'x', '0': 3 },
20711 { 'a': 'y', '0': 4 },
20712 { 'a': 'x', '0': 1 },
20713 { 'a': 'y', '0': 2 }
20716 var funcs = [func, lodashStable.partialRight(func, 'bogus')];
20718 lodashStable.each(['a', 0, [0]], function(props, index) {
20719 var expected = lodashStable.map(funcs, lodashStable.constant(
20721 ? [objects[2], objects[3], objects[0], objects[1]]
20722 : [objects[0], objects[2], objects[1], objects[3]]
20725 var actual = lodashStable.map(funcs, function(func) {
20726 return lodashStable.reduce([props], func, objects);
20729 assert.deepEqual(actual, expected);
20734 /*--------------------------------------------------------------------------*/
20736 QUnit.module('sortedIndex methods');
20738 lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
20739 var func = _[methodName],
20740 isSortedIndex = methodName == 'sortedIndex';
20742 QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
20745 var array = [30, 50],
20746 values = [30, 40, 50],
20747 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20749 var actual = lodashStable.map(values, function(value) {
20750 return func(array, value);
20753 assert.deepEqual(actual, expected);
20756 QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
20759 var array = ['a', 'c'],
20760 values = ['a', 'b', 'c'],
20761 expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
20763 var actual = lodashStable.map(values, function(value) {
20764 return func(array, value);
20767 assert.deepEqual(actual, expected);
20770 QUnit.test('`_.' + methodName + '` should accept a nullish `array` and a `value`', function(assert) {
20773 var values = [null, undefined],
20774 expected = lodashStable.map(values, lodashStable.constant([0, 0, 0]));
20776 var actual = lodashStable.map(values, function(array) {
20777 return [func(array, 1), func(array, undefined), func(array, NaN)];
20780 assert.deepEqual(actual, expected);
20783 QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
20786 var symbol1 = Symbol ? Symbol('a') : null,
20787 symbol2 = Symbol ? Symbol('b') : null,
20788 symbol3 = Symbol ? Symbol('c') : null,
20789 expected = [1, '2', {}, symbol1, symbol2, null, undefined, NaN, NaN];
20791 lodashStable.each([
20792 [NaN, symbol1, null, 1, '2', {}, symbol2, NaN, undefined],
20793 ['2', null, 1, symbol1, NaN, {}, NaN, symbol2, undefined]
20794 ], function(array) {
20795 assert.deepEqual(_.sortBy(array), expected);
20796 assert.strictEqual(func(expected, 3), 2);
20797 assert.strictEqual(func(expected, symbol3), isSortedIndex ? 3 : (Symbol ? 5 : 6));
20798 assert.strictEqual(func(expected, null), isSortedIndex ? (Symbol ? 5 : 3) : 6);
20799 assert.strictEqual(func(expected, undefined), isSortedIndex ? 6 : 7);
20800 assert.strictEqual(func(expected, NaN), isSortedIndex ? 7 : 9);
20804 QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for nulls', function(assert) {
20807 var array = [null, null];
20809 assert.strictEqual(func(array, null), isSortedIndex ? 0 : 2);
20810 assert.strictEqual(func(array, 1), 0);
20811 assert.strictEqual(func(array, 'a'), 0);
20814 QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for symbols', function(assert) {
20817 var symbol1 = Symbol ? Symbol('a') : null,
20818 symbol2 = Symbol ? Symbol('b') : null,
20819 symbol3 = Symbol ? Symbol('c') : null,
20820 array = [symbol1, symbol2];
20822 assert.strictEqual(func(array, symbol3), isSortedIndex ? 0 : 2);
20823 assert.strictEqual(func(array, 1), 0);
20824 assert.strictEqual(func(array, 'a'), 0);
20828 /*--------------------------------------------------------------------------*/
20830 QUnit.module('sortedIndexBy methods');
20832 lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
20833 var func = _[methodName],
20834 isSortedIndexBy = methodName == 'sortedIndexBy';
20836 QUnit.test('`_.' + methodName + '` should provide correct `iteratee` arguments', function(assert) {
20841 func([30, 50], 40, function(assert) {
20842 args || (args = slice.call(arguments));
20845 assert.deepEqual(args, [40]);
20848 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
20851 var objects = [{ 'x': 30 }, { 'x': 50 }],
20852 actual = func(objects, { 'x': 40 }, 'x');
20854 assert.strictEqual(actual, 1);
20857 QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
20860 lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
20862 values = [MAX_ARRAY_LENGTH, NaN, undefined];
20864 array.length = length;
20866 lodashStable.each(values, function(value) {
20869 var actual = func(array, value, function(value) {
20874 var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
20876 : Math.min(length, MAX_ARRAY_INDEX);
20878 assert.ok(steps == 32 || steps == 33);
20879 assert.strictEqual(actual, expected);
20885 /*--------------------------------------------------------------------------*/
20887 QUnit.module('sortedIndexOf methods');
20889 lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
20890 var func = _[methodName],
20891 isSortedIndexOf = methodName == 'sortedIndexOf';
20893 QUnit.test('`_.' + methodName + '` should perform a binary search', function(assert) {
20896 var sorted = [4, 4, 5, 5, 6, 6];
20897 assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
20901 /*--------------------------------------------------------------------------*/
20903 QUnit.module('lodash.sortedUniq');
20906 QUnit.test('should return unique values of a sorted array', function(assert) {
20909 var expected = [1, 2, 3];
20911 lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
20912 assert.deepEqual(_.sortedUniq(array), expected);
20917 /*--------------------------------------------------------------------------*/
20919 QUnit.module('lodash.split');
20922 QUnit.test('should split a string by `separator`', function(assert) {
20925 var string = 'abcde';
20926 assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
20927 assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
20928 assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
20931 QUnit.test('should return an array containing an empty string for empty values', function(assert) {
20934 var values = [, null, undefined, ''],
20935 expected = lodashStable.map(values, lodashStable.constant(['']));
20937 var actual = lodashStable.map(values, function(value, index) {
20938 return index ? _.split(value) : _.split();
20941 assert.deepEqual(actual, expected);
20944 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
20947 var strings = ['abc', 'def', 'ghi'],
20948 actual = lodashStable.map(strings, _.split);
20950 assert.deepEqual(actual, [['abc'], ['def'], ['ghi']]);
20953 QUnit.test('should allow mixed string and array prototype methods', function(assert) {
20957 var wrapped = _('abc');
20958 assert.strictEqual(wrapped.split('b').join(','), 'a,c');
20961 skipAssert(assert);
20966 /*--------------------------------------------------------------------------*/
20968 QUnit.module('lodash.spread');
20971 function fn(a, b, c) {
20972 return slice.call(arguments);
20975 QUnit.test('should spread arguments to `func`', function(assert) {
20978 var spread = _.spread(fn),
20981 assert.deepEqual(spread([1, 2]), expected);
20982 assert.deepEqual(spread([1, 2], 3), expected);
20985 QUnit.test('should accept a falsey `array`', function(assert) {
20988 var spread = _.spread(stubTrue),
20989 expected = lodashStable.map(falsey, stubTrue);
20991 var actual = lodashStable.map(falsey, function(array, index) {
20993 return index ? spread(array) : spread();
20997 assert.deepEqual(actual, expected);
21000 QUnit.test('should work with `start`', function(assert) {
21003 var spread = _.spread(fn, 1),
21004 expected = [1, 2, 3];
21006 assert.deepEqual(spread(1, [2, 3]), expected);
21007 assert.deepEqual(spread(1, [2, 3], 4), expected);
21010 QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
21013 var values = [-1, NaN, 'a'],
21014 expected = lodashStable.map(values, lodashStable.constant([1, 2]));
21016 var actual = lodashStable.map(values, function(value) {
21017 var spread = _.spread(fn, value);
21018 return spread([1, 2]);
21021 assert.deepEqual(actual, expected);
21024 QUnit.test('should coerce `start` to an integer', function(assert) {
21027 var spread = _.spread(fn, 1.6),
21028 expected = [1, 2, 3];
21030 assert.deepEqual(spread(1, [2, 3]), expected);
21031 assert.deepEqual(spread(1, [2, 3], 4), expected);
21035 /*--------------------------------------------------------------------------*/
21037 QUnit.module('lodash.startCase');
21040 QUnit.test('should uppercase only the first character of each word', function(assert) {
21043 assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar');
21044 assert.strictEqual(_.startCase('fooBar'), 'Foo Bar');
21045 assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR');
21049 /*--------------------------------------------------------------------------*/
21051 QUnit.module('lodash.startsWith');
21054 var string = 'abc';
21056 QUnit.test('should return `true` if a string starts with `target`', function(assert) {
21059 assert.strictEqual(_.startsWith(string, 'a'), true);
21062 QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
21065 assert.strictEqual(_.startsWith(string, 'b'), false);
21068 QUnit.test('should work with a `position`', function(assert) {
21071 assert.strictEqual(_.startsWith(string, 'b', 1), true);
21074 QUnit.test('should work with `position` >= `length`', function(assert) {
21077 lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
21078 assert.strictEqual(_.startsWith(string, 'a', position), false);
21082 QUnit.test('should treat falsey `position` values as `0`', function(assert) {
21085 var expected = lodashStable.map(falsey, stubTrue);
21087 var actual = lodashStable.map(falsey, function(position) {
21088 return _.startsWith(string, 'a', position);
21091 assert.deepEqual(actual, expected);
21094 QUnit.test('should treat a negative `position` as `0`', function(assert) {
21097 lodashStable.each([-1, -3, -Infinity], function(position) {
21098 assert.strictEqual(_.startsWith(string, 'a', position), true);
21099 assert.strictEqual(_.startsWith(string, 'b', position), false);
21103 QUnit.test('should coerce `position` to an integer', function(assert) {
21106 assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
21110 /*--------------------------------------------------------------------------*/
21112 QUnit.module('lodash.startsWith and lodash.endsWith');
21114 lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
21115 var func = _[methodName],
21116 isStartsWith = methodName == 'startsWith';
21118 var string = 'abc',
21119 chr = isStartsWith ? 'a' : 'c';
21121 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
21124 assert.strictEqual(func(Object(string), chr), true);
21125 assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
21128 QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
21131 assert.strictEqual(func(string, Object(chr)), true);
21132 assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
21135 QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
21138 var position = isStartsWith ? 1 : 2;
21140 assert.strictEqual(func(string, 'b', Object(position)), true);
21141 assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
21144 QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
21147 var positions = [-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity];
21149 assert.ok(lodashStable.every(positions, function(position) {
21150 return func(string, '', position);
21155 /*--------------------------------------------------------------------------*/
21157 QUnit.module('stub methods');
21159 lodashStable.each(['noop', 'stubTrue', 'stubFalse', 'stubArray', 'stubObject', 'stubString'], function(methodName) {
21160 var func = _[methodName];
21163 'stubArray': [[], 'an empty array'],
21164 'stubFalse': [false, '`false`'],
21165 'stubObject': [{}, 'an empty object'],
21166 'stubString': ['', 'an empty string'],
21167 'stubTrue': [true, '`true`'],
21168 'noop': [undefined, '`undefined`']
21171 var values = Array(2).concat(empties, true, 1, 'a'),
21172 expected = lodashStable.map(values, lodashStable.constant(pair[0]));
21174 QUnit.test('`_.' + methodName + '` should return ' + pair[1], function(assert) {
21177 var actual = lodashStable.map(values, function(value, index) {
21179 return index ? func.call({}) : func();
21181 return func(value);
21184 assert.deepEqual(actual, expected);
21188 /*--------------------------------------------------------------------------*/
21190 QUnit.module('lodash.subtract');
21193 QUnit.test('should subtract two numbers', function(assert) {
21196 assert.strictEqual(_.subtract(6, 4), 2);
21197 assert.strictEqual(_.subtract(-6, 4), -10);
21198 assert.strictEqual(_.subtract(-6, -4), -2);
21201 QUnit.test('should coerce arguments to numbers', function(assert) {
21204 assert.strictEqual(_.subtract('6', '4'), 2);
21205 assert.deepEqual(_.subtract('x', 'y'), NaN);
21209 /*--------------------------------------------------------------------------*/
21211 QUnit.module('math operator methods');
21213 lodashStable.each(['add', 'divide', 'multiply', 'subtract'], function(methodName) {
21214 var func = _[methodName],
21215 isAddSub = methodName == 'add' || methodName == 'subtract';
21217 QUnit.test('`_.' + methodName + '` should return `' + (isAddSub ? 0 : 1) + '` when no arguments are given', function(assert) {
21220 assert.strictEqual(func(), isAddSub ? 0 : 1);
21223 QUnit.test('`_.' + methodName + '` should work with only one defined argument', function(assert) {
21226 assert.strictEqual(func(6), 6);
21227 assert.strictEqual(func(6, undefined), 6);
21228 assert.strictEqual(func(undefined, 4), 4);
21231 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
21234 var values = [0, '0', -0, '-0'],
21235 expected = [[0, Infinity], ['0', Infinity], [-0, -Infinity], ['-0', -Infinity]];
21237 lodashStable.times(2, function(index) {
21238 var actual = lodashStable.map(values, function(value) {
21239 var result = index ? func(undefined, value) : func(value);
21240 return [result, 1 / result];
21243 assert.deepEqual(actual, expected);
21247 QUnit.test('`_.' + methodName + '` should convert objects to `NaN`', function(assert) {
21250 assert.deepEqual(func(0, {}), NaN);
21251 assert.deepEqual(func({}, 0), NaN);
21254 QUnit.test('`_.' + methodName + '` should convert symbols to `NaN`', function(assert) {
21258 assert.deepEqual(func(0, symbol), NaN);
21259 assert.deepEqual(func(symbol, 0), NaN);
21262 skipAssert(assert, 2);
21266 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
21270 var actual = _(1)[methodName](2);
21271 assert.notOk(actual instanceof _);
21274 skipAssert(assert);
21278 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
21282 var actual = _(1).chain()[methodName](2);
21283 assert.ok(actual instanceof _);
21286 skipAssert(assert);
21291 /*--------------------------------------------------------------------------*/
21293 QUnit.module('lodash.sumBy');
21296 var array = [6, 4, 2],
21297 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
21299 QUnit.test('should work with an `iteratee`', function(assert) {
21302 var actual = _.sumBy(objects, function(object) {
21306 assert.deepEqual(actual, 6);
21309 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
21314 _.sumBy(array, function() {
21315 args || (args = slice.call(arguments));
21318 assert.deepEqual(args, [6]);
21321 QUnit.test('should work with `_.property` shorthands', function(assert) {
21324 var arrays = [[2], [3], [1]];
21325 assert.strictEqual(_.sumBy(arrays, 0), 6);
21326 assert.strictEqual(_.sumBy(objects, 'a'), 6);
21330 /*--------------------------------------------------------------------------*/
21332 QUnit.module('sum methods');
21334 lodashStable.each(['sum', 'sumBy'], function(methodName) {
21335 var array = [6, 4, 2],
21336 func = _[methodName];
21338 QUnit.test('`_.' + methodName + '` should return the sum of an array of numbers', function(assert) {
21341 assert.strictEqual(func(array), 12);
21344 QUnit.test('`_.' + methodName + '` should return `0` when passing empty `array` values', function(assert) {
21347 var expected = lodashStable.map(empties, stubZero);
21349 var actual = lodashStable.map(empties, function(value) {
21350 return func(value);
21353 assert.deepEqual(actual, expected);
21356 QUnit.test('`_.' + methodName + '` should skip `undefined` values', function(assert) {
21359 assert.strictEqual(func([1, undefined]), 1);
21362 QUnit.test('`_.' + methodName + '` should not skip `NaN` values', function(assert) {
21365 assert.deepEqual(func([1, NaN]), NaN);
21368 QUnit.test('`_.' + methodName + '` should not coerce values to numbers', function(assert) {
21371 assert.strictEqual(func(['1', '2']), '12');
21375 /*--------------------------------------------------------------------------*/
21377 QUnit.module('lodash.tail');
21380 var array = [1, 2, 3];
21382 QUnit.test('should accept a falsey `array`', function(assert) {
21385 var expected = lodashStable.map(falsey, stubArray);
21387 var actual = lodashStable.map(falsey, function(array, index) {
21389 return index ? _.tail(array) : _.tail();
21393 assert.deepEqual(actual, expected);
21396 QUnit.test('should exclude the first element', function(assert) {
21399 assert.deepEqual(_.tail(array), [2, 3]);
21402 QUnit.test('should return an empty when querying empty arrays', function(assert) {
21405 assert.deepEqual(_.tail([]), []);
21408 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21411 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21412 actual = lodashStable.map(array, _.tail);
21414 assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
21417 QUnit.test('should work in a lazy sequence', function(assert) {
21421 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21424 var actual = _(array).tail().filter(function(value) {
21425 values.push(value);
21430 assert.deepEqual(actual, []);
21431 assert.deepEqual(values, array.slice(1));
21435 actual = _(array).filter(function(value) {
21436 values.push(value);
21437 return isEven(value);
21442 assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
21443 assert.deepEqual(values, array);
21446 skipAssert(assert, 4);
21450 QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
21454 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21455 iteratee = function() { pass = false; },
21457 actual = _(array).slice(0, 1).tail().map(iteratee).value();
21460 assert.deepEqual(actual, []);
21463 actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
21466 assert.deepEqual(actual, []);
21469 skipAssert(assert, 4);
21474 /*--------------------------------------------------------------------------*/
21476 QUnit.module('lodash.take');
21479 var array = [1, 2, 3];
21481 QUnit.test('should take the first two elements', function(assert) {
21484 assert.deepEqual(_.take(array, 2), [1, 2]);
21487 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21490 var expected = lodashStable.map(falsey, function(value) {
21491 return value === undefined ? [1] : [];
21494 var actual = lodashStable.map(falsey, function(n) {
21495 return _.take(array, n);
21498 assert.deepEqual(actual, expected);
21501 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21504 lodashStable.each([0, -1, -Infinity], function(n) {
21505 assert.deepEqual(_.take(array, n), []);
21509 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
21512 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21513 assert.deepEqual(_.take(array, n), array);
21517 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21520 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21521 actual = lodashStable.map(array, _.take);
21523 assert.deepEqual(actual, [[1], [4], [7]]);
21526 QUnit.test('should work in a lazy sequence', function(assert) {
21530 var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
21531 predicate = function(value) { values.push(value); return isEven(value); },
21533 actual = _(array).take(2).take().value();
21535 assert.deepEqual(actual, _.take(_.take(array, 2)));
21537 actual = _(array).filter(predicate).take(2).take().value();
21538 assert.deepEqual(values, [1, 2]);
21539 assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
21541 actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
21542 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
21546 actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
21547 assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
21548 assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
21551 skipAssert(assert, 6);
21556 /*--------------------------------------------------------------------------*/
21558 QUnit.module('lodash.takeRight');
21561 var array = [1, 2, 3];
21563 QUnit.test('should take the last two elements', function(assert) {
21566 assert.deepEqual(_.takeRight(array, 2), [2, 3]);
21569 QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
21572 var expected = lodashStable.map(falsey, function(value) {
21573 return value === undefined ? [3] : [];
21576 var actual = lodashStable.map(falsey, function(n) {
21577 return _.takeRight(array, n);
21580 assert.deepEqual(actual, expected);
21583 QUnit.test('should return an empty array when `n` < `1`', function(assert) {
21586 lodashStable.each([0, -1, -Infinity], function(n) {
21587 assert.deepEqual(_.takeRight(array, n), []);
21591 QUnit.test('should return all elements when `n` >= `length`', function(assert) {
21594 lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
21595 assert.deepEqual(_.takeRight(array, n), array);
21599 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
21602 var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
21603 actual = lodashStable.map(array, _.takeRight);
21605 assert.deepEqual(actual, [[3], [6], [9]]);
21608 QUnit.test('should work in a lazy sequence', function(assert) {
21612 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21613 predicate = function(value) { values.push(value); return isEven(value); },
21615 actual = _(array).takeRight(2).takeRight().value();
21617 assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
21619 actual = _(array).filter(predicate).takeRight(2).takeRight().value();
21620 assert.deepEqual(values, array);
21621 assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
21623 actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
21624 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
21628 actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
21629 assert.deepEqual(values, array);
21630 assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
21633 skipAssert(assert, 6);
21638 /*--------------------------------------------------------------------------*/
21640 QUnit.module('lodash.takeRightWhile');
21643 var array = [1, 2, 3, 4];
21646 { 'a': 0, 'b': 0 },
21647 { 'a': 1, 'b': 1 },
21651 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21654 var actual = _.takeRightWhile(array, function(n) {
21658 assert.deepEqual(actual, [3, 4]);
21661 QUnit.test('should provide correct `predicate` arguments', function(assert) {
21666 _.takeRightWhile(array, function() {
21667 args = slice.call(arguments);
21670 assert.deepEqual(args, [4, 3, array]);
21673 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21676 assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
21679 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21682 assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
21685 QUnit.test('should work with `_.property` shorthands', function(assert) {
21688 assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
21691 QUnit.test('should work in a lazy sequence', function(assert) {
21695 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21696 predicate = function(n) { return n > 2; },
21697 expected = _.takeRightWhile(array, predicate),
21698 wrapped = _(array).takeRightWhile(predicate);
21700 assert.deepEqual(wrapped.value(), expected);
21701 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21702 assert.strictEqual(wrapped.last(), _.last(expected));
21705 skipAssert(assert, 3);
21709 QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
21714 array = lodashStable.range(LARGE_ARRAY_SIZE + 1);
21717 square(LARGE_ARRAY_SIZE),
21718 LARGE_ARRAY_SIZE - 1,
21719 lodashStable.map(array.slice(1), square)
21722 _(array).slice(1).takeRightWhile(function(value, index, array) {
21723 args = slice.call(arguments);
21726 assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
21728 _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
21729 args = slice.call(arguments);
21732 assert.deepEqual(args, expected);
21734 _(array).slice(1).map(square).takeRightWhile(function(value, index) {
21735 args = slice.call(arguments);
21738 assert.deepEqual(args, expected);
21740 _(array).slice(1).map(square).takeRightWhile(function(index) {
21741 args = slice.call(arguments);
21744 assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
21746 _(array).slice(1).map(square).takeRightWhile(function() {
21747 args = slice.call(arguments);
21750 assert.deepEqual(args, expected);
21753 skipAssert(assert, 5);
21758 /*--------------------------------------------------------------------------*/
21760 QUnit.module('lodash.takeWhile');
21763 var array = [1, 2, 3, 4];
21766 { 'a': 2, 'b': 2 },
21767 { 'a': 1, 'b': 1 },
21771 QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
21774 var actual = _.takeWhile(array, function(n) {
21778 assert.deepEqual(actual, [1, 2]);
21781 QUnit.test('should provide correct `predicate` arguments', function(assert) {
21786 _.takeWhile(array, function() {
21787 args = slice.call(arguments);
21790 assert.deepEqual(args, [1, 0, array]);
21793 QUnit.test('should work with `_.matches` shorthands', function(assert) {
21796 assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
21799 QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
21802 assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
21804 QUnit.test('should work with `_.property` shorthands', function(assert) {
21807 assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
21810 QUnit.test('should work in a lazy sequence', function(assert) {
21814 var array = lodashStable.range(LARGE_ARRAY_SIZE),
21815 predicate = function(n) { return n < 3; },
21816 expected = _.takeWhile(array, predicate),
21817 wrapped = _(array).takeWhile(predicate);
21819 assert.deepEqual(wrapped.value(), expected);
21820 assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
21821 assert.strictEqual(wrapped.last(), _.last(expected));
21824 skipAssert(assert, 3);
21828 QUnit.test('should work in a lazy sequence with `take`', function(assert) {
21832 var array = lodashStable.range(LARGE_ARRAY_SIZE);
21834 var actual = _(array)
21835 .takeWhile(function(n) { return n < 4; })
21837 .takeWhile(function(n) { return n == 0; })
21840 assert.deepEqual(actual, [0]);
21843 skipAssert(assert);
21847 QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
21852 array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
21853 expected = [1, 0, lodashStable.map(array.slice(1), square)];
21855 _(array).slice(1).takeWhile(function(value, index, array) {
21856 args = slice.call(arguments);
21859 assert.deepEqual(args, [1, 0, array.slice(1)]);
21861 _(array).slice(1).map(square).takeWhile(function(value, index, array) {
21862 args = slice.call(arguments);
21865 assert.deepEqual(args, expected);
21867 _(array).slice(1).map(square).takeWhile(function(value, index) {
21868 args = slice.call(arguments);
21871 assert.deepEqual(args, expected);
21873 _(array).slice(1).map(square).takeWhile(function(value) {
21874 args = slice.call(arguments);
21877 assert.deepEqual(args, [1]);
21879 _(array).slice(1).map(square).takeWhile(function() {
21880 args = slice.call(arguments);
21883 assert.deepEqual(args, expected);
21886 skipAssert(assert, 5);
21891 /*--------------------------------------------------------------------------*/
21893 QUnit.module('lodash.tap');
21896 QUnit.test('should intercept and return the given value', function(assert) {
21903 var actual = _.tap(array, function(value) {
21904 intercepted = value;
21907 assert.strictEqual(actual, array);
21908 assert.strictEqual(intercepted, array);
21911 skipAssert(assert, 2);
21915 QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
21922 var wrapped = _(array).tap(function(value) {
21923 intercepted = value;
21927 assert.ok(wrapped instanceof _);
21930 assert.strictEqual(intercepted, array);
21933 skipAssert(assert, 2);
21938 /*--------------------------------------------------------------------------*/
21940 QUnit.module('lodash.template');
21943 QUnit.test('should escape values in "escape" delimiters', function(assert) {
21946 var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
21947 expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'/</p>')),
21948 data = { 'value': '&<>"\'/' };
21950 var actual = lodashStable.map(strings, function(string) {
21951 return _.template(string)(data);
21954 assert.deepEqual(actual, expected);
21957 QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
21960 var compiled = _.template('<%= typeof __e %>');
21961 assert.strictEqual(compiled({}), 'undefined');
21964 QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
21967 var compiled = _.template(
21969 for (var key in collection) {\
21970 %><li><%= collection[key] %></li><%\
21974 var data = { 'collection': { 'a': 'A', 'b': 'B' } },
21975 actual = compiled(data);
21977 assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
21980 QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
21983 var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
21984 data = { 'value': true };
21986 assert.strictEqual(compiled(data), 'yap');
21989 QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
21992 var compiled = _.template('<% var b = a; %><%= b.value %>'),
21993 data = { 'a': { 'value': 1 } };
21995 assert.strictEqual(compiled(data), '1');
21998 QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
22001 var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
22002 expected = lodashStable.map(strings, lodashStable.constant('ABC')),
22003 data = { 'a': 'A' };
22005 var actual = lodashStable.map(strings, function(string) {
22006 return _.template(string)(data);
22009 assert.deepEqual(actual, expected);
22012 QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
22015 var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
22016 data = { 'a': true };
22018 assert.strictEqual(compiled(data), 'a="A"');
22021 QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
22024 var compiled = _.template('<%= value ? value : "b" %>'),
22025 data = { 'value': 'a' };
22027 assert.strictEqual(compiled(data), 'a');
22030 QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
22033 var compiled = _.template('<%= typeof Math.abs %>');
22036 var actual = compiled();
22039 assert.strictEqual(actual, 'function');
22042 QUnit.test('should support complex "interpolate" delimiters', function(assert) {
22045 lodashStable.forOwn({
22046 '<%= a + b %>': '3',
22047 '<%= b - a %>': '1',
22048 '<%= a = b %>': '2',
22049 '<%= !a %>': 'false',
22051 '<%= a * b %>': '2',
22052 '<%= a / b %>': '0.5',
22053 '<%= a % b %>': '1',
22054 '<%= a >> b %>': '0',
22055 '<%= a << b %>': '4',
22056 '<%= a & b %>': '0',
22057 '<%= a ^ b %>': '3',
22058 '<%= a | b %>': '3',
22059 '<%= {}.toString.call(0) %>': numberTag,
22060 '<%= a.toFixed(2) %>': '1.00',
22061 '<%= obj["a"] %>': '1',
22062 '<%= delete a %>': 'true',
22063 '<%= "a" in obj %>': 'true',
22064 '<%= obj instanceof Object %>': 'true',
22065 '<%= new Boolean %>': 'false',
22066 '<%= typeof a %>': 'number',
22067 '<%= void a %>': ''
22069 function(value, key) {
22070 var compiled = _.template(key),
22071 data = { 'a': 1, 'b': 2 };
22073 assert.strictEqual(compiled(data), value, key);
22077 QUnit.test('should support ES6 template delimiters', function(assert) {
22080 var data = { 'value': 2 };
22081 assert.strictEqual(_.template('1${value}3')(data), '123');
22082 assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
22085 QUnit.test('should support the "imports" option', function(assert) {
22088 var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
22089 assert.strictEqual(compiled({}), '1');
22092 QUnit.test('should support the "variable" options', function(assert) {
22095 var compiled = _.template(
22096 '<% _.each( data.a, function( value ) { %>' +
22097 '<%= value.valueOf() %>' +
22098 '<% }) %>', { 'variable': 'data' }
22101 var data = { 'a': [1, 2, 3] };
22104 assert.strictEqual(compiled(data), '123');
22106 assert.ok(false, e.message);
22110 QUnit.test('should support custom delimiters', function(assert) {
22113 lodashStable.times(2, function(index) {
22114 var settingsClone = lodashStable.clone(_.templateSettings);
22116 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
22117 'escape': /\{\{-([\s\S]+?)\}\}/g,
22118 'evaluate': /\{\{([\s\S]+?)\}\}/g,
22119 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22122 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
22123 compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
22124 data = { 'collection': ['a & A', 'b & B'] };
22126 assert.strictEqual(compiled(data), expected);
22127 lodashStable.assign(_.templateSettings, settingsClone);
22131 QUnit.test('should support custom delimiters containing special characters', function(assert) {
22134 lodashStable.times(2, function(index) {
22135 var settingsClone = lodashStable.clone(_.templateSettings);
22137 var settings = lodashStable.assign(index ? _.templateSettings : {}, {
22138 'escape': /<\?-([\s\S]+?)\?>/g,
22139 'evaluate': /<\?([\s\S]+?)\?>/g,
22140 'interpolate': /<\?=([\s\S]+?)\?>/g
22143 var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
22144 compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
22145 data = { 'collection': ['a & A', 'b & B'] };
22147 assert.strictEqual(compiled(data), expected);
22148 lodashStable.assign(_.templateSettings, settingsClone);
22152 QUnit.test('should use a `with` statement by default', function(assert) {
22155 var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
22156 actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
22158 assert.strictEqual(actual, '1b012');
22161 QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
22164 var lodash = _.templateSettings.imports._,
22165 settingsClone = lodashStable.clone(lodash.templateSettings);
22167 lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
22168 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22171 var compiled = _.template('{{= a }}');
22172 assert.strictEqual(compiled({ 'a': 1 }), '1');
22174 if (settingsClone) {
22175 lodashStable.assign(lodash.templateSettings, settingsClone);
22177 delete lodash.templateSettings;
22181 QUnit.test('should fallback to `_.templateSettings`', function(assert) {
22184 var lodash = _.templateSettings.imports._,
22185 delimiter = _.templateSettings.interpolate;
22187 _.templateSettings.imports._ = { 'escape': lodashStable.escape };
22188 _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
22190 var compiled = _.template('{{= a }}');
22191 assert.strictEqual(compiled({ 'a': 1 }), '1');
22193 _.templateSettings.imports._ = lodash;
22194 _.templateSettings.interpolate = delimiter;
22197 QUnit.test('should ignore `null` delimiters', function(assert) {
22201 'escape': /\{\{-([\s\S]+?)\}\}/g,
22202 'evaluate': /\{\{([\s\S]+?)\}\}/g,
22203 'interpolate': /\{\{=([\s\S]+?)\}\}/g
22206 lodashStable.forOwn({
22207 'escape': '{{- a }}',
22208 'evaluate': '{{ print(a) }}',
22209 'interpolate': '{{= a }}'
22211 function(value, key) {
22212 var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
22213 settings[key] = delimiter[key];
22215 var expected = '1 <%- a %> <% print(a) %> <%= a %>',
22216 compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
22219 assert.strictEqual(compiled(data), expected);
22223 QUnit.test('should work without delimiters', function(assert) {
22226 var expected = 'abc';
22227 assert.strictEqual(_.template(expected)({}), expected);
22230 QUnit.test('should work with `this` references', function(assert) {
22233 var compiled = _.template('a<%= this.String("b") %>c');
22234 assert.strictEqual(compiled(), 'abc');
22236 var object = { 'b': 'B' };
22237 object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
22238 assert.strictEqual(object.compiled(), 'ABC');
22241 QUnit.test('should work with backslashes', function(assert) {
22244 var compiled = _.template('<%= a %> \\b'),
22245 data = { 'a': 'A' };
22247 assert.strictEqual(compiled(data), 'A \\b');
22250 QUnit.test('should work with escaped characters in string literals', function(assert) {
22253 var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
22254 assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
22256 var data = { 'a': 'A' };
22257 compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
22258 assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
22261 QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
22264 var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
22265 assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
22268 QUnit.test('should work with statements containing quotes', function(assert) {
22271 var compiled = _.template("<%\
22272 if (a == 'A' || a == \"a\") {\
22277 var data = { 'a': 'A' };
22278 assert.strictEqual(compiled(data), "'a',\"A\"");
22281 QUnit.test('should work with templates containing newlines and comments', function(assert) {
22284 var compiled = _.template('<%\n\
22285 // A code comment.\n\
22286 if (value) { value += 3; }\n\
22287 %><p><%= value %></p>'
22290 assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
22293 QUnit.test('should tokenize delimiters', function(assert) {
22296 var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
22297 data = { 'type': 1 };
22299 assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
22302 QUnit.test('should evaluate delimiters once', function(assert) {
22306 compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
22307 data = { 'func': function(value) { actual.push(value); } };
22310 assert.deepEqual(actual, ['a', 'b', 'c']);
22313 QUnit.test('should match delimiters before escaping text', function(assert) {
22316 var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
22317 assert.strictEqual(compiled(), '<<\n a \n>>');
22320 QUnit.test('should resolve nullish values to an empty string', function(assert) {
22323 var compiled = _.template('<%= a %><%- a %>'),
22324 data = { 'a': null };
22326 assert.strictEqual(compiled(data), '');
22328 data = { 'a': undefined };
22329 assert.strictEqual(compiled(data), '');
22331 data = { 'a': {} };
22332 compiled = _.template('<%= a.b %><%- a.b %>');
22333 assert.strictEqual(compiled(data), '');
22336 QUnit.test('should return an empty string for empty values', function(assert) {
22339 var values = [, null, undefined, ''],
22340 expected = lodashStable.map(values, stubString),
22343 var actual = lodashStable.map(values, function(value, index) {
22344 var compiled = index ? _.template(value) : _.template();
22345 return compiled(data);
22348 assert.deepEqual(actual, expected);
22351 QUnit.test('should parse delimiters without newlines', function(assert) {
22354 var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
22355 compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
22356 data = { 'value': true };
22358 assert.strictEqual(compiled(data), expected);
22361 QUnit.test('should support recursive calls', function(assert) {
22364 var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
22365 data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
22367 assert.strictEqual(compiled(data), 'AB');
22370 QUnit.test('should coerce `text` to a string', function(assert) {
22373 var object = { 'toString': lodashStable.constant('<%= a %>') },
22376 assert.strictEqual(_.template(object)(data), '1');
22379 QUnit.test('should not modify the `options` object', function(assert) {
22383 _.template('', options);
22384 assert.deepEqual(options, {});
22387 QUnit.test('should not modify `_.templateSettings` when `options` are given', function(assert) {
22390 var data = { 'a': 1 };
22392 assert.notOk('a' in _.templateSettings);
22393 _.template('', {}, data);
22394 assert.notOk('a' in _.templateSettings);
22396 delete _.templateSettings.a;
22399 QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
22403 assert.ok(true, '`data` value');
22405 _.template('', 1)(1);
22406 assert.ok(true, '`options` value');
22409 QUnit.test('should expose the source on compiled templates', function(assert) {
22412 var compiled = _.template('x'),
22413 values = [String(compiled), compiled.source],
22414 expected = lodashStable.map(values, stubTrue);
22416 var actual = lodashStable.map(values, function(value) {
22417 return lodashStable.includes(value, '__p');
22420 assert.deepEqual(actual, expected);
22423 QUnit.test('should expose the source on SyntaxErrors', function(assert) {
22427 _.template('<% if x %>');
22429 var source = e.source;
22431 assert.ok(lodashStable.includes(source, '__p'));
22434 QUnit.test('should not include sourceURLs in the source', function(assert) {
22437 var options = { 'sourceURL': '/a/b/c' },
22438 compiled = _.template('x', options),
22439 values = [compiled.source, undefined];
22442 _.template('<% if x %>', options);
22444 values[1] = e.source;
22446 var expected = lodashStable.map(values, stubFalse);
22448 var actual = lodashStable.map(values, function(value) {
22449 return lodashStable.includes(value, 'sourceURL');
22452 assert.deepEqual(actual, expected);
22455 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22458 var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
22459 compiles = lodashStable.map(array, _.template),
22460 data = { 'a': 'one', 'b': '"two"', 'c': 'three' };
22462 var actual = lodashStable.map(compiles, function(compiled) {
22463 return compiled(data);
22466 assert.deepEqual(actual, ['one', '"two"', 'three']);
22470 /*--------------------------------------------------------------------------*/
22472 QUnit.module('lodash.truncate');
22475 var string = 'hi-diddly-ho there, neighborino';
22477 QUnit.test('should use a default `length` of `30`', function(assert) {
22480 assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
22483 QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
22486 assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
22487 assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
22490 QUnit.test('should truncate string the given length', function(assert) {
22493 assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
22496 QUnit.test('should support a `omission` option', function(assert) {
22499 assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
22502 QUnit.test('should coerce nullish `omission` values to strings', function(assert) {
22505 assert.strictEqual(_.truncate(string, { 'omission': null }), 'hi-diddly-ho there, neighbnull');
22506 assert.strictEqual(_.truncate(string, { 'omission': undefined }), 'hi-diddly-ho there, nundefined');
22509 QUnit.test('should support a `length` option', function(assert) {
22512 assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
22515 QUnit.test('should support a `separator` option', function(assert) {
22518 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
22519 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
22520 assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
22523 QUnit.test('should treat negative `length` as `0`', function(assert) {
22526 lodashStable.each([0, -2], function(length) {
22527 assert.strictEqual(_.truncate(string, { 'length': length }), '...');
22531 QUnit.test('should coerce `length` to an integer', function(assert) {
22534 lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
22535 var actual = index > 1 ? 'h...' : '...';
22536 assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
22540 QUnit.test('should coerce `string` to a string', function(assert) {
22543 assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
22544 assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
22547 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22550 var actual = lodashStable.map([string, string, string], _.truncate),
22551 truncated = 'hi-diddly-ho there, neighbo...';
22553 assert.deepEqual(actual, [truncated, truncated, truncated]);
22557 /*--------------------------------------------------------------------------*/
22559 QUnit.module('lodash.throttle');
22562 QUnit.test('should throttle a function', function(assert) {
22565 var done = assert.async();
22568 throttled = _.throttle(function() { callCount++; }, 32);
22574 var lastCount = callCount;
22575 assert.ok(callCount);
22577 setTimeout(function() {
22578 assert.ok(callCount > lastCount);
22583 QUnit.test('subsequent calls should return the result of the first call', function(assert) {
22586 var done = assert.async();
22588 var throttled = _.throttle(identity, 32),
22589 results = [throttled('a'), throttled('b')];
22591 assert.deepEqual(results, ['a', 'a']);
22593 setTimeout(function() {
22594 var results = [throttled('c'), throttled('d')];
22595 assert.notEqual(results[0], 'a');
22596 assert.notStrictEqual(results[0], undefined);
22598 assert.notEqual(results[1], 'd');
22599 assert.notStrictEqual(results[1], undefined);
22604 QUnit.test('should clear timeout when `func` is called', function(assert) {
22607 var done = assert.async();
22609 if (!isModularize) {
22613 var lodash = _.runInContext({
22615 'now': function() {
22616 return ++dateCount == 5 ? Infinity : +new Date;
22621 var throttled = lodash.throttle(function() { callCount++; }, 32);
22626 setTimeout(function() {
22627 assert.strictEqual(callCount, 2);
22632 skipAssert(assert);
22637 QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
22640 var done = assert.async();
22643 throttled = _.throttle(function() { callCount++; }, 32);
22646 assert.strictEqual(callCount, 1);
22648 setTimeout(function() {
22649 assert.strictEqual(callCount, 1);
22654 lodashStable.times(2, function(index) {
22655 QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
22658 var done = assert.async();
22661 limit = (argv || isPhantom) ? 1000 : 320,
22662 options = index ? { 'leading': false } : {},
22663 throttled = _.throttle(function() { callCount++; }, 32, options);
22665 var start = +new Date;
22666 while ((new Date - start) < limit) {
22669 var actual = callCount > 1;
22670 setTimeout(function() {
22677 QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
22680 var done = assert.async();
22684 var throttled = _.throttle(function() {
22686 }, 128, { 'leading': false });
22690 setTimeout(function() {
22691 assert.strictEqual(callCount, 1);
22695 setTimeout(function() {
22696 assert.strictEqual(callCount, 1);
22699 setTimeout(function() {
22700 assert.strictEqual(callCount, 2);
22705 QUnit.test('should apply default options', function(assert) {
22708 var done = assert.async();
22711 throttled = _.throttle(function() { callCount++; }, 32, {});
22715 assert.strictEqual(callCount, 1);
22717 setTimeout(function() {
22718 assert.strictEqual(callCount, 2);
22723 QUnit.test('should support a `leading` option', function(assert) {
22726 var withLeading = _.throttle(identity, 32, { 'leading': true });
22727 assert.strictEqual(withLeading('a'), 'a');
22729 var withoutLeading = _.throttle(identity, 32, { 'leading': false });
22730 assert.strictEqual(withoutLeading('a'), undefined);
22733 QUnit.test('should support a `trailing` option', function(assert) {
22736 var done = assert.async();
22741 var withTrailing = _.throttle(function(value) {
22744 }, 64, { 'trailing': true });
22746 var withoutTrailing = _.throttle(function(value) {
22749 }, 64, { 'trailing': false });
22751 assert.strictEqual(withTrailing('a'), 'a');
22752 assert.strictEqual(withTrailing('b'), 'a');
22754 assert.strictEqual(withoutTrailing('a'), 'a');
22755 assert.strictEqual(withoutTrailing('b'), 'a');
22757 setTimeout(function() {
22758 assert.strictEqual(withCount, 2);
22759 assert.strictEqual(withoutCount, 1);
22764 QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
22767 var done = assert.async();
22771 var throttled = _.throttle(function() {
22773 }, 64, { 'trailing': false });
22778 setTimeout(function() {
22783 setTimeout(function() {
22784 assert.ok(callCount > 1);
22789 QUnit.test('should work with a system time of `0`', function(assert) {
22792 var done = assert.async();
22794 if (!isModularize) {
22798 var lodash = _.runInContext({
22800 'now': function() {
22801 return ++dateCount < 4 ? 0 : +new Date;
22806 var throttled = lodash.throttle(function(value) {
22811 var results = [throttled('a'), throttled('b'), throttled('c')];
22812 assert.deepEqual(results, ['a', 'a', 'a']);
22813 assert.strictEqual(callCount, 1);
22815 setTimeout(function() {
22816 assert.strictEqual(callCount, 2);
22821 skipAssert(assert, 3);
22827 /*--------------------------------------------------------------------------*/
22829 QUnit.module('lodash.debounce and lodash.throttle');
22831 lodashStable.each(['debounce', 'throttle'], function(methodName) {
22832 var func = _[methodName],
22833 isDebounce = methodName == 'debounce';
22835 QUnit.test('`_.' + methodName + '` should not error for non-object `options` values', function(assert) {
22842 QUnit.test('`_.' + methodName + '` should use a default `wait` of `0`', function(assert) {
22845 var done = assert.async();
22848 funced = func(function() { callCount++; });
22852 setTimeout(function() {
22854 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22859 QUnit.test('`_.' + methodName + '` should invoke `func` with the correct `this` binding', function(assert) {
22862 var done = assert.async();
22865 object = { 'funced': func(function() { actual.push(this); }, 32) },
22866 expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
22872 setTimeout(function() {
22873 assert.deepEqual(actual, expected);
22878 QUnit.test('`_.' + methodName + '` supports recursive calls', function(assert) {
22881 var done = assert.async();
22884 args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
22885 expected = args.slice(),
22886 queue = args.slice();
22888 var funced = func(function() {
22889 var current = [this];
22890 push.apply(current, arguments);
22891 actual.push(current);
22893 var next = queue.shift();
22895 funced.call(next[0], next[1]);
22899 var next = queue.shift();
22900 funced.call(next[0], next[1]);
22901 assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
22903 setTimeout(function() {
22904 assert.deepEqual(actual, expected.slice(0, actual.length));
22909 QUnit.test('`_.' + methodName + '` should work if the system time is set backwards', function(assert) {
22912 var done = assert.async();
22914 if (!isModularize) {
22918 var lodash = _.runInContext({
22920 'now': function() {
22921 return ++dateCount == 4
22922 ? +new Date(2012, 3, 23, 23, 27, 18)
22928 var funced = lodash[methodName](function() {
22934 setTimeout(function() {
22936 assert.strictEqual(callCount, isDebounce ? 1 : 2);
22941 skipAssert(assert);
22946 QUnit.test('`_.' + methodName + '` should support cancelling delayed calls', function(assert) {
22949 var done = assert.async();
22953 var funced = func(function() {
22955 }, 32, { 'leading': false });
22960 setTimeout(function() {
22961 assert.strictEqual(callCount, 0);
22966 QUnit.test('`_.' + methodName + '` should reset `lastCalled` after cancelling', function(assert) {
22969 var done = assert.async();
22973 var funced = func(function() {
22974 return ++callCount;
22975 }, 32, { 'leading': true });
22977 assert.strictEqual(funced(), 1);
22980 assert.strictEqual(funced(), 2);
22983 setTimeout(function() {
22984 assert.strictEqual(callCount, 3);
22989 QUnit.test('`_.' + methodName + '` should support flushing delayed calls', function(assert) {
22992 var done = assert.async();
22996 var funced = func(function() {
22997 return ++callCount;
22998 }, 32, { 'leading': false });
23001 assert.strictEqual(funced.flush(), 1);
23003 setTimeout(function() {
23004 assert.strictEqual(callCount, 1);
23009 QUnit.test('`_.' + methodName + '` should noop `cancel` and `flush` when nothing is queued', function(assert) {
23012 var done = assert.async();
23015 funced = func(function() { callCount++; }, 32);
23018 assert.strictEqual(funced.flush(), undefined);
23020 setTimeout(function() {
23021 assert.strictEqual(callCount, 0);
23027 /*--------------------------------------------------------------------------*/
23029 QUnit.module('lodash.times');
23032 QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
23035 lodashStable.each([-Infinity, NaN, Infinity], function(n) {
23036 assert.deepEqual(_.times(n), []);
23040 QUnit.test('should coerce `n` to an integer', function(assert) {
23043 var actual = _.times(2.6, _.identity);
23044 assert.deepEqual(actual, [0, 1]);
23047 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
23052 _.times(1, function(assert) {
23053 args || (args = slice.call(arguments));
23056 assert.deepEqual(args, [0]);
23059 QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
23062 var values = [, null, undefined],
23063 expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
23065 var actual = lodashStable.map(values, function(value, index) {
23066 return index ? _.times(3, value) : _.times(3);
23069 assert.deepEqual(actual, expected);
23072 QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
23075 assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
23078 QUnit.test('should return an empty array for falsey and negative `n` values', function(assert) {
23081 var values = falsey.concat(-1, -Infinity),
23082 expected = lodashStable.map(values, stubArray);
23084 var actual = lodashStable.map(values, function(value, index) {
23085 return index ? _.times(value) : _.times();
23088 assert.deepEqual(actual, expected);
23091 QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
23095 assert.deepEqual(_(3).times(), [0, 1, 2]);
23098 skipAssert(assert);
23102 QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
23106 assert.ok(_(3).chain().times() instanceof _);
23109 skipAssert(assert);
23114 /*--------------------------------------------------------------------------*/
23116 QUnit.module('lodash.toArray');
23119 QUnit.test('should convert objects to arrays', function(assert) {
23122 assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
23125 QUnit.test('should convert iterables to arrays', function(assert) {
23128 if (Symbol && Symbol.iterator) {
23129 var object = { '0': 'a', 'length': 1 };
23130 object[Symbol.iterator] = arrayProto[Symbol.iterator];
23132 assert.deepEqual(_.toArray(object), ['a']);
23135 skipAssert(assert);
23139 QUnit.test('should convert maps to arrays', function(assert) {
23146 assert.deepEqual(_.toArray(map), [['a', 1], ['b', 2]]);
23149 skipAssert(assert);
23153 QUnit.test('should convert strings to arrays', function(assert) {
23156 assert.deepEqual(_.toArray(''), []);
23157 assert.deepEqual(_.toArray('ab'), ['a', 'b']);
23158 assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
23161 QUnit.test('should work in a lazy sequence', function(assert) {
23165 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1);
23167 var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
23168 return ['key' + index, index];
23171 var actual = _(array).slice(1).map(String).toArray().value();
23172 assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
23174 actual = _(object).toArray().slice(1).map(String).value();
23175 assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
23178 skipAssert(assert, 2);
23183 /*--------------------------------------------------------------------------*/
23185 QUnit.module('lodash.toLower');
23188 QUnit.test('should convert whole string to lower case', function(assert) {
23191 assert.deepEqual(_.toLower('--Foo-Bar--'), '--foo-bar--');
23192 assert.deepEqual(_.toLower('fooBar'), 'foobar');
23193 assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
23197 /*--------------------------------------------------------------------------*/
23199 QUnit.module('lodash.toUpper');
23202 QUnit.test('should convert whole string to upper case', function(assert) {
23205 assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
23206 assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
23207 assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
23211 /*--------------------------------------------------------------------------*/
23213 QUnit.module('lodash.slice and lodash.toArray');
23215 lodashStable.each(['slice', 'toArray'], function(methodName) {
23216 var array = [1, 2, 3],
23217 func = _[methodName];
23219 QUnit.test('`_.' + methodName + '` should return a dense array', function(assert) {
23222 var sparse = Array(3);
23225 var actual = func(sparse);
23227 assert.ok('0' in actual);
23228 assert.ok('2' in actual);
23229 assert.deepEqual(actual, sparse);
23232 QUnit.test('`_.' + methodName + '` should treat array-like objects like arrays', function(assert) {
23235 var object = { '0': 'a', 'length': 1 };
23236 assert.deepEqual(func(object), ['a']);
23237 assert.deepEqual(func(args), array);
23240 QUnit.test('`_.' + methodName + '` should return a shallow clone of arrays', function(assert) {
23243 var actual = func(array);
23244 assert.deepEqual(actual, array);
23245 assert.notStrictEqual(actual, array);
23248 QUnit.test('`_.' + methodName + '` should work with a node list for `collection`', function(assert) {
23253 var actual = func(document.getElementsByTagName('body'));
23256 assert.deepEqual(actual, [body]);
23259 skipAssert(assert);
23264 /*--------------------------------------------------------------------------*/
23266 QUnit.module('toInteger methods');
23268 lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
23269 var func = _[methodName],
23270 isSafe = methodName == 'toSafeInteger';
23272 QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
23275 assert.strictEqual(func(-5.6), -5);
23276 assert.strictEqual(func('5.6'), 5);
23277 assert.strictEqual(func(), 0);
23278 assert.strictEqual(func(NaN), 0);
23280 var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
23281 assert.strictEqual(func(Infinity), expected);
23282 assert.strictEqual(func(-Infinity), -expected);
23285 QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
23288 assert.strictEqual(1 / func(-0), -Infinity);
23292 /*--------------------------------------------------------------------------*/
23294 QUnit.module('lodash.toLength');
23297 QUnit.test('should return a valid length', function(assert) {
23300 assert.strictEqual(_.toLength(-1), 0);
23301 assert.strictEqual(_.toLength('1'), 1);
23302 assert.strictEqual(_.toLength(1.1), 1);
23303 assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
23306 QUnit.test('should return `value` if a valid length', function(assert) {
23309 assert.strictEqual(_.toLength(0), 0);
23310 assert.strictEqual(_.toLength(3), 3);
23311 assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
23314 QUnit.test('should convert `-0` to `0`', function(assert) {
23317 assert.strictEqual(1 / _.toLength(-0), Infinity);
23321 /*--------------------------------------------------------------------------*/
23323 QUnit.module('number coercion methods');
23325 lodashStable.each(['toFinite', 'toInteger', 'toNumber', 'toSafeInteger'], function(methodName) {
23326 var func = _[methodName];
23328 QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
23331 var values = [0, '0', -0, '-0'],
23332 expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
23334 lodashStable.times(2, function(index) {
23335 var others = lodashStable.map(values, index ? Object : identity);
23337 var actual = lodashStable.map(others, function(value) {
23338 var result = func(value);
23339 return [result, 1 / result];
23342 assert.deepEqual(actual, expected);
23347 lodashStable.each(['toFinite', 'toInteger', 'toLength', 'toNumber', 'toSafeInteger'], function(methodName) {
23348 var func = _[methodName],
23349 isToFinite = methodName == 'toFinite',
23350 isToLength = methodName == 'toLength',
23351 isToNumber = methodName == 'toNumber',
23352 isToSafeInteger = methodName == 'toSafeInteger';
23354 function negative(string) {
23355 return '-' + string;
23358 function pad(string) {
23359 return whitespace + string + whitespace;
23362 function positive(string) {
23363 return '+' + string;
23366 QUnit.test('`_.' + methodName + '` should pass thru primitive number values', function(assert) {
23369 var values = [0, 1, NaN];
23371 var expected = lodashStable.map(values, function(value) {
23372 return (!isToNumber && value !== value) ? 0 : value;
23375 var actual = lodashStable.map(values, func);
23377 assert.deepEqual(actual, expected);
23380 QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
23383 var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
23385 var expected = lodashStable.map(values, function(value) {
23387 if (!isToFinite && value == 1.2) {
23390 else if (value == Infinity) {
23391 value = MAX_INTEGER;
23393 else if (value !== value) {
23396 if (isToLength || isToSafeInteger) {
23397 value = Math.min(value, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
23400 var neg = isToLength ? 0 : -value;
23401 return [value, value, neg, neg];
23404 var actual = lodashStable.map(values, function(value) {
23405 return [func(value), func(Object(value)), func(-value), func(Object(-value))];
23408 assert.deepEqual(actual, expected);
23411 QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
23414 var transforms = [identity, pad, positive, negative];
23417 '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
23418 '1e+308', '1e308', '1E+308', '1E308',
23419 '5e-324', '5E-324',
23423 var expected = lodashStable.map(values, function(value) {
23426 if (!isToFinite && n == 1.234567890) {
23429 else if (n == Infinity) {
23432 else if ((!isToFinite && n == Number.MIN_VALUE) || n !== n) {
23435 if (isToLength || isToSafeInteger) {
23436 n = Math.min(n, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
23439 var neg = isToLength ? 0 : -n;
23440 return [n, n, n, n, n, n, neg, neg];
23443 var actual = lodashStable.map(values, function(value) {
23444 return lodashStable.flatMap(transforms, function(mod) {
23445 return [func(mod(value)), func(Object(mod(value)))];
23449 assert.deepEqual(actual, expected);
23452 QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
23455 var numbers = [42, 5349, 1715004],
23456 transforms = [identity, pad],
23457 values = ['0b101010', '0o12345', '0x1a2b3c'];
23459 var expected = lodashStable.map(numbers, function(n) {
23460 return lodashStable.times(8, lodashStable.constant(n));
23463 var actual = lodashStable.map(values, function(value) {
23464 var upper = value.toUpperCase();
23465 return lodashStable.flatMap(transforms, function(mod) {
23466 return [func(mod(value)), func(Object(mod(value))), func(mod(upper)), func(Object(mod(upper)))];
23470 assert.deepEqual(actual, expected);
23473 QUnit.test('`_.' + methodName + '` should convert invalid binary/octal strings to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23476 var transforms = [identity, pad, positive, negative],
23477 values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
23479 var expected = lodashStable.map(values, function(n) {
23480 return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
23483 var actual = lodashStable.map(values, function(value) {
23484 return lodashStable.flatMap(transforms, function(mod) {
23485 return [func(mod(value)), func(Object(mod(value)))];
23489 assert.deepEqual(actual, expected);
23492 QUnit.test('`_.' + methodName + '` should convert symbols to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
23496 var object1 = Object(symbol),
23497 object2 = Object(symbol),
23498 values = [symbol, object1, object2],
23499 expected = lodashStable.map(values, lodashStable.constant(isToNumber ? NaN : 0));
23501 object2.valueOf = undefined;
23502 var actual = lodashStable.map(values, func);
23504 assert.deepEqual(actual, expected);
23507 skipAssert(assert);
23511 QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
23514 var values = falsey.concat(whitespace);
23516 var expected = lodashStable.map(values, function(value) {
23517 return (isToNumber && value !== whitespace) ? Number(value) : 0;
23520 var actual = lodashStable.map(values, function(value, index) {
23521 return index ? func(value) : func();
23524 assert.deepEqual(actual, expected);
23527 QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
23535 { 'valueOf': '1.1' },
23536 { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
23537 { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
23538 { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
23539 { 'valueOf': lodashStable.constant('-0x1a2b3c') },
23540 { 'toString': lodashStable.constant('-0x1a2b3c') },
23541 { 'valueOf': lodashStable.constant('0o12345') },
23542 { 'toString': lodashStable.constant('0o12345') },
23543 { 'valueOf': lodashStable.constant('0b101010') },
23544 { 'toString': lodashStable.constant('0b101010') }
23549 NaN, 2.2, 1.1, 1.1,
23564 else if (!isToNumber) {
23573 var actual = lodashStable.map(values, func);
23575 assert.deepEqual(actual, expected);
23579 /*--------------------------------------------------------------------------*/
23581 QUnit.module('lodash.toPairs');
23584 QUnit.test('should be aliased', function(assert) {
23587 assert.strictEqual(_.entries, _.toPairs);
23591 /*--------------------------------------------------------------------------*/
23593 QUnit.module('lodash.toPairsIn');
23596 QUnit.test('should be aliased', function(assert) {
23599 assert.strictEqual(_.entriesIn, _.toPairsIn);
23603 /*--------------------------------------------------------------------------*/
23605 QUnit.module('toPairs methods');
23607 lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) {
23608 var func = _[methodName],
23609 isToPairs = methodName == 'toPairs';
23611 QUnit.test('`_.' + methodName + '` should create an array of string keyed-value pairs', function(assert) {
23614 var object = { 'a': 1, 'b': 2 },
23615 actual = lodashStable.sortBy(func(object), 0);
23617 assert.deepEqual(actual, [['a', 1], ['b', 2]]);
23620 QUnit.test('`_.' + methodName + '` should ' + (isToPairs ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
23626 Foo.prototype.b = 2;
23628 var expected = isToPairs ? [['a', 1]] : [['a', 1], ['b', 2]],
23629 actual = lodashStable.sortBy(func(new Foo), 0);
23631 assert.deepEqual(actual, expected);
23634 QUnit.test('`_.' + methodName + '` should convert objects with a `length` property', function(assert) {
23637 var object = { '0': 'a', '1': 'b', 'length': 2 },
23638 actual = lodashStable.sortBy(func(object), 0);
23640 assert.deepEqual(actual, [['0', 'a'], ['1', 'b'], ['length', 2]]);
23643 QUnit.test('`_.' + methodName + '` should convert maps', function(assert) {
23650 assert.deepEqual(func(map), [['a', 1], ['b', 2]]);
23653 skipAssert(assert);
23657 QUnit.test('`_.' + methodName + '` should convert sets', function(assert) {
23664 assert.deepEqual(func(set), [[1, 1], [2, 2]]);
23667 skipAssert(assert);
23671 QUnit.test('`_.' + methodName + '` should convert strings', function(assert) {
23674 lodashStable.each(['xo', Object('xo')], function(string) {
23675 var actual = lodashStable.sortBy(func(string), 0);
23676 assert.deepEqual(actual, [['0', 'x'], ['1', 'o']]);
23681 /*--------------------------------------------------------------------------*/
23683 QUnit.module('lodash.toPath');
23686 QUnit.test('should convert a string to a path', function(assert) {
23689 assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
23690 assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
23693 QUnit.test('should coerce array elements to strings', function(assert) {
23696 var array = ['a', 'b', 'c'];
23698 lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
23699 var actual = _.toPath(value);
23700 assert.deepEqual(actual, array);
23701 assert.notStrictEqual(actual, array);
23705 QUnit.test('should return new path array', function(assert) {
23708 assert.notStrictEqual(_.toPath('a.b.c'), _.toPath('a.b.c'));
23711 QUnit.test('should not coerce symbols to strings', function(assert) {
23715 var object = Object(symbol);
23716 lodashStable.each([symbol, object, [symbol], [object]], function(value) {
23717 var actual = _.toPath(value);
23718 assert.ok(lodashStable.isSymbol(actual[0]));
23722 skipAssert(assert, 4);
23726 QUnit.test('should handle complex paths', function(assert) {
23729 var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
23730 assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
23733 QUnit.test('should handle consecutive empty brackets and dots', function(assert) {
23736 var expected = ['', 'a'];
23737 assert.deepEqual(_.toPath('.a'), expected);
23738 assert.deepEqual(_.toPath('[].a'), expected);
23740 expected = ['', '', 'a'];
23741 assert.deepEqual(_.toPath('..a'), expected);
23742 assert.deepEqual(_.toPath('[][].a'), expected);
23744 expected = ['a', '', 'b'];
23745 assert.deepEqual(_.toPath('a..b'), expected);
23746 assert.deepEqual(_.toPath('a[].b'), expected);
23748 expected = ['a', '', '', 'b'];
23749 assert.deepEqual(_.toPath('a...b'), expected);
23750 assert.deepEqual(_.toPath('a[][].b'), expected);
23752 expected = ['a', ''];
23753 assert.deepEqual(_.toPath('a.'), expected);
23754 assert.deepEqual(_.toPath('a[]'), expected);
23756 expected = ['a', '', ''];
23757 assert.deepEqual(_.toPath('a..'), expected);
23758 assert.deepEqual(_.toPath('a[][]'), expected);
23762 /*--------------------------------------------------------------------------*/
23764 QUnit.module('lodash.toPlainObject');
23767 QUnit.test('should flatten inherited string keyed properties', function(assert) {
23773 Foo.prototype.c = 3;
23775 var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
23776 assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
23779 QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
23782 var actual = _.toPlainObject(args),
23783 expected = { '0': 1, '1': 2, '2': 3 };
23785 assert.deepEqual(actual, expected);
23788 QUnit.test('should convert arrays to plain objects', function(assert) {
23791 var actual = _.toPlainObject(['a', 'b', 'c']),
23792 expected = { '0': 'a', '1': 'b', '2': 'c' };
23794 assert.deepEqual(actual, expected);
23798 /*--------------------------------------------------------------------------*/
23800 QUnit.module('lodash.toString');
23803 QUnit.test('should treat nullish values as empty strings', function(assert) {
23806 var values = [, null, undefined],
23807 expected = lodashStable.map(values, stubString);
23809 var actual = lodashStable.map(values, function(value, index) {
23810 return index ? _.toString(value) : _.toString();
23813 assert.deepEqual(actual, expected);
23816 QUnit.test('should preserve the sign of `0`', function(assert) {
23819 var values = [-0, Object(-0), 0, Object(0)],
23820 expected = ['-0', '-0', '0', '0'],
23821 actual = lodashStable.map(values, _.toString);
23823 assert.deepEqual(actual, expected);
23826 QUnit.test('should preserve the sign of `0` in an array', function(assert) {
23829 var values = [-0, Object(-0), 0, Object(0)];
23830 assert.deepEqual(_.toString(values), '-0,-0,0,0');
23833 QUnit.test('should not error on symbols', function(assert) {
23838 assert.strictEqual(_.toString(symbol), 'Symbol(a)');
23840 assert.ok(false, e.message);
23844 skipAssert(assert);
23848 QUnit.test('should not error on an array of symbols', function(assert) {
23853 assert.strictEqual(_.toString([symbol]), 'Symbol(a)');
23855 assert.ok(false, e.message);
23859 skipAssert(assert);
23863 QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
23867 var wrapped = _([1, 2, 3]);
23868 assert.strictEqual(wrapped.toString(), '1,2,3');
23871 skipAssert(assert);
23876 /*--------------------------------------------------------------------------*/
23878 QUnit.module('lodash.transform');
23887 QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
23890 var accumulators = [, null, undefined],
23892 expected = lodashStable.map(accumulators, stubTrue);
23894 var iteratee = function(result, value, key) {
23895 result[key] = square(value);
23898 var mapper = function(accumulator, index) {
23899 return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
23902 var results = lodashStable.map(accumulators, mapper);
23904 var actual = lodashStable.map(results, function(result) {
23905 return result instanceof Foo;
23908 assert.deepEqual(actual, expected);
23910 expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
23911 actual = lodashStable.map(results, lodashStable.toPlainObject);
23913 assert.deepEqual(actual, expected);
23915 object = { 'a': 1, 'b': 2, 'c': 3 };
23916 actual = lodashStable.map(accumulators, mapper);
23918 assert.deepEqual(actual, expected);
23920 object = [1, 2, 3];
23921 expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
23922 actual = lodashStable.map(accumulators, mapper);
23924 assert.deepEqual(actual, expected);
23927 QUnit.test('should create regular arrays from typed arrays', function(assert) {
23930 var expected = lodashStable.map(typedArrays, stubTrue);
23932 var actual = lodashStable.map(typedArrays, function(type) {
23933 var Ctor = root[type],
23934 array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
23936 return lodashStable.isArray(_.transform(array, noop));
23939 assert.deepEqual(actual, expected);
23942 QUnit.test('should support an `accumulator` value', function(assert) {
23945 var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
23946 expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
23948 var actual = lodashStable.map(values, function(value) {
23949 return _.transform(value, function(result, value) {
23950 result.push(square(value));
23954 assert.deepEqual(actual, expected);
23956 var object = { 'a': 1, 'b': 4, 'c': 9 },
23957 expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
23959 actual = lodashStable.map(values, function(value) {
23960 return _.transform(value, function(result, value, key) {
23961 result[key] = square(value);
23965 assert.deepEqual(actual, expected);
23967 lodashStable.each([[], {}], function(accumulator) {
23968 var actual = lodashStable.map(values, function(value) {
23969 return _.transform(value, noop, accumulator);
23972 assert.ok(lodashStable.every(actual, function(result) {
23973 return result === accumulator;
23976 assert.strictEqual(_.transform(null, null, accumulator), accumulator);
23980 QUnit.test('should treat sparse arrays as dense', function(assert) {
23983 var actual = _.transform(Array(1), function(result, value, index) {
23984 result[index] = String(value);
23987 assert.deepEqual(actual, ['undefined']);
23990 QUnit.test('should work without an `iteratee`', function(assert) {
23993 assert.ok(_.transform(new Foo) instanceof Foo);
23996 QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
23999 var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
24000 values = [false, true, 0, 1, NaN, '', 'a'],
24001 expected = lodashStable.map(values, stubObject);
24003 var results = lodashStable.map(values, function(value) {
24004 return _.transform(value);
24007 assert.deepEqual(results, expected);
24009 expected = lodashStable.map(values, stubFalse);
24011 var actual = lodashStable.map(results, function(value, index) {
24012 return value instanceof Ctors[index];
24015 assert.deepEqual(actual, expected);
24018 QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
24021 Foo.prototype.constructor = null;
24022 assert.notOk(_.transform(new Foo) instanceof Foo);
24023 Foo.prototype.constructor = Foo;
24026 QUnit.test('should create an empty object when given a falsey `object`', function(assert) {
24029 var expected = lodashStable.map(falsey, stubObject);
24031 var actual = lodashStable.map(falsey, function(object, index) {
24032 return index ? _.transform(object) : _.transform();
24035 assert.deepEqual(actual, expected);
24038 lodashStable.each({
24039 'array': [1, 2, 3],
24040 'object': { 'a': 1, 'b': 2, 'c': 3 }
24042 function(object, key) {
24043 QUnit.test('should provide correct `iteratee` arguments when transforming an ' + key, function(assert) {
24048 _.transform(object, function() {
24049 args || (args = slice.call(arguments));
24052 var first = args[0];
24053 if (key == 'array') {
24054 assert.ok(first !== object && lodashStable.isArray(first));
24055 assert.deepEqual(args, [first, 1, 0, object]);
24057 assert.ok(first !== object && lodashStable.isPlainObject(first));
24058 assert.deepEqual(args, [first, 1, 'a', object]);
24063 QUnit.test('should create an object from the same realm as `object`', function(assert) {
24066 var objects = lodashStable.filter(realm, function(value) {
24067 return lodashStable.isObject(value) && !lodashStable.isElement(value);
24070 var expected = lodashStable.map(objects, stubTrue);
24072 var actual = lodashStable.map(objects, function(object) {
24073 var Ctor = object.constructor,
24074 result = _.transform(object);
24076 if (result === object) {
24079 if (lodashStable.isTypedArray(object)) {
24080 return result instanceof Array;
24082 return result instanceof Ctor || !(new Ctor instanceof Ctor);
24085 assert.deepEqual(actual, expected);
24089 /*--------------------------------------------------------------------------*/
24091 QUnit.module('trim methods');
24093 lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
24094 var func = _[methodName],
24098 parts.push('leading');
24101 parts.push('trailing');
24103 parts = parts.join(' and ');
24105 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
24108 var string = whitespace + 'a b c' + whitespace,
24109 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24111 assert.strictEqual(func(string), expected);
24114 QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
24117 var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
24118 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24120 assert.strictEqual(func(object), expected);
24123 QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
24126 var string = '-_-a-b-c-_-',
24127 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
24129 assert.strictEqual(func(string, '_-'), expected);
24132 QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
24135 var object = { 'toString': lodashStable.constant('_-') },
24136 string = '-_-a-b-c-_-',
24137 expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
24139 assert.strictEqual(func(string, object), expected);
24142 QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
24145 lodashStable.each([null, '_-'], function(chars) {
24146 assert.strictEqual(func(null, chars), '');
24147 assert.strictEqual(func(undefined, chars), '');
24148 assert.strictEqual(func('', chars), '');
24152 QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
24155 var string = whitespace + 'a b c' + whitespace,
24156 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24158 assert.strictEqual(func(string, undefined), expected);
24159 assert.strictEqual(func(string, ''), string);
24162 QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
24165 var string = Object(whitespace + 'a b c' + whitespace),
24166 trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
24167 actual = lodashStable.map([string, string, string], func);
24169 assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
24172 QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
24176 var string = whitespace + 'a b c' + whitespace,
24177 expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
24179 assert.strictEqual(_(string)[methodName](), expected);
24182 skipAssert(assert);
24186 QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
24190 var string = whitespace + 'a b c' + whitespace;
24191 assert.ok(_(string).chain()[methodName]() instanceof _);
24194 skipAssert(assert);
24199 /*--------------------------------------------------------------------------*/
24201 QUnit.module('uncommon symbols');
24204 var flag = '\ud83c\uddfa\ud83c\uddf8',
24205 heart = '\u2764' + emojiVar,
24206 hearts = '\ud83d\udc95',
24207 comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68',
24208 hashKeycap = '#' + emojiVar + '\u20e3',
24209 leafs = '\ud83c\udf42',
24210 mic = '\ud83c\udf99',
24211 noMic = mic + '\u20e0',
24212 raisedHand = '\u270B' + emojiVar,
24213 rocket = '\ud83d\ude80',
24214 thumbsUp = '\ud83d\udc4d';
24216 QUnit.test('should account for astral symbols', function(assert) {
24219 var allHearts = _.repeat(hearts, 10),
24220 chars = hearts + comboGlyph,
24221 string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
24222 trimChars = comboGlyph + hearts,
24223 trimString = trimChars + string + trimChars;
24225 assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
24226 assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
24227 assert.strictEqual(_.capitalize(rocket), rocket);
24229 assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
24230 assert.strictEqual(_.padStart(string, 16), ' ' + string);
24231 assert.strictEqual(_.padEnd(string, 16), string + ' ');
24233 assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
24234 assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
24235 assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
24237 assert.strictEqual(_.size(string), 13);
24238 assert.deepEqual(_.split(string, ' '), ['A', leafs + ',', comboGlyph + ',', 'and', rocket]);
24239 assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
24240 assert.deepEqual(_.split(string, undefined), [string]);
24241 assert.deepEqual(_.split(string, undefined, -1), [string]);
24242 assert.deepEqual(_.split(string, undefined, 0), []);
24244 var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];
24246 assert.deepEqual(_.split(string, ''), expected);
24247 assert.deepEqual(_.split(string, '', 6), expected.slice(0, 6));
24248 assert.deepEqual(_.toArray(string), expected);
24250 assert.strictEqual(_.trim(trimString, chars), string);
24251 assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
24252 assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
24254 assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
24255 assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
24257 assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
24258 assert.deepEqual(_.toArray(hashKeycap), [hashKeycap]);
24259 assert.deepEqual(_.toArray(noMic), [noMic]);
24261 lodashStable.times(2, function(index) {
24262 var separator = index ? RegExp(hearts) : hearts,
24263 options = { 'length': 4, 'separator': separator },
24264 actual = _.truncate(string, options);
24266 assert.strictEqual(actual, 'A...');
24267 assert.strictEqual(actual.length, 4);
24269 actual = _.truncate(allHearts, options);
24270 assert.strictEqual(actual, hearts + '...');
24271 assert.strictEqual(actual.length, 5);
24275 QUnit.test('should account for combining diacritical marks', function(assert) {
24278 var values = lodashStable.map(comboMarks, function(mark) {
24282 var expected = lodashStable.map(values, function(value) {
24283 return [1, [value], [value]];
24286 var actual = lodashStable.map(values, function(value) {
24287 return [_.size(value), _.toArray(value), _.words(value)];
24290 assert.deepEqual(actual, expected);
24293 QUnit.test('should account for fitzpatrick modifiers', function(assert) {
24296 var values = lodashStable.map(fitzModifiers, function(modifier) {
24297 return thumbsUp + modifier;
24300 var expected = lodashStable.map(values, function(value) {
24301 return [1, [value], [value]];
24304 var actual = lodashStable.map(values, function(value) {
24305 return [_.size(value), _.toArray(value), _.words(value)];
24308 assert.deepEqual(actual, expected);
24311 QUnit.test('should account for regional symbols', function(assert) {
24314 var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
24315 regionals = pair.join(' ');
24317 assert.strictEqual(_.size(flag), 1);
24318 assert.strictEqual(_.size(regionals), 3);
24320 assert.deepEqual(_.toArray(flag), [flag]);
24321 assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
24323 assert.deepEqual(_.words(flag), [flag]);
24324 assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
24327 QUnit.test('should account for variation selectors', function(assert) {
24330 assert.strictEqual(_.size(heart), 1);
24331 assert.deepEqual(_.toArray(heart), [heart]);
24332 assert.deepEqual(_.words(heart), [heart]);
24335 QUnit.test('should account for variation selectors with fitzpatrick modifiers', function(assert) {
24338 var values = lodashStable.map(fitzModifiers, function(modifier) {
24339 return raisedHand + modifier;
24342 var expected = lodashStable.map(values, function(value) {
24343 return [1, [value], [value]];
24346 var actual = lodashStable.map(values, function(value) {
24347 return [_.size(value), _.toArray(value), _.words(value)];
24350 assert.deepEqual(actual, expected);
24353 QUnit.test('should match lone surrogates', function(assert) {
24356 var pair = hearts.split(''),
24357 surrogates = pair[0] + ' ' + pair[1];
24359 assert.strictEqual(_.size(surrogates), 3);
24360 assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
24361 assert.deepEqual(_.words(surrogates), []);
24364 QUnit.test('should match side by side fitzpatrick modifiers separately ', function(assert) {
24367 var string = fitzModifiers[0] + fitzModifiers[0];
24368 assert.deepEqual(_.toArray(string), [fitzModifiers[0], fitzModifiers[0]]);
24372 /*--------------------------------------------------------------------------*/
24374 QUnit.module('lodash.unary');
24378 return slice.call(arguments);
24381 QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
24384 var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
24385 assert.deepEqual(actual, [6, 8, 10]);
24388 QUnit.test('should not force a minimum argument count', function(assert) {
24391 var capped = _.unary(fn);
24392 assert.deepEqual(capped(), []);
24395 QUnit.test('should use `this` binding of function', function(assert) {
24398 var capped = _.unary(function(a, b) { return this; }),
24399 object = { 'capped': capped };
24401 assert.strictEqual(object.capped(), object);
24405 /*--------------------------------------------------------------------------*/
24407 QUnit.module('lodash.unescape');
24410 var escaped = '&<>"'/',
24411 unescaped = '&<>"\'/';
24413 escaped += escaped;
24414 unescaped += unescaped;
24416 QUnit.test('should unescape entities in order', function(assert) {
24419 assert.strictEqual(_.unescape('&lt;'), '<');
24422 QUnit.test('should unescape the proper entities', function(assert) {
24425 assert.strictEqual(_.unescape(escaped), unescaped);
24428 QUnit.test('should handle strings with nothing to unescape', function(assert) {
24431 assert.strictEqual(_.unescape('abc'), 'abc');
24434 QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
24437 assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
24440 lodashStable.each(['`', '/'], function(entity) {
24441 QUnit.test('should not unescape the "' + entity + '" entity', function(assert) {
24444 assert.strictEqual(_.unescape(entity), entity);
24449 /*--------------------------------------------------------------------------*/
24451 QUnit.module('union methods');
24453 lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
24454 var func = _[methodName];
24456 QUnit.test('`_.' + methodName + '` should return the union of two arrays', function(assert) {
24459 var actual = func([2], [1, 2]);
24460 assert.deepEqual(actual, [2, 1]);
24463 QUnit.test('`_.' + methodName + '` should return the union of multiple arrays', function(assert) {
24466 var actual = func([2], [1, 2], [2, 3]);
24467 assert.deepEqual(actual, [2, 1, 3]);
24470 QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
24473 var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
24474 assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
24477 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
24481 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
24482 assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
24483 assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
24487 /*--------------------------------------------------------------------------*/
24489 QUnit.module('lodash.unionBy');
24492 QUnit.test('should accept an `iteratee`', function(assert) {
24495 var actual = _.unionBy([2.1], [1.2, 2.3], Math.floor);
24496 assert.deepEqual(actual, [2.1, 1.2]);
24498 actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
24499 assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
24502 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
24507 _.unionBy([2.1], [1.2, 2.3], function() {
24508 args || (args = slice.call(arguments));
24511 assert.deepEqual(args, [2.1]);
24514 QUnit.test('should output values from the first possible array', function(assert) {
24517 var actual = _.unionBy([{ 'x': 1, 'y': 1 }], [{ 'x': 1, 'y': 2 }], 'x');
24518 assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]);
24522 /*--------------------------------------------------------------------------*/
24524 QUnit.module('lodash.unionWith');
24527 QUnit.test('should work with a `comparator`', function(assert) {
24530 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
24531 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
24532 actual = _.unionWith(objects, others, lodashStable.isEqual);
24534 assert.deepEqual(actual, [objects[0], objects[1], others[0]]);
24537 QUnit.test('should output values from the first possible array', function(assert) {
24540 var objects = [{ 'x': 1, 'y': 1 }],
24541 others = [{ 'x': 1, 'y': 2 }];
24543 var actual = _.unionWith(objects, others, function(a, b) {
24547 assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]);
24551 /*--------------------------------------------------------------------------*/
24553 QUnit.module('uniq methods');
24555 lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
24556 var func = _[methodName],
24557 isSorted = /^sorted/.test(methodName),
24558 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24561 objects = _.sortBy(objects, 'a');
24564 QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
24567 var array = [2, 1, 2];
24568 assert.deepEqual(func(array), [2, 1]);
24571 QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
24574 var array = [1, 2, 2];
24575 assert.deepEqual(func(array), [1, 2]);
24578 QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
24581 assert.deepEqual(func(objects), objects);
24584 QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
24587 var actual = lodashStable.map(func([-0, 0]), lodashStable.toString);
24588 assert.deepEqual(actual, ['0']);
24591 QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
24594 assert.deepEqual(func([NaN, NaN]), [NaN]);
24597 QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
24600 var largeArray = [],
24601 expected = [0, {}, 'a'],
24602 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24604 lodashStable.each(expected, function(value) {
24605 lodashStable.times(count, function() {
24606 largeArray.push(value);
24610 assert.deepEqual(func(largeArray), expected);
24613 QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
24616 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24617 return isEven(index) ? -0 : 0;
24620 var actual = lodashStable.map(func(largeArray), lodashStable.toString);
24621 assert.deepEqual(actual, ['0']);
24624 QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
24627 var largeArray = [],
24628 expected = [null, undefined, false, true, NaN],
24629 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24631 lodashStable.each(expected, function(value) {
24632 lodashStable.times(count, function() {
24633 largeArray.push(value);
24637 assert.deepEqual(func(largeArray), expected);
24640 QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
24644 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
24645 assert.deepEqual(func(largeArray), largeArray);
24648 skipAssert(assert);
24652 QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
24655 // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
24658 Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
24659 Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
24660 Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
24663 var largeArray = [],
24664 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24666 expected = lodashStable.map(expected, function(symbol) {
24667 return symbol || {};
24670 lodashStable.each(expected, function(value) {
24671 lodashStable.times(count, function() {
24672 largeArray.push(value);
24676 assert.deepEqual(func(largeArray), expected);
24679 skipAssert(assert);
24683 QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
24686 var largeArray = [],
24687 expected = ['2', 2, Object('2'), Object(2)],
24688 count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
24690 lodashStable.each(expected, function(value) {
24691 lodashStable.times(count, function() {
24692 largeArray.push(value);
24696 assert.deepEqual(func(largeArray), expected);
24700 /*--------------------------------------------------------------------------*/
24702 QUnit.module('lodash.uniq');
24705 QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
24708 var array = [[2, 1, 2], [1, 2, 1]],
24709 actual = lodashStable.map(array, lodashStable.uniq);
24711 assert.deepEqual(actual, [[2, 1], [1, 2]]);
24715 /*--------------------------------------------------------------------------*/
24717 QUnit.module('uniqBy methods');
24719 lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
24720 var func = _[methodName],
24721 isSorted = methodName == 'sortedUniqBy',
24722 objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
24725 objects = _.sortBy(objects, 'a');
24727 QUnit.test('`_.' + methodName + '` should work with an `iteratee`', function(assert) {
24730 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
24732 var actual = func(objects, function(object) {
24736 assert.deepEqual(actual, expected);
24739 QUnit.test('should work with large arrays', function(assert) {
24742 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
24746 var actual = func(largeArray, String);
24747 assert.strictEqual(actual[0], largeArray[0]);
24748 assert.deepEqual(actual, [[1, 2]]);
24751 QUnit.test('`_.' + methodName + '` should provide correct `iteratee` arguments', function(assert) {
24756 func(objects, function() {
24757 args || (args = slice.call(arguments));
24760 assert.deepEqual(args, [objects[0]]);
24763 QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
24766 var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
24767 actual = func(objects, 'a');
24769 assert.deepEqual(actual, expected);
24771 var arrays = [[2], [3], [1], [2], [3], [1]];
24773 arrays = lodashStable.sortBy(arrays, 0);
24775 expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
24776 actual = func(arrays, 0);
24778 assert.deepEqual(actual, expected);
24781 lodashStable.each({
24782 'an array': [0, 'a'],
24783 'an object': { '0': 'a' },
24787 function(iteratee, key) {
24788 QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
24791 var actual = func([['a'], ['a'], ['b']], iteratee);
24792 assert.deepEqual(actual, [['a'], ['b']]);
24797 /*--------------------------------------------------------------------------*/
24799 QUnit.module('lodash.uniqWith');
24802 QUnit.test('should work with a `comparator`', function(assert) {
24805 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }],
24806 actual = _.uniqWith(objects, lodashStable.isEqual);
24808 assert.deepEqual(actual, [objects[0], objects[1]]);
24811 QUnit.test('should preserve the sign of `0`', function(assert) {
24814 var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
24815 return isEven(index) ? -0 : 0;
24818 var arrays = [[-0, 0], largeArray],
24819 expected = lodashStable.map(arrays, lodashStable.constant(['-0']));
24821 var actual = lodashStable.map(arrays, function(array) {
24822 return lodashStable.map(_.uniqWith(array, lodashStable.eq), lodashStable.toString);
24825 assert.deepEqual(actual, expected);
24829 /*--------------------------------------------------------------------------*/
24831 QUnit.module('lodash.uniqueId');
24834 QUnit.test('should generate unique ids', function(assert) {
24837 var actual = lodashStable.times(1000, function(assert) {
24838 return _.uniqueId();
24841 assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
24844 QUnit.test('should return a string value when not providing a `prefix`', function(assert) {
24847 assert.strictEqual(typeof _.uniqueId(), 'string');
24850 QUnit.test('should coerce the prefix argument to a string', function(assert) {
24853 var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
24854 assert.ok(/3\d+,2\d+,1\d+/.test(actual));
24858 /*--------------------------------------------------------------------------*/
24860 QUnit.module('lodash.unset');
24863 QUnit.test('should unset property values', function(assert) {
24866 lodashStable.each(['a', ['a']], function(path) {
24867 var object = { 'a': 1, 'c': 2 };
24868 assert.strictEqual(_.unset(object, path), true);
24869 assert.deepEqual(object, { 'c': 2 });
24873 QUnit.test('should preserve the sign of `0`', function(assert) {
24876 var props = [-0, Object(-0), 0, Object(0)],
24877 expected = lodashStable.map(props, lodashStable.constant([true, false]));
24879 var actual = lodashStable.map(props, function(key) {
24880 var object = { '-0': 'a', '0': 'b' };
24881 return [_.unset(object, key), lodashStable.toString(key) in object];
24884 assert.deepEqual(actual, expected);
24887 QUnit.test('should unset symbol keyed property values', function(assert) {
24892 object[symbol] = 1;
24894 assert.strictEqual(_.unset(object, symbol), true);
24895 assert.notOk(symbol in object);
24898 skipAssert(assert, 2);
24902 QUnit.test('should unset deep property values', function(assert) {
24905 lodashStable.each(['a.b', ['a', 'b']], function(path) {
24906 var object = { 'a': { 'b': null } };
24907 assert.strictEqual(_.unset(object, path), true);
24908 assert.deepEqual(object, { 'a': {} });
24912 QUnit.test('should handle complex paths', function(assert) {
24916 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
24917 ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
24920 lodashStable.each(paths, function(path) {
24921 var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
24922 assert.strictEqual(_.unset(object, path), true);
24923 assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
24927 QUnit.test('should return `true` for nonexistent paths', function(assert) {
24930 var object = { 'a': { 'b': { 'c': null } } };
24932 lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
24933 assert.strictEqual(_.unset(object, path), true);
24936 assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
24939 QUnit.test('should not error when `object` is nullish', function(assert) {
24942 var values = [null, undefined],
24943 expected = [[true, true], [true, true]];
24945 var actual = lodashStable.map(values, function(value) {
24947 return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
24953 assert.deepEqual(actual, expected);
24956 QUnit.test('should follow `path` over non-plain objects', function(assert) {
24959 var object = { 'a': '' },
24960 paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
24962 lodashStable.each(paths, function(path) {
24965 var actual = _.unset(0, path);
24966 assert.strictEqual(actual, true);
24967 assert.notOk('a' in numberProto);
24969 delete numberProto.a;
24972 lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
24973 stringProto.replace.b = 1;
24975 var actual = _.unset(object, path);
24976 assert.strictEqual(actual, true);
24977 assert.notOk('a' in stringProto.replace);
24979 delete stringProto.replace.b;
24983 QUnit.test('should return `false` for non-configurable properties', function(assert) {
24989 defineProperty(object, 'a', {
24990 'configurable': false,
24991 'enumerable': true,
24995 assert.strictEqual(_.unset(object, 'a'), false);
24998 skipAssert(assert);
25003 /*--------------------------------------------------------------------------*/
25005 QUnit.module('lodash.unzipWith');
25008 QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
25011 var array = [[1, 4], [2, 5], [3, 6]];
25013 var actual = _.unzipWith(array, function(a, b, c) {
25017 assert.deepEqual(actual, [6, 15]);
25020 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
25025 _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
25026 args || (args = slice.call(arguments));
25029 assert.deepEqual(args, [1, 2]);
25032 QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
25035 var array = [[1, 3], [2, 4]],
25036 values = [, null, undefined],
25037 expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
25039 var actual = lodashStable.map(values, function(value, index) {
25040 return index ? _.unzipWith(array, value) : _.unzipWith(array);
25043 assert.deepEqual(actual, expected);
25047 /*--------------------------------------------------------------------------*/
25049 QUnit.module('lodash.updateWith');
25052 QUnit.test('should work with a `customizer` callback', function(assert) {
25055 var actual = _.updateWith({ '0': {} }, '[0][1][2]', stubThree, function(value) {
25056 return lodashStable.isObject(value) ? undefined : {};
25059 assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
25062 QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
25065 var actual = _.updateWith({}, 'a[0].b.c', stubFour, noop);
25066 assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
25070 /*--------------------------------------------------------------------------*/
25072 QUnit.module('update methods');
25074 lodashStable.each(['update', 'updateWith'], function(methodName) {
25075 var func = _[methodName],
25078 QUnit.test('`_.' + methodName + '` should invoke `updater` with the value on `path` of `object`', function(assert) {
25081 var object = { 'a': [{ 'b': { 'c': oldValue } }] },
25082 expected = oldValue + 1;
25084 lodashStable.each(['a[0].b.c', ['a', '0', 'b', 'c']], function(path) {
25085 func(object, path, function(n) {
25086 assert.strictEqual(n, oldValue);
25090 assert.strictEqual(object.a[0].b.c, expected);
25091 object.a[0].b.c = oldValue;
25096 /*--------------------------------------------------------------------------*/
25098 QUnit.module('lodash.upperCase');
25101 QUnit.test('should uppercase as space-separated words', function(assert) {
25104 assert.strictEqual(_.upperCase('--foo-bar--'), 'FOO BAR');
25105 assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
25106 assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
25110 /*--------------------------------------------------------------------------*/
25112 QUnit.module('lodash.upperFirst');
25115 QUnit.test('should uppercase only the first character', function(assert) {
25118 assert.strictEqual(_.upperFirst('fred'), 'Fred');
25119 assert.strictEqual(_.upperFirst('Fred'), 'Fred');
25120 assert.strictEqual(_.upperFirst('FRED'), 'FRED');
25124 /*--------------------------------------------------------------------------*/
25126 QUnit.module('values methods');
25128 lodashStable.each(['values', 'valuesIn'], function(methodName) {
25129 var func = _[methodName],
25130 isValues = methodName == 'values';
25132 QUnit.test('`_.' + methodName + '` should get string keyed values of `object`', function(assert) {
25135 var object = { 'a': 1, 'b': 2 },
25136 actual = func(object).sort();
25138 assert.deepEqual(actual, [1, 2]);
25141 QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
25144 var object = { '0': 'a', '1': 'b', 'length': 2 },
25145 actual = func(object).sort();
25147 assert.deepEqual(actual, [2, 'a', 'b']);
25150 QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
25156 Foo.prototype.b = 2;
25158 var expected = isValues ? [1] : [1, 2],
25159 actual = func(new Foo).sort();
25161 assert.deepEqual(actual, expected);
25164 QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
25167 var values = [args, strictArgs],
25168 expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
25170 var actual = lodashStable.map(values, function(value) {
25171 return func(value).sort();
25174 assert.deepEqual(actual, expected);
25178 /*--------------------------------------------------------------------------*/
25180 QUnit.module('lodash.without');
25183 QUnit.test('should return the difference of values', function(assert) {
25186 var actual = _.without([2, 1, 2, 3], 1, 2);
25187 assert.deepEqual(actual, [3]);
25190 QUnit.test('should use strict equality to determine the values to reject', function(assert) {
25193 var object1 = { 'a': 1 },
25194 object2 = { 'b': 2 },
25195 array = [object1, object2];
25197 assert.deepEqual(_.without(array, { 'a': 1 }), array);
25198 assert.deepEqual(_.without(array, object1), [object2]);
25201 QUnit.test('should remove all occurrences of each value from an array', function(assert) {
25204 var array = [1, 2, 3, 1, 2, 3];
25205 assert.deepEqual(_.without(array, 1, 2), [3, 3]);
25209 /*--------------------------------------------------------------------------*/
25211 QUnit.module('lodash.words');
25214 QUnit.test('should match words containing Latin Unicode letters', function(assert) {
25217 var expected = lodashStable.map(burredLetters, function(letter) {
25221 var actual = lodashStable.map(burredLetters, function(letter) {
25222 return _.words(letter);
25225 assert.deepEqual(actual, expected);
25228 QUnit.test('should support a `pattern`', function(assert) {
25231 assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
25232 assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
25235 QUnit.test('should work with compound words', function(assert) {
25238 assert.deepEqual(_.words('12ft'), ['12', 'ft']);
25239 assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
25240 assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']);
25241 assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']);
25242 assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']);
25243 assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
25244 assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
25245 assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
25246 assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
25247 assert.deepEqual(_.words('XMLHttp'), ['XML', 'Http']);
25248 assert.deepEqual(_.words('XmlHTTP'), ['Xml', 'HTTP']);
25249 assert.deepEqual(_.words('XmlHttp'), ['Xml', 'Http']);
25252 QUnit.test('should work with compound words containing diacritical marks', function(assert) {
25255 assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
25256 assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
25257 assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
25260 QUnit.test('should not treat contractions as separate words', function(assert) {
25263 var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
25265 lodashStable.each(["'", '\u2019'], function(apos) {
25266 lodashStable.times(2, function(index) {
25267 var actual = lodashStable.map(postfixes, function(postfix) {
25268 var string = 'a b' + apos + postfix + ' c';
25269 return _.words(string[index ? 'toUpperCase' : 'toLowerCase']());
25272 var expected = lodashStable.map(postfixes, function(postfix) {
25273 var words = ['a', 'b' + apos + postfix, 'c'];
25274 return lodashStable.map(words, function(word) {
25275 return word[index ? 'toUpperCase' : 'toLowerCase']();
25279 assert.deepEqual(actual, expected);
25284 QUnit.test('should not treat ordinal numbers as separate words', function(assert) {
25287 var ordinals = ['1st', '2nd', '3rd', '4th'];
25289 lodashStable.times(2, function(index) {
25290 var expected = lodashStable.map(ordinals, function(ordinal) {
25291 return [ordinal[index ? 'toUpperCase' : 'toLowerCase']()];
25294 var actual = lodashStable.map(expected, function(words) {
25295 return _.words(words[0]);
25298 assert.deepEqual(actual, expected);
25302 QUnit.test('should not treat mathematical operators as words', function(assert) {
25305 var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
25306 expected = lodashStable.map(operators, stubArray),
25307 actual = lodashStable.map(operators, _.words);
25309 assert.deepEqual(actual, expected);
25312 QUnit.test('should not treat punctuation as words', function(assert) {
25316 '\u2012', '\u2013', '\u2014', '\u2015',
25317 '\u2024', '\u2025', '\u2026',
25321 var expected = lodashStable.map(marks, stubArray),
25322 actual = lodashStable.map(marks, _.words);
25324 assert.deepEqual(actual, expected);
25327 QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
25330 var strings = lodashStable.map(['a', 'b', 'c'], Object),
25331 actual = lodashStable.map(strings, _.words);
25333 assert.deepEqual(actual, [['a'], ['b'], ['c']]);
25337 /*--------------------------------------------------------------------------*/
25339 QUnit.module('lodash.wrap');
25342 QUnit.test('should create a wrapped function', function(assert) {
25345 var p = _.wrap(lodashStable.escape, function(func, text) {
25346 return '<p>' + func(text) + '</p>';
25349 assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
25352 QUnit.test('should provide correct `wrapper` arguments', function(assert) {
25357 var wrapped = _.wrap(noop, function() {
25358 args || (args = slice.call(arguments));
25362 assert.deepEqual(args, [noop, 1, 2, 3]);
25365 QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
25368 var values = [, null, undefined],
25369 expected = lodashStable.map(values, stubA);
25371 var actual = lodashStable.map(values, function(value, index) {
25372 var wrapped = index ? _.wrap('a', value) : _.wrap('a');
25373 return wrapped('b', 'c');
25376 assert.deepEqual(actual, expected);
25379 QUnit.test('should use `this` binding of function', function(assert) {
25382 var p = _.wrap(lodashStable.escape, function(func) {
25383 return '<p>' + func(this.text) + '</p>';
25386 var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
25387 assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
25391 /*--------------------------------------------------------------------------*/
25393 QUnit.module('xor methods');
25395 lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
25396 var func = _[methodName];
25398 QUnit.test('`_.' + methodName + '` should return the symmetric difference of two arrays', function(assert) {
25401 var actual = func([2, 1], [2, 3]);
25402 assert.deepEqual(actual, [1, 3]);
25405 QUnit.test('`_.' + methodName + '` should return the symmetric difference of multiple arrays', function(assert) {
25408 var actual = func([2, 1], [2, 3], [3, 4]);
25409 assert.deepEqual(actual, [1, 4]);
25411 actual = func([1, 2], [2, 1], [1, 2]);
25412 assert.deepEqual(actual, []);
25415 QUnit.test('`_.' + methodName + '` should return an empty array when comparing the same array', function(assert) {
25419 actual = func(array, array, array);
25421 assert.deepEqual(actual, []);
25424 QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
25427 var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
25428 assert.deepEqual(actual, [1, 4]);
25430 actual = func([1, 1]);
25431 assert.deepEqual(actual, [1]);
25434 QUnit.test('`_.' + methodName + '` should return a new array when a single array is given', function(assert) {
25438 assert.notStrictEqual(func(array), array);
25441 QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
25445 assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
25448 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
25451 var array = [1, 2];
25452 assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
25453 assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
25454 assert.deepEqual(func(array, null, args, null), [3]);
25457 QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
25461 var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
25462 assert.ok(wrapped instanceof _);
25465 skipAssert(assert);
25469 QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
25473 var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
25474 wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
25476 var actual = lodashStable.map(['head', 'last'], function(methodName) {
25477 return wrapped[methodName]();
25480 assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
25483 skipAssert(assert);
25488 /*--------------------------------------------------------------------------*/
25490 QUnit.module('lodash.xorBy');
25493 QUnit.test('should accept an `iteratee`', function(assert) {
25496 var actual = _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
25497 assert.deepEqual(actual, [1.2, 3.4]);
25499 actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
25500 assert.deepEqual(actual, [{ 'x': 2 }]);
25503 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
25508 _.xorBy([2.1, 1.2], [2.3, 3.4], function() {
25509 args || (args = slice.call(arguments));
25512 assert.deepEqual(args, [2.3]);
25516 /*--------------------------------------------------------------------------*/
25518 QUnit.module('lodash.xorWith');
25521 QUnit.test('should work with a `comparator`', function(assert) {
25524 var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
25525 others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
25526 actual = _.xorWith(objects, others, lodashStable.isEqual);
25528 assert.deepEqual(actual, [objects[1], others[0]]);
25532 /*--------------------------------------------------------------------------*/
25534 QUnit.module('zipObject methods');
25536 lodashStable.each(['zipObject', 'zipObjectDeep'], function(methodName) {
25537 var func = _[methodName],
25538 object = { 'barney': 36, 'fred': 40 },
25539 isDeep = methodName == 'zipObjectDeep';
25541 QUnit.test('`_.' + methodName + '` should zip together key/value arrays into an object', function(assert) {
25544 var actual = func(['barney', 'fred'], [36, 40]);
25545 assert.deepEqual(actual, object);
25548 QUnit.test('`_.' + methodName + '` should ignore extra `values`', function(assert) {
25551 assert.deepEqual(func(['a'], [1, 2]), { 'a': 1 });
25554 QUnit.test('`_.' + methodName + '` should assign `undefined` values for extra `keys`', function(assert) {
25557 assert.deepEqual(func(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
25560 QUnit.test('`_.' + methodName + '` should ' + (isDeep ? '' : 'not ') + 'support deep paths', function(assert) {
25563 lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path, index) {
25564 var expected = isDeep ? ({ 'a': { 'b': { 'c': 1 } } }) : (index ? { 'a,b,c': 1 } : { 'a.b.c': 1 });
25565 assert.deepEqual(func([path], [1]), expected);
25569 QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
25573 var values = lodashStable.range(LARGE_ARRAY_SIZE),
25574 props = lodashStable.map(values, function(value) { return 'key' + value; }),
25575 actual = _(props)[methodName](values).map(square).filter(isEven).take().value();
25577 assert.deepEqual(actual, _.take(_.filter(_.map(func(props, values), square), isEven)));
25580 skipAssert(assert);
25585 /*--------------------------------------------------------------------------*/
25587 QUnit.module('lodash.zipWith');
25590 QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
25593 var array1 = [1, 2, 3],
25594 array2 = [4, 5, 6],
25595 array3 = [7, 8, 9];
25597 var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
25601 assert.deepEqual(actual, [12, 15, 18]);
25603 var actual = _.zipWith(array1, [], function(a, b) {
25604 return a + (b || 0);
25607 assert.deepEqual(actual, [1, 2, 3]);
25610 QUnit.test('should provide correct `iteratee` arguments', function(assert) {
25615 _.zipWith([1, 2], [3, 4], [5, 6], function() {
25616 args || (args = slice.call(arguments));
25619 assert.deepEqual(args, [1, 3, 5]);
25622 QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
25625 var array1 = [1, 2],
25627 values = [, null, undefined],
25628 expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
25630 var actual = lodashStable.map(values, function(value, index) {
25631 return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
25634 assert.deepEqual(actual, expected);
25638 /*--------------------------------------------------------------------------*/
25640 QUnit.module('lodash.unzip and lodash.zip');
25642 lodashStable.each(['unzip', 'zip'], function(methodName, index) {
25643 var func = _[methodName];
25644 func = lodashStable.bind(index ? func.apply : func.call, func, null);
25647 'an empty array': [
25656 [['barney', 'fred'], [36, 40]],
25657 [['barney', 36], ['fred', 40]]
25660 [['barney', 'fred'], [36, 40], [false, true]],
25661 [['barney', 36, false], ['fred', 40, true]]
25665 lodashStable.forOwn(object, function(pair, key) {
25666 QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
25669 var actual = func(pair[0]);
25670 assert.deepEqual(actual, pair[1]);
25671 assert.deepEqual(func(actual), actual.length ? pair[0] : []);
25675 QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
25679 [['barney', 36], ['fred', 40, false]],
25680 [['barney', 'fred'], [36, 40], [undefined, false]]
25683 var actual = func(pair[0]);
25684 assert.ok('0' in actual[2]);
25685 assert.deepEqual(actual, pair[1]);
25687 actual = func(actual);
25688 assert.ok('2' in actual[0]);
25689 assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
25692 QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
25695 var expected = lodashStable.map(falsey, stubArray);
25697 var actual = lodashStable.map(falsey, function(value) {
25698 return func([value, value, value]);
25701 assert.deepEqual(actual, expected);
25704 QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
25707 var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
25708 assert.deepEqual(func(array), [[1, 3], [2, 4]]);
25711 QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
25714 var expected = [['barney', 'fred'], [36, 40]];
25715 assert.deepEqual(func(func(func(func(expected)))), expected);
25719 /*--------------------------------------------------------------------------*/
25721 QUnit.module('lodash(...).commit');
25724 QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
25729 wrapped = _(array).push(2).push(3);
25731 assert.deepEqual(array, [1]);
25733 var otherWrapper = wrapped.commit();
25734 assert.ok(otherWrapper instanceof _);
25735 assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
25736 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
25739 skipAssert(assert, 4);
25743 QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
25747 var wrapped = _([1]).chain().commit().head();
25748 assert.ok(wrapped instanceof _);
25749 assert.strictEqual(wrapped.value(), 1);
25752 skipAssert(assert, 2);
25757 /*--------------------------------------------------------------------------*/
25759 QUnit.module('lodash(...).next');
25761 lodashStable.each([false, true], function(implicit) {
25762 function chain(value) {
25763 return implicit ? _(value) : _.chain(value);
25766 var chainType = 'in an ' + (implicit ? 'implicit' : 'explict') + ' chain';
25768 QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
25772 var wrapped = chain([1, 2]);
25774 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
25775 assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
25776 assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
25779 skipAssert(assert, 3);
25783 QUnit.test('should act as an iterable ' + chainType, function(assert) {
25786 if (!isNpm && Symbol && Symbol.iterator) {
25787 var array = [1, 2],
25788 wrapped = chain(array);
25790 assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
25791 assert.deepEqual(lodashStable.toArray(wrapped), array);
25794 skipAssert(assert, 2);
25798 QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
25801 if (!isNpm && Array.from) {
25802 var hearts = '\ud83d\udc95',
25803 values = [[1], { 'a': 1 }, hearts];
25805 lodashStable.each(values, function(value) {
25806 var wrapped = chain(value);
25807 assert.deepEqual(Array.from(wrapped), _.toArray(value));
25811 skipAssert(assert, 3);
25815 QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
25818 if (!isNpm && Symbol && Symbol.iterator) {
25819 var array = [1, 2],
25820 wrapped = chain(array);
25822 assert.deepEqual(lodashStable.toArray(wrapped), array);
25823 assert.deepEqual(lodashStable.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
25825 var other = wrapped.filter();
25826 assert.deepEqual(lodashStable.toArray(other), array, 'reset for new chain segments');
25827 assert.deepEqual(lodashStable.toArray(wrapped), [], 'iterator is still exhausted');
25830 skipAssert(assert, 4);
25834 QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
25837 if (!isNpm && Symbol && Symbol.iterator) {
25838 var array = lodashStable.range(LARGE_ARRAY_SIZE),
25839 predicate = function(value) { values.push(value); return isEven(value); },
25841 wrapped = chain(array);
25843 assert.deepEqual(lodashStable.toArray(wrapped), array);
25845 wrapped = wrapped.filter(predicate);
25846 assert.deepEqual(lodashStable.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
25847 assert.deepEqual(values, array, 'memoizes iterator values');
25850 skipAssert(assert, 3);
25855 /*--------------------------------------------------------------------------*/
25857 QUnit.module('lodash(...).plant');
25860 QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
25864 var array1 = [5, null, 3, null, 1],
25865 array2 = [10, null, 8, null, 6],
25866 wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
25867 wrapped2 = wrapped1.plant(array2);
25869 assert.deepEqual(wrapped2.value(), [36, 64]);
25870 assert.deepEqual(wrapped1.value(), [1, 9]);
25873 skipAssert(assert, 2);
25877 QUnit.test('should clone `chainAll` settings', function(assert) {
25881 var array1 = [2, 4],
25883 wrapped1 = _(array1).chain().map(square),
25884 wrapped2 = wrapped1.plant(array2);
25886 assert.deepEqual(wrapped2.head().value(), 36);
25889 skipAssert(assert);
25893 QUnit.test('should reset iterator data on cloned sequences', function(assert) {
25896 if (!isNpm && Symbol && Symbol.iterator) {
25897 var array1 = [2, 4],
25899 wrapped1 = _(array1).map(square);
25901 assert.deepEqual(lodashStable.toArray(wrapped1), [4, 16]);
25902 assert.deepEqual(lodashStable.toArray(wrapped1), []);
25904 var wrapped2 = wrapped1.plant(array2);
25905 assert.deepEqual(lodashStable.toArray(wrapped2), [36, 64]);
25908 skipAssert(assert, 3);
25913 /*--------------------------------------------------------------------------*/
25915 QUnit.module('lodash(...).pop');
25918 QUnit.test('should remove elements from the end of `array`', function(assert) {
25922 var array = [1, 2],
25923 wrapped = _(array);
25925 assert.strictEqual(wrapped.pop(), 2);
25926 assert.deepEqual(wrapped.value(), [1]);
25927 assert.strictEqual(wrapped.pop(), 1);
25929 var actual = wrapped.value();
25930 assert.strictEqual(actual, array);
25931 assert.deepEqual(actual, []);
25934 skipAssert(assert, 5);
25938 QUnit.test('should accept falsey arguments', function(assert) {
25942 var expected = lodashStable.map(falsey, stubTrue);
25944 var actual = lodashStable.map(falsey, function(value, index) {
25946 var result = index ? _(value).pop() : _().pop();
25947 return result === undefined;
25951 assert.deepEqual(actual, expected);
25954 skipAssert(assert);
25959 /*--------------------------------------------------------------------------*/
25961 QUnit.module('lodash(...).push');
25964 QUnit.test('should append elements to `array`', function(assert) {
25969 wrapped = _(array).push(2, 3),
25970 actual = wrapped.value();
25972 assert.strictEqual(actual, array);
25973 assert.deepEqual(actual, [1, 2, 3]);
25976 skipAssert(assert, 2);
25980 QUnit.test('should accept falsey arguments', function(assert) {
25984 var expected = lodashStable.map(falsey, stubTrue);
25986 var actual = lodashStable.map(falsey, function(value, index) {
25988 var result = index ? _(value).push(1).value() : _().push(1).value();
25989 return lodashStable.eq(result, value);
25993 assert.deepEqual(actual, expected);
25996 skipAssert(assert);
26001 /*--------------------------------------------------------------------------*/
26003 QUnit.module('lodash(...).shift');
26006 QUnit.test('should remove elements from the front of `array`', function(assert) {
26010 var array = [1, 2],
26011 wrapped = _(array);
26013 assert.strictEqual(wrapped.shift(), 1);
26014 assert.deepEqual(wrapped.value(), [2]);
26015 assert.strictEqual(wrapped.shift(), 2);
26017 var actual = wrapped.value();
26018 assert.strictEqual(actual, array);
26019 assert.deepEqual(actual, []);
26022 skipAssert(assert, 5);
26026 QUnit.test('should accept falsey arguments', function(assert) {
26030 var expected = lodashStable.map(falsey, stubTrue);
26032 var actual = lodashStable.map(falsey, function(value, index) {
26034 var result = index ? _(value).shift() : _().shift();
26035 return result === undefined;
26039 assert.deepEqual(actual, expected);
26042 skipAssert(assert);
26047 /*--------------------------------------------------------------------------*/
26049 QUnit.module('lodash(...).sort');
26052 QUnit.test('should return the wrapped sorted `array`', function(assert) {
26056 var array = [3, 1, 2],
26057 wrapped = _(array).sort(),
26058 actual = wrapped.value();
26060 assert.strictEqual(actual, array);
26061 assert.deepEqual(actual, [1, 2, 3]);
26064 skipAssert(assert, 2);
26068 QUnit.test('should accept falsey arguments', function(assert) {
26072 var expected = lodashStable.map(falsey, stubTrue);
26074 var actual = lodashStable.map(falsey, function(value, index) {
26076 var result = index ? _(value).sort().value() : _().sort().value();
26077 return lodashStable.eq(result, value);
26081 assert.deepEqual(actual, expected);
26084 skipAssert(assert);
26089 /*--------------------------------------------------------------------------*/
26091 QUnit.module('lodash(...).splice');
26094 QUnit.test('should support removing and inserting elements', function(assert) {
26098 var array = [1, 2],
26099 wrapped = _(array);
26101 assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
26102 assert.deepEqual(wrapped.value(), [1, 3]);
26103 assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
26105 var actual = wrapped.value();
26106 assert.strictEqual(actual, array);
26107 assert.deepEqual(actual, []);
26110 skipAssert(assert, 5);
26114 QUnit.test('should accept falsey arguments', function(assert) {
26118 var expected = lodashStable.map(falsey, stubTrue);
26120 var actual = lodashStable.map(falsey, function(value, index) {
26122 var result = index ? _(value).splice(0, 1).value() : _().splice(0, 1).value();
26123 return lodashStable.isEqual(result, []);
26127 assert.deepEqual(actual, expected);
26130 skipAssert(assert);
26135 /*--------------------------------------------------------------------------*/
26137 QUnit.module('lodash(...).unshift');
26140 QUnit.test('should prepend elements to `array`', function(assert) {
26145 wrapped = _(array).unshift(1, 2),
26146 actual = wrapped.value();
26148 assert.strictEqual(actual, array);
26149 assert.deepEqual(actual, [1, 2, 3]);
26152 skipAssert(assert, 2);
26156 QUnit.test('should accept falsey arguments', function(assert) {
26160 var expected = lodashStable.map(falsey, stubTrue);
26162 var actual = lodashStable.map(falsey, function(value, index) {
26164 var result = index ? _(value).unshift(1).value() : _().unshift(1).value();
26165 return lodashStable.eq(result, value);
26169 assert.deepEqual(actual, expected);
26172 skipAssert(assert);
26177 /*--------------------------------------------------------------------------*/
26179 QUnit.module('lodash(...).value');
26182 QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
26187 wrapped = _(array).push(2).push(3);
26189 assert.deepEqual(array, [1]);
26190 assert.deepEqual(wrapped.value(), [1, 2, 3]);
26191 assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
26192 assert.deepEqual(array, [1, 2, 3, 2, 3]);
26195 skipAssert(assert, 4);
26199 QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
26203 var wrapped = _(123);
26204 assert.strictEqual(Number(wrapped), 123);
26207 skipAssert(assert);
26211 QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
26214 if (!isNpm && JSON) {
26215 var wrapped = _([1, 2, 3]);
26216 assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
26219 skipAssert(assert);
26223 QUnit.test('should be aliased', function(assert) {
26227 var expected = _.prototype.value;
26228 assert.strictEqual(_.prototype.toJSON, expected);
26229 assert.strictEqual(_.prototype.valueOf, expected);
26232 skipAssert(assert, 2);
26237 /*--------------------------------------------------------------------------*/
26239 QUnit.module('lodash(...) methods that return the wrapped modified array');
26249 lodashStable.each(funcs, function(methodName) {
26250 QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
26254 var array = [1, 2, 3],
26255 wrapped = _(array),
26256 actual = wrapped[methodName]();
26258 assert.ok(actual instanceof _);
26259 assert.notStrictEqual(actual, wrapped);
26262 skipAssert(assert, 2);
26268 /*--------------------------------------------------------------------------*/
26270 QUnit.module('lodash(...) methods that return new wrapped values');
26281 'intersectionWith',
26303 lodashStable.each(funcs, function(methodName) {
26304 QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
26308 var value = methodName == 'split' ? 'abc' : [1, 2, 3],
26309 wrapped = _(value),
26310 actual = wrapped[methodName]();
26312 assert.ok(actual instanceof _);
26313 assert.notStrictEqual(actual, wrapped);
26316 skipAssert(assert, 2);
26322 /*--------------------------------------------------------------------------*/
26324 QUnit.module('lodash(...) methods that return unwrapped values');
26423 lodashStable.each(funcs, function(methodName) {
26424 QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
26428 var actual = _()[methodName]();
26429 assert.notOk(actual instanceof _);
26432 skipAssert(assert);
26436 QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
26440 var actual = _().chain()[methodName]();
26441 assert.ok(actual instanceof _);
26444 skipAssert(assert);
26450 /*--------------------------------------------------------------------------*/
26452 QUnit.module('"Arrays" category methods');
26455 var args = toArgs([1, null, [3], null, 5]),
26456 sortedArgs = toArgs([1, [3], 5, null, null]),
26457 array = [1, 2, 3, 4, 5, 6];
26459 QUnit.test('should work with `arguments` objects', function(assert) {
26462 function message(methodName) {
26463 return '`_.' + methodName + '` should work with `arguments` objects';
26466 assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
26467 assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
26469 assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
26470 assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
26472 assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
26473 assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
26474 assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
26475 assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
26476 assert.deepEqual(_.dropWhile(args,identity), [null, [3], null, 5], message('dropWhile'));
26477 assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
26478 assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
26479 assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
26480 assert.deepEqual(_.head(args), 1, message('head'));
26481 assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
26482 assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
26483 assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
26484 assert.deepEqual(_.last(args), 5, message('last'));
26485 assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
26486 assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
26487 assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
26488 assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
26489 assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
26490 assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
26491 assert.deepEqual(_.take(args, 2), [1, null], message('take'));
26492 assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
26493 assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
26494 assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
26495 assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
26496 assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
26497 assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
26500 QUnit.test('should accept falsey primary arguments', function(assert) {
26503 function message(methodName) {
26504 return '`_.' + methodName + '` should accept falsey primary arguments';
26507 assert.deepEqual(_.difference(null, array), [], message('difference'));
26508 assert.deepEqual(_.intersection(null, array), [], message('intersection'));
26509 assert.deepEqual(_.union(null, array), array, message('union'));
26510 assert.deepEqual(_.xor(null, array), array, message('xor'));
26513 QUnit.test('should accept falsey secondary arguments', function(assert) {
26516 function message(methodName) {
26517 return '`_.' + methodName + '` should accept falsey secondary arguments';
26520 assert.deepEqual(_.difference(array, null), array, message('difference'));
26521 assert.deepEqual(_.intersection(array, null), [], message('intersection'));
26522 assert.deepEqual(_.union(array, null), array, message('union'));
26526 /*--------------------------------------------------------------------------*/
26528 QUnit.module('"Strings" category methods');
26531 var stringMethods = [
26554 lodashStable.each(stringMethods, function(methodName) {
26555 var func = _[methodName];
26557 QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
26560 var values = [, null, undefined, ''],
26561 expected = lodashStable.map(values, stubString);
26563 var actual = lodashStable.map(values, function(value, index) {
26564 return index ? func(value) : func();
26567 assert.deepEqual(actual, expected);
26572 /*--------------------------------------------------------------------------*/
26574 QUnit.module('lodash methods');
26577 var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
26578 return lodashStable.startsWith(methodName, '_');
26619 var rejectFalsey = [
26622 ].concat(checkFuncs);
26624 var returnArrays = [
26662 var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
26664 QUnit.test('should accept falsey arguments', function(assert) {
26665 assert.expect(316);
26667 var arrays = lodashStable.map(falsey, stubArray);
26669 lodashStable.each(acceptFalsey, function(methodName) {
26670 var expected = arrays,
26671 func = _[methodName];
26673 var actual = lodashStable.map(falsey, function(value, index) {
26674 return index ? func(value) : func();
26677 if (methodName == 'noConflict') {
26680 else if (methodName == 'pull' || methodName == 'pullAll') {
26683 if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
26684 assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
26686 assert.ok(true, '`_.' + methodName + '` accepts falsey arguments');
26689 // Skip tests for missing methods of modularized builds.
26690 lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
26691 if (!_[methodName]) {
26692 skipAssert(assert);
26697 QUnit.test('should return an array', function(assert) {
26700 var array = [1, 2, 3];
26702 lodashStable.each(returnArrays, function(methodName) {
26704 func = _[methodName];
26706 switch (methodName) {
26708 actual = func(array, 'toFixed');
26711 actual = func(array, 1);
26714 actual = func(array);
26716 assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
26718 var isPull = methodName == 'pull' || methodName == 'pullAll';
26719 assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the given array');
26723 QUnit.test('should throw an error for falsey arguments', function(assert) {
26726 lodashStable.each(rejectFalsey, function(methodName) {
26727 var expected = lodashStable.map(falsey, stubTrue),
26728 func = _[methodName];
26730 var actual = lodashStable.map(falsey, function(value, index) {
26731 var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
26734 index ? func(value) : func();
26736 pass = !pass && (e instanceof TypeError) &&
26737 (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
26742 assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
26746 QUnit.test('should use `this` binding of function', function(assert) {
26749 lodashStable.each(noBinding, function(methodName) {
26750 var fn = function() { return this.a; },
26751 func = _[methodName],
26752 isNegate = methodName == 'negate',
26753 object = { 'a': 1 },
26754 expected = isNegate ? false : 1;
26756 var wrapper = func(_.bind(fn, object));
26757 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
26759 wrapper = _.bind(func(fn), object);
26760 assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
26762 object.wrapper = func(fn);
26763 assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
26767 QUnit.test('should not contain minified method names (test production builds)', function(assert) {
26770 var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
26771 assert.ok(lodashStable.every(_.functions(_), function(methodName) {
26772 return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
26777 /*--------------------------------------------------------------------------*/
26779 QUnit.config.asyncRetries = 10;
26780 QUnit.config.hidepassed = true;
26783 QUnit.config.noglobals = true;