Skip to content

Commit 1f52d8b

Browse files
committed
Tests for hash serialization.
1 parent a7d8e0f commit 1f52d8b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

t/serialization/01-basic.t

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

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

55
# Serializing an empty SC.
66
{
@@ -271,3 +271,36 @@ plan(53);
271271
ok(+$dsc[0].b[2] == 4, 'array b third element is correct');
272272
}
273273

274+
# Hash in an object attribute.
275+
{
276+
my $sc := pir::nqp_create_sc__Ps('TEST_SC_10_IN');
277+
my $sh := pir::new__Ps('ResizableStringArray');
278+
279+
class T9 {
280+
has $!a;
281+
method new() {
282+
my $obj := nqp::create(self);
283+
$obj.BUILD();
284+
$obj;
285+
}
286+
method BUILD() {
287+
my %h;
288+
%h<a> := 42;
289+
%h<b> := 'polar bear';
290+
$!a := %h;
291+
}
292+
method a() { $!a }
293+
}
294+
my $v := T9.new();
295+
pir::nqp_add_object_to_sc__vPiP($sc, 0, $v);
296+
297+
my $serialized := pir::nqp_serialize_sc__SPP($sc, $sh);
298+
299+
my $dsc := pir::nqp_create_sc__Ps('TEST_SC_10_OUT');
300+
pir::nqp_deserialize_sc__vSPP($serialized, $dsc, $sh);
301+
302+
ok(nqp::istype($dsc[0], T9), 'deserialized object has correct type');
303+
ok(+$dsc[0].a == 2, 'hash came back with correct element count');
304+
ok($dsc[0].a<a> == 42, 'hash first element is correct');
305+
ok($dsc[0].a<b> eq 'polar bear', 'hash second element is correct');
306+
}

0 commit comments

Comments
 (0)