Tests: Account for array-like objects in jQuery.grep

Closes gh-2605
This commit is contained in:
Aurelio De Rosa 2015-09-21 00:05:50 +01:00 committed by Oleg Gaidarenko
parent 625bd303d9
commit 67b76f5986

View File

@ -970,16 +970,83 @@ QUnit.test( "jQuery.grep()", function( assert ) {
assert.deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" );
assert.deepEqual( jQuery.grep( new Array( 4 ), searchCriterion ), [], "Sparse array" );
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" );
assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion ), [], "Satisfying elements absent" );
assert.deepEqual(
jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ),
[ 2, 4, 6 ],
"Satisfying elements present"
);
assert.deepEqual(
jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion ),
[],
"Satisfying elements absent"
);
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" );
assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, true ), [ 1, 3, 5, 7 ], "Satisfying elements absent and grep inverted" );
assert.deepEqual(
jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ),
[ 1, 3, 5 ],
"Satisfying elements present and grep inverted"
);
assert.deepEqual(
jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, true ),
[ 1, 3, 5, 7 ],
"Satisfying elements absent and grep inverted"
);
assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" );
assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" );
assert.deepEqual(
jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ),
[ 2, 4, 6 ],
"Satisfying elements present but grep explicitly uninverted"
);
assert.deepEqual(
jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ),
[],
"Satisfying elements absent and grep explicitly uninverted"
);
} );
QUnit.test( "jQuery.grep(Array-like)", function( assert ) {
assert.expect( 7 );
var searchCriterion = function( value ) {
return value % 2 === 0;
};
assert.deepEqual( jQuery.grep( { length: 0 }, searchCriterion ), [], "Empty array-like" );
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, length: 6 }, searchCriterion ),
[ 2, 4, 6 ],
"Satisfying elements present and array-like object used"
);
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 3, 2: 5, 3: 7, length: 4 }, searchCriterion ),
[],
"Satisfying elements absent and Array-like object used"
);
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, length: 6 }, searchCriterion, true ),
[ 1, 3, 5 ],
"Satisfying elements present, array-like object used, and grep inverted"
);
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 3, 2: 5, 3: 7, length: 4 }, searchCriterion, true ),
[ 1, 3, 5, 7 ],
"Satisfying elements absent, array-like object used, and grep inverted"
);
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, length: 6 }, searchCriterion, false ),
[ 2, 4, 6 ],
"Satisfying elements present, Array-like object used, but grep explicitly uninverted"
);
assert.deepEqual(
jQuery.grep( { 0: 1, 1: 3, 2: 5, 3: 7, length: 4 }, searchCriterion, false ),
[],
"Satisfying elements absent, Array-like object used, and grep explicitly uninverted"
);
});
QUnit.test( "jQuery.extend(Object, Object)", function( assert ) {
assert.expect( 28 );