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:
John-David Dalton
2012-07-10 01:06:06 -04:00
parent fad9b4fa72
commit 329c7e8e05
2 changed files with 76 additions and 13 deletions

View File

@@ -13,9 +13,14 @@
/*--------------------------------------------------------------------------*/
// assign `QUnit.config` properties
QUnit.config.lodashFilename = build == 'prod'
? 'lodash.min'
: (build == 'custom' ? 'lodash.custom.min' : 'lodash');
QUnit.config.lodashFilename = (function() {
switch (build) {
case 'custom': return 'lodash.custom.min';
case 'custom-debug': return 'lodash.custom';
case 'prod': return 'lodash.min';
}
return 'lodash';
}());
// assign `QUnit.urlParams` properties
QUnit.extend(QUnit.urlParams, {
@@ -45,11 +50,15 @@
header.appendChild(label1);
header.appendChild(label2);
if (build == 'prod') {
dropdown.selectedIndex = 1;
} else if (build == 'custom') {
dropdown.selectedIndex = 2;
}
dropdown.selectedIndex = (function() {
switch (build) {
case 'custom': return 3;
case 'custom-debug': return 2;
case 'prod': return 1;
}
return 0;
}());
checkbox.checked = norequire;
addEvent(checkbox, 'click', eventHandler);
addEvent(dropdown, 'change', eventHandler);
@@ -68,6 +77,7 @@
'<select name="build">' +
'<option value="dev">developement</option>' +
'<option value="prod">production</option>' +
'<option value="custom-debug">custom (debug)</option>' +
'<option value="custom">custom</option>' +
'</select>build';

View File

@@ -247,6 +247,26 @@
_.forEach(object, function(value, key) { keys.push(key); });
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() {
test('should pass the correct `callback` arguments when iterating an object', function() {
var args,
object = { 'a': 'A', 'b': 'B', 'c': 'C' },
keys = _.keys(object);
object = { 'a': 'A', 'b': 'B' },
lastKey = _.keys(object).pop();
var expected = lastKey == 'a'
? ['A', 'B', 'b', object]
: ['B', 'A', 'a', object];
_.reduceRight(object, function() {
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() {
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() {
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 };
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));
/*--------------------------------------------------------------------------*/