cebd099291bd59b2c22e67cfb4bc24968f167e5f
[wormy.git] / t / parser.t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Data::Dumper;
8
9 plan tests => 5;
10
11 use_ok('Parse::Binary::Nested');
12
13 my $example = Parse::Binary::Nested->new([
14         foos => [
15                 'C',
16                 message => 'Z*',
17                 period  => 'C',
18         ],
19         trail => 'a*',
20 ]);
21 ok($example, 'example parser');
22 my $data = $example->unpackf("\2foo\0!\0.rest");
23 is(ref $data, 'HASH', 'output structure');
24 is($data->{foos}->[1]->{period}, ord '.', 'sample element');
25
26 is_deeply(
27         Parse::Binary::Nested->new(
28                 [ lstr => 'Ca3', rest => 'a*' ]
29         )->unpackf("\2quux"),
30         { lstr => 'qu', rest => 'x' },
31         'length string'
32 );
33