Skip to content

Commit a32b456

Browse files
committed
Tests for VM array serialization.
1 parent bc443c1 commit a32b456

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

t/serialization/01-basic.t

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

3-
plan(42);
3+
plan(53);
44

55
# Serializing an empty SC.
66
{
@@ -192,7 +192,6 @@ plan(42);
192192
ok($dsc[2].v == 40, 'third object value attribute is ok');
193193
}
194194

195-
# VM Integer/Float/String types
196195
# Serializing an SC with a P6opaque containing VM Integer/Float/String
197196
{
198197
my $sc := pir::nqp_create_sc__Ps('TEST_SC_8_IN');
@@ -230,3 +229,45 @@ plan(42);
230229
ok($dsc[0].b == 6.9, 'Float survived serialization');
231230
ok($dsc[0].c eq 'llama', 'String survived serialization');
232231
}
232+
233+
# Array in an object attribute
234+
{
235+
my $sc := pir::nqp_create_sc__Ps('TEST_SC_9_IN');
236+
my $sh := pir::new__Ps('ResizableStringArray');
237+
238+
class T8 {
239+
has $!a;
240+
has $!b;
241+
method new() {
242+
my $obj := nqp::create(self);
243+
$obj.BUILD();
244+
$obj;
245+
}
246+
method BUILD() {
247+
$!a := [1,'lol',3];
248+
$!b := [1,[2,3],4];
249+
}
250+
method a() { $!a }
251+
method b() { $!b }
252+
}
253+
my $v := T8.new();
254+
pir::nqp_add_object_to_sc__vPiP($sc, 0, $v);
255+
256+
my $serialized := pir::nqp_serialize_sc__SPP($sc, $sh);
257+
258+
my $dsc := pir::nqp_create_sc__Ps('TEST_SC_9_OUT');
259+
pir::nqp_deserialize_sc__vSPP($serialized, $dsc, $sh);
260+
261+
ok(nqp::istype($dsc[0], T8), 'deserialized object has correct type');
262+
ok(+$dsc[0].a == 3, 'array a came back with correct element count');
263+
ok($dsc[0].a[0] == 1, 'array a first element is correct');
264+
ok($dsc[0].a[1] eq 'lol', 'array a second element is correct');
265+
ok($dsc[0].a[2] == 3, 'array a third element is fine');
266+
ok(+$dsc[0].b == 3, 'array b came back with correct element count');
267+
ok($dsc[0].b[0] == 1, 'array b first element is correct');
268+
ok(+$dsc[0].b[1] == 2, 'array b nested array has correct count');
269+
ok(+$dsc[0].b[1][0] == 2, 'array b nested array first element ok');
270+
ok(+$dsc[0].b[1][1] == 3, 'array b nested array second element ok');
271+
ok(+$dsc[0].b[2] == 4, 'array b third element is correct');
272+
}
273+

0 commit comments

Comments
 (0)