Docopt
view release on metacpan or search on metacpan
t/test_docopt.py.t view on Meta::CPAN
'Docopt::Exceptions::DocoptExit',
);
# assert docopt('usage: prog [options]', '--long=arg --long=another',
# any_options=True) == {'--long': ['arg', 'another']}
};
subtest 'test_default_value_for_positional_arguments' => sub {
# disabled right now
is_deeply(
docopt(doc => "usage: prog [<p>]\n\n<p> [default: x]", argv => ""),
{'<p>' => None}
# {'<p>': 'x'}
);
is_deeply(
docopt(doc => "usage: prog [<p>]...\n\n<p> [default: x y]", argv => ""),
{'<p>' => []}
# {'<p>': ['x', 'y']}
);
is_deeply_ex(
docopt(doc => "usage: prog [<p>]...\n\n<p> [default: x y]", argv => "this"),
{'<p>' => ['this']}
# {'<p>': ['this']}
);
};
subtest 'test_issue_59' => sub {
is_deeply(
docopt(doc => 'usage: prog --long=<a>', argv => '--long='),
{'--long' => ''}
);
is_deeply(
docopt(doc => "usage: prog -l <a>\noptions: -l <a>", argv => ['-l', '']),
{'-l'=> ''}
);
};
subtest 'test_options_first()' => sub {
is_deeply_ex(docopt(doc => 'usage: prog [--opt] [<args>...]',
argv => '--opt this that'), {'--opt'=> True,
'<args>'=> ['this', 'that']});
is_deeply_ex(docopt(doc => 'usage: prog [--opt] [<args>...]',
argv => 'this that --opt'), {'--opt'=> True,
'<args>'=> ['this', 'that']});
is_deeply_ex(docopt(doc => 'usage: prog [--opt] [<args>...]',
argv => 'this that --opt',
option_first => True), {'--opt'=> undef,
'<args>'=> ['this', 'that', '--opt']});
};
subtest 'test_issue_68_options_shortcut_does_not_include_options_in_usage_pattern' => sub {
my $args = docopt(doc => "usage: prog [-ab] [options]\noptions: -x\n -y", argv => '-ax');
# Need to use `is` (not `==`) since we want to make sure
# that they are not 1/0, but strictly True/False:
is_deeply($args->{'-a'}, True);
is_deeply($args->{'-b'}, undef);
is_deeply($args->{'-x'}, True);
is_deeply($args->{'-y'}, undef);
};
subtest 'test_issue_65_evaluate_argv_when_called_not_when_imported' => sub {
local @ARGV = qw(-a);
is_deeply(docopt(doc => 'usage: prog [-ab]'), {'-a' => True, '-b' => undef});
local @ARGV = qw(-b);
is_deeply(docopt(doc => 'usage: prog [-ab]'), {'-a' => undef, '-b'=> True});
};
subtest 'test_issue_71_double_dash_is_not_a_valid_option_argument' => sub {
isa_ok(
exception { docopt(doc => 'usage: prog [--log=LEVEL] [--] <args>...', argv => '--log -- 1 2') },
'Docopt::Exceptions::DocoptExit',
);
isa_ok(
exception {
docopt(doc => "usage: prog [-l LEVEL] [--] <args>...
options: -l LEVEL", argv => "-l -- 1 2")
},
'Docopt::Exceptions::DocoptExit',
);
};
subtest 'test_parse_section' => sub {
my $usage = qq{usage: this
usage:hai
usage: this that
usage: foo
bar
PROGRAM USAGE:
foo
bar
usage:
\ttoo
\ttar
Usage: eggs spam
BAZZ
usage: pit stop};
is_deeply([parse_section('usage:', 'foo bar fizz buzz')], []);
is_deeply([parse_section('usage:', 'usage: prog')], ['usage: prog']);
is_deeply([parse_section('usage:',
'usage: -x\n -y')], ['usage: -x\n -y']);
is_deeply([parse_section('usage:', $usage)], [
"usage: this",
"usage:hai",
"usage: this that",
"usage: foo\n bar",
"PROGRAM USAGE:\n foo\n bar",
"usage:\n\ttoo\n\ttar",
"Usage: eggs spam",
"usage: pit stop",
]);
};
done_testing;
sub test_pattern_flat {
my ($input, $expected, $types) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $got = $input->flat($types);
is_deeply(
( run in 0.688 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )