From 5aef64122fbb5a5855af095206bd642ca08cca61 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 15 Jun 2021 16:57:36 +0200 Subject: allow leading - in ::getopt option arguments, add tests --- test/it.t | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/it.t b/test/it.t index a3abf32..a6dc067 100755 --- a/test/it.t +++ b/test/it.t @@ -509,3 +509,29 @@ function requesturi($teststring, $expect) it::params2utf8(); is(urldecode($_SERVER['REQUEST_URI']), $expect, "parms2utf8('$expect')"); } + +_getopt(["val"], ['foo' => "val"]); +_getopt(["--", "-val"], ['foo' => "-val"]); +_getopt(["-v", "val"], ['verbose' => true, 'foo' => "val"]); +_getopt(["--verbose", "val"], ['verbose' => true, 'foo' => "val"]); +_getopt(["-vw", "val"], ['verbose' => true, 'werbose' => true, 'foo' => "val"]); +_getopt(["-a", "val1", "val2"], ['arg' => "val1", 'foo' => "val2"]); +_getopt(["--arg", "val1", "val2"], ['arg' => "val1", 'foo' => "val2"]); +_getopt(["--arg=val1", "val2"], ['arg' => "val1", 'foo' => "val2"]); +_getopt(["-va", "val1", "val2"], ['verbose' => true, 'arg' => "val1", 'foo' => "val2"]); +_getopt(["-va", "-val1", "val2"], ['verbose' => true, 'arg' => "-val1", 'foo' => "val2"]); +_getopt(["val1", "val2"], ['args' => ["val2"], 'foo' => 'val1']); + +function _getopt($in, $expect) +{ + $_SERVER['argv'] = array_merge(["cmd.php"], $in); + $opts = it::getopt(" + Usage: test [OPTIONS] FOO [BAR] + -v, --verbose Be verbose + -w, --werbose Be werbose + -a, --arg=ARG Have argument + -b, --brg=ARG Have another arg + "); + + is($opts, ['args' => $expect['args'] ?? []] + $expect); +} -- cgit v1.2.3