[Opensrf-commits] r1790 - in trunk/src/perl: lib/OpenSRF/Utils t (sboyette)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Sep 15 12:19:51 EDT 2009


Author: sboyette
Date: 2009-09-15 12:19:48 -0400 (Tue, 15 Sep 2009)
New Revision: 1790

Modified:
   trunk/src/perl/lib/OpenSRF/Utils/JSON.pm
   trunk/src/perl/t/09-Utils-JSON.t
Log:
100% test coverage

Modified: trunk/src/perl/lib/OpenSRF/Utils/JSON.pm
===================================================================
--- trunk/src/perl/lib/OpenSRF/Utils/JSON.pm	2009-09-15 16:19:47 UTC (rev 1789)
+++ trunk/src/perl/lib/OpenSRF/Utils/JSON.pm	2009-09-15 16:19:48 UTC (rev 1790)
@@ -143,7 +143,7 @@
             my $class = $obj->{$JSON_CLASS_KEY};
             $class =~ s/^\s+//; # FIXME pretty sure these lines could condense to 's/\s+//g'
             $class =~ s/\s+$//;
-            $class = $pkg->lookup_class($class) || $class;
+            $class = $pkg->lookup_class($class) if $pkg->lookup_class($class);
             return bless(\$vivobj, $class) unless ref $vivobj;
             return bless($vivobj, $class);
         }

Modified: trunk/src/perl/t/09-Utils-JSON.t
===================================================================
--- trunk/src/perl/t/09-Utils-JSON.t	2009-09-15 16:19:47 UTC (rev 1789)
+++ trunk/src/perl/t/09-Utils-JSON.t	2009-09-15 16:19:48 UTC (rev 1790)
@@ -1,6 +1,6 @@
 #!perl -T
 
-use Test::More tests => 38;
+use Test::More tests => 49;
 
 use OpenSRF::Utils::JSON;
 
@@ -115,6 +115,27 @@
 is_deeply (OpenSRF::Utils::JSON->JSONObject2Perl([11, 12]), [11, 12], "Arrayrefs get reconstructed as themselves");
 is_deeply (OpenSRF::Utils::JSON->JSONObject2Perl([11, OpenSRF::Utils::JSON->true, 12]), [11, OpenSRF::Utils::JSON->true, 12],
            "Even when they contain JSON::XS::Booleans; those just don't get recursed upon");
-           # note: [11, 1, 12] doesn't work here, even though you can
-           # do math on J:X:Booleans
+           # note: [11, 1, 12] doesn't work here, even though you can do math on J:X:Booleans
 
+is_deeply (OpenSRF::Utils::JSON->JSONObject2Perl($hashref), { foo => 'bar' }, "Hashrefs without the class flag also get turned into themselves");
+is_deeply (OpenSRF::Utils::JSON->JSONObject2Perl({ foo => OpenSRF::Utils::JSON->true, bar => 'baz' }), 
+           { foo => OpenSRF::Utils::JSON->true, bar => 'baz'},
+           "Even when they contain JSON::XS::Booleans; those just don't get recursed upon");
+
+my $vivobj = OpenSRF::Utils::JSON->JSONObject2Perl($jsonobj);
+is (ref $vivobj, 'OpenSRF::DomainObject::oilsException');
+is_deeply ($vivobj, { foo => 'bar' }, "perl2JSONObject-packaged things get blessed to their original contents and class");
+
+my $codeobj = OpenSRF::Utils::JSON->perl2JSONObject($coderef);
+is_deeply (OpenSRF::Utils::JSON->JSONObject2Perl($codeobj), undef, "Things with undefined payloads (see above)return undef");
+
+$vivobj = OpenSRF::Utils::JSON->JSONObject2Perl({ __c => 'foo', __p => 'bar' });
+is (ref $vivobj, 'foo');
+is_deeply ($vivobj, \'bar', "Scalar payload and non-resolvable class hint vivifies to a scalar *ref* and a class of the class flag");
+
+
+#
+# json2Perl
+my $perlobj = OpenSRF::Utils::JSON->JSON2perl($jsonstr);
+is (ref $perlobj, 'OpenSRF::DomainObject::oilsException');
+is_deeply ($perlobj,  { foo => 'bar' }, "Successful revivification from JSON in one step");



More information about the opensrf-commits mailing list