Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use correct API to look in SCs also.
  • Loading branch information
jnthn committed Mar 9, 2013
1 parent 80dfcef commit fe2575e
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions t/serialization/01-basic.t
Expand Up @@ -38,8 +38,8 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
ok(nqp::istype($dsc[0], T1), 'deserialized object has correct type');
ok(nqp::unbox_i($dsc[0]) == 42, 'deserialized object has correct value');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T1), 'deserialized object has correct type');
ok(nqp::unbox_i(nqp::scgetobj($dsc, 0)) == 42, 'deserialized object has correct value');
}

# Serializing an SC with a single object with P6num REPR.
Expand All @@ -58,8 +58,8 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
ok(nqp::istype($dsc[0], T2), 'deserialized object has correct type');
ok(nqp::unbox_n($dsc[0]) == 6.9, 'deserialized object has correct value');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T2), 'deserialized object has correct type');
ok(nqp::unbox_n(nqp::scgetobj($dsc, 0)) == 6.9, 'deserialized object has correct value');
}

# Serializing an SC with a single object with P6str REPR.
Expand All @@ -78,8 +78,8 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
ok(nqp::istype($dsc[0], T3), 'deserialized object has correct type');
ok(nqp::unbox_s($dsc[0]) eq 'dugong', 'deserialized object has correct value');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T3), 'deserialized object has correct type');
ok(nqp::unbox_s(nqp::scgetobj($dsc, 0)) eq 'dugong', 'deserialized object has correct value');
}

# Serializing an SC with a P6opaque containing a P6int, P6num and P6str.
Expand Down Expand Up @@ -115,10 +115,10 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
ok(nqp::istype($dsc[0], T4), 'deserialized object has correct type');
ok($dsc[0].a == 42, 'P6int attribute has correct value');
ok($dsc[0].b == 6.9, 'P6num attribute has correct value');
ok($dsc[0].c eq 'llama', 'P6str attribute has correct value');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T4), 'deserialized object has correct type');
ok(nqp::scgetobj($dsc, 0).a == 42, 'P6int attribute has correct value');
ok(nqp::scgetobj($dsc, 0).b == 6.9, 'P6num attribute has correct value');
ok(nqp::scgetobj($dsc, 0).c eq 'llama', 'P6str attribute has correct value');
}

# Serializing an SC with P6opaues and circular references
Expand Down Expand Up @@ -147,10 +147,10 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 2, 'deserialized SC has 2 objects');
ok(nqp::istype($dsc[0], T5), 'first deserialized object has correct type');
ok(nqp::istype($dsc[1], T5), 'second deserialized object has correct type');
ok($dsc[0].x =:= $dsc[1], 'reference from first object to second ok');
ok($dsc[1].x =:= $dsc[0], 'reference from second object to first ok');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T5), 'first deserialized object has correct type');
ok(nqp::istype(nqp::scgetobj($dsc, 1), T5), 'second deserialized object has correct type');
ok(nqp::scgetobj($dsc, 0).x =:= nqp::scgetobj($dsc, 1), 'reference from first object to second ok');
ok(nqp::scgetobj($dsc, 1).x =:= nqp::scgetobj($dsc, 0), 'reference from second object to first ok');
}

# Tracing an object graph.
Expand Down Expand Up @@ -186,14 +186,14 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 3, 'deserialized SC has 3 objects - the one we added and two discovered');
ok(nqp::istype($dsc[0], T6), 'first deserialized object has correct type');
ok(nqp::istype($dsc[1], T6), 'second deserialized object has correct type');
ok(nqp::istype($dsc[2], T6), 'third deserialized object has correct type');
ok($dsc[0].x =:= $dsc[1], 'reference from first object to second ok');
ok($dsc[0].v == 5, 'first object value attribute is ok');
ok($dsc[1].x =:= $dsc[2], 'reference from second object to third ok');
ok($dsc[1].v == 8, 'second object value attribute is ok');
ok($dsc[2].v == 40, 'third object value attribute is ok');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T6), 'first deserialized object has correct type');
ok(nqp::istype(nqp::scgetobj($dsc, 1), T6), 'second deserialized object has correct type');
ok(nqp::istype(nqp::scgetobj($dsc, 2), T6), 'third deserialized object has correct type');
ok(nqp::scgetobj($dsc, 0).x =:= nqp::scgetobj($dsc, 1), 'reference from first object to second ok');
ok(nqp::scgetobj($dsc, 0).v == 5, 'first object value attribute is ok');
ok(nqp::scgetobj($dsc, 1).x =:= nqp::scgetobj($dsc, 2), 'reference from second object to third ok');
ok(nqp::scgetobj($dsc, 1).v == 8, 'second object value attribute is ok');
ok(nqp::scgetobj($dsc, 2).v == 40, 'third object value attribute is ok');
}

