11 use_ok('Parse::Binary::Nested');
21 my $testdata = "\2foo\0!\0.rest";
24 {message => 'foo', period => '!'},
25 {message => '', period => '.'},
30 my $parser = Parse::Binary::Nested->new(\@example);
31 ok($parser, 'new object');
32 is_deeply($parser->unpackf($testdata), $testresult, 'object unpackf');
34 Parse::Binary::Nested->import('unpackf');
36 unpackf(\@example, $testdata),
41 my @commonargs = ('cxaXv', "\1\2hi\0");
43 [ values %{ unpackf(@commonargs) } ],
44 [[ unpack($commonargs[0], $commonargs[1]) ]],
45 'unpack compatibility'
49 unpackf([ lstr => 'C/a3', rest => 'a*' ], "\2quux"),
50 { lstr => 'qu', rest => 'x' },
55 unpackf([ ignoreme => 'x2X', value => 'xC' ], "\0\1\2"),
63 asciiz => ['?0', lead => 'v', string => 'Z*'],
65 ], "\377\1\0Hi\0\2\0zer0\0\0\376"),
69 { lead => 1, string => 'Hi' },
70 { lead => 2, string => 'zer0' },
74 'zero-terminated group'
77 my $looptest = Parse::Binary::Nested->new([
79 loop => ['?1', lead => 'c', string => 'Z*'],
83 $looptest->unpackf("\0\1\0Hello\0\377bye"),
87 { lead => 0, string => 'Hello' },
88 { lead => -1, string => 'bye' },
95 $looptest->unpackf("\0\1\1trailing"),
100 'preterminated group'
105 loop => ['?0', byte => 'C'],
108 loop => [map { {byte => $_} } 1..3],
110 'last byte in unterminated loop'