/
unpack.t
46 lines (38 loc) 路 1.43 KB
/
unpack.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use v6;
use Test;
# L<S32::Str/Str/"=item pack">
plan 2 * 12;
{
for "H*", <H*> -> $template {
my $hexstring = Buf.new(:16<41>, :16<42>, :16<43>).unpack($template);
is $hexstring, "414243", 'H* works';
}
}
{
my $buf =
"03/23/2001 Totals 1235.00 1172.98".encode;
for "A10 x A6 x19 A10 x A*", <A10 x A6 x19 A10 x A*> -> $template {
my ($date,$totals,$tot_income,$tot_expend) = $buf.unpack($template);
is $date, "03/23/2001", 'field 1 (A11) works';
is $totals, "Totals", 'field 2 (A28) works';
is $tot_income, " 1235.00", 'field 3 (A8) works';
is $tot_expend, " 1172.98", 'field 4 (A*) works';
}
}
{
my $buf = Buf.new(0x30, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00,
0x12, 0x34, 0x12, 0x34, 0x56, 0x78,
0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
for "C S L n N v V", <C S L n N v V> -> $template {
my ($char, $short, $long, $bigend_short, $bigend_long,
$lilend_short, $lilend_long) = $buf.unpack($template);
is $char, 0x30, 'C works';
is $short, 0x30, 'S works';
is $long, 0x30, 'L works';
is $bigend_short, 0x1234, 'n works';
is $bigend_long, 0x12345678, 'N works';
is $lilend_short, 0x1234, 'v works';
is $lilend_long, 0x12345678, 'V works';
}
}
# vim: ft=perl6