File Coverage

blib/lib/Test/DateTime/Format/Alami.pm
Criterion Covered Total %
statement 54 54 100.0
branch 7 10 70.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 71 74 95.9


line stmt bran cond sub pod time code
1             package Test::DateTime::Format::Alami;
2              
3 2     2   4163 use 5.010001;
  2         11  
4 2     2   12 use strict;
  2         6  
  2         42  
5 2     2   11 use warnings;
  2         5  
  2         55  
6              
7 2     2   1623 use DateTime;
  2         1339004  
  2         102  
8 2     2   1549 use Test::More 0.98;
  2         152506  
  2         26  
9              
10 2     2   829 use Exporter qw(import);
  2         8  
  2         1044  
11             our @EXPORT = qw(test_datetime_format_alami);
12              
13             sub test_datetime_format_alami {
14 2     2 1 247 my ($class0, $tests) = @_;
15              
16 2         9 my $class = "DateTime::Format::Alami::$class0";
17 2 50   2   851 eval "use $class"; die if $@;
  2         40  
  2         65  
  2         190  
  2         18  
18              
19             subtest "test suite for $class" => sub {
20 2     2   3648 my $parser = $class->new;
21              
22 2         7 for my $t (@{ $tests->{parse_datetime_tests} }) {
  2         10  
23 90         225531 my ($str, $exp_result) = @$t;
24             subtest $str => sub {
25 90         112280 my $dt;
26 90         246 eval { $dt = $parser->parse_datetime(
27 90         743 $str, {time_zone => $tests->{time_zone}}) };
28 90         406 my $err = $@;
29 90 100       318 if ($exp_result) {
30 82 50       462 ok(!$err, "parse should succeed") or return;
31 82         61796 is("$dt", $exp_result, "result should be $exp_result");
32             } else {
33 8         46 ok($err, "parse should fail");
34 8         5329 return;
35             }
36 90         842 };
37             } # parse_datetime_tests
38              
39 2         7554 require DateTime::Format::Duration::ISO8601;
40 2         789 my $pdur = DateTime::Format::Duration::ISO8601->new;
41 2         19 for my $t (@{ $tests->{parse_datetime_duration_tests} }) {
  2         12  
42 6         11363 my ($str, $exp_result) = @$t;
43             subtest $str => sub {
44 6         8683 my $dtdur;
45 6         19 eval { $dtdur = $parser->parse_datetime_duration($str) };
  6         47  
46 6         24 my $err = $@;
47 6 100       25 if ($exp_result) {
48 4 50       26 ok(!$err, "parse should succeed") or return;
49 4         2883 is($pdur->format_duration($dtdur), $exp_result,
50             "result should be $exp_result");
51             } else {
52 2         14 ok($err, "parse should fail");
53 2         1501 return;
54             }
55 6         67 };
56             } # parse_datetime_duration_tests
57 2         35 };
58             }
59              
60             1;
61             # ABSTRACT: Test DateTime::Format::Alami
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Test::DateTime::Format::Alami - Test DateTime::Format::Alami
72              
73             =head1 VERSION
74              
75             This document describes version 0.16 of Test::DateTime::Format::Alami (from Perl distribution DateTime-Format-Alami), released on 2017-07-10.
76              
77             =head1 FUNCTIONS
78              
79             =head2 test_datetime_format_alami($class, \%tests)
80              
81             =head1 HOMEPAGE
82              
83             Please visit the project's homepage at L<https://metacpan.org/release/DateTime-Format-Alami>.
84              
85             =head1 SOURCE
86              
87             Source repository is at L<https://github.com/perlancar/perl-DateTime-Format-Alami>.
88              
89             =head1 BUGS
90              
91             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-Alami>
92              
93             When submitting a bug or request, please include a test-file or a
94             patch to an existing test-file that illustrates the bug or desired
95             feature.
96              
97             =head1 AUTHOR
98              
99             perlancar <perlancar@cpan.org>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2017, 2016, 2014 by perlancar@cpan.org.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut