8 use TAP::Parser::YAMLish::Reader;
14 { name => 'Hello World',
19 out => "Hello, World",
21 { name => 'Hello World 2',
23 '--- \'Hello, \'\'World\'',
26 out => "Hello, 'World",
28 { name => 'Hello World 3',
33 out => "Hello, World",
35 { name => 'Hello World 4',
40 out => "Hello, World",
42 { name => 'Hello World 4',
49 out => "Hello, World\n",
51 { name => 'Hello World Block',
58 out => "Hello,\n World\n",
60 { name => 'Hello World 5',
67 error => qr{Missing\s+'[.][.][.]'},
69 { name => 'Simple array',
77 out => [ '1', '2', '3' ],
79 { name => 'Mixed array',
87 out => [ '1', 'two', "three\n" ],
89 { name => 'Hash in array',
97 out => [ '1', { two => '2' }, '3' ],
99 { name => 'Hash in array 2',
108 out => [ '1', { two => '2', three => '3' }, '4' ],
110 { name => 'Nested array',
122 out => [ 'one', [ 'two', ['three'], 'four' ], 'five' ],
124 { name => 'Nested hash',
136 one => { two => { three => '3', four => '4' }, five => '5' },
140 { name => 'Space after colon',
141 in => [ '---', 'spog: ', ' - 1', ' - 2', '...' ],
142 out => { spog => [ 1, 2 ] },
144 { name => 'Original YAML::Tiny test',
162 ' description : Basketball',
166 ' description : Super Hoop',
171 ' Late afternoon is best.',
172 ' Backup contact is Nancy',
173 ' Billsmer @ 338-4338',
180 'city' => 'Royal Oak',
182 'lines' => "458 Walkman Dr.\nSuite #292\n",
187 'invoice' => '34843',
188 'date' => '2001-01-23',
194 'description' => 'Basketball'
196 { 'sku' => 'BL4438H',
198 'price' => '2392.00',
199 'description' => 'Super Hoop'
203 "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
208 # Tests harvested from YAML::Tiny
210 name => 'Regression: empty',
211 error => qr{document\s+header\s+not\s+found}
217 name => 'Regression: only_comment',
218 error => qr{document\s+header\s+not\s+found}
225 name => 'Regression: only_header',
226 error => qr{Premature\s+end}i,
234 name => 'Regression: two_header',
235 error => qr{Unexpected\s+start}i,
242 name => 'Regression: one_undef'
249 name => 'Regression: one_undef2'
256 name => 'Regression: two_undef',
257 error => qr{Missing\s+'[.][.][.]'},
264 name => 'Regression: one_scalar',
271 name => 'Regression: one_scalar2',
278 name => 'Regression: two_scalar',
279 error => qr{Missing\s+'[.][.][.]'},
287 name => 'Regression: one_list1'
299 name => 'Regression: one_list2'
311 name => 'Regression: one_listundef'
313 { out => { 'foo' => 'bar' },
319 name => 'Regression: one_hash1'
331 name => 'Regression: one_hash2'
348 name => 'Regression: array_in_hash'
351 'bar' => { 'foo' => 'bar' },
361 name => 'Regression: hash_in_hash'
384 name => 'Regression: hash_in_array'
392 name => 'Regression: single_quote1'
400 name => 'Regression: single_spaces'
408 name => 'Regression: single_null'
415 name => 'Regression: only_spaces'
432 name => 'Regression: inline_nested_hash'
434 { name => "Unprintables",
437 "- \"\\z\\x01\\x02\\x03\\x04\\x05\\x06\\a\\x08\\t\\n\\v\\f\\r\\x0e\\x0f\"",
438 "- \"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\e\\x1c\\x1d\\x1e\\x1f\"",
439 "- \" !\\\"#\$%&'()*+,-./\"",
440 "- 0123456789:;<=>?",
441 "- '\@ABCDEFGHIJKLMNO'",
442 "- 'PQRSTUVWXYZ[\\]^_'",
443 "- '`abcdefghijklmno'",
444 "- 'pqrstuvwxyz{|}~\177'",
445 "- \200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
446 "- \220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
447 "- \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
448 "- \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
449 "- \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
450 "- \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
451 "- \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
452 "- \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377",
456 "\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17",
457 "\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37",
458 " !\"#\$%&'()*+,-./",
463 "pqrstuvwxyz{|}~\177",
464 "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
465 "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
466 "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
467 "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
468 "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
469 "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
470 "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
471 "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
474 { name => 'Quoted hash keys',
478 ' "\n\t": newline, tab',
483 "\n\t" => 'newline, tab',
492 plan tests => @SCHEDULE * 5;
502 for my $test (@SCHEDULE) {
503 my $name = $test->{name};
504 ok my $yaml = TAP::Parser::YAMLish::Reader->new, "$name: Created";
505 isa_ok $yaml, 'TAP::Parser::YAMLish::Reader';
507 my $source = join( "\n", @{ $test->{in} } ) . "\n";
509 my $iter = iter( $test->{in} );
510 my $got = eval { $yaml->read($iter) };
512 my $raw = $yaml->get_raw;
514 if ( my $err = $test->{error} ) {
515 unless ( like $@, $err, "$name: Error message" ) {
518 ok !$got, "$name: No result";
522 my $want = $test->{out};
523 unless ( ok !$@, "$name: No error" ) {
526 is_deeply $got, $want, "$name: Result matches";
527 is $raw, $source, "$name: Captured source matches";