File: 17-trace.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 (66 lines) | stat: -rwxr-xr-x 1,510 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl

use strict;
use warnings;

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

my $parser = DateTime::Format::Natural->new;
my $stringify = sub { local $" = "\n"; "@_\n" };

{
    my $string;

    $string = 'now';
    $parser->parse_datetime($string);
    is($stringify->(($parser->trace)[0]), <<'EOT', $string);
now
DateTime::Format::Natural::Calc::_no_op
EOT
    $string = 'yesterday 3 years ago';
    $parser->parse_datetime($string);
    is($stringify->(($parser->trace)[0]), <<'EOT', $string);
ago_yesterday
DateTime::Format::Natural::Calc::_unit_variant
DateTime::Format::Natural::Calc::_ago_variant
day: 1
year: 1
EOT
    $string = 'monday to friday';
    $parser->parse_datetime_duration($string);
    is($stringify->($parser->trace), <<'EOT', $string);
weekday
DateTime::Format::Natural::Calc::_weekday
day: 1
weekday
DateTime::Format::Natural::Calc::_weekday
day: 1
EOT
}

{
    my ($string, @trace);

    $string = 'bogus';
    $parser->parse_datetime($string);
    @trace = $parser->trace;
    ok(!@trace, 'empty trace for parse_datetime');

    $string = 'bogus to bogus';
    $parser->parse_datetime_duration($string);
    @trace = $parser->trace;
    ok(!@trace, 'empty trace for parse_datetime_duration');
}

{
    my $string = 'for 8 hours';
    $parser->parse_datetime_duration($string);
    is($stringify->($parser->trace), <<'EOT', $string);
now
DateTime::Format::Natural::Calc::_no_op
for_count_unit
DateTime::Format::Natural::Calc::_in_count_variant
hour: 1
EOT
}