#!perl

use 5.010;
use strict;
use warnings;

use Test::More 0.98;
use Test::Perinci::Sub::Wrapper qw(test_wrap);

subtest 'opt: _schema_is_normalized' => sub {
    my $sub  = sub {};
    my $meta = {v=>1.1, args=>{a=>{schema=>"int"},
                               b=>{cmdline_aliases=>{B=>{schema=>"bool"}}}}};
    test_wrap(
        name => "normalized",
        wrap_args => {sub => $sub, meta => $meta},
        posttest => sub {
            my ($wrap_res, $call_res) = @_;
            my $newmeta = $wrap_res->[2]{meta};
            is_deeply($newmeta->{args}{a}{schema}, [int=>{}, {}],
                      "schemas by default are normalized (a)");
            is_deeply($newmeta->{args}{b}{cmdline_aliases}{B}{schema},[bool=>{},{}],
                      "schemas in cmdline_aliases by default are normalized (b)");
        },
    );
    test_wrap(
        name => 'not normalized',
        wrap_args => {sub => $sub, meta => $meta, _schema_is_normalized=>1},
        posttest => sub {
            my ($wrap_res, $call_res) = @_;
            my $newmeta = $wrap_res->[2]{meta};
            is_deeply($newmeta->{args}{a}{schema}, "int",
                      "schemas are not normalized (a)")
                or diag explain $newmeta;
            is_deeply($newmeta->{args}{b}{cmdline_aliases}{B}{schema}, "bool",
                      "schemas in cmdline_aliases are not normalized (b)")
                or diag explain $newmeta;
        },
    );
};

DONE_TESTING:
done_testing;
