Add some additional boolean-related JSON tests
authorJeff Godin <jgodin@tadl.org>
Tue, 3 Dec 2013 18:52:39 +0000 (13:52 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 3 Dec 2013 19:47:39 +0000 (11:47 -0800)
Add some additional boolean-related JSON tests, enable use strict /
use warnings for JSON tests.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

src/perl/t/09-Utils-JSON.t

index d074d5e..ce94012 100644 (file)
@@ -1,6 +1,8 @@
 #!perl -T
+use strict;
+use warnings;
 
-use Test::More tests => 49;
+use Test::More tests => 54;
 
 use OpenSRF::Utils::JSON;
 
@@ -19,6 +21,7 @@ is ($OpenSRF::Utils::JSON::JSON_PAYLOAD_KEY, '__p');
 # start with the simplest bits possible
 is (OpenSRF::Utils::JSON::true, 1);
 is (OpenSRF::Utils::JSON->true, 1);
+is (OpenSRF::Utils::JSON::false, 0);
 is (OpenSRF::Utils::JSON->false, 0);
 
 
@@ -28,7 +31,7 @@ my $testmap =  { hints   => { osrfException =>
                               { hint => 'osrfException',
                                 name => 'OpenSRF::DomainObject::oilsException' }
                             },
-                 classes => { OpenSRF::DomainObject::oilsException =>
+                 classes => { 'OpenSRF::DomainObject::oilsException' =>
                               { hint => 'osrfException',
                                 name => 'OpenSRF::DomainObject::oilsException' }
                             }
@@ -77,7 +80,11 @@ is (OpenSRF::Utils::JSON->perl2JSONObject(3),     3,     "Returns argument unles
 is (OpenSRF::Utils::JSON->perl2JSONObject('foo'), 'foo', "Returns argument unless it's a ref");
 
 ok (JSON::XS::is_bool(OpenSRF::Utils::JSON->true), 'OpenSRF::Utils::JSON->true is a Boolean according to JSON::XS');
-is (OpenSRF::Utils::JSON->perl2JSONObject(OpenSRF::Utils::JSON->true), '1', "Returns argument if it's a Boolean according to JSON");
+ok (JSON::XS::is_bool(OpenSRF::Utils::JSON->false), 'OpenSRF::Utils::JSON->false is a Boolean according to JSON::XS');
+ok (!JSON::XS::is_bool 1, "1 is not a boolean according to JSON::XS");
+ok (!JSON::XS::is_bool 0, "0 is not a boolean according to JSON::XS");
+is (OpenSRF::Utils::JSON->perl2JSONObject(OpenSRF::Utils::JSON->true), '1', "Returns argument if it's a Boolean according to JSON::XS");
+is (OpenSRF::Utils::JSON->perl2JSONObject(OpenSRF::Utils::JSON->false), '0', "Returns argument if it's a Boolean according to JSON::XS");
 
 my $hashref = { foo => 'bar' };
 is (UNIVERSAL::isa($hashref,'HASH'), 1);
@@ -114,13 +121,13 @@ is (OpenSRF::Utils::JSON->JSONObject2Perl($coderef), $coderef, "Returns argument
 
 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");
+           "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
 
 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");
+           "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');