Help language development. Donate to The Perl Foundation

JSON::Class cpan:JSTOWE last updated on 2021-02-02

use v6;
use Test;
use JSON::Fast;
use JSON::Class;

class TraitTest does JSON::Class {
    has Version $.version is marshalled-by('Str') is unmarshalled-by('new');

my $obj-orig;

lives-ok { $obj-orig = =>"0.0.1")) }, "create new object to test";

my $json;

lives-ok { $json = $ }, "to-json with traits";

is from-json($json)<version>, "0.0.1", "serialised JSON about right";

my $obj-new;

lives-ok { $obj-new = TraitTest.from-json($json) }, "from-json with traits";

isa-ok $obj-new.version, Version, "version is a Version";
is $obj-new.version.Str, "0.0.1", "and it stringies how we want";
is $obj-new.version, $obj-orig.version, "and the two compare the same";

# vim: expandtab shiftwidth=4 ft=raku