From: scribu Date: Thu, 1 Aug 2013 20:08:40 +0000 (+0300) Subject: add a few unit tests for DocParser X-Git-Tag: v0.11.0~7^2~10 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fd37d17336bc433f2976eba6e48bdf66eb7d84b3;p=wvm%2Fwvm.git add a few unit tests for DocParser --- diff --git a/php/WP_CLI/DocParser.php b/php/WP_CLI/DocParser.php index c5bfb164..f830285e 100644 --- a/php/WP_CLI/DocParser.php +++ b/php/WP_CLI/DocParser.php @@ -17,6 +17,10 @@ class DocParser { return $matches[1]; } + function get_longdesc() { + return false; + } + function get_tag( $name ) { if ( preg_match( '/@' . $name . '\s+([a-z-_]+)/', $this->docComment, $matches ) ) return $matches[1]; diff --git a/tests/test-doc-parser.php b/tests/test-doc-parser.php new file mode 100644 index 00000000..2026b3af --- /dev/null +++ b/tests/test-doc-parser.php @@ -0,0 +1,75 @@ +assertFalse( $doc->get_shortdesc() ); + $this->assertFalse( $doc->get_longdesc() ); + $this->assertFalse( $doc->get_synopsis() ); + $this->assertFalse( $doc->get_tag('foo') ); + $this->assertEquals( 'rock-on', $doc->get_tag('alias') ); + } + + function test_no_longdesc() { + $doc = new DocParser( <<assertEquals( 'Rock and roll!', $doc->get_shortdesc() ); + $this->assertFalse( $doc->get_longdesc() ); + $this->assertFalse( $doc->get_synopsis() ); + $this->assertEquals( 'rock-on', $doc->get_tag('alias') ); + } + + function test_complete() { + $doc = new DocParser( << + * : Sets the volume. + * + * ## EXAMPLES + * + * wp rock-on --volume=11 + * + * @synopsis [--volume=] + * @alias rock-on + */ +EOB + ); + + $this->assertEquals( 'Rock and roll!', $doc->get_shortdesc() ); + $this->assertEquals( '[--volume=]', $doc->get_synopsis() ); + $this->assertEquals( 'rock-on', $doc->get_tag('alias') ); + + $longdesc = << +: Sets the volume. + +## EXAMPLES + +wp rock-on --volume=11 +EOB + ; + $this->assertEquals( $longdesc, $doc->get_longdesc() ); + } +} +