# Serializing an SC with a P6opaque containing VM Integer/Float/String
Expand Down Expand Up @@ -228,10 +228,10 @@ sub add_to_sc($sc, $idx, $obj) {
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::scobjcount($dsc) == 1, 'deserialized SC has a single object');
ok(nqp::istype($dsc[0], T7), 'deserialized object has correct type');
ok($dsc[0].a == 42, 'Integer survived serialization');
ok($dsc[0].b == 6.9, 'Float survived serialization');
ok($dsc[0].c eq 'llama', 'String survived serialization');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T7), 'deserialized object has correct type');
ok(nqp::scgetobj($dsc, 0).a == 42, 'Integer survived serialization');
ok(nqp::scgetobj($dsc, 0).b == 6.9, 'Float survived serialization');
ok(nqp::scgetobj($dsc, 0).c eq 'llama', 'String survived serialization');
}

# Array in an object attribute
Expand Down Expand Up @@ -262,17 +262,17 @@ sub add_to_sc($sc, $idx, $obj) {
my $dsc := nqp::createsc('TEST_SC_9_OUT');
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::istype($dsc[0], T8), 'deserialized object has correct type');
ok(nqp::elems($dsc[0].a) == 3, 'array a came back with correct element count');
ok($dsc[0].a[0] == 1, 'array a first element is correct');
ok($dsc[0].a[1] eq 'lol', 'array a second element is correct');
ok($dsc[0].a[2] == 3, 'array a third element is fine');
ok(nqp::elems($dsc[0].b) == 3, 'array b came back with correct element count');
ok($dsc[0].b[0] == 1, 'array b first element is correct');
ok(nqp::elems($dsc[0].b[1]) == 2, 'array b nested array has correct element count');
ok(+$dsc[0].b[1][0] == 2, 'array b nested array first element ok');
ok(+$dsc[0].b[1][1] == 3, 'array b nested array second element ok');
ok(+$dsc[0].b[2] == 4, 'array b third element is correct');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T8), 'deserialized object has correct type');
ok(nqp::elems(nqp::scgetobj($dsc, 0).a) == 3, 'array a came back with correct element count');
ok(nqp::scgetobj($dsc, 0).a[0] == 1, 'array a first element is correct');
ok(nqp::scgetobj($dsc, 0).a[1] eq 'lol', 'array a second element is correct');
ok(nqp::scgetobj($dsc, 0).a[2] == 3, 'array a third element is fine');
ok(nqp::elems(nqp::scgetobj($dsc, 0).b) == 3, 'array b came back with correct element count');
ok(nqp::scgetobj($dsc, 0).b[0] == 1, 'array b first element is correct');
ok(nqp::elems(nqp::scgetobj($dsc, 0).b[1]) == 2, 'array b nested array has correct element count');
ok(+nqp::scgetobj($dsc, 0).b[1][0] == 2, 'array b nested array first element ok');
ok(+nqp::scgetobj($dsc, 0).b[1][1] == 3, 'array b nested array second element ok');
ok(+nqp::scgetobj($dsc, 0).b[2] == 4, 'array b third element is correct');
}

# Hash in an object attribute.
Expand Down Expand Up @@ -303,10 +303,10 @@ sub add_to_sc($sc, $idx, $obj) {
my $dsc := nqp::createsc('TEST_SC_10_OUT');
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::istype($dsc[0], T9), 'deserialized object has correct type');
ok(nqp::elems($dsc[0].a) == 2, 'hash came back with correct element count');
ok($dsc[0].a<a> == 42, 'hash first element is correct');
ok($dsc[0].a<b> eq 'polar bear', 'hash second element is correct');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T9), 'deserialized object has correct type');
ok(nqp::elems(nqp::scgetobj($dsc, 0).a) == 2, 'hash came back with correct element count');
ok(nqp::scgetobj($dsc, 0).a<a> == 42, 'hash first element is correct');
ok(nqp::scgetobj($dsc, 0).a<b> eq 'polar bear', 'hash second element is correct');
}

# Integer array (probably needed for NFA serialization).
Expand Down Expand Up @@ -338,11 +338,11 @@ sub add_to_sc($sc, $idx, $obj) {
my $dsc := nqp::createsc('TEST_SC_11_OUT');
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

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

# String array (used by Rakudo in signatures)
Expand Down Expand Up @@ -374,9 +374,9 @@ sub add_to_sc($sc, $idx, $obj) {
my $dsc := nqp::createsc('TEST_SC_12_OUT');
nqp::deserialize($serialized, $dsc, $sh, nqp::list(), nqp::null());

ok(nqp::istype($dsc[0], T11), 'deserialized object has correct type');
ok(nqp::elems($dsc[0].a) == 3, 'string array came back with correct element count');
ok($dsc[0].a[0] eq 'cow', 'string array first element is correct');
ok($dsc[0].a[1] eq 'sheep', 'string array second element is correct');
ok($dsc[0].a[2] eq 'pig', 'string array third element is correct');
ok(nqp::istype(nqp::scgetobj($dsc, 0), T11), 'deserialized object has correct type');
ok(nqp::elems(nqp::scgetobj($dsc, 0).a) == 3, 'string array came back with correct element count');
ok(nqp::scgetobj($dsc, 0).a[0] eq 'cow', 'string array first element is correct');
ok(nqp::scgetobj($dsc, 0).a[1] eq 'sheep', 'string array second element is correct');
ok(nqp::scgetobj($dsc, 0).a[2] eq 'pig', 'string array third element is correct');
}

0 comments on commit fe2575e

Please sign in to comment.