From: scribu Date: Mon, 11 Feb 2013 20:17:43 +0000 (+0200) Subject: make synopsis parser return unknown tokens X-Git-Tag: v0.9.0~100^2~7 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f0d3d349d6faa9c62263bcea33e15a03248ec0c2;p=wvm%2Fwvm.git make synopsis parser return unknown tokens --- diff --git a/php/WP_CLI/SynopsisParser.php b/php/WP_CLI/SynopsisParser.php index bc594df3..94cb0544 100644 --- a/php/WP_CLI/SynopsisParser.php +++ b/php/WP_CLI/SynopsisParser.php @@ -14,6 +14,8 @@ class SynopsisParser { $tokens = preg_split( '/[\s\t]+/', $synopsis ); foreach ( $tokens as $token ) { + $type = false; + foreach ( $patterns as $regex => $desc ) { if ( preg_match( $regex, $token, $matches ) ) { $type = $desc['type']; @@ -21,6 +23,10 @@ class SynopsisParser { break; } } + + if ( !$type ) { + $params['unknown'][] = $token; + } } return $params; diff --git a/tests/test-synopsis.php b/tests/test-synopsis.php index 624cc45c..a92c7c35 100644 --- a/tests/test-synopsis.php +++ b/tests/test-synopsis.php @@ -13,11 +13,12 @@ class SynopsisParserTest extends PHPUnit_Framework_TestCase { } function testFlag() { - $r = SynopsisParser::parse( '--foo' ); - $this->assertFoundParameters( 0, 'flag', $r ); // flags can't be mandatory - $r = SynopsisParser::parse( '[--foo]' ); $this->assertFoundParameters( 1, 'flag', $r ); + + // flags can't be mandatory + $r = SynopsisParser::parse( '--foo' ); + $this->assertFoundParameters( 1, 'unknown', $r ); } function testGeneric() { @@ -34,6 +35,10 @@ class SynopsisParserTest extends PHPUnit_Framework_TestCase { $this->assertFoundParameters( 2, 'assoc', $r ); $this->assertFalse( $r['assoc'][0]['optional'] ); $this->assertTrue( $r['assoc'][1]['optional'] ); + + // shouldn't pass defaults to assoc parameters + $r = SynopsisParser::parse( '--count=100' ); + $this->assertFoundParameters( 1, 'unknown', $r ); } function testCombined() {