parse-wormedit: seperate parsing module Parse::Binary::Nested
[wormy.git] / t / parser.t
diff --git a/t/parser.t b/t/parser.t
new file mode 100644 (file)
index 0000000..cebd099
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Data::Dumper;
+
+plan tests => 5;
+
+use_ok('Parse::Binary::Nested');
+
+my $example = Parse::Binary::Nested->new([
+       foos => [
+               'C',
+               message => 'Z*',
+               period  => 'C',
+       ],
+       trail => 'a*',
+]);
+ok($example, 'example parser');
+my $data = $example->unpackf("\2foo\0!\0.rest");
+is(ref $data, 'HASH', 'output structure');
+is($data->{foos}->[1]->{period}, ord '.', 'sample element');
+
+is_deeply(
+       Parse::Binary::Nested->new(
+               [ lstr => 'Ca3', rest => 'a*' ]
+       )->unpackf("\2quux"),
+       { lstr => 'qu', rest => 'x' },
+       'length string'
+);
+