Skip to content

Commit d8f1a24

Browse files
committed
Test serialization of a VMArray.
1 parent 4965e17 commit d8f1a24

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

t/serialization/01-basic.t

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! nqp
22

3-
plan(1489);
3+
plan(1494);
44

55
{
66
my $sc := nqp::createsc('exampleHandle');
@@ -412,6 +412,9 @@ sub add_to_sc($sc, $idx, $obj) {
412412
ok(nqp::atpos_s(nqp::scgetobj($dsc, 0).a, 2) eq 'pig', 'string array third element is correct');
413413
}
414414

415+
416+
417+
415418
# Serializing an SC with a P6opaque containing a MultiCache
416419
{
417420
my $sc := nqp::createsc('TEST_SC_13_IN');
@@ -450,6 +453,31 @@ sub add_to_sc($sc, $idx, $obj) {
450453
ok(nqp::isnull(nqp::scgetobj($dsc, 0).fh), 'File handle ends up null');
451454
}
452455

456+
# Serializing an SC with a VMArray
457+
{
458+
my $sc := nqp::createsc('TEST_SC_14_IN');
459+
my $sh := nqp::list_s();
460+
461+
class VMArrayClass is repr('VMArray') {
462+
}
463+
464+
my $v := VMArrayClass.new();
465+
nqp::push($v, 123);
466+
nqp::push($v, 456);
467+
add_to_sc($sc, 0, $v);
468+
469+
my $serialized := nqp::serialize($sc, $sh);
470+
471+
my $dsc := nqp::createsc('TEST_SC_14_OUT');
472+
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());
473+
474+
ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
475+
ok(nqp::istype(nqp::scgetobj($dsc, 0), VMArrayClass), 'deserialized array has correct type');
476+
is(nqp::elems(nqp::scgetobj($dsc, 0)), 2, 'deserialize array has correct number of elements');
477+
is(nqp::scgetobj($dsc, 0)[0], 123, '0th element of array is correct');
478+
is(nqp::scgetobj($dsc, 0)[1], 456, '1st element of array is correct');
479+
}
480+
453481
# integers
454482
sub round_trip_int_array($seq, $desc, @a) {
455483
$seq := 'TEST_SC_' ~ $seq;
@@ -491,7 +519,7 @@ sub round_trip_int_array($seq, $desc, @a) {
491519
nqp::push(@a, $i);
492520
$i := $i + 1;
493521
}
494-
round_trip_int_array(13, 'small integers', @a);
522+
round_trip_int_array(14, 'small integers', @a);
495523
}
496524

497525
{

0 commit comments

Comments
 (0)