OSDN Git Service

add test for combined param types
authorscribu <mail@scribu.net>
Mon, 11 Feb 2013 19:51:12 +0000 (21:51 +0200)
committerscribu <mail@scribu.net>
Mon, 11 Feb 2013 19:51:12 +0000 (21:51 +0200)
tests/test-synopsis.php

index 5649d80..01322b0 100644 (file)
@@ -21,9 +21,11 @@ class SynopsisParserTest extends PHPUnit_Framework_TestCase {
        }
 
        function testGeneric() {
-               $r = SynopsisParser::parse( '--<field>=<value>' );
+               $r = SynopsisParser::parse( '--<field>=<value> [--<field>=<value>]' );
 
-               $this->assertFoundParameters( 1, 'generic', $r );
+               $this->assertFoundParameters( 2, 'generic', $r );
+               $this->assertFalse( $r['generic'][0]['optional'] );
+               $this->assertTrue( $r['generic'][1]['optional'] );
        }
 
        function testAssoc() {
@@ -34,6 +36,15 @@ class SynopsisParserTest extends PHPUnit_Framework_TestCase {
                $this->assertTrue( $r['assoc'][1]['optional'] );
        }
 
+       function testCombined() {
+               $r = SynopsisParser::parse( '<positional> --assoc=<someval> --<field>=<value> [--flag]' );
+
+               $this->assertEquals( 1, count( $r['positional'] ) );
+               $this->assertEquals( 1, count( $r['assoc'] ) );
+               $this->assertEquals( 1, count( $r['generic'] ) );
+               $this->assertEquals( 1, count( $r['flag'] ) );
+       }
+
        protected function assertFoundParameters( $count, $type, $r ) {
                foreach ( $r as $key => $params ) {
                        $expected = ( $key == $type ) ? $count : 0;