File: 03-parse_daytime.t

package info (click to toggle)
libdatetime-format-natural-perl 1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 616 kB
  • sloc: perl: 9,587; makefile: 2
file content (57 lines) | stat: -rwxr-xr-x 1,264 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

use strict;
use warnings;

use DateTime::Format::Natural;
use DateTime::Format::Natural::Test ':set';
use Test::More;

my @daytime_regular = (
    { 'morning'   => '24.11.2006 08:00:00' },
    { 'afternoon' => '24.11.2006 14:00:00' },
    { 'evening'   => '24.11.2006 20:00:00' },
);

my @daytime_user = (
    { 'morning'   => '24.11.2006 06:00:00' },
    { 'afternoon' => '24.11.2006 13:00:00' },
    { 'evening'   => '24.11.2006 19:00:00' },
);

my %opts = (
    morning   =>  6,
    afternoon => 13,
    evening   => 19,
);

_run_tests(6, [ [ \@daytime_regular ], [ \@daytime_user, \%opts ] ], \&compare);

sub compare
{
    my ($aref, $opts) = @_;

    foreach my $href (@$aref) {
        my $key = (keys %$href)[0];
        foreach my $string ($case_strings->($key)) {
            compare_strings($string, $href->{$key}, $opts);
        }
    }
}

sub compare_strings
{
    my ($string, $result, $opts) = @_;

    my $parser = DateTime::Format::Natural->new(daytime => $opts || {});
    $parser->_set_datetime(\%time);

    my $dt = $parser->parse_datetime($string);

    if ($parser->success && $parser->_get_truncated) {
        is(_result_string($dt), $result, _message($string));
    }
    else {
        fail(_message($string));
    }
}