Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 50 lines (40 sloc) 1.139 kb
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 47 48 49
use v6;
use Test;

# L<S32::Str/Str/"=item pack">

plan 6;

{
    my $buf = pack('H*', "414243");
    is_deeply $buf.contents, [:16<41>, :16<42>, :16<43>], 'H* works';
}

{
    my $buf = pack("A11 A28 A8 A*",
                   "03/23/2001", "Totals", "1235.00", " 1172.98");
    is_deeply $buf.contents,
              "03/23/2001 Totals 1235.00 1172.98"\
                .encode.contents,
              "A works";
}

{
    my $buf = pack("C S L n N v V",
                   0x130, 0x10030, 0x100000030,
                   0x1234, 0x12345678,
                   0x1234, 0x12345678);
    is_deeply $buf.contents,
              [0x30, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00,
               0x12, 0x34, 0x12, 0x34, 0x56, 0x78,
               0x34, 0x12, 0x78, 0x56, 0x34, 0x12],
              "C S L n N v V work";
}

{
  my $buf = pack('x');
  is_deeply $buf.contents, [0x00], 'x by itself works';
}

{
  my $buf = pack('x4');
  is_deeply $buf.contents, [0x00, 0x00, 0x00, 0x00], 'x with amount works';
}

{
  my $buf = pack('x*');
  is_deeply $buf.contents, [], 'x* works (as in it does nothing.)';
}

# vim: ft=perl6
Something went wrong with that request. Please try again.