CXC-Gnuplot

 view release on metacpan or  search on metacpan

t/V1/Bound.t  view on Meta::CPAN

                },
            },
            {
                input => {
                    upper_bound => q{"2020-02-01"},
                    bound       => q{*},
                },
                expected => {
                    bound       => q{*},
                    lower_bound => U(),
                    upper_bound => q{"2020-02-01"},
                    to_string   => q{* < "2020-02-01"},
                },
            },
            {
                input => {
                    lower_bound => q{"2020-01-01"},
                    upper_bound => q{"2020-02-01"},
                },
                expected => {
                    bound       => q{*},
                    lower_bound => q{"2020-01-01"},
                    upper_bound => q{"2020-02-01"},
                    to_string   => q{"2020-01-01" < * < "2020-02-01"},
                },
            },
        ],

        fail => [ {
                input    => { bound => q{"2020-01-01" < "2020-02-01"} },
                expected => {
                    direct  => qr/illegal/,
                    factory => qr/illegal/,
                },
            },
            {
                input    => { bound => q{"2020-01-01" < * < *} },
                expected => {
                    direct  => qr/illegal/,
                    factory => qr/illegal/,
                },
            },
            {
                input    => { bound => q{* < * < "2020-02-01"} },
                expected => {
                    direct  => qr/illegal/,
                    factory => qr/illegal/,
                },
            },
        ],
    },
);

sub expect_object ( $class, $input, $expected, $name ) {

    my $ctx = context;

    is(
        $class->new( $input->%* ),
        object {
            prop blessed => $class;
            call $_ => $expected->{$_} for keys $expected->%*;
        },
        $name,
    );

    $ctx->release;
}

sub expect_factory_object ( $input, $subclass, $expected, $name ) {

    my $ctx = context;

    is(
        Bound->new( $input->%* ),
        object {
            prop isa     => Bound;
            prop blessed => $subclass;
            call $_ => $expected->{$_} for keys $expected->%*;
        },
        $name,
    );

    $ctx->release;
}

sub run_factory_pass_cases ( $subclass, $tests ) {
    subtest 'factory pass' => sub {
        for my $test ( $tests->@* ) {
            expect_factory_object( $test->{input}, $subclass, $test->{expected}, pp( $test->{input} ) );
        }
    };
}

sub run_direct_pass_cases ( $class, $tests ) {
    subtest 'direct pass' => sub {
        for my $test ( $tests->@* ) {
            expect_object( $class, $test->{input}, $test->{expected}, pp( $test->{input} ) );
        }
    };
}

sub run_fail_cases ( $label, $constructor, $tests ) {
    subtest "$label fail" => sub {
        for my $test ( $tests->@* ) {
            like( dies { $constructor->( $test->{input} ) }, $test->{expected}{$label}, pp( $test->{input} ) );
        }
    };
}

subtest factory => sub {
    for my $class ( Numeric, TimeDate ) {
        subtest $class => sub {
            run_factory_pass_cases( $class, $cases{$class}{pass} );
            run_fail_cases( 'factory', sub ( $input ) { Bound->new( $input->%* ) }, $cases{$class}{fail} );
        };
    }

    subtest 'mixed args fail' => sub {
        like(
            dies {



( run in 1.059 second using v1.01-cache-2.11-cpan-364913b4093 )