8000 Add custom-debug build to unit test runners and add unit tests for pa… · lodash/lodash@329c7e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 329c7e8

Browse files
committed
Add custom-debug build to unit test runners and add unit tests for passing strings to "Collections" methods.
Former-commit-id: cb6c66d01a9f30908a27e689f8ffba5fa9f04299
1 parent fad9b4f commit 329c7e8

File tree

2 files changed

+76
-13
lines changed

2 files changed

+76
-13
lines changed

test/test-ui.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
/*--------------------------------------------------------------------------*/
1414

1515
// assign `QUnit.config` properties
16-
QUnit.config.lodashFilename = build == 'prod'
17-
? 'lodash.min'
18-
: (build == 'custom' ? 'lodash.custom.min' : 'lodash');
16+
QUnit.config.lodashFilename = (function() {
17+
switch (build) {
18+
case 'custom': return 'lodash.custom.min';
19+
case 'custom-debug': return 'lodash.custom';
20+
case 'prod': return 'lodash.min';
21+
}
22+
return 'lodash';
23+
}());
1924

2025
// assign `QUnit.urlParams` properties
2126
QUnit.extend(QUnit.urlParams, {
@@ -45,11 +50,15 @@
4550
header.appendChild(label1);
4651
header.appendChild(label2);
4752

48-
if (build == 'prod') {
49-
dropdown.selectedIndex = 8000 1;
50-
} else if (build == 'custom') {
51-
dropdown.selectedIndex = 2;
52-
}
53+
dropdown.selectedIndex = (function() {
54+
switch (build) {
55+
case 'custom': return 3;
56+
case 'custom-debug': return 2;
57+
case 'prod': return 1;
58+
}
59+
return 0;
60+
}());
61+
5362
checkbox.checked = norequire;
5463
addEvent(checkbox, 'click', eventHandler);
5564
addEvent(dropdown, 'change', eventHandler);
@@ -68,6 +77,7 @@
6877
'<select name="build">' +
6978
'<option value="dev">developement</option>' +
7079
'<option value="prod">production</option>' +
80+
'<option value="custom-debug">custom (debug)</option>' +
7181
'<option value="custom">custom</option>' +
7282
'</select>build';
7383

test/test.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,26 @@
247247
_.forEach(object, function(value, key) { keys.push(key); });
248248
deepEqual(keys, ['length']);
249249
});
250+
251+
_.each([
252+
{ 'kind': 'literal', 'value': 'abc' },
253+
{ 'kind': 'object', 'value': Object('abc') }
254+
],
255+
function(data) {
256+
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() {
257+
var args,
258+
collection = data.value,
259+
values = [];
260+
261+
_.forEach(collection, function(value) {
262+
args || (args = slice.call(arguments));
263+
values.push(value);
264+
});
265+
266+
deepEqual(args, ['a', 0, collection]);
267+
deepEqual(values, ['a', 'b', 'c']);
268+
});
269+
});
250270
}());
251271

252272
/*--------------------------------------------------------------------------*/
@@ -556,25 +576,53 @@
556576
(function() {
557577
test('should pass the correct `callback` arguments when iterating an object', function() {
558578
var args,
559-
object = { 'a': 'A', 'b': 'B', 'c': 'C' },
560-
keys = _.keys(object);
579+
object = { 'a': 'A', 'b': 'B' },
580+
lastKey = _.keys(object).pop();
581+
582+
var expected = lastKey == 'a'
583+
? ['A', 'B', 'b', object]
584+
: ['B', 'A', 'a', object];
561585

562586
_.reduceRight(object, function() {
563587
args || (args = slice.call(arguments));
564588
});
565589

566-
deepEqual(args, ['C', 'B', 'b', object]);
590+
deepEqual(args, expected);
567591
});
568592

569593
test('should treat array-like object with invalid `length` as a regular object', function() {
570594
var args,
571-
object = { 'a': 'A', 'length': -1 };
595+
object = { 'a': 'A', 'length': -1 },
596+
lastKey = _.keys(object).pop();
597+
598+
var expected = lastKey == 'a'
599+
? ['A', '-1', 'length', object]
600+
: [-1, 'A', 'a', object];
572601

573602
_.reduceRight(object, function() {
574603
args || (args = slice.call(arguments));
575604
});
576605

577-
deepEqual(args, [-1, 'A', 'a', object]);
606+
deepEqual(args, expected);
607+
});
608+
609+
_.each([
610+
{ 'kind': 'literal', 'value': 'abc' },
611+
{ 'kind': 'object', 'value': Object('abc') }
612+
],
613+
function(data) {
614+
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() {
615+
var args,
616+
collection = data.value;
617+
618+
var actual = _.reduceRight(collection, function(accumulator, value) {
619+
args || (args = slice.call(arguments));
620+
return accumulator + value;
621+
});
622+
623+
deepEqual(args, ['c', 'b', 1, collection]);
624+
equal(actual, 'cba');
625+
});
578626
});
579627
}());
580628

@@ -769,6 +817,11 @@
769817
var object = { 'length': -1 };
770818
deepEqual(_.toArray(object), [-1]);
771819
});
820+
821+
test('should work with a string for `collection` (test in IE < 9)', function() {
822+
deepEqual(_.toArray('abc'), ['a', 'b', 'c']);
823+
deepEqual(_.toArray(Object('abc')), ['a', 'b', 'c']);
824+
});
772825
}(1, 2, 3));
773826

774827
/*--------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)
0