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