4ae4ada38947fd05e251e6bc598a8cdb9e3313ef
[p5sagit/JSON-MaybeXS.git] / t / new.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More;
4 use JSON::MaybeXS ();
5
6 our @call;
7
8 sub Fake::new { bless({}, 'Fake') }
9 sub Fake::foo { push @call, a => $_[1] }
10 sub Fake::bar { push @call, c => $_[1] }
11
12 {
13   local $JSON::MaybeXS::JSON_Class = 'Fake';
14
15   my @args = (foo => 'b', bar => 'd');
16
17   foreach my $args (\@args, [ { @args } ]) {
18
19     local @call;
20
21     my $obj = JSON::MaybeXS->new(@$args);
22
23     is(ref($obj), 'Fake', 'Object of correct class');
24
25     is(join(' ', sort @call), 'a b c d', 'Methods called');
26   }
27 }
28
29 done_testing;