Skip to content

Commit

Permalink
Test serializing a nqp::list_n
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jun 17, 2017
1 parent 4355676 commit 6500a4d
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion t/serialization/01-basic.t
@@ -1,6 +1,6 @@
#! nqp

plan(1512);
plan(1517);

{
my $sc := nqp::createsc('exampleHandle');
Expand Down Expand Up @@ -377,6 +377,8 @@ sub add_to_sc($sc, $idx, $obj) {
ok(nqp::atpos_i(nqp::scgetobj($dsc, 0).a, 2) == 103, 'integer array third element is correct');
}

# Number array

# String array (used by Rakudo in signatures)
{
my $sc := nqp::createsc('TEST_SC_12_IN');
Expand Down Expand Up @@ -646,6 +648,41 @@ sub round_trip_int_array($desc, @a) {
ok(nqp::iseq_i(@b[$j], @a[$j]), $desc ~ 'integer ' ~ @a[$j] ~ ' serialization round trip (' ~ $j ~ ')');
++$j;
}
};

{
my $sc := nqp::createsc('TEST_SC_13_IN');
my $sh := nqp::list_s();

class T13 {
has $!a;
method new() {
my $obj := nqp::create(self);
$obj.BUILD();
$obj;
}
method BUILD() {
my @a := nqp::list_n();
nqp::bindpos_n(@a, 0, 101);
nqp::bindpos_n(@a, 1, 102);
nqp::bindpos_n(@a, 2, 103);
$!a := @a;
}
method a() { $!a }
}
my $v := T13.new();
add_to_sc($sc, 0, $v);

my $serialized := nqp::serialize($sc, $sh);

my $dsc := nqp::createsc('TEST_SC_13_OUT');
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::istype(nqp::scgetobj($dsc, 0), T13), 'deserialized object has correct type');
ok(nqp::elems(nqp::scgetobj($dsc, 0).a) == 3, 'num array came back with correct element count');
ok(nqp::atpos_n(nqp::scgetobj($dsc, 0).a, 0) == 101, 'num array first element is correct');
ok(nqp::atpos_n(nqp::scgetobj($dsc, 0).a, 1) == 102, 'num array second element is correct');
ok(nqp::atpos_n(nqp::scgetobj($dsc, 0).a, 2) == 103, 'num array third element is correct');
}

{
Expand Down

0 comments on commit 6500a4d

Please sign in to comment.