Update suppressWarning()/restoreWarning() calls
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / JavaScriptMinifierTest.php
index 3787962..98494c4 100644 (file)
@@ -2,6 +2,8 @@
 
 class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
 
+       use MediaWikiCoversValidator;
+
        public static function provideCases() {
                return [
 
@@ -10,7 +12,7 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
                        [ "/* Foo *\n*bar\n*/", "" ],
 
                        /**
-                        * Slashes used inside block comments (bug 26931).
+                        * Slashes used inside block comments (T28931).
                         * At some point there was a bug that caused this comment to be ended at '* /',
                         * causing /M... to be left as the beginning of a regex.
                         */
@@ -59,13 +61,39 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
                        [ "0xFF.\nx;", "0xFF.x;" ],
                        [ "5.3.\nx;", "5.3.x;" ],
 
+                       // Cover failure case for incomplete hex literal
+                       [ "0x;", false, false ],
+
+                       // Cover failure case for number with no digits after E
+                       [ "1.4E", false, false ],
+
+                       // Cover failure case for number with several E
+                       [ "1.4EE2", false, false ],
+                       [ "1.4EE", false, false ],
+
+                       // Cover failure case for number with several E (nonconsecutive)
+                       // FIXME: This is invalid, but currently tolerated
+                       [ "1.4E2E3", "1.4E2 E3", false ],
+
                        // Semicolon insertion between an expression having an inline
-                       // comment after it, and a statement on the next line (bug 27046).
+                       // comment after it, and a statement on the next line (T29046).
                        [
                                "var a = this //foo bar \n for ( b = 0; c < d; b++ ) {}",
                                "var a=this\nfor(b=0;c<d;b++){}"
                        ],
 
+                       // Cover failure case of incomplete regexp at end of file (T75556)
+                       // FIXME: This is invalid, but currently tolerated
+                       [ "*/", "*/", false ],
+
+                       // Cover failure case of incomplete char class in regexp (T75556)
+                       // FIXME: This is invalid, but currently tolerated
+                       [ "/a[b/.test", "/a[b/.test", false ],
+
+                       // Cover failure case of incomplete string at end of file (T75556)
+                       // FIXME: This is invalid, but currently tolerated
+                       [ "'a", "'a", false ],
+
                        // Token separation
                        [ "x  in  y", "x in y" ],
                        [ "/x/g  in  y", "/x/g in y" ],
@@ -127,7 +155,7 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
                        // newline insertion after 1000 chars: break after the "++", not before
                        [ str_repeat( ';', 996 ) . "if(x++);", str_repeat( ';', 996 ) . "if(x++\n);" ],
 
-                       // Unicode letter characters should pass through ok in identifiers (bug 31187)
+                       // Unicode letter characters should pass through ok in identifiers (T33187)
                        [ "var KaŝSkatolVal = {}", 'var KaŝSkatolVal={}' ],
 
                        // Per spec unicode char escape values should work in identifiers,
@@ -138,6 +166,7 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
                        [ "var a = 5.;", "var a=5.;" ],
                        [ "5.0.toString();", "5.0.toString();" ],
                        [ "5..toString();", "5..toString();" ],
+                       // Cover failure case for too many decimal points
                        [ "5...toString();", false ],
                        [ "5.\n.toString();", '5..toString();' ],
 
@@ -153,16 +182,17 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
        /**
         * @dataProvider provideCases
         * @covers JavaScriptMinifier::minify
+        * @covers JavaScriptMinifier::parseError
         */
-       public function testJavaScriptMinifierOutput( $code, $expectedOutput, $expectedValid = true ) {
+       public function testMinifyOutput( $code, $expectedOutput, $expectedValid = true ) {
                $minified = JavaScriptMinifier::minify( $code );
 
                // JSMin+'s parser will throw an exception if output is not valid JS.
                // suppression of warnings needed for stupid crap
                if ( $expectedValid ) {
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
                        $parser = new JSParser();
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                        $parser->parse( $minified, 'minify-test.js', 1 );
                }