Very basic JavaScriiptDistiller tests, needs serious expansion
authorMax Semenik <maxsem@users.mediawiki.org>
Wed, 23 Feb 2011 08:06:11 +0000 (08:06 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Wed, 23 Feb 2011 08:06:11 +0000 (08:06 +0000)
tests/phpunit/includes/libs/JavaScriptDistillerTest.php [new file with mode: 0644]
tests/phpunit/includes/libs/distiller-in.js [new file with mode: 0644]
tests/phpunit/includes/libs/distiller-out-full.js [new file with mode: 0644]
tests/phpunit/includes/libs/distiller-out.js [new file with mode: 0644]

diff --git a/tests/phpunit/includes/libs/JavaScriptDistillerTest.php b/tests/phpunit/includes/libs/JavaScriptDistillerTest.php
new file mode 100644 (file)
index 0000000..ddacd1e
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @group Distiller
+ */
+class JavaScriptDistillerTest extends PHPUnit_Framework_TestCase {
+       public function testDistiller() {
+               $in = self::read( 'distiller-in.js' );
+               $out = self::read( 'distiller-out.js' );
+               $outFull = self::read( 'distiller-out-full.js' );
+               $this->assertEquals( $out, JavaScriptDistiller::stripWhiteSpace( $in ) );
+               $this->assertEquals( $outFull, JavaScriptDistiller::stripWhiteSpace( $in, true ) );
+       }
+       
+       private static function read( $file ) {
+               $text = file_get_contents( dirname( __FILE__ ) . "/$file" );
+               return str_replace( "\r\n", "\n", $text );
+       }
+}
\ No newline at end of file
diff --git a/tests/phpunit/includes/libs/distiller-in.js b/tests/phpunit/includes/libs/distiller-in.js
new file mode 100644 (file)
index 0000000..6611695
--- /dev/null
@@ -0,0 +1,15 @@
+/* this is a comment */
+/* a multi-
+                 line comment */
+/* a /* weird comment */
+// one-line comment
+var string = /* comment */'/* comment in string */';
+
+move_to_the_same_line()
+
+                               dont_move();
+                               
+if ( / a + bfoo.* /i.test( bar )  && ( a / b ) * c + d - e) { /* blah */
+       statement();
+       statement()
+}
\ No newline at end of file
diff --git a/tests/phpunit/includes/libs/distiller-out-full.js b/tests/phpunit/includes/libs/distiller-out-full.js
new file mode 100644 (file)
index 0000000..ae0b356
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+
+
+var string='/* comment in string */';move_to_the_same_line()
+dont_move();if(/ a + bfoo.* /i.test(bar)&&(a/ b ) * c + d - e){
+statement();statement()}
\ No newline at end of file
diff --git a/tests/phpunit/includes/libs/distiller-out.js b/tests/phpunit/includes/libs/distiller-out.js
new file mode 100644 (file)
index 0000000..1886143
--- /dev/null
@@ -0,0 +1,11 @@
+
+
+
+
+var string='/* comment in string */';
+move_to_the_same_line()
+dont_move();
+if(/ a + bfoo.* /i.test(bar)&&(a/ b ) * c + d - e) { /*blah*/
+statement();
+statement()
+}
\ No newline at end of file