@@ -1923,20 +1923,8 @@ QUnit.test( "find in document fragments", function( assert ) {
19231923 assert . strictEqual ( elem . length , 1 , "Selection works" ) ;
19241924} ) ;
19251925
1926- QUnit . test ( "jQuery.uniqueSort" , function ( assert ) {
1927- assert . expect ( 14 ) ;
1928-
1929- function Arrayish ( arr ) {
1930- var i = this . length = arr . length ;
1931- while ( i -- ) {
1932- this [ i ] = arr [ i ] ;
1933- }
1934- }
1935- Arrayish . prototype = {
1936- sliceForTestOnly : [ ] . slice
1937- } ;
1938-
1939- var i , tests ,
1926+ function getUniqueSortFixtures ( ) {
1927+ var i ,
19401928 detached = [ ] ,
19411929 body = document . body ,
19421930 fixture = document . getElementById ( "qunit-fixture" ) ,
@@ -1951,7 +1939,7 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
19511939 detached2 . appendChild ( document . createElement ( "li" ) ) . id = "detachedChild" + i ;
19521940 }
19531941
1954- tests = {
1942+ return {
19551943 "Empty" : {
19561944 input : [ ] ,
19571945 expected : [ ]
@@ -1992,15 +1980,61 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
19921980 length : 3
19931981 }
19941982 } ;
1983+ }
1984+
1985+ QUnit . test ( "jQuery.uniqueSort" , function ( assert ) {
1986+ assert . expect ( 14 ) ;
19951987
1996- jQuery . each ( tests , function ( label , test ) {
1997- var length = test . length || test . input . length ;
1998- // We duplicate `test.input` because otherwise it is modified by `uniqueSort`
1988+ var fixtures = getUniqueSortFixtures ( ) ;
1989+
1990+ function Arrayish ( arr ) {
1991+ var i = this . length = arr . length ;
1992+ while ( i -- ) {
1993+ this [ i ] = arr [ i ] ;
1994+ }
1995+ }
1996+ Arrayish . prototype = {
1997+ sliceForTestOnly : [ ] . slice
1998+ } ;
1999+
2000+ jQuery . each ( fixtures , function ( label , fixture ) {
2001+ var length = fixture . length || fixture . input . length ;
2002+
2003+ // We duplicate `fixture.input` because otherwise it is modified by `uniqueSort`
19992004 // and the second test becomes worthless.
2000- assert . deepEqual ( jQuery . uniqueSort ( test . input . slice ( 0 ) ) . slice ( 0 , length ) ,
2001- test . expected , label + " (array)" ) ;
2002- assert . deepEqual ( jQuery . uniqueSort ( new Arrayish ( test . input ) ) . sliceForTestOnly ( 0 , length ) ,
2003- test . expected , label + " (quasi-array)" ) ;
2005+ assert . deepEqual (
2006+ jQuery . uniqueSort ( fixture . input . slice ( 0 ) )
2007+ . slice ( 0 , length ) ,
2008+ fixture . expected ,
2009+ label + " (array)"
2010+ ) ;
2011+
2012+ assert . deepEqual (
2013+ jQuery . uniqueSort ( new Arrayish ( fixture . input ) )
2014+ . sliceForTestOnly ( 0 , length ) ,
2015+ fixture . expected ,
2016+ label + " (quasi-array)"
2017+ ) ;
2018+ } ) ;
2019+ } ) ;
2020+
2021+ QUnit . test ( "uniqueSort()" , function ( assert ) {
2022+ assert . expect ( 28 ) ;
2023+
2024+ var fixtures = getUniqueSortFixtures ( ) ;
2025+
2026+ jQuery . each ( fixtures , function ( label , fixture ) {
2027+ var length = fixture . length || fixture . input . length ,
2028+ fixtureInputCopy = fixture . input . slice ( 0 ) ,
2029+ sortedElem = jQuery ( fixture . input ) . uniqueSort ( ) ;
2030+
2031+ assert . deepEqual ( fixture . input , fixtureInputCopy , "Fixture not modified (" + label + ")" ) ;
2032+
2033+ assert . deepEqual ( sortedElem . slice ( 0 , length ) . toArray ( ) , fixture . expected , label ) ;
2034+
2035+ // Chaining
2036+ assert . ok ( sortedElem instanceof jQuery , "chaining" ) ;
2037+ assert . deepEqual ( sortedElem . end ( ) . toArray ( ) , fixture . input , label ) ;
20042038 } ) ;
20052039} ) ;
20062040
0 commit comments