From: Timo Tijhof Date: Wed, 20 Jun 2012 01:52:37 +0000 (+0200) Subject: JavaScriptMinifierTest: Increase test coverage X-Git-Tag: 1.31.0-rc.0~23240^2 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=c33087beaabe3bcc72fe9e5b41017b279f475e6c;p=lhc%2Fweb%2Fwiklou.git JavaScriptMinifierTest: Increase test coverage * Per https://bugzilla.wikimedia.org/show_bug.cgi?id=27395#c1 adding test cases for things that broke in the past: - bug 26931 - bug 27046 * Added various other small tests that seem fitting in their context * Moved testBug32548Exponent to below the data provider (like most other tests iirc). Change-Id: I7a4df097108ec05bc58d5a110329e13ff9587c8a --- diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index d2bfeedfcf..f121b018da 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -4,9 +4,18 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { function provideCases() { return array( - // Basic tokens + + // Basic whitespace and comments that should be stripped entirely array( "\r\t\f \v\n\r", "" ), array( "/* Foo *\n*bar\n*/", "" ), + + /** + * Slashes used inside block comments (bug 26931). + * 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 ' . @@ -15,11 +24,13 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { array( "\" Foo \\\" bar \\\n baz \\\" quox \" .length", "\" Foo \\\" bar \\\n baz \\\" quox \".length" ), array( "// Foo b/ar baz", "" ), array( "/ Foo \\/ bar [ / \\] / ] baz / .length", "/ Foo \\/ bar [ / \\] / ] baz /.length" ), + // HTML comments array( " bar", "" ), array( "--> Foo", "" ), array( "x --> y", "x-->y" ), + // Semicolon insertion array( "(function(){return\nx;})", "(function(){return\nx;})" ), array( "throw\nx;", "throw\nx;" ), @@ -35,12 +46,19 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { array( "5.\nx;", "5.\nx;" ), array( "0xFF.\nx;", "0xFF.x;" ), array( "5.3.\nx;", "5.3.x;" ), + + // Semicolon insertion between an expression having an inline + // comment after it, and a statement on the next line (bug 27046). + array( "var a = this //foo bar \n for ( b = 0; c < d; b++ ) {}", "var a=this\nfor(b=0;cassertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." ); } - /** - * @dataProvider provideBug32548 - */ - function testBug32548Exponent($num) { - // Long line breaking was being incorrectly done between the base and - // exponent part of a number, causing a syntax error. The line should - // instead break at the start of the number. - $prefix = 'var longVarName' . str_repeat('_', 973) . '='; - $suffix = ',shortVarName=0;'; - - $input = $prefix . $num . $suffix; - $expected = $prefix . "\n" . $num . $suffix; - - $minified = JavaScriptMinifier::minify( $input ); - - $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent"); - } - function provideBug32548() { return array( array( @@ -145,4 +149,22 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { ), ); } + + /** + * @dataProvider provideBug32548 + */ + function testBug32548Exponent( $num ) { + // Long line breaking was being incorrectly done between the base and + // exponent part of a number, causing a syntax error. The line should + // instead break at the start of the number. + $prefix = 'var longVarName' . str_repeat( '_', 973 ) . '='; + $suffix = ',shortVarName=0;'; + + $input = $prefix . $num . $suffix; + $expected = $prefix . "\n" . $num . $suffix; + + $minified = JavaScriptMinifier::minify( $input ); + + $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent"); + } }