parse-wormedit: bytes declarable as non-capturing
[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 => 6;
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
34 is_deeply(
35         Parse::Binary::Nested->new(
36                 [ ignoreme => 'x2X', value => 'xC' ]
37         )->unpackf("\0\1\2"),
38         { value => 2 },
39         'empty values'
40 );
41