From: Richard Gibson Date: Tue, 3 Sep 2013 05:24:01 +0000 (-0400) Subject: Ref #14313: Further code and test improvements X-Git-Tag: 2.1.0-beta1~59 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f66d53c85643e703a8e37d9ca9375dd386a60cda;p=jquery.git Ref #14313: Further code and test improvements --- diff --git a/src/core.js b/src/core.js index 82616eaa5..0eef72311 100644 --- a/src/core.js +++ b/src/core.js @@ -552,14 +552,12 @@ jQuery.extend({ }, merge: function( first, second ) { - var l = +second.length, - i = first.length, - j = 0; + var len = +second.length, + j = 0, + i = first.length; - if ( l ) { - for ( ; j < l; j++ ) { - first[ i++ ] = second[ j ]; - } + for ( ; j < len; j++ ) { + first[ i++ ] = second[ j ]; } first.length = i; diff --git a/test/unit/core.js b/test/unit/core.js index a849591dd..00ae36a61 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -903,25 +903,65 @@ test("jQuery.map", function() { }); test("jQuery.merge()", function() { - expect(8); + expect( 10 ); - deepEqual( jQuery.merge([],[]), [], "Empty arrays" ); + deepEqual( + jQuery.merge( [], [] ), + [], + "Empty arrays" + ); - deepEqual( jQuery.merge([ 1 ],[ 2 ]), [ 1, 2 ], "Basic" ); - deepEqual( jQuery.merge([ 1, 2 ], [ 3, 4 ]), [ 1, 2, 3, 4 ], "Basic" ); + deepEqual( + jQuery.merge( [ 1 ], [ 2 ] ), + [ 1, 2 ], + "Basic (single-element)" + ); + deepEqual( + jQuery.merge( [ 1, 2 ], [ 3, 4 ] ), + [ 1, 2, 3, 4 ], + "Basic (multiple-element)" + ); - deepEqual( jQuery.merge([ 1, 2 ],[]), [ 1, 2 ], "Second empty" ); - deepEqual( jQuery.merge([],[ 1, 2 ]), [ 1, 2 ], "First empty" ); + deepEqual( + jQuery.merge( [ 1, 2 ], [] ), + [ 1, 2 ], + "Second empty" + ); + deepEqual( + jQuery.merge( [], [ 1, 2 ] ), + [ 1, 2 ], + "First empty" + ); // Fixed at [5998], #3641 - deepEqual( jQuery.merge([ -2, -1 ], [ 0, 1, 2 ]), [ -2, -1 , 0, 1, 2 ], - "Second array including a zero (falsy)"); + deepEqual( + jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ), + [ -2, -1 , 0, 1, 2 ], + "Second array including a zero (falsy)" + ); // After fixing #5527 - deepEqual( jQuery.merge([], [ null, undefined ]), [ null, undefined ], - "Second array including null and undefined values"); - deepEqual( jQuery.merge({ length: 0 }, [ 1, 2 ] ), { length: 2, 0: 1, 1: 2}, - "First array like"); + deepEqual( + jQuery.merge( [], [ null, undefined ] ), + [ null, undefined ], + "Second array including null and undefined values" + ); + deepEqual( + jQuery.merge( { length: 0 }, [ 1, 2 ] ), + { length: 2, 0: 1, 1: 2 }, + "First array like" + ); + deepEqual( + jQuery.merge( [ 1, 2 ], { length: 1, 0: 3 } ), + [ 1, 2, 3 ], + "Second array like" + ); + + deepEqual( + jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ), + [ document.getElementById("length"), document.getElementById("idTest") ], + "Second NodeList" + ); }); test("jQuery.extend(Object, Object)", function() {