File: 080-type-constraints.t

package info (click to toggle)
raku-json-marshal 0.0.25-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,409 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
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env raku

use Test;

use JSON::Marshal;
use JSON::Fast;

my class TestClassConstraint {
    has $.depends is rw where Positional|Associative;
}

my $obj;

lives-ok { $obj = TestClassConstraint.new }, "create object with anonymous constraint (no arguments)";

my $json;

lives-ok {
    $json =  marshal($obj) ;
}, "marshal that";

my $parsed;

lives-ok { $parsed = from-json($json) }, "got some sane JSON";

ok $parsed<depends>:exists, "and we got the expected key";
ok !$parsed<depends>.defined, "and is 'null' as expected";

lives-ok { $obj = TestClassConstraint.new(depends => ['foo'] ) }, "create object with anonymous constraint positional argument";

lives-ok {
    $json =  marshal($obj) ;
}, "marshal that";

lives-ok { $parsed = from-json($json) }, "got some sane JSON";

ok $parsed<depends>:exists, "and we got the expected key";
ok $parsed<depends> ~~ Positional, "and is a Positional as expected";

lives-ok { $obj = TestClassConstraint.new(depends => { foo => 'bar' } ) }, "create object with anonymous constraint associative argument";

lives-ok {
    $json =  marshal($obj) ;
}, "marshal that";

lives-ok { $parsed = from-json($json) }, "got some sane JSON";

ok $parsed<depends>:exists, "and we got the expected key";
ok $parsed<depends> ~~ Associative, "and is a Associative as expected";
is $parsed<depends><foo>, 'bar' , "with the  expected value";


done-testing;
# vim: ft=raku