$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'];
break;
}
}
+
+ if ( !$type ) {
+ $params['unknown'][] = $token;
+ }
}
return $params;
}
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() {
$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() {