Cleanup string tests and add string test to _.toArray.

Former-commit-id: 3565f7233f1f7662604e3b8e1f07eead62349454
This commit is contained in:
John-David Dalton
2012-08-20 22:45:57 -07:00
parent 24b672b968
commit 35fea30191

View File

@@ -272,14 +272,14 @@
QUnit.module('lodash.contains'); QUnit.module('lodash.contains');
(function() { (function() {
_.each([ _.each({
{ 'kind': 'literal', 'value': 'abc' }, 'literal': 'abc',
{ 'kind': 'object', 'value': Object('abc') } 'object': Object('abc')
], },
function(data) { function(collection, key) {
test('should work with a string ' + data.kind + ' for `collection`', function() { test('should work with a string ' + key + ' for `collection`', function() {
equal(_.contains(data.value, 'bc'), true); equal(_.contains(collection, 'bc'), true);
equal(_.contains(data.value, 'd'), false); equal(_.contains(collection, 'd'), false);
}); });
}); });
}()); }());
@@ -508,14 +508,13 @@
deepEqual(keys, ['length']); deepEqual(keys, ['length']);
}); });
_.each([ _.each({
{ 'kind': 'literal', 'value': 'abc' }, 'literal': 'abc',
{ 'kind': 'object', 'value': Object('abc') } 'object': Object('abc')
], },
function(data) { function(collection, key) {
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() { test('should work with a string ' + key + ' for `collection` (test in IE < 9)', function() {
var args, var args,
collection = data.value,
values = []; values = [];
_.forEach(collection, function(value) { _.forEach(collection, function(value) {
@@ -1151,14 +1150,13 @@
deepEqual(args, expected); deepEqual(args, expected);
}); });
_.each([ _.each({
{ 'kind': 'literal', 'value': 'abc' }, 'literal': 'abc',
{ 'kind': 'object', 'value': Object('abc') } 'object': Object('abc')
], },
function(data) { function(collection, key) {
test('should work with a string ' + data.kind + ' for `collection` (test in IE < 9)', function() { test('should work with a string ' + key + ' for `collection` (test in IE < 9)', function() {
var args, var args;
collection = data.value;
var actual = _.reduceRight(collection, function(accumulator, value) { var actual = _.reduceRight(collection, function(accumulator, value) {
args || (args = slice.call(arguments)); args || (args = slice.call(arguments));
@@ -1425,10 +1423,14 @@
(function() { (function() {
var args = arguments; var args = arguments;
test('should call custom `toArray` method of an array', function() { _.each({
var array = [1, 2, 3]; 'an array': ['a', 'b', 'c'],
array.toArray = function() { return [3, 2, 1]; }; 'a string': Object('abc')
deepEqual(_.toArray(array), [3, 2, 1]); }, function(collection, key) {
test('should call custom `toArray` method of ' + key, function() {
collection.toArray = function() { return [3, 2, 1]; };
deepEqual(_.toArray(collection), [3, 2, 1]);
});
}); });
test('should treat array-like objects like arrays', function() { test('should treat array-like objects like arrays', function() {