File: 050-array.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 (38 lines) | stat: -rw-r--r-- 819 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
#!raku

use v6;

use Test;
use JSON::Class;

class TestObject does JSON::Class {
    has Str $.string;
}

constant TestObjects = (Array[TestObject] but JSON::Class);

my $json = '[{ "string" : "one" }, { "string" : "two" }]';

my $obj;

lives-ok { $obj = TestObjects.from-json($json) }, "from-json with array data";

does-ok $obj, JSON::Class, "and the return does the role";

isa-ok $obj[0], TestObject, "and the items are the right type";

my $json2;

lives-ok { $json2 = $obj.to-json() }, "to-json on the array typed thing";


my $obj2;

lives-ok { $obj2 = TestObjects.from-json($json2) }, "back from-json again";

is $obj2[0].string, $obj[0].string, "got the first item back correctly";
is $obj2[1].string, $obj[1].string, "got the second item back correctly";


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