1 2# copied over from JSON::PC and modified to use JSON 3# copied over from JSON::XS and modified to use JSON 4 5use strict; 6use Test::More; 7BEGIN { plan tests => 9 }; 8 9BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; } 10 11use JSON; 12 13my ($js,$obj,$json); 14my $pc = new JSON; 15 16$obj = {foo => "bar"}; 17$js = $pc->encode($obj); 18is($js,q|{"foo":"bar"}|); 19 20$obj = [10, "hoge", {foo => "bar"}]; 21$pc->pretty (1); 22$js = $pc->encode($obj); 23is($js,q|[ 24 10, 25 "hoge", 26 { 27 "foo" : "bar" 28 } 29] 30|); 31 32$obj = { foo => [ {a=>"b"}, 0, 1, 2 ] }; 33$pc->pretty(0); 34$js = $pc->encode($obj); 35is($js,q|{"foo":[{"a":"b"},0,1,2]}|); 36 37 38$obj = { foo => [ {a=>"b"}, 0, 1, 2 ] }; 39$pc->pretty(1); 40$js = $pc->encode($obj); 41is($js,q|{ 42 "foo" : [ 43 { 44 "a" : "b" 45 }, 46 0, 47 1, 48 2 49 ] 50} 51|); 52 53$obj = { foo => [ {a=>"b"}, 0, 1, 2 ] }; 54$pc->pretty(0); 55$js = $pc->encode($obj); 56is($js,q|{"foo":[{"a":"b"},0,1,2]}|); 57 58 59$obj = {foo => "bar"}; 60$pc->indent(3); # original -- $pc->indent(1); 61is($pc->encode($obj), qq|{\n "foo":"bar"\n}\n|, "nospace"); 62$pc->space_after(1); 63is($pc->encode($obj), qq|{\n "foo": "bar"\n}\n|, "after"); 64$pc->space_before(1); 65is($pc->encode($obj), qq|{\n "foo" : "bar"\n}\n|, "both"); 66$pc->space_after(0); 67is($pc->encode($obj), qq|{\n "foo" :"bar"\n}\n|, "before"); 68 69