Skip to content

Commit

Permalink
Add test file for testing Blob.read-int8
Browse files Browse the repository at this point in the history
Created a new directory for these tests.  Also, did not add this to rakudo's
spectest.data as it presently still has quite a number of failures.
  • Loading branch information
lizmat committed Dec 11, 2018
1 parent 27476f9 commit f08f4a4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions S03-buf/read-int8.t
@@ -0,0 +1,46 @@
use v6;
use Test;

my @uintbufs =
Blob.new(1,2,3,4), 'Blob1234',
Blob[uint8].new(1,2,3,4), 'Blobuint1234',
Blob.new((^256).roll(4)), 'Blobrandom',
Blob[uint8].new((^256).roll(4)), 'Blobuintrandom',
Blob[uint8].new((-128..127).roll(4)), 'Blobuintnegrandom',
;
my @intbufs =
Blob[int8].new(1,2,3,4), 'Blobint1234',
Blob[int8].new(-1,-2,-3,-4), 'Blobint-1-2-3-4',
Blob[int8].new((^256).roll(4)), 'Blobintposrandom',
Blob[int8].new((-128..127).roll(4)), 'Blobintnegrandom',
;

my $uintcells = @uintbufs.map( -> \buf, \name { buf.elems }).sum;
my $intcells = @intbufs.map( -> \buf, \name { buf.elems }).sum;
plan ($uintcells + $intcells) * 4;

for @uintbufs -> \buffer, $name {
for ^buffer.elems {
is buffer.read-uint8($_), buffer[$_], "is $name $_ correct";

# endianness doesn't matter for byte sized reads
for native-endian, little-endian, big-endian -> $endian {
is buffer.read-uint8($_,$endian), buffer[$_],
"is $name $_ $endian correct";
}
}
}

for @intbufs -> \buffer, $name {
for ^buffer.elems {
is buffer.read-int8($_), buffer[$_], "is $name $_ correct";

# endianness doesn't matter for byte sized reads
for native-endian, little-endian, big-endian -> $endian {
is buffer.read-int8($_,$endian), buffer[$_],
"is $name $_ $endian correct";
}
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit f08f4a4

Please sign in to comment.