Skip to content

Commit cec284e

Browse files
committed
Add a test for P6opaque serialization when attributes are natives.
1 parent a5990b0 commit cec284e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

t/serialization/01-basic.t

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

3-
plan(16);
3+
plan(22);
44

55
# Serializing an empty SC.
66
{
@@ -78,3 +78,37 @@ plan(16);
7878
ok(nqp::unbox_s($dsc[0]) eq 'dugong', 'deserialized object has correct value');
7979
}
8080

81+
# Serializing an SC with a P6opaque containing a P6int, P6num and P6str.
82+
{
83+
my $sc := pir::nqp_create_sc__Ps('TEST_SC_5_IN');
84+
my $sh := pir::new__Ps('ResizableStringArray');
85+
86+
class T4 {
87+
has int $!a;
88+
has num $!b;
89+
has str $!c;
90+
method BUILD() {
91+
$!a := 42;
92+
$!b := 6.9;
93+
$!c := 'llama';
94+
}
95+
method a() { $!a }
96+
method b() { $!b }
97+
method c() { $!c }
98+
}
99+
my $v := T4.new();
100+
$sc[0] := $v;
101+
102+
my $serialized := pir::nqp_serialize_sc__SPP($sc, $sh);
103+
ok(nqp::chars($serialized) > 36, 'serialized SC with P6opaque output longer than a header');
104+
105+
my $dsc := pir::nqp_create_sc__Ps('TEST_SC_5_OUT');
106+
pir::nqp_deserialize_sc__vSPP($serialized, $dsc, $sh);
107+
108+
ok(nqp::elems($dsc) == 1, 'deserialized SC has a single element');
109+
ok(nqp::istype($dsc[0], T4), 'deserialized object has correct type');
110+
ok($dsc[0].a == 42, 'P6int attribute has correct value');
111+
ok($dsc[0].b == 6.9, 'P6num attribute has correct value');
112+
ok($dsc[0].c == 'llama', 'P6str attribute has correct value');
113+
}
114+

0 commit comments

Comments
 (0)