From 68a33aeccff175d412cccbc256e4cd5549420870 Mon Sep 17 00:00:00 2001 From: scribu Date: Mon, 11 Feb 2013 19:14:07 +0200 Subject: [PATCH] add tests for SynopsisParser --- phpunit.xml.dist | 1 + tests/bootstrap.php | 1 + tests/test-synopsis.php | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/test-synopsis.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 917a7d50..529dae0e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,6 +5,7 @@ tests/ + tests/ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4e82b7fa..c24b9461 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,6 @@ []' ); + + $this->assertEquals( 2, count( $r['positional'] ) ); + $this->assertFalse( $r['positional'][0]['optional'] ); + $this->assertTrue( $r['positional'][1]['optional'] ); + } + + function testFlag() { + $r = SynopsisParser::parse( '--foo' ); + $this->assertEquals( 0, count( $r['flag'] ) ); // flags can't be mandatory + + $r = SynopsisParser::parse( '[--foo]' ); + $this->assertEquals( 1, count( $r['flag'] ) ); + } + + function testGeneric() { + $r = SynopsisParser::parse( '--=' ); + + $this->assertEquals( 1, count( $r['generic'] ) ); + } + + function testAssoc() { + $r = SynopsisParser::parse( '--foo= [--bar=]' ); + + $this->assertEquals( 2, count( $r['assoc'] ) ); + $this->assertFalse( $r['assoc'][0]['optional'] ); + $this->assertTrue( $r['assoc'][1]['optional'] ); + } +} + -- 2.11.0