r88012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88011‎ | r88012 | r88013 >
Date:17:28, 13 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Adding qunit tests for isIPv4Address and isIPv6Address in mw.util
Modified paths:
  • /trunk/phase3/resources/test/unit/mediawiki.util/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/test/unit/mediawiki.util/mediawiki.util.js
@@ -108,3 +108,27 @@
109109 same( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Hyphen' );
110110
111111 });
 112+
 113+
 114+
 115+test( 'isIPv6Address', function(){
 116+
 117+ // Based on IPTest.php > IPv6
 118+ same( mw.util.isIPv6Address( "" ), false, 'Empty string is not an IP' );
 119+ same( mw.util.isIPv6Address( ":fc:100::" ), false, 'IPv6 starting with lone ":"' );
 120+ same( mw.util.isIPv6Address( "fc:100::" ), true );
 121+ same( mw.util.isIPv6Address( "fc:100:a:d:1:e:ac::" ), true );
 122+ same( mw.util.isIPv6Address( ":::" ), false );
 123+ same( mw.util.isIPv6Address( "::0:" ), false );
 124+
 125+});
 126+
 127+
 128+test( 'isIPv4Address', function(){
 129+
 130+ // Based on IPTest.php > IPv4
 131+ same( mw.util.isIPv4Address( "" ), false, 'Empty string is not an IP' );
 132+ same( mw.util.isIPv4Address( "...." ), false );
 133+ same( mw.util.isIPv4Address( "1.24.52.13" ), true );
 134+
 135+});

Comments

#Comment by Hashar (talk | contribs)   08:37, 14 May 2011

Maybe we should have a meta language describing tests, then we could generate the PHPUnit test suite and the QUnit test suite from the same source. I hate it how we actually have to implements tests twice :(

#Comment by Krinkle (talk | contribs)   07:43, 15 May 2011

I'm not sure we can or should. They don't test the same code.


PHPUnit tests the IP Class from IP.php, whereas these QUnit tests test the behaviour of the isIP* functions in mediawiki.util.js, they do not behave competely the same (for example when passing no arguments, or when passing an IP-range).

I only used the tests examples (ie. "...", "::0:", etc.) from the PHP Unit tests.

Status & tagging log