<commit_before>use v6;

use Test;
use App::Subcommander;

my $prev-name;
my $prev-required-name;
my $show-help-called;

sub reset {
    $prev-name = Str;
    $prev-required-name = Str;
    $show-help-called = False;
}

my class App does App::Subcommander {
    method do-stuff(Str :$name = 'Bob') is subcommand {
        $prev-name = $name;
    }

    method has-required-flag(Str :$name!) is subcommand {
        $prev-required-name = $name;
    }

    method show-help {
        $show-help-called = True;
    }
}

my $*ERR = open(IO::Spec.devnull, :w);

App.new.run(['do-stuff']);

is $prev-name, 'Bob', 'the default value should be used if no value is provided';
ok !$show-help-called, 'show-help should not have been called even if a value for an option is not provided';

reset();

App.new.run(['do-stuff', '--name=Fred']);

is $prev-name, 'Fred', 'the value used should follow the equals sign';
ok !$show-help-called, 'show-help should not have been called if a value for an option has been provided';

reset();

App.new.run(['do-stuff', '--name', 'Fred']);

is $prev-name, 'Fred', 'the value used may also be the following parameter';
ok !$show-help-called, 'show-help should not have been called if a value for an option has been provided';

reset();

App.new.run(['do-stuff', '--name']);

ok !$prev-name.defined, 'the subcommand should not be called if no value is provided for an option';
ok $show-help-called, 'show-help should be called if no value is provided for an option';

reset();

App.new.run(['has-required-flag']);

ok !$prev-required-name.defined, 'missing required named parameter should not call the subcommand';
ok $show-help-called, 'show-help should be called if required named parameter is missing';

reset();

App.new.run(['has-required-flag', '--name=Fred']);

is $prev-required-name, 'Fred', 'passing in a value to a required option should work';
ok !$show-help-called, 'show-help should not be called if required option is given a value';

reset();

done();

# XXX boolean option
# XXX integer option
# XXX "mandatory" option<commit_msg>Test unrecognized named parameters<commit_after>use v6;

use Test;
use App::Subcommander;

my $prev-name;
my $prev-required-name;
my $show-help-called;

sub reset {
    $prev-name = Str;
    $prev-required-name = Str;
    $show-help-called = False;
}

my class App does App::Subcommander {
    method do-stuff(Str :$name = 'Bob') is subcommand {
        $prev-name = $name;
    }

    method has-required-flag(Str :$name!) is subcommand {
        $prev-required-name = $name;
    }

    method show-help {
        $show-help-called = True;
    }
}

my $*ERR = open(IO::Spec.devnull, :w);

App.new.run(['do-stuff']);

is $prev-name, 'Bob', 'the default value should be used if no value is provided';
ok !$show-help-called, 'show-help should not have been called even if a value for an option is not provided';

reset();

App.new.run(['do-stuff', '--name=Fred']);

is $prev-name, 'Fred', 'the value used should follow the equals sign';
ok !$show-help-called, 'show-help should not have been called if a value for an option has been provided';

reset();

App.new.run(['do-stuff', '--name', 'Fred']);

is $prev-name, 'Fred', 'the value used may also be the following parameter';
ok !$show-help-called, 'show-help should not have been called if a value for an option has been provided';

reset();

App.new.run(['do-stuff', '--name']);

ok !$prev-name.defined, 'the subcommand should not be called if no value is provided for an option';
ok $show-help-called, 'show-help should be called if no value is provided for an option';

reset();

App.new.run(['has-required-flag']);

ok !$prev-required-name.defined, 'missing required named parameter should not call the subcommand';
ok $show-help-called, 'show-help should be called if required named parameter is missing';

reset();

App.new.run(['has-required-flag', '--name=Fred']);

is $prev-required-name, 'Fred', 'passing in a value to a required option should work';
ok !$show-help-called, 'show-help should not be called if required option is given a value';

reset();

App.new.run(['do-stuff', '--bad-name=Fred']);

ok !$prev-name.defined, 'passing in an unrecognized option should not invoke the subcommand';
ok $show-help-called, 'show-help should be called if an unrecognized option is passed in';

reset();

done();

# XXX boolean option
# XXX integer option
# XXX "mandatory" option
{'fraction_non_alphanumeric': 0.14766015447523853, 'fraction_numerical': 0.00045433893684688776, 'mean_word_length': 3.8922222222222222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3904360', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1403, 'n_words': 518}