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