DateTime-Format-Strptime

 view release on metacpan or  search on metacpan

t/lib/T.pm  view on Meta::CPAN

package    # hide from PAUSE
    T;

use strict;
use warnings;

use Test::Builder;
use Test::More 0.96;
use Test::Fatal;

use DateTime::Format::Strptime;

use Exporter qw( import );

our @EXPORT_OK = qw( run_tests_from_data test_datetime_object utf8_output );

sub run_tests_from_data {
    my $fh = shift;

    for my $test ( _tests_from_fh($fh) ) {
        subtest(
            qq{$test->{name}},
            sub {
                utf8_output();

                my $parser;
                is(
                    exception {
                        $parser = DateTime::Format::Strptime->new(
                            pattern => $test->{pattern},
                            (
                                $test->{locale}
                                ? ( locale => $test->{locale} )
                                : ()
                            ),
                            strict   => $test->{strict},
                            on_error => 'croak',
                        );
                    },
                    undef,
                    "no exception building parser for $test->{pattern}"
                ) or return;

                ( my $real_input = $test->{input} ) =~ s/\\n/\n/g;

                my $dt;
                is(
                    exception { $dt = $parser->parse_datetime($real_input) },
                    undef,
                    "no exception parsing $test->{input}"
                ) or return;

                test_datetime_object( $dt, $test->{expect} );

                unless ( $test->{skip_round_trip} ) {
                    is(
                        $parser->format_datetime($dt),
                        $real_input,
                        'round trip via strftime produces original input'
                    );
                }
            }
        );
    }
}

sub utf8_output {
    binmode $_, ':encoding(UTF-8)'
        or die $!



( run in 1.260 second using v1.01-cache-2.11-cpan-54e63673c56 )