Date-Holidays-GB

 view release on metacpan or  search on metacpan

t/test.t  view on Meta::CPAN

# test.t

use utf8;
use Test::Most;
use Test::Fatal;

my $builder = Test::More->builder;
binmode $builder->output,         ":utf8";
binmode $builder->failure_output, ":utf8";
binmode $builder->todo_output,    ":utf8";

use Date::Holidays::GB qw( is_holiday holidays holidays_ymd );

open( my $fh, '<:encoding(utf-8)', 't/samples/2013-holidays' )
    or die "Can't open 2013-holidays: $!";

Date::Holidays::GB::set_holidays($fh);

subtest is_holiday => sub {

    my @tests = (
        { date => [ year => 2013, month => 1,  day => 3 ],  holiday => 0, },
        { date => [ year => 2013, month => 12, day => 25 ], holiday => 'Christmas Day', },
        {   date    => [ year => 2013, month => 12, day => 25 ],
            regions => [],
            holiday => 0,
        },
        {   date    => [ year => 2013, month => 11, day => 30 ],
            regions => ['EAW'],
            holiday => 0,
        },
        {   date    => [ year => 2013, month => 12, day => 2 ],
            regions => ['EAW'],
            holiday => 0,
        },
        {   date    => [ year => 2013, month => 12, day => 2 ],
            regions => ['SCT'],
            holiday => "St Andrew\x{2019}s Day (Scotland)",
        },
    );

    foreach my $test (@tests) {
        my $regions = $test->{regions};
        my %date    = @{ $test->{date} };
        my $string
            = sprintf( "%02d-%02d-%02d", $date{year}, $date{month}, $date{day} );

        my $regions_str = $regions ? join( ',', @{$regions} ) : '<none>';
        note $string . " - regions: $regions_str";

        if ( my $expected = $test->{holiday} ) {
            my $holiday;
            ok $holiday
                = is_holiday( $date{year}, $date{month}, $date{day}, $regions ),
                "is a holiday (using list)";
            is $holiday, $expected, "holiday name ok";

            ok $holiday = is_holiday( date => $string, regions => $regions ),
                "is a holiday (using 'date')";
            is $holiday, $expected, "holiday name ok";

            ok $holiday = is_holiday( %date, regions => $regions ),
                "is a holiday (using year/month/day arguments')";
            is $holiday, $expected, "holiday name ok";
        }



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