File: 030-roundtrip.t

package info (click to toggle)
raku-json-class 0.0.21-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!raku

use v6;
use Test;

use JSON::Class;

class Inner {
    has %.hash;
    has Rat $.rat;
}
class Outer does JSON::Class {
    has Bool $.bool-attr;
    has Str  $.string;
    has Str  @.str-array;
    has Int  $.int;
    has Inner $.inner;
    has $!private = 'private';
}

my $outer = Outer.new(bool-attr => True, string => "string", str-array => <one two three>, int => 42, inner => Inner.new(rat => 4.2, hash => { A => 1, B => 2 }));

my $ret;

lives-ok { $ret = $outer.to-json }, "marshal object with to-json";

my Outer $new;

lives-ok { $new = Outer.from-json($ret) }, "unmarshall to object with from-json";

ok $new.defined, "it's defined";

isa-ok $new, Outer, "its the right kind of object";

is $new.bool-attr, $outer.bool-attr, "bool right";
is $new.string, $outer.string, "string right";
is $new.int, $outer.int, "int right";
is $new.str-array, $outer.str-array, "arrays are the same";
is $new.inner.rat, $outer.inner.rat, "inner class rat the same";
is $new.inner.hash<A>, $outer.inner.hash<A>, "inner hash 1";
is $new.inner.hash<B>, $outer.inner.hash<B>, "inner hash 2";

done-testing;
# vim: expandtab shiftwidth=4 ft=raku