Followup r86088: test cases and a correction for bug 17141 (IPv4 address sorting)
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 23 Jun 2011 00:37:23 +0000 (00:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 23 Jun 2011 00:37:23 +0000 (00:37 +0000)
Test lists 8 randomly generated IPv4 addresses and attempts to sort them both forward and back.
Turned up a bug where single-digit octets (eg a .1 or .9) were not expanded in the sort key, causing them to mis-sort.

resources/jquery/jquery.tablesorter.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

index 821d9ac..3ce4c66 100644 (file)
                                l = a.length;
                        for ( var i = 0; i < l; i++ ) {
                                var item = a[i];
-                               if ( item.length == 2 ) {
+                               if ( item.length == 1 ) {
+                                       r += "00" + item;
+                               } else if ( item.length == 2 ) {
                                        r += "0" + item;
                                } else {
                                        r += item;
index 1289e95..385d98a 100644 (file)
@@ -212,4 +212,47 @@ tableTest(
        }
 );
 
+var ipv4 = [
+       // Some randomly generated fake IPs
+       ['45.238.27.109'],
+       ['44.172.9.22'],
+       ['247.240.82.209'],
+       ['204.204.132.158'],
+       ['170.38.91.162'],
+       ['197.219.164.9'],
+       ['45.68.154.72'],
+       ['182.195.149.80']
+];
+var ipv4Sorted = [
+       // Sort order should go octet by octet
+       ['44.172.9.22'],
+       ['45.68.154.72'],
+       ['45.238.27.109'],
+       ['170.38.91.162'],
+       ['182.195.149.80'],
+       ['197.219.164.9'],
+       ['204.204.132.158'],
+       ['247.240.82.209']
+];
+tableTest(
+       'Bug 17141: IPv4 address sorting',
+       ['IP'],
+       ipv4,
+       ipv4Sorted,
+       function( $table ) {
+               $table.tablesorter();
+               $table.find('.headerSort:eq(0)').click();
+       }
+);
+tableTest(
+       'Bug 17141: IPv4 address sorting (reverse)',
+       ['IP'],
+       ipv4,
+       reversed(ipv4Sorted),
+       function( $table ) {
+               $table.tablesorter();
+               $table.find('.headerSort:eq(0)').click().click();
+       }
+);
+
 })();