summaryrefslogtreecommitdiff
path: root/t/json.t
diff options
context:
space:
mode:
Diffstat (limited to 't/json.t')
-rw-r--r--t/json.t65
1 files changed, 65 insertions, 0 deletions
diff --git a/t/json.t b/t/json.t
new file mode 100644
index 0000000..5e00080
--- /dev/null
+++ b/t/json.t
@@ -0,0 +1,65 @@
+#!perl
+use strict;
+use warnings;
+package Foo;{
+use Moose;
+use Data::MultiValued::AttributeTrait::Tags;
+use Data::MultiValued::AttributeTrait::Ranges;
+use Data::MultiValued::AttributeTrait::TagsAndRanges;
+
+with 'Data::MultiValued::UglySerializationHelperRole';
+
+has tt => (
+ is => 'rw',
+ isa => 'Int',
+ traits => ['MultiValued::Tags'],
+ default => 3,
+ predicate => 'has_tt',
+ clearer => 'clear_tt',
+);
+
+has rr => (
+ is => 'rw',
+ isa => 'Str',
+ traits => ['MultiValued::Ranges'],
+ predicate => 'has_rr',
+ clearer => 'clear_rr',
+);
+
+has ttrr => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'default',
+ traits => ['MultiValued::TagsAndRanges'],
+ predicate => 'has_ttrr',
+ clearer => 'clear_ttrr',
+);
+
+
+}
+package main;
+use Test::Most 'die';
+use Data::Printer;
+use JSON::XS;
+
+my $opts={tag=>'something'};
+
+my $json = JSON::XS->new->utf8;
+my $obj = Foo->new(rr=>'foo');
+$obj->tt_multi($opts,1234);
+my $hash = $obj->as_hash;
+note p $hash;
+my $str = $json->encode($hash);
+note p $str;
+
+note "rebuilding";
+my $obj2 = Foo->new_in_place($json->decode($str));
+
+note p $obj;
+note p $obj2;
+
+is($obj2->tt,$obj->tt,'tt');
+is($obj2->tt_multi($opts),$obj->tt_multi($opts),'tt tagged');
+is($obj2->rr,$obj->rr,'rr');
+
+done_testing;