Add getopts support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3525 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
157
Tests/getoptsTest.php
Normal file
157
Tests/getoptsTest.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
require_once ("getopts.php");
|
||||
|
||||
/** Test the GetOpts */
|
||||
class test_getopts extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_empty1 ()
|
||||
{
|
||||
// Empty
|
||||
$getopts = new getopts ();
|
||||
$res = $getopts->help ();
|
||||
$this->assertSame ($res, "No option defined\n");
|
||||
}
|
||||
|
||||
public function test_simu1 ()
|
||||
{
|
||||
$getopts = new getopts ();
|
||||
$res = $getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
|
||||
$this->assertSame (is_object ($res), true);
|
||||
}
|
||||
|
||||
public function test_add1 ()
|
||||
{
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
|
||||
$res = $getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$this->assertSame (is_object ($res), true);
|
||||
}
|
||||
|
||||
public function test_add2 ()
|
||||
{
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$res = $getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$this->assertSame (is_object ($res), true);
|
||||
}
|
||||
|
||||
public function test_scan1 ()
|
||||
{
|
||||
$this->expectException ("Exception", "Provided tokens are not known: -f,ii,-o,1 2,-o,2 2,-o,3");
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->scan ();
|
||||
}
|
||||
|
||||
public function test_getShort1 ()
|
||||
{
|
||||
// One unique value (-h -> true/false)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Help");
|
||||
$this->assertSame ($res, true);
|
||||
}
|
||||
|
||||
public function test_getShort2 ()
|
||||
{
|
||||
// Multiple values, two set (-d -d)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array (true,true));
|
||||
}
|
||||
|
||||
public function test_getShort3 ()
|
||||
{
|
||||
// Multiple values, one set (-d)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array (true));
|
||||
}
|
||||
|
||||
public function test_getShort4 ()
|
||||
{
|
||||
// Multiple values, None set (-d)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array ());
|
||||
}
|
||||
|
||||
public function test_getLong1 ()
|
||||
{
|
||||
// One unique value (--help -> true/false)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate --help -d -d ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Help");
|
||||
$this->assertSame ($res, true);
|
||||
}
|
||||
|
||||
public function test_getLong2 ()
|
||||
{
|
||||
// Multiple values, two set (-debug --debug)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h --debug --debug ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array (true,true));
|
||||
}
|
||||
|
||||
public function test_getLong3 ()
|
||||
{
|
||||
// Multiple values, one set (-d)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate --help -d ");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array (true));
|
||||
}
|
||||
|
||||
public function test_getLong4 ()
|
||||
{
|
||||
// Multiple values, None set (-d)
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->get ("Debug");
|
||||
$this->assertSame ($res, array ());
|
||||
}
|
||||
|
||||
public function test_restOfLine1 ()
|
||||
{
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d -- -bla final");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->restOfLine ();
|
||||
$this->assertSame ($res, array ("-bla", "final"));
|
||||
}
|
||||
|
||||
public function test_programName1 ()
|
||||
{
|
||||
$getopts = new getopts ();
|
||||
$getopts->simulate ("sim\ ulate -h -d -d -- -bla final");
|
||||
$getopts->add ("Help", "?h", array ("help","help2"), "Help of the software");
|
||||
$getopts->add ("Debug", "d", "debug", "Debug", "DebugLevel", 2);
|
||||
$res = $getopts->programName ();
|
||||
$this->assertSame ($res, "sim ulate");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user