chiark / gitweb /
v0.06
[nailing-cargo.git] / t / toml-test / valid / datetime.t
1 # File automatically generated from BurntSushi/toml-test
2 use utf8;
3 use Test2::V0;
4 use Data::Dumper;
5 use DateTime;
6 use DateTime::Format::RFC3339;
7 use Math::BigInt;
8 use Math::BigFloat;
9 use TOML::Tiny;
10
11 binmode STDIN,  ':encoding(UTF-8)';
12 binmode STDOUT, ':encoding(UTF-8)';
13
14 my $expected1 = {
15                'bestdayever' => bless( {
16                                          'code' => sub {
17                                                        BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x00\x04\x40\x05\x04\x54"}
18                                                        use strict;
19                                                        no feature ':all';
20                                                        use feature ':5.16';
21                                                        my $exp = 'DateTime::Format::RFC3339'->parse_datetime('1987-07-05T17:45:00Z');
22                                                        my $got = 'DateTime::Format::RFC3339'->parse_datetime($_);
23                                                        $exp->set_time_zone('UTC');
24                                                        $got->set_time_zone('UTC');
25                                                        return 'DateTime'->compare($got, $exp) == 0;
26                                                    },
27                                          '_file' => '(eval 369)',
28                                          'name' => '<Custom Code>',
29                                          'operator' => 'CODE(...)',
30                                          '_lines' => [
31                                                        11
32                                                      ]
33                                        }, 'Test2::Compare::Custom' ),
34                'milliseconds' => bless( {
35                                           '_lines' => [
36                                                         11
37                                                       ],
38                                           'code' => sub {
39                                                         BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x00\x04\x40\x05\x04\x54"}
40                                                         use strict;
41                                                         no feature ':all';
42                                                         use feature ':5.16';
43                                                         my $exp = 'DateTime::Format::RFC3339'->parse_datetime('1977-12-21T03:32:00.555+00:00');
44                                                         my $got = 'DateTime::Format::RFC3339'->parse_datetime($_);
45                                                         $exp->set_time_zone('UTC');
46                                                         $got->set_time_zone('UTC');
47                                                         return 'DateTime'->compare($got, $exp) == 0;
48                                                     },
49                                           '_file' => '(eval 371)',
50                                           'name' => '<Custom Code>',
51                                           'operator' => 'CODE(...)'
52                                         }, 'Test2::Compare::Custom' ),
53                'numoffset' => bless( {
54                                        'code' => sub {
55                                                      BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x00\x04\x40\x05\x04\x54"}
56                                                      use strict;
57                                                      no feature ':all';
58                                                      use feature ':5.16';
59                                                      my $exp = 'DateTime::Format::RFC3339'->parse_datetime('1977-06-28T12:32:00Z');
60                                                      my $got = 'DateTime::Format::RFC3339'->parse_datetime($_);
61                                                      $exp->set_time_zone('UTC');
62                                                      $got->set_time_zone('UTC');
63                                                      return 'DateTime'->compare($got, $exp) == 0;
64                                                  },
65                                        '_file' => '(eval 370)',
66                                        'name' => '<Custom Code>',
67                                        'operator' => 'CODE(...)',
68                                        '_lines' => [
69                                                      11
70                                                    ]
71                                      }, 'Test2::Compare::Custom' )
72              };
73
74
75 my $actual = from_toml(q{bestdayever = 1987-07-05T17:45:00Z
76 numoffset = 1977-06-28T07:32:00-05:00
77 milliseconds = 1977-12-21T10:32:00.555+07:00
78 });
79
80 is($actual, $expected1, 'datetime - from_toml') or do{
81   diag 'EXPECTED:';
82   diag Dumper($expected1);
83
84   diag 'ACTUAL:';
85   diag Dumper($actual);
86 };
87
88 is(eval{ from_toml(to_toml($actual)) }, $actual, 'datetime - to_toml') or do{
89   diag 'INPUT:';
90   diag Dumper($actual);
91
92   diag 'TOML OUTPUT:';
93   diag to_toml($actual);
94
95   diag 'REPARSED OUTPUT:';
96   diag Dumper(from_toml(to_toml($actual)));
97 };
98
99 done_testing;