"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/JSON-PP/t/006_pc_pretty.t" (18 Dec 2020, 1265 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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