8 use TAP::Parser::YAMLish::Reader;
9 use TAP::Parser::YAMLish::Writer;
15 { name => 'Simple scalar',
29 { name => 'Unprintable',
36 { name => 'Simple array',
46 { name => 'Empty array',
53 { name => 'Empty hash',
60 { name => 'Array, two elements, undef',
61 in => [ undef, undef ],
69 { name => 'Nested array',
70 in => [ 1, 2, [ 3, 4 ], 5 ],
82 { name => 'Nested empty',
83 in => [ 1, 2, [], 5 ],
93 { name => 'Simple hash',
94 in => { one => '1', two => '2', three => '3' },
103 { name => 'Nested hash',
105 one => '1', two => '2',
106 more => { three => '3', four => '4' }
118 { name => 'Nested empty',
119 in => { one => '1', two => '2', more => {} },
128 { name => 'Unprintable key',
129 in => { one => '1', "\x02" => '2', three => '3' },
138 { name => 'Empty key',
139 in => { '' => 'empty' },
146 { name => 'Empty value',
154 { name => 'Funky hash key',
155 in => { './frob' => 'is_frob' },
167 'city' => 'Royal Oak',
169 'lines' => "458 Walkman Dr.\nSuite #292\n",
174 'invoice' => '34843',
175 'date' => '2001-01-23',
181 'description' => 'Basketball'
183 { 'sku' => 'BL4438H',
185 'price' => '2392.00',
186 'description' => 'Super Hoop'
190 "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
197 " city: \"Royal Oak\"",
198 " lines: \"458 Walkman Dr.\\nSuite #292\\n\"",
203 "comments: \"Late afternoon is best. Backup contact is Nancy Billsmer \@ 338-4338\\n\"",
208 " description: Basketball",
213 " description: \"Super Hoop\"",
224 plan tests => @SCHEDULE * 6;
234 for my $test (@SCHEDULE) {
235 my $name = $test->{name};
236 ok my $yaml = TAP::Parser::YAMLish::Writer->new, "$name: Created";
237 isa_ok $yaml, 'TAP::Parser::YAMLish::Writer';
240 my $writer = sub { push @$got, shift };
242 my $data = $test->{in};
244 eval { $yaml->write( $data, $writer ) };
246 if ( my $err = $test->{error} ) {
247 unless ( like $@, $err, "$name: Error message" ) {
250 is_deeply $got, [], "$name: No result";
254 my $want = $test->{out};
255 unless ( ok !$@, "$name: No error" ) {
258 unless ( is_deeply $got, $want, "$name: Result matches" ) {
264 my $yr = TAP::Parser::YAMLish::Reader->new;
267 my $reader = sub { shift @$got };
268 my $parsed = eval { $yr->read($reader) };
269 ok !$@, "$name: no error" or diag "$@";
271 is_deeply $parsed, $data, "$name: Reparse OK";