constructor test I wrote when I added new() and forgot about
Matt S Trout [Sun, 14 Dec 2014 16:33:45 +0000 (16:33 +0000)]
t/new.t [new file with mode: 0644]

diff --git a/t/new.t b/t/new.t
new file mode 100644 (file)
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;