Adding isIp-tests to MW JS Test Suite (based on IPTest.php)
authorKrinkle <krinkle@users.mediawiki.org>
Fri, 4 Mar 2011 02:11:13 +0000 (02:11 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Fri, 4 Mar 2011 02:11:13 +0000 (02:11 +0000)
* fixing a typo in variable statement (semicolon->comma, thx JSHint, browsers tend to ignore)
* Clean up comments

resources/mediawiki.util/mediawiki.util.js
resources/mediawiki.util/mediawiki.util.test.js

index 085c4f1..26e4724 100644 (file)
                                );
                        return (null !== mailtxt.match( HTML5_email_regexp ) );
                },
-               // Note: borrows from IP.php
+               // Note: borrows from IP::isIPv4
                'isIPv4Address' : function( address, allowBlock ) {
                        var block = allowBlock ? '(?:\\/(?:3[0-2]|[12]?\\d))?' : '';
                        var RE_IP_BYTE = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])';
                        var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\\.){3}' + RE_IP_BYTE;
                        return address.search( new RegExp( '^' + RE_IP_ADD + block + '$' ) ) != -1;
                },
-               // Note: borrows from IP.php
+               // Note: borrows from IP::isIPv6
                'isIPv6Address' : function( address, allowBlock ) {
                        var block = allowBlock ? '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : '';
                        var RE_IPV6_ADD =
index ca0599b..f98632e 100644 (file)
@@ -69,7 +69,7 @@
                                                // Build page
                                                document.title = 'mediaWiki JavaScript library test suite - ' + mw.config.get( 'wgSiteName' );
                                                $( '#firstHeading' ).text( 'mediaWiki JavaScript library test suite' );
-                                               var     skinLinksText = 'Test in: ';
+                                               var     skinLinksText = 'Test in: ',
                                                        skinLinks = [],
                                                        availableSkins = mw.config.get( 'wgAvailableSkins' ),
                                                        skincode = '';
@@ -99,7 +99,7 @@
                                                // Try to roughly keep the order similar to the order in the files
                                                // or alphabetical (depending on the context)
 
-                                               // Main modules and their aliases
+                                               /** Main modules and their aliases **/
                                                mw.test.addHead( 'Main modules and their aliases' );
 
                                                mw.test.addTest( 'typeof mediaWiki',
                                                mw.test.addTest( 'typeof $',
                                                        'function (string)' );
 
-                                               // Prototype functions added by MediaWiki
+                                               /** Prototype functions added by MediaWiki **/
                                                mw.test.addHead( 'Prototype functions added by MediaWiki' );
 
                                                mw.test.addTest( 'typeof $.trimLeft',
                                                mw.test.addTest( 'typeof $.compareObject',
                                                        'function (string)' );
 
-                                               // mediawiki.js
+                                               /** mediawiki.js **/
                                                mw.test.addHead( 'mediawiki.js' );
 
                                                mw.test.addTest( 'mw.config instanceof mw.Map',
                                                mw.test.addTest( 'typeof mw.user.anonymous()',
                                                        'boolean (string)' );
 
-                                               // mediawiki.util.js
+                                               /** mediawiki.util.js **/
                                                mw.test.addHead( 'mediawiki.util.js' );
 
                                                mw.test.addTest( 'typeof mw.util',
                                                mw.test.addTest( 'mw.util.validateEmail( "userfoo@ex-ample.org" )',
                                                        'true (boolean)' );
 
+                                               // From IPTest.php IPv6
+                                               mw.test.addTest( 'mw.util.isIPv6Address( "" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv6Address( ":fc:100::" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv6Address( "fc:100::" )',
+                                                       'true (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv6Address( "fc:100:a:d:1:e:ac::" )',
+                                                       'true (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv6Address( ":::" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv6Address( "::0:" )',
+                                                       'false (boolean)' );
+
+                                               // From IPTest.php IPv4
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "...." )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "abc" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "124.24.52" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( ".24.52.13" )',
+                                                       'false (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "124.24.52.13" )',
+                                                       'true (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "1.24.52.13" )',
+                                                       'true (boolean)' );
+                                               mw.test.addTest( 'mw.util.isIPv4Address( "74.24.52.13/20" )', // Range
+                                                       'false (boolean)' );
+                                                       // @FIXME: The regex that's been in MW JS has never supported ranges but it should
+                                                       // The regex is expected to return false for that reason
+
                                                // jQuery plugins
                                                mw.test.addHead( 'jQuery plugins' );