|
1 | 1 | #! nqp
|
2 | 2 |
|
3 |
| -plan(42); |
| 3 | +plan(53); |
4 | 4 |
|
5 | 5 | # Serializing an empty SC.
|
6 | 6 | {
|
@@ -192,7 +192,6 @@ plan(42);
|
192 | 192 | ok($dsc[2].v == 40, 'third object value attribute is ok');
|
193 | 193 | }
|
194 | 194 |
|
195 |
| -# VM Integer/Float/String types |
196 | 195 | # Serializing an SC with a P6opaque containing VM Integer/Float/String
|
197 | 196 | {
|
198 | 197 | my $sc := pir::nqp_create_sc__Ps('TEST_SC_8_IN');
|
@@ -230,3 +229,45 @@ plan(42);
|
230 | 229 | ok($dsc[0].b == 6.9, 'Float survived serialization');
|
231 | 230 | ok($dsc[0].c eq 'llama', 'String survived serialization');
|
232 | 231 | }
|
| 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