File: 11-parse_success.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 (72 lines) | stat: -rwxr-xr-x 1,103 bytes parent folder | download | duplicates (6)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl

use strict;
use warnings;

use DateTime::Format::Natural;
use Test::More tests => 19;

my @ordinal_number = (
    '2d aug',
    '3d aug',
    '11th sep',
    '12th sep',
    '13th sep',
    '21st oct',
    '22nd oct',
    '23rd oct',
);

my @durations = (
    '26 oct 10:00am to 11:00am',
    '26 oct 10:00pm to 11:00pm',
);

my @filtered = (
    'thurs,',
);

my @formatted = (
    '2011-Jan-04',
);

my @rewrite = (
    # \d{1,2}$ -> \d{1,2}:00$
    'feb 28 at 3',
    '28 feb at 3',
    'may 22nd 2011 at 9',
    '22nd may 2011 at 9',
    'saturday 3 months ago at 5',
);

my @spaces = (
    ' now',
    'now ',
);

foreach my $list (\@ordinal_number, \@durations, \@filtered, \@formatted, \@rewrite, \@spaces) {
    check($list);
}

sub check
{
    my $list = shift;
    foreach my $string (@$list) {
        check_success($string);
    }
}

sub check_success
{
    my ($string) = @_;

    my $parser = DateTime::Format::Natural->new;
    $parser->parse_datetime_duration($string);

    if ($parser->success) {
        pass($string);
    }
    else {
        fail($string);
    }
}