use strict;
use warnings;
use utf8;
use Test::More;
use File::Spec;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;

my $lib = File::Spec->rel2abs('lib');
my $t = File::Spec->rel2abs('t');
my $home = "$t/home";
my $app_lib = "$home/lib";
$ENV{HOME} = $home;

use Getopt::EX::Loader;

unshift @INC, $app_lib;

##
## deal_with
##
{
    local %INC = %INC;
    my $rcloader = Getopt::EX::Loader->new(
	BASECLASS => "App::example",
    );
    my @argv = qw(-Mexample_test
		  --drink-me
		  --shift-here howdy
		  --deprecated --ignore-me
		  --remove-next remove-me
		  --double-next double-me
		  --exch 2nd 1st
	);
    $rcloader->load_file("$ENV{HOME}/testrc");
    $rcloader->deal_with(\@argv);
    is_deeply(\@argv,
	      [ qw(--default poison
		--shift-howdy
		double-me double-me
		1st 2nd)
	      ],
	      "deal_with");
}

##
## call twice
##
{
    local %INC = %INC;
    my $rcloader = Getopt::EX::Loader->new(
	BASECLASS => "App::example",
    );
    my @argv = qw(-Mexample_test -Mexample_test dont panic);
    $rcloader->deal_with(\@argv);
    is_deeply(\@argv, [ qw(--default dont panic) ],
	      "call twice");
}

##
## BASECLASS
##
for my $param (
    [ "single",             'App::example' ],
    [ "array",              [ qw(App::foo App::bar App::example) ] ],
    [ "array w/empty base", [ '', 'App::example' ] ],
    )
{
    local %INC = %INC;
    my($comment, $baseclass) = @$param;
    my $rcloader = Getopt::EX::Loader->new(
	BASECLASS => $baseclass,
	);
    my $mod = $rcloader->load_module('example_test');
    is($mod->{Module}, "App::example::example_test", $comment);
}

done_testing();
