From: Matt S Trout Date: Sun, 14 Dec 2014 16:33:45 +0000 (+0000) Subject: constructor test I wrote when I added new() and forgot about X-Git-Tag: v1.003004~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d411803f45d9d9ab45af647118fdd79178524fd;p=p5sagit%2FJSON-MaybeXS.git constructor test I wrote when I added new() and forgot about --- diff --git a/t/new.t b/t/new.t new file mode 100644 index 0000000..4ae4ada --- /dev/null +++ b/t/new.t @@ -0,0 +1,29 @@ +use strict; +use warnings FATAL => 'all'; +use Test::More; +use JSON::MaybeXS (); + +our @call; + +sub Fake::new { bless({}, 'Fake') } +sub Fake::foo { push @call, a => $_[1] } +sub Fake::bar { push @call, c => $_[1] } + +{ + local $JSON::MaybeXS::JSON_Class = 'Fake'; + + my @args = (foo => 'b', bar => 'd'); + + foreach my $args (\@args, [ { @args } ]) { + + local @call; + + my $obj = JSON::MaybeXS->new(@$args); + + is(ref($obj), 'Fake', 'Object of correct class'); + + is(join(' ', sort @call), 'a b c d', 'Methods called'); + } +} + +done_testing;