File: 040-json-name.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 (33 lines) | stat: -rw-r--r-- 721 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
#!raku

use v6;

use Test;

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

class TestClass {
    has $.nice-name is rw is json-name('666.evil.name');
}

my $obj;
lives-ok { $obj = TestClass.new(nice-name => "value for money") }, "create on object with a json-name attribute";

my $json;

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

my $back;

lives-ok { $back = from-json($json) }, "parse the JSON";

is $back<666.evil.name>, $obj.nice-name, "and we got the key back with the json name";

lives-ok { $obj = TestClass.new }, "create on object with a json-name attribute but not defined";

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

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