X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2FJavaScriptMinifierTest.php;h=3787962affd7ddcb30ce537b6fc76d5567c65444;hb=39f0f919c5708f4c672a8eb7e0891f50bf16883e;hp=d23534ed67077832cc8d4228e0083cfe6f508e44;hpb=c2246e3327f7a1907a8ad53b04de2d142518dc0b;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index d23534ed67..98494c4386 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -2,167 +2,197 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase { + use MediaWikiCoversValidator; + public static function provideCases() { - return array( + return [ // Basic whitespace and comments that should be stripped entirely - array( "\r\t\f \v\n\r", "" ), - array( "/* Foo *\n*bar\n*/", "" ), + [ "\r\t\f \v\n\r", "" ], + [ "/* 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. */ - array( + [ "/**\n * Foo\n * {\n * 'bar' : {\n * " . "//Multiple rules with configurable operators\n * 'baz' : false\n * }\n */", - "" ), + "" ], /** * ' Foo \' bar \ * baz \' quox ' . */ - array( + [ "' Foo \\' bar \\\n baz \\' quox ' .length", "' Foo \\' bar \\\n baz \\' quox '.length" - ), - array( + ], + [ "\" Foo \\\" bar \\\n baz \\\" quox \" .length", "\" Foo \\\" bar \\\n baz \\\" quox \".length" - ), - array( "// Foo b/ar baz", "" ), - array( + ], + [ "// Foo b/ar baz", "" ], + [ "/ Foo \\/ bar [ / \\] / ] baz / .length", "/ Foo \\/ bar [ / \\] / ] baz /.length" - ), + ], // HTML comments - array( " bar", "" ), - array( "--> Foo", "" ), - array( "x --> y", "x-->y" ), + [ " bar", "" ], + [ "--> Foo", "" ], + [ "x --> y", "x-->y" ], // Semicolon insertion - array( "(function(){return\nx;})", "(function(){return\nx;})" ), - array( "throw\nx;", "throw\nx;" ), - array( "while(p){continue\nx;}", "while(p){continue\nx;}" ), - array( "while(p){break\nx;}", "while(p){break\nx;}" ), - array( "var\nx;", "var x;" ), - array( "x\ny;", "x\ny;" ), - array( "x\n++y;", "x\n++y;" ), - array( "x\n!y;", "x\n!y;" ), - array( "x\n{y}", "x\n{y}" ), - array( "x\n+y;", "x+y;" ), - array( "x\n(y);", "x(y);" ), - array( "5.\nx;", "5.\nx;" ), - array( "0xFF.\nx;", "0xFF.x;" ), - array( "5.3.\nx;", "5.3.x;" ), + [ "(function(){return\nx;})", "(function(){return\nx;})" ], + [ "throw\nx;", "throw\nx;" ], + [ "while(p){continue\nx;}", "while(p){continue\nx;}" ], + [ "while(p){break\nx;}", "while(p){break\nx;}" ], + [ "var\nx;", "var x;" ], + [ "x\ny;", "x\ny;" ], + [ "x\n++y;", "x\n++y;" ], + [ "x\n!y;", "x\n!y;" ], + [ "x\n{y}", "x\n{y}" ], + [ "x\n+y;", "x+y;" ], + [ "x\n(y);", "x(y);" ], + [ "5.\nx;", "5.\nx;" ], + [ "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). - array( + // 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;cparse( $minified, 'minify-test.js', 1 ); } @@ -174,21 +204,21 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase { } public static function provideExponentLineBreaking() { - return array( - array( + return [ + [ // This one gets interpreted all together by the prior code; // no break at the 'E' happens. '1.23456789E55', - ), - array( + ], + [ // This one breaks under the bad code; splits between 'E' and '+' '1.23456789E+5', - ), - array( + ], + [ // This one breaks under the bad code; splits between 'E' and '-' '1.23456789E-5', - ), - ); + ], + ]; } /**