mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Add custom-debug build to unit test runners and add unit tests for passing strings to "Collections" methods.
Former-commit-id: cb6c66d01a9f30908a27e689f8ffba5fa9f04299
This commit is contained in:
@@ -13,9 +13,14 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// assign `QUnit.config` properties
|
// assign `QUnit.config` properties
|
||||||
QUnit.config.lodashFilename = build == 'prod'
|
QUnit.config.lodashFilename = (function() {
|
||||||
? 'lodash.min'
|
switch (build) {
|
||||||
: (build == 'custom' ? 'lodash.custom.min' : 'lodash');
|
case 'custom': return 'lodash.custom.min';
|
||||||
|
case 'custom-debug': return 'lodash.custom';
|
||||||
|
case 'prod': return 'lodash.min';
|
||||||
|
}
|
||||||
|
return 'lodash';
|
||||||
|
}());
|
||||||
|
|
||||||
// assign `QUnit.urlParams` properties
|
// assign `QUnit.urlParams` properties
|
||||||
QUnit.extend(QUnit.urlParams, {
|
QUnit.extend(QUnit.urlParams, {
|
||||||
@@ -45,11 +50,15 @@
|
|||||||
header.appendChild(label1);
|
header.appendChild(label1);
|
||||||
header.appendChild(label2);
|
header.appendChild(label2);
|
||||||
|
|
||||||
if (build == 'prod') {
|
dropdown.selectedIndex = (function() {
|
||||||
dropdown.selectedIndex = 1;
|
switch (build) {
|
||||||
} else if (build == 'custom') {
|
case 'custom': return 3;
|
||||||
dropdown.selectedIndex = 2;
|
case 'custom-debug': return 2;
|
||||||
}
|
case 'prod': return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}());
|
||||||
|
|
||||||
checkbox.checked = norequire;
|
checkbox.checked = norequire;
|
||||||
addEvent(checkbox, 'click', eventHandler);
|
addEvent(checkbox, 'click', eventHandler);
|
||||||
addEvent(dropdown, 'change', eventHandler);
|
addEvent(dropdown, 'change', eventHandler);
|
||||||
@@ -68,6 +77,7 @@
|
|||||||
'<select name="build">' +
|
'<select name="build">' +
|
||||||
'<option value="dev">developement</option>' +
|
'<option value="dev">developement</option>' +
|
||||||
'<option value="prod">production</option>' +
|
'<option value="prod">production</option>' +
|
||||||
|
'<option value="custom-debug">custom (debug)</option>' +
|
||||||
'<option value="custom">custom</option>' +
|
'<option value="custom">custom</option>' +
|
||||||
'</select>build';
|
'</select>build';
|
||||||
|
|
||||||
|
|||||||
63
test/test.js
63
test/test.js
@@ -247,6 +247,26 @@
|
|||||||
_.forEach(object, function(value, key) { keys.push(key); });
|
_.forEach(object, function(value, key) { keys.push(key); });
|
||||||
deepEqual(keys, ['length']);
|
deepEqual(keys, ['length']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_.each([
|
||||||
|
{ 'kind': 'literal', 'value': 'abc' },
|
||||||
|
{ 'kind': 'object', 'value': Object('abc') }
|
||||||
|
],
|
||||||
|
function(data) {
|
||||||
|
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() {
|
||||||
|
var args,
|
||||||
|
collection = data.value,
|
||||||
|
values = [];
|
||||||
|
|
||||||
|
_.forEach(collection, function(value) {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
values.push(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(args, ['a', 0, collection]);
|
||||||
|
deepEqual(values, ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -556,25 +576,53 @@
|
|||||||
(function() {
|
(function() {
|
||||||
test('should pass the correct `callback` arguments when iterating an object', function() {
|
test('should pass the correct `callback` arguments when iterating an object', function() {
|
||||||
var args,
|
var args,
|
||||||
object = { 'a': 'A', 'b': 'B', 'c': 'C' },
|
object = { 'a': 'A', 'b': 'B' },
|
||||||
keys = _.keys(object);
|
lastKey = _.keys(object).pop();
|
||||||
|
|
||||||
|
var expected = lastKey == 'a'
|
||||||
|
? ['A', 'B', 'b', object]
|
||||||
|
: ['B', 'A', 'a', object];
|
||||||
|
|
||||||
_.reduceRight(object, function() {
|
_.reduceRight(object, function() {
|
||||||
args || (args = slice.call(arguments));
|
args || (args = slice.call(arguments));
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual(args, ['C', 'B', 'b', object]);
|
deepEqual(args, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should treat array-like object with invalid `length` as a regular object', function() {
|
test('should treat array-like object with invalid `length` as a regular object', function() {
|
||||||
var args,
|
var args,
|
||||||
object = { 'a': 'A', 'length': -1 };
|
object = { 'a': 'A', 'length': -1 },
|
||||||
|
lastKey = _.keys(object).pop();
|
||||||
|
|
||||||
|
var expected = lastKey == 'a'
|
||||||
|
? ['A', '-1', 'length', object]
|
||||||
|
: [-1, 'A', 'a', object];
|
||||||
|
|
||||||
_.reduceRight(object, function() {
|
_.reduceRight(object, function() {
|
||||||
args || (args = slice.call(arguments));
|
args || (args = slice.call(arguments));
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual(args, [-1, 'A', 'a', object]);
|
deepEqual(args, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
_.each([
|
||||||
|
{ 'kind': 'literal', 'value': 'abc' },
|
||||||
|
{ 'kind': 'object', 'value': Object('abc') }
|
||||||
|
],
|
||||||
|
function(data) {
|
||||||
|
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() {
|
||||||
|
var args,
|
||||||
|
collection = data.value;
|
||||||
|
|
||||||
|
var actual = _.reduceRight(collection, function(accumulator, value) {
|
||||||
|
args || (args = slice.call(arguments));
|
||||||
|
return accumulator + value;
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(args, ['c', 'b', 1, collection]);
|
||||||
|
equal(actual, 'cba');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -769,6 +817,11 @@
|
|||||||
var object = { 'length': -1 };
|
var object = { 'length': -1 };
|
||||||
deepEqual(_.toArray(object), [-1]);
|
deepEqual(_.toArray(object), [-1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work with a string for `collection` (test in IE < 9)', function() {
|
||||||
|
deepEqual(_.toArray('abc'), ['a', 'b', 'c']);
|
||||||
|
deepEqual(_.toArray(Object('abc')), ['a', 'b', 'c']);
|
||||||
|
});
|
||||||
}(1, 2, 3));
|
}(1, 2, 3));
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user