diff options
author | Nathan Gass | 2012-03-22 18:18:42 +0000 |
---|---|---|
committer | Nathan Gass | 2012-03-22 18:18:42 +0000 |
commit | d59a4921188753dbe4c0161081755a28112c3ef6 (patch) | |
tree | 81496414d988f37f1db9d92c9750d888ffa13746 /devel-utf8/tests/getopt.t | |
parent | ca11771e8fad5fef96615df4c44e04b8fb60ac31 (diff) | |
download | itools-d59a4921188753dbe4c0161081755a28112c3ef6.tar.gz itools-d59a4921188753dbe4c0161081755a28112c3ef6.tar.bz2 itools-d59a4921188753dbe4c0161081755a28112c3ef6.zip |
Branch itools/devel-utf8 created
Diffstat (limited to 'devel-utf8/tests/getopt.t')
-rwxr-xr-x | devel-utf8/tests/getopt.t | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/devel-utf8/tests/getopt.t b/devel-utf8/tests/getopt.t new file mode 100755 index 0000000..7a84588 --- /dev/null +++ b/devel-utf8/tests/getopt.t @@ -0,0 +1,29 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for getopt in it.class + +$GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS] +Some help to a not existing program + -h,--help the help argument + -a,--argument=ARG the arg argument + -0,--zero testworthy shortarg +"; + +function getopt_ok($argv, $exp, $name) +{ + $_SERVER['argv'] = array_merge(array('doesnotexist.php'), $argv); + $got = it::getopt($GLOBALS['usage']); + return is($got['argument'], $exp, $name); +} + +foreach (array("" => "blah gnaber", " (umlaute)" => "pre üäpost") as $variant => $testarg) { + getopt_ok(array('-a', $testarg), $testarg, "Short version" . $variant); + getopt_ok(array('--argument', $testarg), $testarg, "Long version with space" . $variant); + getopt_ok(array("--argument=$testarg"), $testarg, "Long version with equal" . $variant); +} + +$_SERVER['argv'] = array('doesnotexist.php', '-0'); +$zero_opts = it::getopt($GLOBALS['usage']); +ok($zero_opts['zero'], '-0'); + |